mptensor v0.5.1
Parallel Library for Tensor Network Methods
Loading...
Searching...
No Matches
mptensor::mpi Namespace Reference

Typedefs

using comm_type = MPI_Comm
 

Functions

void initialize (int argc, char **argv)
 True if the calling process is the root (rank 0), false otherwise.
 
void finalize ()
 Finalize MPI environment.
 
void barrier (const comm_type &comm)
 Barrier synchronization among processes in the communicator.
 
void get_info (const comm_type &comm, int &rank, int &size, bool &is_root)
 Get MPI information: rank, size, and whether the process is the root.
 
template<typename C >
C allreduce_sum (C val, const MPI_Comm &comm)
 Calculate a summation over MPI communicator.
 
template<typename C >
std::vector< C > allreduce_vec (const std::vector< C > &vec, const MPI_Comm &comm)
 Calculate a summation of each element of vector over MPI communicator.
 
template<typename C >
void allreduce (const C *sendbuf, C *recvbuf, int count, MPI_Op op, const MPI_Comm &comm)
 Wrapper of MPI_Allreduce.
 
template<typename C >
void sendrecv (const C *sendbuf, int sendcount, int dest, int sendtag, C *recvbuf, int recvcount, int source, int recvtag, const MPI_Comm &comm)
 Wrapper of MPI_Sendrecv.
 
template<typename C >
void sendrecv (const std::vector< C > &send_vec, int dest, int sendtag, std::vector< C > &recv_vec, int source, int recvtag, const MPI_Comm &comm)
 Wrapper of MPI_Sendrecv for std::vector.
 
template<typename C >
void alltoall (const C *sendbuf, int sendcount, C *recvbuf, int recvcount, const MPI_Comm &comm)
 Wrapper of MPI_Alltoall.
 
template<typename C >
void alltoallv (const C *sendbuf, const int *sendcounts, const int *sdispls, C *recvbuf, const int *recvcounts, const int *rdispls, const MPI_Comm &comm)
 Wrapper of MPI_Alltoallv.
 
template<typename C >
void bcast (C *buffer, int count, int root, const MPI_Comm &comm)
 Wrapper of MPI_Bcast.
 

Variables

int rank = -1
 Type for MPI communicator.
 
int size = -1
 Rank of the calling process in the communicator.
 
bool is_root = false
 Number of processes in the communicator.
 
template<typename C >
MPI_Datatype mpi_datatype = MPI_DATATYPE_NULL
 Template variable for MPI Datatype.
 

Typedef Documentation

◆ comm_type

Function Documentation

◆ allreduce()

template<typename C >
void mptensor::mpi::allreduce ( const C *  sendbuf,
C *  recvbuf,
int  count,
MPI_Op  op,
const MPI_Comm &  comm 
)
inline

Wrapper of MPI_Allreduce.

Parameters
[in]sendbufsend buffer
[out]recvbufreceive buffer
[in]countthe number in send buffer
[in]opOpreation
[in]commMPI Communicator

◆ allreduce_sum()

template<typename C >
C mptensor::mpi::allreduce_sum ( C  val,
const MPI_Comm &  comm 
)
inline

Calculate a summation over MPI communicator.

Parameters
[in]valvalue to be summed.
[in]commMPI communicator.
Returns
summation of val.

◆ allreduce_vec()

template<typename C >
std::vector< C > mptensor::mpi::allreduce_vec ( const std::vector< C > &  vec,
const MPI_Comm &  comm 
)
inline

Calculate a summation of each element of vector over MPI communicator.

Parameters
[in]vecvector to be summed.
[in]commMPI communicator.
Returns
resulted vector.

◆ alltoall()

template<typename C >
void mptensor::mpi::alltoall ( const C *  sendbuf,
int  sendcount,
C *  recvbuf,
int  recvcount,
const MPI_Comm &  comm 
)
inline

Wrapper of MPI_Alltoall.

Parameters
[in]sendbufStarting address of send buffer.
[in]sendcountThe number of elements to send.
[out]recvbufAddress of receive buffer.
[in]recvcountThe number of elements to receive.
[in]commCommunicator over which data is to be exchanged.

