2020-02-20 23:40:10 +00:00
|
|
|
#define NUM 100
|
2020-02-15 20:01:48 +00:00
|
|
|
|
|
|
|
I64 mp_not_done_flags,grand_total;
|
|
|
|
|
|
|
|
U0 MPRoutine(CDoc *doc)
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
I64 i,sum=0,
|
|
|
|
lo=NUM*Gs->num/mp_count, //This is how to divide a job
|
|
|
|
hi=NUM*(Gs->num+1)/mp_count;
|
|
|
|
for (i=lo;i<hi;i++)
|
|
|
|
sum+=i;
|
|
|
|
DocPrint(doc,"Core#%d:%d-%d:%d\n",Gs->num,lo,hi-1,sum);
|
|
|
|
lock {grand_total+=sum;}
|
|
|
|
LBtr(&mp_not_done_flags,Gs->num);
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U0 Main()
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
I64 i;
|
|
|
|
grand_total=0;
|
|
|
|
mp_not_done_flags=1<<mp_count-1;
|
|
|
|
for (i=0;i<mp_count;i++)
|
|
|
|
Spawn(&MPRoutine,DocPut,NULL,i);
|
|
|
|
while (mp_not_done_flags)
|
|
|
|
Yield;
|
|
|
|
"Grand total:%d\n",grand_total;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Main;
|