39 template <
class IT,
class NT,
class Enable=
void>
58 template <
class IT,
class NT>
64 SpParHelper::Print(
"COMBBLAS Warning: It is dangerous to create (vector) objects without specifying the communicator, are you sure you want to create this object in MPI_COMM_WORLD?\n");
65 commGrid.reset(
new CommGrid(MPI_COMM_WORLD, 0, 0));
69 SpParHelper::Print(
"COMBBLAS Warning: It is dangerous to create (vector) objects without specifying the communicator, are you sure you want to create this object in MPI_COMM_WORLD?\n");
70 commGrid.reset(
new CommGrid(MPI_COMM_WORLD, 0, 0));
81 FullyDist( std::shared_ptr<CommGrid> grid, IT globallen): glen(globallen)
88 commGrid = rhs.commGrid;
92 IT LengthUntil()
const;
93 IT RowLenUntil()
const;
94 IT RowLenUntil(
int k)
const;
95 IT MyLocLength()
const;
96 IT MyRowLength()
const;
98 int Owner(IT gind, IT & lind)
const;
99 int OwnerWithinRow(IT n_thisrow, IT ind_withinrow, IT & lind)
const;
110 template <
class IT,
class NT>
112 ::Owner(IT gind, IT & lind)
const 115 int procrows = commGrid->GetGridRows();
116 IT n_perprocrow = glen / procrows;
119 if(n_perprocrow != 0)
121 own_procrow = std::min(static_cast<int>(gind / n_perprocrow), procrows-1);
125 own_procrow = procrows -1;
128 IT ind_withinrow = gind - (own_procrow * n_perprocrow);
129 if(own_procrow == procrows-1)
130 n_thisrow = glen - (n_perprocrow*(procrows-1));
132 n_thisrow = n_perprocrow;
134 int proccols = commGrid->GetGridCols();
135 IT n_perproc = n_thisrow / proccols;
140 own_proccol = std::min(static_cast<int>(ind_withinrow / n_perproc), proccols-1);
144 own_proccol = proccols-1;
146 lind = ind_withinrow - (own_proccol * n_perproc);
149 return commGrid->GetRank(own_procrow, own_proccol);
158 template <
class IT,
class NT>
160 ::OwnerWithinRow(IT n_thisrow, IT ind_withinrow, IT & lind)
const 162 int proccols = commGrid->GetGridCols();
163 IT n_perproc = n_thisrow / proccols;
168 own_proccol = std::min(static_cast<int>(ind_withinrow / n_perproc), proccols-1);
172 own_proccol = proccols-1;
174 lind = ind_withinrow - (own_proccol * n_perproc);
179 template <
class IT,
class NT>
180 IT FullyDist<IT,NT,typename combblas::disable_if< combblas::is_boolean<NT>::value, NT >::type >
181 ::LengthUntil()
const 183 int procrows = commGrid->GetGridRows();
184 int my_procrow = commGrid->GetRankInProcCol();
185 IT n_perprocrow = glen / procrows;
187 if(my_procrow == procrows-1)
188 n_thisrow = glen - (n_perprocrow*(procrows-1));
190 n_thisrow = n_perprocrow;
192 int proccols = commGrid->GetGridCols();
193 int my_proccol = commGrid->GetRankInProcRow();
194 IT n_perproc = n_thisrow / proccols;
195 return ((n_perprocrow * my_procrow)+(n_perproc*my_proccol));
199 template <
class IT,
class NT>
200 IT FullyDist<IT,NT,typename combblas::disable_if< combblas::is_boolean<NT>::value, NT >::type >
201 ::RowLenUntil()
const 203 int procrows = commGrid->GetGridRows();
204 int my_procrow = commGrid->GetRankInProcCol();
205 IT n_perprocrow = glen / procrows;
207 if(my_procrow == procrows-1)
208 n_thisrow = glen - (n_perprocrow*(procrows-1));
210 n_thisrow = n_perprocrow;
212 int proccols = commGrid->GetGridCols();
213 int my_proccol = commGrid->GetRankInProcRow();
214 IT n_perproc = n_thisrow / proccols;
215 return (n_perproc*my_proccol);
219 template <
class IT,
class NT>
220 IT FullyDist<IT,NT,typename combblas::disable_if< combblas::is_boolean<NT>::value, NT >::type >
221 ::RowLenUntil(
int k)
const 223 int procrows = commGrid->GetGridRows();
224 int my_procrow = commGrid->GetRankInProcCol();
225 IT n_perprocrow = glen / procrows;
227 if(my_procrow == procrows-1)
228 n_thisrow = glen - (n_perprocrow*(procrows-1));
230 n_thisrow = n_perprocrow;
232 int proccols = commGrid->GetGridCols();
233 IT n_perproc = n_thisrow / proccols;
234 assert(k < proccols);
235 return (n_perproc*k);
238 template <
class IT,
class NT>
239 IT FullyDist<IT,NT, typename combblas::disable_if< combblas::is_boolean<NT>::value, NT >::type>
240 ::MyLocLength()
const 242 int procrows = commGrid->GetGridRows();
243 int my_procrow = commGrid->GetRankInProcCol();
244 IT n_perprocrow = glen / procrows;
246 if(my_procrow == procrows-1)
247 n_thisrow = glen - (n_perprocrow*(procrows-1));
249 n_thisrow = n_perprocrow;
251 int proccols = commGrid->GetGridCols();
252 int my_proccol = commGrid->GetRankInProcRow();
253 IT n_perproc = n_thisrow / proccols;
254 if(my_proccol == proccols-1)
255 return (n_thisrow - (n_perproc*(proccols-1)));
261 template <
class IT,
class NT>
262 IT FullyDist<IT,NT,typename combblas::disable_if< combblas::is_boolean<NT>::value, NT >::type>
263 ::MyRowLength()
const 265 int procrows = commGrid->GetGridRows();
266 int my_procrow = commGrid->GetRankInProcCol();
267 IT n_perprocrow = glen / procrows;
269 if(my_procrow == procrows-1)
270 n_thisrow = glen - (n_perprocrow*(procrows-1));
272 n_thisrow = n_perprocrow;
FullyDist< IT, NT > & operator=(const FullyDist< IT, NT > &rhs)
static void Print(const std::string &s)
std::shared_ptr< CommGrid > commGrid
FullyDist(std::shared_ptr< CommGrid > grid, IT globallen)
FullyDist(std::shared_ptr< CommGrid > grid)