PetaVision  Alpha
BorderExchange.hpp
1 /*
2  * BorderExchange.hpp
3  */
4 
5 #ifndef BORDEREXCHANGE_HPP_
6 #define BORDEREXCHANGE_HPP_
7 
8 #include "arch/mpi/mpi.h"
9 #include "include/PVLayerLoc.h"
10 #include "structures/MPIBlock.hpp"
11 #include <vector>
12 
13 namespace PV {
14 
16  public:
17  BorderExchange(MPIBlock const &mpiBlock, PVLayerLoc const &loc);
18  ~BorderExchange();
19 
20  void exchange(float *data, std::vector<MPI_Request> &req);
21 
22  static int wait(std::vector<MPI_Request> &req);
23 
24  MPIBlock const *getMPIBlock() const { return mMPIBlock; }
25 
26  int getRank() const { return mMPIBlock->getRank(); }
27 
28  int getNumNeighbors() const { return mNumNeighbors; }
29 
30  static int northwest(int row, int column, int numRows, int numColumns);
31  static int north(int row, int column, int numRows, int numColumns);
32  static int northeast(int row, int column, int numRows, int numColumns);
33  static int west(int row, int column, int numRows, int numColumns);
34  static int east(int row, int column, int numRows, int numColumns);
35  static int southwest(int row, int column, int numRows, int numColumns);
36  static int south(int row, int column, int numRows, int numColumns);
37  static int southeast(int row, int column, int numRows, int numColumns);
38 
39  static bool hasNorthwesternNeighbor(int row, int column, int numRows, int numColumns);
40  static bool hasNorthernNeighbor(int row, int column, int numRows, int numColumns);
41  static bool hasNortheasternNeighbor(int row, int column, int numRows, int numColumns);
42  static bool hasWesternNeighbor(int row, int column, int numRows, int numColumns);
43  static bool hasEasternNeighbor(int row, int column, int numRows, int numColumns);
44  static bool hasSouthwesternNeighbor(int row, int column, int numRows, int numColumns);
45  static bool hasSouthernNeighbor(int row, int column, int numRows, int numColumns);
46  static bool hasSoutheasternNeighbor(int row, int column, int numRows, int numColumns);
47 
48  private:
49  void newDatatypes();
50  void freeDatatypes();
51 
52  void initNeighbors();
53 
66  int reverseDirection(int commId, int direction);
67 
72  std::size_t recvOffset(int direction);
73 
78  std::size_t sendOffset(int direction);
79 
80  // Data members
81  private:
82  MPIBlock const *mMPIBlock = nullptr; // TODO: copy mpiBlock instead of storing a pointer.
83  PVLayerLoc mLayerLoc;
84  std::vector<MPI_Datatype> mDatatypes;
85  std::vector<int> neighbors;
86  unsigned int mNumNeighbors;
87 
92  int neighborIndex(int commId, int direction);
93 
94  static int const LOCAL = 0;
95  static int const NORTHWEST = 1;
96  static int const NORTH = 2;
97  static int const NORTHEAST = 3;
98  static int const WEST = 4;
99  static int const EAST = 5;
100  static int const SOUTHWEST = 6;
101  static int const SOUTH = 7;
102  static int const SOUTHEAST = 8;
103  static std::vector<int> const mTags;
104 
105  static int exchangeCounter;
106 
107 }; // end class BorderExchange
108 
109 } // end namespace PV
110 
111 #endif // BORDEREXCHANGE_HPP_
int reverseDirection(int commId, int direction)
std::size_t recvOffset(int direction)
std::size_t sendOffset(int direction)
int getRank() const
Definition: MPIBlock.hpp:100
int neighborIndex(int commId, int direction)