TempleOSTS_130315.ISO
This commit is contained in:
1 parent
e57428affb
commit
17b71f1a2d
958 files changed
+26043
-15907
No files matched your search
@@ -0,0 +1,76 @@
|
||||
U8 *master_bitmap;
|
||||
I64 prime_range,my_mp_cnt,pending;
|
||||
|
||||
U0 PrimesJob(I64 i)
|
||||
{
|
||||
I64 j,k,l=Sqrt(prime_range),
|
||||
lo=i*prime_range/my_mp_cnt,
|
||||
hi=(i+1)*prime_range/my_mp_cnt,
|
||||
lo2=lo+sys_cache_line_width,
|
||||
hi2=hi-sys_cache_line_width;
|
||||
if (lo2>hi2) lo2=hi2;
|
||||
for (j=2;j<=l;j++) {
|
||||
if (!Bt(master_bitmap,j)) {
|
||||
if (j>=lo)
|
||||
k=j+j;
|
||||
else {
|
||||
k=lo-lo%j;
|
||||
if (k<lo)
|
||||
k+=j;
|
||||
}
|
||||
while (k<lo2) {
|
||||
LBts(master_bitmap,k);
|
||||
k+=j;
|
||||
}
|
||||
while (k<hi2) {
|
||||
Bts(master_bitmap,k);
|
||||
k+=j;
|
||||
}
|
||||
while (k<hi) {
|
||||
LBts(master_bitmap,k);
|
||||
k+=j;
|
||||
}
|
||||
}
|
||||
}
|
||||
lock pending--;
|
||||
}
|
||||
|
||||
I64 Primes(I64 range,I64 _my_mp_cnt)
|
||||
{
|
||||
I64 i,prime_cnt=0;
|
||||
F64 t0=tT,tf;
|
||||
prime_range=range;
|
||||
if (_my_mp_cnt<=mp_cnt)
|
||||
my_mp_cnt=_my_mp_cnt;
|
||||
else
|
||||
my_mp_cnt=mp_cnt;
|
||||
master_bitmap=CAlloc((prime_range+7)/8+1);
|
||||
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);
|
||||
while (pending)
|
||||
Yield;
|
||||
tf=tT;
|
||||
|
||||
for (i=0;i<prime_range;i++)
|
||||
if (!Bt(master_bitmap,i))
|
||||
prime_cnt++;
|
||||
|
||||
for (i=MaxI64(prime_range-100,0);i<prime_range;i++)
|
||||
if (!Bt(master_bitmap,i))
|
||||
"%d ",i;
|
||||
|
||||
"\n$$FG,RED$$CPUs:%d PrimeRange:%,d PrimeCnt:%,d Time:%9.6,f$$FG$$\n",
|
||||
my_mp_cnt,prime_range,prime_cnt,tf-t0;
|
||||
|
||||
Free(master_bitmap);
|
||||
return prime_cnt;
|
||||
}
|
||||
|
||||
Primes(100,1);
|
||||
Primes(100,mp_cnt);
|
||||
Primes(1000000,1);
|
||||
Primes(1000000,mp_cnt);
|
||||
Reference in new issue
Block a user