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 {
38 public int interactions;
39 public int[] 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 mold.epot = global new double [mold.nthreads];
73 mold.vir = global new double [mold.nthreads];
74 mold.ek = global new double [mold.nthreads];
75 mold.interacts = global new int [mold.nthreads];
78 int partsize, numthreads;
80 partsize = mold.PARTSIZE;
81 numthreads = mold.nthreads;
85 double sh_force2 [][][];
87 sh_force = global new double[3][partsize];
88 sh_force2 = global new double[3][numthreads][partsize];
95 thobjects = global new mdRunner[numthreads];
96 br= global new Barrier(numthreads);
99 int[] mid = new int[4];
100 mid[0] = (128<<24)|(195<<16)|(175<<8)|73;
101 mid[1] = (128<<24)|(195<<16)|(175<<8)|69;
102 mid[2] = (128<<24)|(195<<16)|(175<<8)|79;
103 mid[3] = (128<<24)|(195<<16)|(175<<8)|78;
106 for(int i=1;i<numthreads;i++) {
108 thobjects[i] = global new mdRunner(i,mold.mm,sh_force,sh_force2,br,mold.nthreads,mold);
115 thobjects[0] = global new mdRunner(0,mold.mm,sh_force,sh_force2,br,mold.nthreads,mold);
121 for(int i=1;i<numthreads;i++) {
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] - 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 {
144 int id,i,j,k,lg,mdsize,mm;
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,v1,v2,s, xx, yy, zz;
153 double xvelocity, yvelocity, zvelocity;
155 double [][] sh_force;
156 double [][][] sh_force2;
158 int ijk,npartm,iseed,tint;
170 public mdRunner(int id, int mm, double [][] sh_force, double [][][] sh_force2,Barrier br,
171 int nthreads, JGFMolDynBench mymd) {
174 this.sh_force=sh_force;
175 this.sh_force2=sh_force2;
177 this.nthreads = nthreads;
190 /* Parameter determination */
199 mdsize = mymd.PARTSIZE;
200 one = global new particle[mdsize];
204 side = Math.pow((tmpmdsize/tmpden),0.3333333);
211 npartm = tmpmdsize - 1;
212 rcoffs = rcoff * rcoff;
213 tscale = 16.0 / (1.0 * tmpmdsize - 1.0);
214 vaver = 1.13 * Math.sqrt(tref / 24.0);
217 /* Particle Generation */
224 for (lg=0; lg<=1; lg++) {
225 for (i=0; i<mm; i++) {
226 for (j=0; j<mm; j++) {
227 for (k=0; k<mm; k++) {
228 one[ijk] = global new particle((i*a+lg*a*0.5),(j*a+lg*a*0.5),(k*a),
229 xvelocity,yvelocity,zvelocity,sh_force,sh_force2,id,this);
236 for (lg=1; lg<=2; lg++) {
237 for (i=0; i<mm; i++) {
238 for (j=0; j<mm; j++) {
239 for (k=0; k<mm; k++) {
240 one[ijk] = global new particle((i*a+(2-lg)*a*0.5),(j*a+(lg-1)*a*0.5),
241 (k*a+a*0.5),xvelocity,yvelocity,zvelocity,sh_force,sh_force2,id,this);
248 /* Initialise velocities */
253 randnum = global new random(iseed,v1,v2);
255 for (i=0; i<tmpmdsize; i+=2) {
257 one[i].xvelocity = r*randnum.v1;
258 one[i+1].xvelocity = r*randnum.v2;
261 for (i=0; i<tmpmdsize; i+=2) {
263 one[i].yvelocity = r*randnum.v1;
264 one[i+1].yvelocity = r*randnum.v2;
267 for (i=0; i<tmpmdsize; i+=2) {
269 one[i].zvelocity = r*randnum.v1;
270 one[i+1].zvelocity = r*randnum.v2;
274 /* velocity scaling */
279 for(i=0;i<tmpmdsize;i++) {
280 sp = sp + one[i].xvelocity;
284 for(i=0;i<tmpmdsize;i++) {
285 one[i].xvelocity = one[i].xvelocity - sp;
286 ekin = ekin + one[i].xvelocity*one[i].xvelocity;
290 for(i=0;i<tmpmdsize;i++) {
291 sp = sp + one[i].yvelocity;
295 for(i=0;i<tmpmdsize;i++) {
296 one[i].yvelocity = one[i].yvelocity - sp;
297 ekin = ekin + one[i].yvelocity*one[i].yvelocity;
302 for(i=0;i<tmpmdsize;i++) {
303 sp = sp + one[i].zvelocity;
307 for(i=0;i<tmpmdsize;i++) {
308 one[i].zvelocity = one[i].zvelocity - sp;
309 ekin = ekin + one[i].zvelocity*one[i].zvelocity;
313 sc = h * Math.sqrt(tref/ts);
316 for(i=0;i<tmpmdsize;i++) {
318 one[i].xvelocity = one[i].xvelocity * sc;
319 one[i].yvelocity = one[i].yvelocity * sc;
320 one[i].zvelocity = one[i].zvelocity * sc;
325 /* Synchronise threads and start timer before MD simulation */
327 Barrier.enterBarrier(tmpbr);
328 System.clearPrefetchCache();
332 for (int move=0;move<movemx;move++) {
334 /* move the particles and update velocities */
336 for (i=0;i<tmpmdsize;i++) {
337 one[i].domove(side,i);
342 Barrier.enterBarrier(tmpbr);
343 System.clearPrefetchCache();
349 for (i=0;i<tmpmdsize;i++) {
350 sh_force[j][i] = 0.0;
357 mymd.interacts[id] = 0;
362 Barrier.enterBarrier(tmpbr);
363 System.clearPrefetchCache();
368 for (i=0+id;i<tmpmdsize;i+=nthreads) {
369 one[i].force(side,rcoff,tmpmdsize,i,xx,yy,zz,mymd);
374 Barrier.enterBarrier(tmpbr);
375 System.clearPrefetchCache();
377 /* update force arrays */
381 for(int k=0;k<3;k++) {
382 for(i=0;i<tmpmdsize;i++) {
383 for(j=0;j<nthreads;j++) {
384 sh_force[k][i] += sh_force2[k][j][i];
391 for(int k=0;k<3;k++) {
392 for(i=0;i<tmpmdsize;i++) {
393 for(j=0;j<nthreads;j++) {
394 sh_force2[k][j][i] = 0.0;
401 for(j=1;j<nthreads;j++) {
402 mymd.epot[0] += mymd.epot[j];
403 mymd.vir[0] += mymd.vir[j];
405 for(j=1;j<nthreads;j++) {
406 mymd.epot[j] = mymd.epot[0];
407 mymd.vir[j] = mymd.vir[0];
409 for(j=0;j<nthreads;j++) {
410 mymd.interactions += mymd.interacts[j];
416 Barrier.enterBarrier(tmpbr);
417 System.clearPrefetchCache();
422 for (i=0;i<tmpmdsize;i++) {
423 sh_force[j][i] = sh_force[j][i] * hsq2;
433 Barrier.enterBarrier(tmpbr);
434 System.clearPrefetchCache();
437 /*scale forces, update velocities */
439 for (i=0;i<tmpmdsize;i++) {
440 sum = sum + one[i].mkekin(hsq2,i);
448 /* average velocity */
450 for (i=0;i<tmpmdsize;i++) {
451 velt = one[i].velavg(vaverh,h);
452 if(velt > vaverh) { count = count + 1.0; }
458 /* temperature scale if required */
460 if((move < istop) && (((move+1) % irep) == 0)) {
461 sc = Math.sqrt(tref / (tscale*ekin));
462 for (i=0;i<tmpmdsize;i++) {
465 ekin = tref / tscale;
468 /* sum to get full potential energy and virial */
470 if(((move+1) % iprint) == 0) {
471 mymd.ek[id] = 24.0*ekin;
472 mymd.epot[id] = 4.0*mymd.epot[id];
473 etot = mymd.ek[id] + mymd.epot[id];
474 temp = tscale * ekin;
475 pres = tmpden * 16.0 * (ekin - mymd.vir[id]) / tmpmdsize;
476 vel = vel / tmpmdsize;
477 rp = (count / tmpmdsize) * 100.0;
480 Barrier.enterBarrier(tmpbr);
481 System.clearPrefetchCache();
484 Barrier.enterBarrier(tmpbr);
485 System.clearPrefetchCache();
486 //if (id == 0) JGFInstrumentor.stopTimer("Section3:MolDyn:Run", instr.timers);
493 public double xcoord, ycoord, zcoord;
494 public double xvelocity,yvelocity,zvelocity;
497 double [][] sh_force;
498 double [][][] sh_force2;
501 public particle(double xcoord, double ycoord, double zcoord, double xvelocity,
502 double yvelocity,double zvelocity,double [][] sh_force,
503 double [][][] sh_force2,int id,mdRunner runner) {
505 this.xcoord = xcoord;
506 this.ycoord = ycoord;
507 this.zcoord = zcoord;
508 this.xvelocity = xvelocity;
509 this.yvelocity = yvelocity;
510 this.zvelocity = zvelocity;
511 this.sh_force = sh_force;
512 this.sh_force2 = sh_force2;
517 public void domove(double side,int part_id) {
519 xcoord = xcoord + xvelocity + sh_force[0][part_id];
520 ycoord = ycoord + yvelocity + sh_force[1][part_id];
521 zcoord = zcoord + zvelocity + sh_force[2][part_id];
523 if(xcoord < 0) { xcoord = xcoord + side; }
524 if(xcoord > side) { xcoord = xcoord - side; }
525 if(ycoord < 0) { ycoord = ycoord + side; }
526 if(ycoord > side) { ycoord = ycoord - side; }
527 if(zcoord < 0) { zcoord = zcoord + side; }
528 if(zcoord > side) { zcoord = zcoord - side; }
530 xvelocity = xvelocity + sh_force[0][part_id];
531 yvelocity = yvelocity + sh_force[1][part_id];
532 zvelocity = zvelocity + sh_force[2][part_id];
536 public void force(double side, double rcoff,int mdsize,int x, double xx, double yy, double zz, JGFMolDynBench mymd) {
542 double rd,rrd,rrd2,rrd3,rrd4,rrd6,rrd7,r148;
543 double forcex,forcey,forcez;
546 rcoffs = rcoff*rcoff;
552 for (int i=x+1;i<mdsize;i++) {
553 xx = this.xcoord - runner.one[i].xcoord;
554 yy = this.ycoord - runner.one[i].ycoord;
555 zz = this.zcoord - runner.one[i].zcoord;
557 if(xx < (-sideh)) { xx = xx + side; }
558 if(xx > (sideh)) { xx = xx - side; }
559 if(yy < (-sideh)) { yy = yy + side; }
560 if(yy > (sideh)) { yy = yy - side; }
561 if(zz < (-sideh)) { zz = zz + side; }
562 if(zz > (sideh)) { zz = zz - side; }
565 rd = xx*xx + yy*yy + zz*zz;
574 mymd.epot[id] = mymd.epot[id] + (rrd6 - rrd3);
575 r148 = rrd7 - 0.5*rrd4;
576 mymd.vir[id] = mymd.vir[id] - rd*r148;
580 sh_force2[0][id][i] = sh_force2[0][id][i] - forcex;
585 sh_force2[1][id][i] = sh_force2[1][id][i] - forcey;
590 sh_force2[2][id][i] = sh_force2[2][id][i] - forcez;
592 mymd.interacts[id]++;
597 sh_force2[0][id][x] = sh_force2[0][id][x] + fxi;
598 sh_force2[1][id][x] = sh_force2[1][id][x] + fyi;
599 sh_force2[2][id][x] = sh_force2[2][id][x] + fzi;
603 public double mkekin(double hsq2,int part_id) {
607 xvelocity = xvelocity + sh_force[0][part_id];
608 yvelocity = yvelocity + sh_force[1][part_id];
609 zvelocity = zvelocity + sh_force[2][part_id];
611 sumt = (xvelocity*xvelocity)+(yvelocity*yvelocity)+(zvelocity*zvelocity);
615 public double velavg(double vaverh,double h) {
620 sq = Math.sqrt(xvelocity*xvelocity + yvelocity*yvelocity +
621 zvelocity*zvelocity);
627 public void dscal(double sc,int incx) {
629 xvelocity = xvelocity * sc;
630 yvelocity = yvelocity * sc;
631 zvelocity = zvelocity * sc;
644 public random(int iseed,double v1,double v2) {
650 public double update() {
653 double scale= 4.656612875e-10;
657 int imod = 2147483647;
659 if (iseed<=0) { iseed = 1; }
662 is1 = (iseed-is2)/32768;
665 is1 = (is1*imult+(iss2-is2)/32768) % (65536);
667 iseed = (is1*32768+is2) % imod;
669 rand = scale * iseed;
675 public double seed() {
689 r = Math.sqrt(-2.0*Math.log(s)/s);