Team Ai
Datasetpublic

hschumann2/TempleOS-Source-Code

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes847downloads
MPAdd.txt87 linesDownload Raw Back to MultiCore
1 2I64 mp_n;3 4I64 MPSum(I64 my_mp_cnt)5{//We could use the formula n*(n+1)/26  I64 lo=mp_n*Gs->num/my_mp_cnt,7        hi=mp_n*(Gs->num+1)/my_mp_cnt,8        res=0,i;9  for (i=lo;i<hi;i++)10    res+=i;11  return res;12}13 14I64 Sum(I64 n,I64 my_mp_cnt)15{16  CJob *tmpm[MP_PROCESSORS_NUM];17  I64 res=0,i;18  mp_n=n+1;19  for (i=0;i<my_mp_cnt;i++)20    tmpm[i]=JobQue(&MPSum,my_mp_cnt,i,0);21  for (i=0;i<my_mp_cnt;i++)22    res+=JobResGet(tmpm[i]);23  return res;24}25 26#define SAMPLE_SIZE 10027 28F64 Test(I64 n,I64 my_mp_cnt)29{30  I64 i,val=0;31  F64 start,end;32  start=tS;33  for (i=0;i<SAMPLE_SIZE;i++)34    val+=Sum(n,my_mp_cnt);35  end=tS;36  "Val:%,d\n",val/SAMPLE_SIZE;37  "$RED$N:%12,d Time:%10.8f$FG$\n",n,(end-start)/SAMPLE_SIZE;38  return end-start;39}40 41#define VAL_MIN         100042#define TEST_MIN        343#define TEST_MAX        744#define TESTS_NUM       (TEST_MAX-TEST_MIN+1)45#define PERCENT_MAX     20046 47U0 MPAdd()48{49  I64 i,n,50        h=Fs->pix_width,51        v=Fs->pix_height;52  F64 t1,t2,ress[TESTS_NUM];53  CDC *dc=DCAlias;54 55  for (i=0,n=VAL_MIN;i<TESTS_NUM;i++,n*=10) {56    t1=Test(n,1);57    t2=Test(n,mp_cnt);58    ress[i]=t2*100.0/t1;59    "$GREEN$%8.4f%%$FG$\n\n",ress[i];60  }61  PressAKey;62 63  DocClear;64 65  dc->color=BLUE;66  for (i=PERCENT_MAX/10;i<PERCENT_MAX;i+=PERCENT_MAX/10) {67    GrPrint(dc,0,v-ToF64(i)/PERCENT_MAX*v-FONT_HEIGHT,"%3d%%",i);68    GrLine(dc,0,v-ToF64(i)/PERCENT_MAX*v,h,v-ToF64(i)/PERCENT_MAX*v);69  }70 71  for (i=0;i<TESTS_NUM-1;i++) {72    dc->color=RED;73    dc->thick=2;74    GrLine3(dc,i*h/(TESTS_NUM-1),      v-ress[i  ]/PERCENT_MAX*v,0,75          (i+1)*h/(TESTS_NUM-1),v-ress[i+1]/PERCENT_MAX*v,0);76    dc->color=GREEN;77    GrPrint(dc,i*h/(TESTS_NUM-1),v-FONT_HEIGHT,"10e%d",i+TEST_MIN);78    GrLine(dc,i*h/(TESTS_NUM-1),0,i*h/(TESTS_NUM-1),v);79  }80  PressAKey;81 82  DCFill;83  DCDel(dc);84}85 86MPAdd;87