Skip to content

Commit 607de99

Browse files
committed
Some more redudancy removed like trying to get new AppID from MPAS
1 parent a9e74ab commit 607de99

File tree

5 files changed

+8
-125
lines changed

5 files changed

+8
-125
lines changed

src/pmpo_c.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,7 @@ void polympo_setAppIDFunc_f(MPMesh_ptr p_mpmesh, IntVoidFunc getNext, void* appI
249249
checkMPMeshValid(p_mpmesh);
250250
auto p_MPs = ((polyMPO::MPMesh*)p_mpmesh)->p_MPs;
251251
polyMPO::IntFunc getNextAppID = [getNext, appIDs]() { return getNext(appIDs); };
252-
//p_MPs->setAppIDFunc(getNextAppID);
253-
}
254-
255-
//arg1 is blockPtr, arg2 is blockSize and arg3 is nCells
256-
void polympo_setMPASAppIDFunc_f(MPMesh_ptr p_mpmesh, VoidVoidFunc getMPASAppID, void*arg1,
257-
const int arg2, const int arg3) {
258-
checkMPMeshValid(p_mpmesh);
259-
auto p_MPs = ((polyMPO::MPMesh*)p_mpmesh)->p_MPs;
260-
std::function<int(int)> polyMPO_getMPASAppID = [getMPASAppID, arg1, arg2, arg3](int iCell)
261-
{ int iParticleNew=-1; getMPASAppID(arg1, arg2, arg3, iCell, iParticleNew); return iParticleNew;};
262-
p_MPs->setAppIDFunc(polyMPO_getMPASAppID);
252+
p_MPs->setAppIDFunc(getNextAppID);
263253
}
264254

