Bridge++  Version 1.6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
polyakovLoop.cpp
Go to the documentation of this file.
1 
14 #include "polyakovLoop.h"
16 
17 const std::string PolyakovLoop::class_name = "PolyakovLoop";
18 
19 //====================================================================
21 {
22  m_filename_output = params.get_string("filename_output");
23  if (m_filename_output.empty()) {
24  m_filename_output = "stdout";
25  }
26 
27  const string str_vlevel = params.get_string("verbose_level");
28  m_vl = vout.set_verbose_level(str_vlevel);
29 
30 #if 0
31  //- fetch and check input parameters
32  int Nspc_size, Ntype;
33 
34  int err = 0;
35  err += params.fetch_int("spatial_correlator_size", Nspc_size);
36  err += params.fetch_int("number_of_correlator_type", Ntype);
37 
38  if (err) {
39  vout.crucial(m_vl, "Error at %s: input parameter not found.\n", class_name.c_str());
40  exit(EXIT_FAILURE);
41  }
42 
43 
44  set_parameters(Nspc_size, Ntype);
45 #endif
46 }
47 
48 
49 //====================================================================
50 void PolyakovLoop::set_parameters(const int Nspc_size, const int Ntype)
51 {
52 #if 0
53  //- print input parameters
54  vout.general(m_vl, "Polyakov loop measurement:\n");
55  vout.general(m_vl, " Nspc_size = %d\n", Nspc_size);
56  vout.general(m_vl, " Ntype = %d\n", Ntype);
57 
58  //- range check
59  int err = 0;
60  err += ParameterCheck::non_negative(Nspc_size);
61  err += ParameterCheck::non_negative(Ntype);
62 
65  if (Ntype > 6) ++err;
66 
67  if (err) {
68  vout.crucial(m_vl, "Error at %s: parameter range check failed.\n", class_name.c_str());
69  exit(EXIT_FAILURE);
70  }
71 
72  //- store values
73  m_Nspc_size = Nspc_size;
74  m_Ntype = Ntype;
75 
76 
77  //- post-process
78  m_Nx_ext = CommonParameters::Nx() + m_Nspc_size + 1;
79  m_Ny_ext = CommonParameters::Ny() + m_Nspc_size + 1;
80  m_Nz_ext = CommonParameters::Nz() + m_Nspc_size + 1;
81  m_Nt_ext = 1;
82  m_Nvol_ext = m_Nx_ext * m_Ny_ext * m_Nz_ext * m_Nt_ext;
83 
86  m_Nmax[0] = Nspc_size;
87  m_Nmax[1] = Nspc_size;
88  m_Nmax[2] = Nspc_size / 2;
89  m_Nmax[3] = Nspc_size;
90  m_Nmax[4] = Nspc_size / 2;
91  m_Nmax[5] = Nspc_size / 2;
92 #endif
93 }
94 
95 
96 //====================================================================
98 {
99  const int Ndim = CommonParameters::Ndim();
100 
101  assert(Ndim == 4);
102 
103  m_filename_output = "stdout";
104 
105  const int Nx = CommonParameters::Nx();
106  const int Ny = CommonParameters::Ny();
107  const int Nz = CommonParameters::Nz();
108  const int Nvol_spc = Nx * Ny * Nz;
109 
110  m_P.reset(Nvol_spc, 1);
111  m_Pcp1.reset(Nvol_spc, 1);
112  m_Pcp2.reset(Nvol_spc, 1);
113 
114 #if 0
115  m_Ntype_max = 6;
116  const int Ndim_spc = Ndim - 1;
117 
118  m_Nunit.resize(m_Ntype_max);
119  m_Nmax.resize(m_Ntype_max);
120 
121  for (int i = 0; i < m_Ntype_max; ++i) {
122  m_Nunit[i].resize(Ndim_spc);
123  }
124 
125  // The following setting explicitly depends on the definition
126  // of unit vectors.
127  assert(m_Ntype_max >= 6);
128 
129  m_Nunit[0][0] = 1;
130  m_Nunit[0][1] = 0;
131  m_Nunit[0][2] = 0;
132 
133  m_Nunit[1][0] = 1;
134  m_Nunit[1][1] = 1;
135  m_Nunit[1][2] = 0;
136 
137  m_Nunit[2][0] = 2;
138  m_Nunit[2][1] = 1;
139  m_Nunit[2][2] = 0;
140 
141  m_Nunit[3][0] = 1;
142  m_Nunit[3][1] = 1;
143  m_Nunit[3][2] = 1;
144 
145  m_Nunit[4][0] = 2;
146  m_Nunit[4][1] = 1;
147  m_Nunit[4][2] = 1;
148 
149  m_Nunit[5][0] = 2;
150  m_Nunit[5][1] = 2;
151  m_Nunit[5][2] = 1;
152 #endif
153 }
154 
155 
156 //====================================================================
158 {
159  dcomplex ploop;
160 
161 #pragma omp parallel
162  {
163  calc_ploop(ploop, U);
164  }
165 
166  std::ostream& log_file_previous = vout.getStream();
167  std::ofstream log_file;
168 
169  if (m_filename_output != "stdout") {
170  log_file.open(m_filename_output.c_str(), std::ios::app);
171  vout.init(log_file);
172  }
173 
174  vout.general(m_vl, "PolyakovLoop(Re,Im) = %20.16e %20.16e\n", real(ploop), imag(ploop));
175 
176  if (m_filename_output != "stdout") {
177  log_file.close();
178  vout.init(log_file_previous);
179  }
180 
181  return ploop;
182 }
183 
184 
185 //====================================================================
186 void PolyakovLoop::calc_ploop(dcomplex& ploop, const Field_G& U)
187 {
188  const int Nc = CommonParameters::Nc();
189  const int Ndim = CommonParameters::Ndim();
190 
191  const int Nx = CommonParameters::Nx();
192  const int Ny = CommonParameters::Ny();
193  const int Nz = CommonParameters::Nz();
194  const int Nt = CommonParameters::Nt();
195 
196  const int Nvol = U.nvol();
197  assert(Nvol == Nx * Ny * Nz * Nt);
198 
199  const int Nvol_spc = m_P.nvol();
200  assert(Nvol_spc == Nx * Ny * Nz);
201 
202  const Index_lex index;
203  const Index_lex index_spc(Nx, Ny, Nz, 1);
204 
205  const int Nthread = ThreadManager_OpenMP::get_num_threads();
206  const int i_thread = ThreadManager_OpenMP::get_thread_id();
207 
208  if (Nthread > Nvol_spc) {
209  vout.crucial(m_vl, "Error at %s: Too large Nthread = %d\n", class_name.c_str(), Nthread);
210  // exit(EXIT_FAILURE);
211  }
212 
213  const int Ntask = Nvol_spc / Nthread;
214 
215  if (Ntask * Nthread != Nvol_spc) {
216  vout.crucial(m_vl, "Error at %s: Nvol_spc = %d does not match Nthread = %d\n",
217  class_name.c_str(), Nvol_spc, Nthread);
218  exit(EXIT_FAILURE);
219  }
220 
221  const int is = Nvol_spc * i_thread / Nthread;
222  const int ns = Nvol_spc * (i_thread + 1) / Nthread - is;
223 
224  m_Ut.setpart_ex(0, U, Ndim - 1);
225 
226  //- Definition of local Polyakov loops
227  const int t = 0;
228 
229  // for (int z = 0; z < Nz; ++z)
230  // for (int y = 0; y < Ny; ++y)
231  // for (int x = 0; x < Nx; ++x) {
232  // int site2 = index_spc.site(x, y, z, 0);
233  for (int site2 = is; site2 < is + ns; ++site2) {
234  int x = site2 % Nx;
235  int y = (site2 % (Nx * Ny) - x) / Nx;
236  int z = (site2 - Nx * y - x) / (Nx * Ny);
237 
238  int site = index.site(x, y, z, t);
239 #pragma omp barrier
240 
241  Mat_SU_N utmp1(Nc);
242  m_Ut.mat(utmp1, site, 0);
243 #pragma omp barrier
244 
245  m_P.set_mat(site2, 0, utmp1);
246  }
247 
248 
249  for (int t = 1; t < Nt; ++t) {
250  // for (int z = 0; z < Nz; ++z)
251  // for (int y = 0; y < Ny; ++y)
252  // for (int x = 0; x < Nx; ++x) {
253  // int site2 = index_spc.site(x, y, z, 0);
254  for (int site2 = is; site2 < is + ns; ++site2) {
255  int x = site2 % Nx;
256  int y = (site2 % (Nx * Ny) - x) / Nx;
257  int z = (site2 - Nx * y - x) / (Nx * Ny);
258 
259  int site = index.site(x, y, z, t);
260 #pragma omp barrier
261 
262  Mat_SU_N utmp1(Nc);
263  m_Ut.mat(utmp1, site, 0);
264 
265  Mat_SU_N utmp2(Nc);
266  m_P.mat(utmp2, site2, 0);
267 #pragma omp barrier
268 
269  Mat_SU_N utmp3(Nc);
270  utmp3.mult_nn(utmp2, utmp1);
271 #pragma omp barrier
272 
273  m_P.set_mat(site2, 0, utmp3);
274  }
275  }
276 
277 
278  //- global Polyakov loops
279  const int Npe_t = Communicator::npe(Ndim - 1);
280  if (Npe_t > 1) {
281  const int size_cp = m_P.nin() * Nvol_spc;
282 
283  for (int ipe_t = 1; ipe_t < Npe_t; ++ipe_t) {
284  if (ipe_t == 1) {
285  m_Pcp1.setpart_ex(0, m_P, 0);
286  } else {
287  m_Pcp1.setpart_ex(0, m_Pcp2, 0);
288  }
289 
290 #pragma omp barrier
291 #pragma omp master
292  {
293  Communicator::exchange(size_cp, m_Pcp2.ptr(0), m_Pcp1.ptr(0), Ndim - 1, 1, 0);
294  }
295 #pragma omp barrier
296 
297  mult_Field_Gnn(m_Pcp1, 0, m_P, 0, m_Pcp2, 0);
298 #pragma omp barrier
299 
300  m_P.setpart_ex(0, m_Pcp1, 0);
301 #pragma omp barrier
302  }
303  }
304 
305  //- Take the trace
306  dcomplex tr = 0.0;
307 
308  // for (int site = 0; site < Nvol_spc; ++site) {
309  for (int site = is; site < is + ns; ++site) {
310  Mat_SU_N utmp(Nc);
311  m_P.mat(utmp, site, 0);
312 #pragma omp barrier
313 
314  tr += Tr(utmp);
315 #pragma omp barrier
316  }
317  ThreadManager_OpenMP::reduce_sum_global(tr, i_thread, Nthread);
318 
319  const int Lvol_spc = CommonParameters::Lvol() / CommonParameters::Lt();
320 
321  const double re_ploop = real(tr) / Nc / Lvol_spc / Npe_t;
322  const double im_ploop = imag(tr) / Nc / Lvol_spc / Npe_t;
323 
324 #pragma omp barrier
325 #pragma omp master
326  {
327  ploop = cmplx(re_ploop, im_ploop);
328  }
329 #pragma omp barrier
330 }
331 
332 
333 //====================================================================
334 //============================================================END=====
BridgeIO vout
Definition: bridgeIO.cpp:503
virtual void set_parameters(const Parameters &params)
setting parameters: only for Polyakov loop correlators.
static int get_num_threads()
returns available number of threads.
static int npe(const int dir)
logical grid extent
const double * ptr(const int jin, const int site, const int jex) const
Definition: field.h:154
int site(const int &x, const int &y, const int &z, const int &t) const
Definition: index_lex.h:53
void general(const char *format,...)
Definition: bridgeIO.cpp:197
void reset(const int Nvol, const int Nex)
Definition: field_G.h:79
dcomplex Tr(const Mat_SU_N &m)
Definition: mat_SU_N.h:558
int nvol() const
Definition: field.h:128
void init(const std::string &filename)
Definition: bridgeIO.cpp:51
Class for parameters.
Definition: parameters.h:46
static int get_thread_id()
returns thread id.
Field_G m_Ut
Definition: polyakovLoop.h:56
Field_G m_P
working area
Definition: polyakovLoop.h:56
int nin() const
Definition: field.h:127
SU(N) gauge field.
Definition: field_G.h:38
Bridge::VerboseLevel m_vl
Definition: polyakovLoop.h:46
int fetch_int(const string &key, int &value) const
Definition: parameters.cpp:346
Lexical site index.
Definition: index_lex.h:34
void mult_Field_Gnn(Field_G &W, const int ex, const Field_G &U1, const int ex1, const Field_G &U2, const int ex2)
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
static void reduce_sum_global(dcomplex &value, const int i_thread, const int Nthread)
global reduction with summation: dcomplex values are assumed thread local.
void init()
initial setup independent of parameters.
std::string m_filename_output
Definition: polyakovLoop.h:49
static const std::string class_name
Definition: polyakovLoop.h:43
std::ostream & getStream()
Definition: bridgeIO.cpp:391
int m_Nspc_size
parameters set by user
Definition: polyakovLoop.h:52
static int exchange(int count, dcomplex *recv_buf, dcomplex *send_buf, int idir, int ipm, int tag)
receive array of dcomplex from upstream specified by idir and ipm, and send array to downstream...
int non_negative(const int v)
Field_G m_Pcp2
Definition: polyakovLoop.h:56
int m_Ntype
number of measured loop-type
Definition: polyakovLoop.h:53
void setpart_ex(int ex, const Field &w, int exw)
Definition: field.h:202
string get_string(const string &key) const
Definition: parameters.cpp:221
void set_mat(const int site, const int mn, const Mat_SU_N &U)
Definition: field_G.h:160
Mat_SU_N mat(const int site, const int mn=0) const
Definition: field_G.h:114
static long_t Lvol()
void mult_nn(const Mat_SU_N &u1, const Mat_SU_N &u2)
Definition: mat_SU_N.h:189
Field_G m_Pcp1
Definition: polyakovLoop.h:56
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131
void calc_ploop(dcomplex &ploop, const Field_G &U)
Polyakov loop correlator measurement (to be implemented).
dcomplex measure_ploop(const Field_G &U)
Polyakov loop measurement.