Added init entry methods to be called during startup phase to fix readonly race condi...
authorDavid Kunzman <kunzman2@illinois.edu>
Mon, 16 Mar 2009 17:47:48 +0000 (17:47 +0000)
committerDavid Kunzman <kunzman2@illinois.edu>
Mon, 16 Mar 2009 17:47:48 +0000 (17:47 +0000)
14 files changed:
examples/charm++/cell/md/Makefile
examples/charm++/cell/md/main.C
examples/charm++/cell/md/main.ci
examples/charm++/cell/md/main.h
examples/charm++/cell/md/md_config.h
examples/charm++/cell/md/pairCompute.C
examples/charm++/cell/md/pairCompute.ci
examples/charm++/cell/md/pairCompute.h
examples/charm++/cell/md/patch.C
examples/charm++/cell/md/patch.ci
examples/charm++/cell/md/patch.h
examples/charm++/cell/md/selfCompute.C
examples/charm++/cell/md/selfCompute.ci
examples/charm++/cell/md/selfCompute.h

index 639af0c17d22cd851ed5a2fc282a4da9082edba8..bf493be231cc1f359e4e194836c385cd4a8b2a94 100644 (file)
@@ -5,7 +5,7 @@ CHARMC = $(CHARM_BIN_DIR)/charmc $(OPTS)
 PGM = md
 
 default: all
-all: $(PGM)
+all: $(PGM) $(PGM)_proj
 
 OBJS = main.o patch.o selfCompute.o pairCompute.o
 SPE_LIBS = -spu-lib m
@@ -40,7 +40,7 @@ main.o: main.h main.C main.decl.h patch.decl.h selfCompute.decl.h pairCompute.de
 patch.decl.h patch.def.h: patch.ci
        $(CHARMC) patch.ci
 
-patch.o: patch.h main.h patch.C patch.decl.h main.decl.h patch.def.h
+patch.o: patch.h main.h patch.C patch.decl.h main.decl.h pairCompute.decl.h patch.def.h
        $(CHARMC) -c patch.C
 
 
