10 #define OMPI_SKIP_MPICXX 1
16 #include "../_internals/print.hh"
18 #include "internals/blacs_prototypes.h"
76 void set(
const int blacs_context);
78 void finalize(
const bool mpi_continue=
false);
81 void printf(
const int row,
const int col,
const char *fmt, ...)
const;
87 void send(
const int m,
const int n,
const int *x,
const int rdest=0,
const int cdest=0)
const;
88 void send(
const int m,
const int n,
const float *x,
const int rdest=0,
const int cdest=0)
const;
89 void send(
const int m,
const int n,
const double *x,
const int rdest=0,
const int cdest=0)
const;
90 void send(
const int m,
const int n,
const int ldx,
const int *x,
const int rdest=0,
const int cdest=0)
const;
91 void send(
const int m,
const int n,
const int ldx,
const float *x,
const int rdest=0,
const int cdest=0)
const;
92 void send(
const int m,
const int n,
const int ldx,
const double *x,
const int rdest=0,
const int cdest=0)
const;
94 void recv(
const int m,
const int n,
int *x,
const int rsrc=0,
const int csrc=0)
const;
95 void recv(
const int m,
const int n,
float *x,
const int rsrc=0,
const int csrc=0)
const;
96 void recv(
const int m,
const int n,
double *x,
const int rsrc=0,
const int csrc=0)
const;
97 void recv(
const int m,
const int n,
const int ldx,
int *x,
const int rsrc=0,
const int csrc=0)
const;
98 void recv(
const int m,
const int n,
const int ldx,
float *x,
const int rsrc=0,
const int csrc=0)
const;
99 void recv(
const int m,
const int n,
const int ldx,
double *x,
const int rsrc=0,
const int csrc=0)
const;
102 void barrier(
const char scope=
'A')
const;
104 void allreduce(
const int m,
const int n,
int *x,
const char scope=
'A',
const blacsops op=BLACS_SUM)
const;
105 void allreduce(
const int m,
const int n,
float *x,
const char scope=
'A',
const blacsops op=BLACS_SUM)
const;
106 void allreduce(
const int m,
const int n,
double *x,
const char scope=
'A',
const blacsops op=BLACS_SUM)
const;
108 void reduce(
const int m,
const int n,
int *x,
const char scope=
'A',
const blacsops op=BLACS_SUM,
const int rdest=0,
const int cdest=0)
const;
109 void reduce(
const int m,
const int n,
float *x,
const char scope=
'A',
const blacsops op=BLACS_SUM,
const int rdest=0,
const int cdest=0)
const;
110 void reduce(
const int m,
const int n,
double *x,
const char scope=
'A',
const blacsops op=BLACS_SUM,
const int rdest=0,
const int cdest=0)
const;
112 void bcast(
const int m,
const int n,
int *x,
const char scope=
'A',
const int rsrc=0,
const int csrc=0)
const;
113 void bcast(
const int m,
const int n,
float *x,
const char scope=
'A',
const int rsrc=0,
const int csrc=0)
const;
114 void bcast(
const int m,
const int n,
double *x,
const char scope=
'A',
const int rsrc=0,
const int csrc=0)
const;
133 bool valid_grid()
const {
return (_ictxt!=UNINITIALIZED_GRID && _ictxt!=EXITED_GRID);};
144 static const int UNINITIALIZED_GRID = -1;
145 static const int EXITED_GRID = -11;
147 void squarish(
int *nr,
int *nc)
const;
164 _ictxt = UNINITIALIZED_GRID;
165 _nprocs = _nprow = _npcol = _myrow = _mycol = -1;
184 Cblacs_pinfo(&mypnum, &_nprocs);
186 Cblacs_get(-1, 0, &_ictxt);
193 Cblacs_gridinit(&_ictxt, &order, nr, nc);
196 Cblacs_gridinit(&_ictxt, &order, _nprocs, 1);
198 Cblacs_gridinit(&_ictxt, &order, 1, _nprocs);
200 throw std::runtime_error(
"Process grid should be one of PROC_GRID_SQUARE, PROC_GRID_TALL, or PROC_GRID_WIDE");
202 Cblacs_gridinfo(_ictxt, &_nprow, &_npcol, &_myrow, &_mycol);
214 _ictxt = blacs_context;
215 Cblacs_gridinfo(_ictxt, &_nprow, &_npcol, &_myrow, &_mycol);
218 throw std::runtime_error(
"context handle does not point at a valid context");
220 _nprocs = _nprow * _npcol;
228 if (_ictxt != EXITED_GRID && _ictxt != UNINITIALIZED_GRID)
229 Cblacs_gridexit(_ictxt);
231 _ictxt = EXITED_GRID;
232 _nprocs = _nprow = _npcol = _myrow = _mycol = -1;
246 int cont = (int) mpi_continue;
265 if (_myrow == row && _mycol == col)
270 fml::print::vprintf(fmt, args);
283 printf(0, 0,
"## Grid %d %dx%d\n\n", _ictxt, _nprow, _npcol);
294 return (_myrow==0 && _mycol==0);
305 return !(_myrow==-1 && _mycol==-1);
320 inline void fml::grid::send(
const int m,
const int n,
const int *x,
const int rdest,
const int cdest)
const
323 Cigesd2d(_ictxt, m, n, x, m, rdest, cdest);
326 inline void fml::grid::send(
const int m,
const int n,
const float *x,
const int rdest,
const int cdest)
const
328 Csgesd2d(_ictxt, m, n, x, m, rdest, cdest);
331 inline void fml::grid::send(
const int m,
const int n,
const double *x,
const int rdest,
const int cdest)
const
333 Cdgesd2d(_ictxt, m, n, x, m, rdest, cdest);
336 inline void fml::grid::send(
const int m,
const int n,
const int ldx,
const int *x,
const int rdest,
const int cdest)
const
338 Cigesd2d(_ictxt, m, n, x, ldx, rdest, cdest);
341 inline void fml::grid::send(
const int m,
const int n,
const int ldx,
const float *x,
const int rdest,
const int cdest)
const
343 Csgesd2d(_ictxt, m, n, x, ldx, rdest, cdest);
346 inline void fml::grid::send(
const int m,
const int n,
const int ldx,
const double *x,
const int rdest,
const int cdest)
const
348 Cdgesd2d(_ictxt, m, n, x, ldx, rdest, cdest);
362 inline void fml::grid::recv(
const int m,
const int n,
int *x,
const int rsrc,
const int csrc)
const
365 Cigerv2d(_ictxt, m, n, x, m, rsrc, csrc);
368 inline void fml::grid::recv(
const int m,
const int n,
float *x,
const int rsrc,
const int csrc)
const
370 Csgerv2d(_ictxt, m, n, x, m, rsrc, csrc);
373 inline void fml::grid::recv(
const int m,
const int n,
double *x,
const int rsrc,
const int csrc)
const
375 Cdgerv2d(_ictxt, m, n, x, m, rsrc, csrc);
378 inline void fml::grid::recv(
const int m,
const int n,
const int ldx,
int *x,
const int rsrc,
const int csrc)
const
380 Cigerv2d(_ictxt, m, n, x, ldx, rsrc, csrc);
383 inline void fml::grid::recv(
const int m,
const int n,
const int ldx,
float *x,
const int rsrc,
const int csrc)
const
385 Csgerv2d(_ictxt, m, n, x, ldx, rsrc, csrc);
388 inline void fml::grid::recv(
const int m,
const int n,
const int ldx,
double *x,
const int rsrc,
const int csrc)
const
390 Cdgerv2d(_ictxt, m, n, x, ldx, rsrc, csrc);
406 Cblacs_barrier(_ictxt, &scope);
422 reduce(m, n, x, scope, op, -1, -1);
427 reduce(m, n, x, scope, op, -1, -1);
432 reduce(m, n, x, scope, op, -1, -1);
448 inline void fml::grid::reduce(
const int m,
const int n,
int *x,
const char scope,
const blacsops op,
const int rdest,
const int cdest)
const
454 Cigsum2d(_ictxt, &scope, &top, m, n, x, m, rdest, cdest);
455 else if (op == BLACS_MAX)
456 Cigamx2d(_ictxt, &scope, &top, m, n, x, m, NULL, NULL, -1, rdest, cdest);
457 else if (op == BLACS_MIN)
458 Cigamn2d(_ictxt, &scope, &top, m, n, x, m, NULL, NULL, -1, rdest, cdest);
461 inline void fml::grid::reduce(
const int m,
const int n,
float *x,
const char scope,
const blacsops op,
const int rdest,
const int cdest)
const
466 Csgsum2d(_ictxt, &scope, &top, m, n, x, m, rdest, cdest);
467 else if (op == BLACS_MAX)
468 Csgamx2d(_ictxt, &scope, &top, m, n, x, m, NULL, NULL, -1, rdest, cdest);
469 else if (op == BLACS_MIN)
470 Csgamn2d(_ictxt, &scope, &top, m, n, x, m, NULL, NULL, -1, rdest, cdest);
473 inline void fml::grid::reduce(
const int m,
const int n,
double *x,
const char scope,
const blacsops op,
const int rdest,
const int cdest)
const
478 Cdgsum2d(_ictxt, &scope, &top, m, n, x, m, rdest, cdest);
479 else if (op == BLACS_MAX)
480 Cdgamx2d(_ictxt, &scope, &top, m, n, x, m, NULL, NULL, -1, rdest, cdest);
481 else if (op == BLACS_MIN)
482 Cdgamn2d(_ictxt, &scope, &top, m, n, x, m, NULL, NULL, -1, rdest, cdest);
498 inline void fml::grid::bcast(
const int m,
const int n,
int *x,
const char scope,
const int rsrc,
const int csrc)
const
502 if (rsrc == _myrow && csrc == _mycol)
503 Cigebs2d(_ictxt, &scope, &top, m, n, x, m);
505 Cigebr2d(_ictxt, &scope, &top, m, n, x, m, rsrc, csrc);
508 inline void fml::grid::bcast(
const int m,
const int n,
float *x,
const char scope,
const int rsrc,
const int csrc)
const
511 if (rsrc == _myrow && csrc == _mycol)
512 Csgebs2d(_ictxt, &scope, &top, m, n, x, m);
514 Csgebr2d(_ictxt, &scope, &top, m, n, x, m, rsrc, csrc);
517 inline void fml::grid::bcast(
const int m,
const int n,
double *x,
const char scope,
const int rsrc,
const int csrc)
const
520 if (rsrc == _myrow && csrc == _mycol)
521 Cdgebs2d(_ictxt, &scope, &top, m, n, x, m);
523 Cdgebr2d(_ictxt, &scope, &top, m, n, x, m, rsrc, csrc);
533 inline void fml::grid::squarish(
int *nr,
int *nc)
const
535 int n = (int) sqrt((
double) _nprocs);
538 for (
int i=0; i<n; i++)
541 (*nr) = _nprocs % (*nc);
546 (*nr) = _nprocs / (*nc);