Effacer les filtres
Effacer les filtres

round robin

1 vue (au cours des 30 derniers jours)
Ayda
Ayda le 7 Avr 2012
Good Morning\evening i have to write a code for round robin(example 5 processes) i have number of processes and each process has its CPUtime(10,6,2,4 and 8 respectively)
i could not know why the CPUtime for process 4 and 5 do not go to zero
numOfJobs=input('Enter the number of jobs to run = ');
for i=1:numOfJobs
job(i)=i;
end
CPUtime=input('Enter the CPU time required by each job = ,[in vector form] ');
totalCPUtime= sum(CPUtime)
while (totalCPUtime ~= 0)
for i=1:numOfJobs
if (CPUtime(i)== 0)
break
else
CPUtime(i)=CPUtime(i)-1;
end
job(i)
end
totalCPUtime=totalCPUtime-1;
end

Réponses (1)

Walter Roberson
Walter Roberson le 7 Avr 2012
TotalCPUtime needs to be recomputed as sum(CPUtime). Your "for i" loop can end up decrementing more than one CPUtime entry, so your total does not get decremented by exactly 1 under most circumstances.
  2 commentaires
Ayda
Ayda le 8 Avr 2012
why should the tolalCPUtime recomputed
Walter Roberson
Walter Roberson le 8 Avr 2012
Your present code initializes totalCPUtime as the sum of the CPUtime . You then change what could be several of the CPUtime (all the non-zero ones), but your code only decreases totalCPUtime by 1 rather than by 1 per CPUtime that was decreased.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by