Skip to content

Commit

Permalink
fix race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
lucafedeli88 committed May 15, 2024
1 parent 42c3e28 commit 865ba63
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Source/BoundaryConditions/WarpX_PEC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ PEC::ApplyReflectiveBoundarytoJfield(
}

// Each current component is handled separately below, starting with Jx.
grown_domain_box.convert(Jx_nodal);
#ifdef AMREX_USE_OMP
#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
#endif
Expand All @@ -850,7 +851,6 @@ PEC::ApplyReflectiveBoundarytoJfield(

// If grown_domain_box contains fabbox it means there are no PEC
// boundaries to handle so continue to next box
grown_domain_box.convert(Jx_nodal);
if (grown_domain_box.contains(fabbox)) { continue; }

// Extract field data
Expand All @@ -875,6 +875,7 @@ PEC::ApplyReflectiveBoundarytoJfield(
}

// Handle Jy.
grown_domain_box.convert(Jy_nodal);
#ifdef AMREX_USE_OMP
#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
#endif
Expand All @@ -885,7 +886,6 @@ PEC::ApplyReflectiveBoundarytoJfield(

// If grown_domain_box contains fabbox it means there are no PEC
// boundaries to handle so continue to next box
grown_domain_box.convert(Jy_nodal);
if (grown_domain_box.contains(fabbox)) { continue; }

// Extract field data
Expand All @@ -910,6 +910,7 @@ PEC::ApplyReflectiveBoundarytoJfield(
}

// Handle Jz.
grown_domain_box.convert(Jz_nodal);
#ifdef AMREX_USE_OMP
#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
#endif
Expand All @@ -920,7 +921,6 @@ PEC::ApplyReflectiveBoundarytoJfield(

// If grown_domain_box contains fabbox it means there are no PEC
// boundaries to handle so continue to next box
grown_domain_box.convert(Jz_nodal);
if (grown_domain_box.contains(fabbox)) { continue; }

// Extract field data
Expand Down
19 changes: 13 additions & 6 deletions Source/Particles/PhysicalParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,19 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int
const bool radially_weighted = plasma_injector.radially_weighted;
#endif


// User-defined integer and real attributes: prepare parsers
const auto n_user_int_attribs = static_cast<int>(m_user_int_attribs.size());
const auto n_user_real_attribs = static_cast<int>(m_user_real_attribs.size());
amrex::Gpu::PinnedVector< amrex::ParserExecutor<7> > user_int_attrib_parserexec_pinned(n_user_int_attribs);
amrex::Gpu::PinnedVector< amrex::ParserExecutor<7> > user_real_attrib_parserexec_pinned(n_user_real_attribs);
for (int ia = 0; ia < n_user_int_attribs; ++ia) {
user_int_attrib_parserexec_pinned[ia] = m_user_int_attrib_parser[ia]->compile<7>();
}
for (int ia = 0; ia < n_user_real_attribs; ++ia) {
user_real_attrib_parserexec_pinned[ia] = m_user_real_attrib_parser[ia]->compile<7>();
}

MFItInfo info;
if (do_tiling && Gpu::notInLaunchRegion()) {
info.EnableTiling(tile_size);
Expand Down Expand Up @@ -1156,19 +1169,13 @@ PhysicalParticleContainer::AddPlasma (PlasmaInjector const& plasma_injector, int
}
uint64_t * AMREX_RESTRICT pa_idcpu = soa.GetIdCPUData().data() + old_size;
// user-defined integer and real attributes
const auto n_user_int_attribs = static_cast<int>(m_user_int_attribs.size());
const auto n_user_real_attribs = static_cast<int>(m_user_real_attribs.size());
amrex::Gpu::PinnedVector<int*> pa_user_int_pinned(n_user_int_attribs);
amrex::Gpu::PinnedVector<ParticleReal*> pa_user_real_pinned(n_user_real_attribs);
amrex::Gpu::PinnedVector< amrex::ParserExecutor<7> > user_int_attrib_parserexec_pinned(n_user_int_attribs);
amrex::Gpu::PinnedVector< amrex::ParserExecutor<7> > user_real_attrib_parserexec_pinned(n_user_real_attribs);
for (int ia = 0; ia < n_user_int_attribs; ++ia) {
pa_user_int_pinned[ia] = soa.GetIntData(particle_icomps[m_user_int_attribs[ia]]).data() + old_size;
user_int_attrib_parserexec_pinned[ia] = m_user_int_attrib_parser[ia]->compile<7>();
}
for (int ia = 0; ia < n_user_real_attribs; ++ia) {
pa_user_real_pinned[ia] = soa.GetRealData(particle_comps[m_user_real_attribs[ia]]).data() + old_size;
user_real_attrib_parserexec_pinned[ia] = m_user_real_attrib_parser[ia]->compile<7>();
}
#ifdef AMREX_USE_GPU
// To avoid using managed memory, we first define pinned memory vector, initialize on cpu,
Expand Down

0 comments on commit 865ba63

Please sign in to comment.