Bridge++  Ver. 2.0.2
aindex_block_lex.h
Go to the documentation of this file.
1 
10 #ifndef QXS_AINDEX_BLOCK_LEX_INCLUDED
11 #define QXS_AINDEX_BLOCK_LEX_INCLUDED
12 
13 #include <string>
14 #include <vector>
15 
17 
18 #include "lib_alt_QXS/inline/define_vlen.h"
19 #include "lib_alt_QXS/inline/define_params.h"
21 
22 
24 
30 template<typename REALTYPE>
31 class AIndex_block_lex<REALTYPE, QXS>
32 {
33  private:
34  int m_coarse_lattice[4];
35  int m_fine_lattice[4];
36  int m_block_size[4];
37  std::vector<int> m_block_eo;
38  size_t m_coarse_nvol;
39  size_t m_fine_nvol;
41 
42  public:
43  AIndex_block_lex() { /* do nothing */ }
44 
45  AIndex_block_lex(const std::vector<int>& coarse_lattice)
46  {
47  std::vector<int> fine_lattice(4);
48  fine_lattice[0] = CommonParameters::Nx();
49  fine_lattice[1] = CommonParameters::Ny();
50  fine_lattice[2] = CommonParameters::Nz();
51  fine_lattice[3] = CommonParameters::Nt();
52  init(coarse_lattice, fine_lattice);
53  }
54 
55  AIndex_block_lex(const std::vector<int>& coarse_lattice,
56  const std::vector<int>& fine_lattice)
57  { init(coarse_lattice, fine_lattice); }
58 
59  public:
60 
61  int coarse_lattice_size(const int mu) const
62  { return m_coarse_lattice[mu]; }
63 
64  int fine_lattice_size(const int mu) const
65  { return m_fine_lattice[mu]; }
66 
67  int block_size(const int mu) const
68  { return m_block_size[mu]; }
69 
70  size_t fine_nvol() const { return m_fine_nvol; }
71 
72  size_t coarse_nvol() const { return m_coarse_nvol; }
73 
74  size_t block_nvol() const { return m_block_nvol; }
75 
76  int block_eo(const int block_idx) const
77  { return m_block_eo[block_idx]; }
78 
79  void get_coarse_coord(int& ibx, int& iby, int& ibz, int& ibt,
80  const int block_idx) const
81  {
82  int idx_tmp = block_idx;
83  ibx = idx_tmp % m_coarse_lattice[0];
84  idx_tmp = idx_tmp / m_coarse_lattice[0];
85  iby = idx_tmp % m_coarse_lattice[1];
86  idx_tmp = idx_tmp / m_coarse_lattice[1];
87  ibz = idx_tmp % m_coarse_lattice[2];
88  ibt = idx_tmp / m_coarse_lattice[2];
89  }
90 
91  // private:
92 
93  void init(const std::vector<int>& coarse_lattice,
94  const std::vector<int>& fine_lattice)
95  {
96  m_coarse_nvol = 1;
97  m_fine_nvol = 1;
98  m_block_nvol = 1;
99  for (int mu = 0; mu < 4; ++mu) {
100  m_coarse_lattice[mu] = coarse_lattice[mu];
101  m_fine_lattice[mu] = fine_lattice[mu];
102  if (m_fine_lattice[mu] % m_coarse_lattice[mu] != 0) {
103  vout.crucial("AIndex_block_lex: fine_lattice is");
104  vout.crucial(" not multiple of coarse lattice\n");
105  exit(EXIT_FAILURE);
106  }
107  m_block_size[mu] = fine_lattice[mu] / coarse_lattice[mu];
108  m_coarse_nvol *= m_coarse_lattice[mu];
109  m_fine_nvol *= m_fine_lattice[mu];
110  m_block_nvol *= m_block_size[mu];
111  }
112  // sanity check
113  {
114  int vlen = 1;
115  if (sizeof(REALTYPE) == 4) {
116  vlen = VLENS;
117  } else if (sizeof(REALTYPE) == 8) {
118  vlen = VLEND;
119  } else {
120  vout.crucial("index_block_lex_alt: unkown REALTYPE\n");
121  exit(EXIT_FAILURE);
122  }
123  if (m_coarse_nvol % vlen != 0) {
124  vout.crucial("index_block_lex_alt: bad coarse_novl (too small?), must be multiple of VLEN\n");
125  vout.crucial(" coarse_nvol=%d, coarse_lattice = %d %d %d %d\n", m_coarse_nvol, m_coarse_lattice[0], m_coarse_lattice[1], m_coarse_lattice[2], m_coarse_lattice[3]);
126  exit(EXIT_FAILURE);
127  }
128  }
129  m_block_eo.resize(m_coarse_nvol);
130  int NBx = m_coarse_lattice[0];
131  int NBy = m_coarse_lattice[1];
132  int NBz = m_coarse_lattice[2];
133  int NBt = m_coarse_lattice[3];
134  int ipex = Communicator::ipe(0);
135  int ipey = Communicator::ipe(1);
136  int ipez = Communicator::ipe(2);
137  int ipet = Communicator::ipe(3);
138  int Ieo = (NBx * ipex + NBy * ipey + NBz * ipez + NBt * ipet) % 2;
139  for (int block_idx = 0; block_idx < m_coarse_nvol; ++block_idx) {
140  int kx, ky, kz, kt;
141  get_coarse_coord(kx, ky, kz, kt, block_idx);
142  m_block_eo[block_idx] = (Ieo + kx + ky + kz + kt) % 2;
143  }
144  }
145 };
146 
147 #endif
CommonParameters::Ny
static int Ny()
Definition: commonParameters.h:106
AIndex_block_lex< REALTYPE, QXS >::block_size
int block_size(const int mu) const
Definition: aindex_block_lex.h:67
AIndex_block_lex< REALTYPE, QXS >::block_eo
int block_eo(const int block_idx) const
Definition: aindex_block_lex.h:76
CommonParameters::Nz
static int Nz()
Definition: commonParameters.h:107
AIndex_block_lex< REALTYPE, QXS >::coarse_lattice_size
int coarse_lattice_size(const int mu) const
Definition: aindex_block_lex.h:61
VLEND
#define VLEND
Definition: define_vlen.h:42
AIndex_block_lex< REALTYPE, QXS >::m_coarse_nvol
size_t m_coarse_nvol
Definition: aindex_block_lex.h:38
AIndex_block_lex< REALTYPE, QXS >::fine_lattice_size
int fine_lattice_size(const int mu) const
Definition: aindex_block_lex.h:64
VLENS
#define VLENS
Definition: define_vlen.h:41
AIndex_block_lex< REALTYPE, QXS >::AIndex_block_lex
AIndex_block_lex()
Definition: aindex_block_lex.h:43
AIndex_block_lex< REALTYPE, QXS >::AIndex_block_lex
AIndex_block_lex(const std::vector< int > &coarse_lattice)
Definition: aindex_block_lex.h:45
AIndex_block_lex
Definition: aindex_block_lex_base.h:18
AIndex_block_lex< REALTYPE, QXS >::m_block_eo
std::vector< int > m_block_eo
Definition: aindex_block_lex.h:37
CommonParameters::Nx
static int Nx()
Definition: commonParameters.h:105
AIndex_block_lex< REALTYPE, QXS >::fine_nvol
size_t fine_nvol() const
Definition: aindex_block_lex.h:70
AIndex_block_lex< REALTYPE, QXS >::init
void init(const std::vector< int > &coarse_lattice, const std::vector< int > &fine_lattice)
Definition: aindex_block_lex.h:93
CommonParameters::Nt
static int Nt()
Definition: commonParameters.h:108
AIndex_block_lex< REALTYPE, QXS >::coarse_nvol
size_t coarse_nvol() const
Definition: aindex_block_lex.h:72
AIndex_block_lex< REALTYPE, QXS >::block_nvol
size_t block_nvol() const
Definition: aindex_block_lex.h:74
AIndex_block_lex< REALTYPE, QXS >::AIndex_block_lex
AIndex_block_lex(const std::vector< int > &coarse_lattice, const std::vector< int > &fine_lattice)
Definition: aindex_block_lex.h:55
QXS
@ QXS
Definition: alt_impl.h:15
AIndex_block_lex< REALTYPE, QXS >::get_coarse_coord
void get_coarse_coord(int &ibx, int &iby, int &ibz, int &ibt, const int block_idx) const
Definition: aindex_block_lex.h:79
AIndex_block_lex< REALTYPE, QXS >::m_block_nvol
int m_block_nvol
Definition: aindex_block_lex.h:40
Communicator::ipe
static int ipe(const int dir)
logical coordinate of current proc.
Definition: communicator.cpp:105
aindex_block_lex_base.h
AIndex_block_lex< REALTYPE, QXS >::m_fine_nvol
size_t m_fine_nvol
Definition: aindex_block_lex.h:39
commonParameters.h
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512