@@ -209,18 +209,33 @@ BackgroundMCCCollision::doCollisions (amrex::Real cur_time, MultiParticleContain
209209 auto const flvl = species1.finestLevel ();
210210 for (int lev = 0 ; lev <= flvl; ++lev) {
211211
212+ auto cost = WarpX::getCosts (lev);
213+
212214 // firstly loop over particles box by box and do all particle conserving
213215 // scattering
214216#ifdef _OPENMP
215217#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
216218#endif
217219 for (WarpXParIter pti (species1, lev); pti.isValid (); ++pti) {
220+ if (cost && WarpX::load_balance_costs_update_algo == LoadBalanceCostsUpdateAlgo::Timers)
221+ {
222+ amrex::Gpu::synchronize ();
223+ }
224+ amrex::Real wt = amrex::second ();
225+
218226 doBackgroundCollisionsWithinTile (pti);
227+
228+ if (cost && WarpX::load_balance_costs_update_algo == LoadBalanceCostsUpdateAlgo::Timers)
229+ {
230+ amrex::Gpu::synchronize ();
231+ wt = amrex::second () - wt;
232+ amrex::HostDevice::Atomic::Add ( &(*cost)[pti.index ()], wt);
233+ }
219234 }
220235
221236 // secondly perform ionization through the SmartCopyFactory if needed
222237 if (ionization_flag) {
223- doBackgroundIonization (lev, species1, species2);
238+ doBackgroundIonization (lev, cost, species1, species2);
224239 }
225240 }
226241}
@@ -348,8 +363,8 @@ void BackgroundMCCCollision::doBackgroundCollisionsWithinTile
348363
349364
350365void BackgroundMCCCollision::doBackgroundIonization
351- ( int lev, WarpXParticleContainer& species1 ,
352- WarpXParticleContainer& species2)
366+ ( int lev, amrex::LayoutData<amrex::Real>* cost ,
367+ WarpXParticleContainer& species1, WarpXParticleContainer& species2)
353368{
354369 WARPX_PROFILE (" BackgroundMCCCollision::doBackgroundIonization()" );
355370
@@ -372,6 +387,13 @@ void BackgroundMCCCollision::doBackgroundIonization
372387#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
373388#endif
374389 for (WarpXParIter pti (species1, lev); pti.isValid (); ++pti) {
390+
391+ if (cost && WarpX::load_balance_costs_update_algo == LoadBalanceCostsUpdateAlgo::Timers)
392+ {
393+ amrex::Gpu::synchronize ();
394+ }
395+ amrex::Real wt = amrex::second ();
396+
375397 auto & elec_tile = species1.ParticlesAt (lev, pti);
376398 auto & ion_tile = species2.ParticlesAt (lev, pti);
377399
@@ -389,5 +411,12 @@ void BackgroundMCCCollision::doBackgroundIonization
389411
390412 setNewParticleIDs (elec_tile, np_elec, num_added);
391413 setNewParticleIDs (ion_tile, np_ion, num_added);
414+
415+ if (cost && WarpX::load_balance_costs_update_algo == LoadBalanceCostsUpdateAlgo::Timers)
416+ {
417+ amrex::Gpu::synchronize ();
418+ wt = amrex::second () - wt;
419+ amrex::HostDevice::Atomic::Add ( &(*cost)[pti.index ()], wt);
420+ }
392421 }
393422}
0 commit comments