TempleOSTS_130707.ISO
This commit is contained in:
1 parent
17b71f1a2d
commit
1343005a29
617 files changed
+14399
-25130
No files matched your search
@@ -1,5 +1,22 @@
|
||||
//This uses $LK,"fixed-point","FI:::/TempleOS/Demo/Lectures/FixedPoint.CPP"$.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$SP+BP,"<1>",1,"::/TempleOS/Demo/Graphics/Camp.CPP.Z,6"$ //Pointer to sprite <6> in Camp.CPP.Z file
|
||||
|
||||
#define NUM_CLOUDS 16
|
||||
#define SKY_LINES 30
|
||||
#define CLOUD_PTS 512
|
||||
@@ -22,11 +39,11 @@ class CloudPen
|
||||
|
||||
CDC *cloud_pen;
|
||||
|
||||
I64 mp_done_flags;
|
||||
I64 mp_not_done_flags;
|
||||
U0 MPDrawClouds(CTask *task)
|
||||
{
|
||||
Cloud *c;
|
||||
CDC *dc=DCAlias(gr_dc,task);
|
||||
CDC *dc=DCAlias(gr_dc2,task);
|
||||
I64 i,j,k,xx,yy,
|
||||
lo= Gs->num *CLOUD_PTS/mp_cnt,
|
||||
hi=(Gs->num+1)*CLOUD_PTS/mp_cnt;
|
||||
@@ -54,17 +71,17 @@ U0 MPDrawClouds(CTask *task)
|
||||
GrBlot(dc,xx,yy,cloud_pens[i&(CLOUD_PENS-1)].img);
|
||||
}
|
||||
DCDel(dc);
|
||||
LBts(&mp_done_flags,Gs->num);
|
||||
LBtr(&mp_not_done_flags,Gs->num);
|
||||
}
|
||||
|
||||
U0 DrawIt(CTask *task,CDC *)
|
||||
U0 DrawIt(CTask *task,CDC *dc)
|
||||
{
|
||||
I64 i;
|
||||
mp_done_flags=0;
|
||||
for (i=1;i<mp_cnt;i++)
|
||||
MPJob(&MPDrawClouds,task,i);
|
||||
MPDrawClouds(task);
|
||||
while (mp_done_flags!=1<<mp_cnt-1)
|
||||
SpritePlot3(dc,0,SKY_LINES*FONT_HEIGHT,0,$IB,"<1>",1$);
|
||||
mp_not_done_flags=1<<mp_cnt-1;
|
||||
for (i=0;i<mp_cnt;i++)
|
||||
JobQue(&MPDrawClouds,task,i);
|
||||
while (mp_not_done_flags)
|
||||
Yield;
|
||||
}
|
||||
|
||||
@@ -152,10 +169,10 @@ U0 SongTask(I64)
|
||||
Fs->task_end_cb=&SndTaskEndCB;
|
||||
MusicSettingsRst;
|
||||
while (TRUE) {
|
||||
Play("W13qBetDA2G3qD2sG!3E2G!3EetCEDqFEeDC");
|
||||
Play("qBetDA2G3qD2sG!3E2G!3EetCEDqFEeDC");
|
||||
Play("C!GqDeADsDCDCqGEetDAD!2sG3D2G!!3D");
|
||||
Play("eC!GqDeADsDCDCqGEetDAD!2sG3D2G!!3D");
|
||||
Play("3qBetDA2G3qD2sG3E2G3EetCEDqFEeDC");
|
||||
Play("qBetDA2G3qD2sG3E2G3EetCEDqFEeDC");
|
||||
Play("CGqDeADsDCDCqGEetDAD2sG3D2G3D");
|
||||
Play("eCGqDeADsDCDCqGEetDAD2sG3D2G3D");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,24 +180,24 @@ U0 CloudScene()
|
||||
{
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
try {
|
||||
Fs->song_task=Spawn(&SongTask,NULL,"Song",Fs);
|
||||
Fs->text_attr=YELLOW<<4+BLUE;
|
||||
Fs->song_task=Spawn(&SongTask,NULL,"Song",,Fs);
|
||||
DocCursor;
|
||||
WinMax;
|
||||
WinBorder;
|
||||
WordStat;
|
||||
Init;
|
||||
Fs->animate_task=Spawn(&AnimateTask,NULL,"Animate",Fs);
|
||||
Fs->animate_task=Spawn(&AnimateTask,NULL,"Animate",,Fs);
|
||||
|
||||
"$$CL$$$$BG,LTCYAN$$"; NewLine(SKY_LINES);
|
||||
"$$BG,YELLOW$$";
|
||||
NewLine(5);
|
||||
DocClear;
|
||||
"$$BG,LTCYAN$$"; NewLine(SKY_LINES);
|
||||
"$$BG,YELLOW$$"; NewLine(5);
|
||||
PutBibleVerse("Exodus,14:19",7);
|
||||
|
||||
Preempt(OFF);
|
||||
Fs->draw_it=&DrawIt;
|
||||
GetChar;
|
||||
WinMgrSync;
|
||||
|
||||
"$$BG$$\n";
|
||||
} catch
|
||||
CatchAll;
|
||||
SettingsPop;
|
||||
|
||||
Binary file not shown.
@@ -1,83 +0,0 @@
|
||||
class MPCtrl
|
||||
{
|
||||
CTask *win_task;
|
||||
I64 i;
|
||||
Bool app_done,app_done_ack;
|
||||
Bool refresh_start,refresh_done;
|
||||
} mp;
|
||||
|
||||
|
||||
U0 DrawIt(CTask *,CDC *dc)
|
||||
{
|
||||
I64 i;
|
||||
F64 t0=tT,t1;
|
||||
|
||||
mp.refresh_done=FALSE;
|
||||
mp.refresh_start=TRUE;
|
||||
mp.i++;
|
||||
|
||||
for (i=0;i<32;i++) {
|
||||
t1=t0+i*2*ã/64;
|
||||
dc->color=(mp.i+i)/10&15;
|
||||
GrEllipse(dc,GR_WIDTH/2,GR_HEIGHT/2,
|
||||
GR_WIDTH/4*(Sin(t1)+1.0),GR_HEIGHT/4*(Sin(t1)+1.0),t1*2.0);
|
||||
}
|
||||
while (!mp.refresh_done)
|
||||
Yield;
|
||||
}
|
||||
|
||||
U0 MPDrawIt()
|
||||
{
|
||||
I64 i;
|
||||
F64 t0=tT,t1;
|
||||
CDC *dc=DCAlias;
|
||||
dc->win_task=mp.win_task;
|
||||
|
||||
while (!mp.refresh_start && !mp.app_done)
|
||||
Yield;
|
||||
if (mp.app_done)
|
||||
goto mp_done;
|
||||
mp.refresh_start=FALSE;
|
||||
DCFill;
|
||||
for (i=32;i<64;i++) {
|
||||
t1=t0+i*2*ã/64;
|
||||
dc->color=(mp.i+i)/10&15;
|
||||
GrEllipse(dc,GR_WIDTH/2,GR_HEIGHT/2,
|
||||
GR_WIDTH/4*(Sin(t1)+1.0),GR_HEIGHT/4*(Sin(t1)+1.0),t1*2.0);
|
||||
}
|
||||
mp_done:
|
||||
DCDel(dc);
|
||||
mp.refresh_done=TRUE;
|
||||
}
|
||||
|
||||
U0 MPTask(I64)
|
||||
{
|
||||
while (!mp.app_done)
|
||||
MPDrawIt;
|
||||
mp.app_done_ack=TRUE;
|
||||
DCFill;
|
||||
}
|
||||
|
||||
|
||||
U0 LayersSpawn()
|
||||
{
|
||||
if (mp_cnt<2) throw(EXCEPT_MULTICORE);
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
WinMax;
|
||||
DocClear;
|
||||
Fs->draw_it=&DrawIt;
|
||||
WinBorder;
|
||||
|
||||
mp.i=0;
|
||||
mp.app_done=FALSE;
|
||||
mp.win_task=Fs;
|
||||
MPSpawn(&MPTask);
|
||||
GetChar;
|
||||
mp.app_done=TRUE;
|
||||
while (!mp.app_done_ack)
|
||||
Yield;
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
LayersSpawn;
|
||||
@@ -1,56 +1,53 @@
|
||||
I64 load_test_done;
|
||||
Bool app_done;
|
||||
I64 app_done_ack;
|
||||
|
||||
U0 Job1(I64)
|
||||
{ //Compile Compiler
|
||||
TaskInitExt; //Enable file access
|
||||
Preempt(ON); //Off by default
|
||||
Silent(ON);
|
||||
while (!load_test_done) {
|
||||
while (!app_done) {
|
||||
Cd("::/TempleOS/Compiler");
|
||||
Cmp("Compiler");
|
||||
}
|
||||
lock {load_test_done--;}
|
||||
lock {app_done_ack--;}
|
||||
}
|
||||
|
||||
U0 Job2(I64)
|
||||
{ //Log a file
|
||||
TaskInitExt; //Enable file access
|
||||
Preempt(ON); //Off by default
|
||||
while (!load_test_done) {
|
||||
while (!app_done) {
|
||||
AdamLog("%F","::/TempleOS/Demo/MultiCore/LoadTest.CPP");
|
||||
Yield;
|
||||
}
|
||||
lock {load_test_done--;}
|
||||
lock {app_done_ack--;}
|
||||
}
|
||||
|
||||
U0 Job3(I64)
|
||||
{ //Log a file
|
||||
TaskInitExt; //Enable file access
|
||||
Preempt(ON); //Off by default
|
||||
while (!load_test_done) {
|
||||
while (!app_done) {
|
||||
Cd("::/TempleOS/Compiler");
|
||||
AdamLog("%F","Compiler.PRJ.Z");
|
||||
Yield;
|
||||
}
|
||||
lock {load_test_done--;}
|
||||
lock {app_done_ack--;}
|
||||
}
|
||||
|
||||
U0 Main()
|
||||
{
|
||||
load_test_done=0;
|
||||
app_done=FALSE;
|
||||
"Running MultiCore Test...\n";
|
||||
MPSpawn(&Job1);
|
||||
MPSpawn(&Job2);
|
||||
MPSpawn(&Job1);
|
||||
MPSpawn(&Job3);
|
||||
Spawn(&Job1);
|
||||
Spawn(&Job2);
|
||||
Spawn(&Job1);
|
||||
Spawn(&Job3);
|
||||
Spawn(&Job1,,,1); //core #1
|
||||
Spawn(&Job2,,,1);
|
||||
Spawn(&Job3,,,1);
|
||||
PressAKey;
|
||||
load_test_done=8;
|
||||
//We don't want to yank code from under MP cores.
|
||||
while (load_test_done)
|
||||
app_done_ack=3;
|
||||
app_done=TRUE;
|
||||
while (app_done_ack)
|
||||
Yield;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,15 +22,12 @@ U0 MPUnlockedInc(I64)
|
||||
|
||||
U0 UnlockedInc()
|
||||
{
|
||||
I64 i;
|
||||
CMPCmd *tempm;
|
||||
CSrvCmd *tempm0,*tempm1;
|
||||
glbl=0;
|
||||
|
||||
tempm=MPJob(&MPUnlockedInc,NULL,1,0);
|
||||
for (i=0;i<CNT;i++)
|
||||
glbl++;
|
||||
|
||||
MPJobResult(tempm);
|
||||
tempm0=JobQue(&MPUnlockedInc,NULL,0,0);
|
||||
tempm1=JobQue(&MPUnlockedInc,NULL,1,0);
|
||||
GetResult(tempm0);
|
||||
GetResult(tempm1);
|
||||
"Correct Cnt:%X Actual Cnt:%X\n",CNT*2,glbl;
|
||||
}
|
||||
|
||||
@@ -46,17 +43,12 @@ U0 MPLockedInc(I64)
|
||||
|
||||
U0 LockedInc()
|
||||
{
|
||||
I64 i;
|
||||
CMPCmd *tempm;
|
||||
CSrvCmd *tempm0,*tempm1;
|
||||
glbl=0;
|
||||
|
||||
tempm=MPJob(&MPLockedInc,NULL,1,0);
|
||||
for (i=0;i<CNT;i++)
|
||||
lock {
|
||||
glbl++;
|
||||
}
|
||||
|
||||
MPJobResult(tempm);
|
||||
tempm0=JobQue(&MPLockedInc,NULL,0,0);
|
||||
tempm1=JobQue(&MPLockedInc,NULL,1,0);
|
||||
GetResult(tempm0);
|
||||
GetResult(tempm1);
|
||||
"Correct Cnt:%X Actual Cnt:%X\n",CNT*2,glbl;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,14 +12,13 @@ I64 MPSum(I64 my_mp_cnt)
|
||||
|
||||
I64 Sum(I64 n,I64 my_mp_cnt)
|
||||
{
|
||||
CMPCmd *tempm[MP_MAX_PROCESSORS];
|
||||
CSrvCmd *tempm[MP_MAX_PROCESSORS];
|
||||
I64 result=0,i;
|
||||
mp_n=n+1;
|
||||
for (i=1;i<my_mp_cnt;i++)
|
||||
tempm[i]=MPJob(&MPSum,my_mp_cnt,i,0);
|
||||
result=MPSum(my_mp_cnt);
|
||||
for (i=1;i<my_mp_cnt;i++)
|
||||
result+=MPJobResult(tempm[i]);
|
||||
for (i=0;i<my_mp_cnt;i++)
|
||||
tempm[i]=JobQue(&MPSum,my_mp_cnt,i,0);
|
||||
for (i=0;i<my_mp_cnt;i++)
|
||||
result+=GetResult(tempm[i]);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -39,7 +38,10 @@ F64 Test(I64 n,I64 my_mp_cnt)
|
||||
return end-start;
|
||||
}
|
||||
|
||||
#define NUM_TESTS 7
|
||||
#define MIN_VAL 1000
|
||||
#define MIN_TEST 3
|
||||
#define MAX_TEST 7
|
||||
#define NUM_TESTS (MAX_TEST-MIN_TEST+1)
|
||||
#define MAX_PERCENT 200
|
||||
|
||||
U0 MPAdd()
|
||||
@@ -50,7 +52,7 @@ U0 MPAdd()
|
||||
F64 t1,t2,results[NUM_TESTS];
|
||||
CDC *dc=DCAlias;
|
||||
|
||||
for (i=0,n=10;i<NUM_TESTS;i++,n*=10) {
|
||||
for (i=0,n=MIN_VAL;i<NUM_TESTS;i++,n*=10) {
|
||||
t1=Test(n,1);
|
||||
t2=Test(n,mp_cnt);
|
||||
results[i]=t2*100.0/t1;
|
||||
@@ -61,7 +63,7 @@ U0 MPAdd()
|
||||
DocClear;
|
||||
|
||||
dc->color=BLUE;
|
||||
for (i=0;i<MAX_PERCENT;i+=MAX_PERCENT/10) {
|
||||
for (i=MAX_PERCENT/10;i<MAX_PERCENT;i+=MAX_PERCENT/10) {
|
||||
GrPrintF(dc,0,v-ToF64(i)/MAX_PERCENT*v-FONT_HEIGHT,"%3d%%",i);
|
||||
GrLine(dc,0,v-ToF64(i)/MAX_PERCENT*v,h,v-ToF64(i)/MAX_PERCENT*v);
|
||||
}
|
||||
@@ -72,9 +74,8 @@ U0 MPAdd()
|
||||
GrLine3(dc,i*h/(NUM_TESTS-1), v-results[i ]/MAX_PERCENT*v,0,
|
||||
(i+1)*h/(NUM_TESTS-1),v-results[i+1]/MAX_PERCENT*v,0);
|
||||
dc->color=GREEN;
|
||||
GrPrintF(dc,i*h/(NUM_TESTS-1),v-FONT_HEIGHT,"10e%d",i+1);
|
||||
GrLine(dc,i*h/(NUM_TESTS-1),0,
|
||||
i*h/(NUM_TESTS-1),v);
|
||||
GrPrintF(dc,i*h/(NUM_TESTS-1),v-FONT_HEIGHT,"10e%d",i+MIN_TEST);
|
||||
GrLine(dc,i*h/(NUM_TESTS-1),0,i*h/(NUM_TESTS-1),v);
|
||||
}
|
||||
PressAKey;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
U0 Job(CDoc *doc)
|
||||
{
|
||||
I64 i;
|
||||
for (i=0;i<10;i++)
|
||||
for (i=0;i<2;i++)
|
||||
DocPrintF(doc,"$$FG,%d$$CPU%d ",Gs->num,Gs->num);
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ U0 Job(CDoc *doc)
|
||||
U0 MPPrintFDemo()
|
||||
{
|
||||
I64 i;
|
||||
for (i=0;i<1000;i++)
|
||||
MPJob(&Job,DocCur,1+i%(mp_cnt-1));
|
||||
Sleep(1000);
|
||||
for (i=0;i<500;i++)
|
||||
JobQue(&Job,DocPut,i%mp_cnt);
|
||||
Sleep(500);
|
||||
"$$FG$$\n";
|
||||
}
|
||||
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
Bool noise_done;
|
||||
I64 done_ack;
|
||||
I64 cnt;
|
||||
|
||||
U0 DrawNoise(CTask *task)
|
||||
{
|
||||
I64 i,
|
||||
h=task->win_pixel_width,
|
||||
v=task->win_pixel_height;
|
||||
CDC *dc=DCAlias(gr_dc2,task);
|
||||
for (i=0;i<cnt;i++) {
|
||||
dc->color=RandU16&15;
|
||||
GrPlot(dc,RandU16%h,RandU16%v);
|
||||
}
|
||||
dc->color=WHITE;
|
||||
GrRect(dc,0,Gs->num*FONT_HEIGHT,12*FONT_WIDTH,FONT_HEIGHT);
|
||||
dc->color=BLACK;
|
||||
GrPrintF(dc,0,Gs->num*FONT_HEIGHT,"Cnt:%08X",cnt);
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
U0 MPTask(CTask *task)
|
||||
{
|
||||
while (!noise_done) {
|
||||
DrawNoise(task);
|
||||
WinMgrSync;
|
||||
}
|
||||
LBts(&done_ack,Gs->num);
|
||||
}
|
||||
|
||||
U0 NoiseDemo()
|
||||
{
|
||||
I64 i;
|
||||
F64 t0;
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
WinMax;
|
||||
WordStat;
|
||||
cnt=0x1000;
|
||||
|
||||
noise_done=FALSE;
|
||||
for (i=1;i<mp_cnt;i++)
|
||||
MPSpawn(&MPTask,Fs,"Job",i);
|
||||
|
||||
while (!ScanChar) {
|
||||
t0=tT;
|
||||
DrawNoise(Fs);
|
||||
if (tT-t0>1.0/80.0)
|
||||
cnt-=0x100;
|
||||
else
|
||||
cnt+=0x100;
|
||||
WinMgrSync;
|
||||
}
|
||||
|
||||
done_ack=1;
|
||||
noise_done=TRUE;
|
||||
while (done_ack!=1<<mp_cnt-1)
|
||||
Yield;
|
||||
|
||||
DCFill;
|
||||
SettingsPop;
|
||||
}
|
||||
|
||||
NoiseDemo;
|
||||
@@ -1,7 +1,7 @@
|
||||
#define BORDER_CHARS 1
|
||||
|
||||
U8 *buf;
|
||||
I64 size,mp_done_flags;
|
||||
I64 size,mp_not_done_flags;
|
||||
CDoc *doc;
|
||||
|
||||
U0 PDNormalize()
|
||||
@@ -72,7 +72,7 @@ U0 MPPalindrome(I64 dummy=0)
|
||||
|
||||
src++;
|
||||
}
|
||||
LBts(&mp_done_flags,Gs->num);
|
||||
LBtr(&mp_not_done_flags,Gs->num);
|
||||
}
|
||||
|
||||
U0 Palindrome(U8 *filename)
|
||||
@@ -83,12 +83,11 @@ U0 Palindrome(U8 *filename)
|
||||
buf=FileRead(filename,&size);
|
||||
PDNormalize;
|
||||
|
||||
doc=DocCur;
|
||||
mp_done_flags=0;
|
||||
for (i=1;i<mp_cnt;i++)
|
||||
MPJob(&MPPalindrome,NULL,i);
|
||||
MPPalindrome;
|
||||
while (mp_done_flags!=1<<mp_cnt-1)
|
||||
doc=DocPut;
|
||||
mp_not_done_flags=1<<mp_cnt-1;
|
||||
for (i=0;i<mp_cnt;i++)
|
||||
JobQue(&MPPalindrome,NULL,i);
|
||||
while (mp_not_done_flags)
|
||||
Yield;
|
||||
|
||||
Free(buf);
|
||||
|
||||
@@ -48,9 +48,8 @@ I64 Primes(I64 range,I64 _my_mp_cnt)
|
||||
Bts(master_bitmap,0);
|
||||
Bts(master_bitmap,1);
|
||||
pending=my_mp_cnt;
|
||||
for (i=1;i<my_mp_cnt;i++)
|
||||
MPJob(&PrimesJob,i,i);
|
||||
PrimesJob(0);
|
||||
for (i=0;i<my_mp_cnt;i++)
|
||||
JobQue(&PrimesJob,i,i);
|
||||
while (pending)
|
||||
Yield;
|
||||
tf=tT;
|
||||
|
||||
@@ -4,7 +4,7 @@ I64 my_mp_cnt=1<<Bsr(mp_cnt);//Power of 2
|
||||
|
||||
I32 *a1,*a2;
|
||||
I32 *b[my_mp_cnt],bn[my_mp_cnt];
|
||||
I64 mp_done_flags;
|
||||
I64 mp_not_done_flags;
|
||||
|
||||
I64 Compare(I32 *e1,I32 *e2)
|
||||
{
|
||||
@@ -61,7 +61,7 @@ U0 MPSort(I64 dummy=0)
|
||||
{
|
||||
nounusedwarn dummy;
|
||||
QSortU32(b[Gs->num],bn[Gs->num]);
|
||||
LBts(&mp_done_flags,Gs->num);
|
||||
LBtr(&mp_not_done_flags,Gs->num);
|
||||
}
|
||||
|
||||
U0 MPRadixSortDemo(I64 dummy=0)
|
||||
@@ -109,11 +109,10 @@ U0 MPRadixSortDemo(I64 dummy=0)
|
||||
j=a1[i]>>k1+k2; //This is a preliminary radix sort.
|
||||
b[j][bn[j]++]=a1[i];
|
||||
}
|
||||
mp_done_flags=0;
|
||||
for (i=1;i<my_mp_cnt;i++)
|
||||
MPSpawn(&MPSort,NULL,NULL,i);
|
||||
MPSort;
|
||||
while (mp_done_flags!=1<<my_mp_cnt-1)
|
||||
mp_not_done_flags=1<<my_mp_cnt-1;
|
||||
for (i=0;i<my_mp_cnt;i++)
|
||||
Spawn(&MPSort,NULL,NULL,i);
|
||||
while (mp_not_done_flags)
|
||||
Yield;
|
||||
j=0;
|
||||
for (i=0;i<my_mp_cnt;i++) {
|
||||
@@ -131,8 +130,8 @@ U0 MPRadixSortDemo(I64 dummy=0)
|
||||
|
||||
MPRadixSortDemo;
|
||||
|
||||
/*$HL,0$ Results on $FG$$BG$8 Cores 2.660GHz Core i7:
|
||||
$FG$$BG$$FG,2$QSort$FG$
|
||||
/*$HL,0$ Results on 8 Cores 2.660GHz Core i7:
|
||||
$FG,2$QSort$FG$
|
||||
Time: 1.535474
|
||||
00000000 EA 1D F6 BF 16 2E F6 BF 0B 3C F6 BF CD 44 F6 BF ê.ö¿..ö¿.<ö¿ÍDö¿
|
||||
00000010 B1 45 F6 BF 52 4A F6 BF 96 71 F6 BF 9F 78 F6 BF ±Eö¿RJö¿–qö¿Ÿxö¿
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
class MPCtrl
|
||||
{
|
||||
Bool done[MP_MAX_PROCESSORS];
|
||||
} mp;
|
||||
|
||||
I32 *a1=NULL, //This is the master copy of random nums
|
||||
//so we have the same nums for both tests.
|
||||
*a2=NULL, //This is the temp copy.
|
||||
*a3=NULL; //This is a merged final array for dual core example.
|
||||
|
||||
U0 Init(I64 n)
|
||||
{
|
||||
I64 i;
|
||||
Free(a1);
|
||||
a1=MAlloc(n*sizeof(I32));
|
||||
for (i=0;i<n;i++)
|
||||
a1[i]=RandI32;
|
||||
Free(a2);
|
||||
a2=MAlloc(n*sizeof(I32));
|
||||
Free(a3);
|
||||
a3=MAlloc(n*sizeof(I32));
|
||||
}
|
||||
|
||||
U0 CleanUp()
|
||||
{
|
||||
Free(a1);
|
||||
a1=NULL;
|
||||
Free(a2);
|
||||
a2=NULL;
|
||||
Free(a3);
|
||||
a3=NULL;
|
||||
}
|
||||
|
||||
U0 Output(I32 *a,I64 n)
|
||||
{
|
||||
I64 i;
|
||||
WinMax;
|
||||
for (i=0;i<n;i++) {
|
||||
"%08X ",a[i];
|
||||
if (i&7==3)
|
||||
NewLine;
|
||||
}
|
||||
NewLine;
|
||||
}
|
||||
|
||||
I64 IntCompare(I32 *i1,I32 *i2)
|
||||
{
|
||||
return *i1-*i2;
|
||||
}
|
||||
|
||||
F64 Sort1(I64 n)
|
||||
{
|
||||
F64 t0=tT;
|
||||
MemCpy(a2,a1,n*sizeof(I32));
|
||||
QSort(a2,n,sizeof(I32),&IntCompare);
|
||||
mp.done[Gs->num]=TRUE;
|
||||
return tT-t0;
|
||||
}
|
||||
|
||||
F64 Sort2(I64 n)
|
||||
{
|
||||
I64 i1=0,i2=n/2,i3=0;
|
||||
F64 t0=tT;
|
||||
MemSet(&mp,0,sizeof(MPCtrl));
|
||||
MemCpy(&a2[n/2],&a1[n/2],n/2*sizeof(I32));
|
||||
MPJob(&Sort1,n/2,1);
|
||||
QSort(&a2[n/2],n/2,sizeof(I32),&IntCompare);
|
||||
while (!mp.done[1])
|
||||
Yield;
|
||||
while (i3<n) {
|
||||
if (i2==n)
|
||||
while (i3<n)
|
||||
a3[i3++]=a2[i1++];
|
||||
else
|
||||
while (i3<n && i1<n/2 && a2[i1]<=a2[i2])
|
||||
a3[i3++]=a2[i1++];
|
||||
if (i1==n/2)
|
||||
while (i3<n)
|
||||
a3[i3++]=a2[i2++];
|
||||
else
|
||||
while (i3<n && i2<n && a2[i2]<=a2[i1])
|
||||
a3[i3++]=a2[i2++];
|
||||
}
|
||||
return tT-t0;
|
||||
}
|
||||
|
||||
#define SAMPLES 8
|
||||
|
||||
U0 CompareSorts(I64 n)
|
||||
{
|
||||
I64 i;
|
||||
F64 t1=0,t2=0;
|
||||
for (i=0;i<SAMPLES;i++) {
|
||||
//The times depend heavily on the random num arrays
|
||||
//so run multiple times, to get an average.
|
||||
Init(n);
|
||||
|
||||
t1+=Sort1(n);
|
||||
// Output(a2,n);
|
||||
|
||||
t2+=Sort2(n);
|
||||
// Output(a3,n);
|
||||
}
|
||||
CleanUp;
|
||||
"Array N:%08X Timings Sampled:%d\n",n,SAMPLES;
|
||||
"Single Core Average Time:%9.5fs\n",t1/SAMPLES;
|
||||
"Dual Core Average Time :%9.5fs\n",t2/SAMPLES;
|
||||
NewLine;
|
||||
}
|
||||
|
||||
CompareSorts(0x4000);
|
||||
CompareSorts(0x8000);
|
||||
CompareSorts(0x10000);
|
||||
Reference in new issue
Block a user