examples/charm++: Always use CkWallTimer, not CmiWallTimer (tested)
[charm.git] / examples / charm++ / cell / md / selfCompute.C
1 #include "selfCompute.h"
2 #include "main.h"
3
4
5 SelfCompute::SelfCompute() {
6   numParticles = -1;
7   particleX = NULL;
8   particleY = NULL;
9   particleZ = NULL;
10   particleQ = NULL;
11   forceX = NULL;
12   forceY = NULL;
13   forceZ = NULL;
14 }
15
16
17 SelfCompute::SelfCompute(CkMigrateMessage* msg) {
18   CkAbort("SelfCompute::SelfCompute(CkMigrateMessage *msg) not implemented yet");
19 }
20
21
22 SelfCompute::~SelfCompute() {
23   #if USE_PROXY_PATCHES == 0
24     if (particleX != NULL) { CmiFreeAligned(particleX); particleX = NULL; }
25     if (particleY != NULL) { CmiFreeAligned(particleY); particleY = NULL; }
26     if (particleZ != NULL) { CmiFreeAligned(particleZ); particleZ = NULL; }
27     if (particleQ != NULL) { CmiFreeAligned(particleQ); particleQ = NULL; }
28   #endif
29   if (forceX != NULL) { CmiFreeAligned(forceX); forceX = NULL; }
30   if (forceY != NULL) { CmiFreeAligned(forceY); forceY = NULL; }
31   if (forceZ != NULL) { CmiFreeAligned(forceZ); forceZ = NULL; }
32   numParticles = -1;
33 }
34
35
36 void SelfCompute::init(int numParticlesPerPatch) {
37
38   // Allocate buffers for force data
39   numParticles = numParticlesPerPatch;
40   #if USE_PROXY_PATCHES == 0
41     particleX = (MD_FLOAT*)(CmiMallocAligned(numParticles * sizeof(MD_FLOAT), 128));
42     particleY = (MD_FLOAT*)(CmiMallocAligned(numParticles * sizeof(MD_FLOAT), 128));
43     particleZ = (MD_FLOAT*)(CmiMallocAligned(numParticles * sizeof(MD_FLOAT), 128));
44     particleQ = (MD_FLOAT*)(CmiMallocAligned(numParticles * sizeof(MD_FLOAT), 128));
45   #endif
46   forceX = (MD_FLOAT*)(CmiMallocAligned(numParticles * sizeof(MD_FLOAT), 128));
47   forceY = (MD_FLOAT*)(CmiMallocAligned(numParticles * sizeof(MD_FLOAT), 128));
48   forceZ = (MD_FLOAT*)(CmiMallocAligned(numParticles * sizeof(MD_FLOAT), 128));
49
50   // Check in with the main chare
51   mainProxy.initCheckIn();
52 }
53
54
55 void SelfCompute::patchData(int numParticles, MD_FLOAT* particleX, MD_FLOAT* particleY, MD_FLOAT* particleZ, MD_FLOAT* particleQ, CProxy_ProxyPatch proxyPatchProxy) {
56   #if USE_PROXY_PATCHES != 0
57     this->proxyPatchProxy = proxyPatchProxy;
58   #endif
59   patchData(numParticles, particleX, particleY, particleZ, particleQ);
60 }
61
62 void SelfCompute::patchData(int numParticles, MD_FLOAT* particleX, MD_FLOAT* particleY, MD_FLOAT* particleZ, MD_FLOAT* particleQ) {
63
64   // Copy the data from the parameters
65   #if USE_PROXY_PATCHES != 0
66     this->particleX = particleX;
67     this->particleY = particleY;
68     this->particleZ = particleZ;
69     this->particleQ = particleQ;
70   #else
71     memcpy(this->particleX, particleX, numParticles * sizeof(MD_FLOAT));
72     memcpy(this->particleY, particleY, numParticles * sizeof(MD_FLOAT));
73     memcpy(this->particleZ, particleZ, numParticles * sizeof(MD_FLOAT));
74     memcpy(this->particleQ, particleQ, numParticles * sizeof(MD_FLOAT));
75   #endif
76
77   // Initiate the calculation for this compute
78   thisProxy(thisIndex.x, thisIndex.y, thisIndex.z).doCalc();
79 }
80
81
82 void SelfCompute::doCalc_callback() {
83
84   // DMK - DEBUG
85   #if ENABLE_USER_EVENTS != 0
86     double __start_time__ = CkWallTimer();
87   #endif
88
89   // DMK - DEBUG
90   #if COUNT_FLOPS != 0
91     globalFlopCount += localFlopCount;
92   #endif
93
94   // DMK - DEBUG
95   NetworkProgress;
96
97   #if USE_PROXY_PATCHES != 0
98     proxyPatchProxy.ckLocalBranch()->forceCheckIn(numParticles, forceX, forceY, forceZ);
99   #else
100     patchArrayProxy(thisIndex.x, thisIndex.y, thisIndex.z).forceCheckIn(numParticles, forceX, forceY, forceZ);
101   #endif
102
103   // DMK - DEBUG
104   NetworkProgress;
105
106   // DMK - DEBUG
107   #if ENABLE_USER_EVENTS != 0
108     double __end_time__ = CkWallTimer();
109     traceUserBracketEvent(PROJ_USER_EVENT_SELFCOMPUTE_DOCALC_CALLBACK, __start_time__, __end_time__);
110   #endif
111 }
112
113
114 #include "selfCompute.def.h"