Bridge++  Ver. 2.0.2
afield.h
Go to the documentation of this file.
1 
10 #ifndef QXS_AFIELD_INCLUDED
11 #define QXS_AFIELD_INCLUDED
12 
13 #include <cstddef>
14 #include <cstdio>
15 #include <vector>
16 #include <string>
17 
18 #include "lib_alt/Field/afield_base.h" // primary template
19 
20 #include "bridge_defs.h"
21 #include "bridge_complex.h"
22 #include "complexTraits.h"
23 
26 #include "lib/Field/field.h"
27 #include "lib/IO/bridgeIO.h"
28 using Bridge::vout;
29 
31 #include "lib_alt_QXS/inline/define_params.h"
32 #include "aligned_allocator_impl.h"
33 
34 template<typename REALTYPE>
35 class AField<REALTYPE, QXS>
36 {
37  public:
38  typedef REALTYPE real_t;
40  typedef Element_type::type element_type; // see bridge_defs.h
41  static const Impl IMPL = QXS;
42  template<typename T>
44  static const std::string class_name;
45 
46  protected:
47  int m_nin;
48  int m_nvol;
49  int m_nex;
52 
53  std::size_t m_nsize;
54  std::size_t m_nsize_off; // size with offset
55  std::size_t m_nsizev; // m_nsize/VLEN
56  std::size_t m_offset;
57  std::vector<real_t, aligned_allocator<real_t> > m_field;
58 
60  int m_size_rem;
61  std::size_t m_size_quot;
62  std::vector<real_t, aligned_allocator<real_t> > m_reduce;
63 
64  public:
66  AField() { init(0, 0, 0, Element_type::COMPLEX); }
67 
69  AField(const int nin, const int nvol, const int nex,
71  { init(nin, nvol, nex, cmpl); }
72 
75  {
76  init(w.nin(), w.nvol(), w.nex(), w.field_element_type());
77  copy(w);
78  }
79 
81  AField(const Field& w)
82  {
83  init(w.nin(), w.nvol(), w.nex(), w.field_element_type());
84  copy(w);
85  }
86 
88  ~AField() { tidyup(); }
89 
90  private:
91  // void init(const size_t nsize);
92  void init(const int nin, const int nvol, const int nex,
93  const element_type cmpl);
94 
95  void tidyup();
96 
97  public:
98 
99  // resetting object.
100  void reset(const int nin, const int nvol, const int nex,
101  const element_type cmpl = Element_type::COMPLEX)
102  {
103  if (check_size(nin, nvol, nex) && (m_element_type == cmpl)) return;
104 
105  init(nin, nvol, nex, cmpl);
106  }
107 
109  int nin() const { return m_nin; }
110 
112  int nvol() const { return m_nvol; }
113 
115  int nex() const { return m_nex; }
116 
118  element_type field_element_type() const { return m_element_type; }
119 
121  bool check_size(const int nin, const int nvol, const int nex) const
122  {
123  bool chk = true;
124  if ((m_nin != nin) || (m_nvol != nvol) || (m_nex != nex)) chk = false;
125  return chk;
126  }
127 
128  bool check_size(const AField<REALTYPE, QXS>& w) const
129  {
130  bool chk = true;
131  if ((m_nin != w.nin()) || (m_nvol != w.nvol()) || (m_nex != w.nex()))
132  chk = false;
133  return chk;
134  }
135 
137  inline real_t& e(const int index)
138  { return m_field[m_offset + index]; }
139 
141  inline int size(void) const { return m_nsize; }
142 
144  inline int ntot(void) const { return m_nsize; }
145 
146  real_t *ptr(int i) { return &m_field[m_offset + i]; }
147 
148  const real_t *ptr(int i) const { return &m_field[m_offset + i]; }
149 
151  { return (complex_t *)&m_field[m_offset + 2 * i]; }
152 
153  const complex_t *ptr_complex(int i) const
154  { return (const complex_t *)&m_field[m_offset + 2 * i]; }
155 
157  real_t cmp(const int index) const
158  { return m_field[m_offset + index]; }
159 
160  void set(const int index, const real_t a)
161  { m_field[m_offset + index] = a; }
162 
163  void set(const real_t a);
164 
165  void copy(const Field& w);
166 
167  void copy(const AField<real_t, QXS>& w);
168 
169  void copy(const int ex,
170  const AField<real_t, QXS>& w, const int ex_w);
171 
173 
174  /*
175  void copy(const int index,
176  const AField<real_t, QXS>& w, const int index_w, const int size);
177  */
178 
179  void axpy(const real_t, const AField<real_t, QXS>&);
180 
181  void axpy(const int ex, const real_t a,
182  const AField<real_t, QXS>& w, const int ex_w);
183 
184  void axpy(const int ex, const real_t ar, const real_t ai,
185  const AField<real_t, QXS>& w, const int ex_w);
186 
187  void axpy(const real_t ar, const real_t ai,
188  const AField<real_t, QXS>& w);
189 
190  void aypx(const int ex, const real_t ar, const real_t ai,
191  const AField<real_t, QXS>& w, const int ex_w);
192 
193  void aypx(const real_t ar, const real_t ai,
194  const AField<real_t, QXS>& w);
195 
196 
198  void axpy(const int index, const real_t a,
199  const AField<real_t, QXS>& w, const int index_w,
200  const int size);
201 
202  void aypx(const real_t, const AField<real_t, QXS>&);
203 
204  void scal(const real_t);
205 
206  void scal(const real_t, const real_t);
207 
208  real_t dot(const AField<real_t, QXS>&) const;
209 
210  void dotc(real_t&, real_t&, const AField<real_t, QXS>&) const;
211 
212  real_t norm2(void) const;
213 
215 };
216 
217 #endif
Impl
Impl
Definition: alt_impl.h:13
alignment_size_qxs.h
AField< REALTYPE, QXS >::nex
int nex() const
returning size of extra d.o.f.
Definition: afield.h:115
bridgeIO.h
AField< REALTYPE, QXS >::ptr
const real_t * ptr(int i) const
Definition: afield.h:148
AField< REALTYPE, QXS >::ptr
real_t * ptr(int i)
Definition: afield.h:146
AField< REALTYPE, QXS >::m_size_quot
std::size_t m_size_quot
nsize/m_size_unit
Definition: afield.h:61
AField< REALTYPE, QXS >::complex_t
ComplexTraits< REALTYPE >::complex_t complex_t
Definition: afield.h:39
AField< REALTYPE, QXS >
Definition: afield.h:35
AField< REALTYPE, QXS >::m_nin
int m_nin
Definition: afield.h:47
afield_base.h
AField
Definition: afield_base.h:16
AField< REALTYPE, QXS >::nvol
int nvol() const
returning size of site d.o.f.
Definition: afield.h:112
AField< REALTYPE, QXS >::size
int size(void) const
return the array size
Definition: afield.h:141
Field::nex
int nex() const
Definition: field.h:128
AField< REALTYPE, QXS >::element_type
Element_type::type element_type
Definition: afield.h:40
aypx
void aypx(const double a, Field &y, const Field &x)
aypx(y, a, x): y := a * y + x
Definition: field.cpp:509
AField< REALTYPE, QXS >::m_element_type
element_type m_element_type
Definition: afield.h:50
AField< REALTYPE, QXS >::m_nsizev
std::size_t m_nsizev
Definition: afield.h:55
axpy
void axpy(Field &y, const double a, const Field &x)
axpy(y, a, x): y := a * x + y
Definition: field.cpp:380
dot
double dot(const Field &y, const Field &x)
Definition: field.cpp:576
aligned_allocator_impl.h
allocator with alignment
AField< REALTYPE, QXS >::ptr_complex
const complex_t * ptr_complex(int i) const
Definition: afield.h:153
dotc_and_norm2
void dotc_and_norm2(dcomplex &yx, double &y2, double &x2, const Field &y, const Field &x)
Definition: field.cpp:806
real_t
double real_t
Definition: bridgeQXS_Clover_coarse_double.cpp:16
norm2
REALTYPE norm2(const AField< REALTYPE, QXS > &v)
Definition: afield-inc.h:453
AField< REALTYPE, QXS >::m_offset
std::size_t m_offset
Definition: afield.h:56
Field::nin
int nin() const
Definition: field.h:126
AField< REALTYPE, QXS >::m_nsize
std::size_t m_nsize
Definition: afield.h:53
copy
void copy(Field &y, const Field &x)
copy(y, x): y = x
Definition: field.cpp:212
AField< REALTYPE, QXS >::AField
AField(const Field &w)
copy constructor
Definition: afield.h:81
AField< REALTYPE, QXS >::AField
AField(const AField< real_t, QXS > &w)
copy constructor
Definition: afield.h:74
bridge_complex.h
AField< REALTYPE, QXS >::e
real_t & e(const int index)
reference of data element. to be discarded.
Definition: afield.h:137
AField< REALTYPE, QXS >::AField
AField(const int nin, const int nvol, const int nex, const element_type cmpl=Element_type::COMPLEX)
constructor
Definition: afield.h:69
AField< REALTYPE, QXS >::~AField
~AField()
destructor
Definition: afield.h:88
AField< REALTYPE, QXS >::field_element_type
element_type field_element_type() const
returning element_type (real or complex).
Definition: afield.h:118
field.h
Field::nvol
int nvol() const
Definition: field.h:127
dotc
dcomplex dotc(const Field &y, const Field &x)
Definition: field.cpp:712
ComplexTraits
Definition: complexTraits.h:16
AField< REALTYPE, QXS >::m_field
std::vector< real_t, aligned_allocator< real_t > > m_field
Definition: afield.h:57
AField< REALTYPE, QXS >::check_size
bool check_size(const int nin, const int nvol, const int nex) const
checking size parameters.
Definition: afield.h:121
Field::field_element_type
element_type field_element_type() const
Definition: field.h:129
AField< REALTYPE, QXS >::real_t
REALTYPE real_t
Definition: afield.h:38
AField< REALTYPE, QXS >::reset
void reset(const int nin, const int nvol, const int nex, const element_type cmpl=Element_type::COMPLEX)
Definition: afield.h:100
QXS
@ QXS
Definition: alt_impl.h:15
AField< REALTYPE, QXS >::m_reduce
std::vector< real_t, aligned_allocator< real_t > > m_reduce
array for reduction
Definition: afield.h:62
AField< REALTYPE, QXS >::m_size_unit
int m_size_unit
unit of reduction
Definition: afield.h:59
AField< REALTYPE, QXS >::m_size_rem
int m_size_rem
nsize % m_size_unit
Definition: afield.h:60
Element_type::COMPLEX
@ COMPLEX
Definition: bridge_defs.h:43
AField< REALTYPE, QXS >::ptr_complex
complex_t * ptr_complex(int i)
Definition: afield.h:150
AField< REALTYPE, QXS >::AField
AField()
constructor without argument
Definition: afield.h:66
AField< REALTYPE, QXS >::set
void set(const int index, const real_t a)
Definition: afield.h:160
scal
void scal(Field &x, const double a)
scal(x, a): x = a * x
Definition: field.cpp:261
AField< REALTYPE, QXS >::m_nex
int m_nex
Definition: afield.h:49
aligned_allocator_offset_impl
Definition: aligned_allocator_impl.h:95
complex_t
ComplexTraits< double >::complex_t complex_t
Definition: afopr_Clover_coarse_double.cpp:23
commonParameters.h
AField< REALTYPE, QXS >::m_nvol
int m_nvol
Definition: afield.h:48
AField< REALTYPE, QXS >::m_nsize_off
std::size_t m_nsize_off
Definition: afield.h:54
AField< REALTYPE, QXS >::check_size
bool check_size(const AField< REALTYPE, QXS > &w) const
Definition: afield.h:128
complexTraits.h
AField< REALTYPE, QXS >::ntot
int ntot(void) const
return the array size
Definition: afield.h:144
Field
Container of Field-type object.
Definition: field.h:46
communicator.h
Bridge::VerboseLevel
VerboseLevel
Definition: bridgeIO.h:42
AField< REALTYPE, QXS >::m_vl
Bridge::VerboseLevel m_vl
Definition: afield.h:51
AField< REALTYPE, QXS >::nin
int nin() const
returning size of inner (on site) d.o.f.
Definition: afield.h:109
AField< REALTYPE, QXS >::cmp
real_t cmp(const int index) const
reference of data element
Definition: afield.h:157
bridge_defs.h
AField< REALTYPE, QXS >::class_name
static const std::string class_name
Definition: afield.h:44
Element_type::type
type
Definition: bridge_defs.h:41
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512