Skip to content

[OpenMP] AddParticles(pc & other) Broken in ImpactX #4498

@ax3l

Description

@ax3l

When using more than one OpenMP thread in ImpactX, the addParticles(pc & other) does not work. This might be due to the particular init logic we use in ImpactX for particles when not using collective effects (i.e., redistribute is never called)?

Here is a reproducer:

In detail, we draw a particle distribution once for a series of tests (which is time consuming) and then copy in the exact same particle container over and over for following tests (to be reproducible in exact particles that we had drawn for other tests & be faster than drawing again).

# once we do
sim.add_particles(bunch_charge_C, distr, npart)

sim.backup_beam = self.sim.particle_container().make_alike()  # note: not sure if the issue could also be here?
self.sim.backup_beam.add_particles(self.sim.particle_container())
# then repeated for each test we do

# instead of drawing from the distribution again, create a 2nd
# particle container and copy the same initial particles again.
pc = sim.particle_container()
pc.clear_particles()
pc.add_particles(sim.backup_beam)  # note: uses default of local=False (no difference if I use local=True)

assert pc.total_number_of_particles() == npart  # this fails for more than one OMP thread

results in total_number_of_particles() (with default arguemtns) to return Npart / OpenMP threads.

/**
* \brief Returns # of particles at all levels
*
* If "only_valid" is true it only counts valid particles.
*
* \param only_valid
* \param only_local
*/
Long TotalNumberOfParticles (bool only_valid=true, bool only_local=false) const;

CC @atmyers @WeiqunZhang

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions