Skip to content

Commit 4274cd6

Browse files
committed
Towards multi Process
1 parent e004bc5 commit 4274cd6

File tree

6 files changed

+66
-9
lines changed

6 files changed

+66
-9
lines changed

src/pmpo_MPMesh.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,6 @@ void MPMesh::CVTTrackingElmCenterBased(const int printVTPIndex){
212212
};
213213
p_MPs->parallel_for(CVTElmCalc,"CVTTrackingElmCenterBasedCalc");
214214

215-
assert(cudaDeviceSynchronize()==cudaSuccess);
216-
MPI_Barrier(MPI_COMM_WORLD);
217-
printf("After Tracking \n");
218-
219215
if(printVTPIndex>=0 && numMPs>0){
220216
Vec3dView::HostMirror h_history = Kokkos::create_mirror_view(history);
221217
Vec3dView::HostMirror h_resultLeft = Kokkos::create_mirror_view(resultLeft);
@@ -228,7 +224,6 @@ void MPMesh::CVTTrackingElmCenterBased(const int printVTPIndex){
228224
Kokkos::deep_copy(h_resultRight, resultRight);
229225
Kokkos::deep_copy(h_mpTgtPos, mpTgtPosArray);
230226
Kokkos::deep_copy(h_counter, counter);
231-
printf("Host counter value: %d\n", h_counter(0));
232227
// printVTP file
233228
char* fileOutput = (char *)malloc(sizeof(char) * 256);
234229
sprintf(fileOutput, "polyMPOCVTTrackingElmCenter_MPtracks_%d_%d.vtp", comm_rank, printVTPIndex);
@@ -253,10 +248,6 @@ void MPMesh::CVTTrackingElmCenterBased(const int printVTPIndex){
253248
fprintf(pFile," </DataArray>\n </Lines>\n </Piece>\n </PolyData>\n</VTKFile>\n");
254249
fclose(pFile);
255250
}
256-
assert(cudaDeviceSynchronize()==cudaSuccess);
257-
MPI_Barrier(MPI_COMM_WORLD);
258-
printf("After printing particle paths \n");
259-
260251

261252
pumipic::RecordTime("PolyMPO_CVTTrackingElmCenterBased", timer.seconds());
262253
}

src/pmpo_c.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ 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+
void* arg4, void* arg5, void*arg6) {
217+
checkMPMeshValid(p_mpmesh);
218+
auto p_MPs = ((polyMPO::MPMesh*)p_mpmesh)->p_MPs;
219+
std::function<int()> polyMPO_getMPASAppID = [getMPASAppID, arg1, arg2, arg3, arg4, arg5, arg6]()
220+
{getMPASAppID(arg1, arg2, arg3, arg4, arg5, arg6); return *(static_cast<int*>(arg5));};
221+
p_MPs->setAppIDFunc(polyMPO_getMPASAppID);
222+
}
223+
215224
void polympo_getMPCurElmID_f(MPMesh_ptr p_mpmesh,
216225
const int numMPs,
217226
int* elmIDs){

src/pmpo_c.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ void polympo_setMPICommunicator_f(MPMesh_ptr p_mpmesh, MPI_Fint fcomm);
2222
void polympo_createMPs_f(MPMesh_ptr p_mpmesh, const int numElms, const int numMPs, int* mpsPerElm, const int* mp2Elm, const int* isMPActive);
2323
void polympo_startRebuildMPs_f(MPMesh_ptr p_mpmesh, const int numMPs, const int* allTgtMpElmIn, const int* addedMPMask);
2424
void polympo_finishRebuildMPs_f(MPMesh_ptr p_mpmesh);
25+
2526
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+
void* arg4, void*arg5, void* arg6);
29+
2630
void polympo_getMPCurElmID_f(MPMesh_ptr p_mpmesh, const int numMPs, int* elmIDs);
2731
void polympo_setMPLatLonRotatedFlag_f(MPMesh_ptr p_mpmesh, const int isRotateFlag);
2832

src/pmpo_defines.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +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*, void*, void*, void*);
1112

1213
using space_t = Kokkos::DefaultExecutionSpace::memory_space;
1314

