PSCF v1.4.0
cuda/RField.h
1#ifndef PRDC_CUDA_R_FIELD_H
2#define PRDC_CUDA_R_FIELD_H
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2025, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <pscf/cuda/DeviceArray.h> // base class template
12#include <pscf/cuda/cudaTypes.h> // base class argument
13#include <pscf/math/IntVec.h> // member
14
15#include <pscf/cuda/HostDArray.h>
16#include <util/global.h>
17
18namespace Pscf {
19namespace Prdc {
20namespace Cuda {
21
22 using namespace Util;
23
31 template <int D>
32 class RField : public DeviceArray<cudaReal>
33 {
34
35 public:
36
40 RField();
41
50
58 RField(RField<D> const& other);
59
65 virtual ~RField();
66
74 void allocate(IntVec<D> const & meshDimensions);
75
85 void associate(DeviceArray<cudaReal>& arr, int beginId,
87
101 RField<D>& operator = (const RField<D>& other);
102
115
119 IntVec<D> const & meshDimensions() const;
120
127 template <class Archive>
128 void serialize(Archive& ar, const unsigned int version);
129
130 private:
131
132 // Vector containing number of grid points in each direction.
133 IntVec<D> meshDimensions_;
134
135 // Make private to prevent allocation without mesh dimensions.
137
138 // Make private to prevent association without mesh dimensions.
140
141 // Make private to prevent assignment without mesh dimensions.
142 using DeviceArray<cudaReal>::operator=;
143
144 };
145
146 /*
147 * Return mesh dimensions by constant reference.
148 */
149 template <int D>
151 { return meshDimensions_; }
152
153 /*
154 * Serialize a Field to/from an Archive.
155 */
156 template <int D>
157 template <class Archive>
158 void RField<D>::serialize(Archive& ar, const unsigned int version)
159 {
160 int capacity;
161 if (Archive::is_saving()) {
163 }
164 ar & capacity;
165 if (Archive::is_loading()) {
166 if (!isAllocated()) {
167 if (capacity > 0) {
169 }
170 } else {
171 if (capacity != capacity_) {
172 UTIL_THROW("Inconsistent Field capacities");
173 }
174 }
175 }
176
177 if (isAllocated()) {
179 tempData = this; // copy this object's data from device to host
180 for (int i = 0; i < capacity_; ++i) {
181 ar & tempData[i];
182 }
183 }
184 ar & meshDimensions_;
185 }
186
187 #ifndef PRDC_CUDA_R_FIELD_TPP
188 extern template class RField<1>;
189 extern template class RField<2>;
190 extern template class RField<3>;
191 #endif
192
193}
194}
195}
196#endif
Template for dynamic array stored in host CPU memory.
Definition HostDArray.h:41
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition IntVec.h:27
Field of real values on a regular mesh, allocated on a GPU device.
Definition cuda/RField.h:33
RField()
Default constructor.
void associate(DeviceArray< cudaReal > &arr, int beginId, IntVec< D > const &meshDimensions)
Associate this object with a slice of another DeviceArray.
void serialize(Archive &ar, const unsigned int version)
Serialize a Field to/from an Archive.
void allocate(IntVec< D > const &meshDimensions)
Allocate the underlying C array for data on a regular mesh.
RField< D > & operator=(const RField< D > &other)
Assignment operator, assignment from another RField<D>.
IntVec< D > const & meshDimensions() const
Return mesh dimensions by constant reference.
virtual ~RField()
Destructor.
File containing preprocessor macros for error handling.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition global.h:49
Fields, FFTs, and utilities for periodic boundary conditions (CUDA).
Definition CField.cu:12
Periodic fields and crystallography.
Definition complex.cpp:11
PSCF package top-level namespace.
cufftDoubleReal cudaReal
Real number type used in CPU code that uses FFTW.
Definition cudaTypes.h:35