Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
commonParameters.cpp
Go to the documentation of this file.
1 
14 #include "commonParameters.h"
15 
17 
18 #include "IO/bridgeIO.h"
19 using Bridge::vout;
20 
21 // initialize static parameters
22 // color, spinor and space-time dimension
23 int CommonParameters::m_Nc = 3; // `const' removed. [07 May 2014]
24 const int CommonParameters::m_Nd = 4;
25 const int CommonParameters::m_Ndim = 4;
26 
27 const double CommonParameters::m_epsilon_criterion = 1.0e-16;
28 
33 
35 
41 
42 // note: obsolete. moved to MPI/Communicator_impl.
43 char CommonParameters::m_map_grid[] = "xyzt";
44 
50 
51 //CommonParameters* CommonParameters::m_instance = 0;
53 
55 
56 const std::string CommonParameters::class_name = "CommonParameters";
57 
58 //====================================================================
59 void CommonParameters::init(const std::vector<int>& lattice_size,
60  const std::vector<int>& grid_size)
61 {
62  init(lattice_size, grid_size, 3);
63 }
64 
65 
66 //====================================================================
67 void CommonParameters::init(const std::vector<int>& lattice_size,
68  const std::vector<int>& grid_size,
69  const int Nc)
70 {
71  if (m_initialized == true) {
72  vout.crucial("Error at %s: CommonParameters already initialized.\n", class_name.c_str());
73  exit(EXIT_FAILURE);
74  }
75 
76  m_Nc = Nc;
77 
78  m_Lx = lattice_size[0];
79  m_Ly = lattice_size[1];
80  m_Lz = lattice_size[2];
81  m_Lt = lattice_size[3];
82 
83  m_NPEx = grid_size[0];
84  m_NPEy = grid_size[1];
85  m_NPEz = grid_size[2];
86  m_NPEt = grid_size[3];
87 
88  if (check_parameters() == false) {
89  vout.crucial("Error at %s: check_parameters failed.\n", class_name.c_str());
90  exit(EXIT_FAILURE);
91  }
92 
94 
95  m_initialized = true;
96 }
97 
98 
99 //====================================================================
101 {
102  m_vlevel = vlevel;
103 }
104 
105 
106 //====================================================================
107 int CommonParameters::Lsize(const int dir)
108 {
109  switch (dir)
110  {
111  case 0:
112  return m_Lx;
113 
114  case 1:
115  return m_Ly;
116 
117  case 2:
118  return m_Lz;
119 
120  case 3:
121  return m_Lt;
122 
123  default:
124  vout.crucial("Error at %s: invalid argument value.\n",
125  class_name.c_str());
126  exit(EXIT_FAILURE);
127  return -1;
128  }
129 }
130 
131 
132 //====================================================================
133 int CommonParameters::Nsize(const int dir)
134 {
135  switch (dir)
136  {
137  case 0:
138  return m_Nx;
139 
140  case 1:
141  return m_Ny;
142 
143  case 2:
144  return m_Nz;
145 
146  case 3:
147  return m_Nt;
148 
149  default:
150  vout.crucial("Error at %s: invalid argument value.\n",
151  class_name.c_str());
152  exit(EXIT_FAILURE);
153  return -1;
154  }
155 }
156 
157 
158 //====================================================================
159 int CommonParameters::NPEsize(const int dir)
160 {
161  switch (dir)
162  {
163  case 0:
164  return m_NPEx;
165 
166  case 1:
167  return m_NPEy;
168 
169  case 2:
170  return m_NPEz;
171 
172  case 3:
173  return m_NPEt;
174 
175  default:
176  vout.crucial("Error at %s: invalid argument value.\n",
177  class_name.c_str());
178  exit(EXIT_FAILURE);
179  return -1;
180  }
181 }
182 
183 
184 //====================================================================
186 {
187  if (m_Ndim == 0) return false;
188 
189  if (m_Nc == 0) return false;
190 
191  if (m_Nd == 0) return false;
192 
193  if (m_Lx == 0) return false;
194 
195  if (m_Ly == 0) return false;
196 
197  if (m_Lz == 0) return false;
198 
199  if (m_Lt == 0) return false;
200 
201  m_Lvol = m_Lx * m_Ly * m_Lz * m_Lt;
202 
203  if (m_NPE == 1) {
204  // if (m_NPEx != 1 || m_NPEy != 1 || m_NPEz != 1 || m_NPEt != 1) {
205  // vout.general(m_vl,stderr, "assume NPE_mu = 1\n");
206  // }
207  m_NPEx = m_NPEy = m_NPEz = m_NPEt = 1;
208  }
209 
210  if ((m_Nx != 0) && (m_NPEx != 0) && (m_Lx != m_Nx * m_NPEx)) return false;
211 
212  if ((m_Ny != 0) && (m_NPEy != 0) && (m_Ly != m_Ny * m_NPEy)) return false;
213 
214  if ((m_Nz != 0) && (m_NPEz != 0) && (m_Lz != m_Nz * m_NPEz)) return false;
215 
216  if ((m_Nt != 0) && (m_NPEt != 0) && (m_Lt != m_Nt * m_NPEt)) return false;
217 
218  if ((m_Nx == 0) && (m_NPEx != 0)) {
219  if (m_Lx % m_NPEx != 0) return false; else m_Nx = m_Lx / m_NPEx;
220  }
221  if ((m_Ny == 0) && (m_NPEy != 0)) {
222  if (m_Ly % m_NPEy != 0) return false; else m_Ny = m_Ly / m_NPEy;
223  }
224  if ((m_Nz == 0) && (m_NPEz != 0)) {
225  if (m_Lz % m_NPEz != 0) return false; else m_Nz = m_Lz / m_NPEz;
226  }
227  if ((m_Nt == 0) && (m_NPEt != 0)) {
228  if (m_Lt % m_NPEt != 0) return false; else m_Nt = m_Lt / m_NPEt;
229  }
230 
231  if ((m_Nx != 0) && (m_NPEx == 0)) {
232  if (m_Lx % m_Nx != 0) return false; else m_NPEx = m_Lx / m_Nx;
233  }
234  if ((m_Ny != 0) && (m_NPEy == 0)) {
235  if (m_Ly % m_Ny != 0) return false; else m_NPEy = m_Ly / m_Ny;
236  }
237  if ((m_Nz != 0) && (m_NPEz == 0)) {
238  if (m_Lz % m_Nz != 0) return false; else m_NPEz = m_Lz / m_Nz;
239  }
240  if ((m_Nt != 0) && (m_NPEt == 0)) {
241  if (m_Lt % m_Nt != 0) return false; else m_NPEt = m_Lt / m_Nt;
242  }
243 
244  if ((m_NPEx != 0) && (m_NPEy != 0) && (m_NPEz != 0) && (m_NPEt != 0)) {
245  if ((m_NPE != 0) && (m_NPE != m_NPEx * m_NPEy * m_NPEz * m_NPEt)) return false;
246 
247  if (m_NPE == 0) m_NPE = m_NPEx * m_NPEy * m_NPEz * m_NPEt;
248  }
249 
250  if ((m_Nx != 0) && (m_Ny != 0) && (m_Nz != 0) && (m_Nt != 0)) {
251  if ((m_Nvol != 0) && (m_Nvol != m_Nx * m_Ny * m_Nz * m_Nt)) return false;
252 
253  if (m_Nvol == 0) m_Nvol = m_Nx * m_Ny * m_Nz * m_Nt;
254  }
255 
256  return true;
257 }
258 
259 
260 //====================================================================
262 {
263  vout.general("\n");
264  vout.general("Lattice parameters:\n");
265  vout.general(" Lx = %d, Ly = %d, Lz = %d, Lt = %d,\n",
266  m_Lx, m_Ly, m_Lz, m_Lt);
267  vout.general(" Nx = %d, Ny = %d, Nz = %d, Nt = %d,\n",
268  m_Nx, m_Ny, m_Nz, m_Nt);
269  vout.general(" NPEx = %d, NPEy = %d, NPEz = %d, NPEt = %d,\n",
271  vout.general(" Lvol = %ld, Nvol = %d, NPE = %d,\n",
272  m_Lvol, m_Nvol, m_NPE);
273  vout.general(" Ndim = %d\n", m_Ndim);
274  vout.general(" Nc = %d\n", m_Nc);
275  vout.general(" Nd = %d\n", m_Nd);
276  vout.general("\n");
277 }
278 
279 
280 //====================================================================
281 //============================================================END=====
BridgeIO vout
Definition: bridgeIO.cpp:503
static long_t m_Lvol
static const int m_Nd
void general(const char *format,...)
Definition: bridgeIO.cpp:197
static const std::string class_name
static char m_map_grid[16]
static void print_parameters()
static void init_Vlevel(Bridge::VerboseLevel vlevel)
initialization for default verbose level.
static Bridge::VerboseLevel m_vlevel
static const int m_Ndim
long long_t
definition of long for Bridge++
Definition: bridge_long.h:46
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
static bool check_parameters()
static int NPEsize(const int dir)
static int Nsize(const int dir)
VerboseLevel
Definition: bridgeIO.h:42
static bool m_initialized
static const double m_epsilon_criterion
static void init(const std::vector< int > &lattice_size, const std::vector< int > &grid_size)
initialization (Nc=3 is assumed).
static int Lsize(const int dir)