Skip to content

Commit dbc0c6f

Browse files
ax3latmyers
andauthored
ParticleCopyPlan for SoA Particles (#3732)
## Summary Update `ParticleCopyPlan::build` for pure SoA particle layout. ## Additional background - [x] testing on GPU in BLAST-WarpX/warpx#4653 ## Checklist The proposed changes: - [x] fix a bug or incorrect behavior in AMReX - [ ] add new capabilities to AMReX - [ ] changes answers in the test suite to more than roundoff level - [ ] are likely to significantly affect the results of downstream AMReX users - [ ] include documentation in the code and/or rst files, if appropriate --------- Co-authored-by: Andrew Myers <atmyers2@gmail.com>
1 parent 47c4f95 commit dbc0c6f

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

Src/Particle/AMReX_ParticleCommunication.H

+7-3
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,13 @@ struct ParticleCopyPlan
220220
if (int_comp_mask[i]) {++num_int_comm_comp;}
221221
}
222222

223-
m_superparticle_size = sizeof(typename PC::ParticleType)
224-
+ num_real_comm_comp * sizeof(typename PC::ParticleType::RealType)
225-
+ num_int_comm_comp * sizeof(int);
223+
if constexpr (PC::ParticleType::is_soa_particle) {
224+
m_superparticle_size = sizeof(uint64_t); // idcpu
225+
} else {
226+
m_superparticle_size = sizeof(typename PC::ParticleType);
227+
}
228+
m_superparticle_size += num_real_comm_comp * sizeof(typename PC::ParticleType::RealType)
229+
+ num_int_comm_comp * sizeof(int);
226230

227231
buildMPIStart(pc.BufferMap(), m_superparticle_size);
228232
}

Src/Particle/AMReX_ParticleTransformation.H

+10-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ void copyParticle (const ParticleTileData<T_ParticleType, NAR, NAI>& dst,
8181
AMREX_ASSERT(dst.m_num_runtime_real == src.m_num_runtime_real);
8282
AMREX_ASSERT(dst.m_num_runtime_int == src.m_num_runtime_int );
8383

84-
dst.m_aos[dst_i] = src.m_aos[src_i];
84+
if constexpr(T_ParticleType::is_soa_particle) {
85+
dst.m_idcpu[dst_i] = src.m_idcpu[src_i];
86+
} else {
87+
dst.m_aos[dst_i] = src.m_aos[src_i];
88+
}
8589
for (int j = 0; j < NAR; ++j) {
8690
dst.m_rdata[j][dst_i] = src.m_rdata[j][src_i];
8791
}
@@ -119,7 +123,11 @@ void swapParticle (const ParticleTileData<T_ParticleType, NAR, NAI>& dst,
119123
AMREX_ASSERT(dst.m_num_runtime_real == src.m_num_runtime_real);
120124
AMREX_ASSERT(dst.m_num_runtime_int == src.m_num_runtime_int );
121125

122-
amrex::Swap(src.m_aos[src_i], dst.m_aos[dst_i]);
126+
if constexpr(T_ParticleType::is_soa_particle) {
127+
amrex::Swap(src.m_idcpu[src_i], dst.m_idcpu[dst_i]);
128+
} else {
129+
amrex::Swap(src.m_aos[src_i], dst.m_aos[dst_i]);
130+
}
123131
for (int j = 0; j < NAR; ++j) {
124132
amrex::Swap(dst.m_rdata[j][dst_i], src.m_rdata[j][src_i]);
125133
}

0 commit comments

Comments
 (0)