Communicator
-
class Communicator
Wrapper around
MPI_Comm
Subclassed by mpicpp_lite::CartesianCommunicator
Public Functions
-
inline Communicator()
Create
MPI_COMM_WORLD
communicator.
-
inline Communicator(const MPI_Comm &comm)
Create communicator from an
MPI_Comm
one.
-
inline Communicator(const Communicator &comm)
Copy constructor.
-
inline void free()
Marks the communicator object for deallocation.
-
inline int rank() const
Determine the rank of the executing process in a communicator.
- Returns:
Rank of the executing process
-
inline int size() const
Determine the number of processes in a communicator.
- Returns:
Number of processes
-
inline CartesianCommunicator create_cartesian(const std::vector<int> &dims, bool reorder = false) const
Makes a new communicator to which topology information has been attached.
- Parameters:
dims – Number of processes in each dimension
reorder – Allow the function to reorder the processes
-
inline Group group() const
Accesses the group associated with given communicator.
- Returns:
Group corresponding to communicator
-
template<typename T>
inline void send(int dest, int tag, const T &value) const Send data to another process.
- Template Parameters:
T – C++ type of the data
- Parameters:
dest – Destination rank
tag – Message tag
value – Value to send
-
template<typename T>
inline void send(int dest, int tag, const T *values, int n) const Send data to another process.
- Template Parameters:
T – C++ type of the data
- Parameters:
dest – Destination rank
tag – Message tag
values – Values to send
n – Number of values to send
-
template<typename T, typename A>
inline void send(int dest, int tag, const std::vector<T, A> &value) const Send
std::vector
of data to another process.- Template Parameters:
T – C++ type of the data
- Parameters:
dest – Destination rank
tag – Message tag
value – Vector of
T
to send
-
inline void send(int dest, int tag) const
Send a message to another process without any data.
- Parameters:
dest – Destination rank
tag – Message tag
-
template<typename T>
inline Status recv(int source, int tag, T &value) const Receive data from a remote process.
- Template Parameters:
T – C++ type of the data
- Parameters:
source – Source rank
tag – Message tag
value – Variable to recieve the data
- Returns:
Status
of the operation
-
template<typename T>
inline Status recv(int source, int tag, T *values, int n) const Receive data from a remote process.
- Template Parameters:
T – C++ type of the data
- Parameters:
source – Source rank
tag – Message tag
values – Variable to recieve the data
n – Number of values to receive
- Returns:
Status
of the operation
-
template<typename T, typename A>
inline Status recv(int source, int tag, std::vector<T, A> &value) const Receive std::vector of data from a remote process.
- Template Parameters:
T – C++ type of the data
- Parameters:
source – Source rank
tag – Message tag
value – Variable to recieve the data
- Returns:
Status
of the operation
-
inline Status recv(int source, int tag) const
Receive a message from a remote process without any data.
- Parameters:
source – Source rank
tag – Message tag
- Returns:
Status
of the operation
-
template<typename T>
inline Request isend(int dest, int tag, const T &value) const Send a message to a remote process without blocking.
- Template Parameters:
T – C++ type of the data
- Parameters:
dest – Destination rank
tag – Message tag
value – Value to send
- Returns:
Communication
Request
-
template<typename T, typename A>
inline Request isend(int dest, int tag, const std::vector<T, A> &values) const Send a std::vector of values to a remote process without blocking.
- Template Parameters:
T – C++ type of the data
- Parameters:
dest – Destination rank
tag – Message tag
value – Values to send
- Returns:
Communication
Request
-
template<typename T>
inline Request isend(int dest, int tag, const T *values, int n) const Send a message to a remote process without blocking.
- Template Parameters:
T – C++ type of the data
- Parameters:
dest – Destination rank
tag – Message tag
values – Values to send
n – Number of values to send
- Returns:
Communication
Request
-
template<typename T>
inline Request irecv(int source, int tag, T &value) const Receive a message from a remote process without blocking.
- Template Parameters:
T – C++ type of the data
- Parameters:
source – Source rank
tag – Message tag
value – Variable to recieve the data
- Returns:
Communication
Request
-
template<typename T>
inline Request irecv(int source, int tag, T *values, int n) const Receive a message from a remote process without blocking.
- Template Parameters:
T – C++ type of the data
- Parameters:
source – Source rank
tag – Message tag
values – Variable to recieve the data
n – Number of values to receive
-
inline bool iprobe(int source, int tag) const
Nonblocking test for a message.
- Parameters:
source – Rank of source or
ANY_SOURCE
tag – Message tag or
ANY_TAG
- Returns:
true
if a message with the specified source, and tag is available,false
otherwise
-
inline bool iprobe(int source, int tag, Status &status) const
Nonblocking test for a message.
- Parameters:
source – Rank of source or
ANY_SOURCE
tag – Message tag or
ANY_TAG
status – Status object
- Returns:
true
if a message with the specified source, and tag is available,false
otherwise
-
inline void barrier() const
Wait for all processes within a communicator to reach the barrier.
-
template<typename T>
inline void broadcast(T &value, int root) const Broadcast a value from a root process to all other processes.
- Template Parameters:
T – C++ type of the data
- Parameters:
value – Value to send
root – Rank of the sending process
-
template<typename T>
inline void broadcast(std::vector<T> &value, int root) const Broadcast a std::vector of values from a root process to all other processes.
- Template Parameters:
T – C++ type of the data
- Parameters:
value – Value to send
root – Rank of the sending process
-
template<typename T>
inline void broadcast(T *values, int n, int root) const Broadcast a value from a root process to all other processes.
- Template Parameters:
T – C++ type of the data
- Parameters:
values – Values to send
n – Number of values to send
root – Rank of the sending process
-
template<typename KEY, typename VALUE>
inline void broadcast(std::map<KEY, VALUE> &map, int root) const Broadcast a map from a root process to all other processes.
- Template Parameters:
KEY – Key in the map
VALUE – Value in the map
- Parameters:
map – map to send
root – Rank of the sending process
-
template<typename T>
inline void gather(const T &in_value, T *out_values, int root) const Gather together values from a group of processes.
- Template Parameters:
T – C++ type of the data
- Parameters:
in_value – Value to send
out_values – Receiving variable
root – Rank of receiving process
-
template<typename T>
inline void gather(const T &in_value, std::vector<T> &out_values, int root) const Gather together values from a group of processes.
- Template Parameters:
T – C++ type of the data
- Parameters:
in_value – Value to send
out_values – Receiving variable
root – Rank of receiving process
-
template<typename T>
inline void gather(const T *in_values, int n, T *out_values, int root) const Gather together values from a group of processes.
- Template Parameters:
T – C++ type of the data
- Parameters:
in_values – Values to send
n – Number of values to send
out_values – Receiving variable
root – Rank of receiving process
-
template<typename T>
inline void gather(const T *in_values, int n, std::vector<T> &out_values, int root) const Gather together values from a group of processes.
- Template Parameters:
T – C++ type of the data
- Parameters:
in_values – Values to send
n – Number of values to send
out_values – Receiving variable
root – Rank of receiving process
-
template<typename T>
inline void gather(const std::vector<T> &in_values, std::vector<T> &out_values, const std::vector<int> &out_counts, const std::vector<int> &out_offsets, int root) const Gather together values from a group of processes.
- Template Parameters:
T – C++ datatype
- Parameters:
in_values[in] – Values to send
out_values[out] – Buffer to receive the data
out_counts[in] – Integer array (of length group size) containing the number of elements that are to be received from each process
out_offsets[in] – Integer array (of length group size). Entry
i
specifies the displacement (relative to out_values) at which to place the incoming data from processi
root – Rank of receiving process
-
template<typename T>
inline void all_gather(const T *in_value, int n, T *out_values, int m) const Gathers data from all tasks and distribute the combined data to all tasks.
- Template Parameters:
T – C++ type of the data
- Parameters:
in_value – Value to send
n – Number of values to send
out_values – Receiving variable
m – Number of values to receive
-
template<typename T>
inline void all_gather(const T &in_value, std::vector<T> &out_values) const Gathers data from all tasks and distribute the combined data to all tasks.
- Template Parameters:
T – C++ type of the data
- Parameters:
in_value – Value to send
out_values – Receiving variable
-
template<typename T>
inline void all_gather(const std::vector<T> &in_value, std::vector<T> &out_values) const Gathers data from all tasks and distribute the combined data to all tasks.
- Template Parameters:
T – C++ type of the data
- Parameters:
in_value – Vector of values to send (the size of this vector can be different on every process)
out_values – Receiving variable
-
template<typename T>
inline void all_gather(const std::vector<T> &in_values, std::vector<T> &out_values, const std::vector<int> &out_counts, const std::vector<int> &out_offsets) const Gathers data from all tasks and deliver the combined data to all tasks.
- Template Parameters:
T – C++ datatype
- Parameters:
in_values[in] – Values to send
out_values[out] – Buffer to receive the data
out_counts[in] – Integer array (of length group size) containing the number of elements that are to be received from each process
out_offsets[in] – Integer array (of length group size). Entry
i
specifies the displacement (relative to out_values) at which to place the incoming data from processi
-
template<typename T>
inline void scatter(const T *in_values, T &out_value, int root) const Send data from one process to all other processes in a communicator.
- Template Parameters:
T – C++ type of the data
- Parameters:
in_values – Values to send
out_value – Receiving variable
root – Rank of the sending process
-
template<typename T>
inline void scatter(const std::vector<T> &in_values, T &out_value, int root) const Send data from one process to all other processes in a communicator.
- Template Parameters:
T – C++ type of the data
- Parameters:
in_values – Values to send
out_value – Receiving variable
root – Rank of the sending process
-
template<typename T>
inline void scatter(const T *in_values, T *out_values, int n, int root) const Send data from one process to all other processes in a communicator.
- Template Parameters:
T – C++ type of the data
- Parameters:
in_values – Values to send
out_values – Receiving variable
n – Number of values to send
root – Rank of the sending process
-
template<typename T>
inline void scatter(const std::vector<T> &in_values, T *out_values, int n, int root) const Send data from one process to all other processes in a communicator.
- Template Parameters:
T – C++ type of the data
- Parameters:
in_values – Values to send
out_values – Receiving variable
n – Number of values to send
root – Rank of the sending process
-
template<typename T, typename Op>
inline void reduce(const T *in_values, int n, T *out_values, Op op, int root) const Reduce values on all processes to a single value.
- Template Parameters:
T – C++ type of the data
Op – Type of the reduce operation
- Parameters:
in_values – Values to send
n – Number of values to send
out_values – Receiving variable
op – Reduce operation
root – Rank of root process
-
template<typename T, typename Op>
inline void reduce(std::vector<T> const &in_values, std::vector<T> &out_values, Op op, int root) const Reduce values on all processes to a single value.
- Template Parameters:
T – C++ type of the data
Op – Type of the reduce operation
- Parameters:
in_values – Values to send
out_values – Receiving variable
op – Reduce operation
root – Rank of root process
-
template<typename T, typename Op>
inline void reduce(const T &in_value, T &out_value, Op op, int root) const Reduce values on all processes to a single value.
- Template Parameters:
T – C++ type of the data
Op – Type of the reduce operation
- Parameters:
in_value – Values to send
out_value – Receiving variable
op – Reduce operation
root – Rank of root process
-
template<typename T, typename Op>
inline void all_reduce(const T *in_values, int n, T *out_values, Op op) const Combine values from all processes and distributes the result back to all processes.
- Template Parameters:
T – C++ type of the data
Op – Type of the reduce operation
- Parameters:
in_values – Values to send
n – Number of values to send
out_values – Receiving variable
op – Reduce operation
-
template<typename T, typename Op>
inline void all_reduce(const std::vector<T> &in_values, std::vector<T> &out_values, Op op) const Combine values from all processes and distributes the result back to all processes.
- Template Parameters:
T – C++ type of the data
Op – Type of the reduce operation
- Parameters:
in_values – Values to send
out_values – Receiving variable
op – Reduce operation
-
template<typename T, typename Op>
inline void all_reduce(const T &in_value, T &out_value, Op op) const Combine values from all processes and distributes the result back to all processes.
- Template Parameters:
T – C++ type of the data
Op – Type of the reduce operation
- Parameters:
in_value – Values to send
out_value – Receiving variable
op – Reduce operation
-
template<typename T, typename Op>
inline void all_reduce(T &value, Op op) const Combine values from all processes and distributes the result back to all processes.
- Template Parameters:
T – C++ type of the data
Op – Type of the reduce operation
- Parameters:
value – Send/receive variable
op – Reduce operation
-
template<typename T>
inline void all_to_all(const T *in_values, int n, T *out_values, int m) const Sends data from all to all processes.
- Template Parameters:
T – C++ type of the data
- Parameters:
in_values – Values to send
n – Number valus to send
out_values – Receiving variable
m – Values to receive
-
template<typename T>
inline void all_to_all(const std::vector<T> &in_values, std::vector<T> &out_values) const Sends data from all to all processes.
- Template Parameters:
T – C++ type of the data
- Parameters:
in_values – Values to send
out_values – Receiving variable
-
template<typename T>
inline void all_to_all(const std::vector<std::vector<T>> &in_values, std::vector<T> &out_values) const Sends data from all to all processes.
-
template<typename T>
inline void all_to_all(const std::vector<T> &in_values, const std::vector<int> &in_counts, const std::vector<int> &in_offsets, std::vector<T> &out_values, const std::vector<int> &out_counts, const std::vector<int> &out_offsets) const Sends data from all to all processes; each process may send a different amount of data and provide displacements for the input and output data.
- Template Parameters:
T – C++ datatype
- Parameters:
in_values[in] – Values to send
in_counts[in] – Integer array equal to the group size specifying the number of elements to send to each processor
in_offsets[in] – integer array (of length group size). Entry
j
specifies the displacement relative to sendbuf from which to take the outgoing data destined for processj
out_values[out] – Buffer that will receive the data
out_counts[in] – Integer array equal to the group size specifying the maximum number of elements that can be received from each processor
out_offsets[in] – Integer array (of length group size). Entry
i
specifies the displacement relative to recvbuf at which to place the incoming data from processi
-
inline Communicator split(int color, int key) const
Split a communicator.
- Parameters:
color – Control of subset assignment. Processes with the same color are in the same new communicator
key – Control of rank assignment. This is the rank of the calling process in the new communicator
-
template<typename T, typename Op>
inline void scan(const T *in_values, int n, T *out_values, Op op) const Computes the scan (partial reductions) of data on a collection of processes.
- Template Parameters:
T – C++ type of the data
Op – Type of the reduction operation
- Parameters:
in_values – Values to perform the scan on
n – Number of values to scan (size of
in_values
)out_values – Receiving variable
op – Reduce operation
-
template<typename T, typename Op>
inline void scan(const std::vector<T> &in_values, std::vector<T> &out_values, Op op) const Computes the scan (partial reductions) of data on a collection of processes.
- Template Parameters:
T – C++ type of the data
Op – Type of the reduction operation
- Parameters:
in_values – Values to perform the scan on
out_values – Receiving variable
op – Reduce operation
-
template<typename T, typename Op>
inline void scan(const T &in_value, T &out_value, Op op) const Computes the scan (partial reductions) of data on a collection of processes.
- Template Parameters:
T – C++ type of the data
Op – Type of the reduction operation
- Parameters:
in_value – Value to perform the scan on
out_value – Receiving variable
op – Reduce operation
-
template<typename T, typename Op>
inline void exscan(const T *in_values, int n, T *out_value, Op op) const Computes the exclusive scan (partial reductions) of data on a collection of processes.
- Template Parameters:
T – C++ type of the data
Op – Type of the reduction operation
- Parameters:
in_values – Values to perform the scan on
n – Number of values to scan (size of
in_values
)out_value – Receiving variable
op – Reduce operation
-
template<typename T, typename Op>
inline void exscan(const std::vector<T> &in_values, std::vector<T> &out_values, Op op) const Computes the exclusive scan (partial reductions) of data on a collection of processes.
- Template Parameters:
T – C++ type of the data
Op – Type of the reduction operation
- Parameters:
in_values – Values to perform the scan on
out_values – Receiving variable
op – Reduce operation
-
template<typename T, typename Op>
inline void exscan(const T &in_value, T &out_value, Op op) const Computes the exclusive scan (partial reductions) of data on a collection of processes.
- Template Parameters:
T – C++ type of the data
Op – Type of the reduction operation
- Parameters:
in_value – Value to perform the scan on
out_value – Receiving variable
op – Reduce operation
-
inline void abort(int errcode) const
Abort all tasks in the group of this communicator.
- Parameters:
errcode – Error code to return to invoking environment
-
inline operator MPI_Comm() const
Cast operator so we can pass this directly in MPI API.
-
inline operator bool() const
Check if communicator.
-
inline Communicator()