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
24bde08c
Commit
24bde08c
authored
Mar 29, 2021
by
Elizabeth Baker
Browse files
Options
Downloads
Patches
Plain Diff
!!!!!!!!!!IT WORKS!!!!!!!!!
parent
8bb536cf
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
+54
-12
54 additions, 12 deletions
allocate.c
with
54 additions
and
12 deletions
allocate.c
+
54
−
12
View file @
24bde08c
...
@@ -46,6 +46,8 @@ int leastTimeRemaining(process *p, process *q);
...
@@ -46,6 +46,8 @@ int leastTimeRemaining(process *p, process *q);
int
leastExecutionTime
(
process
*
p
,
process
*
q
);
int
leastExecutionTime
(
process
*
p
,
process
*
q
);
int
leastCompletionTime
(
process
*
p
,
process
*
q
);
void
calStats
(
llist
*
completedProcesses
,
int
*
currentTime
,
float
*
aveTurnaroundTime
,
void
calStats
(
llist
*
completedProcesses
,
int
*
currentTime
,
float
*
aveTurnaroundTime
,
float
*
maxOverhead
,
float
*
averageOverhead
);
float
*
maxOverhead
,
float
*
averageOverhead
);
...
@@ -176,7 +178,7 @@ int main(int argc, char *argv[]) {
...
@@ -176,7 +178,7 @@ int main(int argc, char *argv[]) {
process
*
currProc
;
process
*
currProc
;
if
(
currNode
)
currProc
=
currNode
->
data
;
if
(
currNode
)
currProc
=
currNode
->
data
;
while
(
currNode
){
while
(
currNode
){
if
(
currProc
->
timeCompleted
>=
currentTime
)
{
if
(
currProc
!=
NULL
&&
currProc
->
timeCompleted
>=
currentTime
)
{
printf
(
"%d,FINISHED,pid=%s,proc_remaining=%d
\n
"
,
printf
(
"%d,FINISHED,pid=%s,proc_remaining=%d
\n
"
,
currProc
->
timeCompleted
,
currProc
->
processID
,
numProcessesLeft
);
currProc
->
timeCompleted
,
currProc
->
processID
,
numProcessesLeft
);
...
@@ -230,6 +232,18 @@ int main(int argc, char *argv[]) {
...
@@ -230,6 +232,18 @@ int main(int argc, char *argv[]) {
CPUs
[
j
].
totalExecutionTimeRemaining
-=
deltaTime
;
CPUs
[
j
].
totalExecutionTimeRemaining
-=
deltaTime
;
}
}
}
}
// Log finished processes.
struct
node
*
currNode
=
*
completedProcesses
;
//(struct node *)
headData
(
completedProcesses
);
process
*
currProc
=
currNode
->
data
;
while
(
currNode
){
if
(
currProc
!=
NULL
&&
currProc
->
timeCompleted
>=
currentTime
)
{
printf
(
"%d,FINISHED,pid=%s,proc_remaining=%d
\n
"
,
currProc
->
timeCompleted
,
currProc
->
processID
,
numProcessesLeft
);
}
currNode
=
currNode
->
next
;
if
(
currNode
)
currProc
=
currNode
->
data
;
}
// Log process starts
// Log process starts
for
(
int
j
=
0
;
j
<
numCPU
;
j
++
)
{
for
(
int
j
=
0
;
j
<
numCPU
;
j
++
)
{
headProcess
=
headData
(
CPUs
[
j
].
processQueue
);
headProcess
=
headData
(
CPUs
[
j
].
processQueue
);
...
@@ -274,16 +288,47 @@ void printQEntry(process *p) {
...
@@ -274,16 +288,47 @@ void printQEntry(process *p) {
else
printf
(
"EMPTY LIST
\n
"
);
else
printf
(
"EMPTY LIST
\n
"
);
}
}
void
headNULL
(
llist
*
p
){
struct
node
*
currNode
=
*
p
;
currNode
->
data
=
NULL
;
currNode
->
next
=
NULL
;
}
int
leastTimeRemaining
(
process
*
p
,
process
*
q
)
{
int
leastTimeRemaining
(
process
*
p
,
process
*
q
)
{
if
(
p
->
timeRemaining
<
q
->
timeRemaining
)
int
pid
=
atoi
(
p
->
processID
);
int
qid
=
atoi
(
q
->
processID
);
if
(
p
->
timeRemaining
<
q
->
timeRemaining
){
return
-
1
;
//true
}
else
if
(
p
->
executionTime
==
q
->
executionTime
&&
pid
<
qid
)
{
return
-
1
;
return
-
1
;
}
else
return
0
;
else
return
0
;
}
}
int
leastExecutionTime
(
process
*
p
,
process
*
q
)
{
int
leastExecutionTime
(
process
*
p
,
process
*
q
)
{
if
(
p
->
executionTime
<
q
->
executionTime
||
p
->
executionTime
==
q
->
executionTime
&&
int
pid
=
atoi
(
p
->
processID
);
strcmp
(
p
->
processID
,
q
->
processID
))
int
qid
=
atoi
(
q
->
processID
);
if
(
p
->
executionTime
<
q
->
executionTime
){
return
-
1
;
//true
}
else
if
(
p
->
executionTime
==
q
->
executionTime
&&
pid
<
qid
)
{
return
-
1
;
}
else
return
0
;
//false
}
int
leastCompletionTime
(
process
*
p
,
process
*
q
)
{
int
pid
=
atoi
(
p
->
processID
);
int
qid
=
atoi
(
q
->
processID
);
if
(
p
->
timeCompleted
<
q
->
timeCompleted
){
return
-
1
;
//true
return
-
1
;
//true
}
else
if
(
p
->
timeCompleted
==
q
->
timeCompleted
&&
pid
<
qid
){
return
-
1
;
//true
}
else
return
0
;
//false
else
return
0
;
//false
}
}
...
@@ -364,12 +409,8 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
...
@@ -364,12 +409,8 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
*
numProcessComplete
+=
1
;
*
numProcessComplete
+=
1
;
paralizedProcess
->
timeCompleted
=
currentTime
-
deltaTime
;
paralizedProcess
->
timeCompleted
=
currentTime
-
deltaTime
;
paralizedProcess
->
timeRemaining
=
0
;
paralizedProcess
->
timeRemaining
=
0
;
headProcess
->
timeRemaining
=
0
;
llist_add_inorder
(
paralizedProcess
,
processesComplete
,(
int
(
*
)(
void
*
,
void
*
))
&
leastCompletionTime
);
//printf("process had finished: Current time: %d, deltaTime: %d\n", currentTime, deltaTime);
//llist_push(processesComplete, paralizedProcess);
// printf("%d,FINISHED,pid=%s,proc_remaining=%d\n",
// paralizedProcess->timeCompleted, paralizedProcess->processID, *numProcessesLeft);
// Could accumulate statistics here instead of keeping list of completed processes
llist_push
(
processesComplete
,
paralizedProcess
);
}
}
llist_pop
(
processQueue
);
llist_pop
(
processQueue
);
headProcess
=
headData
(
processQueue
);
headProcess
=
headData
(
processQueue
);
...
@@ -385,7 +426,9 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
...
@@ -385,7 +426,9 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll
// printf("%d,FINISHED,pid=%s,proc_remaining=%d\n",
// printf("%d,FINISHED,pid=%s,proc_remaining=%d\n",
// headProcess->timeCompleted, headProcess->processID, *numProcessesLeft);
// headProcess->timeCompleted, headProcess->processID, *numProcessesLeft);
// Could accumulate statistics here instead of keeping list of completed processes
// Could accumulate statistics here instead of keeping list of completed processes
llist_push
(
processesComplete
,
headProcess
);
llist_add_inorder
(
headProcess
,
processesComplete
,
(
int
(
*
)(
void
*
,
void
*
))
&
leastCompletionTime
);
//llist_push(processesComplete, headProcess);
llist_pop
(
processQueue
);
llist_pop
(
processQueue
);
headProcess
=
headData
(
processQueue
);
headProcess
=
headData
(
processQueue
);
if
(
headProcess
){
if
(
headProcess
){
...
@@ -455,7 +498,6 @@ process *getNextProcessB(FILE *f, llist *arrivals, process *readAhead) {
...
@@ -455,7 +498,6 @@ process *getNextProcessB(FILE *f, llist *arrivals, process *readAhead) {
newProcess
=
malloc
(
sizeof
(
process
));
newProcess
=
malloc
(
sizeof
(
process
));
memcpy
(
newProcess
,
readAhead
,
sizeof
(
process
));
memcpy
(
newProcess
,
readAhead
,
sizeof
(
process
));
llist_add_inorder
(
newProcess
,
arrivals
,
(
int
(
*
)(
void
*
,
void
*
))
&
leastExecutionTime
);
llist_add_inorder
(
newProcess
,
arrivals
,
(
int
(
*
)(
void
*
,
void
*
))
&
leastExecutionTime
);
//llist_print();
while
(
readAhead
->
timeArrived
!=
-
1
&&
!
batchEnd
)
{
while
(
readAhead
->
timeArrived
!=
-
1
&&
!
batchEnd
)
{
if
(
fgets
(
line
,
sizeof
line
,
f
)
!=
NULL
)
{
if
(
fgets
(
line
,
sizeof
line
,
f
)
!=
NULL
)
{
newProcess
=
malloc
(
sizeof
(
process
));
newProcess
=
malloc
(
sizeof
(
process
));
...
...
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