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
Communicatorclass initializes MPI communications for ahoomd.Simulationand exposes rank and partition information to the user as properties. To use MPI, launch your Python script with an MPI launcher (e.g.mpirunormpiexec). By default,Communicatoruses all ranks provided by the launchernum_launch_ranksfor a singlehoomd.Simulationobject which decomposes the state onto that many domains.Set
ranks_per_partitionto an integer to partition launched ranks intonum_launch_ranks / ranks_per_partitioncommunicators, each with their ownpartitionindex. Use this to perform many simulations in parallel, for example by usingpartitionas 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_Abortto 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_partitionargument 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_ranksis equal to thenum_launch_ranksset by the MPI launcher. When using partitions,num_ranksis 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].walltimereturns the same value on each rank in the current partition.Example:
walltime = communicator.walltime