Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
comp30023-2021-project-1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Elizabeth Baker
comp30023-2021-project-1
Commits
aa7d11bc
Commit
aa7d11bc
authored
Mar 28, 2021
by
Elizabeth Baker
Browse files
Options
Downloads
Patches
Plain Diff
compare diff
parent
e1a1b26b
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
allocate.c
+24
-17
24 additions, 17 deletions
allocate.c
with
24 additions
and
17 deletions
allocate.c
+
24
−
17
View file @
aa7d11bc
...
@@ -20,7 +20,7 @@ typedef struct {
...
@@ -20,7 +20,7 @@ typedef struct {
int
timeRemaining
;
int
timeRemaining
;
int
subProcsRunning
;
int
subProcsRunning
;
int
justStarted
;
int
justStarted
;
int
start
Time
;
int
delta
Time
;
}
process
;
}
process
;
typedef
struct
{
typedef
struct
{
...
@@ -111,7 +111,11 @@ int main(int argc, char *argv[]) {
...
@@ -111,7 +111,11 @@ int main(int argc, char *argv[]) {
//while (fgets(line, sizeof line, f) != NULL) {
//while (fgets(line, sizeof line, f) != NULL) {
while
(
newProcess
=
getNextProcessB
(
f
,
arrivalLounge
,
readAhead
))
{
while
(
newProcess
=
getNextProcessB
(
f
,
arrivalLounge
,
readAhead
))
{
//printf("process id:%s process arrival time: %d\n", newProcess->processID, newProcess->timeArrived);
deltaTime
=
newProcess
->
timeArrived
-
currentTime
;
deltaTime
=
newProcess
->
timeArrived
-
currentTime
;
//update currentTime
//update currentTime
currentTime
+=
deltaTime
;
currentTime
+=
deltaTime
;
...
@@ -160,11 +164,14 @@ int main(int argc, char *argv[]) {
...
@@ -160,11 +164,14 @@ int main(int argc, char *argv[]) {
parableProcess
[
i
].
parallelisable
=
newProcess
->
parallelisable
;
parableProcess
[
i
].
parallelisable
=
newProcess
->
parallelisable
;
parableProcess
[
i
].
timeCompleted
=
-
1
;
parableProcess
[
i
].
timeCompleted
=
-
1
;
parableProcess
[
i
].
timeRemaining
=
parableProcess
[
i
].
executionTime
;
parableProcess
[
i
].
timeRemaining
=
parableProcess
[
i
].
executionTime
;
parableProcess
[
i
].
start
Time
=
newProcess
->
start
Time
;
parableProcess
[
i
].
delta
Time
=
newProcess
->
delta
Time
;
addProcessToQueue
(
CPUs
[
i
].
processQueue
,
&
parableProcess
[
i
],
currentTime
,
i
);
addProcessToQueue
(
CPUs
[
i
].
processQueue
,
&
parableProcess
[
i
],
currentTime
,
i
);
}
}
numProcessesLeft
+=
1
;
numProcessesLeft
+=
1
;
llist_push
(
paralellizedProcesses
,
newProcess
);
llist_push
(
paralellizedProcesses
,
newProcess
);
}
else
{
printf
(
"Error in test file "
);
exit
(
1
);
}
}
// Log started processes.
// Log started processes.
for
(
int
j
=
0
;
j
<
numCPU
;
j
++
)
{
for
(
int
j
=
0
;
j
<
numCPU
;
j
++
)
{
...
@@ -172,9 +179,10 @@ int main(int argc, char *argv[]) {
...
@@ -172,9 +179,10 @@ int main(int argc, char *argv[]) {
//next process in queue started
//next process in queue started
if
(
headProcess
!=
NULL
&&
headProcess
->
justStarted
)
{
if
(
headProcess
!=
NULL
&&
headProcess
->
justStarted
)
{
// printf("current time: %d\n", currentTime);
// printf("current time: %d\n", currentTime);
printf
(
"%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d
\n
"
,
headProcess
->
startTime
,
headProcess
->
processID
,
headProcess
->
timeRemaining
,
j
);
headProcess
->
justStarted
=
0
;
headProcess
->
justStarted
=
0
;
printf
(
"%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d - AAAA line 184
\n
"
,
currentTime
-
headProcess
->
deltaTime
,
headProcess
->
processID
,
headProcess
->
timeRemaining
+
headProcess
->
deltaTime
,
j
);
}
}
}
}
...
@@ -218,9 +226,9 @@ int main(int argc, char *argv[]) {
...
@@ -218,9 +226,9 @@ int main(int argc, char *argv[]) {
//next process in queue started
//next process in queue started
if
(
headProcess
!=
NULL
&&
headProcess
->
justStarted
)
{
if
(
headProcess
!=
NULL
&&
headProcess
->
justStarted
)
{
// printf("current time: %d\n", currentTime);
// printf("current time: %d\n", currentTime);
printf
(
"%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d
\n
"
,
headProcess
->
startTime
,
headProcess
->
processID
,
headProcess
->
timeRemaining
,
j
);
headProcess
->
justStarted
=
0
;
headProcess
->
justStarted
=
0
;
printf
(
"%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d
\n
"
,
currentTime
,
headProcess
->
processID
,
headProcess
->
timeRemaining
,
j
);
}
}
}
}
...
@@ -288,10 +296,10 @@ void initializeProcess(char data[], process *newProcess) {
...
@@ -288,10 +296,10 @@ void initializeProcess(char data[], process *newProcess) {
if
(
token
!=
NULL
)
{
if
(
token
!=
NULL
)
{
newProcess
->
parallelisable
=
token
[
0
];
newProcess
->
parallelisable
=
token
[
0
];
}
}
newProcess
->
startTime
=
0
;
newProcess
->
deltaTime
=
0
;
newProcess
->
justStarted
=
0
;
newProcess
->
timeCompleted
=
-
1
;
newProcess
->
timeCompleted
=
-
1
;
newProcess
->
timeRemaining
=
newProcess
->
executionTime
;
newProcess
->
timeRemaining
=
newProcess
->
executionTime
;
newProcess
->
justStarted
=
0
;
}
}
process
*
headData
(
llist
*
q
)
{
process
*
headData
(
llist
*
q
)
{
...
@@ -329,11 +337,12 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
...
@@ -329,11 +337,12 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
while
(
headProcess
!=
NULL
&&
deltaTime
!=
0
)
{
while
(
headProcess
!=
NULL
&&
deltaTime
!=
0
)
{
if
(
deltaTime
>=
headProcess
->
timeRemaining
)
{
// Process has finished
if
(
deltaTime
>=
headProcess
->
timeRemaining
)
{
// Process has finished
deltaTime
-=
headProcess
->
timeRemaining
;
deltaTime
-=
headProcess
->
timeRemaining
;
headProcess
->
timeCompleted
=
currentTime
-
deltaTime
;
headProcess
->
timeCompleted
=
currentTime
-
deltaTime
;
//+ headProcess->timeRemaining;
// int t = headProcess->timeRemaining;
headProcess
->
timeRemaining
=
0
;
headProcess
->
timeRemaining
=
0
;
if
(
headProcess
->
parallelisable
==
'p'
)
{
if
(
headProcess
->
parallelisable
==
'p'
)
{
//printf("process had finished, and was a paralized subprocess\n");
//printf("process had finished, and was a paralized subprocess\n");
parentPid
[
0
]
=
strtok
(
headProcess
->
processID
,
"."
);
parentPid
[
0
]
=
strtok
(
headProcess
->
processID
,
"."
);
//todo to get rid of warning strncopy
paralizedProcess
=
parallelParent
(
paralellProcesses
,
parentPid
);
paralizedProcess
=
parallelParent
(
paralellProcesses
,
parentPid
);
paralizedProcess
->
subProcsRunning
-=
1
;
paralizedProcess
->
subProcsRunning
-=
1
;
if
(
paralizedProcess
->
subProcsRunning
==
0
)
{
if
(
paralizedProcess
->
subProcsRunning
==
0
)
{
...
@@ -354,7 +363,7 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
...
@@ -354,7 +363,7 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
headProcess
=
headData
(
processQueue
);
headProcess
=
headData
(
processQueue
);
if
(
headProcess
){
if
(
headProcess
){
headProcess
->
justStarted
=
-
1
;
headProcess
->
justStarted
=
-
1
;
headProcess
->
start
Time
=
currentTime
-
deltaTime
;
headProcess
->
delta
Time
=
deltaTime
;
}
}
}
else
{
// finishedprocess is not parallelisable
}
else
{
// finishedprocess is not parallelisable
...
@@ -368,12 +377,13 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
...
@@ -368,12 +377,13 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
headProcess
=
headData
(
processQueue
);
headProcess
=
headData
(
processQueue
);
if
(
headProcess
){
if
(
headProcess
){
headProcess
->
justStarted
=
-
1
;
headProcess
->
justStarted
=
-
1
;
headProcess
->
start
Time
=
currentTime
-
deltaTime
;
headProcess
->
delta
Time
=
deltaTime
;
}
}
}
}
}
else
{
// head process not finished
}
else
{
// head process not finished
headProcess
->
timeRemaining
-=
deltaTime
;
headProcess
->
timeRemaining
-=
deltaTime
;
headProcess
->
deltaTime
=
deltaTime
;
deltaTime
=
0
;
deltaTime
=
0
;
// llist_print( processQueue, (void (*)(void *)) &printQEntry );
// llist_print( processQueue, (void (*)(void *)) &printQEntry );
}
}
...
@@ -414,11 +424,8 @@ void addProcessToQueue(llist *processQueue, process *newProcess, int currentTime
...
@@ -414,11 +424,8 @@ void addProcessToQueue(llist *processQueue, process *newProcess, int currentTime
process
*
headProcess
;
process
*
headProcess
;
llist_add_inorder
(
newProcess
,
processQueue
,
(
int
(
*
)(
void
*
,
void
*
))
&
leastTimeRemaining
);
llist_add_inorder
(
newProcess
,
processQueue
,
(
int
(
*
)(
void
*
,
void
*
))
&
leastTimeRemaining
);
headProcess
=
headData
(
processQueue
);
headProcess
=
headData
(
processQueue
);
// llist_print(processQueue, (void (*)(void *)) &printQEntry);
if
(
oldProcess
!=
NULL
&&
!
strncmp
(
headProcess
->
processID
,
oldProcess
->
processID
,
sizeof
(
newProcess
->
processID
))
)
if
(
!
strncmp
(
headProcess
->
processID
,
newProcess
->
processID
,
sizeof
(
newProcess
->
processID
)))
{
headProcess
->
justStarted
=-
1
;
headProcess
->
justStarted
=-
1
;
headProcess
->
startTime
=
currentTime
;
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment