3 #ifndef DISTNMF_MPICOMM_HPP_ 4 #define DISTNMF_MPICOMM_HPP_ 11 #include "pacoss/pacoss.h" 36 INFO <<
"successfully setup MPI communicators" << std::endl;
37 INFO <<
"size=" <<
size() << std::endl;
38 INFO <<
"rowsize=" << m_row_size <<
":pr=" << m_pr << std::endl;
39 INFO <<
"colsize=" << m_col_size <<
":pc=" << m_pc << std::endl;
41 MPI_Barrier(MPI_COMM_WORLD);
51 TMPI_Init(&argc, &argv);
53 MPI_Init(&argc, &argv);
55 MPI_Comm_rank(MPI_COMM_WORLD, &m_rank);
56 MPI_Comm_size(MPI_COMM_WORLD, &m_numProcs);
59 MPI_Barrier(MPI_COMM_WORLD);
68 TMPI_Init(&argc, &argv);
70 MPI_Init(&argc, &argv);
72 MPI_Comm_rank(MPI_COMM_WORLD, &m_rank);
73 MPI_Comm_size(MPI_COMM_WORLD, &m_numProcs);
75 std::vector<int> dimSizes;
76 std::vector<int> periods;
85 std::vector<int> gridCoords;
86 fillVector<int>(1, &periods);
89 if (dimSizes[0] * dimSizes[1] != m_numProcs) {
91 std::cerr <<
"Processor grid dimensions do not" 92 <<
"multiply to MPI_SIZE::" << dimSizes[0] <<
'x' 93 << dimSizes[1] <<
"::m_numProcs::" << m_numProcs << std::endl;
95 MPI_Barrier(MPI_COMM_WORLD);
96 MPI_Abort(MPI_COMM_WORLD, 1);
98 MPI_Cart_create(MPI_COMM_WORLD, nd, &dimSizes[0], &periods[0], reorder,
100 gridCoords.resize(nd);
101 MPI_Cart_get(gridComm, nd, &dimSizes[0], &periods[0], &(gridCoords[0]));
102 this->m_commSubs =
new MPI_Comm[nd];
103 int *keepCols =
new int[nd];
104 for (
int i = 0; i < nd; i++) {
105 std::fill_n(keepCols, nd, 0);
107 MPI_Cart_sub(gridComm, keepCols, &(this->m_commSubs[i]));
109 MPI_Comm_size(m_commSubs[0], &m_row_size);
110 MPI_Comm_size(m_commSubs[1], &m_col_size);
111 MPI_Comm_rank(m_commSubs[0], &m_row_rank);
112 MPI_Comm_rank(m_commSubs[1], &m_col_rank);
118 const int rank()
const {
return m_rank; }
120 const int size()
const {
return m_numProcs; }
126 const int pr()
const {
return m_pr; }
128 const int pc()
const {
return m_pc; }
129 const MPI_Comm *
commSubs()
const {
return m_commSubs; }
134 #endif // DISTNMF_MPICOMM_HPP_ MPICommunicator(int argc, char *argv[])
const int pc() const
Total number of column processor.
const int pr() const
Total number of row processors.
const int row_rank() const
returns its rank in the row processor grid
MPICommunicator(int argc, char *argv[], int pr, int pc)
const int size() const
returns the total number of mpi processes
const int col_rank() const
returns the rank in the column processor grid
const int rank() const
returns the global rank
ncp_factors contains the factors of the ncp every ith factor is of size n_i * k number of factors is ...
const MPI_Comm * commSubs() const