我試圖實現一個多CPU FCFS算法,但我想不出一種方式來實現作業/進程如何跳轉到另一個CPU。實現多CPU FCFS算法
任何人都可以向我解釋或給我提示從哪裏開始?
這是我到目前爲止,我試圖實現FCFS算法單個CPU第一:
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 time
for (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 time
for (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;
編輯: 例如,這裏有我想要做的,與實現樣本輸出程序:
Enter number of CPUs: 2
Enter total number of processes: 6
Enter Process Burst Time
P1: [input here]
P2: [input here]
P3: [input here]
p4: [input here]
p5: [input here]
p6: [input here]
Process Burst Time Waiting Time Turn Around Time
P1 [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, P4
CPU 2: P2, P5, P6
多CPU意味着什麼?你打算使用線程嗎? – Chiel