Communicator¶
- class hoomd.communicator.Communicator(mpi_comm=None, ranks_per_partition=None)¶
MPI communicator.
- Parameters:
mpi_comm – Accepts an mpi4py communicator. Use this argument to perform many independent hoomd simulations where you communicate between those simulations using mpi4py.
ranks_per_partition (int) – (MPI) Number of ranks to include in a partition.
The
Communicator
class initializes MPI communications for ahoomd.Simulation
and exposes rank and partition information to the user as properties. To use MPI, launch your Python script with an MPI launcher (e.g.mpirun
ormpiexec
). By default,Communicator
uses all ranks provided by the launchernum_launch_ranks
for a singlehoomd.Simulation
object which decomposes the state onto that many domains.Set
ranks_per_partition
to an integer to partition launched ranks intonum_launch_ranks / ranks_per_partition
communicators, each with their ownpartition
index. Use this to perform many simulations in parallel, for example by usingpartition
as an index into an array of state points to execute.Examples:
communicator = hoomd.communicator.Communicator()
communicator = simulation.device.communicator
- barrier()¶
Perform a barrier synchronization across all ranks in the partition.
Note
Does nothing in builds with ENABLE_MPI=off.
Example:
communicator.barrier()
- barrier_all()¶
Perform a MPI barrier synchronization across all ranks.
Note
Does nothing in builds with ENABLE_MPI=off.
Example:
communicator.barrier_all()
- localize_abort()¶
Localize MPI_Abort to this partition.
HOOMD calls
MPI_Abort
to tear down all running MPI processes whenever there is an uncaught exception. By default, this will abort the entire MPI execution. When using partitions, an uncaught exception on one partition will therefore abort all of them.Use the return value of
localize_abort()
as a context manager to tell HOOMD that all operations within the context will use only that MPI communicator so that an uncaught exception in one partition will only abort that partition and leave the others running.Example:
with communicator.localize_abort(): simulation.run(1_000)
- property num_partitions¶
The number of partitions in this execution.
Create partitions with the
ranks_per_partition
argument on initialization. Then, the number of partitions isnum_launch_ranks / ranks_per_partition
.Note
Returns 1 in builds with ENABLE_MPI=off.
Example:
num_partitions = communicator.num_partitions
- Type:
- property num_ranks¶
The number of ranks in this partition.
When initialized with
ranks_per_partition=None
,num_ranks
is equal to thenum_launch_ranks
set by the MPI launcher. When using partitions,num_ranks
is equal toranks_per_partition
.Note
Returns 1 in builds with ENABLE_MPI=off.
Example:
num_ranks = communicator.num_ranks
- Type:
- property partition¶
The current partition.
Note
Returns 0 in builds with ENABLE_MPI=off.
Example:
partition = communicator.partition
- Type:
- property rank¶
The current rank within the partition.
Note
Returns 0 in builds with ENABLE_MPI=off.
Example:
rank = communicator.rank
- Type:
- property walltime¶
Wall clock time since creating the
Communicator
[seconds].walltime
returns the same value on each rank in the current partition.Example:
walltime = communicator.walltime