DFT-FE 1.3.0-pre
Density Functional Theory With Finite-Elements
Loading...
Searching...
No Matches
MatrixFree.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (c) 2017-2022 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/**
19 * @author Gourab Panigrahi
20 *
21 */
22
23#ifndef MatrixFree_H_
24#define MatrixFree_H_
25#include <type_traits>
26#include <headers.h>
27#include <MemoryStorage.h>
28#include <BLASWrapper.h>
29#include <MatrixFreeDevice.h>
30
31#ifdef _OPENMP
32# include <omp.h>
33#else
34# define omp_get_thread_num() 0
35#endif
36
37namespace dftfe
38{
39 /**
40 * @brief MatrixFree class template. template parameter nDofsPerDim
41 * is the finite element polynomial order. nQuadPointsPerDim is the order of
42 * the Gauss quadrature rule. batchSize is the size of batch tuned to hardware
43 *
44 * @author Gourab Panigrahi
45 *
46 */
47 template <typename T,
48 dftfe::operatorList operatorID,
49 dftfe::utils::MemorySpace memorySpace,
50 bool isComplex,
51 std::uint32_t nDofsPerDim,
52 std::uint32_t nQuadPointsPerDim,
53 std::uint32_t batchSize,
54 std::uint32_t subBatchSize>
56 {
57 public:
58 /// Constructor
60 const MPI_Comm &mpi_comm,
61 const dealii::MatrixFree<3, double> *matrixFreeDataPtr,
62 const dealii::AffineConstraints<double> &constraintMatrix,
64 BLASWrapperPtr,
65 const std::uint32_t dofHandlerID,
66 const std::uint32_t quadratureID,
67 const dftfe::uInt nVectors);
68
69 /**
70 * @brief Initialize data structures for MatrixFree class
71 *
72 */
73 inline void
75
76 /**
77 * @brief Initialize Helmholtz operator coefficient
78 *
79 */
80 inline void
81 initOperatorCoeffs(T coeffHelmholtz);
82
83 /**
84 * @brief Compute Laplace operator multipled by X
85 *
86 */
87 inline void
88 computeAX(T *dst, T *src);
89
90 /**
91 * @brief Apply constraints to src vector
92 *
93 */
94 inline void
96
97 /**
98 * @brief Apply transpose of constraints to src vector and set zero on src
99 *
100 */
101 inline void
103
104 private:
105 /**
106 * @brief Initialize optimized constraints
107 *
108 */
109 void
111
112 void
113 setupConstraints(const dealii::IndexSet &indexSet);
114
115 typedef std::conditional_t<isComplex, std::complex<T>, T> DataType;
116
119
121
125
127
128 static constexpr std::uint32_t d_quadODim = nQuadPointsPerDim / 2;
129 static constexpr std::uint32_t d_quadEDim =
130 nQuadPointsPerDim % 2 == 1 ? d_quadODim + 1 : d_quadODim;
131 static constexpr std::uint32_t d_dofODim = nDofsPerDim / 2;
132 static constexpr std::uint32_t d_dofEDim =
133 nDofsPerDim % 2 == 1 ? d_dofODim + 1 : d_dofODim;
134
135 std::array<T, d_quadEDim * d_dofEDim + d_quadODim * d_dofODim>
137 std::array<T, 2 * d_quadODim * d_quadEDim>
139 std::array<T, nQuadPointsPerDim> quadratureWeights;
140
143
144 // HOST only Data Structures
145 std::vector<std::vector<dftfe::uInt>> d_constrainingNodeBuckets,
147 std::vector<std::vector<T>> d_weightMatrixList;
148 std::vector<T> d_inhomogenityList;
149
150 // Device only Data Structures
153
158
159 // Buffer for shape function values and gradients at quadrature points for
160 // SYCL. For CUDA/HIP, these are stored in constant memory in
161 // MatrixFreeDevice.
164
165 // pointer to dealii MatrixFree object
166 const dealii::MatrixFree<3, double> *d_matrixFreeDataPtr;
167
168 // pointer to dealii AffineConstraints object
169 const dealii::AffineConstraints<double> *d_constraintMatrixPtr;
170
171 // pointer to BLAS wrapper object
172 const std::shared_ptr<dftfe::linearAlgebra::BLASWrapper<memorySpace>>
174
175 std::shared_ptr<const dealii::Utilities::MPI::Partitioner>
177
178 dealii::ConditionalOStream pcout;
179 const MPI_Comm mpi_communicator;
180 const std::uint32_t n_mpi_processes;
181 const std::uint32_t this_mpi_process;
183 std::vector<MPI_Request> mpiRequestsGhost;
184 std::vector<MPI_Request> mpiRequestsCompress;
185 };
186
187} // namespace dftfe
188#endif // MatrixFree_H_
static constexpr std::uint32_t d_dofODim
Definition MatrixFree.h:131
dftfe::utils::MemoryStorage< dftfe::uInt, memorySpace > d_map
Definition MatrixFree.h:142
void constraintsDistributeTranspose(T *dst, T *src)
Apply transpose of constraints to src vector and set zero on src.
std::shared_ptr< const dealii::Utilities::MPI::Partitioner > d_singleVectorPartitioner
Definition MatrixFree.h:176
dftfe::uInt d_nGhostDofs
Definition MatrixFree.h:122
dftfe::utils::MemoryStorage< dftfe::uInt, dftfe::utils::MemorySpace::DEVICE > d_constrainedNodeBucketsDevice
Definition MatrixFree.h:155
std::array< T, 2 *d_quadODim *d_quadEDim > quadShapeFunctionGradientsAtQuadPointsEO
Definition MatrixFree.h:138
std::vector< MPI_Request > mpiRequestsGhost
Definition MatrixFree.h:183
dftfe::uInt d_localSize
Definition MatrixFree.h:123
std::vector< std::vector< dftfe::uInt > > d_constrainingNodeBuckets
Definition MatrixFree.h:145
const std::uint32_t d_nQuadsPerCell
Definition MatrixFree.h:118
std::array< T, d_quadEDim *d_dofEDim+d_quadODim *d_dofODim > nodalShapeFunctionValuesAtQuadPointsEO
Definition MatrixFree.h:136
void setupConstraints(const dealii::IndexSet &indexSet)
void init()
Initialize data structures for MatrixFree class.
std::vector< T > tempGhostStorage
Definition MatrixFree.h:182
const std::uint32_t this_mpi_process
Definition MatrixFree.h:181
static constexpr std::uint32_t d_quadEDim
Definition MatrixFree.h:129
dftfe::uInt d_nOMPThreads
Definition MatrixFree.h:124
const dealii::AffineConstraints< double > * d_constraintMatrixPtr
Definition MatrixFree.h:169
static constexpr std::uint32_t d_quadODim
Definition MatrixFree.h:128
const dftfe::uInt d_nBatch
Definition MatrixFree.h:120
const MPI_Comm mpi_communicator
Definition MatrixFree.h:179
const dftfe::uInt d_nVectors
Definition MatrixFree.h:120
std::shared_ptr< const dealii::Utilities::MPI::Partitioner > d_singleBatchPartitioner
Definition MatrixFree.h:176
std::vector< std::vector< T > > d_weightMatrixList
Definition MatrixFree.h:147
dftfe::utils::MemoryStorage< T, dftfe::utils::MemorySpace::DEVICE > d_inhomogenityListDevice
Definition MatrixFree.h:152
T d_coeffHelmholtz
Definition MatrixFree.h:126
dftfe::uInt d_nOwnedDofs
Definition MatrixFree.h:122
void computeAX(T *dst, T *src)
Compute Laplace operator multipled by X.
dftfe::utils::MemoryStorage< T, memorySpace > d_jacobianFactor
Definition MatrixFree.h:141
static constexpr std::uint32_t d_dofEDim
Definition MatrixFree.h:132
std::vector< T > d_inhomogenityList
Definition MatrixFree.h:148
dftfe::uInt d_nCells
Definition MatrixFree.h:122
const std::uint32_t d_nDofsPerCell
Definition MatrixFree.h:117
dealii::ConditionalOStream pcout
Definition MatrixFree.h:178
dftfe::uInt d_ghostSize
Definition MatrixFree.h:123
const std::uint32_t d_quadratureID
Definition MatrixFree.h:117
std::conditional_t< isComplex, std::complex< T >, T > DataType
Definition MatrixFree.h:115
std::array< T, nQuadPointsPerDim > quadratureWeights
Definition MatrixFree.h:139
const std::uint32_t d_dofHandlerID
Definition MatrixFree.h:117
const std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< memorySpace > > d_BLASWrapperPtr
Definition MatrixFree.h:173
std::vector< T > tempCompressStorage
Definition MatrixFree.h:182
dftfe::utils::MemoryStorage< T, dftfe::utils::MemorySpace::DEVICE > shapeBufferDevice
Definition MatrixFree.h:163
std::vector< std::vector< dftfe::uInt > > d_constrainedNodeBuckets
Definition MatrixFree.h:146
dftfe::uInt d_ghostBlockSize
Definition MatrixFree.h:123
dftfe::uInt d_localBlockSize
Definition MatrixFree.h:123
const dealii::MatrixFree< 3, double > * d_matrixFreeDataPtr
Definition MatrixFree.h:166
const std::uint32_t n_mpi_processes
Definition MatrixFree.h:180
dftfe::utils::MemoryStorage< T, dftfe::utils::MemorySpace::DEVICE > d_weightMatrixListDevice
Definition MatrixFree.h:152
dftfe::utils::MemoryStorage< dftfe::uInt, dftfe::utils::MemorySpace::DEVICE > d_constrainingNodeBucketsDevice
Definition MatrixFree.h:155
dftfe::utils::MemoryStorage< dftfe::uInt, dftfe::utils::MemorySpace::DEVICE > d_constrainedNodeOffsetDevice
Definition MatrixFree.h:156
void initOperatorCoeffs(T coeffHelmholtz)
Initialize Helmholtz operator coefficient.
std::vector< MPI_Request > mpiRequestsCompress
Definition MatrixFree.h:184
void initConstraints()
Initialize optimized constraints.
dftfe::uInt d_nRelaventDofs
Definition MatrixFree.h:122
MatrixFree(const MPI_Comm &mpi_comm, const dealii::MatrixFree< 3, double > *matrixFreeDataPtr, const dealii::AffineConstraints< double > &constraintMatrix, const std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< memorySpace > > BLASWrapperPtr, const std::uint32_t dofHandlerID, const std::uint32_t quadratureID, const dftfe::uInt nVectors)
Constructor.
dftfe::utils::MemoryStorage< dftfe::uInt, dftfe::utils::MemorySpace::DEVICE > d_weightMatrixOffsetDevice
Definition MatrixFree.h:157
dftfe::utils::MemoryStorage< dftfe::uInt, dftfe::utils::MemorySpace::DEVICE > d_constrainingNodeOffsetDevice
Definition MatrixFree.h:156
void constraintsDistribute(T *src)
Apply constraints to src vector.
Definition BLASWrapper.h:35
Definition MemoryStorage.h:33
MemorySpace
Definition MemorySpaceType.h:33
Definition pseudoPotentialToDftfeConverter.cc:34
std::uint32_t uInt
Definition TypeConfig.h:10
operatorList
Definition MatrixFreeDevice.h:37