Skip to content

Commit aeb3e65

Browse files
committed
New particleID can be found from MPAS in polyMPO
1 parent 8e310cf commit aeb3e65

File tree

6 files changed

+64
-30
lines changed

6 files changed

+64
-30
lines changed

src/pmpo_MPMesh.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "pmpo_utils.hpp"
33
#include "pmpo_MPMesh.hpp"
44
#include "pmpo_wachspressBasis.hpp"
5-
5+
#include <unistd.h>
66
namespace polyMPO{
77

88
void printVTP_mesh(MPMesh& mpMesh, int printVTPIndex=-1);
@@ -345,7 +345,7 @@ void MPMesh::push(){
345345

346346
static int count=0;
347347
std::cout<<"Push"<<" "<<count<<std::endl;
348-
if(count>473) exit(-1);
348+
349349
Kokkos::Timer timer;
350350

351351
p_mesh->computeRotLatLonIncr();
@@ -358,7 +358,7 @@ void MPMesh::push(){
358358

359359
bool anyIsMigrating = false;
360360
do {
361-
CVTTrackingElmCenterBased(count); // move to Tgt_XYZ
361+
CVTTrackingElmCenterBased(); // move to Tgt_XYZ
362362
assert(cudaDeviceSynchronize() == cudaSuccess);
363363
p_MPs->updateMPSlice<MPF_Cur_Pos_XYZ, MPF_Tgt_Pos_XYZ>(); // Tgt_XYZ becomes Cur_XYZ
364364
p_MPs->updateMPSlice<MPF_Cur_Pos_Rot_Lat_Lon, MPF_Tgt_Pos_Rot_Lat_Lon>(); // Tgt becomes Cur
@@ -369,12 +369,26 @@ void MPMesh::push(){
369369
p_MPs->migrate();
370370
else
371371
p_MPs->rebuild();
372+
printf("Done till here 0\n");
372373

373374
p_MPs->updateMPElmID(); //update mpElm IDs slices
374375
reconstructSlices();
375376
}
376377
while (anyIsMigrating);
377-
count ++;
378+
379+
count ++;
380+
381+
volatile int i = 0;
382+
char hostname[256];
383+
gethostname(hostname, sizeof(hostname));
384+
MPI_Comm comm = p_MPs->getMPIComm();
385+
int comm_rank;
386+
MPI_Comm_rank(comm, &comm_rank);
387+
printf("Rank %d PID %d on %s ready for attach\n", comm_rank, getpid(), hostname);
388+
fflush(stdout);
389+
if(count==480) sleep(100);
390+
391+
printf("Done till here\n");
378392
pumipic::RecordTime("PolyMPO_push", timer.seconds());
379393
}
380394

src/pmpo_c.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,13 @@ void polympo_setAppIDFunc_f(MPMesh_ptr p_mpmesh, IntVoidFunc getNext, void* appI
212212
//p_MPs->setAppIDFunc(getNextAppID);
213213
}
214214

215-
void polympo_setMPASAppIDFunc_f(MPMesh_ptr p_mpmesh, VoidVoidFunc getMPASAppID, void* arg1, void*arg2, void*arg3,
216-
const int arg4, const int arg5) {
215+
//arg1 is blockPtr, arg2 is blockSize and arg3 is nCells
216+
void polympo_setMPASAppIDFunc_f(MPMesh_ptr p_mpmesh, VoidVoidFunc getMPASAppID, void*arg1,
217+
const int arg2, const int arg3) {
217218
checkMPMeshValid(p_mpmesh);
218219
auto p_MPs = ((polyMPO::MPMesh*)p_mpmesh)->p_MPs;
219-
std::function<int(int)> polyMPO_getMPASAppID = [getMPASAppID, arg1, arg2, arg3, arg4, arg5](int iCell)
220-
{ int iParticleNew; getMPASAppID(arg1, arg2, arg3, arg4, iCell, iParticleNew, arg5); return iParticleNew;};
220+
std::function<int(int)> polyMPO_getMPASAppID = [getMPASAppID, arg1, arg2, arg3](int iCell)
221+
{ int iParticleNew=-1; getMPASAppID(arg1, arg2, arg3, iCell, iParticleNew); return iParticleNew;};
221222
p_MPs->setAppIDFunc(polyMPO_getMPASAppID);
222223
}
223224

src/pmpo_c.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ void polympo_startRebuildMPs_f(MPMesh_ptr p_mpmesh, const int numMPs, const int*
2424
void polympo_finishRebuildMPs_f(MPMesh_ptr p_mpmesh);
2525

2626
void polympo_setAppIDFunc_f(MPMesh_ptr p_mpmesh, IntVoidFunc getNext, void* appIDs);
27-
void polympo_setMPASAppIDFunc_f(MPMesh_ptr p_mpmesh, VoidVoidFunc getMPASAppID, void* arg1, void* arg2, void*arg3,
28-
const int arg4, const int arg5);
27+
void polympo_setMPASAppIDFunc_f(MPMesh_ptr p_mpmesh, VoidVoidFunc getMPASAppID, void* arg1, const int arg2, const int arg3);
2928

3029
void polympo_getMPCurElmID_f(MPMesh_ptr p_mpmesh, const int numMPs, int* elmIDs);
3130
void polympo_setMPLatLonRotatedFlag_f(MPMesh_ptr p_mpmesh, const int isRotateFlag);

src/pmpo_defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
typedef void* MPMesh_ptr;
99
//Function that receives void* and returns an int
1010
typedef int (*IntVoidFunc)(void*);
11-
typedef void (*VoidVoidFunc)(void*, void*, void*, const int, int, int, const int);
11+
typedef void (*VoidVoidFunc)(void*, const int, const int, const int, int&);
1212

1313
using space_t = Kokkos::DefaultExecutionSpace::memory_space;
1414

src/pmpo_fortran.f90

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,14 @@ subroutine polympo_setAppIDFunc(mpMesh, getNext, appIDs) &
118118
!> @param appIDs(in) Pointer to opaque data application data structure (that may contain all available app IDs)
119119
!---------------------------------------------------------------------------
120120
subroutine polympo_setMPASAppIDFunc(mpMesh, getMPASAppID, &
121-
arg1, arg2, arg3, arg4, arg5) &
121+
arg1, arg2, arg3) &
122122
bind(C, NAME='polympo_setMPASAppIDFunc_f')
123123
use :: iso_c_binding
124124
type(c_ptr), value :: mpMesh
125125
type(c_funptr), value :: getMPASAppID
126126
type(c_ptr), value :: arg1
127-
type(c_ptr), value :: arg2
128-
type(c_ptr), value :: arg3
129-
integer(c_int), intent(in), value :: arg4
130-
integer(c_int), intent(in), value :: arg5
127+
integer(c_int), intent(in), value :: arg2
128+
integer(c_int), intent(in), value :: arg3
131129
end subroutine
132130

133131

src/pmpo_materialPoints.cpp

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ void MaterialPoints::migrate() {
158158
parallel_for(setMigrationFields, "setMigrationFields");
159159
MPs->migrate(new_elem, new_process);
160160

161-
//SINCE REBUILT, mpAppID needs to be be recalled
161+
//AS REBUILT, mpAppID needs to be be recalled
162162
mpAppID = getData<polyMPO::MPF_MP_APP_ID>();
163-
//Count MPs that have -1 appID, so that we can count no of MPs received
163+
//Count MPs that have -1 appID, so that we can count no of MPs received by a rank
164164
Kokkos::View<int*> numReceivedMPs("numReceivedMPs", 1);
165165
Kokkos::deep_copy(numReceivedMPs, 0);
166166
auto countnewMPs = PS_LAMBDA(const int& e, const int& mp, const bool& mask) {
@@ -170,34 +170,56 @@ void MaterialPoints::migrate() {
170170
}
171171
};
172172
parallel_for(countnewMPs, "countReceivedPtcls");
173-
Kokkos::fence();
174-
//Bring them to CPU and print particles received
175173
auto numReceivedMPs_host = Kokkos::create_mirror_view(numReceivedMPs);
176174
Kokkos::deep_copy(numReceivedMPs_host, numReceivedMPs);
177-
if(numReceivedMPs_host(0))
178-
std::cout <<"Rank "<<rank<<" received "<<numReceivedMPs_host(0)<< "MPs \n";
179175

180-
//Another array that contains element id of the the MPs that have migrated
176+
//Another array that contains new element id of the the MPs that have migrated
177+
//Array size is #elements received
181178
Kokkos::View<int*> receivedMPs2Elm("ReceivedMPs2Elm", numReceivedMPs_host(0));
182179
Kokkos::View<int*> counter("counter", 1);
180+
Kokkos::deep_copy(counter, 0);
183181
auto set_new_elem = PS_LAMBDA(const int& e, const int& mp, const bool& mask) {
184182
if(mask){
185183
if (mpAppID(mp) == -1){
186-
auto xx=Kokkos::atomic_fetch_add(&counter(0), 1);
187-
receivedMPs2Elm(xx) = e;
184+
auto count_temp=Kokkos::atomic_fetch_add(&counter(0), 1);
185+
receivedMPs2Elm(count_temp) = e;
188186
}
189187
}
190188
};
191-
parallel_for(set_new_elem, "countReceivedPtcls");
192-
//NEED AN ASSERT ELEMNT DOING COUNTER=#RECEIVED MPs
189+
parallel_for(set_new_elem, "countReceivedPtcls");
190+
//Bring them to CPU so that elm_id can be passed and a new mpAppID can be found from CPU
193191
auto receivedMPs2Elm_host = Kokkos::create_mirror_view(receivedMPs2Elm);
194192
Kokkos::deep_copy(receivedMPs2Elm_host, receivedMPs2Elm);
195-
193+
auto counter_host = Kokkos::create_mirror_view(counter);
194+
Kokkos::deep_copy(counter_host, counter);
195+
assert(numReceivedMPs_host(0)==counter_host(0));
196+
if(counter_host(0))
197+
std::cout <<"Rank "<<rank<<" received "<<counter_host(0)<<" "<< numReceivedMPs_host(0) <<" MPs \n";
198+
199+
//Find new AppIDS from CPU-MPAS and store so that they can be added to MPs that have appID=-1
200+
std::vector<int> appIDs;
196201
for(int i=0; i<numReceivedMPs_host(0); i++){
197-
printf("Trying to find an ID for a material point\n");
198-
auto xx = getNextAppID(receivedMPs2Elm_host(i)+1);
202+
auto app_id_new = getNextAppID(receivedMPs2Elm_host(i)+1);
203+
printf("Trying to find ID for MP located in %d and it's %d \n", receivedMPs2Elm_host(i), app_id_new);
204+
appIDs.push_back(app_id_new);
199205
}
206+
kkViewHostU<int*> appIDs_host(appIDs.data(), appIDs.size());
207+
Kokkos::View<int*> appIDs_d("appIDsDevice", appIDs.size());
208+
Kokkos::deep_copy(appIDs_d, appIDs_host);
200209

210+
//If the mpAppID is -1 assign a new mpAppID
211+
Kokkos::deep_copy(counter, 0);
212+
auto set_appID = PS_LAMBDA(const int& e, const int& mp, const bool& mask) {
213+
if(mask){
214+
if (mpAppID(mp) == -1){
215+
auto count_temp=Kokkos::atomic_fetch_add(&counter(0), 1);
216+
mpAppID(mp)=appIDs_d(count_temp)-1;
217+
printf("Count_temp %d and new appID %d \n", count_temp, mpAppID(mp));
218+
}
219+
}
220+
};
221+
parallel_for(set_appID, "setApplicationIDs");
222+
201223
if (getOpMode() == polyMPO::MP_DEBUG)
202224
printf("Material point migration: %f\n", timer.seconds());
203225
pumipic::RecordTime("PolyMPO_migrate", timer.seconds());

0 commit comments

Comments
 (0)