ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
parallel_2d.h
Go to the documentation of this file.
1#ifndef _PARALLEL_2D_H_
2#define _PARALLEL_2D_H_
3
4#include <cstdint>
5#include <vector>
6
8
12{
13 public:
14 Parallel_2D() = default;
15 ~Parallel_2D() = default;
16
18 Parallel_2D(Parallel_2D&& rhs) = default;
19
21 int get_row_size() const
22 {
23 return nrow;
24 };
25
27 int get_col_size() const
28 {
29 return ncol;
30 };
31
33 int get_global_row_size() const;
34
36 int get_global_col_size() const;
37
39 int64_t get_local_size() const
40 {
41 return nloc;
42 };
43
45 int global2local_row(const int igr) const
46 {
47 return global2local_row_[igr];
48 }
49
51 int global2local_col(const int igc) const
52 {
53 return global2local_col_[igc];
54 }
55
57 int local2global_row(const int ilr) const
58 {
59 return local2global_row_[ilr];
60 }
61
63 int local2global_col(const int ilc) const
64 {
65 return local2global_col_[ilc];
66 }
67
69 bool in_this_processor(const int iw1_all, const int iw2_all) const;
70
72 int get_block_size() const
73 {
74 return nb;
75 };
76
77#ifdef __MPI
83 int init(const int mg,
84 const int ng,
85 const int nb, // square block is assumed
86 const MPI_Comm comm,
87 bool mode = false);
88
94 int set(const int mg,
95 const int ng,
96 const int nb, // square block is assumed
97 const int blacs_ctxt);
98
100 int blacs_ctxt = -1;
101
103 int desc[9] = {};
104
105 MPI_Comm comm() const;
106#endif
107
108 void set_serial(const int mg, const int ng);
109
110 // FIXME the following variables should be private, but they are
111 // widely used in the code currently. Public visibility is kept
112 // for now, but might be changed in the future.
113
115 int nrow = 0;
116 int ncol = 0;
117 int64_t nloc = 0;
118 // NOTE: ScaLAPACK descriptors use int type for the number of rows and columns of
119 // both the global and local matrices, so nrow & ncol have to be int type. Their
120 // product, however, can exceed the range of int type.
121
123 int nb = 1;
124
126 int dim0 = 0;
127 int dim1 = 0;
128
130 int coord[2] = {-1, -1};
131
133 bool is_serial = false;
134
135 protected:
137 std::vector<int> global2local_row_;
138 std::vector<int> global2local_col_;
139
141 std::vector<int> local2global_row_;
142 std::vector<int> local2global_col_;
143
144#ifdef __MPI
145 void _init_proc_grid(const MPI_Comm comm, const bool mode);
146 void _set_dist_info(const int mg, const int ng, const int nb);
147#endif
148};
149#endif
This class packs the basic information of 2D-block-cyclic parallel distribution of an arbitrary matri...
Definition parallel_2d.h:12
std::vector< int > local2global_row_
map from local index to global index
Definition parallel_2d.h:141
int64_t get_local_size() const
number of local matrix elements
Definition parallel_2d.h:39
void _set_dist_info(const int mg, const int ng, const int nb)
Definition parallel_2d.cpp:76
bool in_this_processor(const int iw1_all, const int iw2_all) const
check whether a global index is in this process
Definition parallel_2d.cpp:8
int get_global_row_size() const
number of global rows
Definition parallel_2d.cpp:13
int dim0
number of processes in each dimension of the MPI Cartesian grid
Definition parallel_2d.h:126
int blacs_ctxt
BLACS context.
Definition parallel_2d.h:100
int ncol
Definition parallel_2d.h:116
int local2global_col(const int ilc) const
get the global index of a local index (col)
Definition parallel_2d.h:63
int get_block_size() const
side length of 2d square block
Definition parallel_2d.h:72
int set(const int mg, const int ng, const int nb, const int blacs_ctxt)
Set up the info of a block-cyclic distribution using given BLACS context.
Definition parallel_2d.cpp:115
MPI_Comm comm() const
Definition parallel_2d.cpp:36
int get_row_size() const
number of local rows
Definition parallel_2d.h:21
int nrow
local size (nloc = nrow * ncol)
Definition parallel_2d.h:115
int coord[2]
process coordinate in the BLACS grid
Definition parallel_2d.h:130
void set_serial(const int mg, const int ng)
Definition parallel_2d.cpp:124
std::vector< int > global2local_col_
Definition parallel_2d.h:138
int local2global_row(const int ilr) const
get the global index of a local index (row)
Definition parallel_2d.h:57
int get_global_col_size() const
number of global columns
Definition parallel_2d.cpp:24
int nb
block size
Definition parallel_2d.h:123
Parallel_2D()=default
int global2local_col(const int igc) const
get the local index of a global index (col)
Definition parallel_2d.h:51
void _init_proc_grid(const MPI_Comm comm, const bool mode)
Definition parallel_2d.cpp:52
int init(const int mg, const int ng, const int nb, const MPI_Comm comm, bool mode=false)
Initialize a BLACS grid with the given MPI communicator and set up the info of a block-cyclic distrib...
Definition parallel_2d.cpp:108
int global2local_row(const int igr) const
get the local index of a global index (row)
Definition parallel_2d.h:45
Parallel_2D(Parallel_2D &&rhs)=default
int64_t nloc
Definition parallel_2d.h:117
bool is_serial
whether to use the serial mode
Definition parallel_2d.h:133
int dim1
Definition parallel_2d.h:127
int desc[9]
ScaLAPACK descriptor.
Definition parallel_2d.h:103
std::vector< int > global2local_row_
map from global index to local index
Definition parallel_2d.h:137
std::vector< int > local2global_col_
Definition parallel_2d.h:142
int get_col_size() const
number of local columns
Definition parallel_2d.h:27
Parallel_2D & operator=(Parallel_2D &&rhs)=default
~Parallel_2D()=default