Skip to content

Commit

Permalink
more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhil-jain committed Oct 20, 2011
1 parent a9dca9d commit 564a57c
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 23 deletions.
19 changes: 12 additions & 7 deletions Compute.C
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extern /* readonly */ BigReal stepTime;
Compute::Compute() {
cellCount = 0;
bmsgLenAll = -1;
stepCount = 0;
usesAtSync = CmiTrue;
}

Expand All @@ -35,14 +36,16 @@ void Compute::interact(ParticleDataMsg *msg){

// self interaction check
if (thisIndex.x1 ==thisIndex.x2 && thisIndex.y1 ==thisIndex.y2 && thisIndex.z1 ==thisIndex.z2) {
stepCount++;
bool doatSync = false;
bmsgLenAll = -1;
if (msg->doAtSync){
doatSync = true;
}
CkGetSectionInfo(cookie1,msg);
energy = calcInternalForces(msg, &cookie1);
contribute(sizeof(double),&energy,CkReduction::sum_double,CkCallback(CkIndex_Main::energySumP(NULL),mainProxy));
energy = calcInternalForces(msg, &cookie1, stepCount);
if(stepCount == 1 || stepCount == finalStepCount)
contribute(sizeof(double),&energy,CkReduction::sum_double,CkCallback(CkIndex_Main::energySumP(NULL),mainProxy));
if(doatSync)
AtSync();
} else {
Expand All @@ -53,23 +56,25 @@ void Compute::interact(ParticleDataMsg *msg){
} else if (cellCount == 1) {
// if both particle sets are received, compute interaction
cellCount = 0;
stepCount++;
bool doatSync = false;
bmsgLenAll = -1;
if (msg->doAtSync){
doatSync = true;
}
if (bufferedMsg->x*patchArrayDimY*patchArrayDimZ + bufferedMsg->y*patchArrayDimZ + bufferedMsg->z < msg->x*patchArrayDimY*patchArrayDimZ + msg->y*patchArrayDimZ + msg->z){
if (bufferedMsg->lengthAll <= msg->lengthAll)
energy = calcPairForces(bufferedMsg, msg, &cookie1, &cookie2);
energy = calcPairForces(bufferedMsg, msg, &cookie1, &cookie2,stepTime);
else
energy = calcPairForces(msg, bufferedMsg, &cookie2, &cookie1);
energy = calcPairForces(msg, bufferedMsg, &cookie2, &cookie1,stepTime);
} else {
if (bufferedMsg->lengthAll <= msg->lengthAll)
energy = calcPairForces(bufferedMsg, msg, &cookie2, &cookie1);
energy = calcPairForces(bufferedMsg, msg, &cookie2, &cookie1,stepTime);
else
energy = calcPairForces(msg, bufferedMsg, &cookie1, &cookie2);
energy = calcPairForces(msg, bufferedMsg, &cookie1, &cookie2,stepTime);
}
contribute(sizeof(double),&energy,CkReduction::sum_double,CkCallback(CkIndex_Main::energySumP(NULL),mainProxy));
if(stepCount == 1 || stepCount == finalStepCount)
contribute(sizeof(double),&energy,CkReduction::sum_double,CkCallback(CkIndex_Main::energySumP(NULL),mainProxy));
bufferedMsg = NULL;
if(doatSync)
AtSync();
Expand Down
2 changes: 2 additions & 0 deletions Compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Compute : public CBase_Compute {
private:
int cellCount; // to count the number of interact() calls
int bmsgLenAll;
int stepCount;
ParticleDataMsg *bufferedMsg;
CkSectionInfo cookie1;
CkSectionInfo cookie2;
Expand All @@ -20,6 +21,7 @@ class Compute : public CBase_Compute {

void pup(PUP::er &p) {
CBase_Compute::pup(p);
p | stepCount;
p | cookie1;
p | cookie2;
if (p.isUnpacking() && CkInRestarting()) {
Expand Down
4 changes: 2 additions & 2 deletions Main.C
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void Main::energySumK(CkReductionMsg *msg) {
}
prevEnergy = energy;
energy = 0;
patchArray.testDone(1);
//patchArray.testDone(1);
}
}

Expand All @@ -162,7 +162,7 @@ void Main::energySumP(CkReductionMsg *msg) {
}
prevEnergy = energy;
energy = 0;
patchArray.testDone(1);
//patchArray.testDone(1);
}
}

Expand Down
12 changes: 7 additions & 5 deletions Patch.C
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ Patch::Patch() {
particles[i].x = drand48() * PATCH_SIZE_X + thisIndex.x * PATCH_SIZE_X;
particles[i].y = drand48() * PATCH_SIZE_Y + thisIndex.y * PATCH_SIZE_Y;
particles[i].z = drand48() * PATCH_SIZE_Z + thisIndex.z * PATCH_SIZE_Z;
particles[i].vx = 0;
particles[i].vy = 0;
particles[i].vz = 0;
particles[i].vx = (drand48() - 0.5) * .2 * MAX_VELOCITY;
particles[i].vy = (drand48() - 0.5) * .2 * MAX_VELOCITY;
particles[i].vz = (drand48() - 0.5) * .2 * MAX_VELOCITY;
particles[i].fx = 0;
particles[i].fy = 0;
particles[i].fz = 0;
Expand Down Expand Up @@ -269,7 +269,8 @@ void Patch::updateProperties() {
powFteen = pow(10.0, -15);
realTimeDelta = DEFAULT_DELTA * powFteen;
for(i = 0; i < particles.length(); i++) {
energy += (0.5*particles[i].mass*(particles[i].vx*particles[i].vx + particles[i].vy*particles[i].vy*particles[i].vz*particles[i].vz));
if(stepCount == 0 || stepCount == (finalStepCount - 1))
energy += (0.5*particles[i].mass*(particles[i].vx*particles[i].vx + particles[i].vy*particles[i].vy*particles[i].vz*particles[i].vz));

// applying kinetic equations
invMassParticle = 1 / particles[i].mass;
Expand All @@ -290,7 +291,8 @@ void Patch::updateProperties() {
particles[i].fy = 0.0;
particles[i].fz = 0.0;
}
contribute(sizeof(double),&energy,CkReduction::sum_double,CkCallback(CkIndex_Main::energySumK(NULL),mainProxy));
if(stepCount == 0 || stepCount == (finalStepCount - 1))
contribute(sizeof(double),&energy,CkReduction::sum_double,CkCallback(CkIndex_Main::energySumK(NULL),mainProxy));
}

void Patch::limitVelocity(Particle &p) {
Expand Down
2 changes: 1 addition & 1 deletion defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ typedef double BigReal;
#define VDW_B (1.031093844 * pow(10.0, -77))

#define ENERGY_VAR (1.0 * pow(10.0,-5))
#define PARTICLES_PER_PATCH 63
#define PARTICLES_PER_PATCH 75

#define DEFAULT_DELTA 1 // in femtoseconds

Expand Down
4 changes: 1 addition & 3 deletions leanmd.ci
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mainmodule leanmd {
entry void receiveParticles(CkVec<Particle> updates);
entry void ResumeFromSync();
entry void nextStep();
entry void testDone(int proceed);
//entry void testDone(int proceed);

entry void doStep() {
atomic {
Expand Down Expand Up @@ -72,8 +72,6 @@ mainmodule leanmd {
stepCount, ((timer - stepTime)/20)*1000);
stepTime = CkWallTimer();
}
}
when testDone(int proceed) atomic {
stepCount++;
patchArray(thisIndex.x,thisIndex.y,thisIndex.z).nextStep();
}
Expand Down
17 changes: 12 additions & 5 deletions physics.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ extern /* readonly */ BigReal stepTime;

#define BLOCK_SIZE 512

inline double calcPairForces(ParticleDataMsg* first, ParticleDataMsg* second, CkSectionInfo* cookie1, CkSectionInfo* cookie2) {
inline double calcPairForces(ParticleDataMsg* first, ParticleDataMsg* second, CkSectionInfo* cookie1, CkSectionInfo* cookie2, int stepCount) {
int i, j, jpart, ptpCutOffSqd, diff;
int firstLen = first->lengthAll;
int secondLen = second->lengthAll;
BigReal powTwenty, powTen, rx, ry, rz, r, rsqd, fx, fy, fz, f, fr;
double rSix, rTwelve;
double energy = 0;
int doEnergy = 0;
if(stepCount == 1 || stepCount == finalStepCount)
doEnergy = 1;

ParticleForceMsg *firstmsg = new (firstLen) ParticleForceMsg;
ParticleForceMsg *secondmsg = new (secondLen) ParticleForceMsg;
Expand Down Expand Up @@ -71,7 +74,8 @@ inline double calcPairForces(ParticleDataMsg* first, ParticleDataMsg* second, Ck
rSix = ((double)rsqd) * rsqd * rsqd;
rTwelve = rSix * rSix;
f = (BigReal)(VDW_A / rTwelve - VDW_B / rSix);
energy += (BigReal)( VDW_A / (12*rTwelve) - VDW_B / (6*rSix));
if(doEnergy)
energy += (BigReal)( VDW_A / (12*rTwelve) - VDW_B / (6*rSix));
fr = f /r;
fx = rx * fr * powTen;
fy = ry * fr * powTen;
Expand Down Expand Up @@ -99,13 +103,15 @@ inline double calcPairForces(ParticleDataMsg* first, ParticleDataMsg* second, Ck
}

// Local function to compute all the interactions between pairs of particles in two sets
inline double calcInternalForces(ParticleDataMsg* first, CkSectionInfo *cookie1) {
inline double calcInternalForces(ParticleDataMsg* first, CkSectionInfo *cookie1, int stepCount) {
int i, j, ptpCutOffSqd;
int firstLen = first->lengthAll;
BigReal powTwenty, powTen, firstx, firsty, firstz, rx, ry, rz, r, rsqd, fx, fy, fz, f, fr;
double rSix, rTwelve;
double energy = 0;

int doEnergy = 0;
if(stepCount == 1 || stepCount == finalStepCount)
doEnergy = 1;
ParticleForceMsg *firstmsg = new (firstLen) ParticleForceMsg;
firstmsg->lengthUpdates = firstLen;

Expand All @@ -129,7 +135,8 @@ inline double calcInternalForces(ParticleDataMsg* first, CkSectionInfo *cookie1)
rSix = ((double)rsqd) * rsqd * rsqd;
rTwelve = rSix * rSix;
f = (BigReal)(VDW_A / rTwelve - VDW_B / rSix);
energy += (BigReal)( VDW_A / (12*rTwelve) - VDW_B / (6*rSix));
if(doEnergy)
energy += (BigReal)( VDW_A / (12*rTwelve) - VDW_B / (6*rSix));

fr = f /r;
fx = rx * fr * powTen;
Expand Down

0 comments on commit 564a57c

Please sign in to comment.