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) {
184 for (lg=0; lg<=1; lg++) {
185 for (i=0; i<mm; i++) {
186 for (j=0; j<mm; j++) {
187 for (k=0; k<mm; k++) {
188 one[ijk] = new particle((i*a+lg*a*0.5),(j*a+lg*a*0.5),(k*a),
189 xvelocity,yvelocity,zvelocity,sh_force,sh_force2,id,one);
196 for (lg=1; lg<=2; lg++) {
197 for (i=0; i<mm; i++) {
198 for (j=0; j<mm; j++) {
199 for (k=0; k<mm; k++) {
200 one[ijk] = new particle((i*a+(2-lg)*a*0.5),(j*a+(lg-1)*a*0.5),
201 (k*a+a*0.5),xvelocity,yvelocity,zvelocity,sh_force,sh_force2,id,one);
208 /* Initialise velocities */
213 random randnum = new random(iseed,v1,v2);
216 for (i=0; i<mdsize; i+=2) {
218 one[i].xvelocity = r*randnum.v1;
219 one[i+1].xvelocity = r*randnum.v2;
222 for (i=0; i<mdsize; i+=2) {
224 one[i].yvelocity = r*randnum.v1;
225 one[i+1].yvelocity = r*randnum.v2;
228 for (i=0; i<mdsize; i+=2) {
230 one[i].zvelocity = r*randnum.v1;
231 one[i+1].zvelocity = r*randnum.v2;
235 /* velocity scaling */
240 for(i=0;i<mdsize;i++) {
241 sp = sp + one[i].xvelocity;
245 for(i=0;i<mdsize;i++) {
246 one[i].xvelocity = one[i].xvelocity - sp;
247 ekin = ekin + one[i].xvelocity*one[i].xvelocity;
251 for(i=0;i<mdsize;i++) {
252 sp = sp + one[i].yvelocity;
256 for(i=0;i<mdsize;i++) {
257 one[i].yvelocity = one[i].yvelocity - sp;
258 ekin = ekin + one[i].yvelocity*one[i].yvelocity;
263 for(i=0;i<mdsize;i++) {
264 sp = sp + one[i].zvelocity;
268 for(i=0;i<mdsize;i++) {
269 one[i].zvelocity = one[i].zvelocity - sp;
270 ekin = ekin + one[i].zvelocity*one[i].zvelocity;
274 sc = h * Math.sqrt(tref/ts);
277 for(i=0;i<mdsize;i++) {
279 one[i].xvelocity = one[i].xvelocity * sc;
280 one[i].yvelocity = one[i].yvelocity * sc;
281 one[i].zvelocity = one[i].zvelocity * sc;
288 /* Parameter determination */
293 Barrier barr=new Barrier("128.195.175.79");
296 mdsize = mymd.PARTSIZE;
297 one=new particle[mdsize];
300 side = Math.pow((mdsize/tmpden),0.3333333);
308 rcoffs = rcoff * rcoff;
309 tscale = 16.0 / (1.0 * mdsize - 1.0);
310 vaver = 1.13 * Math.sqrt(tref / 24.0);
313 /* Particle Generation */
323 /* Synchronise threads and start timer before MD simulation */
325 Barrier.enterBarrier(barr);
329 for (int move=0;move<movemx;move++) {
331 /* move the particles and update velocities */
332 for (i=0;i<mdsize;i++) {
333 one[i].domove(side,i);
338 Barrier.enterBarrier(barr);
343 for (i=0;i<mdsize;i++) {
344 sh_force[j][i] = 0.0;
349 mymd.epot[id].d = 0.0;
350 mymd.vir[id].d = 0.0;
351 mymd.interacts[id].i = 0;
356 Barrier.enterBarrier(barr);
361 for (i=0+id;i<mdsize;i+=nthreads) {
362 one[i].force(side,rcoff,mdsize,i,xx,yy,zz,mymd);
367 Barrier.enterBarrier(barr);
369 /* update force arrays */
372 for(int k=0;k<3;k++) {
373 for(i=0;i<mdsize;i++) {
374 for(j=0;j<nthreads;j++) {
375 sh_force[k][i] += sh_force2[k][j][i];
380 for(int k=0;k<3;k++) {
381 for(i=0;i<mdsize;i++) {
382 for(j=0;j<nthreads;j++) {
383 sh_force2[k][j][i] = 0.0;
388 for(j=1;j<nthreads;j++) {
389 mymd.epot[0].d += mymd.epot[j].d;
390 mymd.vir[0].d += mymd.vir[j].d;
392 for(j=1;j<nthreads;j++) {
393 mymd.epot[j].d = mymd.epot[0].d;
394 mymd.vir[j].d = mymd.vir[0].d;
396 for(j=0;j<nthreads;j++) {
397 mymd.interactions += mymd.interacts[j].i;
401 for (i=0;i<mdsize;i++) {
402 sh_force[j][i] = sh_force[j][i] * hsq2;
409 Barrier.enterBarrier(barr);
412 /*scale forces, update velocities */
414 for (i=0;i<mdsize;i++) {
415 sum = sum + one[i].mkekin(hsq2,i);
423 /* average velocity */
425 for (i=0;i<mdsize;i++) {
426 velt = one[i].velavg(vaverh,h);
427 if(velt > vaverh) { count = count + 1.0; }
433 /* temperature scale if required */
435 if((move < istop) && (((move+1) % irep) == 0)) {
436 sc = Math.sqrt(tref / (tscale*ekin));
437 for (i=0;i<mdsize;i++) {
440 ekin = tref / tscale;
443 /* sum to get full potential energy and virial */
445 if(((move+1) % iprint) == 0) {
446 mymd.ek[id].d = 24.0*ekin;
447 mymd.epot[id].d = 4.0*mymd.epot[id].d;
448 etot = mymd.ek[id].d + mymd.epot[id].d;
449 temp = tscale * ekin;
450 pres = tmpden * 16.0 * (ekin - mymd.vir[id].d) / mdsize;
452 rp = (count / mdsize) * 100.0;
455 Barrier.enterBarrier(barr);
458 Barrier.enterBarrier(barr);
459 //if (id == 0) JGFInstrumentor.stopTimer("Section3:MolDyn:Run", instr.timers);
466 public double xcoord, ycoord, zcoord;
467 public double xvelocity,yvelocity,zvelocity;
470 global double [][] sh_force;
471 global double [][][] sh_force2;
474 public particle(double xcoord, double ycoord, double zcoord, double xvelocity,
475 double yvelocity,double zvelocity, double [][] sh_force,
476 double [][][] sh_force2,int id, particle[] one) {
478 this.xcoord = xcoord;
479 this.ycoord = ycoord;
480 this.zcoord = zcoord;
481 this.xvelocity = xvelocity;
482 this.yvelocity = yvelocity;
483 this.zvelocity = zvelocity;
484 this.sh_force = sh_force;
485 this.sh_force2 = sh_force2;
490 public void domove(double side,int part_id) {
492 xcoord = xcoord + xvelocity + sh_force[0][part_id];
493 ycoord = ycoord + yvelocity + sh_force[1][part_id];
494 zcoord = zcoord + zvelocity + sh_force[2][part_id];
496 if(xcoord < 0) { xcoord = xcoord + side; }
497 if(xcoord > side) { xcoord = xcoord - side; }
498 if(ycoord < 0) { ycoord = ycoord + side; }
499 if(ycoord > side) { ycoord = ycoord - side; }
500 if(zcoord < 0) { zcoord = zcoord + side; }
501 if(zcoord > side) { zcoord = zcoord - side; }
503 xvelocity = xvelocity + sh_force[0][part_id];
504 yvelocity = yvelocity + sh_force[1][part_id];
505 zvelocity = zvelocity + sh_force[2][part_id];
509 public void force(double side, double rcoff,int mdsize,int x, double xx, double yy, double zz, JGFMolDynBench mymd) {
515 double rd,rrd,rrd2,rrd3,rrd4,rrd6,rrd7,r148;
516 double forcex,forcey,forcez;
519 rcoffs = rcoff*rcoff;
525 for (int i=x+1;i<mdsize;i++) {
526 xx = this.xcoord - one[i].xcoord;
527 yy = this.ycoord - one[i].ycoord;
528 zz = this.zcoord - one[i].zcoord;
530 if(xx < (-sideh)) { xx = xx + side; }
531 if(xx > (sideh)) { xx = xx - side; }
532 if(yy < (-sideh)) { yy = yy + side; }
533 if(yy > (sideh)) { yy = yy - side; }
534 if(zz < (-sideh)) { zz = zz + side; }
535 if(zz > (sideh)) { zz = zz - side; }
538 rd = xx*xx + yy*yy + zz*zz;
547 mymd.epot[id].d += (rrd6 - rrd3);
548 r148 = rrd7 - 0.5*rrd4;
549 mymd.vir[id].d += - rd*r148;
553 sh_force2[0][id][i] = sh_force2[0][id][i] - forcex;
558 sh_force2[1][id][i] = sh_force2[1][id][i] - forcey;
563 sh_force2[2][id][i] = sh_force2[2][id][i] - forcez;
565 mymd.interacts[id].i++;
570 sh_force2[0][id][x] = sh_force2[0][id][x] + fxi;
571 sh_force2[1][id][x] = sh_force2[1][id][x] + fyi;
572 sh_force2[2][id][x] = sh_force2[2][id][x] + fzi;
576 public double mkekin(double hsq2,int part_id) {
580 xvelocity = xvelocity + sh_force[0][part_id];
581 yvelocity = yvelocity + sh_force[1][part_id];
582 zvelocity = zvelocity + sh_force[2][part_id];
584 sumt = (xvelocity*xvelocity)+(yvelocity*yvelocity)+(zvelocity*zvelocity);
588 public double velavg(double vaverh,double h) {
593 sq = Math.sqrt(xvelocity*xvelocity + yvelocity*yvelocity +
594 zvelocity*zvelocity);
600 public void dscal(double sc,int incx) {
601 xvelocity = xvelocity * sc;
602 yvelocity = yvelocity * sc;
603 zvelocity = zvelocity * sc;
612 public random(int iseed,double v1,double v2) {
618 public double update() {
621 double scale= 4.656612875e-10;
625 int imod = 2147483647;
627 if (iseed<=0) { iseed = 1; }
630 is1 = (iseed-is2)/32768;
633 is1 = (is1*imult+(iss2-is2)/32768) % (65536);
635 iseed = (is1*32768+is2) % imod;
637 rand = scale * iseed;
643 public double seed() {
657 r = Math.sqrt(-2.0*Math.log(s)/s);