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 double sh_force2 [][][];
73 int partsize, numthreads;
74 partsize = mold.PARTSIZE;
75 numthreads = mold.nthreads;
77 sh_force = new double[3][partsize];
78 sh_force2 = new double[3][numthreads][partsize];
79 mold.epot = new DoubleWrapper[numthreads];
80 mold.vir = new DoubleWrapper[numthreads];
81 mold.ek = new DoubleWrapper[numthreads];
82 mold.interacts = new IntWrapper[numthreads];
83 for(int i=0;i<numthreads;i++) {
84 mold.epot[i]=new DoubleWrapper();
85 mold.vir[i]=new DoubleWrapper();
86 mold.ek[i]=new DoubleWrapper();
87 mold.interacts[i]=new IntWrapper();
91 MDWrap[] thobjects = new MDWrap[numthreads];
93 for(int i=0;i<numthreads;i++) {
94 thobjects[i] = new MDWrap(new mdRunner(i,mold.mm,sh_force,sh_force2,mold.nthreads,mold));
98 boolean waitfordone=true;
105 for(int i=0;i<numthreads;i++) {
106 //thobjects[i].md.start(mid[i]);
107 thobjects[i].md.run();
111 public void JGFvalidate(){
112 double[] refval = new double[2];
113 refval[0] = 1731.4306625334357;
114 refval[1] = 7397.392307839352;
115 double dev = Math.fabs(ek[0].d - refval[size]);
117 //System.printString("Validation failed\n");
118 //System.printString("Kinetic Energy = " + (long)ek[0] + " " + (long)dev + " " + size + "\n");
127 double l,rcoff,rcoffs,side,sideh,hsq,hsq2,vel,velt;
128 double a,r,sum,tscale,sc,ekin,ts,sp;
132 double vaver,vaverh,rand;
133 double etot,temp,pres,rp;
134 double u1, u2, s, xx, yy, zz;
135 double xvelocity, yvelocity, zvelocity;
137 double [][] sh_force;
138 double [][][] sh_force2;
140 int ijk,npartm,iseed,tint;
148 public mdRunner(int id, int mm, double [][] sh_force, double [][][] sh_force2,
149 int nthreads, JGFMolDynBench mymd) {
152 this.sh_force=sh_force;
153 this.sh_force2=sh_force2;
154 this.nthreads = nthreads;
165 public void init(particle[] one, int mdsize) {
167 for (int lg=0; lg<=1; lg++) {
168 for (int i=0; i<mm; i++) {
169 for (int j=0; j<mm; j++) {
170 for (int k=0; k<mm; k++) {
171 one[ijk] = new particle((i*a+lg*a*0.5),(j*a+lg*a*0.5),(k*a),
172 xvelocity,yvelocity,zvelocity,sh_force,sh_force2,id,one);
179 for (int lg=1; lg<=2; lg++) {
180 for (int i=0; i<mm; i++) {
181 for (int j=0; j<mm; j++) {
182 for (int k=0; k<mm; k++) {
183 one[ijk] = new particle((i*a+(2-lg)*a*0.5),(j*a+(lg-1)*a*0.5),
184 (k*a+a*0.5),xvelocity,yvelocity,zvelocity,sh_force,sh_force2,id,one);
191 /* Initialise velocities */
196 random randnum = new random(iseed,v1,v2);
199 for (int i=0; i<mdsize; i+=2) {
201 one[i].xvelocity = r*randnum.v1;
202 one[i+1].xvelocity = r*randnum.v2;
205 for (int i=0; i<mdsize; i+=2) {
207 one[i].yvelocity = r*randnum.v1;
208 one[i+1].yvelocity = r*randnum.v2;
211 for (int i=0; i<mdsize; i+=2) {
213 one[i].zvelocity = r*randnum.v1;
214 one[i+1].zvelocity = r*randnum.v2;
218 /* velocity scaling */
223 for(int i=0;i<mdsize;i++) {
224 sp = sp + one[i].xvelocity;
228 for(int i=0;i<mdsize;i++) {
229 one[i].xvelocity = one[i].xvelocity - sp;
230 ekin = ekin + one[i].xvelocity*one[i].xvelocity;
234 for(int i=0;i<mdsize;i++) {
235 sp = sp + one[i].yvelocity;
239 for(int i=0;i<mdsize;i++) {
240 one[i].yvelocity = one[i].yvelocity - sp;
241 ekin = ekin + one[i].yvelocity*one[i].yvelocity;
246 for(int i=0;i<mdsize;i++) {
247 sp = sp + one[i].zvelocity;
251 for(int i=0;i<mdsize;i++) {
252 one[i].zvelocity = one[i].zvelocity - sp;
253 ekin = ekin + one[i].zvelocity*one[i].zvelocity;
257 sc = h * Math.sqrt(tref/ts);
260 for(int i=0;i<mdsize;i++) {
262 one[i].xvelocity = one[i].xvelocity * sc;
263 one[i].yvelocity = one[i].yvelocity * sc;
264 one[i].zvelocity = one[i].zvelocity * sc;
270 public void doinit(int mdsize) {
271 for(int j=0;j<3;j++) {
272 double[] sh=sh_force[j];
273 for (int i=0;i<mdsize;i++) {
280 public void doinit2(int mdsize) {
281 for(int k=0;k<3;k++) {
282 double[] sh=sh_force[k];
283 double [][] sha=sh_force2[k];
284 for(int j=0;j<nthreads;j++) {
285 double[] sha2=sha[j];
286 for(int i=0;i<mdsize;i++) {
292 for(int k=0;k<3;k++) {
293 double [][] sh1=sh_force2[k];
294 for(int j=0;j<nthreads;j++) {
296 for(int i=0;i<mdsize;i++) {
304 for(int j=1;j<nthreads;j++) {
305 mymd.epot[0].d += mymd.epot[j].d;
306 mymd.vir[0].d += mymd.vir[j].d;
308 for(int j=1;j<nthreads;j++) {
309 mymd.epot[j].d = mymd.epot[0].d;
310 mymd.vir[j].d = mymd.vir[0].d;
312 for(int j=0;j<nthreads;j++) {
313 mymd.interactions += mymd.interacts[j].i;
316 for (int j=0;j<3;j++) {
317 double sh[]=sh_force[j];
318 for (int i=0;i<mdsize;i++) {
319 sh[i] = sh[i] * hsq2;
325 /* Parameter determination */
333 mdsize = mymd.PARTSIZE;
334 one=new particle[mdsize];
337 side = Math.pow((mdsize/tmpden),0.3333333);
345 rcoffs = rcoff * rcoff;
346 tscale = 16.0 / (1.0 * mdsize - 1.0);
347 vaver = 1.13 * Math.sqrt(tref / 24.0);
350 /* Particle Generation */
359 /* Synchronise threads and start timer before MD simulation */
364 for (int move=0;move<movemx;move++) {
365 /* move the particles and update velocities */
366 for (int i=0;i<mdsize;i++) {
367 one[i].domove(side,i);
375 mymd.epot[id].d = 0.0;
376 mymd.vir[id].d = 0.0;
377 mymd.interacts[id].i = 0;
383 for (int i=0+id;i<mdsize;i+=nthreads) {
384 one[i].force(side,rcoff,mdsize,i,xx,yy,zz,mymd);
388 /* update force arrays */
394 /*scale forces, update velocities */
396 for (int i=0;i<mdsize;i++) {
397 sum = sum + one[i].mkekin(hsq2,i);
405 /* average velocity */
407 for (int i=0;i<mdsize;i++) {
408 velt = one[i].velavg(vaverh,h);
409 if(velt > vaverh) { count = count + 1.0; }
415 /* temperature scale if required */
417 if((move < istop) && (((move+1) % irep) == 0)) {
418 sc = Math.sqrt(tref / (tscale*ekin));
419 for (int i=0;i<mdsize;i++) {
422 ekin = tref / tscale;
425 /* sum to get full potential energy and virial */
427 if(((move+1) % iprint) == 0) {
428 mymd.ek[id].d = 24.0*ekin;
429 mymd.epot[id].d = 4.0*mymd.epot[id].d;
430 etot = mymd.ek[id].d + mymd.epot[id].d;
431 temp = tscale * ekin;
432 pres = tmpden * 16.0 * (ekin - mymd.vir[id].d) / mdsize;
434 rp = (count / mdsize) * 100.0;
437 //if (id == 0) JGFInstrumentor.stopTimer("Section3:MolDyn:Run", instr.timers);
444 public double xcoord, ycoord, zcoord;
445 public double xvelocity,yvelocity,zvelocity;
448 double [][] sh_force;
449 double [][][] sh_force2;
452 public particle(double xcoord, double ycoord, double zcoord, double xvelocity,
453 double yvelocity,double zvelocity, double [][] sh_force,
454 double [][][] sh_force2,int id, particle[] one) {
456 this.xcoord = xcoord;
457 this.ycoord = ycoord;
458 this.zcoord = zcoord;
459 this.xvelocity = xvelocity;
460 this.yvelocity = yvelocity;
461 this.zvelocity = zvelocity;
462 this.sh_force = sh_force;
463 this.sh_force2 = sh_force2;
468 public void domove(double side,int part_id) {
470 xcoord = xcoord + xvelocity + sh_force[0][part_id];
471 ycoord = ycoord + yvelocity + sh_force[1][part_id];
472 zcoord = zcoord + zvelocity + sh_force[2][part_id];
474 if(xcoord < 0) { xcoord = xcoord + side; }
475 if(xcoord > side) { xcoord = xcoord - side; }
476 if(ycoord < 0) { ycoord = ycoord + side; }
477 if(ycoord > side) { ycoord = ycoord - side; }
478 if(zcoord < 0) { zcoord = zcoord + side; }
479 if(zcoord > side) { zcoord = zcoord - side; }
481 xvelocity = xvelocity + sh_force[0][part_id];
482 yvelocity = yvelocity + sh_force[1][part_id];
483 zvelocity = zvelocity + sh_force[2][part_id];
487 public void force(double side, double rcoff,int mdsize,int x, double xx, double yy, double zz, JGFMolDynBench mymd) {
493 double rd,rrd,rrd2,rrd3,rrd4,rrd6,rrd7,r148;
494 double forcex,forcey,forcez;
497 rcoffs = rcoff*rcoff;
503 for (int i=x+1;i<mdsize;i++) {
504 xx = this.xcoord - one[i].xcoord;
505 yy = this.ycoord - one[i].ycoord;
506 zz = this.zcoord - one[i].zcoord;
508 if(xx < (-sideh)) { xx = xx + side; }
509 if(xx > (sideh)) { xx = xx - side; }
510 if(yy < (-sideh)) { yy = yy + side; }
511 if(yy > (sideh)) { yy = yy - side; }
512 if(zz < (-sideh)) { zz = zz + side; }
513 if(zz > (sideh)) { zz = zz - side; }
516 rd = xx*xx + yy*yy + zz*zz;
525 mymd.epot[id].d += (rrd6 - rrd3);
526 r148 = rrd7 - 0.5*rrd4;
527 mymd.vir[id].d += - rd*r148;
531 sh_force2[0][id][i] = sh_force2[0][id][i] - forcex;
536 sh_force2[1][id][i] = sh_force2[1][id][i] - forcey;
541 sh_force2[2][id][i] = sh_force2[2][id][i] - forcez;
543 mymd.interacts[id].i++;
548 sh_force2[0][id][x] = sh_force2[0][id][x] + fxi;
549 sh_force2[1][id][x] = sh_force2[1][id][x] + fyi;
550 sh_force2[2][id][x] = sh_force2[2][id][x] + fzi;
554 public double mkekin(double hsq2,int part_id) {
558 xvelocity = xvelocity + sh_force[0][part_id];
559 yvelocity = yvelocity + sh_force[1][part_id];
560 zvelocity = zvelocity + sh_force[2][part_id];
562 sumt = (xvelocity*xvelocity)+(yvelocity*yvelocity)+(zvelocity*zvelocity);
566 public double velavg(double vaverh,double h) {
571 sq = Math.sqrt(xvelocity*xvelocity + yvelocity*yvelocity +
572 zvelocity*zvelocity);
578 public void dscal(double sc,int incx) {
579 xvelocity = xvelocity * sc;
580 yvelocity = yvelocity * sc;
581 zvelocity = zvelocity * sc;
590 public random(int iseed,double v1,double v2) {
596 public double update() {
599 double scale= 4.656612875e-10;
603 int imod = 2147483647;
605 if (iseed<=0) { iseed = 1; }
608 is1 = (iseed-is2)/32768;
611 is1 = (is1*imult+(iss2-is2)/32768) % (65536);
613 iseed = (is1*32768+is2) % imod;
615 rand = scale * iseed;
621 public double seed() {
635 r = Math.sqrt(-2.0*Math.log(s)/s);