Skip to content
Snippets Groups Projects
Commit aa7d11bc authored by Elizabeth Baker's avatar Elizabeth Baker
Browse files

compare diff

parent e1a1b26b
No related branches found
No related tags found
No related merge requests found
...@@ -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 startTime; int deltaTime;
} 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].startTime = newProcess->startTime; parableProcess[i].deltaTime = newProcess->deltaTime;
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->startTime = currentTime - deltaTime; headProcess->deltaTime = 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->startTime = currentTime - deltaTime; headProcess->deltaTime = 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;
}
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment