diff --git a/allocate.c b/allocate.c index d1567e4950a458a8c8130753663be2edb1a5ab93..a458cfbbdcf862a1360ea4a43c488670479429f9 100644 --- a/allocate.c +++ b/allocate.c @@ -129,10 +129,8 @@ int main(int argc, char *argv[]) { CPUs[j].totalExecutionTimeRemaining -= deltaTime; } } - - - if (newProcess->parallelisable == 'n') { - //allocate process to cpu + //allocate process to cpu(s) + if (newProcess->parallelisable == 'n') { // If its not parallelizable just allocate it to queue int shortestTimeRemaining = 0; //this is the index for the CPU with the shortest time remaining for (int j = 1; j < numCPU; j++) { // this is choosing a cpu queue scheduling @@ -140,20 +138,19 @@ int main(int argc, char *argv[]) { shortestTimeRemaining = j; } } - //position the new process in the queue addProcessToQueue(CPUs[shortestTimeRemaining].processQueue, newProcess, currentTime, shortestTimeRemaining); numProcessesLeft += 1; - CPUs[shortestTimeRemaining].totalExecutionTimeRemaining += newProcess->executionTime; - - } else if (newProcess->parallelisable == 'p') { + } else if (newProcess->parallelisable == 'p') { // Parallelizable processes need to be split up + // calculate number of sub processes and execution times for sub processes int quot = newProcess->executionTime / numCPU; int rem = newProcess->executionTime % numCPU; int nSubProc = numCPU; if (quot == 0) nSubProc = rem; newProcess->subProcsRunning = nSubProc; + // create the sub processes process *parableProcess = malloc(nSubProc * (sizeof(process))); for (int i = 0; i < nSubProc; i++) { parableProcess[i].timeArrived = newProcess->timeArrived; @@ -180,7 +177,7 @@ int main(int argc, char *argv[]) { // printf("current time: %d\n", currentTime); headProcess->justStarted = 0; printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d\n", - deltaTime+1, headProcess->processID, headProcess->timeRemaining, j); + currentTime, headProcess->processID, headProcess->timeRemaining, j); } }