PetaVision  Alpha
PV::MPIBlock Class Reference

#include <MPIBlock.hpp>

Public Member Functions

 MPIBlock (MPI_Comm comm, int globalNumRows, int globalNumColumns, int globalBatchDimension, int blockNumRows, int blockNumColumns, int blockBatchDimension)
 
int calcBatchIndexFromRank (int const rank) const
 
int calcColumnFromRank (int const rank) const
 
int calcRankFromRowColBatch (int const rowIndex, int const columnIndex, int const batchIndex) const
 
void calcRowColBatchFromRank (int const rank, int &rowIndex, int &columnIndex, int &batchIndex) const
 
int calcRowFromRank (int const rank) const
 
int getBatchDimension () const
 
int getBatchIndex () const
 
int getColumnIndex () const
 
MPI_Comm getComm () const
 
int getGlobalBatchDimension () const
 
MPI_Comm getGlobalComm () const
 
int getGlobalNumColumns () const
 
int getGlobalNumRows () const
 
int getGlobalRank () const
 
int getNumColumns () const
 
int getNumRows () const
 
int getRank () const
 
int getRowIndex () const
 
int getSize () const
 
int getStartBatch () const
 
int getStartColumn () const
 
int getStartRow () const
 

Private Member Functions

int calcBatchIndexFromRankInternal (int const rank) const
 
int calcColumnFromRankInternal (int const rank) const
 
int calcRowFromRankInternal (int const rank) const
 
void checkRankInBounds (int const rank) const
 
void createBlockComm (MPI_Comm comm)
 
void initBlockDimensions (int const blockNumRows, int const blockNumColumns, int const globalBatchDimension)
 
void initBlockLocation (MPI_Comm comm)
 
void initGlobalDimensions (MPI_Comm comm, int const globalNumRows, int const globalNumColumns, int const globalBatchDimension)
 

Static Private Member Functions

static int calcNumCells (int cellSize, int overallSize)
 

Private Attributes

int mBatchDimension = 0
 
int mBatchIndex = 0
 
int mColumnIndex = 0
 
MPI_Comm mComm
 
int mGlobalBatchDimension = 0
 
MPI_Comm mGlobalComm
 
int mGlobalNumColumns = 0
 
int mGlobalNumRows = 0
 
int mGlobalRank = 0
 
int mNumColumns = 0
 
int mNumRows = 0
 
int mRank = 0
 
int mRowIndex = 0
 
int mStartBatch = 0
 
int mStartColumn = 0
 
int mStartRow = 0
 

Detailed Description

A class to define a set of MPI processes made up of a block of rows, columns, and batch elements in the MPI setup. The buffer MPI utilities take an MPIBlock as an argument. The Communicator class contains two MPIBlock data members, one for the global communicator and one for the local communicator that slices along the batch dimension.

Definition at line 23 of file MPIBlock.hpp.

Constructor & Destructor Documentation

PV::MPIBlock::MPIBlock ( MPI_Comm  comm,
int  globalNumRows,
int  globalNumColumns,
int  globalBatchDimension,
int  blockNumRows,
int  blockNumColumns,
int  blockBatchDimension 
)

The constructor for MPIBlock. The MPI_Comm argument specifies the communicator that will be used to create the MPI communicators for the subblocks. Typically, it is the global communicator after any excess processes are removed. (We cannot use the Communicator object because the Communicator uses MPIBlocks as data members.)

globalNumRows, globalNumColumns, globalBatchDimension indicate the dimensions of the MPI configuration covered by the global MPI communicator.

blockNumRows, blockNumColumns, blockBatchDimension indicate the dimensions of the local block.

The constructor saves the dimensions of the block; and computes the global row, column, and batch index of the start of the block; and the row, column, and batch index of the process relative to the start of the block. These values all have get-methods.

Definition at line 10 of file MPIBlock.cpp.

Member Function Documentation

int PV::MPIBlock::calcBatchIndexFromRank ( int const  rank) const

Calculates the batch index of the process with the given rank. Throws an invalid_argument exception if rank is out of bounds.

Definition at line 168 of file MPIBlock.cpp.

