@@ -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
136120MPI_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
255173bool 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}
0 commit comments