DFT-FE 1.1.0-pre
Density Functional Theory With Finite-Elements
Loading...
Searching...
No Matches
linearAlgebraOperationsCPU.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (c) 2017-2025 The Regents of the University of Michigan and DFT-FE
4// authors.
5//
6// This file is part of the DFT-FE code.
7//
8// The DFT-FE code is free software; you can use it, redistribute
9// it, and/or modify it under the terms of the GNU Lesser General
10// Public License as published by the Free Software Foundation; either
11// version 2.1 of the License, or (at your option) any later version.
12// The full text of the license can be found in the file LICENSE at
13// the top level of the DFT-FE distribution.
14//
15// ---------------------------------------------------------------------
16
17
18#ifndef linearAlgebraOperationsCPU_h
19#define linearAlgebraOperationsCPU_h
20
21#include <elpaScalaManager.h>
22#include <headers.h>
23#include <operator.h>
24#include "process_grid.h"
25#include "scalapackWrapper.h"
26#include "dftParameters.h"
27#include <BLASWrapper.h>
28namespace dftfe
29{
30 //
31 // extern declarations for blas-lapack routines
32 //
33
34
35
36 /**
37 * @brief Contains linear algebra functions used in the implementation of an eigen solver
38 *
39 * @author Phani Motamarri, Sambit Das
40 */
42 {
43 /** @brief Orthogonalize given subspace using GramSchmidt orthogonalization
44 *
45 * @param[in,out] X Given subspace as flattened array of multi-vectors.
46 * In-place update of the given subspace
47 * @param[in] numberComponents Number of multiple-fields
48 * @param[in] mpiComm global communicator
49 */
50 template <typename T>
51 void
53 const unsigned int numberComponents,
54 const unsigned int numberDofs,
55 const MPI_Comm & mpiComm);
56
57
58 /** @brief Orthogonalize given subspace using Lowden orthogonalization for double data-type
59 * (serial version using LAPACK)
60 *
61 * @param[in,out] X Given subspace as flattened array of multi-vectors.
62 * In-place update of the given subspace
63 * @param[in] numberComponents Number of multiple-fields
64 * @param[in] mpiComm global communicator
65 * @return flag indicating success/failure. 1 for failure, 0 for success
66 */
67 unsigned int
68 lowdenOrthogonalization(std::vector<dataTypes::number> &X,
69 const unsigned int numberComponents,
70 const MPI_Comm & mpiComm,
71 const dftParameters & dftParams);
72
73
74 /** @brief Orthogonalize given subspace using Pseudo-Gram-Schmidt orthogonalization
75 * (serial version using LAPACK, parallel version using ScaLAPACK)
76 *
77 * @param[in,out] X Given subspace as flattened array of multi-vectors.
78 * In-place update of the given subspace
79 * @param[in] numberComponents Number of multiple-fields
80 * @param[in] mpiCommParent parent communicator
81 * @param[in] interBandGroupComm interpool communicator for parallelization
82 * over band groups
83 * @param[in] mpiComm domain decomposition communicator
84 *
85 * @return flag indicating success/failure. 1 for failure, 0 for success
86 */
87 template <typename T>
88 unsigned int
90 elpaScalaManager &elpaScala,
91 const std::shared_ptr<
93 & BLASWrapperPtr,
94 T * X,
95 const unsigned int numberComponents,
96 const unsigned int numberDofs,
97 const MPI_Comm & mpiCommParent,
98 const MPI_Comm & interBandGroupComm,
99 const MPI_Comm & mpiCommDomain,
100 const bool useMixedPrec,
101 const dftParameters &dftParams);
102
103
104 /** @brief Compute Rayleigh-Ritz projection
105 * (serial version using LAPACK, parallel version using ScaLAPACK)
106 *
107 * @param[in] operatorMatrix An object which has access to the given matrix
108 * @param[in,out] X Given subspace as flattened array of multi-vectors.
109 * In-place rotated subspace
110 * @param[in] numberComponents Number of vectors
111 * @param[in] mpiCommDomain parent communicator
112 * @param[in] interBandGroupComm interpool communicator for parallelization
113 * over band groups
114 * @param[in] mpiCommDomain domain decomposition communicator
115 * @param[out] eigenValues of the Projected Hamiltonian
116 */
117 template <typename T>
118 void
121 const std::shared_ptr<
123 & BLASWrapperPtr,
124 elpaScalaManager & elpaScala,
125 T * X,
126 const unsigned int numberComponents,
127 const unsigned int numberDofs,
128 const MPI_Comm & mpiCommParent,
129 const MPI_Comm & interBandGroupComm,
130 const MPI_Comm & mpiCommDomain,
131 std::vector<double> &eigenValues,
132 const bool useMixedPrec,
133 const dftParameters &dftParams);
134
135
136 /** @brief Compute Rayleigh-Ritz projection
137 * (serial version using LAPACK, parallel version using ScaLAPACK)
138 *
139 * @param[in] operatorMatrix An object which has access to the given matrix
140 * @param[in,out] X Given subspace as flattened array of multi-vectors.
141 * In-place rotated subspace
142 * @param[in] numberComponents Number of vectors
143 * @param[in] mpiCommParent parent mpi communicator
144 * @param[in] interBandGroupComm interpool communicator for parallelization
145 * over band groups
146 * @param[in] mpiCommDomain domain decomposition communicator
147 * @param[out] eigenValues of the Projected Hamiltonian
148 */
149 template <typename T>
150 void
153 const std::shared_ptr<
155 & BLASWrapperPtr,
156 elpaScalaManager & elpaScala,
157 T * X,
158 const unsigned int numberComponents,
159 const unsigned int numberDofs,
160 const MPI_Comm & mpiCommParent,
161 const MPI_Comm & interBandGroupComm,
162 const MPI_Comm & mpiCommDomain,
163 std::vector<double> &eigenValues,
164 const dftParameters &dftParams,
165 const bool doCommAfterBandParal = true);
166
167
168
169 /** @brief Compute residual norm associated with eigenValue problem of the given operator
170 *
171 * @param[in] operatorMatrix An object which has access to the given matrix
172 * @param[in] X Given subspace as STL vector of dealii vectors
173 * @param[in] eigenValues eigenValues of the operator
174 * @param[in] mpiCommParent parent mpi communicator
175 * @param[in] mpiCommDomain domain decomposition communicator
176 * @param[out] residualNorms of the eigen Value problem
177 */
178 template <typename T>
179 void
182 const std::shared_ptr<
184 & BLASWrapperPtr,
185 T * X,
186 const std::vector<double> &eigenValues,
187 const unsigned int numberComponents,
188 const unsigned int numberDofs,
189 const MPI_Comm & mpiCommParent,
190 const MPI_Comm & mpiCommDomain,
191 const MPI_Comm & interBandGroupComm,
192 std::vector<double> & residualNorm,
193 const dftParameters & dftParams);
194
195 /** @brief Compute first order response in density matrix with respect to perturbation in the Hamiltonian.
196 * Perturbation is computed in the eigenbasis.
197 */
198 template <typename T>
199 void
202 const std::shared_ptr<
204 & BLASWrapperPtr,
205 T * X,
206 const unsigned int N,
207 const unsigned int numberLocalDofs,
208 const MPI_Comm & mpiCommParent,
209 const MPI_Comm & mpiCommDomain,
210 const MPI_Comm & interBandGroupComm,
211 const std::vector<double> &eigenValues,
212 const double fermiEnergy,
213 std::vector<double> & densityMatDerFermiEnergy,
214 elpaScalaManager & elpaScala,
215 const dftParameters & dftParams);
216
217 /**
218 * @brief Compute projection of the operator into a subspace spanned by a given orthogonal basis HProjConj=X^{T}*HConj*XConj
219 *
220 * @param X Vector of Vectors containing multi-wavefunction fields
221 * @param numberComponents number of wavefunctions associated with a given node
222 * @param ProjMatrix projected small matrix
223 */
224 void
226 const std::shared_ptr<
228 & BLASWrapperPtr,
229 const dataTypes::number * X,
230 const unsigned int numberComponents,
231 const unsigned int numberLocalDofs,
232 const MPI_Comm & mpiCommDomain,
233 const MPI_Comm & interBandGroupComm,
234 const dftParameters & dftParams,
235 std::vector<dataTypes::number> &ProjHam);
236
237 /**
238 * @brief Compute projection of the operator into a subspace spanned by a given orthogonal basis HProjConj=X^{T}*HConj*XConj
239 *
240 * @param X Vector of Vectors containing multi-wavefunction fields
241 * @param numberComponents number of wavefunctions associated with a given node
242 * @param processGrid two-dimensional processor grid corresponding to the parallel projHamPar
243 * @param projHamPar parallel ScaLAPACKMatrix which stores the computed projection
244 * of the operation into the given subspace
245 */
246 void
248 const std::shared_ptr<
250 & BLASWrapperPtr,
251 const dataTypes::number * X,
252 const unsigned int numberComponents,
253 const unsigned int numberLocalDofs,
254 const std::shared_ptr<const dftfe::ProcessGrid> &processGrid,
255 const MPI_Comm & mpiCommDomain,
256 const MPI_Comm & interBandGroupComm,
257 const dftParameters & dftParams,
259 const bool onlyHPrimePartForFirstOrderDensityMatResponse = false);
260
261
262 /**
263 * @brief Compute projection of the operator into a subspace spanned by a given orthogonal basis HProjConj=X^{T}*HConj*XConj
264 *
265 * @param X Vector of Vectors containing multi-wavefunction fields
266 * @param numberComponents number of wavefunctions associated with a given node
267 * @param processGrid two-dimensional processor grid corresponding to the parallel projHamPar
268 * @param projHamPar parallel ScaLAPACKMatrix which stores the computed projection
269 * of the operation into the given subspace
270 */
271 void
273 const std::shared_ptr<
275 & BLASWrapperPtr,
276 const dataTypes::number * X,
277 const unsigned int numberComponents,
278 const unsigned int numberLocalDofs,
279 const std::shared_ptr<const dftfe::ProcessGrid> &processGrid,
280 const MPI_Comm & mpiCommDomain,
281 const MPI_Comm & interBandGroupComm,
282 const dftParameters & dftParams,
284
285 /**
286 * @brief Compute projection of the operator into a subspace spanned by a given orthogonal basis HProjConj=X^{T}*HConj*XConj
287 *
288 * @param X Vector of Vectors containing multi-wavefunction fields
289 * @param totalNumberComponents number of wavefunctions associated with a given node
290 * @param singlePrecComponents number of wavecfuntions starting from the first for
291 * which the project Hamiltionian block will be computed in single
292 * procession. However the cross blocks will still be computed in double
293 * precision.
294 * @param processGrid two-dimensional processor grid corresponding to the parallel projHamPar
295 * @param projHamPar parallel ScaLAPACKMatrix which stores the computed projection
296 * of the operation into the given subspace
297 */
298 void
301 const std::shared_ptr<
303 & BLASWrapperPtr,
304 const dataTypes::number * X,
305 const unsigned int totalNumberComponents,
306 const unsigned int singlePrecComponents,
307 const unsigned int numberLocalDofs,
308 const std::shared_ptr<const dftfe::ProcessGrid> &processGrid,
309 const MPI_Comm & mpiCommDomain,
310 const MPI_Comm & interBandGroupComm,
311 const dftParameters & dftParams,
313 const bool onlyHPrimePartForFirstOrderDensityMatResponse = false);
314
315
316 /**
317 * @brief Compute projection of the operator into a subspace spanned by a given orthogonal basis HProjConj=X^{T}*HConj*XConj
318 *
319 * @param X Vector of Vectors containing multi-wavefunction fields
320 * @param totalNumberComponents number of wavefunctions associated with a given node
321 * @param singlePrecComponents number of wavecfuntions starting from the first for
322 * which the project Hamiltionian block will be computed in single
323 * procession. However the cross blocks will still be computed in double
324 * precision.
325 * @param processGrid two-dimensional processor grid corresponding to the parallel projHamPar
326 * @param projHamPar parallel ScaLAPACKMatrix which stores the computed projection
327 * of the operation into the given subspace
328 */
329 void
332 const std::shared_ptr<
334 & BLASWrapperPtr,
335 const dataTypes::number * X,
336 const unsigned int totalNumberComponents,
337 const unsigned int singlePrecComponents,
338 const unsigned int numberLocalDofs,
339 const std::shared_ptr<const dftfe::ProcessGrid> &processGrid,
340 const MPI_Comm & mpiCommDomain,
341 const MPI_Comm & interBandGroupComm,
342 const dftParameters & dftParams,
344
345 /**
346 * @brief Computes the projection of Hamiltonian and Overlap with only a single extraction.
347 * Single extraction will be beneficial in full M, PAW cases.
348 * @param X Vector of Vectors containing multi-wavefunction fields
349 * @param numberComponents number of wavefunctions associated with a given node
350 * @param numberLocalDofs number of DOFs owned in the current procesor
351 * @param processGrid two-dimensional processor grid corresponding to the parallel projHamPar
352 * @param projHamPar parallel ScaLAPACKMatrix which stores the computed projection
353 * of the Hamiltonian into the given subspace
354 * @param projOverlapPar parallel ScaLAPACKMatrix which stores the computed projection
355 * of the Overlap into the given subspace
356 */
357 void
359 const std::shared_ptr<dftfe::linearAlgebra::BLASWrapper<
360 dftfe::utils::MemorySpace::HOST>> & BLASWrapperPtr,
361 const dataTypes::number * X,
362 const unsigned int numberComponents,
363 const unsigned int numberLocalDofs,
364 const std::shared_ptr<const dftfe::ProcessGrid> &processGrid,
365 const MPI_Comm & mpiCommDomain,
366 const MPI_Comm & interBandGroupComm,
367 const dftParameters & dftParams,
370 const bool onlyHPrimePartForFirstOrderDensityMatResponse = false);
371 /**
372 * @brief Computes the projection of Hamiltonian and Overlap with only a single extraction with mixed precision.
373 * Single extraction will be beneficial in full M, PAW cases.
374 * THe projected Hamiltonain has full precision along blocks of diagonal and
375 * for states greater than Ncore THe projected Overlap will be of full
376 * precision along the diagonal.
377 * @param X Vector of Vectors containing multi-wavefunction fields
378 * @param numberComponents number of wavefunctions associated with a given node
379 * @param numberLocalDofs number of DOFs owned in the current procesor
380 * @param processGrid two-dimensional processor grid corresponding to the parallel projHamPar
381 * @param projHamPar parallel ScaLAPACKMatrix which stores the computed projection
382 * of the Hamiltonian into the given subspace
383 * @param projOverlapPar parallel ScaLAPACKMatrix which stores the computed projection
384 * of the Overlap into the given subspace
385 */
386 void
389 const std::shared_ptr<
391 & BLASWrapperPtr,
392 const dataTypes::number * X,
393 const unsigned int totalNumberComponents,
394 const unsigned int singlePrecComponents,
395 const unsigned int numberLocalDofs,
396 const std::shared_ptr<const dftfe::ProcessGrid> &processGrid,
397 const MPI_Comm & mpiCommDomain,
398 const MPI_Comm & interBandGroupComm,
399 const dftParameters & dftParams,
402 const bool onlyHPrimePartForFirstOrderDensityMatResponse = false);
403
404 } // namespace linearAlgebraOperations
405
406} // namespace dftfe
407#endif
Scalapack wrapper adapted from dealii library and extended implementation to complex datatype.
Definition scalapackWrapper.h:37
Namespace which declares the input parameters and the functions to parse them from the input paramete...
Definition dftParameters.h:35
Manager class for ELPA and ScaLAPACK.
Definition elpaScalaManager.h:38
Definition BLASWrapper.h:35
Base class for building the DFT operator and the action of operator on a vector.
Definition operator.h:43
double number
Definition dftfeDataTypes.h:44
Contains linear algebra functions used in the implementation of an eigen solver.
Definition linearAlgebraOperations.h:502
void XtHXMixedPrec(operatorDFTClass< dftfe::utils::MemorySpace::HOST > &operatorMatrix, const std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< dftfe::utils::MemorySpace::HOST > > &BLASWrapperPtr, const dataTypes::number *X, const unsigned int totalNumberComponents, const unsigned int singlePrecComponents, const unsigned int numberLocalDofs, const std::shared_ptr< const dftfe::ProcessGrid > &processGrid, const MPI_Comm &mpiCommDomain, const MPI_Comm &interBandGroupComm, const dftParameters &dftParams, dftfe::ScaLAPACKMatrix< dataTypes::number > &projHamPar, const bool onlyHPrimePartForFirstOrderDensityMatResponse=false)
Compute projection of the operator into a subspace spanned by a given orthogonal basis HProjConj=X^{T...
void rayleighRitzGEP(operatorDFTClass< dftfe::utils::MemorySpace::HOST > &operatorMatrix, const std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< dftfe::utils::MemorySpace::HOST > > &BLASWrapperPtr, elpaScalaManager &elpaScala, T *X, const unsigned int numberComponents, const unsigned int numberDofs, const MPI_Comm &mpiCommParent, const MPI_Comm &interBandGroupComm, const MPI_Comm &mpiCommDomain, std::vector< double > &eigenValues, const bool useMixedPrec, const dftParameters &dftParams)
Compute Rayleigh-Ritz projection (serial version using LAPACK, parallel version using ScaLAPACK)
void densityMatrixEigenBasisFirstOrderResponse(operatorDFTClass< dftfe::utils::MemorySpace::HOST > &operatorMatrix, const std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< dftfe::utils::MemorySpace::HOST > > &BLASWrapperPtr, T *X, const unsigned int N, const unsigned int numberLocalDofs, const MPI_Comm &mpiCommParent, const MPI_Comm &mpiCommDomain, const MPI_Comm &interBandGroupComm, const std::vector< double > &eigenValues, const double fermiEnergy, std::vector< double > &densityMatDerFermiEnergy, elpaScalaManager &elpaScala, const dftParameters &dftParams)
Compute first order response in density matrix with respect to perturbation in the Hamiltonian....
void gramSchmidtOrthogonalization(T *X, const unsigned int numberComponents, const unsigned int numberDofs, const MPI_Comm &mpiComm)
Orthogonalize given subspace using GramSchmidt orthogonalization.
unsigned int lowdenOrthogonalization(std::vector< dataTypes::number > &X, const unsigned int numberComponents, const MPI_Comm &mpiComm, const dftParameters &dftParams)
Orthogonalize given subspace using Lowden orthogonalization for double data-type (serial version usin...
void XtHX(operatorDFTClass< dftfe::utils::MemorySpace::HOST > &operatorMatrix, const std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< dftfe::utils::MemorySpace::HOST > > &BLASWrapperPtr, const dataTypes::number *X, const unsigned int numberComponents, const unsigned int numberLocalDofs, const MPI_Comm &mpiCommDomain, const MPI_Comm &interBandGroupComm, const dftParameters &dftParams, std::vector< dataTypes::number > &ProjHam)
Compute projection of the operator into a subspace spanned by a given orthogonal basis HProjConj=X^{T...
void XtOX(operatorDFTClass< dftfe::utils::MemorySpace::HOST > &operatorMatrix, const std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< dftfe::utils::MemorySpace::HOST > > &BLASWrapperPtr, const dataTypes::number *X, const unsigned int numberComponents, const unsigned int numberLocalDofs, const std::shared_ptr< const dftfe::ProcessGrid > &processGrid, const MPI_Comm &mpiCommDomain, const MPI_Comm &interBandGroupComm, const dftParameters &dftParams, dftfe::ScaLAPACKMatrix< dataTypes::number > &projOverlapPar)
Compute projection of the operator into a subspace spanned by a given orthogonal basis HProjConj=X^{T...
void computeEigenResidualNorm(operatorDFTClass< dftfe::utils::MemorySpace::HOST > &operatorMatrix, const std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< dftfe::utils::MemorySpace::HOST > > &BLASWrapperPtr, T *X, const std::vector< double > &eigenValues, const unsigned int numberComponents, const unsigned int numberDofs, const MPI_Comm &mpiCommParent, const MPI_Comm &mpiCommDomain, const MPI_Comm &interBandGroupComm, std::vector< double > &residualNorm, const dftParameters &dftParams)
Compute residual norm associated with eigenValue problem of the given operator.
void rayleighRitz(operatorDFTClass< dftfe::utils::MemorySpace::HOST > &operatorMatrix, const std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< dftfe::utils::MemorySpace::HOST > > &BLASWrapperPtr, elpaScalaManager &elpaScala, T *X, const unsigned int numberComponents, const unsigned int numberDofs, const MPI_Comm &mpiCommParent, const MPI_Comm &interBandGroupComm, const MPI_Comm &mpiCommDomain, std::vector< double > &eigenValues, const dftParameters &dftParams, const bool doCommAfterBandParal=true)
Compute Rayleigh-Ritz projection (serial version using LAPACK, parallel version using ScaLAPACK)
unsigned int pseudoGramSchmidtOrthogonalization(elpaScalaManager &elpaScala, const std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< dftfe::utils::MemorySpace::HOST > > &BLASWrapperPtr, T *X, const unsigned int numberComponents, const unsigned int numberDofs, const MPI_Comm &mpiCommParent, const MPI_Comm &interBandGroupComm, const MPI_Comm &mpiCommDomain, const bool useMixedPrec, const dftParameters &dftParams)
Orthogonalize given subspace using Pseudo-Gram-Schmidt orthogonalization (serial version using LAPACK...
void XtHXXtOX(operatorDFTClass< dftfe::utils::MemorySpace::HOST > &operatorMatrix, const std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< dftfe::utils::MemorySpace::HOST > > &BLASWrapperPtr, const dataTypes::number *X, const unsigned int numberComponents, const unsigned int numberLocalDofs, const std::shared_ptr< const dftfe::ProcessGrid > &processGrid, const MPI_Comm &mpiCommDomain, const MPI_Comm &interBandGroupComm, const dftParameters &dftParams, dftfe::ScaLAPACKMatrix< dataTypes::number > &projHamPar, dftfe::ScaLAPACKMatrix< dataTypes::number > &projOverlapPar, const bool onlyHPrimePartForFirstOrderDensityMatResponse=false)
Computes the projection of Hamiltonian and Overlap with only a single extraction. Single extraction w...
void XtHXXtOXMixedPrec(operatorDFTClass< dftfe::utils::MemorySpace::HOST > &operatorMatrix, const std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< dftfe::utils::MemorySpace::HOST > > &BLASWrapperPtr, const dataTypes::number *X, const unsigned int totalNumberComponents, const unsigned int singlePrecComponents, const unsigned int numberLocalDofs, const std::shared_ptr< const dftfe::ProcessGrid > &processGrid, const MPI_Comm &mpiCommDomain, const MPI_Comm &interBandGroupComm, const dftParameters &dftParams, dftfe::ScaLAPACKMatrix< dataTypes::number > &projHamPar, dftfe::ScaLAPACKMatrix< dataTypes::number > &projOverlapPar, const bool onlyHPrimePartForFirstOrderDensityMatResponse=false)
Computes the projection of Hamiltonian and Overlap with only a single extraction with mixed precision...
void XtOXMixedPrec(operatorDFTClass< dftfe::utils::MemorySpace::HOST > &operatorMatrix, const std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< dftfe::utils::MemorySpace::HOST > > &BLASWrapperPtr, const dataTypes::number *X, const unsigned int totalNumberComponents, const unsigned int singlePrecComponents, const unsigned int numberLocalDofs, const std::shared_ptr< const dftfe::ProcessGrid > &processGrid, const MPI_Comm &mpiCommDomain, const MPI_Comm &interBandGroupComm, const dftParameters &dftParams, dftfe::ScaLAPACKMatrix< dataTypes::number > &projOverlapPar)
Compute projection of the operator into a subspace spanned by a given orthogonal basis HProjConj=X^{T...
@ HOST
Definition MemorySpaceType.h:34
Definition pseudoPotentialToDftfeConverter.cc:34