Demo entry 6350240

force-acc

   

Submitted by anonymous on Mar 09, 2017 at 00:33
Language: C. Code size: 2.1 kB.

   #pragma acc parallel loop independent gang vector reduction(+:ePot) \
								present(s_boxes_nAtoms[0:s_boxes_nTotalBoxes], \
										s_boxes_nbrBoxes_array[0:s_boxes_nLocalBoxes * nNbrBoxes], \
										s_atoms_r[0:fSize][0:3],\
										s_atoms_f[0:fSize][0:3],\
										s_atoms_U[0:fSize])
   for (int iBox=0; iBox < s_boxes_nLocalBoxes; iBox++)
   {
      int nIBox = s_boxes_nAtoms[iBox];
   
      // loop over neighbors of iBox
      #pragma acc loop independent
      for (int jTmp=0; jTmp<nNbrBoxes; jTmp++)
      {
    	   int jBox = s_boxes_nbrBoxes_array[iBox * nNbrBoxes + jTmp];
         int nJBox = s_boxes_nAtoms[jBox];
         
         // loop over atoms in iBox
         #pragma acc loop independent
         for (int iOff=MAXATOMS*iBox; iOff<(iBox*MAXATOMS+nIBox); iOff++)
         {

            // loop over atoms in jBox
         	#pragma acc loop independent
            for (int jOff=jBox*MAXATOMS; jOff<(jBox*MAXATOMS+nJBox); jOff++)
            {
               real3 dr;
               real_t r2 = 0.0;

               dr[0] = s_atoms_r[iOff][0] - s_atoms_r[jOff][0];
               dr[1] = s_atoms_r[iOff][1] - s_atoms_r[jOff][1];
               dr[2] = s_atoms_r[iOff][2] - s_atoms_r[jOff][2];
               r2 += dr[0]*dr[0];
               r2 += dr[1]*dr[1];
               r2 += dr[2]*dr[2];

               if ( r2 <= rCut2 && r2 > 0.0)
               {

                  // Important note:
               	// from this point on r actually refers to 1.0/r
                  r2 = 1.0/r2;
                  real_t r6 = s6 * (r2*r2*r2);
                  real_t eLocal = r6 * (r6 - 1.0) - eShift;
                  s_atoms_U[iOff] += 0.5*eLocal;
                  ePot += 0.5*eLocal;

                  // different formulation to avoid sqrt computation
                  real_t fr = -4.0*epsilon*r6*r2*(12.0*r6 - 6.0);

                  s_atoms_f[iOff][0] -= dr[0]*fr;
                  s_atoms_f[iOff][1] -= dr[1]*fr;
                  s_atoms_f[iOff][2] -= dr[2]*fr;
               }
            }
         }
      }
   }

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).