PetaVision  Alpha
MPIBlock.hpp
1 /*
2  * MPIBlock.hpp
3  *
4  * Created on: Dec 7, 2016
5  * Author: Pete Schultz
6  */
7 
8 #ifndef MPIBLOCK_HPP_
9 #define MPIBLOCK_HPP_
10 
11 #include "arch/mpi/mpi.h"
12 
13 namespace PV {
14 
23 class MPIBlock {
24  public:
44  MPIBlock(
45  MPI_Comm comm,
46  int globalNumRows,
47  int globalNumColumns,
48  int globalBatchDimension,
49  int blockNumRows,
50  int blockNumColumns,
51  int blockBatchDimension);
52 
58  int
59  calcRankFromRowColBatch(int const rowIndex, int const columnIndex, int const batchIndex) const;
60 
66  void
67  calcRowColBatchFromRank(int const rank, int &rowIndex, int &columnIndex, int &batchIndex) const;
68 
73  int calcRowFromRank(int const rank) const;
74 
79  int calcColumnFromRank(int const rank) const;
80 
85  int calcBatchIndexFromRank(int const rank) const;
86 
90  MPI_Comm getComm() const { return mComm; }
91 
95  MPI_Comm getGlobalComm() const { return mGlobalComm; }
96 
100  int getRank() const { return mRank; }
101 
105  int getGlobalRank() const { return mGlobalRank; }
106 
110  int getGlobalNumRows() const { return mGlobalNumRows; }
111 
115  int getGlobalNumColumns() const { return mGlobalNumColumns; }
116 
120  int getGlobalBatchDimension() const { return mGlobalBatchDimension; }
121 
125  int getNumRows() const { return mNumRows; }
126 
130  int getNumColumns() const { return mNumColumns; }
131 
135  int getBatchDimension() const { return mBatchDimension; }
136 
141  int getSize() const { return mNumRows * mNumColumns * mBatchDimension; }
142 
146  int getStartRow() const { return mStartRow; }
147 
151  int getStartColumn() const { return mStartColumn; }
152 
156  int getStartBatch() const { return mStartBatch; }
157 
161  int getRowIndex() const { return mRowIndex; }
162 
166  int getColumnIndex() const { return mColumnIndex; }
167 
171  int getBatchIndex() const { return mBatchIndex; }
172 
173  private:
194  MPI_Comm comm,
195  int const globalNumRows,
196  int const globalNumColumns,
197  int const globalBatchDimension);
198 
209  void initBlockDimensions(
210  int const blockNumRows,
211  int const blockNumColumns,
212  int const globalBatchDimension);
213 
223  void initBlockLocation(MPI_Comm comm);
224 
230  void createBlockComm(MPI_Comm comm);
231 
237  void checkRankInBounds(int const rank) const;
238 
244  int calcRowFromRankInternal(int const rank) const;
245 
251  int calcColumnFromRankInternal(int const rank) const;
252 
258  int calcBatchIndexFromRankInternal(int const rank) const;
259 
269  static int calcNumCells(int cellSize, int overallSize);
270 
271  // Data members
272  private:
273  MPI_Comm mGlobalComm;
274  MPI_Comm mComm;
275  int mGlobalRank = 0;
276  int mRank = 0;
277  int mGlobalNumRows = 0;
278  int mGlobalNumColumns = 0;
279  int mGlobalBatchDimension = 0;
280  int mNumRows = 0;
281  int mNumColumns = 0;
282  int mBatchDimension = 0;
283  int mStartRow = 0;
284  int mStartColumn = 0;
285  int mStartBatch = 0;
286  int mRowIndex = 0;
287  int mColumnIndex = 0;
288  int mBatchIndex = 0;
289 
290 }; // end classe MPIBlock
291 
292 } // end namespace PV
293 
294 #endif // MPIBLOCK_HPP_
void initGlobalDimensions(MPI_Comm comm, int const globalNumRows, int const globalNumColumns, int const globalBatchDimension)
Definition: MPIBlock.cpp:26
int getGlobalNumColumns() const
Definition: MPIBlock.hpp:115
void initBlockDimensions(int const blockNumRows, int const blockNumColumns, int const globalBatchDimension)
Definition: MPIBlock.cpp:76
MPIBlock(MPI_Comm comm, int globalNumRows, int globalNumColumns, int globalBatchDimension, int blockNumRows, int blockNumColumns, int blockBatchDimension)
Definition: MPIBlock.cpp:10
int getNumColumns() const
Definition: MPIBlock.hpp:130
int getNumRows() const
Definition: MPIBlock.hpp:125
void checkRankInBounds(int const rank) const
Definition: MPIBlock.cpp:141
MPI_Comm getComm() const
Definition: MPIBlock.hpp:90
int calcRankFromRowColBatch(int const rowIndex, int const columnIndex, int const batchIndex) const
Definition: MPIBlock.cpp:130
int getRank() const
Definition: MPIBlock.hpp:100
MPI_Comm getGlobalComm() const
Definition: MPIBlock.hpp:95
int getStartColumn() const
Definition: MPIBlock.hpp:151
int getGlobalBatchDimension() const
Definition: MPIBlock.hpp:120
int getGlobalRank() const
Definition: MPIBlock.hpp:105
int getStartRow() const
Definition: MPIBlock.hpp:146
int getColumnIndex() const
Definition: MPIBlock.hpp:166
int getBatchDimension() const
Definition: MPIBlock.hpp:135
void initBlockLocation(MPI_Comm comm)
Definition: MPIBlock.cpp:82
void createBlockComm(MPI_Comm comm)
Definition: MPIBlock.cpp:101
int calcBatchIndexFromRank(int const rank) const
Definition: MPIBlock.cpp:168
int getGlobalNumRows() const
Definition: MPIBlock.hpp:110
int calcBatchIndexFromRankInternal(int const rank) const
Definition: MPIBlock.cpp:179
int calcColumnFromRank(int const rank) const
Definition: MPIBlock.cpp:163
int calcColumnFromRankInternal(int const rank) const
Definition: MPIBlock.cpp:177
void calcRowColBatchFromRank(int const rank, int &rowIndex, int &columnIndex, int &batchIndex) const
Definition: MPIBlock.cpp:147
int getBatchIndex() const
Definition: MPIBlock.hpp:171
int getStartBatch() const
Definition: MPIBlock.hpp:156
int getRowIndex() const
Definition: MPIBlock.hpp:161
int getSize() const
Definition: MPIBlock.hpp:141
int calcRowFromRank(int const rank) const
Definition: MPIBlock.cpp:158
int calcRowFromRankInternal(int const rank) const
Definition: MPIBlock.cpp:173
static int calcNumCells(int cellSize, int overallSize)
Definition: MPIBlock.cpp:122