PSCF v1.5.0
cpp/BackendArray.h
1#ifndef PSCF_BACKEND_ARRAY_CP_H
2#define PSCF_BACKEND_ARRAY_CP_H
3
4/*
5* Util Package - C++ Utilities for Scientific Computation
6*
7* Copyright 2010 - 2017, David Morse (morse012@um.edu) and co-authors
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "FftwDRArray.h" // base class
12#include "CPT.h" // template argument
13
14// Forward declaration
15namespace Pscf {
16 template <typename Data, typename T> class HostSendArray;
17}
18
19namespace Pscf {
20
21 using namespace Util;
22
23 // Declare primary template
24 template <typename Data, typename T> class BackendArray;
25
81 template <typename Data>
82 class BackendArray<Data, CPT> : public FftwDRArray<Data>
83 {
84
85 public:
86
87 using typename FftwDRArray<Data>::ValueType;
88
93
94 // Default constructor
95 BackendArray() = default;
96
102 BackendArray(int capacity);
103
104 // Copy constructor.
105 BackendArray(BackendArray<Data,CPT> const & other) = default;
106
107 // Destructor.
108 ~BackendArray() override = default;
109
110 // Assignment.
111 BackendArray<Data,CPT>&
112 operator = (BackendArray<Data,CPT> const&) = default;
113
132 BackendArray<Data,CPT>& operator = (HostSendArray<Data,CPT> const & other);
133
134 // Inherited public function (to prevent hiding)
135 using FftwDRArray<Data>::operator =;
136
137 };
138
139 // Explicit instantiation declarations
140 extern template class BackendArray<double,CPT>;
141 extern template class BackendArray<fftw_complex,CPT>;
142
143} // namespace Pscf
144
145#include "HostSendArray.h"
146namespace Pscf {
147
148 /*
149 * Allocating constructor.
150 */
151 template <typename Data>
152 BackendArray<Data,CPT>::BackendArray(int capacity)
153 : FftwDRArray<Data>(capacity)
154 {}
155
156 /*
157 * Check for a pre-existing association with a HostSendArray.
158 */
159 template <typename Data>
161 BackendArray<Data,CPT>::operator = (HostSendArray<Data,CPT> const & other)
162 {
164 UTIL_CHECK(other.isAllocated());
165 UTIL_CHECK(Array<Data>::cArray() == other.cArray());
166 UTIL_CHECK(Array<Data>::capacity() == other.capacity());
167 return *this;
168 }
169
170}
171#endif
CPT BackendIdClass
Backend identifier class typename aliase.
Backend identifier class for the C++ serial CPU backend.
Definition CPT.h:32
Data ValueType
Data type of each array element.
Definition FftwDRArray.h:79
FftwDRArray()
Default constructor.
Data * cArray()
Return a pointer to the underlying C array (non-const data).
Definition Array.h:222
int capacity() const
Return allocated size.
Definition Array.h:250
bool isAllocated() const
Does this array have associated data?
Definition Array.h:236
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
PSCF package top-level namespace.
Utility classes for scientific computation.