mptensor  v0.3.0
Parallel Library for Tensor Network Methods
blacsgrid.hpp
Go to the documentation of this file.
1 /*
2  mptensor - Parallel Library for Tensor Network Methods
3 
4  Copyright 2016 Satoshi Morita
5 
6  mptensor is free software: you can redistribute it and/or modify it
7  under the terms of the GNU Lesser General Public License as
8  published by the Free Software Foundation, either version 3 of the
9  License, or (at your option) any later version.
10 
11  mptensor is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with mptensor. If not, see
18  <https://www.gnu.org/licenses/>.
19 */
20 
29 #ifndef _BLACSGRID_HPP_
30 #define _BLACSGRID_HPP_
31 #ifndef _NO_MPI
32 
33 #include <mpi.h>
34 #include <vector>
35 
36 namespace mptensor {
37 namespace scalapack {
38 
39 class BlacsGrid {
40  private:
41  // std::vector<int> pnum2mpirank;
42  // std::vector<int> mpirank2pnum;
43  void init_grid(const MPI_Comm &comm, int nprow, int npcol);
44  static bool is_initialized;
45 
46  public:
47  BlacsGrid(const MPI_Comm &comm);
48 
49  static void init();
50  static void exit();
51 
52  MPI_Comm comm;
53  int ictxt;
54  int nprow, npcol;
57  int mpirank(int prow, int pcol) const;
58  int mpirank() const;
59  void show() const;
60 };
61 
62 inline int BlacsGrid::mpirank(int prow, int pcol) const {
63  return prow * npcol + pcol;
64  // return Cblacs_pnum(ictxt, prow, pcol);
65  // This equibalence is checked in BlacsGrid::init_grid()
66 
67  // int pnum = Cblacs_pnum(ictxt, prow, pcol);
68  // return pnum2mpirank[pnum];
69 }
70 
71 inline int BlacsGrid::mpirank() const { return myrank; }
72 
73 } // namespace scalapack
74 } // namespace mptensor
75 
76 #endif // _NO_MPI
77 #endif // _BLACSGRID_HPP_
Definition: blacsgrid.hpp:39
int mpisize
Definition: blacsgrid.hpp:56
static void exit()
Definition: blacsgrid.cc:142
int myrank
Definition: blacsgrid.hpp:56
BlacsGrid(const MPI_Comm &comm)
Definition: blacsgrid.cc:56
MPI_Comm comm
Definition: blacsgrid.hpp:52
void show() const
Definition: blacsgrid.cc:152
int nprow
Definition: blacsgrid.hpp:54
int mpirank() const
Definition: blacsgrid.hpp:71
int mypcol
Definition: blacsgrid.hpp:55
int myprow
Definition: blacsgrid.hpp:55
int npcol
Definition: blacsgrid.hpp:54
int mypnum
Definition: blacsgrid.hpp:55
int ictxt
Definition: blacsgrid.hpp:53
static void init()
Definition: blacsgrid.cc:111
Definition: complex.hpp:34