Révision 167 NBody/NBodyGL.py
| NBodyGL.py (revision 167) | ||
|---|---|---|
| 22 | 22 |
return(Marsaglia,Computing) |
| 23 | 23 |
|
| 24 | 24 |
|
| 25 |
|
|
| 26 |
Blob=""" |
|
| 27 |
__kernel void RungeKutta(__global MYFLOAT4* clDataX,__global MYFLOAT4* clDataV,MYFLOAT h) |
|
| 28 |
{
|
|
| 29 |
private int gid = get_global_id(0); |
|
| 30 |
private MYFLOAT8 clDataGid; |
|
| 31 |
|
|
| 32 |
clDataGid=AtomicRungeKutta(clDataX,clDataV,gid,h); |
|
| 33 |
barrier(CLK_GLOBAL_MEM_FENCE); |
|
| 34 |
clDataX[gid]=clDataGid.s0123; |
|
| 35 |
clDataV[gid]=clDataGid.s4567; |
|
| 36 |
} |
|
| 37 |
|
|
| 38 |
""" |
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 25 | 100 |
BlobOpenCL= """ |
| 101 |
#define TFP32 0 |
|
| 102 |
#define TFP64 1 |
|
| 103 |
|
|
| 26 | 104 |
#if TYPE == TFP32 |
| 27 | 105 |
#define MYFLOAT4 float4 |
| 28 | 106 |
#define MYFLOAT8 float8 |
| ... | ... | |
| 46 | 124 |
#define CONG (jcong=69069*jcong+1234567) |
| 47 | 125 |
#define KISS ((MWC^CONG)+SHR3) |
| 48 | 126 |
|
| 49 |
#define TFP32 0 |
|
| 50 |
#define TFP64 1 |
|
| 51 | 127 |
|
| 52 | 128 |
#define MWCfp (MYFLOAT)(MWC * 2.3283064365386963e-10f) |
| 53 | 129 |
#define KISSfp (MYFLOAT)(KISS * 2.3283064365386963e-10f) |
| ... | ... | |
| 77 | 153 |
MYFLOAT4 Interaction(MYFLOAT4 m,MYFLOAT4 n) |
| 78 | 154 |
{
|
| 79 | 155 |
private MYFLOAT r=MyDistance((MYFLOAT4)n,(MYFLOAT4)m); |
| 80 |
// private MYFLOAT r=DISTANCE(n,m); |
|
| 81 | 156 |
|
| 82 |
return((n-m)/(MYFLOAT)(r*r*r));
|
|
| 157 |
return(((MYFLOAT4)n-(MYFLOAT4)m)/(MYFLOAT)(r*r*r));
|
|
| 83 | 158 |
} |
| 84 | 159 |
|
| 85 | 160 |
MYFLOAT PairPotential(MYFLOAT4 m,MYFLOAT4 n) |
| 86 | 161 |
{
|
| 87 | 162 |
return((MYFLOAT)(-1.e0f)/(DISTANCE(n,m))); |
| 163 |
|
|
| 164 |
// return((MYFLOAT)(-1.e0f)/(MyDistance(n,m))); |
|
| 88 | 165 |
} |
| 89 | 166 |
|
| 90 | 167 |
MYFLOAT AtomicPotential(__global MYFLOAT4* clDataX,int gid) |
| ... | ... | |
| 170 | 247 |
MYFLOAT8 AtomicHeun(__global MYFLOAT4* clDataInX,__global MYFLOAT4* clDataInV,int gid,MYFLOAT dt) |
| 171 | 248 |
{
|
| 172 | 249 |
private MYFLOAT4 x0,v0,a0,x1,v1,a1,xf,vf; |
| 173 |
MYFLOAT4 DT=dt*(MYFLOAT4)(1.e0f,1.e0f,1.e0f,1.e0f);
|
|
| 250 |
MYFLOAT4 Dt=dt*(MYFLOAT4)(1.e0f,1.e0f,1.e0f,1.e0f);
|
|
| 174 | 251 |
|
| 175 | 252 |
x0=(MYFLOAT4)clDataInX[gid]; |
| 176 | 253 |
v0=(MYFLOAT4)clDataInV[gid]; |
| ... | ... | |
| 183 | 260 |
} |
| 184 | 261 |
|
| 185 | 262 |
a1=(MYFLOAT4)(0.e0f,0.e0f,0.e0f,0.e0f); |
| 263 |
//v1=v0+dt*a0; |
|
| 264 |
//x1=x0+dt*v0; |
|
| 186 | 265 |
v1=dt*a0+v0; |
| 187 | 266 |
x1=dt*v0+x0; |
| 188 | 267 |
|
| ... | ... | |
| 243 | 322 |
{
|
| 244 | 323 |
int gid=get_global_id(0); |
| 245 | 324 |
uint zmwc=seed_z+gid; |
| 246 |
uint wmwc=seed_w+gid; |
|
| 325 |
uint wmwc=seed_w-gid; |
|
| 326 |
private MYFLOAT Heat; |
|
| 247 | 327 |
|
| 248 | 328 |
for (int i=0;i<gid;i++) |
| 249 | 329 |
{
|
| 250 |
private MYFLOAT heat=MWCfp;
|
|
| 330 |
Heat=MWCfp;
|
|
| 251 | 331 |
} |
| 252 |
|
|
| 253 |
clDataX[gid]=(MYFLOAT4)((MWCfp-0.5e0f)*box,(MWCfp-0.5e0f)*box, |
|
| 254 |
(MWCfp-0.5e0f)*box,0.e0f); |
|
| 255 | 332 |
|
| 333 |
// More accurate distribution based on spherical coordonates |
|
| 334 |
// Disactivated because of AMD Oland GPU problems |
|
| 335 |
// MYFLOAT Radius=Heat*box; |
|
| 336 |
// MYFLOAT Theta=acos((float)(-2.e0f*MWCfp+1.0e0f)); |
|
| 337 |
// MYFLOAT Phi=(MYFLOAT)2.e0f*PI*MWCfp; |
|
| 338 |
// MYFLOAT sinTheta=sin((float)Theta); |
|
| 339 |
// MYFLOAT PosX=cos((float)Phi)*Radius*sinTheta; |
|
| 340 |
// MYFLOAT PosY=sin((float)Phi)*Radius*sinTheta; |
|
| 341 |
// MYFLOAT PosZ=cos((float)Theta)*Radius; |
|
| 342 |
// clDataX[gid]=(MYFLOAT4)(PosX,PosY,PosZ,0.e0f); |
|
| 343 |
|
|
| 344 |
MYFLOAT4 Position=(MYFLOAT4)((Heat-0.5e0f)*box,(MWCfp-0.5e0f)*box,(MWCfp-0.5e0f)*box,0.e0f); |
|
| 345 |
MYFLOAT Length=(MYFLOAT)length((MYFLOAT4)Position); |
|
| 346 |
clDataX[gid]=Position/Length*box*MWCfp; |
|
| 347 |
|
|
| 256 | 348 |
barrier(CLK_GLOBAL_MEM_FENCE); |
| 257 | 349 |
} |
| 258 | 350 |
|
| ... | ... | |
| 265 | 357 |
MYFLOAT4 SpeedVector; |
| 266 | 358 |
|
| 267 | 359 |
if (velocity<SMALL_NUM) {
|
| 268 |
SpeedVector=(MYFLOAT4)normalize(cross(clDataX[gid],clCoM[0]))*sqrt(-AtomicPotential(clDataX,gid)/(MYFLOAT)2.e0f);
|
|
| 360 |
SpeedVector=(MYFLOAT4)normalize(cross(clDataX[gid],clCoM[0]))*sqrt((-AtomicPotential(clDataX,gid)/(MYFLOAT)2.e0f));
|
|
| 269 | 361 |
} |
| 270 | 362 |
else |
| 271 | 363 |
{
|
| ... | ... | |
| 502 | 594 |
VirielStress=True |
| 503 | 595 |
# Verbose |
| 504 | 596 |
Verbose=False |
| 597 |
# OpenGL demo |
|
| 598 |
OpenGL=False |
|
| 505 | 599 |
|
| 506 |
HowToUse='%s -h [Help] -r [InitialRandom] -e [VirielStress] -d <DeviceId> -n <NumberOfParticules> -z <SizeOfBall> -v <Velocity> -s <Step> -m <ImplicitEuler|RungeKutta|ExplicitEuler|Heun> -t <FP32|FP64>' |
|
| 600 |
HowToUse='%s -h [Help] -r [InitialRandom] -g [OpenGL] -e [VirielStress] -d <DeviceId> -n <NumberOfParticules> -z <SizeOfBall> -v <Velocity> -s <Step> -m <ImplicitEuler|RungeKutta|ExplicitEuler|Heun> -t <FP32|FP64>'
|
|
| 507 | 601 |
|
| 508 | 602 |
try: |
| 509 |
opts, args = getopt.getopt(sys.argv[1:],"rehd:n:z:v:s:m:t:",["random","viriel","device=","number=","size=","velocity=","step=","method=","valuetype="]) |
|
| 603 |
opts, args = getopt.getopt(sys.argv[1:],"rgehd:n:z:v:s:m:t:",["random","viriel","device=","number=","size=","velocity=","step=","method=","valuetype="])
|
|
| 510 | 604 |
except getopt.GetoptError: |
| 511 | 605 |
print(HowToUse % sys.argv[0]) |
| 512 | 606 |
sys.exit(2) |
| ... | ... | |
| 556 | 650 |
CheckEnergies=True |
| 557 | 651 |
elif opt in ("-e", "--viriel"):
|
| 558 | 652 |
VirielStress=True |
| 653 |
elif opt in ("-g", "--opengl"):
|
|
| 654 |
OpenGL=True |
|
| 559 | 655 |
|
| 560 |
SizeOfBall=MyFloat(SizeOfBall*Number) |
|
| 656 |
SizeOfBall=MyFloat(SizeOfBall*Number/2.)
|
|
| 561 | 657 |
Velocity=MyFloat(Velocity) |
| 562 | 658 |
Step=MyFloat(Step) |
| 563 | 659 |
|
| ... | ... | |
| 689 | 785 |
cl.enqueue_copy(queue,MyKinetic,clKinetic) |
| 690 | 786 |
print('\nCenter Of Mass: (%s,%s,%s)' % (MyCoM[0],MyCoM[1],MyCoM[2]))
|
| 691 | 787 |
print('Viriel=%s Potential=%s Kinetic=%s\n'% (np.sum(MyPotential)+2.*np.sum(MyKinetic),np.sum(MyPotential),np.sum(MyKinetic)))
|
| 692 |
|
|
| 693 |
print("\nDuration stats on device %s :\n\tMean:\t%s\n\tMedian:\t%s\n\tStddev:\t%s\n\tMin:\t%s\n\tMax:\t%s\n\tVarty:\t%s\n" % (Device,np.mean(Durations),np.median(Durations),np.std(Durations),np.min(Durations),np.max(Durations),np.std(Durations)/np.median(Durations)))
|
|
| 694 | 788 |
|
| 695 |
# Contraction of Square*Size*Hertz: Size*Size/Tile |
|
| 789 |
print("\nDuration stats on device %s with %s iterations :\n\tMean:\t%s\n\tMedian:\t%s\n\tStddev:\t%s\n\tMin:\t%s\n\tMax:\t%s\n\n\tVariability:\t%s\n" % (Device,Iterations,np.mean(Durations),np.median(Durations),np.std(Durations),np.min(Durations),np.max(Durations),np.std(Durations)/np.median(Durations)))
|
|
| 790 |
|
|
| 791 |
# Contraction of Square*Size*Hertz: Size*Size/Elapsed |
|
| 696 | 792 |
Squertz=np.ones(len(Durations)) |
| 697 | 793 |
Squertz*=Number*Number |
| 698 | 794 |
Squertz/=Durations |
| 699 | 795 |
|
| 700 |
print("\nSquertz in log10 stats on device %s :\n\tMean:\t%s\n\tMedian:\t%s\n\tStddev:\t%s\n\tMin:\t%s\n\tMax:\t%s\n\tVarty:\t%s\n" % (Device,np.log10(np.mean(Squertz)),np.log10(np.median(Squertz)),np.log10(np.std(Squertz)),np.log10(np.min(Squertz)),np.log10(np.max(Squertz)),np.std(Squertz)/np.median(Squertz)))
|
|
| 796 |
print("Squertz in log10 stats on device %s with %s iterations :\n\tMean:\t%s\n\tMedian:\t%s\n\tStddev:\t%s\n\tMin:\t%s\n\tMax:\t%s\n" % (Device,Iterations,np.log10(np.mean(Squertz)),np.log10(np.median(Squertz)),np.log10(np.std(Squertz)),np.log10(np.min(Squertz)),np.log10(np.max(Squertz))))
|
|
| 701 | 797 |
|
| 702 | 798 |
clDataX.release() |
| 703 | 799 |
clDataV.release() |
Formats disponibles : Unified diff