src/pmpo_fortran.f90

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,28 @@ subroutine polympo_setAppIDFunc(mpMesh, getNext, appIDs) &
110110
type(c_funptr), value :: getNext
111111
type(c_ptr), value :: appIDs
112112
end subroutine
113+
114+
!---------------------------------------------------------------------------
115+
!> @brief Stores pointer to appID data structure and a function to retrieve them used in migration
116+
!> @param mpmesh(in/out) MPMesh object
117+
!> @param getNext(in) Pointer to function that returns next App IDs
118+
!> @param appIDs(in) Pointer to opaque data application data structure (that may contain all available app IDs)
119+
!---------------------------------------------------------------------------
120+
subroutine polympo_setMPASAppIDFunc(mpMesh, getMPASAppID, &
121+
arg1, arg2, arg3, arg4, arg5, arg6) &
122+
bind(C, NAME='polympo_setMPASAppIDFunc_f')
123+
use :: iso_c_binding
124+
type(c_ptr), value :: mpMesh
125+
type(c_funptr), value :: getMPASAppID
126+
type(c_ptr), value :: arg1
127+
type(c_ptr), value :: arg2
128+
type(c_ptr), value :: arg3
129+
type(c_ptr), value :: arg4
130+
type(c_ptr), value :: arg5
131+
type(c_ptr), value :: arg6
132+
end subroutine
133+
134+
113135
!---------------------------------------------------------------------------
114136
!> @brief get the current element ID MP array from a polympo array
115137
!> @param mpmesh(in/out) MPMesh object

src/pmpo_materialPoints.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ void MaterialPoints::migrate() {
138138
Kokkos::Timer timer;
139139
auto MPs2Elm = getData<MPF_Tgt_Elm_ID>();
140140
auto MPs2Proc = getData<MPF_Tgt_Proc_ID>();
141+
auto mpAppID = getData<polyMPO::MPF_MP_APP_ID>();
141142

142143
IntView new_elem("new_elem", MPs->capacity());
143144
IntView new_process("new_process", MPs->capacity());
@@ -148,11 +149,40 @@ void MaterialPoints::migrate() {
148149
if (mask) {
149150
new_elem(mp) = MPs2Elm(mp);
150151
new_process(mp) = MPs2Proc(mp);
152+
if(rank!=new_process(mp)){
153+
mpAppID(mp)=-1;
154+
printf("Particle migrated and so its AppID is -1\n");
155+
}
151156
}
152157
};
153158
parallel_for(setMigrationFields, "setMigrationFields");
154159
MPs->migrate(new_elem, new_process);
155160

161+
//Since rebuilt
162+
mpAppID = getData<polyMPO::MPF_MP_APP_ID>();
163+
//Count MPs that have -1 appID, so that we can count no of MPs received
164+
Kokkos::View<int*> numReceivedMPs("numReceivedMPs", 1);
165+
Kokkos::deep_copy(numReceivedMPs, 0);
166+
auto countnewMPs = PS_LAMBDA(const int& e, const int& mp, const bool& mask) {
167+
if(mask){
168+
if (mpAppID(mp) == -1)
169+
Kokkos::atomic_add(&numReceivedMPs(0), 1);
170+
}
171+
};
172+
parallel_for(countnewMPs, "countReceivedPtcls");
173+
Kokkos::fence();
174+
175+
auto numReceivedMPs_host = Kokkos::create_mirror_view(numReceivedMPs);
176+
Kokkos::deep_copy(numReceivedMPs_host, numReceivedMPs);
177+
if(numReceivedMPs_host(0))
178+
std::cout <<"Rank "<<rank<<" received "<<numReceivedMPs_host(0)<< "MPs \n";
179+
180+
std::vector<int> added_mpIDs(numReceivedMPs_host(0));
181+
for(int i=0; i<numReceivedMPs_host(0); i++){
182+
printf("Trying to find an ID for a material point\n");
183+
auto xx = getNextAppID();
184+
}
185+
156186
if (getOpMode() == polyMPO::MP_DEBUG)
157187
printf("Material point migration: %f\n", timer.seconds());
158188
pumipic::RecordTime("PolyMPO_migrate", timer.seconds());

0 commit comments

Comments
 (0)