◆ alltoallv()

template<typename C >
void mptensor::mpi::alltoallv ( const C *  sendbuf,
const int *  sendcounts,
const int *  sdispls,
C *  recvbuf,
const int *  recvcounts,
const int *  rdispls,
const MPI_Comm &  comm 
)
inline

Wrapper of MPI_Alltoallv.

Parameters
[in]sendbufStarting address of send buffer.
[in]sendcountsInteger array, where entry i specifies the number of elements to send to rank i.
[in]sdisplsInteger array, where entry i specifies the displacement (offset from sendbuf, in units of sendtype) from which to send data to rank i.
[out]recvbufAddress of receive buffer.
[in]recvcountsInteger array, where entry j specifies the number of elements to receive from rank j.
[in]rdisplsInteger array, where entry j specifies the displacement (offset from recvbuf, in units of recvtype) to which data from rank j should be written.
[in]commCommunicator over which data is to be exchanged.

◆ barrier()

void mptensor::mpi::barrier ( const comm_type &  comm)

Barrier synchronization among processes in the communicator.

Parameters
commMPI communicator

◆ bcast()

template<typename C >
void mptensor::mpi::bcast ( C *  buffer,
int  count,
int  root,
const MPI_Comm &  comm 
)
inline

Wrapper of MPI_Bcast.

Parameters
bufferStarting address of buffer.
countNumber of entries in buffer.
rootRank of broadcast root.
commCommunicator.

◆ finalize()

void mptensor::mpi::finalize ( )

Finalize MPI environment.

This function is registered to be called at exit by initialize().

◆ get_info()

void mptensor::mpi::get_info ( const comm_type &  comm,
int &  rank,
int &  size,
bool &  is_root 
)

Get MPI information: rank, size, and whether the process is the root.

Parameters
commMPI communicator
rankRank of the calling process in the communicator
sizeNumber of processes in the communicator
is_rootTrue if the calling process is the root (rank 0), false otherwise

◆ initialize()

void mptensor::mpi::initialize ( int  argc,
char **  argv 
)

True if the calling process is the root (rank 0), false otherwise.

Initialize MPI environment and get MPI information

Parameters
argcNumber of command-line arguments
argvArray of command-line arguments

This function should be called before any MPI communication. It also registers the finalize function to be called at exit.

◆ sendrecv() [1/2]

template<typename C >
void mptensor::mpi::sendrecv ( const C *  sendbuf,
int  sendcount,
int  dest,
int  sendtag,
C *  recvbuf,
int  recvcount,
int  source,
int  recvtag,
const MPI_Comm &  comm 
)
inline

Wrapper of MPI_Sendrecv.

Parameters
[in]sendbufsend buffer
[in]sendcountthe number of elements to send
[in]destRank of destination
[in]sendtagSend tag
[out]recvbufreceive buffer
[in]recvcountthe number of elements to receive
[in]sourceRank of source
[in]recvtagReceive tag
[in]commMPI Communicator

◆ sendrecv() [2/2]

template<typename C >
void mptensor::mpi::sendrecv ( const std::vector< C > &  send_vec,
int  dest,
int  sendtag,
std::vector< C > &  recv_vec,
int  source,
int  recvtag,
const MPI_Comm &  comm 
)
inline

Wrapper of MPI_Sendrecv for std::vector.

Parameters
[in]send_vecsend vector
[in]destRank of destination
[in]sendtagSend tag
[out]recv_vecreceive vector
[in]sourceRank of source
[in]recvtagReceive tag
[in]commMPI Communicator

Variable Documentation

◆ is_root

bool mptensor::mpi::is_root = false

Number of processes in the communicator.

◆ mpi_datatype

template<typename C >
MPI_Datatype mptensor::mpi::mpi_datatype = MPI_DATATYPE_NULL
inline

Template variable for MPI Datatype.

◆ rank

int mptensor::mpi::rank = -1

Type for MPI communicator.

◆ size

int mptensor::mpi::size = -1

Rank of the calling process in the communicator.