It is easy to schedule task on uniprocessor but what we do if we want to schedule task on multiprocessors with several sheduling criteria.
What I have tried:
int
main(int argc, char **argv)
{
FILE *fp = 0;
int size = 0;
int cpus = 0;
int iter = 0;
int *a = 0;
int *b = 0;
int *c = 0;
int bsize = 0;
int csize = 0;
int count = 0;
int sum = 0;
work *j = 0;
if(argc != 2) {
fprintf(stderr, "syntax:: r input_file\n");
return 1;
}
fp = fopen(argv[1], "r");
if(!fp) {
fprintf(stderr, "error opening file [%s]\n", argv[1]);
return 1;
}
fscanf(fp, "%d", &size);
fscanf(fp, "%d", &cpus);
if(!size || size < 0) {
fprintf(stderr, "invalid size [%d]\n", size);
fclose(fp);
return 1;
}
if(!cpus || cpus < 0) {
fprintf(stderr, "invalid cpus [%d]\n", cpus);
fclose(fp);
return 1;
}
fprintf(stdout, " size [%d] cpus [%d]\n", size, cpus);
a = (int *)calloc(1, size * sizeof(int));
for(int i = 0; i < size; ++i) {
fscanf(fp, "%d", &a[i]);
}
iter = _log2(cpus);
if(iter == -1 || exp2(iter) != cpus) {
fprintf(stderr, "invalid cpus not power of two cpus [%d] iter [%d]", cpus, iter);
fclose(fp);
return 1;
}
fprintf(stdout, " log2 [%d]\n", iter);
work_q .push(new work(a, size, 0));
for(int i = 0; i < iter; ++i) {
j = work_q.front();
if(!j) {
break;
}
while(j && j->pass == i) {
work_q.pop();
p(j->a,j->size,&b,&bsize,&c,&csize);
if(bsize)
work_q.push(new work(b,bsize,j->pass+1));
if(csize)
work_q.push(new work(c,csize,j->pass+1));
free((void *)j->a);
delete j;
j = work_q.front();
}
}
fprintf(stdout, " queue size [%d]\n", work_q.size());
size = work_q.size();
for(count = 0; count < size; ++count) {
printf("cpu = [%d]\n",count);
j = work_q.front();
sum = 0;
printf(" len = [%d] { ", j->size);
for(int k = 0; k < j->size; ++k) {
printf("%d ", j->a[k]);
sum += j->a[k];
}
printf("} \n");
printf(" sum = [%d]\n", sum);
free((void *)j->a);
delete j;
work_q.pop();
}
fclose(fp);
return 0;
}