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 = global new int[2];
59 PARTSIZE = mm*mm*mm*4;
69 public static void JGFapplication(JGFMolDynBench mold) {
72 int[] mid = new int[4];
73 mid[0] = (128<<24)|(195<<16)|(175<<8)|79;
74 mid[1] = (128<<24)|(195<<16)|(175<<8)|80;
75 mid[2] = (128<<24)|(195<<16)|(175<<8)|78;
76 mid[3] = (128<<24)|(195<<16)|(175<<8)|73;
79 double sh_force2 [][][];
80 int partsize, numthreads;
82 partsize = mold.PARTSIZE;
83 numthreads = mold.nthreads;
84 mybarr = global new BarrierServer(numthreads);
89 sh_force = global new double[3][partsize];
90 sh_force2 = global new double[3][numthreads][partsize];
91 mold.epot = global new DoubleWrapper[numthreads];
92 mold.vir = global new DoubleWrapper[numthreads];
93 mold.ek = global new DoubleWrapper[numthreads];
94 mold.interacts = global new IntWrapper[numthreads];
95 for(int i=0;i<numthreads;i++) {
96 mold.epot[i]=global new DoubleWrapper();
97 mold.vir[i]=global new DoubleWrapper();
98 mold.ek[i]=global new DoubleWrapper();
99 mold.interacts[i]=global new IntWrapper();
104 MDWrap[] thobjects = new MDWrap[numthreads];
107 for(int i=0;i<numthreads;i++) {
108 thobjects[i] = new MDWrap(global new mdRunner(i,mold.mm,sh_force,sh_force2,mold.nthreads,mold));
112 boolean waitfordone=true;
120 for(int i=0;i<numthreads;i++) {
121 thobjects[i].md.start(mid[i]);
124 for(int i=0;i<numthreads;i++) {
125 thobjects[i].md.join();
129 public void JGFvalidate(){
130 double[] refval = new double[2];
131 refval[0] = 1731.4306625334357;
132 refval[1] = 7397.392307839352;
133 double dev = Math.fabs(ek[0].d - refval[size]);
135 //System.printString("Validation failed\n");
136 //System.printString("Kinetic Energy = " + (long)ek[0] + " " + (long)dev + " " + size + "\n");
141 class mdRunner extends Thread {
145 double l,rcoff,rcoffs,side,sideh,hsq,hsq2,vel,velt;
146 double a,r,sum,tscale,sc,ekin,ts,sp;
150 double vaver,vaverh,rand;
151 double etot,temp,pres,rp;
152 double u1, u2, s, xx, yy, zz;
153 double xvelocity, yvelocity, zvelocity;
155 double [][] sh_force;
156 double [][][] sh_force2;
158 int ijk,npartm,iseed,tint;
166 public mdRunner(int id, int mm, double [][] sh_force, double [][][] sh_force2,
167 int nthreads, JGFMolDynBench mymd) {
170 this.sh_force=sh_force;
171 this.sh_force2=sh_force2;
172 this.nthreads = nthreads;
183 public void init(particle[] one, int mdsize) {
185 for (int lg=0; lg<=1; lg++) {
186 for (int i=0; i<mm; i++) {
187 for (int j=0; j<mm; j++) {
188 for (int k=0; k<mm; k++) {
189 one[ijk] = new particle((i*a+lg*a*0.5),(j*a+lg*a*0.5),(k*a),
190 xvelocity,yvelocity,zvelocity,sh_force,sh_force2,id,one);
197 for (int lg=1; lg<=2; lg++) {
198 for (int i=0; i<mm; i++) {
199 for (int j=0; j<mm; j++) {
200 for (int k=0; k<mm; k++) {
201 one[ijk] = new particle((i*a+(2-lg)*a*0.5),(j*a+(lg-1)*a*0.5),
202 (k*a+a*0.5),xvelocity,yvelocity,zvelocity,sh_force,sh_force2,id,one);
209 /* Initialise velocities */
214 random randnum = new random(iseed,v1,v2);
217 for (int i=0; i<mdsize; i+=2) {
219 one[i].xvelocity = r*randnum.v1;
220 one[i+1].xvelocity = r*randnum.v2;
223 for (int i=0; i<mdsize; i+=2) {
225 one[i].yvelocity = r*randnum.v1;
226 one[i+1].yvelocity = r*randnum.v2;
229 for (int i=0; i<mdsize; i+=2) {
231 one[i].zvelocity = r*randnum.v1;
232 one[i+1].zvelocity = r*randnum.v2;
236 /* velocity scaling */
241 for(int i=0;i<mdsize;i++) {
242 sp = sp + one[i].xvelocity;
246 for(int i=0;i<mdsize;i++) {
247 one[i].xvelocity = one[i].xvelocity - sp;
248 ekin = ekin + one[i].xvelocity*one[i].xvelocity;
252 for(int i=0;i<mdsize;i++) {
253 sp = sp + one[i].yvelocity;
257 for(int i=0;i<mdsize;i++) {
258 one[i].yvelocity = one[i].yvelocity - sp;
259 ekin = ekin + one[i].yvelocity*one[i].yvelocity;
264 for(int i=0;i<mdsize;i++) {
265 sp = sp + one[i].zvelocity;
269 for(int i=0;i<mdsize;i++) {
270 one[i].zvelocity = one[i].zvelocity - sp;
271 ekin = ekin + one[i].zvelocity*one[i].zvelocity;
275 sc = h * Math.sqrt(tref/ts);
278 for(int i=0;i<mdsize;i++) {
280 one[i].xvelocity = one[i].xvelocity * sc;
281 one[i].yvelocity = one[i].yvelocity * sc;
282 one[i].zvelocity = one[i].zvelocity * sc;
288 public void doinit(int mdsize) {
289 for(int j=0;j<3;j++) {
290 double[] sh=sh_force[j];
291 for (int i=0;i<mdsize;i++) {
298 public void doinit2(int mdsize) {
299 for(int k=0;k<3;k++) {
300 double[] sh=sh_force[k];
301 double [][] sha=sh_force2[k];
302 for(int j=0;j<nthreads;j++) {
303 double[] sha2=sha[j];
304 for(int i=0;i<mdsize;i++) {
310 for(int k=0;k<3;k++) {
311 double [][] sh1=sh_force2[k];
312 for(int j=0;j<nthreads;j++) {
314 for(int i=0;i<mdsize;i++) {
322 for(int j=1;j<nthreads;j++) {
323 mymd.epot[0].d += mymd.epot[j].d;
324 mymd.vir[0].d += mymd.vir[j].d;
326 for(int j=1;j<nthreads;j++) {
327 mymd.epot[j].d = mymd.epot[0].d;
328 mymd.vir[j].d = mymd.vir[0].d;
330 for(int j=0;j<nthreads;j++) {
331 mymd.interactions += mymd.interacts[j].i;
334 for (int j=0;j<3;j++) {
335 double sh[]=sh_force[j];
336 for (int i=0;i<mdsize;i++) {
337 sh[i] = sh[i] * hsq2;
343 /* Parameter determination */
348 Barrier barr=new Barrier("128.195.175.79");
353 mdsize = mymd.PARTSIZE;
354 one=new particle[mdsize];
357 side = Math.pow((mdsize/tmpden),0.3333333);
365 rcoffs = rcoff * rcoff;
366 tscale = 16.0 / (1.0 * mdsize - 1.0);
367 vaver = 1.13 * Math.sqrt(tref / 24.0);
370 /* Particle Generation */
380 /* Synchronise threads and start timer before MD simulation */
382 Barrier.enterBarrier(barr);
386 for (int move=0;move<movemx;move++) {
388 /* move the particles and update velocities */
389 for (int i=0;i<mdsize;i++) {
390 one[i].domove(side,i);
395 Barrier.enterBarrier(barr);
402 mymd.epot[id].d = 0.0;
403 mymd.vir[id].d = 0.0;
404 mymd.interacts[id].i = 0;
409 Barrier.enterBarrier(barr);
414 for (int i=0+id;i<mdsize;i+=nthreads) {
415 one[i].force(side,rcoff,mdsize,i,xx,yy,zz,mymd);
420 Barrier.enterBarrier(barr);
422 /* update force arrays */
430 Barrier.enterBarrier(barr);
433 /*scale forces, update velocities */
435 for (int i=0;i<mdsize;i++) {
436 sum = sum + one[i].mkekin(hsq2,i);
444 /* average velocity */
446 for (int i=0;i<mdsize;i++) {
447 velt = one[i].velavg(vaverh,h);
448 if(velt > vaverh) { count = count + 1.0; }
454 /* temperature scale if required */
456 if((move < istop) && (((move+1) % irep) == 0)) {
457 sc = Math.sqrt(tref / (tscale*ekin));
458 for (int i=0;i<mdsize;i++) {
461 ekin = tref / tscale;
464 /* sum to get full potential energy and virial */
466 if(((move+1) % iprint) == 0) {
467 mymd.ek[id].d = 24.0*ekin;
468 mymd.epot[id].d = 4.0*mymd.epot[id].d;
469 etot = mymd.ek[id].d + mymd.epot[id].d;
470 temp = tscale * ekin;
471 pres = tmpden * 16.0 * (ekin - mymd.vir[id].d) / mdsize;
473 rp = (count / mdsize) * 100.0;
476 Barrier.enterBarrier(barr);
479 //if (id == 0) JGFInstrumentor.stopTimer("Section3:MolDyn:Run", instr.timers);
486 public double xcoord, ycoord, zcoord;
487 public double xvelocity,yvelocity,zvelocity;
490 global double [][] sh_force;
491 global double [][][] sh_force2;
494 public particle(double xcoord, double ycoord, double zcoord, double xvelocity,
495 double yvelocity,double zvelocity, double [][] sh_force,
496 double [][][] sh_force2,int id, particle[] one) {
498 this.xcoord = xcoord;
499 this.ycoord = ycoord;
500 this.zcoord = zcoord;
501 this.xvelocity = xvelocity;
502 this.yvelocity = yvelocity;
503 this.zvelocity = zvelocity;
504 this.sh_force = sh_force;
505 this.sh_force2 = sh_force2;
510 public void domove(double side,int part_id) {
512 xcoord = xcoord + xvelocity + sh_force[0][part_id];
513 ycoord = ycoord + yvelocity + sh_force[1][part_id];
514 zcoord = zcoord + zvelocity + sh_force[2][part_id];
516 if(xcoord < 0) { xcoord = xcoord + side; }
517 if(xcoord > side) { xcoord = xcoord - side; }
518 if(ycoord < 0) { ycoord = ycoord + side; }
519 if(ycoord > side) { ycoord = ycoord - side; }
520 if(zcoord < 0) { zcoord = zcoord + side; }
521 if(zcoord > side) { zcoord = zcoord - side; }
523 xvelocity = xvelocity + sh_force[0][part_id];
524 yvelocity = yvelocity + sh_force[1][part_id];
525 zvelocity = zvelocity + sh_force[2][part_id];
529 public void force(double side, double rcoff,int mdsize,int x, double xx, double yy, double zz, JGFMolDynBench mymd) {
535 double rd,rrd,rrd2,rrd3,rrd4,rrd6,rrd7,r148;
536 double forcex,forcey,forcez;
539 rcoffs = rcoff*rcoff;
545 for (int i=x+1;i<mdsize;i++) {
546 xx = this.xcoord - one[i].xcoord;
547 yy = this.ycoord - one[i].ycoord;
548 zz = this.zcoord - one[i].zcoord;
550 if(xx < (-sideh)) { xx = xx + side; }
551 if(xx > (sideh)) { xx = xx - side; }
552 if(yy < (-sideh)) { yy = yy + side; }
553 if(yy > (sideh)) { yy = yy - side; }
554 if(zz < (-sideh)) { zz = zz + side; }
555 if(zz > (sideh)) { zz = zz - side; }
558 rd = xx*xx + yy*yy + zz*zz;
567 mymd.epot[id].d += (rrd6 - rrd3);
568 r148 = rrd7 - 0.5*rrd4;
569 mymd.vir[id].d += - rd*r148;
573 sh_force2[0][id][i] = sh_force2[0][id][i] - forcex;
578 sh_force2[1][id][i] = sh_force2[1][id][i] - forcey;
583 sh_force2[2][id][i] = sh_force2[2][id][i] - forcez;
585 mymd.interacts[id].i++;
590 sh_force2[0][id][x] = sh_force2[0][id][x] + fxi;
591 sh_force2[1][id][x] = sh_force2[1][id][x] + fyi;
592 sh_force2[2][id][x] = sh_force2[2][id][x] + fzi;
596 public double mkekin(double hsq2,int part_id) {
600 xvelocity = xvelocity + sh_force[0][part_id];
601 yvelocity = yvelocity + sh_force[1][part_id];
602 zvelocity = zvelocity + sh_force[2][part_id];
604 sumt = (xvelocity*xvelocity)+(yvelocity*yvelocity)+(zvelocity*zvelocity);
608 public double velavg(double vaverh,double h) {
613 sq = Math.sqrt(xvelocity*xvelocity + yvelocity*yvelocity +
614 zvelocity*zvelocity);
620 public void dscal(double sc,int incx) {
621 xvelocity = xvelocity * sc;
622 yvelocity = yvelocity * sc;
623 zvelocity = zvelocity * sc;
632 public random(int iseed,double v1,double v2) {
638 public double update() {
641 double scale= 4.656612875e-10;
645 int imod = 2147483647;
647 if (iseed<=0) { iseed = 1; }
650 is1 = (iseed-is2)/32768;
653 is1 = (is1*imult+(iss2-is2)/32768) % (65536);
655 iseed = (is1*32768+is2) % imod;
657 rand = scale * iseed;
663 public double seed() {
677 r = Math.sqrt(-2.0*Math.log(s)/s);