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[3];
60 PARTSIZE = mm*mm*mm*4;
70 public static void JGFapplication(JGFMolDynBench mold) {
72 //BarrierServer mybarr;
74 int[] mid = new int[8];
75 mid[0] = (128<<24)|(195<<16)|(175<<8)|84;//dw-10
76 mid[1] = (128<<24)|(195<<16)|(175<<8)|85;//dw-11
77 mid[2] = (128<<24)|(195<<16)|(175<<8)|86;//dw-12
78 mid[3] = (128<<24)|(195<<16)|(175<<8)|87;//dw-13
79 mid[4] = (128<<24)|(195<<16)|(175<<8)|88;//dw-14
80 mid[5] = (128<<24)|(195<<16)|(175<<8)|89;//dw-15
81 mid[6] = (128<<24)|(195<<16)|(175<<8)|90;//dw-16
82 mid[7] = (128<<24)|(195<<16)|(175<<8)|91;//dw-17
86 double sh_force2 [][][];
87 int partsize, numthreads;
88 partsize = mold.PARTSIZE;
89 numthreads = mold.nthreads;
90 //mybarr = new BarrierServer(numthreads);
91 //mybarr.start(mid[0]);
93 sh_force = new double[3][partsize];
94 sh_force2 = new double[3][numthreads][partsize];
95 mold.epot = new DoubleWrapper[numthreads];
96 mold.vir = new DoubleWrapper[numthreads];
97 mold.ek = new DoubleWrapper[numthreads];
98 mold.interacts = new IntWrapper[numthreads];
99 for(int i=0;i<numthreads;i++) {
100 mold.epot[i]=new DoubleWrapper();
101 mold.vir[i]=new DoubleWrapper();
102 mold.ek[i]=new DoubleWrapper();
103 mold.interacts[i]=new IntWrapper();
107 MDWrap[] thobjects = new MDWrap[numthreads];
109 for(int i=0;i<numthreads;i++) {
110 thobjects[i] = new MDWrap(new mdRunner(i,mold.mm,sh_force,sh_force2,mold.nthreads,mold));
114 boolean waitfordone=true;
121 for(int i=0;i<numthreads;i++) {
122 //thobjects[i].md.start(mid[i]);
123 thobjects[i].md.run();
127 public void JGFvalidate(){
128 double[] refval = new double[2];
129 refval[0] = 1731.4306625334357;
130 refval[1] = 7397.392307839352;
131 double dev = Math.fabs(ek[0].d - refval[size]);
133 //System.printString("Validation failed\n");
134 //System.printString("Kinetic Energy = " + (long)ek[0] + " " + (long)dev + " " + size + "\n");
143 double l,rcoff,rcoffs,side,sideh,hsq,hsq2,vel,velt;
144 double a,r,sum,tscale,sc,ekin,ts,sp;
148 double vaver,vaverh,rand;
149 double etot,temp,pres,rp;
150 double u1, u2, s, xx, yy, zz;
151 double xvelocity, yvelocity, zvelocity;
153 double [][] sh_force;
154 double [][][] sh_force2;
156 int ijk,npartm,iseed,tint;
164 public mdRunner(int id, int mm, double [][] sh_force, double [][][] sh_force2,
165 int nthreads, JGFMolDynBench mymd) {
168 this.sh_force=sh_force;
169 this.sh_force2=sh_force2;
170 this.nthreads = nthreads;
181 public void init(particle[] one, int mdsize) {
183 for (int lg=0; lg<=1; lg++) {
184 for (int i=0; i<mm; i++) {
185 for (int j=0; j<mm; j++) {
186 for (int k=0; k<mm; k++) {
187 one[ijk] = new particle((i*a+lg*a*0.5),(j*a+lg*a*0.5),(k*a),
188 xvelocity,yvelocity,zvelocity,sh_force,sh_force2,id,one);
195 for (int lg=1; lg<=2; lg++) {
196 for (int i=0; i<mm; i++) {
197 for (int j=0; j<mm; j++) {
198 for (int k=0; k<mm; k++) {
199 one[ijk] = new particle((i*a+(2-lg)*a*0.5),(j*a+(lg-1)*a*0.5),
200 (k*a+a*0.5),xvelocity,yvelocity,zvelocity,sh_force,sh_force2,id,one);
207 /* Initialise velocities */
212 random randnum = new random(iseed,v1,v2);
215 for (int i=0; i<mdsize; i+=2) {
217 one[i].xvelocity = r*randnum.v1;
218 one[i+1].xvelocity = r*randnum.v2;
221 for (int i=0; i<mdsize; i+=2) {
223 one[i].yvelocity = r*randnum.v1;
224 one[i+1].yvelocity = r*randnum.v2;
227 for (int i=0; i<mdsize; i+=2) {
229 one[i].zvelocity = r*randnum.v1;
230 one[i+1].zvelocity = r*randnum.v2;
234 /* velocity scaling */
239 for(int i=0;i<mdsize;i++) {
240 sp = sp + one[i].xvelocity;
244 for(int i=0;i<mdsize;i++) {
245 one[i].xvelocity = one[i].xvelocity - sp;
246 ekin = ekin + one[i].xvelocity*one[i].xvelocity;
250 for(int i=0;i<mdsize;i++) {
251 sp = sp + one[i].yvelocity;
255 for(int i=0;i<mdsize;i++) {
256 one[i].yvelocity = one[i].yvelocity - sp;
257 ekin = ekin + one[i].yvelocity*one[i].yvelocity;
262 for(int i=0;i<mdsize;i++) {
263 sp = sp + one[i].zvelocity;
267 for(int i=0;i<mdsize;i++) {
268 one[i].zvelocity = one[i].zvelocity - sp;
269 ekin = ekin + one[i].zvelocity*one[i].zvelocity;
273 sc = h * Math.sqrt(tref/ts);
276 for(int i=0;i<mdsize;i++) {
278 one[i].xvelocity = one[i].xvelocity * sc;
279 one[i].yvelocity = one[i].yvelocity * sc;
280 one[i].zvelocity = one[i].zvelocity * sc;
286 public void doinit(int mdsize) {
287 for(int j=0;j<3;j++) {
288 double[] sh=sh_force[j];
289 for (int i=0;i<mdsize;i++) {
296 public void doinit2(int mdsize) {
297 for(int k=0;k<3;k++) {
298 double[] sh=sh_force[k];
299 double [][] sha=sh_force2[k];
300 for(int j=0;j<nthreads;j++) {
301 double[] sha2=sha[j];
302 for(int i=0;i<mdsize;i++) {
308 for(int k=0;k<3;k++) {
309 double [][] sh1=sh_force2[k];
310 for(int j=0;j<nthreads;j++) {
312 for(int i=0;i<mdsize;i++) {
320 for(int j=1;j<nthreads;j++) {
321 mymd.epot[0].d += mymd.epot[j].d;
322 mymd.vir[0].d += mymd.vir[j].d;
324 for(int j=1;j<nthreads;j++) {
325 mymd.epot[j].d = mymd.epot[0].d;
326 mymd.vir[j].d = mymd.vir[0].d;
328 for(int j=0;j<nthreads;j++) {
329 mymd.interactions += mymd.interacts[j].i;
332 for (int j=0;j<3;j++) {
333 double sh[]=sh_force[j];
334 for (int i=0;i<mdsize;i++) {
335 sh[i] = sh[i] * hsq2;
341 /* Parameter determination */
346 //Barrier barr=new Barrier("128.195.175.84");
350 mdsize = mymd.PARTSIZE;
351 one=new particle[mdsize];
354 side = Math.pow((mdsize/tmpden),0.3333333);
362 rcoffs = rcoff * rcoff;
363 tscale = 16.0 / (1.0 * mdsize - 1.0);
364 vaver = 1.13 * Math.sqrt(tref / 24.0);
367 /* Particle Generation */
376 /* Synchronise threads and start timer before MD simulation */
378 //Barrier.enterBarrier(barr);
382 for (int move=0;move<movemx;move++) {
383 /* move the particles and update velocities */
384 for (int i=0;i<mdsize;i++) {
385 one[i].domove(side,i);
389 //Barrier.enterBarrier(barr);
395 mymd.epot[id].d = 0.0;
396 mymd.vir[id].d = 0.0;
397 mymd.interacts[id].i = 0;
401 //Barrier.enterBarrier(barr);
405 for (int i=0+id;i<mdsize;i+=nthreads) {
406 one[i].force(side,rcoff,mdsize,i,xx,yy,zz,mymd);
410 //Barrier.enterBarrier(barr);
412 /* update force arrays */
418 //Barrier.enterBarrier(barr);
420 /*scale forces, update velocities */
422 for (int i=0;i<mdsize;i++) {
423 sum = sum + one[i].mkekin(hsq2,i);
431 /* average velocity */
433 for (int i=0;i<mdsize;i++) {
434 velt = one[i].velavg(vaverh,h);
435 if(velt > vaverh) { count = count + 1.0; }
441 /* temperature scale if required */
443 if((move < istop) && (((move+1) % irep) == 0)) {
444 sc = Math.sqrt(tref / (tscale*ekin));
445 for (int i=0;i<mdsize;i++) {
448 ekin = tref / tscale;
451 /* sum to get full potential energy and virial */
453 if(((move+1) % iprint) == 0) {
454 mymd.ek[id].d = 24.0*ekin;
455 mymd.epot[id].d = 4.0*mymd.epot[id].d;
456 etot = mymd.ek[id].d + mymd.epot[id].d;
457 temp = tscale * ekin;
458 pres = tmpden * 16.0 * (ekin - mymd.vir[id].d) / mdsize;
460 rp = (count / mdsize) * 100.0;
462 //Barrier.enterBarrier(barr);
464 //if (id == 0) JGFInstrumentor.stopTimer("Section3:MolDyn:Run", instr.timers);
471 public double xcoord, ycoord, zcoord;
472 public double xvelocity,yvelocity,zvelocity;
475 double [][] sh_force;
476 double [][][] sh_force2;
479 public particle(double xcoord, double ycoord, double zcoord, double xvelocity,
480 double yvelocity,double zvelocity, double [][] sh_force,
481 double [][][] sh_force2,int id, particle[] one) {
483 this.xcoord = xcoord;
484 this.ycoord = ycoord;
485 this.zcoord = zcoord;
486 this.xvelocity = xvelocity;
487 this.yvelocity = yvelocity;
488 this.zvelocity = zvelocity;
489 this.sh_force = sh_force;
490 this.sh_force2 = sh_force2;
495 public void domove(double side,int part_id) {
497 xcoord = xcoord + xvelocity + sh_force[0][part_id];
498 ycoord = ycoord + yvelocity + sh_force[1][part_id];
499 zcoord = zcoord + zvelocity + sh_force[2][part_id];
501 if(xcoord < 0) { xcoord = xcoord + side; }
502 if(xcoord > side) { xcoord = xcoord - side; }
503 if(ycoord < 0) { ycoord = ycoord + side; }
504 if(ycoord > side) { ycoord = ycoord - side; }
505 if(zcoord < 0) { zcoord = zcoord + side; }
506 if(zcoord > side) { zcoord = zcoord - side; }
508 xvelocity = xvelocity + sh_force[0][part_id];
509 yvelocity = yvelocity + sh_force[1][part_id];
510 zvelocity = zvelocity + sh_force[2][part_id];
514 public void force(double side, double rcoff,int mdsize,int x, double xx, double yy, double zz, JGFMolDynBench mymd) {
520 double rd,rrd,rrd2,rrd3,rrd4,rrd6,rrd7,r148;
521 double forcex,forcey,forcez;
524 rcoffs = rcoff*rcoff;
530 for (int i=x+1;i<mdsize;i++) {
531 xx = this.xcoord - one[i].xcoord;
532 yy = this.ycoord - one[i].ycoord;
533 zz = this.zcoord - one[i].zcoord;
535 if(xx < (-sideh)) { xx = xx + side; }
536 if(xx > (sideh)) { xx = xx - side; }
537 if(yy < (-sideh)) { yy = yy + side; }
538 if(yy > (sideh)) { yy = yy - side; }
539 if(zz < (-sideh)) { zz = zz + side; }
540 if(zz > (sideh)) { zz = zz - side; }
543 rd = xx*xx + yy*yy + zz*zz;
552 mymd.epot[id].d += (rrd6 - rrd3);
553 r148 = rrd7 - 0.5*rrd4;
554 mymd.vir[id].d += - rd*r148;
558 sh_force2[0][id][i] = sh_force2[0][id][i] - forcex;
563 sh_force2[1][id][i] = sh_force2[1][id][i] - forcey;
568 sh_force2[2][id][i] = sh_force2[2][id][i] - forcez;
570 mymd.interacts[id].i++;
575 sh_force2[0][id][x] = sh_force2[0][id][x] + fxi;
576 sh_force2[1][id][x] = sh_force2[1][id][x] + fyi;
577 sh_force2[2][id][x] = sh_force2[2][id][x] + fzi;
581 public double mkekin(double hsq2,int part_id) {
585 xvelocity = xvelocity + sh_force[0][part_id];
586 yvelocity = yvelocity + sh_force[1][part_id];
587 zvelocity = zvelocity + sh_force[2][part_id];
589 sumt = (xvelocity*xvelocity)+(yvelocity*yvelocity)+(zvelocity*zvelocity);
593 public double velavg(double vaverh,double h) {
598 sq = Math.sqrt(xvelocity*xvelocity + yvelocity*yvelocity +
599 zvelocity*zvelocity);
605 public void dscal(double sc,int incx) {
606 xvelocity = xvelocity * sc;
607 yvelocity = yvelocity * sc;
608 zvelocity = zvelocity * sc;
617 public random(int iseed,double v1,double v2) {
623 public double update() {
626 double scale= 4.656612875e-10;
630 int imod = 2147483647;
632 if (iseed<=0) { iseed = 1; }
635 is1 = (iseed-is2)/32768;
638 is1 = (is1*imult+(iss2-is2)/32768) % (65536);
640 iseed = (is1*32768+is2) % imod;
642 rand = scale * iseed;
648 public double seed() {
662 r = Math.sqrt(-2.0*Math.log(s)/s);