1 /**************************************************************************
3 * Java Grande Forum Benchmark Suite - Thread Version 1.0 *
7 * Java Grande Benchmarking Project *
11 * Edinburgh Parallel Computing Centre *
13 * email: epcc-javagrande@epcc.ed.ac.uk *
16 * This version copyright (c) The University of Edinburgh, 2001. *
17 * All rights reserved. *
19 **************************************************************************/
20 public class JGFMolDynBench {
31 public DoubleWrapper[] epot;
32 public DoubleWrapper[] vir;
33 public DoubleWrapper[] ek;
38 public int interactions;
39 public IntWrapper[] interacts;
42 public JGFInstrumentor instr;
44 public JGFMolDynBench(int nthreads) {
45 this.nthreads=nthreads;
48 public void JGFsetsize(int size){
52 public void JGFinitialise(){
54 datasizes = new int[2];
59 PARTSIZE = mm*mm*mm*4;
69 public static void JGFapplication(JGFMolDynBench mold) {
71 //BarrierServer mybarr;
73 int[] mid = new int[8];
74 mid[0] = (128<<24)|(195<<16)|(175<<8)|84;//dw-10
75 mid[1] = (128<<24)|(195<<16)|(175<<8)|85;//dw-11
76 mid[2] = (128<<24)|(195<<16)|(175<<8)|86;//dw-12
77 mid[3] = (128<<24)|(195<<16)|(175<<8)|87;//dw-13
78 mid[4] = (128<<24)|(195<<16)|(175<<8)|88;//dw-14
79 mid[5] = (128<<24)|(195<<16)|(175<<8)|89;//dw-15
80 mid[6] = (128<<24)|(195<<16)|(175<<8)|90;//dw-16
81 mid[7] = (128<<24)|(195<<16)|(175<<8)|91;//dw-17
85 double sh_force2 [][][];
86 int partsize, numthreads;
87 partsize = mold.PARTSIZE;
88 numthreads = mold.nthreads;
89 //mybarr = new BarrierServer(numthreads);
90 //mybarr.start(mid[0]);
92 sh_force = new double[3][partsize];
93 sh_force2 = new double[3][numthreads][partsize];
94 mold.epot = new DoubleWrapper[numthreads];
95 mold.vir = new DoubleWrapper[numthreads];
96 mold.ek = new DoubleWrapper[numthreads];
97 mold.interacts = new IntWrapper[numthreads];
98 for(int i=0;i<numthreads;i++) {
99 mold.epot[i]=new DoubleWrapper();
100 mold.vir[i]=new DoubleWrapper();
101 mold.ek[i]=new DoubleWrapper();
102 mold.interacts[i]=new IntWrapper();
106 MDWrap[] thobjects = new MDWrap[numthreads];
108 for(int i=0;i<numthreads;i++) {
109 thobjects[i] = new MDWrap(new mdRunner(i,mold.mm,sh_force,sh_force2,mold.nthreads,mold));
113 boolean waitfordone=true;
120 for(int i=0;i<numthreads;i++) {
121 //thobjects[i].md.start(mid[i]);
122 thobjects[i].md.run();
126 public void JGFvalidate(){
127 double[] refval = new double[2];
128 refval[0] = 1731.4306625334357;
129 refval[1] = 7397.392307839352;
130 double dev = Math.fabs(ek[0].d - refval[size]);
132 //System.printString("Validation failed\n");
133 //System.printString("Kinetic Energy = " + (long)ek[0] + " " + (long)dev + " " + size + "\n");
142 double l,rcoff,rcoffs,side,sideh,hsq,hsq2,vel,velt;
143 double a,r,sum,tscale,sc,ekin,ts,sp;
147 double vaver,vaverh,rand;
148 double etot,temp,pres,rp;
149 double u1, u2, s, xx, yy, zz;
150 double xvelocity, yvelocity, zvelocity;
152 double [][] sh_force;
153 double [][][] sh_force2;
155 int ijk,npartm,iseed,tint;
163 public mdRunner(int id, int mm, double [][] sh_force, double [][][] sh_force2,
164 int nthreads, JGFMolDynBench mymd) {
167 this.sh_force=sh_force;
168 this.sh_force2=sh_force2;
169 this.nthreads = nthreads;
180 public void init(particle[] one, int mdsize) {
182 for (int lg=0; lg<=1; lg++) {
183 for (int i=0; i<mm; i++) {
184 for (int j=0; j<mm; j++) {
185 for (int k=0; k<mm; k++) {
186 one[ijk] = new particle((i*a+lg*a*0.5),(j*a+lg*a*0.5),(k*a),
187 xvelocity,yvelocity,zvelocity,sh_force,sh_force2,id,one);
194 for (int lg=1; lg<=2; lg++) {
195 for (int i=0; i<mm; i++) {
196 for (int j=0; j<mm; j++) {
197 for (int k=0; k<mm; k++) {
198 one[ijk] = new particle((i*a+(2-lg)*a*0.5),(j*a+(lg-1)*a*0.5),
199 (k*a+a*0.5),xvelocity,yvelocity,zvelocity,sh_force,sh_force2,id,one);
206 /* Initialise velocities */
211 random randnum = new random(iseed,v1,v2);
214 for (int i=0; i<mdsize; i+=2) {
216 one[i].xvelocity = r*randnum.v1;
217 one[i+1].xvelocity = r*randnum.v2;
220 for (int i=0; i<mdsize; i+=2) {
222 one[i].yvelocity = r*randnum.v1;
223 one[i+1].yvelocity = r*randnum.v2;
226 for (int i=0; i<mdsize; i+=2) {
228 one[i].zvelocity = r*randnum.v1;
229 one[i+1].zvelocity = r*randnum.v2;
233 /* velocity scaling */
238 for(int i=0;i<mdsize;i++) {
239 sp = sp + one[i].xvelocity;
243 for(int i=0;i<mdsize;i++) {
244 one[i].xvelocity = one[i].xvelocity - sp;
245 ekin = ekin + one[i].xvelocity*one[i].xvelocity;
249 for(int i=0;i<mdsize;i++) {
250 sp = sp + one[i].yvelocity;
254 for(int i=0;i<mdsize;i++) {
255 one[i].yvelocity = one[i].yvelocity - sp;
256 ekin = ekin + one[i].yvelocity*one[i].yvelocity;
261 for(int i=0;i<mdsize;i++) {
262 sp = sp + one[i].zvelocity;
266 for(int i=0;i<mdsize;i++) {
267 one[i].zvelocity = one[i].zvelocity - sp;
268 ekin = ekin + one[i].zvelocity*one[i].zvelocity;
272 sc = h * Math.sqrt(tref/ts);
275 for(int i=0;i<mdsize;i++) {
277 one[i].xvelocity = one[i].xvelocity * sc;
278 one[i].yvelocity = one[i].yvelocity * sc;
279 one[i].zvelocity = one[i].zvelocity * sc;
285 public void doinit(int mdsize) {
286 for(int j=0;j<3;j++) {
287 double[] sh=sh_force[j];
288 for (int i=0;i<mdsize;i++) {
295 public void doinit2(int mdsize) {
296 for(int k=0;k<3;k++) {
297 double[] sh=sh_force[k];
298 double [][] sha=sh_force2[k];
299 for(int j=0;j<nthreads;j++) {
300 double[] sha2=sha[j];
301 for(int i=0;i<mdsize;i++) {
307 for(int k=0;k<3;k++) {
308 double [][] sh1=sh_force2[k];
309 for(int j=0;j<nthreads;j++) {
311 for(int i=0;i<mdsize;i++) {
319 for(int j=1;j<nthreads;j++) {
320 mymd.epot[0].d += mymd.epot[j].d;
321 mymd.vir[0].d += mymd.vir[j].d;
323 for(int j=1;j<nthreads;j++) {
324 mymd.epot[j].d = mymd.epot[0].d;
325 mymd.vir[j].d = mymd.vir[0].d;
327 for(int j=0;j<nthreads;j++) {
328 mymd.interactions += mymd.interacts[j].i;
331 for (int j=0;j<3;j++) {
332 double sh[]=sh_force[j];
333 for (int i=0;i<mdsize;i++) {
334 sh[i] = sh[i] * hsq2;
340 /* Parameter determination */
345 //Barrier barr=new Barrier("128.195.175.84");
349 mdsize = mymd.PARTSIZE;
350 one=new particle[mdsize];
353 side = Math.pow((mdsize/tmpden),0.3333333);
361 rcoffs = rcoff * rcoff;
362 tscale = 16.0 / (1.0 * mdsize - 1.0);
363 vaver = 1.13 * Math.sqrt(tref / 24.0);
366 /* Particle Generation */
375 /* Synchronise threads and start timer before MD simulation */
377 //Barrier.enterBarrier(barr);
381 for (int move=0;move<movemx;move++) {
382 /* move the particles and update velocities */
383 for (int i=0;i<mdsize;i++) {
384 one[i].domove(side,i);
388 //Barrier.enterBarrier(barr);
394 mymd.epot[id].d = 0.0;
395 mymd.vir[id].d = 0.0;
396 mymd.interacts[id].i = 0;
400 //Barrier.enterBarrier(barr);
404 for (int i=0+id;i<mdsize;i+=nthreads) {
405 one[i].force(side,rcoff,mdsize,i,xx,yy,zz,mymd);
409 //Barrier.enterBarrier(barr);
411 /* update force arrays */
417 //Barrier.enterBarrier(barr);
419 /*scale forces, update velocities */
421 for (int i=0;i<mdsize;i++) {
422 sum = sum + one[i].mkekin(hsq2,i);
430 /* average velocity */
432 for (int i=0;i<mdsize;i++) {
433 velt = one[i].velavg(vaverh,h);
434 if(velt > vaverh) { count = count + 1.0; }
440 /* temperature scale if required */
442 if((move < istop) && (((move+1) % irep) == 0)) {
443 sc = Math.sqrt(tref / (tscale*ekin));
444 for (int i=0;i<mdsize;i++) {
447 ekin = tref / tscale;
450 /* sum to get full potential energy and virial */
452 if(((move+1) % iprint) == 0) {
453 mymd.ek[id].d = 24.0*ekin;
454 mymd.epot[id].d = 4.0*mymd.epot[id].d;
455 etot = mymd.ek[id].d + mymd.epot[id].d;
456 temp = tscale * ekin;
457 pres = tmpden * 16.0 * (ekin - mymd.vir[id].d) / mdsize;
459 rp = (count / mdsize) * 100.0;
461 //Barrier.enterBarrier(barr);
463 //if (id == 0) JGFInstrumentor.stopTimer("Section3:MolDyn:Run", instr.timers);
470 public double xcoord, ycoord, zcoord;
471 public double xvelocity,yvelocity,zvelocity;
474 double [][] sh_force;
475 double [][][] sh_force2;
478 public particle(double xcoord, double ycoord, double zcoord, double xvelocity,
479 double yvelocity,double zvelocity, double [][] sh_force,
480 double [][][] sh_force2,int id, particle[] one) {
482 this.xcoord = xcoord;
483 this.ycoord = ycoord;
484 this.zcoord = zcoord;
485 this.xvelocity = xvelocity;
486 this.yvelocity = yvelocity;
487 this.zvelocity = zvelocity;
488 this.sh_force = sh_force;
489 this.sh_force2 = sh_force2;
494 public void domove(double side,int part_id) {
496 xcoord = xcoord + xvelocity + sh_force[0][part_id];
497 ycoord = ycoord + yvelocity + sh_force[1][part_id];
498 zcoord = zcoord + zvelocity + sh_force[2][part_id];
500 if(xcoord < 0) { xcoord = xcoord + side; }
501 if(xcoord > side) { xcoord = xcoord - side; }
502 if(ycoord < 0) { ycoord = ycoord + side; }
503 if(ycoord > side) { ycoord = ycoord - side; }
504 if(zcoord < 0) { zcoord = zcoord + side; }
505 if(zcoord > side) { zcoord = zcoord - side; }
507 xvelocity = xvelocity + sh_force[0][part_id];
508 yvelocity = yvelocity + sh_force[1][part_id];
509 zvelocity = zvelocity + sh_force[2][part_id];
513 public void force(double side, double rcoff,int mdsize,int x, double xx, double yy, double zz, JGFMolDynBench mymd) {
519 double rd,rrd,rrd2,rrd3,rrd4,rrd6,rrd7,r148;
520 double forcex,forcey,forcez;
523 rcoffs = rcoff*rcoff;
529 for (int i=x+1;i<mdsize;i++) {
530 xx = this.xcoord - one[i].xcoord;
531 yy = this.ycoord - one[i].ycoord;
532 zz = this.zcoord - one[i].zcoord;
534 if(xx < (-sideh)) { xx = xx + side; }
535 if(xx > (sideh)) { xx = xx - side; }
536 if(yy < (-sideh)) { yy = yy + side; }
537 if(yy > (sideh)) { yy = yy - side; }
538 if(zz < (-sideh)) { zz = zz + side; }
539 if(zz > (sideh)) { zz = zz - side; }
542 rd = xx*xx + yy*yy + zz*zz;
551 mymd.epot[id].d += (rrd6 - rrd3);
552 r148 = rrd7 - 0.5*rrd4;
553 mymd.vir[id].d += - rd*r148;
557 sh_force2[0][id][i] = sh_force2[0][id][i] - forcex;
562 sh_force2[1][id][i] = sh_force2[1][id][i] - forcey;
567 sh_force2[2][id][i] = sh_force2[2][id][i] - forcez;
569 mymd.interacts[id].i++;
574 sh_force2[0][id][x] = sh_force2[0][id][x] + fxi;
575 sh_force2[1][id][x] = sh_force2[1][id][x] + fyi;
576 sh_force2[2][id][x] = sh_force2[2][id][x] + fzi;
580 public double mkekin(double hsq2,int part_id) {
584 xvelocity = xvelocity + sh_force[0][part_id];
585 yvelocity = yvelocity + sh_force[1][part_id];
586 zvelocity = zvelocity + sh_force[2][part_id];
588 sumt = (xvelocity*xvelocity)+(yvelocity*yvelocity)+(zvelocity*zvelocity);
592 public double velavg(double vaverh,double h) {
597 sq = Math.sqrt(xvelocity*xvelocity + yvelocity*yvelocity +
598 zvelocity*zvelocity);
604 public void dscal(double sc,int incx) {
605 xvelocity = xvelocity * sc;
606 yvelocity = yvelocity * sc;
607 zvelocity = zvelocity * sc;
616 public random(int iseed,double v1,double v2) {
622 public double update() {
625 double scale= 4.656612875e-10;
629 int imod = 2147483647;
631 if (iseed<=0) { iseed = 1; }
634 is1 = (iseed-is2)/32768;
637 is1 = (is1*imult+(iss2-is2)/32768) % (65536);
639 iseed = (is1*32768+is2) % imod;
641 rand = scale * iseed;
647 public double seed() {
661 r = Math.sqrt(-2.0*Math.log(s)/s);