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
65e89a87
Commit
65e89a87
authored
Mar 28, 2021
by
Elizabeth Baker
Browse files
Options
Downloads
Patches
Plain Diff
"RUNNING" time fiddles
parent
3dd0834f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
allocate.c
+19
-24
19 additions, 24 deletions
allocate.c
with
19 additions
and
24 deletions
allocate.c
+
19
−
24
View file @
65e89a87
...
@@ -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
delta
Time
;
int
start
Time
;
}
process
;
}
process
;
typedef
struct
{
typedef
struct
{
...
@@ -111,11 +111,7 @@ int main(int argc, char *argv[]) {
...
@@ -111,11 +111,7 @@ 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
;
...
@@ -167,9 +163,6 @@ int main(int argc, char *argv[]) {
...
@@ -167,9 +163,6 @@ int main(int argc, char *argv[]) {
}
}
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
++
)
{
...
@@ -177,9 +170,9 @@ int main(int argc, char *argv[]) {
...
@@ -177,9 +170,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 - AAAA line 181
\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
,
j
);
}
}
}
}
...
@@ -223,13 +216,13 @@ int main(int argc, char *argv[]) {
...
@@ -223,13 +216,13 @@ 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);
headProcess
->
justStarted
=
0
;
printf
(
"%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d
\n
"
,
printf
(
"%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d
\n
"
,
currentTime
,
headProcess
->
processID
,
headProcess
->
timeRemaining
,
j
);
headProcess
->
startTime
,
headProcess
->
processID
,
headProcess
->
timeRemaining
,
j
);
headProcess
->
justStarted
=
0
;
}
}
}
}
// currentTime +=
delta
Time;
// currentTime +=
start
Time;
}
}
// printf("Completed Queue:");
// printf("Completed Queue:");
// llist_print(completedProcesses, (void (*)(void *)) &printQEntry);
// llist_print(completedProcesses, (void (*)(void *)) &printQEntry);
...
@@ -293,9 +286,10 @@ void initializeProcess(char data[], process *newProcess) {
...
@@ -293,9 +286,10 @@ void initializeProcess(char data[], process *newProcess) {
if
(
token
!=
NULL
)
{
if
(
token
!=
NULL
)
{
newProcess
->
parallelisable
=
token
[
0
];
newProcess
->
parallelisable
=
token
[
0
];
}
}
newProcess
->
delta
Time
=
0
;
newProcess
->
start
Time
=
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
)
{
...
@@ -333,12 +327,11 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
...
@@ -333,12 +327,11 @@ 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->timeRemaining;
headProcess
->
timeCompleted
=
currentTime
-
deltaTime
;
// 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
,
"."
);
//todo to get rid of warning strncopy
parentPid
[
0
]
=
strtok
(
headProcess
->
processID
,
"."
);
paralizedProcess
=
parallelParent
(
paralellProcesses
,
parentPid
);
paralizedProcess
=
parallelParent
(
paralellProcesses
,
parentPid
);
paralizedProcess
->
subProcsRunning
-=
1
;
paralizedProcess
->
subProcsRunning
-=
1
;
if
(
paralizedProcess
->
subProcsRunning
==
0
)
{
if
(
paralizedProcess
->
subProcsRunning
==
0
)
{
...
@@ -346,10 +339,10 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
...
@@ -346,10 +339,10 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
// parallelized process has completed.
// parallelized process has completed.
*
numProcessesLeft
-=
1
;
*
numProcessesLeft
-=
1
;
*
numProcessComplete
+=
1
;
*
numProcessComplete
+=
1
;
paralizedProcess
->
timeCompleted
=
currentTime
-
deltaTime
;
//todo error on calculation here
paralizedProcess
->
timeCompleted
=
currentTime
-
deltaTime
;
paralizedProcess
->
timeRemaining
=
0
;
paralizedProcess
->
timeRemaining
=
0
;
headProcess
->
timeRemaining
=
0
;
headProcess
->
timeRemaining
=
0
;
//printf("process had finished: Current time: %d,
delta
Time: %d\n", currentTime,
delta
Time);
//printf("process had finished: Current time: %d,
start
Time: %d\n", currentTime,
start
Time);
printf
(
"%d,FINISHED,pid=%s,proc_remaining=%d
\n
"
,
printf
(
"%d,FINISHED,pid=%s,proc_remaining=%d
\n
"
,
paralizedProcess
->
timeCompleted
,
paralizedProcess
->
processID
,
*
numProcessesLeft
);
paralizedProcess
->
timeCompleted
,
paralizedProcess
->
processID
,
*
numProcessesLeft
);
// Could accumulate statistics here instead of keeping list of completed processes
// Could accumulate statistics here instead of keeping list of completed processes
...
@@ -359,7 +352,7 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
...
@@ -359,7 +352,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
->
delta
Time
=
deltaTime
;
headProcess
->
start
Time
=
currentTime
-
deltaTime
;
}
}
}
else
{
// finishedprocess is not parallelisable
}
else
{
// finishedprocess is not parallelisable
...
@@ -373,13 +366,12 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
...
@@ -373,13 +366,12 @@ 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
->
delta
Time
=
deltaTime
;
headProcess
->
start
Time
=
currentTime
-
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 );
}
}
...
@@ -420,8 +412,11 @@ void addProcessToQueue(llist *processQueue, process *newProcess, int currentTime
...
@@ -420,8 +412,11 @@ 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
);
if
(
strncmp
(
headProcess
->
processID
,
newProcess
->
processID
,
sizeof
(
newProcess
->
processID
)))
// llist_print(processQueue, (void (*)(void *)) &printQEntry);
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