@@ -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