Borrar filtros
Borrar filtros

round robin

1 visualización (últimos 30 días)
Ayda
Ayda el 7 de Abr. de 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

Respuestas (1)

Walter Roberson
Walter Roberson el 7 de Abr. de 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 comentarios
Ayda
Ayda el 8 de Abr. de 2012
why should the tolalCPUtime recomputed
Walter Roberson
Walter Roberson el 8 de Abr. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by