Skip to content

Commit

Permalink
Conduit: Fix SoA Particle
Browse files Browse the repository at this point in the history
Fix the SoA particle structures for Conduit. Handle zero particles
on MPI ranks without UB.
  • Loading branch information
ax3l committed Aug 6, 2024
1 parent 4efca79 commit 6233aa5
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions Src/Extern/Conduit/AMReX_Conduit_Blueprint_ParticlesI.H
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ ParticleTileToBlueprint(const ParticleTile<ParticleType,
// for soa entries, we can use standard strides,
// since these are contiguous arrays

n_coords["values/x"].set_external(const_cast<ParticleReal*>(&soa.GetRealData(0)[0]),
n_coords["values/x"].set_external(const_cast<ParticleReal*>(soa.GetRealData(0).data()),
num_particles);
#if AMREX_SPACEDIM > 1
n_coords["values/y"].set_external(const_cast<ParticleReal*>(&soa.GetRealData(1)[0]),
n_coords["values/y"].set_external(const_cast<ParticleReal*>(soa.GetRealData(1).data()),
num_particles);
#endif
#if AMREX_SPACEDIM > 2
n_coords["values/z"].set_external(const_cast<ParticleReal*>(&soa.GetRealData(2)[0]),
n_coords["values/z"].set_external(const_cast<ParticleReal*>(soa.GetRealData(2).data()),
num_particles);
#endif
} else
Expand Down Expand Up @@ -172,30 +172,15 @@ ParticleTileToBlueprint(const ParticleTile<ParticleType,
} else {
const auto &soa = ptile.GetStructOfArrays();

// for soa entries, we can use standard strides,
// since these are contiguous arrays

if(!soa.GetIntData().empty())
{

// for soa entries, we can use standard strides,
// since these are contiguous arrays

// id is the first int entry
conduit::Node &n_f_id = n_fields[topology_name + "_id"];

n_f_id["topology"] = topology_name;
n_f_id["association"] = "element";
n_f_id["values"].set_external(const_cast<int*>(&soa.GetIntData(0)[0]),
num_particles);

// cpu is the second int entry
conduit::Node &n_f_cpu = n_fields[topology_name + "_cpu"];

n_f_cpu["topology"] = topology_name;
n_f_cpu["association"] = "element";
n_f_cpu["values"].set_external(const_cast<int*>(&soa.GetIntData(0)[0]),
num_particles);
conduit::Node &n_f_idcpu = n_fields[topology_name + "_idcpu"];

}
n_f_idcpu["topology"] = topology_name;
n_f_idcpu["association"] = "element";
n_f_idcpu["values"].set_external(const_cast<uint64_t*>(soa.GetIdCPUData().data()),
num_particles);
}

// --------------------------------
Expand Down Expand Up @@ -237,7 +222,7 @@ ParticleTileToBlueprint(const ParticleTile<ParticleType,
conduit::Node &n_f = n_fields[real_comp_names.at(vname_real_idx)];
n_f["topology"] = topology_name;
n_f["association"] = "element";
n_f["values"].set_external(const_cast<ParticleReal*>(&soa.GetRealData(i)[0]),
n_f["values"].set_external(const_cast<ParticleReal*>(soa.GetRealData(i).data()),
num_particles);

vname_real_idx++;
Expand All @@ -249,7 +234,7 @@ ParticleTileToBlueprint(const ParticleTile<ParticleType,
conduit::Node &n_f = n_fields[int_comp_names.at(vname_int_idx)];
n_f["topology"] = topology_name;
n_f["association"] = "element";
n_f["values"].set_external(const_cast<int*>(&soa.GetIntData(i)[0]),
n_f["values"].set_external(const_cast<int*>(soa.GetIntData(i).data()),
num_particles);

vname_int_idx++;
Expand Down

0 comments on commit 6233aa5

Please sign in to comment.