int PV::MPIBlock::calcBatchIndexFromRankInternal ( int const  rank) const
private

Calculates the batch index of the process with the given rank. Does not do any bounds-checking. (The calcBatchINdexFromRank method calls this internally.)

Definition at line 179 of file MPIBlock.cpp.

int PV::MPIBlock::calcColumnFromRank ( int const  rank) const

Calculates the column index of the process with the given rank. Throws an invalid_argument exception if rank is out of bounds.

Definition at line 163 of file MPIBlock.cpp.

int PV::MPIBlock::calcColumnFromRankInternal ( int const  rank) const
private

Calculates the column index of the process with the given rank. Does not do any bounds-checking. (The calcColumnFromRank method calls this internally.)

Definition at line 177 of file MPIBlock.cpp.

int PV::MPIBlock::calcNumCells ( int  cellSize,
int  overallSize 
)
staticprivate

Used internally by createBlockComm. Returns the number of cells needed in one dimension (which dimension it is doesn't affect the calculation) based on the given cell size and overall dimension. If cellSize divides overallSize evenly, the return value is the quotient. Otherwise, it is one more than the integer quotient (e.g. if cellSize is 3 and overall size is 16, the return value is 6, since 5 cells would only cover 15 processes).

Definition at line 122 of file MPIBlock.cpp.

int PV::MPIBlock::calcRankFromRowColBatch ( int const  rowIndex,
int const  columnIndex,
int const  batchIndex 
) const

Returns the rank of the process in the MPI block with the indicated row, column, and batch index. If any of the arguments are out of bounds, throws an invalid_argument exception.

Definition at line 130 of file MPIBlock.cpp.

void PV::MPIBlock::calcRowColBatchFromRank ( int const  rank,
int &  rowIndex,
int &  columnIndex,
int &  batchIndex 
) const

Calculates the row, column, and batch index of the process with the given rank. Throws an invalid_argument exception if rank is out of bounds.

Definition at line 147 of file MPIBlock.cpp.

int PV::MPIBlock::calcRowFromRank ( int const  rank) const

Calculates the row index of the process with the given rank. Throws an invalid_argument exception if rank is out of bounds.

Definition at line 158 of file MPIBlock.cpp.

int PV::MPIBlock::calcRowFromRankInternal ( int const  rank) const
private

Calculates the row index of the process with the given rank. Does not do any bounds-checking. (The calcRowFromRank method calls this internally.)

Definition at line 173 of file MPIBlock.cpp.

void PV::MPIBlock::checkRankInBounds ( int const  rank) const
private

Used internally by the public calc-methods that take rank as an argument. It tests whether rank is >=0 and <= getSize(), and throws an invalid_argument exception if not.

Definition at line 141 of file MPIBlock.cpp.

void PV::MPIBlock::createBlockComm ( MPI_Comm  comm)
private

Used internally by the constructor to create the MPI communicator for the various blocks defined by the data members. Must be called after the initBlockLocation method.

Definition at line 101 of file MPIBlock.cpp.

int PV::MPIBlock::getBatchDimension ( ) const
inline

Returns the number of MPI process the block covers in the batch dimension.

Definition at line 135 of file MPIBlock.hpp.

int PV::MPIBlock::getBatchIndex ( ) const
inline

Returns the MPI-batch index within the MPI block of the running process.

Definition at line 171 of file MPIBlock.hpp.

int PV::MPIBlock::getColumnIndex ( ) const
inline

Returns the column index within the MPI block of the running process.

Definition at line 166 of file MPIBlock.hpp.

MPI_Comm PV::MPIBlock::getComm ( ) const
inline

Returns the MPI_Comm object for the block the running process belongs to.

Definition at line 90 of file MPIBlock.hpp.

int PV::MPIBlock::getGlobalBatchDimension ( ) const
inline

Returns the global batch dimension, across all blocks

Definition at line 120 of file MPIBlock.hpp.

MPI_Comm PV::MPIBlock::getGlobalComm ( ) const
inline

Returns the global MPI_Comm object for the entire column.

Definition at line 95 of file MPIBlock.hpp.

int PV::MPIBlock::getGlobalNumColumns ( ) const
inline

Returns the global number of columns, across all blocks

Definition at line 115 of file MPIBlock.hpp.

int PV::MPIBlock::getGlobalNumRows ( ) const
inline

Returns the global number of rows, across all blocks

Definition at line 110 of file MPIBlock.hpp.

int PV::MPIBlock::getGlobalRank ( ) const
inline

Returns the rank within the global MPI block

Definition at line 105 of file MPIBlock.hpp.

int PV::MPIBlock::getNumColumns ( ) const
inline

Returns the size of the MPI block in the column dimension.

Definition at line 130 of file MPIBlock.hpp.

int PV::MPIBlock::getNumRows ( ) const
inline

Returns the size of the MPI block in the row dimension.

Definition at line 125 of file MPIBlock.hpp.

int PV::MPIBlock::getRank ( ) const
inline

Returns the rank within the MPI block of the running process.

Definition at line 100 of file MPIBlock.hpp.

int PV::MPIBlock::getRowIndex ( ) const
inline

Returns the row index within the MPI block of the running process.

Definition at line 161 of file MPIBlock.hpp.

int PV::MPIBlock::getSize ( ) const
inline

Returns the number of processes in the block: that is, the product of getNumRows(), getNumColumns(), and getBatchDimension().

Definition at line 141 of file MPIBlock.hpp.

int PV::MPIBlock::getStartBatch ( ) const
inline

Returns the global MPI-batch index of the start of the MPI block.

Definition at line 156 of file MPIBlock.hpp.

int PV::MPIBlock::getStartColumn ( ) const
inline

Returns the global column index of the start of the MPI block.

Definition at line 151 of file MPIBlock.hpp.

int PV::MPIBlock::getStartRow ( ) const
inline

Returns the global row index of the start of the MPI block.

Definition at line 146 of file MPIBlock.hpp.

void PV::MPIBlock::initBlockDimensions ( int const  blockNumRows,
int const  blockNumColumns,
int const  globalBatchDimension 
)
private

Used internally by the constructor to set NumRows, NumColumns, and BatchDimension. These are the dimensions of the MPIBlock, not the dimensions of the global MPI configuration. If the arguments are positive, the data member is the specified value. If any argument is positive, the corresponding data member is the same as the global data member in the corresponding dimension (so that there is a single block in that dimension). Must be called after the initGlobalDimensions method.

Definition at line 76 of file MPIBlock.cpp.

void PV::MPIBlock::initBlockLocation ( MPI_Comm  comm)
private

Used internally by the constructor to set the StartRow, RowIndex, StartColumn, ColumnIndex, StartBatch, and BatchIndex data members. Start[dimension] is the index in that dimension in the global MPI configuration of the start of the current process's block. [dimension]Index is the local index within the current process's block. Must be called after the initGlobalDimensions and initBlockDimensions methods.

Definition at line 82 of file MPIBlock.cpp.

void PV::MPIBlock::initGlobalDimensions ( MPI_Comm  comm,
int const  globalNumRows,
int const  globalNumColumns,
int const  globalBatchDimension 
)
private

Used internally by the constructor to set GlobalNumRows, GlobalNumColumns and GlobalBatchDimension data members. If the arguments are positive, the data member is the specified value. Nonpositive arguments are handled as follows: globalBatchDimension<=0: GlobalBatchDimension becomes 1. globalNumColumns<=0 but globalNumRows>0: GlobalNumColumns is the largest integer such that GlobalNumColumns * GlobalNumRows * GlobalBatchDimension is no larger than the MPI_Comm size. globalNumRows<=0 but globalNumColumns>0: GlobalNumRows is the largest integer such that GlobalNumColumns * GlobalNumRows * GlobalBatchDimension is no larger than the MPI_Comm size. Both globalNumRows<=0 and globalNumColumns<=0: GlobalNumRows is the largest integer not larger than sqrt(MPI_Comm size / GlobalBatchDimension), and GlobalNumRows determined as above.

Definition at line 26 of file MPIBlock.cpp.


The documentation for this class was generated from the following files: