DFT-FE 1.1.0-pre
Density Functional Theory With Finite-Elements
Loading...
Searching...
No Matches
process_grid.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2017 - 2019 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16#ifndef dftfe_process_grid_h
17#define dftfe_process_grid_h
18
19#include "headers.h"
20
21
22namespace dftfe
23{
24// Forward declaration of class ScaLAPACKMatrix for ProcessGrid
25#ifndef DOXYGEN
26 template <typename NumberType>
27 class ScaLAPACKMatrix;
28#endif
29
30 /**
31 * A class taking care of setting up a two-dimensional processor grid.
32 * For example an MPI communicator with 5 processes can be arranged into a
33 * 2x2 grid with the 5-th processor being inactive:
34 * @code
35 * | 0 | 1
36 * -----| ------- |-----
37 * 0 | P0 | P1
38 * | |
39 * -----| ------- |-----
40 * 1 | P2 | P3
41 * @endcode
42 *
43 * A shared pointer to this class is provided to ScaLAPACKMatrix matrices to
44 * perform block-cyclic distribution.
45 *
46 * Note that this class allows to setup a process grid which has fewer
47 * MPI cores than the total number of cores in the communicator.
48 *
49 * Currently the only place where one would use a ProcessGrid object is
50 * in connection with a ScaLAPACKMatrix object.
51 */
53 {
54 public:
55 // Declare class ScaLAPACK as friend to provide access to private members.
56 template <typename NumberType>
58
59 /**
60 * Constructor for a process grid with @p n_rows and @p n_columns for a given @p mpi_communicator.
61 * The product of rows and columns should be less or equal to the total
62 * number of cores
63 * in the @p mpi_communicator.
64 */
65 ProcessGrid(const MPI_Comm & mpi_communicator,
66 const unsigned int n_rows,
67 const unsigned int n_columns);
68
69 /**
70 * Constructor for a process grid for a given @p mpi_communicator.
71 * In this case the process grid is heuristically chosen based on the
72 * dimensions and block-cyclic distribution of a target matrix provided
73 * in @p n_rows_matrix, @p n_columns_matrix, @p row_block_size and @p column_block_size.
74 *
75 * The maximum number of MPI cores one can utilize is
76 * $\min\{\frac{M}{MB}\frac{N}{NB}, Np\}$, where $M,N$ are the matrix
77 * dimension and $MB,NB$ are the block sizes and $Np$ is the number of
78 * processes in the @p mpi_communicator. This function then creates a 2D processor grid
79 * assuming the ratio between number of process row $p$ and columns $q$ to
80 * be equal the ratio between matrix dimensions $M$ and $N$.
81 *
82 * For example, a square matrix $640x640$ with the block size $32$
83 * and the @p mpi_communicator with 11 cores will result in the $3x3$
84 * process grid.
85 */
86 ProcessGrid(const MPI_Comm & mpi_communicator,
87 const unsigned int n_rows_matrix,
88 const unsigned int n_columns_matrix,
89 const unsigned int row_block_size,
90 const unsigned int column_block_size);
91
92 /**
93 * Destructor.
94 */
96
97 /**
98 * Return the blacs_context.
99 */
100 int
101 get_blacs_context() const;
102
103
104 /**
105 * Return the number of rows in the processes grid.
106 */
107 unsigned int
108 get_process_grid_rows() const;
109
110 /**
111 * Return the number of columns in the processes grid.
112 */
113 unsigned int
115
116 /**
117 * Return row of this process in the process grid.
118 *
119 * It's negative for inactive processes.
120 */
121 int
122 get_this_process_row() const;
123
124 /**
125 * Return column of this process in the process grid.
126 *
127 * It's negative for inactive processes.
128 */
129 int
131
132 /**
133 * Send @p count values stored consequently starting at @p value from
134 * the process with rank zero to processes which
135 * are not in the process grid.
136 */
137 template <typename NumberType>
138 void
139 send_to_inactive(NumberType *value, const int count = 1) const;
140
141 /**
142 * Return <code>true</code> if the process is active within the grid.
143 */
144 bool
145 is_process_active() const;
146
147 private:
148 /**
149 * A private constructor which takes grid dimensions as an
150 * <code>std::pair</code>.
151 */
153 const std::pair<unsigned int, unsigned int> &grid_dimensions);
154
155 /**
156 * An MPI communicator with all processes (active and inactive).
157 */
159
160 /**
161 * An MPI communicator with inactive processes and the process with rank
162 * zero.
163 */
165
166 /**
167 * BLACS context. This is equivalent to MPI communicators and is
168 * used by ScaLAPACK.
169 */
171
172 /**
173 * Rank of this MPI process.
174 */
175 const unsigned int this_mpi_process;
176
177 /**
178 * Total number of MPI processes.
179 */
180 const unsigned int n_mpi_processes;
181
182 /**
183 * Number of rows in the processes grid.
184 */
186
187 /**
188 * Number of columns in the processes grid.
189 */
191
192 /**
193 * Row of this process in the grid.
194 *
195 * It's negative for in-active processes.
196 */
198
199 /**
200 * Column of this process in the grid.
201 *
202 * It's negative for in-active processes.
203 */
205
206 /**
207 * A flag which is true for processes within the 2D process grid.
208 */
210 };
211
212 /*--------------------- Inline functions --------------------------------*/
213
214#ifndef DOXYGEN
215
216 inline int
218 {
219 return blacs_context;
220 }
221
222 inline unsigned int
224 {
225 return n_process_rows;
226 }
227
228
229
230 inline unsigned int
235
236
237
238 inline int
243
244
245
246 inline int
251
252
253
254 inline bool
259
260
261#endif // ifndef DOXYGEN
262
263} // end of namespace dftfe
264
265#endif
unsigned int get_process_grid_rows() const
Definition process_grid.h:223
int get_this_process_row() const
Definition process_grid.h:239
int n_process_columns
Definition process_grid.h:190
bool is_process_active() const
Definition process_grid.h:255
MPI_Comm mpi_communicator
Definition process_grid.h:158
int this_process_column
Definition process_grid.h:204
const unsigned int n_mpi_processes
Definition process_grid.h:180
int blacs_context
Definition process_grid.h:170
int this_process_row
Definition process_grid.h:197
int n_process_rows
Definition process_grid.h:185
ProcessGrid(const MPI_Comm &mpi_communicator, const std::pair< unsigned int, unsigned int > &grid_dimensions)
void send_to_inactive(NumberType *value, const int count=1) const
bool mpi_process_is_active
Definition process_grid.h:209
int get_this_process_column() const
Definition process_grid.h:247
int get_blacs_context() const
Definition process_grid.h:217
unsigned int get_process_grid_columns() const
Definition process_grid.h:231
MPI_Comm mpi_communicator_inactive_with_root
Definition process_grid.h:164
ProcessGrid(const MPI_Comm &mpi_communicator, const unsigned int n_rows_matrix, const unsigned int n_columns_matrix, const unsigned int row_block_size, const unsigned int column_block_size)
ProcessGrid(const MPI_Comm &mpi_communicator, const unsigned int n_rows, const unsigned int n_columns)
const unsigned int this_mpi_process
Definition process_grid.h:175
Scalapack wrapper adapted from dealii library and extended implementation to complex datatype.
Definition scalapackWrapper.h:37
Definition pseudoPotentialToDftfeConverter.cc:34