StatMech
Loading...
Searching...
No Matches
ScalableOperator< MatrixType > Class Template Reference
Collaboration diagram for ScalableOperator< MatrixType >:
Collaboration graph

Public Member Functions

 ScalableOperator (MatrixType &&locOp, size_t dimLoc)
 
 ScalableOperator ()=default
 
MatrixType construct_globalOp (size_t L)
 
 ScalableOperator (MatrixType &&locOp, size_t dimLoc)
 
 ScalableOperator ()=default
 
MatrixType construct_globalOp (size_t L)
 

Private Types

using Scalar = typename MatrixType::Scalar
 
using Scalar = typename MatrixType::Scalar
 

Private Attributes

MatrixType m_locOp
 
size_t m_dimLoc
 
size_t m_Locality
 

Detailed Description

template<class MatrixType>
class ScalableOperator< MatrixType >
Template Parameters
MatrixType

MatrixType should have the following methods:

Member Typedef Documentation

◆ Scalar [1/2]

template<class MatrixType >
using ScalableOperator< MatrixType >::Scalar = typename MatrixType::Scalar
private

◆ Scalar [2/2]

template<class MatrixType >
using ScalableOperator< MatrixType >::Scalar = typename MatrixType::Scalar
private

Constructor & Destructor Documentation

◆ ScalableOperator() [1/4]

template<class MatrixType >
ScalableOperator< MatrixType >::ScalableOperator ( MatrixType &&  locOp,
size_t  dimLoc 
)
inline
121 : m_locOp{std::move(locOp)}, m_dimLoc{dimLoc} {
122 if(m_locOp.rows() != m_locOp.cols()) {
123 std::cerr << "Error at [" << __FILE__ << ":" << __LINE__ << "]\n\t"
124 << __PRETTY_FUNCTION__ << "\nMessage:\t locOp.rows()(" << m_locOp.rows()
125 << ") != locOp.cols()(" << locOp.cols() << "): "
126 << "local operator must be a square matrix" << std::endl;
127 std::exit(EXIT_FAILURE);
128 }
129 size_t dim = m_locOp.rows();
130 for(m_Locality = 0; dim > 1; ++m_Locality) {
131 if(dim % dimLoc != 0) {
132 std::cerr << "Error at [" << __FILE__ << ":" << __LINE__ << "]\n\t"
133 << __PRETTY_FUNCTION__ << "\nMessage:\t locOp.rows()("
134 << m_locOp.rows() << ") must be a power of dimLoc(" << dimLoc << ")"
135 << std::endl;
136 std::exit(EXIT_FAILURE);
137 }
138 dim /= dimLoc;
139 }
140 }
size_t m_Locality
Definition Ensemble.cuh:117
size_t m_dimLoc
Definition Ensemble.cuh:116
MatrixType m_locOp
Definition Ensemble.cuh:115

◆ ScalableOperator() [2/4]

template<class MatrixType >
ScalableOperator< MatrixType >::ScalableOperator ( )
default

◆ ScalableOperator() [3/4]

template<class MatrixType >
ScalableOperator< MatrixType >::ScalableOperator ( MatrixType &&  locOp,
size_t  dimLoc 
)
inline
121 : m_locOp{std::move(locOp)}, m_dimLoc{dimLoc} {
122 if(m_locOp.rows() != m_locOp.cols()) {
123 std::cerr << "Error at [" << __FILE__ << ":" << __LINE__ << "]\n\t"
124 << __PRETTY_FUNCTION__ << "\nMessage:\t locOp.rows()(" << m_locOp.rows()
125 << ") != locOp.cols()(" << locOp.cols() << "): "
126 << "local operator must be a square matrix" << std::endl;
127 std::exit(EXIT_FAILURE);
128 }
129 size_t dim = m_locOp.rows();
130 for(m_Locality = 0; dim > 1; ++m_Locality) {
131 if(dim % dimLoc != 0) {
132 std::cerr << "Error at [" << __FILE__ << ":" << __LINE__ << "]\n\t"
133 << __PRETTY_FUNCTION__ << "\nMessage:\t locOp.rows()("
134 << m_locOp.rows() << ") must be a power of dimLoc(" << dimLoc << ")"
135 << std::endl;
136 std::exit(EXIT_FAILURE);
137 }
138 dim /= dimLoc;
139 }
140 }

◆ ScalableOperator() [4/4]

template<class MatrixType >
ScalableOperator< MatrixType >::ScalableOperator ( )
default

Member Function Documentation

◆ construct_globalOp() [1/2]

