Bridge++  Ver.2.1.3
afield.h
Go to the documentation of this file.
1 
10 #ifndef ACCEL_AFIELD_INCLUDED
11 #define ACCEL_AFIELD_INCLUDED
12 
13 #include <cstddef>
14 #include <cstdio>
15 #include <string>
16 
17 #include "lib_alt/Field/afield_base.h" // primary template
18 
19 #include "bridge_defs.h"
20 #include "bridge_complex.h"
21 #include "complexTraits.h"
24 #include "lib/Field/field.h"
25 #include "lib/IO/bridgeIO.h"
26 using Bridge::vout;
27 
29 
30 template<typename REALTYPE>
31 class AField<REALTYPE, ACCEL>
32 {
33 
34 public:
35  typedef REALTYPE real_t;
37  typedef Element_type::type element_type; // see bridge_defs.h
38 
39  static const Impl IMPL = ACCEL;
40  static const std::string class_name;
41 
42  static real_t* m_red1;
43  static real_t* m_red2;
44  static int m_num_instance;
45 
46 protected:
47  int m_nin;
48  int m_nvol;
49  int m_nex;
52 
53  int m_nvol_pad;
54  std::size_t m_nsize;
55  std::size_t m_nsize_pad;
56 
58 
59 public:
60 
63  { init(0, 0, 0, Element_type::COMPLEX); }
64 
66  AField(const int nin, const int nvol, const int nex,
67  const element_type cmpl = Element_type::COMPLEX){
68  init(nin, nvol, nex, cmpl);
69  }
70 
73  init(w.nin(), w.nvol(), w.nex(), w.field_element_type());
74  if(m_nsize > 0) copy(w);
75  }
76 
78  AField(const Field& w){
79  init(w.nin(), w.nvol(), w.nex(), w.field_element_type());
80  if(m_nsize > 0) copy(w);
81  }
82 
84  AField& operator=(const Field& w) {
85  assert(check_size(w.nin(), w.nvol(), w.nex()));
86  if(m_nsize > 0) copy(w);
87  return *this;
88  }
89 
91  AField& operator=(const AField& w) {
92  assert(check_size(w));
93  if(m_nsize > 0) copy(w);
94  return *this;
95  }
96 
98  ~AField(){ tidyup(); };
99 
100  private:
101 
103  void init(const int nin, const int nvol, const int nex,
104  const element_type cmpl);
105 
107  void tidyup();
108 
109  public:
110 
111  // resetting object.
112  void reset(const int nin, const int nvol, const int nex,
113  const element_type cmpl = Element_type::COMPLEX);
114 
116  int nin() const { return m_nin; }
117 
119  int nvol() const { return m_nvol; }
120 
122  int nex() const { return m_nex; }
123 
125  element_type field_element_type() const { return m_element_type; }
126 
128  bool check_size(const int nin, const int nvol, const int nex) const
129  {
130  bool chk = true;
131  if(m_nin != nin || m_nvol != nvol || m_nex != nex) chk = false;
132  return chk;
133  }
134 
136  bool check_size(const AField<REALTYPE, ACCEL>& w) const
137  {
138  bool chk = true;
139  if(m_nin != w.nin() || m_nvol != w.nvol() || m_nex != w.nex())
140  chk = false;
141  return chk;
142  }
143 
145  inline int size(void) const { return m_nsize; }
146 
148  real_t* ptr(int i){ return &m_field[i]; }
149 
150  //complex_t* ptr_complex(int i){ return (complex_t*)&m_field[2*i]; }
151  complex_t* ptr_complex(int i){ return (complex_t*)&m_field[i]; }
152 
154  real_t cmp(const int index) const;
155 
156  void set(const int index, const real_t a);
157 
158  void set(const real_t a);
159 
160  // ### BLAS-like methods ###
161 
162  void copy(const Field &w);
163 
164  void copy(const AField<real_t, ACCEL>& w);
165 
166  void copy(const int ex,
167  const AField<real_t, ACCEL>& w, const int ex_w);
168 
169  void axpy(const real_t, const AField<real_t, ACCEL>&);
170 
171  void axpy(const int ex, const real_t a,
172  const AField<real_t, ACCEL>& w, const int ex_w);
173 
175  void axpy(const real_t a_r, const real_t a_i,
176  const AField<real_t, ACCEL>&);
177 
179  void axpy(const int ex, const real_t a_r, const real_t a_i,
180  const AField<real_t, ACCEL>& w, const int ex_w);
181 
183  void axpy(const int ex, const complex_t a,
184  const AField<real_t, ACCEL>& w, const int ex_w);
185 
187  void axpy(const complex_t a,
188  const AField<real_t, ACCEL>& w);
189 
190  void aypx(const real_t, const AField<real_t, ACCEL>&);
191 
192  void aypx(const int ex, const real_t,
193  const AField<real_t, ACCEL>& w, const int ex_w);
194 
196  void aypx(const real_t a_r, const real_t a_i,
197  const AField<real_t, ACCEL>&);
198 
200  void aypx(const int ex, const real_t a_r, const real_t a_i,
201  const AField<real_t, ACCEL>& w, const int ex_w);
202 
204  void aypx(const complex_t a,
205  const AField<real_t, ACCEL>& w);
206 
208  void aypx(const int ex, const complex_t a,
209  const AField<real_t, ACCEL>& w, const int ex_w);
210 
211  void scal(const real_t);
212 
213  void scal(const real_t, const int ex);
214 
215  void scal(const complex_t);
216 
217  void scal(const complex_t, const int ex);
218 
220 
222  void dotc(real_t&, real_t&, const AField<real_t, ACCEL>&) const;
223 
225  real_t norm2(void) const;
226 
228  real_t norm2_host(void) const;
229 
231  void xI();
232 
234  void conjg();
235 
236  //### Methods specific to Accel implementation ###
237 
238  void set_host(const real_t a);
239 
240  real_t cmp_host(const int index) const
241  { return m_field[index]; }
242 
243  void set_host(const int index, const real_t a)
244  { m_field[index] = a; }
245 
246  void update_host() const;
247 
248  void update_device();
249 
251  int nvol_pad() const { return m_nvol_pad; }
252 
254  int size_pad() const { return m_nsize_pad; }
255 
256 };
257 
258 // copy between fields with different precisions.
259 
262 
263 
264 #endif // ACCEL_AFIELD_INCLUDED
Impl
Impl
Definition: alt_impl.h:13
AField< REALTYPE, ACCEL >::class_name
static const std::string class_name
Definition: afield.h:40
AField< REALTYPE, ACCEL >::ptr
real_t * ptr(int i)
return the address of data at given index.
Definition: afield.h:148
bridgeIO.h
AField< REALTYPE, ACCEL >::AField
AField(const AField< real_t, ACCEL > &w)
copy constructor
Definition: afield.h:72
copy
void copy(AField< double, ACCEL > &, const AField< float, ACCEL > &)
AField< REALTYPE, ACCEL >::m_nvol_pad
int m_nvol_pad
after padding.
Definition: afield.h:53
AField< REALTYPE, ACCEL >::nin
int nin() const
returning size of inner (on site) d.o.f.
Definition: afield.h:116
update_device
void update_device(AField< REALTYPE, ACCEL > &v)
Definition: afield-inc.h:33
afield_base.h
AField< REALTYPE, ACCEL >::m_nsize
std::size_t m_nsize
Definition: afield.h:54
AField< REALTYPE, ACCEL >::element_type
Element_type::type element_type
Definition: afield.h:37
AField
Definition: afield_base.h:16
AField< REALTYPE, ACCEL >::m_red2
static real_t * m_red2
Definition: afield.h:43
AField< REALTYPE, ACCEL >::field_element_type
element_type field_element_type() const
returning element_type (real or complex).
Definition: afield.h:125
Field::nex
int nex() const
Definition: field.h:128
AField< REALTYPE, ACCEL >::ptr_complex
complex_t * ptr_complex(int i)
Definition: afield.h:151
AField< REALTYPE, ACCEL >::size
int size(void) const
return the array size
Definition: afield.h:145
aypx
void aypx(const double a, Field &y, const Field &x)
aypx(y, a, x): y := a * y + x
Definition: field.cpp:510
axpy
void axpy(Field &y, const double a, const Field &x)
axpy(y, a, x): y := a * x + y
Definition: field.cpp:381
dot
double dot(const Field &y, const Field &x)
Definition: field.cpp:577
AField< REALTYPE, ACCEL >::check_size
bool check_size(const AField< REALTYPE, ACCEL > &w) const
checking size parameters
Definition: afield.h:136
AField< REALTYPE, ACCEL >::m_nin
int m_nin
Definition: afield.h:47
AField< REALTYPE, ACCEL >::cmp_host
real_t cmp_host(const int index) const
Definition: afield.h:240
update_host
void update_host(AField< REALTYPE, ACCEL > &v)
Definition: afield-inc.h:26
Field::nin
int nin() const
Definition: field.h:126
AField< REALTYPE, ACCEL >::set_host
void set_host(const int index, const real_t a)
Definition: afield.h:243
AField< REALTYPE, ACCEL >::m_red1
static real_t * m_red1
Definition: afield.h:42
AField< REALTYPE, ACCEL >::nex
int nex() const
returning size of extra d.o.f.
Definition: afield.h:122
AField< REALTYPE, ACCEL >::m_nvol
int m_nvol
Definition: afield.h:48
AField< REALTYPE, ACCEL >::m_vl
Bridge::VerboseLevel m_vl
Definition: afield.h:51
BridgeACC::conjg
void conjg(double *restrict v1, int nin, int nvol)
AField< REALTYPE, ACCEL >::check_size
bool check_size(const int nin, const int nvol, const int nex) const
checking size parameters
Definition: afield.h:128
bridge_complex.h
AField< REALTYPE, ACCEL >::size_pad
int size_pad() const
returning volume size after padding.
Definition: afield.h:254
AField< REALTYPE, ACCEL >::nvol_pad
int nvol_pad() const
returning volume size after padding.
Definition: afield.h:251
AField< REALTYPE, ACCEL >::m_nex
int m_nex
Definition: afield.h:49
AField< REALTYPE, ACCEL >::m_field
real_t * m_field
Definition: afield.h:57
field.h
Field::nvol
int nvol() const
Definition: field.h:127
dotc
dcomplex dotc(const Field &y, const Field &x)
Definition: field.cpp:713
SU_N::xI
Mat_SU_N xI(const Mat_SU_N &u)
Definition: mat_SU_N.h:586
AField< REALTYPE, ACCEL >::m_element_type
element_type m_element_type
Definition: afield.h:50
ComplexTraits
Definition: complexTraits.h:16
BridgeACC::norm2
double norm2(double *restrict v1, int nin, int nvol)
real_t
double real_t
Definition: bridgeACC_AField_double.cpp:14
Field::field_element_type
element_type field_element_type() const
Definition: field.h:129
AField< REALTYPE, ACCEL >::real_t
REALTYPE real_t
Definition: afield.h:35
ACCEL
@ ACCEL
Definition: alt_impl.h:15
AField< REALTYPE, ACCEL >::m_num_instance
static int m_num_instance
Definition: afield.h:44
Element_type::COMPLEX
@ COMPLEX
Definition: bridge_defs.h:43
AField< REALTYPE, ACCEL >::AField
AField(const int nin, const int nvol, const int nex, const element_type cmpl=Element_type::COMPLEX)
constructor
Definition: afield.h:66
AField< REALTYPE, ACCEL >::operator=
AField & operator=(const Field &w)
operator overload
Definition: afield.h:84
scal
void scal(Field &x, const double a)
scal(x, a): x = a * x
Definition: field.cpp:262
AField< REALTYPE, ACCEL >::AField
AField()
constructor without argument
Definition: afield.h:62
AField< REALTYPE, ACCEL >::~AField
~AField()
destructor
Definition: afield.h:98
AField< REALTYPE, ACCEL >::complex_t
ComplexTraits< REALTYPE >::complex_t complex_t
Definition: afield.h:36
AField< REALTYPE, ACCEL >::nvol
int nvol() const
returning size of site d.o.f.
Definition: afield.h:119
complex_t
ComplexTraits< double >::complex_t complex_t
Definition: afopr_Clover_coarse_double.cpp:23
commonParameters.h
define_params.h
AField< REALTYPE, ACCEL >::operator=
AField & operator=(const AField &w)
operator overload
Definition: afield.h:91
complexTraits.h
Field
Container of Field-type object.
Definition: field.h:46
communicator.h
Bridge::VerboseLevel
VerboseLevel
Definition: bridgeIO.h:45
AField< REALTYPE, ACCEL >::m_nsize_pad
std::size_t m_nsize_pad
after padding.
Definition: afield.h:55
AField< REALTYPE, ACCEL >
Definition: afield.h:31
bridge_defs.h
Element_type::type
type
Definition: bridge_defs.h:41
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:572
AField< REALTYPE, ACCEL >::AField
AField(const Field &w)
copy constructor
Definition: afield.h:78