News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

### Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

### Topics - Kronus_Arm

Pages: [1]
1
##### Programming / Simulating the FCFS CPU Scheduling algorithm with multiple CPUs
« on: October 20, 2015, 08:32:07 am »
After hours of braining I've come to the point of crashing, and come to realize that I cannot implement a way to simulate the FCFS algorithm with the idea of having multiple CPUs handling each jobs/processes in C++, specifically 2 CPUs/cores.

Anyone has an idea, tips or clues where can I start?

Here's my code for simulating the FCFS algorithim in a single CPU:

Code: [Select]
`int n, burstTime[99], waitingTime[99], totalAT[99], aveWT = 0, aveTAT = 0, i, j;cout << "Enter total number of processes: ";cin >> n;cout << "\nEnter Process Burst Time\n";for (i = 0; i<n; i++){    cout << "P[" << i + 1 << "]: ";    cin >> burstTime[i];}waitingTime[0] = 0;    //waiting time for first process is 0              //calculating waiting timefor (i = 1; i<n; i++){    waitingTime[i] = 0;    for (j = 0; j<i; j++)        waitingTime[i] += burstTime[j];}cout << "\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time";//calculating turnaround timefor (i = 0; i<n; i++){    totalAT[i] = burstTime[i] + waitingTime[i];    aveWT += waitingTime[i];    aveTAT += totalAT[i];    cout << "\nP[" << i + 1 << "]" << "\t\t" << burstTime[i] << "\t\t" << waitingTime[i] << "\t\t" << totalAT[i];}aveWT /= i;aveTAT /= i;cout << "\n\nAverage Waiting Time: " << aveWT;cout << "\nAverage Turnaround Time: " << aveTAT <<endl;`
I know, noob-ish code at best. I have little experience with C++ and programming in general, but I am getting there somehow. Take note of the word "simulating", I'm not really doing anything fancy like multi threading or actually coding something to actually use 2 cores, just a simulation process.

EDIT:

Here's what I envisioned of the output of this code in the commandline:

Code: [Select]
`Enter total number of processes: 6Enter Process Burst TimeP1: [input here]P2: [input here]P3: [input here]p4: [input here]p5: [input here]p6: [input here]Process     Burst Time         Waiting Time                                 Turn Around TimeP1          [burst time here]  [calculated waiting time here]      [calculated turn around time]P2          [burst time here]  [calculated waiting time here]      [calculated turn around time]P3          [burst time here]  [calculated waiting time here]      [calculated turn around time]P4          [burst time here]  [calculated waiting time here]      [calculated turn around time]P5          [burst time here]  [calculated waiting time here]      [calculated turn around time]P6          [burst time here]  [calculated waiting time here]      [calculated turn around time]CPUs handling the processes: CPU 1: P1, P3, P4CPU 2: P2, P5, P6`
for example: the first process/job (which is P1) having the arrival time of 0 and the burst time of 5 gets processed automatically by the first CPU, the second job which is P2 has an arrival time of 2 and a burst time of 8, as the first CPU is still actively processing the first job, the second job goes to the second CPU (which is CPU 2) for it to be processed.

Pages: [1]