265255
void polympo_getMPTgtElmID_f(MPMesh_ptr p_mpmesh,
@@ -1263,7 +1253,7 @@ void polympo_setElmGlobal_f(MPMesh_ptr p_mpmesh, const int nCells, const int* ar
12631253
PMT_ALWAYS_ASSERT(p_mesh->meshEditable());
12641254
Kokkos::View<int*, Kokkos::HostSpace> arrayHost("arrayHost", nCells);
12651255
for (int i = 0; i < nCells; i++) {
1266-
arrayHost(i) = array[i] - 1; // Decrease each value by 1
1256+
arrayHost(i) = array[i] - 1; // TODO right now elmID offset is set after MPs initialized
12671257
}
12681258
//check the size
12691259
PMT_ALWAYS_ASSERT(nCells == p_mesh->getNumElements());

src/pmpo_c.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ int polympo_getMPCount_f(MPMesh_ptr p_mpmesh);
2828
void polympo_finishRebuildMPs_f(MPMesh_ptr p_mpmesh);
2929

3030
void polympo_setAppIDFunc_f(MPMesh_ptr p_mpmesh, IntVoidFunc getNext, void* appIDs);
31-
void polympo_setMPASAppIDFunc_f(MPMesh_ptr p_mpmesh, VoidVoidFunc getMPASAppID, void* arg1, const int arg2, const int arg3);
3231

3332
void polympo_getMPTgtElmID_f(MPMesh_ptr p_mpmesh, const int numMPs, int* elmIDs);
3433
void polympo_getMPCurElmID_f(MPMesh_ptr p_mpmesh, const int numMPs, int* elmIDs);

src/pmpo_fortran.f90

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,6 @@ subroutine polympo_setAppIDFunc(mpMesh, getNext, appIDs) &
125125
type(c_ptr), value :: appIDs
126126
end subroutine
127127

128-
!---------------------------------------------------------------------------
129-
!> @brief Stores pointer to appID data structure and a function to retrieve them used in migration
130-
!> @param mpmesh(in/out) MPMesh object
131-
!> @param getNext(in) Pointer to function that returns next App IDs
132-
!> @param appIDs(in) Pointer to opaque data application data structure (that may contain all available app IDs)
133-
!---------------------------------------------------------------------------
134-
subroutine polympo_setMPASAppIDFunc(mpMesh, getMPASAppID, &
135-
arg1, arg2, arg3) &
136-
bind(C, NAME='polympo_setMPASAppIDFunc_f')
137-
use :: iso_c_binding
138-
type(c_ptr), value :: mpMesh
139-
type(c_funptr), value :: getMPASAppID
140-
type(c_ptr), value :: arg1
141-
integer(c_int), intent(in), value :: arg2
142-
integer(c_int), intent(in), value :: arg3
143-
end subroutine
144-
145-
146128
!---------------------------------------------------------------------------
147129
!> @brief get the current element ID MP array from a polympo array
148130
!> @param mpmesh(in/out) MPMesh object

src/pmpo_materialPoints.cpp

Lines changed: 3 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,7 @@ void MaterialPoints::finishRebuild() {
114114
updateMaxAppID();
115115
ps::destroyViews<MaterialPointTypes>(rebuildFields.addedSlices_h);
116116
ps::destroyViews<MaterialPointTypes>(addedSlices_d);
117-
rebuildFields.ongoing = false;
118-
119-
//Debug
120-
/*
121-
int rank;
122-
MPI_Comm_rank(mpi_comm, &rank);
123-
if (rank==0) return;
124-
auto curr_elm=getData<MPF_Cur_Elm_ID>();
125-
auto tgt_elm =getData<MPF_Tgt_Elm_ID>();
126-
auto mpAppID = getData<polyMPO::MPF_MP_APP_ID>();
127-
auto testElm = PS_LAMBDA(const int& e, const int& mp, const bool& mask) {
128-
if (mask) {
129-
printf("R1: finishRebuild AppID %d Curr %d Tgt %d e %d \n", mpAppID(mp), curr_elm(mp), tgt_elm(mp), e);
130-
}
131-
};
132-
parallel_for(testElm, "curr_elm");
133-
*/
117+
rebuildFields.ongoing = false;
134118
}
135119

136120
MPI_Comm MaterialPoints::getMPIComm() {
@@ -166,7 +150,6 @@ void MaterialPoints::migrate() {
166150
Kokkos::Timer timer;
167151
auto MPs2Elm = getData<MPF_Tgt_Elm_ID>();
168152
auto MPs2Proc = getData<MPF_Tgt_Proc_ID>();
169-
auto mpAppID = getData<polyMPO::MPF_MP_APP_ID>();
170153

171154
IntView new_elem("new_elem", MPs->capacity());
172155
IntView new_process("new_process", MPs->capacity());
@@ -177,85 +160,20 @@ void MaterialPoints::migrate() {
177160
if (mask) {
178161
new_elem(mp) = MPs2Elm(mp);
179162
new_process(mp) = MPs2Proc(mp);
180-
if(rank!=new_process(mp)){
181-
printf("Particle %d in rank %d to be moved from %d %d \n", mpAppID(mp), rank, e, new_elem(mp) );
182-
mpAppID(mp)=-1;
183-
}
184163
}
185164
};
186165
parallel_for(setMigrationFields, "setMigrationFields");
187166
MPs->migrate(new_elem, new_process);
188167

189-
//AS REBUILT, mpAppID needs to be be recalled
190-
mpAppID = getData<polyMPO::MPF_MP_APP_ID>();
191-
//Count MPs that have -1 appID, so that we can count no of MPs received by a rank
192-
Kokkos::View<int*> numReceivedMPs("numReceivedMPs", 1);
193-
Kokkos::deep_copy(numReceivedMPs, 0);
194-
auto countnewMPs = PS_LAMBDA(const int& e, const int& mp, const bool& mask) {
195-
if(mask){
196-
if (mpAppID(mp) == -1)
197-
Kokkos::atomic_add(&numReceivedMPs(0), 1);
198-
}
199-
};
200-
parallel_for(countnewMPs, "countReceivedPtcls");
201-
auto numReceivedMPs_host = Kokkos::create_mirror_view(numReceivedMPs);
202-
Kokkos::deep_copy(numReceivedMPs_host, numReceivedMPs);
203-
204-
//Another array that contains new element id of the the MPs that have migrated
205-
//Array size is #elements received
206-
Kokkos::View<int*> receivedMPs2Elm("ReceivedMPs2Elm", numReceivedMPs_host(0));
207-
Kokkos::View<int*> counter("counter", 1);
208-
Kokkos::deep_copy(counter, 0);
209-
auto set_new_elem = PS_LAMBDA(const int& e, const int& mp, const bool& mask) {
210-
if(mask){
211-
if (mpAppID(mp) == -1){
212-
auto count_temp=Kokkos::atomic_fetch_add(&counter(0), 1);
213-
receivedMPs2Elm(count_temp) = e;
214-
}
215-
}
216-
};
217-
parallel_for(set_new_elem, "countReceivedPtcls");
218-
//Bring them to CPU so that elm_id can be passed and a new mpAppID can be found from CPU
219-
auto receivedMPs2Elm_host = Kokkos::create_mirror_view(receivedMPs2Elm);
220-
Kokkos::deep_copy(receivedMPs2Elm_host, receivedMPs2Elm);
221-
auto counter_host = Kokkos::create_mirror_view(counter);
222-
Kokkos::deep_copy(counter_host, counter);
223-
assert(numReceivedMPs_host(0)==counter_host(0));
224-
if(counter_host(0))
225-
std::cout <<"Rank "<<rank<<" received "<<counter_host(0)<<" "<< numReceivedMPs_host(0) <<" MPs \n";
226-
227-
//Find new AppIDS from CPU-MPAS and store so that they can be added to MPs that have appID=-1
228-
std::vector<int> appIDs;
229-
for(int i=0; i<numReceivedMPs_host(0); i++){
230-
auto app_id_new = getNextAppID(receivedMPs2Elm_host(i)+1);
231-
printf("Finding ID for MP migrated to el %d in rank %d and it's %d \n", receivedMPs2Elm_host(i), rank, app_id_new);
232-
appIDs.push_back(app_id_new);
233-
}
234-
kkViewHostU<int*> appIDs_host(appIDs.data(), appIDs.size());
235-
Kokkos::View<int*> appIDs_d("appIDsDevice", appIDs.size());
236-
Kokkos::deep_copy(appIDs_d, appIDs_host);
237-
238-
//If the mpAppID is -1 assign a new mpAppID
239-
Kokkos::deep_copy(counter, 0);
240-
auto set_appID = PS_LAMBDA(const int& e, const int& mp, const bool& mask) {
241-
if(mask){
242-
if (mpAppID(mp) == -1){
243-
auto count_temp=Kokkos::atomic_fetch_add(&counter(0), 1);
244-
mpAppID(mp)=appIDs_d(count_temp)-1;
245-
}
246-
}
247-
};
248-
parallel_for(set_appID, "setApplicationIDs");
249-
250168
if (getOpMode() == polyMPO::MP_DEBUG)
251169
printf("Material point migration: %f\n", timer.seconds());
252170
pumipic::RecordTime("PolyMPO_migrate", timer.seconds());
253171
}
254172

255173
bool MaterialPoints::rebuildOngoing() { return rebuildFields.ongoing; }
256174

257-
void MaterialPoints::setAppIDFunc(IntIntFunc getAppIDIn) { getAppID = getAppIDIn; }
175+
void MaterialPoints::setAppIDFunc(IntFunc getAppIDIn) { getAppID = getAppIDIn; }
258176

259-
int MaterialPoints::getNextAppID(int iElm) { return getAppID(iElm); }
177+
int MaterialPoints::getNextAppID() { return getAppID(); }
260178

261179
}

src/pmpo_materialPoints.hpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ class MaterialPoints {
127127
bool isRotatedFlag = false;
128128
Operating_Mode operating_mode;
129129
RebuildHelper rebuildFields;
130-
//IntFunc getAppID;
131-
IntIntFunc getAppID;
130+
IntFunc getAppID;
132131
MPI_Comm mpi_comm;
133132

134133
public:
@@ -157,20 +156,15 @@ class MaterialPoints {
157156
typename std::enable_if<mpSliceData::rank==2>::type
158157
setRebuildMPSlice(mpSliceData mpSliceIn);
159158

160-
//void setAppIDFunc(IntFunc getAppIDIn);
161-
void setAppIDFunc(IntIntFunc getAppIDIn);
162-
163-
int getNextAppID(int iElm);
159+
void setAppIDFunc(IntFunc getAppIDIn);
160+
int getNextAppID();
164161

165162
void rebuild() {
166163
IntView tgtElm("tgtElm", MPs->capacity());
167164
auto tgtMpElm = MPs->get<MPF_Tgt_Elm_ID>();
168-
auto mpAppID = MPs->get<MPF_MP_APP_ID>();
169165
auto setTgtElm = PS_LAMBDA(const int& e, const int& mp, const int& mask) {
170166
if(mask) {
171-
auto app_id=mpAppID(mp);
172167
tgtElm(mp) = tgtMpElm(mp);
173-
if(app_id==191) printf("Going from elm %d to %d \n", e, tgtMpElm(mp));
174168
}
175169
};
176170
ps::parallel_for(MPs, setTgtElm, "setTargetElement");

0 commit comments

Comments
 (0)