Skip to content
Snippets Groups Projects
Commit bd16168a authored by Syufan's avatar Syufan
Browse files

Update allocate.c

parent e76832a3
Branches
No related tags found
No related merge requests found
......@@ -140,8 +140,9 @@ int main(int argc, char *argv[]) {
// add all process
pickup_input(batch_list, input_list, simulated_time);
}
turnaround_time = round(turnaround_time/(num+1));
time_overhead = time_overhead/(num+1);
turnaround_time = ceil(turnaround_time/(num+1));
time_overhead = round((time_overhead / (num+1)) *100)/100;
max_time_overhead = round(max_time_overhead*100)/100;
printf("Turnaround time %0.f\nTime overhead %.2f %.2f \nMakespan %d\n",turnaround_time,max_time_overhead,time_overhead,simulated_time);
}
//================================TASK 1 END================================//
......@@ -231,7 +232,6 @@ int main(int argc, char *argv[]) {
printf("%d,%s,process_name=%s,remaining_time=%d \n",simulated_time,current->state,current->process_name,current->time_required);
current->time_required -= quantum;
}
}
if(current == ready_list->head && current == ready_list->foot){
// there are only one process
......@@ -245,9 +245,9 @@ int main(int argc, char *argv[]) {
simulated_time += quantum;
pickup_input(batch_list, ready_list, simulated_time);
}
printf("turnaround time = %f \n", num);
max_time_overhead = round(max_time_overhead*100)/100;
turnaround_time = ceil(turnaround_time/(num));
time_overhead = time_overhead/(num);
time_overhead = round((time_overhead / num) *100)/100;
printf("Turnaround time %0.f\nTime overhead %.2f %.2f \nMakespan %d\n",turnaround_time,max_time_overhead,time_overhead,simulated_time-quantum);
}
......@@ -402,8 +402,15 @@ int main(int argc, char *argv[]) {
if(strcmp(scheduler_algorithm,"SJF") == 0 && strcmp(memory_strategy,"best-fit") == 0){
// put all the process which arrive time <= simmulated time
pickup_input_task3(batch_list, input_list, simulated_time,memory_list);
double num = count_list(batch_list);
process_n* processing = NULL;
double turnaround_time = 0;
double end = 0;
double single = 0;
double time_overhead = 0;
double time_single = 0;
double max_time_overhead = 0;
while(input_list->head != NULL){
// pick up the shortest by time_required
processing = search_shortest_process(input_list);
......@@ -413,18 +420,34 @@ int main(int argc, char *argv[]) {
remaining_time = processing->time_required;
while(remaining_time > 0){
simulated_time+=quantum;
pickup_input_task3(batch_list, input_list, simulated_time,memory_list);
remaining_time-=quantum;
}
// calculate time
end = simulated_time;
single = end - processing->arrival_time;
turnaround_time += single;
time_single = single/processing->time_required;
if(max_time_overhead<time_single){
max_time_overhead = time_single;
}
time_overhead += time_single;
strcpy(processing->state, "FINISHED");
free_memory(memory_list,processing);
// move finished process from input list
move_node(input_list, processing);
// add all process except this cycle
pickup_input_task3(batch_list, input_list, simulated_time-quantum,memory_list);
//pickup_input(batch_list, input_list, simulated_time-quantum);
int proc_remaining = count_list(input_list);
printf("%d,%s,process_name=%s,proc_remaining=%d \n",simulated_time,processing->state,processing->process_name,proc_remaining);
// add all process
pickup_input_task3(batch_list, input_list, simulated_time,memory_list);
}
turnaround_time = ceil(turnaround_time/(num+1));
time_overhead = round((time_overhead / (num+1)) *100)/100;
max_time_overhead = round(max_time_overhead*100)/100;
printf("Turnaround time %0.f\nTime overhead %.2f %.2f \nMakespan %d\n",turnaround_time,max_time_overhead,time_overhead,simulated_time);
}
return 0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment