COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
CommGrid.h
Go to the documentation of this file.
1/****************************************************************/
2/* Parallel Combinatorial BLAS Library (for Graph Computations) */
3/* version 1.5 -------------------------------------------------*/
4/* date: 10/09/2015 ---------------------------------------------*/
5/* authors: Ariful Azad, Aydin Buluc, Adam Lugowski ------------*/
6/****************************************************************/
7/*
8 Copyright (c) 2010-2015, The Regents of the University of California
9
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 THE SOFTWARE.
27 */
28
29#ifndef _COMM_GRID_H_
30#define _COMM_GRID_H_
31
32#include <iostream>
33#include <cmath>
34#include <cassert>
35#include <mpi.h>
36#include <sstream>
37#include <string>
38#include <fstream>
39#include <stdint.h>
40#include "MPIType.h"
41
42namespace combblas {
43
45{
46public:
48
50 {
51 MPI_Comm_free(&commWorld);
52 MPI_Comm_free(&rowWorld);
53 MPI_Comm_free(&colWorld);
54 if(grrows == grcols) {
55 if(diagWorld != MPI_COMM_NULL) MPI_Comm_free(&diagWorld);
56 }
57 }
58 CommGrid (const CommGrid & rhs): grrows(rhs.grrows), grcols(rhs.grcols),
59 myprocrow(rhs.myprocrow), myproccol(rhs.myproccol), myrank(rhs.myrank) // copy constructor
60 {
61 MPI_Comm_dup(rhs.commWorld, &commWorld);
62 MPI_Comm_dup(rhs.rowWorld, &rowWorld);
63 MPI_Comm_dup(rhs.colWorld, &colWorld);
64
65 // don't use the shortcut ternary ? operator, C++ syntax fails as
66 // mpich implements MPI::COMM_NULL of different type than MPI::IntraComm
67 if(rhs.diagWorld == MPI_COMM_NULL)
68 diagWorld = MPI_COMM_NULL;
69 else
70 MPI_Comm_dup(rhs.diagWorld,&diagWorld);
71 }
72
73 CommGrid & operator=(const CommGrid & rhs) // assignment operator
74 {
75 if(this != &rhs)
76 {
77 MPI_Comm_free(&commWorld);
78 MPI_Comm_free(&rowWorld);
79 MPI_Comm_free(&colWorld);
80
81 grrows = rhs.grrows;
82 grcols = rhs.grcols;
83 myrank = rhs.myrank;
84 myprocrow = rhs.myprocrow;
85 myproccol = rhs.myproccol;
86
87 MPI_Comm_dup(rhs.commWorld, &commWorld);
88 MPI_Comm_dup(rhs.rowWorld, &rowWorld);
89 MPI_Comm_dup(rhs.colWorld, &colWorld);
90
91 if(rhs.diagWorld == MPI_COMM_NULL) diagWorld = MPI_COMM_NULL;
92 else MPI_Comm_dup(rhs.diagWorld,&diagWorld);
93 }
94 return *this;
95 }
96 void CreateDiagWorld();
97
98 bool operator== (const CommGrid & rhs) const;
99 bool operator!= (const CommGrid & rhs) const
100 {
101 return (! (*this == rhs));
102 }
103 bool OnSameProcCol( int rhsrank );
104 bool OnSameProcRow( int rhsrank );
105
106 int GetRank(int rowrank, int colrank) { return rowrank * grcols + colrank; }
107 int GetRank(int diagrank) { return diagrank * grcols + diagrank; }
108 int GetRank() { return myrank; }
109 int GetRankInProcRow() { return myproccol; }
110 int GetRankInProcCol() { return myprocrow; }
112 {
113 int rank;
114 MPI_Comm_rank(diagWorld, &rank);
115 return rank;
116 }
117
120
121 int GetDiagOfProcRow();
122 int GetDiagOfProcCol();
123
124 int GetComplementRank() // For P(i,j), get rank of P(j,i)
125 {
126 return ((grcols * myproccol) + myprocrow);
127 }
128
129 MPI_Comm & GetWorld() { return commWorld; }
130 MPI_Comm & GetRowWorld() { return rowWorld; }
131 MPI_Comm & GetColWorld() { return colWorld; }
132 MPI_Comm & GetDiagWorld() { return diagWorld; }
133 MPI_Comm GetWorld() const { return commWorld; }
134 MPI_Comm GetRowWorld() const { return rowWorld; }
135 MPI_Comm GetColWorld() const { return colWorld; }
136 MPI_Comm GetDiagWorld() const { return diagWorld; }
137
138 int GetGridRows() { return grrows; }
139 int GetGridCols() { return grcols; }
140 int GetSize() { return grrows * grcols; }
142 {
143 int size;
144 MPI_Comm_size(diagWorld, &size);
145 return size;
146 }
147
148 void OpenDebugFile(std::string prefix, std::ofstream & output) const;
149
150 friend std::shared_ptr<CommGrid> ProductGrid(CommGrid * gridA, CommGrid * gridB, int & innerdim, int & Aoffset, int & Boffset);
151private:
152 // A "normal" MPI-1 communicator is an intracommunicator; MPI::COMM_WORLD is also an MPI::Intracomm object
153 MPI_Comm commWorld, rowWorld, colWorld, diagWorld;
154
155 // Processor grid is (grrow X grcol)
156 int grrows, grcols;
157 int myprocrow;
158 int myproccol;
159 int myrank;
160
161 template <class IT, class NT, class DER>
162 friend class SpParMat;
163
164 template <class IT, class NT>
165 friend class FullyDistSpVec;
166};
167
168}
169
170#endif
MPI_Comm GetColWorld() const
Definition CommGrid.h:135
MPI_Comm & GetColWorld()
Definition CommGrid.h:131
bool operator==(const CommGrid &rhs) const
Definition CommGrid.cpp:139
bool OnSameProcRow(int rhsrank)
Definition CommGrid.cpp:108
void OpenDebugFile(std::string prefix, std::ofstream &output) const
MPI_Comm GetWorld() const
Definition CommGrid.h:133
MPI_Comm GetRowWorld() const
Definition CommGrid.h:134
MPI_Comm & GetDiagWorld()
Definition CommGrid.h:132
int GetRank(int rowrank, int colrank)
Definition CommGrid.h:106
MPI_Comm & GetRowWorld()
Definition CommGrid.h:130
friend std::shared_ptr< CommGrid > ProductGrid(CommGrid *gridA, CommGrid *gridB, int &innerdim, int &Aoffset, int &Boffset)
Definition CommGrid.cpp:164
bool OnSameProcCol(int rhsrank)
Definition CommGrid.cpp:103
CommGrid & operator=(const CommGrid &rhs)
Definition CommGrid.h:73
MPI_Comm & GetWorld()
Definition CommGrid.h:129
MPI_Comm GetDiagWorld() const
Definition CommGrid.h:136
int GetRank(int diagrank)
Definition CommGrid.h:107
CommGrid(const CommGrid &rhs)
Definition CommGrid.h:58
int GetComplementRank()
Definition CommGrid.h:124
bool operator!=(const CommGrid &rhs) const
Definition CommGrid.h:99
int size
Definition common.h:20
int rank
bool output
Definition comms.cpp:56