Quickstart
First, ensure that mpiparticles is installed.
One rank
Section titled “One rank”A ParticleStore keeps the markers of one rank in component-major arrays: positions (ndim, n),
velocities (nvel, n), weights, alive flags and int64 ids.
import cunumpy as xp
from mpiparticles import ParticleStore
store = ParticleStore(ndim=2, nvel=3)ids = store.add(xp.asarray([[0.1, 0.9], [0.2, 0.8]]), xp.zeros((3, 2)), weights=1.0)
store.deactivate(xp.asarray([False, True])) # dead markers stay until compactedstore.compact_if_needed()print(store.num_alive, store.length)Several ranks
Section titled “Several ranks”Split a box between the ranks with a Decomposition, push the markers, and call migrate after
every push. It is collective: every rank calls it, also a rank with nothing to send.
import maybempi
from mpiparticles import BoxDecomposition, IdAllocator, ParticleStore, migrate
comm = maybempi.get_mpi().COMM_WORLDdecomposition = BoxDecomposition(comm, [0.0, 0.0], [1.0, 1.0], proc_sizes=[2, 2])store = ParticleStore(2, 3, id_allocator=IdAllocator.from_comm(comm))
# ... add the markers of this rank, push them ...sent, received = migrate(store, decomposition)mpiexec -n 4 python example.py # or just: python example.py (one rank)The tutorial runs this on four ranks and checks that no marker or id is lost. See the API reference for every function.