index 5d317407d9c2e649cb6bb0b6baaa16f01e2a13df..4de0cfdf20d50f23029c9bb57b6aab565998f89e 100644 (file)
@@ -57,10 +57,18 @@ Main::Main(CkArgMsg* msg) {
   CkPrintf("MD Simulation\n"
            "  Patch Grid: x:%d by y:%d by z:%d\n"
            "  NumParticlesPerPatch: %d\n"
-           "  Simulation Steps: %d\n",
+           "  Simulation Steps: %d\n"
+           #if USE_PROXY_PATCHES != 0
+           "  Proxy Patches Enabled\n"
+           #endif
+           #if USE_ARRAY_SECTIONS != 0
+           "  Array Sections Enabled\n"
+           #endif
+           "  StepPerPrint: %d\n",
            numPatchesX, numPatchesY, numPatchesZ,
            numParticlesPerPatch,
-           numStepsRemaining
+           numStepsRemaining,
+           STEPS_PER_PRINT
          );
 
   // DMK - DEBUG
@@ -76,20 +84,25 @@ Main::Main(CkArgMsg* msg) {
   mainProxy = thisProxy;
 
   // Create the patch array
-  patchArrayProxy = CProxy_Patch::ckNew(numParticlesPerPatch, numPatchesX, numPatchesY, numPatchesZ);
+  patchArrayProxy = CProxy_Patch::ckNew(numPatchesX, numPatchesY, numPatchesZ);
 
   // Create the self compute array
-  selfComputeArrayProxy = CProxy_SelfCompute::ckNew(numParticlesPerPatch, numPatchesX, numPatchesY, numPatchesZ);
+  selfComputeArrayProxy = CProxy_SelfCompute::ckNew(numPatchesX, numPatchesY, numPatchesZ);
 
   // Create the pair compute array
   pairComputeArrayProxy = CProxy_PairCompute::ckNew();
   const int numPatches = numPatchesX * numPatchesY * numPatchesZ;
   for (int p0 = 0; p0 < numPatches; p0++) {
     for (int p1 = p0 + 1; p1 < numPatches; p1++) {
-      pairComputeArrayProxy(p0, p1).insert(numParticlesPerPatch);
+      pairComputeArrayProxy(p0, p1).insert();
     }
   }
   pairComputeArrayProxy.doneInserting();
+
+  // Start initialization (NOTE: Patch will initiate proxy patches directly if proxy patches are being used)
+  patchArrayProxy.init(numParticlesPerPatch);
+  selfComputeArrayProxy.init(numParticlesPerPatch);
+  pairComputeArrayProxy.init(numParticlesPerPatch);
 }
 
 
@@ -97,11 +110,14 @@ Main::~Main() {
 }
 
 
-void Main::proxyCheckIn() {
+void Main::initCheckIn() {
 
   static int numCheckedIn = 0;
   const int numPatches = numPatchesX * numPatchesY * numPatchesZ;
-  const int numToCheckIn = (2 * numPatches) + ((numPatches * (numPatches - 1)) / 2);
+  int numToCheckIn = (2 * numPatches) + ((numPatches * (numPatches - 1)) / 2);
+  #if USE_PROXY_PATCHES != 0
+    numToCheckIn += (numPatches * CkNumPes());
+  #endif
 
   // Count this caller and check to see if everyone has called
   numCheckedIn++;
@@ -115,7 +131,7 @@ void Main::proxyCheckIn() {
     const int numStepsToDo = (numStepsRemaining > STEPS_PER_PRINT) ? (STEPS_PER_PRINT) : (numStepsRemaining);
     patchArrayProxy.startIterations(numStepsToDo);
     CkPrintf("Main::patchCheckIn() - Starting Simulation (%d steps remaining)...\n", numStepsRemaining);
-    numStepsRemaining -= numStepsToDo - 1;
+    numStepsRemaining -= numStepsToDo - 1;    
   }
 }
 
index e839fdd7bc2a0421aa68d0b107bfc11adb2595de..7ccec3e6ba411558ec98c41d414d0b549490c928 100644 (file)
@@ -14,7 +14,7 @@ mainmodule main {
 
   mainchare Main {
     entry Main(CkArgMsg *msg);
-    entry void proxyCheckIn();
+    entry void initCheckIn();
     entry void patchCheckIn();
   };
 
index 18683b1f898ad97f591ca922090485c982333e52..c254799ae0dc0bfff852766f1aec1a5f408d6f73 100644 (file)
@@ -2,8 +2,8 @@
 #define __MAIN_H__
 
 
-#include "main.decl.h"
 #include "md_config.h"
+#include "main.decl.h"
 
 
 // DMK - DEBUG - Until a general Charm++ API for aligned memory buffers is defined,
@@ -48,7 +48,7 @@ class Main : public CBase_Main {
     ~Main();
 
     /// Entry Methods ///
-    void proxyCheckIn();
+    void initCheckIn();
     void patchCheckIn();
 
 };
index 8ea511478383048923bf5660d6139ca9b9e6f4ff..63f90210d487db8a20647e02829a852b0d586224 100644 (file)
 #define DEFAULT_NUM_PATCHES_Z              (2)
 
 #define DEFAULT_NUM_STEPS                 (16)
-#define STEPS_PER_PRINT                    (4)
+#define STEPS_PER_PRINT                   (16)
+
+#define USE_ARRAY_SECTIONS                 (1)
+
+#define USE_PROXY_PATCHES                  (1)
 
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -38,7 +42,7 @@
 // Misc. Macros for Performance Testing
 
 // DMK - DEBUG
-#define ENABLE_USER_EVENTS        (0)
+#define ENABLE_USER_EVENTS               (1)
 #define PROJ_USER_EVENT_PATCH_FORCECHECKIN_CALLBACK  (1120)
 #define PROJ_USER_EVENT_PATCH_INTEGRATE_CALLBACK     (1121)
 #define PROJ_USER_EVENT_SELFCOMPUTE_DOCALC_CALLBACK  (1130)
@@ -46,7 +50,7 @@
 #define PROJ_USER_EVENT_MACHINEPROGRESS              (1150)
 
 // DMK - DEBUG
-#define ENABLE_NETWORK_PROGRESS   (0)
+#define ENABLE_NETWORK_PROGRESS          (0)
 #if ENABLE_NETWORK_PROGRESS != 0
   #if ENABLE_USER_EVENTS != 0
     #define NetworkProgress  \
index b3ce263c468a50c673124d6fc519ec633d7b6c5d..ca3a696d211acf21c5c297013edf12a44005622c 100644 (file)
@@ -1,28 +1,17 @@
 #include "pairCompute.h"
+#include "patch.h"
 #include "main.h"
 
 
-PairCompute::PairCompute(int numParticlesPerPatch) {
-
-  numParticles = numParticlesPerPatch;
-  particleX[0] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  particleX[1] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  particleY[0] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  particleY[1] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  particleZ[0] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  particleZ[1] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  particleQ[0] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  particleQ[1] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  forceX[0] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  forceX[1] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  forceY[0] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  forceY[1] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  forceZ[0] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  forceZ[1] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  patchDataCount = 0;
-
-  // Check in with the main chare so it "knows" this object is ready for the simulation to start
-  mainProxy.proxyCheckIn();
+PairCompute::PairCompute() {
+  particleX[0] = particleX[1] = NULL;
+  particleY[0] = particleY[1] = NULL;
+  particleZ[0] = particleZ[1] = NULL;
+  particleQ[0] = particleQ[1] = NULL;
+  forceX[0] = forceX[1] = NULL;
+  forceY[0] = forceY[1] = NULL;
+  forceZ[0] = forceZ[1] = NULL;
+  numParticles = -1;
 }
 
 
@@ -32,31 +21,75 @@ PairCompute::PairCompute(CkMigrateMessage* msg) {
 
 
 PairCompute::~PairCompute() {
-  if (particleX[0] != NULL) { free_aligned(particleX[0]); particleX[0] = NULL; }
-  if (particleX[1] != NULL) { free_aligned(particleX[1]); particleX[1] = NULL; }
-  if (particleY[0] != NULL) { free_aligned(particleY[0]); particleY[0] = NULL; }
-  if (particleY[1] != NULL) { free_aligned(particleY[1]); particleY[1] = NULL; }
-  if (particleZ[0] != NULL) { free_aligned(particleZ[0]); particleZ[0] = NULL; }
-  if (particleZ[1] != NULL) { free_aligned(particleZ[1]); particleZ[1] = NULL; }
-  if (particleQ[0] != NULL) { free_aligned(particleQ[0]); particleQ[0] = NULL; }
-  if (particleQ[1] != NULL) { free_aligned(particleQ[1]); particleQ[1] = NULL; }
+
+  #if USE_PROXY_PATCHES == 0
+    if (particleX[0] != NULL) { free_aligned(particleX[0]); particleX[0] = NULL; }
+    if (particleX[1] != NULL) { free_aligned(particleX[1]); particleX[1] = NULL; }
+    if (particleY[0] != NULL) { free_aligned(particleY[0]); particleY[0] = NULL; }
+    if (particleY[1] != NULL) { free_aligned(particleY[1]); particleY[1] = NULL; }
+    if (particleZ[0] != NULL) { free_aligned(particleZ[0]); particleZ[0] = NULL; }
+    if (particleZ[1] != NULL) { free_aligned(particleZ[1]); particleZ[1] = NULL; }
+    if (particleQ[0] != NULL) { free_aligned(particleQ[0]); particleQ[0] = NULL; }
+    if (particleQ[1] != NULL) { free_aligned(particleQ[1]); particleQ[1] = NULL; }
+  #endif
   if (forceX[0] != NULL) { free_aligned(forceX[0]); forceX[0] = NULL; }
   if (forceX[1] != NULL) { free_aligned(forceX[1]); forceX[1] = NULL; }
   if (forceY[0] != NULL) { free_aligned(forceY[0]); forceY[0] = NULL; }
   if (forceY[1] != NULL) { free_aligned(forceY[1]); forceY[1] = NULL; }
   if (forceZ[0] != NULL) { free_aligned(forceZ[0]); forceZ[0] = NULL; }
   if (forceZ[1] != NULL) { free_aligned(forceZ[1]); forceZ[1] = NULL; }
-  numParticles = 0;
+  numParticles = -1;
+}
+
+
+void PairCompute::init(int numParticlesPerPatch) {
+
+  // Initialize the arrays
+  numParticles = numParticlesPerPatch;
+  #if USE_PROXY_PATCHES == 0
+    particleX[0] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+    particleX[1] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+    particleY[0] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+    particleY[1] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+    particleZ[0] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+    particleZ[1] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+    particleQ[0] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+    particleQ[1] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  #endif
+  forceX[0] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  forceX[1] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  forceY[0] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  forceY[1] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  forceZ[0] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  forceZ[1] = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  patchDataCount = 0;
+
+  // Check in with the main chare
+  mainProxy.initCheckIn();
 }
 
 
+void PairCompute::patchData(int numParticles, float* particleX, float* particleY, float* particleZ, float* particleQ, int fromPatch, CProxy_ProxyPatch proxyPatchProxy) {
+  #if USE_PROXY_PATCHES != 0
+    this->proxyPatchProxy[fromPatch] = proxyPatchProxy;
+  #endif
+  patchData(numParticles, particleX, particleY, particleZ, particleQ, fromPatch);
+}
+
 void PairCompute::patchData(int numParticles, float* particleX, float* particleY, float* particleZ, float* particleQ, int fromPatch) {
 
   // Copy the data from the parameters
-  memcpy(this->particleX[fromPatch], particleX, numParticles * sizeof(float));
-  memcpy(this->particleY[fromPatch], particleY, numParticles * sizeof(float));
-  memcpy(this->particleZ[fromPatch], particleZ, numParticles * sizeof(float));
-  memcpy(this->particleQ[fromPatch], particleQ, numParticles * sizeof(float));
+  #if USE_PROXY_PATCHES != 0
+    this->particleX[fromPatch] = particleX;
+    this->particleY[fromPatch] = particleY;
+    this->particleZ[fromPatch] = particleZ;
+    this->particleQ[fromPatch] = particleQ;
+  #else
+    memcpy(this->particleX[fromPatch], particleX, numParticles * sizeof(float));
+    memcpy(this->particleY[fromPatch], particleY, numParticles * sizeof(float));
+    memcpy(this->particleZ[fromPatch], particleZ, numParticles * sizeof(float));
+    memcpy(this->particleQ[fromPatch], particleQ, numParticles * sizeof(float));
+  #endif
 
   // Increment the patch count and initiate the calculation of both patches have
   //   sent their data to this compute
@@ -75,28 +108,37 @@ void PairCompute::doCalc_callback() {
     double __start_time__ = CmiWallTimer();
   #endif
 
-  // DMK - DEBUG
-  NetworkProgress;
+  #if USE_PROXY_PATCHES != 0
 
-  // Calculate the index of patch 0 and send force data back to it
-  int p0Index = thisIndex.x;
-  int p0IndexX = PATCH_I_TO_X(p0Index);
-  int p0IndexY = PATCH_I_TO_Y(p0Index);
-  int p0IndexZ = PATCH_I_TO_Z(p0Index);
-  patchArrayProxy(p0IndexX, p0IndexY, p0IndexZ).forceCheckIn(numParticles, forceX[0], forceY[0], forceZ[0]);
+    (proxyPatchProxy[0].ckLocalBranch())->forceCheckIn(numParticles, forceX[0], forceY[0], forceZ[0]);
+    (proxyPatchProxy[1].ckLocalBranch())->forceCheckIn(numParticles, forceX[1], forceY[1], forceZ[1]);
 
-  // DMK - DEBUG
-  NetworkProgress;
+  #else
 
-  // Calculate the index of patch 1 and send force data back to it
-  int p1Index = thisIndex.y;
-  int p1IndexX = PATCH_I_TO_X(p1Index);
-  int p1IndexY = PATCH_I_TO_Y(p1Index);
-  int p1IndexZ = PATCH_I_TO_Z(p1Index);
-  patchArrayProxy(p1IndexX, p1IndexY, p1IndexZ).forceCheckIn(numParticles, forceX[1], forceY[1], forceZ[1]);
+    // DMK - DEBUG
+    NetworkProgress;
 
-  // DMK - DEBUG
-  NetworkProgress;
+    // Calculate the index of patch 0 and send force data back to it
+    int p0Index = thisIndex.x;
+    int p0IndexX = PATCH_I_TO_X(p0Index);
+    int p0IndexY = PATCH_I_TO_Y(p0Index);
+    int p0IndexZ = PATCH_I_TO_Z(p0Index);
+    patchArrayProxy(p0IndexX, p0IndexY, p0IndexZ).forceCheckIn(numParticles, forceX[0], forceY[0], forceZ[0]);
+
+    // DMK - DEBUG
+    NetworkProgress;
+
+    // Calculate the index of patch 1 and send force data back to it
+    int p1Index = thisIndex.y;
+    int p1IndexX = PATCH_I_TO_X(p1Index);
+    int p1IndexY = PATCH_I_TO_Y(p1Index);
+    int p1IndexZ = PATCH_I_TO_Z(p1Index);
+    patchArrayProxy(p1IndexX, p1IndexY, p1IndexZ).forceCheckIn(numParticles, forceX[1], forceY[1], forceZ[1]);
+
+    // DMK - DEBUG
+    NetworkProgress;
+
+  #endif
 
   // DMK - DEBUG
   #if ENABLE_USER_EVENTS != 0
index 73611041633b745a6521ad15734bead436f9c814..4ed3c14f32331dc3e10d4ff12054073dd540afd7 100644 (file)
@@ -5,7 +5,9 @@ module pairCompute {
 
   array[2D] PairCompute {
 
-    entry PairCompute(int numParticlesPerPatch);
+    entry PairCompute();
+
+    entry void init(int numParticlesPerPatch);
 
     entry void patchData(int numParticles,
                          float particleX[numParticles],
@@ -125,4 +127,4 @@ module pairCompute {
 
   };
 
-};
\ No newline at end of file
+};
index c378e6b31063a93bc63ccc4802abbc8b5bc4e9af..0cf03a1f4f2e842a3f83667fa1902e95236d967a 100644 (file)
@@ -2,7 +2,9 @@
 #define __PAIR_COMPUTE_H__
 
 
+#include "md_config.h"
 #include "pairCompute.decl.h"
+#include "patch.decl.h"
 
 
 class PairCompute : public CBase_PairCompute {
@@ -27,14 +29,20 @@ class PairCompute : public CBase_PairCompute {
     float* forceY[2];
     float* forceZ[2];
 
+    #if USE_PROXY_PATCHES != 0
+      CProxy_ProxyPatch proxyPatchProxy[2];
+    #endif
+
   public:
 
     /// Constructor(s) \ Destructor ///
-    PairCompute(int numParticlesPerPatch);
+    PairCompute();
     PairCompute(CkMigrateMessage *msg);
     ~PairCompute();
 
     /// Entry Methods ///
+    void init(int numParticlesPerPatch);
+    void patchData(int numParticles, float* particleX, float* particleY, float* particleZ, float* particleQ, int fromPatch, CProxy_ProxyPatch proxyPatchProxy);
     void patchData(int numParticles, float* particleX, float* particleY, float* particleZ, float* particleQ, int fromPatch);
     void doCalc_callback();
 
index 6987291624984d7010d002bf1757e3c76fb33647..32387973b57998d6d854f5889cc78618a5a00f14 100644 (file)
@@ -1,4 +1,6 @@
 #include "patch.h"
+#include "selfCompute.h"
+#include "pairCompute.h"
 #include "main.h"
 
 
@@ -23,27 +25,18 @@ float Patch::randf() {
 }
 
 
-Patch::Patch(int numParticles) {
+Patch::Patch() {
 
-  // Allocate memory for the particles
-  this->numParticles = numParticles;
-  particleX = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  particleY = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  particleZ = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  particleQ = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  particleM = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  forceSumX = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  forceSumY = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  forceSumZ = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  velocityX = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  velocityY = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
-  velocityZ = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  particleX = particleY = particleZ = NULL;
+  particleQ = particleM = NULL;
+  forceSumX = forceSumY = forceSumZ = NULL;
+  velocityX = velocityY = velocityZ = NULL;
+  numParticles = -1;
 
-  // Initialize the particles
-  randomizeParticles();
-
-  // Check in with the main proxy so it "knows" that this patch is ready to start simulation
-  mainProxy.proxyCheckIn();
+  #if USE_PROXY_PATCHES != 0
+    const int patchIndex = PATCH_XYZ_TO_I(thisIndex.x, thisIndex.y, thisIndex.z);
+    proxyPatchProxy = CProxy_ProxyPatch::ckNew(patchIndex);
+  #endif
 }
 
 
@@ -68,6 +61,57 @@ Patch::~Patch() {
 }
 
 
+void Patch::init(int numParticles) {
+
+  // Also tell the proxy patches to initialize
+  #if USE_PROXY_PATCHES != 0
+    proxyPatchProxy.init(numParticles);
+  #endif
+
+  // Allocate memory for the particles
+  this->numParticles = numParticles;
+  particleX = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  particleY = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  particleZ = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  particleQ = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  particleM = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  forceSumX = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  forceSumY = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  forceSumZ = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  velocityX = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  velocityY = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  velocityZ = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+
+  // Initialize the particles
+  randomizeParticles();
+
+  // Create an array section for the pair computes this patch interacts with
+  #if USE_ARRAY_SECTIONS != 0
+
+    // Enumerate the pair computes that this patch interacts with
+    const int patchIndex = PATCH_XYZ_TO_I(thisIndex.x, thisIndex.y, thisIndex.z);
+    const int numPatches = numPatchesX * numPatchesY * numPatchesZ;
+
+    // Lower section
+    CkVec<CkArrayIndex2D> pairIndexes_lower;
+    for (int i = 0; i < patchIndex; i++) {
+      pairIndexes_lower.push_back(CkArrayIndex2D(i, patchIndex));
+    }
+    pairComputeArraySection_lower = CProxySection_PairCompute::ckNew(pairComputeArrayProxy, pairIndexes_lower.getVec(), pairIndexes_lower.size());
+
+    CkVec<CkArrayIndex2D> pairIndexes_upper;
+    for (int i = patchIndex + 1; i < numPatches; i++) {
+      pairIndexes_upper.push_back(CkArrayIndex2D(patchIndex, i));
+    }
+    pairComputeArraySection_upper = CProxySection_PairCompute::ckNew(pairComputeArrayProxy, pairIndexes_upper.getVec(), pairIndexes_upper.size());
+
+  #endif
+
+  // Check in with the main proxy
+  mainProxy.initCheckIn();
+}
+
+
 void Patch::startIteration() { startIteration_common(1); }
 void Patch::startIterations(int numIters) { startIteration_common(numIters); }
 void Patch::startIteration_common(int numIters) {
@@ -95,60 +139,77 @@ void Patch::startIteration_common(int numIters) {
   // DMK - DEBUG
   NetworkProgress
 
-  // Send particle data to self computes
-  selfComputeArrayProxy(thisIndex.x, thisIndex.y, thisIndex.z).doCalc(numParticles, particleX, particleY, particleZ, particleQ);
-
   // Send particle data to pair computes
-  const int index = PATCH_XYZ_TO_I(thisIndex.x, thisIndex.y, thisIndex.z);
-  for (int i = 0; i < index; i++) {
 
-    // DMK - DEBUG
-    NetworkProgress
+  #if USE_PROXY_PATCHES != 0
 
-    pairComputeArrayProxy(i, index).patchData(numParticles, particleX, particleY, particleZ, particleQ, 1);
-  }
-  const int numPatches = numPatchesX * numPatchesY * numPatchesZ;
-  for (int i = index + 1; i < numPatches; i++) {
+    proxyPatchProxy.patchData(numParticles, particleX, particleY, particleZ, particleQ);
 
-    // DMK - DEBUG
-    NetworkProgress
+  #elif USE_ARRAY_SECTIONS != 0
 
-    pairComputeArrayProxy(index, i).patchData(numParticles, particleX, particleY, particleZ, particleQ, 0);
-  }
+    // Send particle data to self computes
+    selfComputeArrayProxy(thisIndex.x, thisIndex.y, thisIndex.z).patchData(numParticles, particleX, particleY, particleZ, particleQ);
 
-  // DMK - DEBUG
-  NetworkProgress
-}
+    pairComputeArraySection_lower.patchData(numParticles, particleX, particleY, particleZ, particleQ, 1);
+    pairComputeArraySection_upper.patchData(numParticles, particleX, particleY, particleZ, particleQ, 0);
 
+  #else
 
-void Patch::forceCheckIn_callback() {
+    // Send particle data to self computes
+    selfComputeArrayProxy(thisIndex.x, thisIndex.y, thisIndex.z).patchData(numParticles, particleX, particleY, particleZ, particleQ);
+
+    const int index = PATCH_XYZ_TO_I(thisIndex.x, thisIndex.y, thisIndex.z);
+    for (int i = 0; i < index; i++) {
+
+      // DMK - DEBUG
+      NetworkProgress
+
+      pairComputeArrayProxy(i, index).patchData(numParticles, particleX, particleY, particleZ, particleQ, 1);
+    }
+    const int numPatches = numPatchesX * numPatchesY * numPatchesZ;
+    for (int i = index + 1; i < numPatches; i++) {
+
+      // DMK - DEBUG
+      NetworkProgress
+
+      pairComputeArrayProxy(index, i).patchData(numParticles, particleX, particleY, particleZ, particleQ, 0);
+    }
+
+    // DMK - DEBUG
+    NetworkProgress
 
-  // DMK - DEBUG
-  #if ENABLE_USER_EVENTS != 0
-    double __start_time__ = CmiWallTimer();
   #endif
+}
 
-  // DMK - DEBUG
-  NetworkProgress
 
-  // Decrement the counter containing the number of remaining computes that need to report forces
-  //   back to this patch.  Once all computes have checked in, send a message to accelerated
-  //   'integrate' entry method.
-  remainingForceCheckIns--;
+void Patch::forceCheckIn(int numParticles, float* forceX, float* forceY, float* forceZ) {
+  forceCheckIn(numParticles, forceX, forceY, forceZ, 1);
+}
+void Patch::forceCheckIn(int numParticles, float* forceX, float* forceY, float* forceZ, int numForceCheckIns) {
+
+  // Accumulate the force data
+  register vec4f* fsx = (vec4f*)forceSumX;
+  register vec4f* fsy = (vec4f*)forceSumY;
+  register vec4f* fsz = (vec4f*)forceSumZ;
+  register vec4f* fx = (vec4f*)forceX;
+  register vec4f* fy = (vec4f*)forceY;
+  register vec4f* fz = (vec4f*)forceZ;
+  register const int numParticles_vec = numParticles / (sizeof(vec4f) * sizeof(float));
+  register int i;
+  for (i = 0; i < numParticles_vec; i++) {
+    fsx[i] = vadd4f(fsx[i], fx[i]);
+    fsy[i] = vadd4f(fsy[i], fy[i]);
+    fsz[i] = vadd4f(fsz[i], fz[i]);
+  }
+
+  // Count the incoming forced data and integrate if all force data has arrived
+  remainingForceCheckIns -= numForceCheckIns;
   if (remainingForceCheckIns <= 0) {
     thisProxy(thisIndex.x, thisIndex.y, thisIndex.z).integrate();
   }
-
-  // DMK - DEBUG
-  NetworkProgress
-
-  // DMK - DEBUG
-  #if ENABLE_USER_EVENTS != 0
-    double __end_time__ = CmiWallTimer();
-    traceUserBracketEvent(PROJ_USER_EVENT_PATCH_FORCECHECKIN_CALLBACK, __start_time__, __end_time__);
-  #endif
 }
 
+
 void Patch::integrate_callback() {
 
   // DMK - DEBUG
@@ -179,4 +240,121 @@ void Patch::integrate_callback() {
 }
 
 
+ProxyPatch::ProxyPatch(int patchIndex) {
+  this->patchIndex = patchIndex;
+  numParticles = -1;
+  particleX = particleY = particleZ = particleQ = NULL;
+  forceSumX = forceSumY = forceSumZ = NULL;
+}
+
+
+ProxyPatch::ProxyPatch(CkMigrateMessage *msg) {
+  CkAbort("ProxyPatch::ProxyPatch(CkMigrateMessage *msg) not implemented yet");
+}
+
+
+ProxyPatch::~ProxyPatch() {
+  if (particleX != NULL) { free_aligned(particleX); particleX = NULL; }
+  if (particleY != NULL) { free_aligned(particleY); particleY = NULL; }
+  if (particleZ != NULL) { free_aligned(particleZ); particleZ = NULL; }
+  if (particleQ != NULL) { free_aligned(particleQ); particleQ = NULL; }
+  if (forceSumX != NULL) { free_aligned(forceSumX); forceSumX = NULL; }
+  if (forceSumY != NULL) { free_aligned(forceSumY); forceSumY = NULL; }
+  if (forceSumZ != NULL) { free_aligned(forceSumZ); forceSumZ = NULL; }
+  numParticles = -1;
+}
+
+
+void ProxyPatch::init(int numParticles) {
+
+  // Allocate memory for the particles
+  this->numParticles = numParticles;
+  particleX = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  particleY = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  particleZ = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  particleQ = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  forceSumX = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  forceSumY = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  forceSumZ = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+
+  // Check in with the main proxy
+  mainProxy.initCheckIn();
+}
+
+
+void ProxyPatch::patchData(int numParticles, float* particleX, float* particleY, float* particleZ, float* particleQ) {
+
+  // Copy in the updated particle data
+  memcpy(this->particleX, particleX, numParticles * sizeof(float));
+  memcpy(this->particleY, particleY, numParticles * sizeof(float));
+  memcpy(this->particleZ, particleZ, numParticles * sizeof(float));
+  memcpy(this->particleQ, particleQ, numParticles * sizeof(float));
+
+  // Clear out the force arrays
+  memset(this->forceSumX, 0, numParticles * sizeof(float));
+  memset(this->forceSumY, 0, numParticles * sizeof(float));
+  memset(this->forceSumZ, 0, numParticles * sizeof(float));
+
+  // Reset the patch checkin counters
+  checkInCount = 0;
+
+  // Call patchData on the local self compute
+  const int patchX = PATCH_I_TO_X(patchIndex);
+  const int patchY = PATCH_I_TO_Y(patchIndex);
+  const int patchZ = PATCH_I_TO_Z(patchIndex);
+  SelfCompute* localSelfCompute = selfComputeArrayProxy(patchX, patchY, patchZ).ckLocal();
+  if (localSelfCompute != NULL) {
+    localSelfCompute->patchData(numParticles, this->particleX, this->particleY, this->particleZ, this->particleQ, thisProxy);
+    checkInCount++;
+  }
+
+  // Call patchData on all local pair computes
+  const int myPe = CkMyPe();
+  for (int i = 0; i < patchIndex; i++) {
+    PairCompute* localPairCompute = pairComputeArrayProxy(i, patchIndex).ckLocal();
+    if (localPairCompute != NULL) {
+      localPairCompute->patchData(numParticles, this->particleX, this->particleY, this->particleZ, this->particleQ, 1, thisProxy);
+      checkInCount++;
+    }
+  }
+  const int numPatches = numPatchesX * numPatchesY * numPatchesZ;
+  for (int i = patchIndex + 1; i < numPatches; i++) {
+    PairCompute* localPairCompute = pairComputeArrayProxy(patchIndex, i).ckLocal();
+    if (localPairCompute != NULL) {
+      localPairCompute->patchData(numParticles, this->particleX, this->particleY, this->particleZ, this->particleQ, 0, thisProxy);
+      checkInCount++;
+    }
+  }
+
+  numToCheckIn = checkInCount;
+}
+
+
+void ProxyPatch::forceCheckIn(int numParticles, float* forceX, float* forceY, float* forceZ) {
+
+  // Accumulate the force data
+  register vec4f* forceX_vec = (vec4f*)forceX;
+  register vec4f* forceY_vec = (vec4f*)forceY;
+  register vec4f* forceZ_vec = (vec4f*)forceZ;
+  register vec4f* forceSumX_vec = (vec4f*)forceSumX;
+  register vec4f* forceSumY_vec = (vec4f*)forceSumY;
+  register vec4f* forceSumZ_vec = (vec4f*)forceSumZ;
+  const int numParticles_vec = numParticles / (sizeof(vec4f) / sizeof(float));
+  for (int i = 0; i < numParticles_vec; i++) {
+    forceSumX_vec[i] += forceX_vec[i];
+    forceSumY_vec[i] += forceY_vec[i];
+    forceSumZ_vec[i] += forceZ_vec[i];
+  }
+
+  // Once all computes this proxy called have contributed forces, send the data back to the patch itself
+  checkInCount--;
+  if (checkInCount <= 0) {
+    const int patchX = PATCH_I_TO_X(patchIndex);
+    const int patchY = PATCH_I_TO_Y(patchIndex);
+    const int patchZ = PATCH_I_TO_Z(patchIndex);
+    patchArrayProxy(patchX, patchY, patchZ).forceCheckIn(numParticles, forceSumX, forceSumY, forceSumZ, numToCheckIn);
+  }
+}
+
+
 #include "patch.def.h"
index c047d6a376a61054422a81077947b4ee71dca18c..bc298acf9dbff883ca27653ce7318fb949e980f2 100644 (file)
@@ -2,24 +2,12 @@ module patch {
 
   accelblock { #include "md_config.h" };
 
-  array[3D] Patch {
-
-    entry Patch(int numParticles);
-
-    entry void startIteration();
-    entry void startIterations(int numIters);
+  accelblock {
 
-    entry [accel] void forceCheckIn(int numParticles,
-                                    float forceX[numParticles],
-                                    float forceY[numParticles],
-                                    float forceZ[numParticles]
-                                   )[
-                                    readwrite : float forceSumX[numParticles] <impl_obj->forceSumX>,
-                                    readwrite : float forceSumY[numParticles] <impl_obj->forceSumY>,
-                                    readwrite : float forceSumZ[numParticles] <impl_obj->forceSumZ>
-                                   ] {
-
-      // Combine the incoming force with the accumulated forces for this patch
+    void accumForce(int numParticles,
+                    float* forceSumX, float* forceSumY, float* forceSumZ,
+                    float* forceX, float* forceY, float* forceZ
+                   ) {
       register vec4f* fsx = (vec4f*)forceSumX;
       register vec4f* fsy = (vec4f*)forceSumY;
       register vec4f* fsz = (vec4f*)forceSumZ;
@@ -33,23 +21,44 @@ module patch {
         fsy[i] = vadd4f(fsy[i], fy[i]);
         fsz[i] = vadd4f(fsz[i], fz[i]);
       }
+    }
+  };
+
+  array[3D] Patch {
+
+    entry Patch();
+
+    entry void init(int numParticles);
 
-    } forceCheckIn_callback;
-
-    entry [accel] void integrate()[  readonly : int numParticles <impl_obj->numParticles>,
-                                     readonly : int thisIndex_x <impl_obj->thisIndex.x>,
-                                     readonly : int thisIndex_y <impl_obj->thisIndex.y>,
-                                     readonly : int thisIndex_z <impl_obj->thisIndex.z>,
-                                    readwrite : float p_x[numParticles] <impl_obj->particleX>,
-                                    readwrite : float p_y[numParticles] <impl_obj->particleY>,
-                                    readwrite : float p_z[numParticles] <impl_obj->particleZ>,
-                                     readonly : float p_m[numParticles] <impl_obj->particleM>,
-                                     readonly : float f_x[numParticles] <impl_obj->forceSumX>,
-                                     readonly : float f_y[numParticles] <impl_obj->forceSumY>,
-                                     readonly : float f_z[numParticles] <impl_obj->forceSumZ>,
-                                    readwrite : float v_x[numParticles] <impl_obj->velocityX>,
-                                    readwrite : float v_y[numParticles] <impl_obj->velocityY>,
-                                    readwrite : float v_z[numParticles] <impl_obj->velocityZ>
+    entry void startIteration();
+    entry void startIterations(int numIters);
+
+    entry void forceCheckIn(int numParticles,
+                            float forceX[numParticles],
+                            float forceY[numParticles],
+                            float forceZ[numParticles]
+                           );
+    entry void forceCheckIn(int numParticles,
+                            float forceX[numParticles],
+                            float forceY[numParticles],
+                            float forceZ[numParticles],
+                            int numForceCheckIns
+                           );
+
+    entry [accel] void integrate()[ readonly : int numParticles <impl_obj->numParticles>,
+                                    readonly : int thisIndex_x <impl_obj->thisIndex.x>,
+                                    readonly : int thisIndex_y <impl_obj->thisIndex.y>,
+                                    readonly : int thisIndex_z <impl_obj->thisIndex.z>,
+                                   readwrite : float p_x[numParticles] <impl_obj->particleX>,
+                                   readwrite : float p_y[numParticles] <impl_obj->particleY>,
+                                   readwrite : float p_z[numParticles] <impl_obj->particleZ>,
+                                    readonly : float p_m[numParticles] <impl_obj->particleM>,
+                                    readonly : float f_x[numParticles] <impl_obj->forceSumX>,
+                                    readonly : float f_y[numParticles] <impl_obj->forceSumY>,
+                                    readonly : float f_z[numParticles] <impl_obj->forceSumZ>,
+                                   readwrite : float v_x[numParticles] <impl_obj->velocityX>,
+                                   readwrite : float v_y[numParticles] <impl_obj->velocityY>,
+                                   readwrite : float v_z[numParticles] <impl_obj->velocityZ>
                                   ] {
 
       register vec4f* p_x_vec = (vec4f*)p_x;
@@ -70,7 +79,7 @@ module patch {
       // Add the acceleration to the velocity and add the update velocity to the position
       for (i = 0; i < numParticles_vec; i++) {
 
-        //// Update the velocity : v_new = v_old + (F/m)
+        // Update the velocity : v_new = v_old + (F/m)
         vec4f new_v_x_vec = v_x_vec[i] + (delta_time_vec * (f_x_vec[i] / p_m_vec[i]));
         vec4f new_v_y_vec = v_y_vec[i] + (delta_time_vec * (f_y_vec[i] / p_m_vec[i]));
         vec4f new_v_z_vec = v_z_vec[i] + (delta_time_vec * (f_z_vec[i] / p_m_vec[i]));
@@ -78,7 +87,7 @@ module patch {
         v_y_vec[i] = new_v_y_vec;
         v_z_vec[i] = new_v_z_vec;
 
-        //// Update the position : pos_new = pos_old + v_new
+        // Update the position : pos_new = pos_old + v_new
         p_x_vec[i] += delta_time_vec * new_v_x_vec;
         p_y_vec[i] += delta_time_vec * new_v_y_vec;
         p_z_vec[i] += delta_time_vec * new_v_z_vec;
@@ -88,4 +97,25 @@ module patch {
 
   };
 
-};
\ No newline at end of file
+
+  group ProxyPatch {
+
+    entry ProxyPatch(int patchIndex);
+
+    entry void init(int numParticles);
+
+    entry void patchData(int numParticles,
+                         float particleX[numParticles],
+                         float particleY[numParticles],
+                         float particleZ[numParticles],
+                         float particleQ[numParticles]
+                        );
+
+    entry void forceCheckIn(int numParticles,
+                            float forceX[numParticles],
+                            float forceY[numParticles],
+                            float forceZ[numParticles]
+                           );
+  };
+
+};
index 35cae8ec0319f51d019c5998abd1f2aae137eb85..5acc86a1c41c11dfde5d3594c0a2c390dc07d75b 100644 (file)
@@ -2,8 +2,9 @@
 #define __PATCH_H__
 
 
-#include "patch.decl.h"
 #include "md_config.h"
+#include "patch.decl.h"
+#include "pairCompute.decl.h"
 
 
 class Patch : public CBase_Patch {
@@ -31,6 +32,16 @@ class Patch : public CBase_Patch {
     float* forceSumY;  // Buffer to sum of force y components from computes
     float* forceSumZ;  // Buffer to sum of force z components from computes
 
+    #if USE_ARRAY_SECTIONS != 0
+      CProxySection_PairCompute pairComputeArraySection_lower;
+      CProxySection_PairCompute pairComputeArraySection_upper;
+    #endif
+
+    #if USE_PROXY_PATCHES != 0
+      CProxy_ProxyPatch proxyPatchProxy;
+      int* proxyPatchPresentFlags;
+    #endif
+
     /// Member Functions ///
     void randomizeParticles();
     float randf();
@@ -39,17 +50,56 @@ class Patch : public CBase_Patch {
   public:
 
     /// Constructor(s) \ Destructor ///
-    Patch(int numParticles);
+    Patch();
     Patch(CkMigrateMessage* msg);
     ~Patch();
 
     /// Entry Methods ///
+    void init(int numParticles);
     void startIteration();
     void startIterations(int numIters);
-    void forceCheckIn_callback();
+    void forceCheckIn(int numParticles, float* forceX, float* forceY, float* forceZ);
+    void forceCheckIn(int numParticles, float* forceX, float* forceY, float* forceZ, int numForceCheckIns);
     void integrate_callback();
 
 };
 
 
+class ProxyPatch : public CBase_ProxyPatch {
+
+  // Declare CkIndex_ProxyPatch as a friend so accelerated entry methods can access
+  //   the member variables of the object they execute on
+  friend class CkIndex_ProxyPatch;
+
+  private:
+
+    /// Member Variables ///
+    int numParticles;
+    float* particleX;
+    float* particleY;
+    float* particleZ;
+    float* particleQ;
+    float* forceSumX;
+    float* forceSumY;
+    float* forceSumZ;
+
+    int patchIndex;
+
+    int checkInCount;
+    int numToCheckIn;
+
+  public:
+
+    /// Constructor(s) \ Destructor ///
+    ProxyPatch(int proxyIndex);
+    ProxyPatch(CkMigrateMessage *msg);
+    ~ProxyPatch();
+
+    /// Entry Methods ///
+    void init(int numParticles);
+    void patchData(int numParticles, float* particleX, float* particleY, float* particleZ, float* particleQ);
+    void forceCheckIn(int numParticles, float* forceX, float* forceY, float* forceZ);
+
+};
+
 #endif //__PATCH_H__
index 2fc8361f220ab4a7bc8b0c4d8ab8f59223ca079a..fea44f1accc449a3388a41b9b0b552c3ce7f1548 100644 (file)
@@ -2,29 +2,80 @@
 #include "main.h"
 
 
-SelfCompute::SelfCompute(int numParticlesPerPatch) {
+SelfCompute::SelfCompute() {
+  numParticles = -1;
+  particleX = NULL;
+  particleY = NULL;
+  particleZ = NULL;
+  particleQ = NULL;
+  forceX = NULL;
+  forceY = NULL;
+  forceZ = NULL;
+}
+
+
+SelfCompute::SelfCompute(CkMigrateMessage* msg) {
+  CkAbort("SelfCompute::SelfCompute(CkMigrateMessage *msg) not implemented yet");
+}
+
+
+SelfCompute::~SelfCompute() {
+  #if USE_PROXY_PATCHES == 0
+    if (particleX != NULL) { free_aligned(particleX); particleX = NULL; }
+    if (particleY != NULL) { free_aligned(particleY); particleY = NULL; }
+    if (particleZ != NULL) { free_aligned(particleZ); particleZ = NULL; }
+    if (particleQ != NULL) { free_aligned(particleQ); particleQ = NULL; }
+  #endif
+  if (forceX != NULL) { free_aligned(forceX); forceX = NULL; }
+  if (forceY != NULL) { free_aligned(forceY); forceY = NULL; }
+  if (forceZ != NULL) { free_aligned(forceZ); forceZ = NULL; }
+  numParticles = -1;
+}
+
+
+void SelfCompute::init(int numParticlesPerPatch) {
 
   // Allocate buffers for force data
   numParticles = numParticlesPerPatch;
+  #if USE_PROXY_PATCHES == 0
+    particleX = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+    particleY = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+    particleZ = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+    particleQ = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
+  #endif
   forceX = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
   forceY = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
   forceZ = (float*)(malloc_aligned(numParticles * sizeof(float), 128));
 
-  // Check in with the main chare indicating that this object is ready for the simulation to start
-  mainProxy.proxyCheckIn();
+  // Check in with the main chare
+  mainProxy.initCheckIn();
 }
 
 
-SelfCompute::SelfCompute(CkMigrateMessage* msg) {
-  CkAbort("SelfCompute::SelfCompute(CkMigrateMessage *msg) not implemented yet");
+void SelfCompute::patchData(int numParticles, float* particleX, float* particleY, float* particleZ, float* particleQ, CProxy_ProxyPatch proxyPatchProxy) {
+  #if USE_PROXY_PATCHES != 0
+    this->proxyPatchProxy = proxyPatchProxy;
+  #endif
+  patchData(numParticles, particleX, particleY, particleZ, particleQ);
 }
 
+void SelfCompute::patchData(int numParticles, float* particleX, float* particleY, float* particleZ, float* particleQ) {
+
+  // Copy the data from the parameters
+  #if USE_PROXY_PATCHES != 0
+    this->particleX = particleX;
+    this->particleY = particleY;
+    this->particleZ = particleZ;
+    this->particleQ = particleQ;
+  #else
+    memcpy(this->particleX, particleX, numParticles * sizeof(float));
+    memcpy(this->particleY, particleY, numParticles * sizeof(float));
+    memcpy(this->particleZ, particleZ, numParticles * sizeof(float));
+    memcpy(this->particleQ, particleQ, numParticles * sizeof(float));
+  #endif
 
-SelfCompute::~SelfCompute() {
-  if (forceX != NULL) { free_aligned(forceX); forceX = NULL; }
-  if (forceY != NULL) { free_aligned(forceY); forceY = NULL; }
-  if (forceZ != NULL) { free_aligned(forceZ); forceZ = NULL; }
-  numParticles = 0;
+  // Initiate the calculation for this compute
+  thisProxy(thisIndex.x, thisIndex.y, thisIndex.z).doCalc();
 }
 
 
@@ -38,7 +89,11 @@ void SelfCompute::doCalc_callback() {
   // DMK - DEBUG
   NetworkProgress;
 
-  patchArrayProxy(thisIndex.x, thisIndex.y, thisIndex.z).forceCheckIn(numParticles, forceX, forceY, forceZ);
+  #if USE_PROXY_PATCHES != 0
+    proxyPatchProxy.ckLocalBranch()->forceCheckIn(numParticles, forceX, forceY, forceZ);
+  #else
+    patchArrayProxy(thisIndex.x, thisIndex.y, thisIndex.z).forceCheckIn(numParticles, forceX, forceY, forceZ);
+  #endif
 
   // DMK - DEBUG
   NetworkProgress;
index a373842911ec3ce04bab7aad6c81ccc30121cd3f..61219af15944144cee10a54b10a9ee215cc7feb9 100644 (file)
@@ -5,20 +5,29 @@ module selfCompute {
 
   array[3D] SelfCompute {
 
-    entry SelfCompute(int numParticlesPerPatch);
-
-    entry [accel] void doCalc(int numParticles,
-                              float particleX[numParticles],
-                              float particleY[numParticles],
-                              float particleZ[numParticles],
-                              float particleQ[numParticles]
-                             )[
-                               readonly : int thisIndex_x <impl_obj->thisIndex.x>,
-                               readonly : int thisIndex_y <impl_obj->thisIndex.y>,
-                              writeonly : float f0_x[numParticles] <impl_obj->forceX>,
-                              writeonly : float f0_y[numParticles] <impl_obj->forceY>,
-                              writeonly : float f0_z[numParticles] <impl_obj->forceZ>
-                             ] {
+    entry SelfCompute();
+
+    entry void init(int numParticlesPerPatch);
+
+    entry void patchData(int numParticles,
+                         float particleX[numParticles],
+                         float particleY[numParticles],
+                         float particleZ[numParticles],
+                         float particleQ[numParticles]
+                        );
+
+    entry [accel] void doCalc()[
+                                 readonly : int numParticles <impl_obj->numParticles>,
+                                 readonly : int thisIndex_x <impl_obj->thisIndex.x>,
+                                 readonly : int thisIndex_y <impl_obj->thisIndex.y>,
+                                 readonly : float particleX[numParticles] <impl_obj->particleX>,
+                                 readonly : float particleY[numParticles] <impl_obj->particleY>,
+                                 readonly : float particleZ[numParticles] <impl_obj->particleZ>,
+                                 readonly : float particleQ[numParticles] <impl_obj->particleQ>,
+                                writeonly : float f0_x[numParticles] <impl_obj->forceX>,
+                                writeonly : float f0_y[numParticles] <impl_obj->forceY>,
+                                writeonly : float f0_z[numParticles] <impl_obj->forceZ>
+                               ] {
 
       // Calculate the electrostatic force (coulumb's law) between the particles
       //   F = (k_e * (q_0 * q_1)) / (r^2)
@@ -138,4 +147,4 @@ module selfCompute {
 
   };
 
-};
\ No newline at end of file
+};
index 30e698335500be2b87457a140650385840b2ead3..660d453ab895b12a94103db2a84172702d93894d 100644 (file)
@@ -2,8 +2,9 @@
 #define __SELF_COMPUTE_H__
 
 
-#include "selfCompute.decl.h"
 #include "md_config.h"
+#include "selfCompute.decl.h"
+#include "patch.h"
 
 
 class SelfCompute : public CBase_SelfCompute {
@@ -14,20 +15,29 @@ class SelfCompute : public CBase_SelfCompute {
 
   private:
 
-    /// Force Buffers ///
+    /// Member Variables ///
     int numParticles;
+    float* particleX;
+    float* particleY;
+    float* particleZ;
+    float* particleQ;
     float* forceX;
     float* forceY;
     float* forceZ;
 
+    CProxy_ProxyPatch proxyPatchProxy;
+
   public:
 
     /// Constructor(s) \ Destructor ///
-    SelfCompute(int numParticlesPerPatch);
+    SelfCompute();
     SelfCompute(CkMigrateMessage* msg);
     ~SelfCompute();
 
     /// Entry Methods ///
+    void init(int numParticlesPerPatch);
+    void patchData(int numParticles, float* particleX, float* particleY, float* particleZ, float* particleQ, CProxy_ProxyPatch proxyPatchProxy);
+    void patchData(int numParticles, float* particleX, float* particleY, float* particleZ, float* particleQ);
     void doCalc_callback();
 
 };