DFT-EFE
 
Loading...
Searching...
No Matches
MultivectorScratch.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2021. *
3 * The Regents of the University of Michigan and DFT-EFE developers. *
4 * *
5 * This file is part of the DFT-EFE code. *
6 * *
7 * DFT-EFE is free software: you can redistribute it and/or modify *
8 * it under the terms of the Lesser GNU General Public License as *
9 * published by the Free Software Foundation, either version 3 of *
10 * the License, or (at your option) any later version. *
11 * *
12 * DFT-EFE is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
15 * See the Lesser GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License at the top level of DFT-EFE distribution. If not, see *
19 * <https://www.gnu.org/licenses/>. *
20 ******************************************************************************/
21
22/*
23 * @author Avirup Sircar
24 */
25
26#ifndef dftefeMultivectorScratch_h
27#define dftefeMultivectorScratch_h
28
29#include <memory>
30#include <utils/TypeConfig.h>
32#include <utils/Exceptions.h>
34
35namespace dftefe
36{
37 namespace linearAlgebra
38 {
50 template <typename ValueType, utils::MemorySpace memorySpace>
52 {
53 public:
55 std::shared_ptr<MultiVector<ValueType, memorySpace>> XinBatch,
56 std::shared_ptr<MultiVector<ValueType, memorySpace>> XoutBatch)
57 : d_XinBatch(XinBatch)
58 , d_XoutBatch(XoutBatch)
59 , d_XinBatchSmall(nullptr)
60 , d_XoutBatchSmall(nullptr)
61 , d_inUse(false)
62 {}
63
64 // --- concurrent-access guard ---
65
66 void
68 {
70 !d_inUse,
71 "MultivectorScratch is already in use. Concurrent access detected.");
72 d_inUse = true;
73 }
74
75 void
77 {
78 d_inUse = false;
79 }
80
81 // --- small-batch setters (called once on first remainder batch) ---
82
83 void
85 {
87 }
88
89 void
91 {
93 }
94
95 // --- getters ---
96
97 std::shared_ptr<MultiVector<ValueType, memorySpace>>
99 {
100 return d_XinBatch;
101 }
102
103 std::shared_ptr<MultiVector<ValueType, memorySpace>>
105 {
106 return d_XoutBatch;
107 }
108
109 std::shared_ptr<MultiVector<ValueType, memorySpace>>
111 {
112 return d_XinBatchSmall;
113 }
114
115 std::shared_ptr<MultiVector<ValueType, memorySpace>>
117 {
118 return d_XoutBatchSmall;
119 }
120
121 // --- validation helpers ---
122
123 bool
125 {
126 return d_XinBatch != nullptr;
127 }
128
129 bool
131 {
132 return d_XoutBatch != nullptr;
133 }
134
135 bool
137 {
138 return d_XinBatchSmall != nullptr;
139 }
140
141 bool
143 {
144 return d_XoutBatchSmall != nullptr;
145 }
146
149 {
150 return d_XinBatch ? d_XinBatch->getNumberComponents() : 0;
151 }
152
155 {
156 return d_XoutBatch ? d_XoutBatch->getNumberComponents() : 0;
157 }
158
161 {
162 return d_XinBatchSmall ? d_XinBatchSmall->getNumberComponents() : 0;
163 }
164
165 private:
166 std::shared_ptr<MultiVector<ValueType, memorySpace>> d_XinBatch;
167 std::shared_ptr<MultiVector<ValueType, memorySpace>> d_XoutBatch;
168 std::shared_ptr<MultiVector<ValueType, memorySpace>> d_XinBatchSmall;
169 std::shared_ptr<MultiVector<ValueType, memorySpace>> d_XoutBatchSmall;
171 };
172
173 } // end of namespace linearAlgebra
174} // end of namespace dftefe
175
176#endif // dftefeMultivectorScratch_h
An class template to encapsulate a MultiVector. A MultiVector is a collection of vectors belonging t...
Definition: MultiVector.h:134
Shared scratch MultiVectors (large-batch and small-batch variants) that can be reused across Chebyshe...
Definition: MultivectorScratch.h:52
size_type getXinBatchSize() const
Definition: MultivectorScratch.h:148
void release()
Definition: MultivectorScratch.h:76
std::shared_ptr< MultiVector< ValueType, memorySpace > > getXoutBatch() const
Definition: MultivectorScratch.h:104
bool hasXoutBatch() const
Definition: MultivectorScratch.h:130
std::shared_ptr< MultiVector< ValueType, memorySpace > > d_XoutBatch
Definition: MultivectorScratch.h:167
bool d_inUse
Definition: MultivectorScratch.h:170
void acquire()
Definition: MultivectorScratch.h:67
MultivectorScratch(std::shared_ptr< MultiVector< ValueType, memorySpace > > XinBatch, std::shared_ptr< MultiVector< ValueType, memorySpace > > XoutBatch)
Definition: MultivectorScratch.h:54
std::shared_ptr< MultiVector< ValueType, memorySpace > > d_XinBatch
Definition: MultivectorScratch.h:166
void setXinBatchSmall(std::shared_ptr< MultiVector< ValueType, memorySpace > > v)
Definition: MultivectorScratch.h:84
std::shared_ptr< MultiVector< ValueType, memorySpace > > d_XoutBatchSmall
Definition: MultivectorScratch.h:169
std::shared_ptr< MultiVector< ValueType, memorySpace > > d_XinBatchSmall
Definition: MultivectorScratch.h:168
std::shared_ptr< MultiVector< ValueType, memorySpace > > getXinBatchSmall() const
Definition: MultivectorScratch.h:110
void setXoutBatchSmall(std::shared_ptr< MultiVector< ValueType, memorySpace > > v)
Definition: MultivectorScratch.h:90
bool hasXinBatchSmall() const
Definition: MultivectorScratch.h:136
std::shared_ptr< MultiVector< ValueType, memorySpace > > getXinBatch() const
Definition: MultivectorScratch.h:98
std::shared_ptr< MultiVector< ValueType, memorySpace > > getXoutBatchSmall() const
Definition: MultivectorScratch.h:116
size_type getXinBatchSmallSize() const
Definition: MultivectorScratch.h:160
size_type getXoutBatchSize() const
Definition: MultivectorScratch.h:154
bool hasXinBatch() const
Definition: MultivectorScratch.h:124
bool hasXoutBatchSmall() const
Definition: MultivectorScratch.h:142
void throwException(bool condition, std::string msg)
Definition: Exceptions.cpp:56
dealii includes
Definition: AtomFieldDataSpherical.cpp:31
std::uint64_t size_type
Definition: TypeConfig.h:9