template<class MatrixType >
MatrixType ScalableOperator< MatrixType >::construct_globalOp ( size_t  L)
inline
144 {
145 if(L < m_Locality) {
146 std::cerr << "Error at [" << __FILE__ << ":" << __LINE__ << "]\n\t"
147 << __PRETTY_FUNCTION__ << "\n\t L(" << L
148 << ") must not be smaller than m_Locality(" << m_Locality << ")."
149 << std::endl;
150 std::exit(EXIT_FAILURE);
151 }
152
154 int const dim = subSpaces[L].dim();
155 MatrixType res(dim, dim);
156
157 constexpr void (*kernel)(
158 Eigen::MatrixBase< std::remove_reference_t<decltype(*res.ptr())> >*,
159 Eigen::MatrixBase< std::remove_reference_t<decltype(*m_locOp.ptr())> > const*,
162 struct cudaFuncAttributes attr;
163 cuCHECK(cudaFuncGetAttributes(&attr, kernel));
164 int const nThread = min(dim, (int)sqrt(attr.maxThreadsPerBlock));
165 int const nBlock = (int)(dim % nThread == 0 ? dim / nThread : dim / nThread + 1);
166 debug_print(__func__ << ":\t subSpace.dim()=" << dim << ", nBlock=" << nBlock
167 << ", nThread=" << nThread);
168
169 auto dSubSpace = ObjectOnGPU<typename SubSpaceManager::SubHilbertSpace>(subSpaces[L]);
170 kernel<<<dim3(nBlock, nBlock, 1), dim3(nThread, nThread, 1)>>>(res.ptr(), m_locOp.ptr(),
171 dSubSpace.ptr());
172 cuCHECK(cudaDeviceSynchronize());
173 // std::cout << __func__ << ": res.data() = " << res.data() << std::endl;
174 // std::cout << __func__ << ": m_locOp\n" << m_locOp << std::endl;
175 // std::cout << __func__ << ": Result\n" << res << std::endl;
176 return res;
177 };
Definition ObjectOnGPU.cuh:149
Definition HilbertSpace.hpp:568
Definition Ensemble.cuh:17
static SubSpaceManager & get_instance()
Definition Ensemble.cuh:32
cuCHECK(cudaFuncGetAttributes(&attr, MatrixElementsInSector))
debug_print("# Determining GPU configuration.")
struct cudaFuncAttributes attr
Definition getAttributesOfMatrixElementsInSector.cpp:2
Integer_t const nBlock
Definition getAttributesOfMatrixElementsInSector.cpp:5
Integer_t const nThread
Definition getAttributesOfMatrixElementsInSector.cpp:4
__global__ void construct_globalOp_kernel(Eigen::MatrixBase< Derived1 > *dTotMat, Eigen::MatrixBase< Derived2 > const *dLocMat, SubSpace< TotalSpace, Scalar > const *subSpace)
Definition Ensemble.cuh:64

◆ construct_globalOp() [2/2]

template<class MatrixType >
MatrixType ScalableOperator< MatrixType >::construct_globalOp ( size_t  L)
inline
144 {
145 if(L < m_Locality) {
146 std::cerr << "Error at [" << __FILE__ << ":" << __LINE__ << "]\n\t"
147 << __PRETTY_FUNCTION__ << "\n\t L(" << L
148 << ") must not be smaller than m_Locality(" << m_Locality << ")."
149 << std::endl;
150 std::exit(EXIT_FAILURE);
151 }
152
154 int const dim = subSpaces[L].dim();
155 MatrixType res(dim, dim);
156
157 constexpr void (*kernel)(
158 Eigen::MatrixBase< std::remove_reference_t<decltype(*res.ptr())> >*,
159 Eigen::MatrixBase< std::remove_reference_t<decltype(*m_locOp.ptr())> > const*,
162 struct cudaFuncAttributes attr;
163 cuCHECK(cudaFuncGetAttributes(&attr, kernel));
164 int const nThread = min(dim, (int)sqrt(attr.maxThreadsPerBlock));
165 int const nBlock = (int)(dim % nThread == 0 ? dim / nThread : dim / nThread + 1);
166 debug_print(__func__ << ":\t subSpace.dim()=" << dim << ", nBlock=" << nBlock
167 << ", nThread=" << nThread);
168
169 auto dSubSpace = ObjectOnGPU<typename SubSpaceManager::SubHilbertSpace>(subSpaces[L]);
170 kernel<<<dim3(nBlock, nBlock, 1), dim3(nThread, nThread, 1)>>>(res.ptr(), m_locOp.ptr(),
171 dSubSpace.ptr());
172 cuCHECK(cudaDeviceSynchronize());
173 // std::cout << __func__ << ": res.data() = " << res.data() << std::endl;
174 // std::cout << __func__ << ": m_locOp\n" << m_locOp << std::endl;
175 // std::cout << __func__ << ": Result\n" << res << std::endl;
176 return res;
177 };

Member Data Documentation

◆ m_dimLoc

template<class MatrixType >
size_t ScalableOperator< MatrixType >::m_dimLoc
private

◆ m_Locality

template<class MatrixType >
size_t ScalableOperator< MatrixType >::m_Locality
private

◆ m_locOp

template<class MatrixType >
MatrixType ScalableOperator< MatrixType >::m_locOp
private

The documentation for this class was generated from the following files: