@@ -135,16 +135,21 @@ void MPMesh::CVTTrackingElmCenterBased(const int printVTPIndex){
135135 Kokkos::parallel_for (" countProcess" , numElms, KOKKOS_LAMBDA (const int iElm){
136136 int pp_id=elm2Process (iElm);
137137 });
138-
139- if (printVTPIndex>=0 ) {
140- printVTP_mesh (printVTPIndex);
138+
139+ // Since Mesh is static print pnly for 1 time step
140+ if (printVTPIndex==0 ) {
141+ printVTP_mesh (comm_rank);
141142 }
143+
144+ assert (cudaDeviceSynchronize ()==cudaSuccess);
145+ MPI_Barrier (MPI_COMM_WORLD);
142146
143147 Vec3dView history (" positionHistory" ,numMPs);
144148 Vec3dView resultLeft (" positionResult" ,numMPs);
145149 Vec3dView resultRight (" positionResult" ,numMPs);
146150 Vec3dView mpTgtPosArray (" positionTarget" ,numMPs);
147-
151+ Kokkos::View<int *> counter (" counter" ,1 );
152+
148153 auto CVTElmCalc = PS_LAMBDA (const int & elm, const int & mp, const int &mask){
149154 Vec3d MP (mpPositions (mp,0 ),mpPositions (mp,1 ),mpPositions (mp,2 ));
150155 if (mask){
@@ -163,7 +168,7 @@ void MPMesh::CVTTrackingElmCenterBased(const int printVTPIndex){
163168 for (int i=1 ; i<=numConnElms; i++){
164169 int elmID = elm2ElmConn (iElm,i)-1 ;
165170
166- // New delta
171+ // New delta
167172 Vec3d center (elmCenter (elmID, 0 ), elmCenter (elmID, 1 ), elmCenter (elmID, 2 ));
168173 delta = MPnew - center;
169174
@@ -183,7 +188,9 @@ void MPMesh::CVTTrackingElmCenterBased(const int printVTPIndex){
183188 iElm = closestElm;
184189 }
185190 }
186- if (printVTPIndex>=0 ){
191+
192+ if (printVTPIndex>=0 && numMPs>0 ){
193+ // printf("Rank %d mp %d counter %d \n", comm_rank, mp, counter);
187194 double d1 = dx[0 ];
188195 double d2 = dx[2 ];
189196 double d3 = dx[3 ];
@@ -195,29 +202,36 @@ void MPMesh::CVTTrackingElmCenterBased(const int printVTPIndex){
195202 Vec3d shift = dx.cross (r) * ((1.0 -0.7 )*dx.magnitude ()/(dx.cross (r)).magnitude ());
196203 Vec3d MPLeft = MParrow + shift;
197204 Vec3d MPRight = MParrow - shift;
198- history (mp) = MP;
199- resultLeft (mp) = MPLeft;
200- resultRight (mp) = MPRight;
201- mpTgtPosArray (mp) = MPnew;
205+ auto xx=Kokkos::atomic_fetch_add (&counter (0 ), 1 );
206+ history (xx) = MP;
207+ resultLeft (xx) = MPLeft;
208+ resultRight (xx) = MPRight;
209+ mpTgtPosArray (xx) = MPnew;
202210 }
203211 }
204212 };
205213 p_MPs->parallel_for (CVTElmCalc," CVTTrackingElmCenterBasedCalc" );
206214
207- if (printVTPIndex>=0 ){
215+ assert (cudaDeviceSynchronize ()==cudaSuccess);
216+ MPI_Barrier (MPI_COMM_WORLD);
217+ printf (" After Tracking \n " );
218+
219+ if (printVTPIndex>=0 && numMPs>0 ){
208220 Vec3dView::HostMirror h_history = Kokkos::create_mirror_view (history);
209221 Vec3dView::HostMirror h_resultLeft = Kokkos::create_mirror_view (resultLeft);
210222 Vec3dView::HostMirror h_resultRight = Kokkos::create_mirror_view (resultRight);
211223 Vec3dView::HostMirror h_mpTgtPos = Kokkos::create_mirror_view (mpTgtPosArray);
224+ Kokkos::View<int *>::HostMirror h_counter = Kokkos::create_mirror_view (counter);
212225
213226 Kokkos::deep_copy (h_history, history);
214227 Kokkos::deep_copy (h_resultLeft, resultLeft);
215228 Kokkos::deep_copy (h_resultRight, resultRight);
216229 Kokkos::deep_copy (h_mpTgtPos, mpTgtPosArray);
217-
230+ Kokkos::deep_copy (h_counter, counter);
231+ printf (" Host counter value: %d\n " , h_counter (0 ));
218232 // printVTP file
219233 char * fileOutput = (char *)malloc (sizeof (char ) * 256 );
220- sprintf (fileOutput, " polyMPOCVTTrackingElmCenter_MPtracks_%d.vtp" , printVTPIndex);
234+ sprintf (fileOutput, " polyMPOCVTTrackingElmCenter_MPtracks_%d_% d.vtp" , comm_rank , printVTPIndex);
221235 FILE * pFile = fopen (fileOutput," w" );
222236 free (fileOutput);
223237 fprintf (pFile, " <VTKFile type=\" PolyData\" version=\" 1.0\" byte_order=\" LittleEndian\" header_type=\" UInt64\" >\n <PolyData>\n <Piece NumberOfPoints=\" %d\" NumberOfVerts=\" 0\" NumberOfLines=\" %d\" NumberOfStrips=\" 0\" NumberOfPolys=\" 0\" >\n <Points>\n <DataArray type=\" Float32\" Name=\" Points\" NumberOfComponents=\" 3\" format=\" ascii\" >\n " ,numMPs*4 ,numMPs*2 );
@@ -239,6 +253,11 @@ void MPMesh::CVTTrackingElmCenterBased(const int printVTPIndex){
239253 fprintf (pFile," </DataArray>\n </Lines>\n </Piece>\n </PolyData>\n </VTKFile>\n " );
240254 fclose (pFile);
241255 }
256+ assert (cudaDeviceSynchronize ()==cudaSuccess);
257+ MPI_Barrier (MPI_COMM_WORLD);
258+ printf (" After printing particle paths \n " );
259+
260+
242261 pumipic::RecordTime (" PolyMPO_CVTTrackingElmCenterBased" , timer.seconds ());
243262}
244263
@@ -335,7 +354,6 @@ void MPMesh::push(){
335354
336355 static int count=0 ;
337356 std::cout<<" Push" <<" " <<count<<std::endl;
338- count++;
339357
340358 Kokkos::Timer timer;
341359
@@ -349,7 +367,7 @@ void MPMesh::push(){
349367
350368 bool anyIsMigrating = false ;
351369 do {
352- CVTTrackingElmCenterBased (); // move to Tgt_XYZ
370+ CVTTrackingElmCenterBased (count ); // move to Tgt_XYZ
353371 assert (cudaDeviceSynchronize () == cudaSuccess);
354372 p_MPs->updateMPSlice <MPF_Cur_Pos_XYZ, MPF_Tgt_Pos_XYZ>(); // Tgt_XYZ becomes Cur_XYZ
355373 p_MPs->updateMPSlice <MPF_Cur_Pos_Rot_Lat_Lon, MPF_Tgt_Pos_Rot_Lat_Lon>(); // Tgt becomes Cur
@@ -365,7 +383,7 @@ void MPMesh::push(){
365383 reconstructSlices ();
366384 }
367385 while (anyIsMigrating);
368-
386+ count ++;
369387 pumipic::RecordTime (" PolyMPO_push" , timer.seconds ());
370388}
371389
0 commit comments