Particle ReduceSum function #4593
-
In the amrex/Src/Particle/AMReX_ParticleReduce.H Lines 179 to 180 in de8c576 using value_type = decltype(particle_detail::call_f(f, typename PC::ParticleTileType::ConstParticleTileDataType(), int()));
value_type sm{}; Here I have created a custom data structure. template<typename T, int size = 6>
class ParallelVector {
public:
ParallelVector() = default;
ParallelVector& operator +=(const ParallelVector& v) {
for (int i = 0; i < size; i++) {
data[i] += v[i];
}
return *this;
}
ParallelVector& operator =(int v) {
for (int i = 0; i < size; i++) {
data[i] = v;
}
return *this;
}
T& operator[](size_t v) {
if (v >= size) {
throw std::out_of_range("index out of range!");
}
return data[v];
}
const T& operator[](size_t v) const {
if (v >= size) {
throw std::out_of_range("index out of range!");
}
return data[v];
}
T at(const int index) {
return data.at(index);
}
void setValue(const int index, const T& d) {
data[index] = d;
}
private:
std::array<T, size> data = {};
}; Calling auto data = ReduceSum(*mContainer, [=]AMREX_GPU_HOST_DEVICE(const pc& p) {
if (p.idata(M_ID) == cur_p.id) {
auto v = ParallelVector<double>();
v.setValue(0, p.rdata(P_ATTR_REAL::Fx_Marker));
v.setValue(1, p.rdata(P_ATTR_REAL::Fy_Marker));
v.setValue(2, p.rdata(P_ATTR_REAL::Fz_Marker));
v.setValue(3, p.rdata(P_ATTR_REAL::Mx_Marker));
v.setValue(4, p.rdata(P_ATTR_REAL::My_Marker));
v.setValue(5, p.rdata(P_ATTR_REAL::Mz_Marker));
}
return ParallelVector<double>();
});
// MPI sum reduce -> current particle all IB force and moment
auto fx = data.at(0);
auto fy = data.at(1);
auto fz = data.at(2);
auto mx = data.at(3);
auto my = data.at(4);
auto mz = data.at(5); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @S-Explorer, It's possible to do reductions over multiple variables in the current development branch, using the syntax demonstrated here: https://github.com/AMReX-Codes/amrex/blob/development/Tests/Particles/ParticleReduce/main.cpp#L230 -Andrew |
Beta Was this translation helpful? Give feedback.
Hi @S-Explorer,
It's possible to do reductions over multiple variables in the current development branch, using the syntax demonstrated here: https://github.com/AMReX-Codes/amrex/blob/development/Tests/Particles/ParticleReduce/main.cpp#L230
-Andrew