HPhi++  3.1.0
FirstMultiply.cpp
Go to the documentation of this file.
1 /* HPhi - Quantum Lattice Model Simulator */
2 /* Copyright (C) 2015 The University of Tokyo */
3 
4 /* This program is free software: you can redistribute it and/or modify */
5 /* it under the terms of the GNU General Public License as published by */
6 /* the Free Software Foundation, either version 3 of the License, or */
7 /* (at your option) any later version. */
8 
9 /* This program is distributed in the hope that it will be useful, */
10 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
11 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
12 /* GNU General Public License for more details. */
13 
14 /* You should have received a copy of the GNU General Public License */
15 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 #include "FirstMultiply.hpp"
17 #include "expec_energy_flct.hpp"
18 #include "common/setmemory.hpp"
19 #include "wrapperMPI.hpp"
20 #include "CalcTime.hpp"
21 #include "mltplyCommon.hpp"
22 #include "expec_cisajs.hpp"
23 #include "expec_cisajscktaltdc.hpp"
33 int FirstMultiply(struct BindStruct *X) {
43 
44  long int i, i_max;
45  double dnorm;
46  double Ns;
47  long int u_long_i;
48  dsfmt_t dsfmt;
49  int mythread, rand_i, iret;
50 
51  Ns = 1.0*X->Def.NsiteMPI;
52  i_max = X->Check.idim_max;
53 
54  for (rand_i = 0; rand_i < NumAve; rand_i++) {
55 #pragma omp parallel default(none) private(i, mythread, u_long_i, dsfmt) \
56 shared(I, v0, v1, nthreads, myrank, rand_i, X, stdoutMPI) \
57 firstprivate(i_max)
58  {
59 #pragma omp for
60  for (i = 1; i <= i_max; i++) {
61  v0[i][rand_i] = 0.0;
62  v1[i][rand_i] = 0.0;
63  }
64  /*
65  Initialise MT
66  */
67 #ifdef _OPENMP
68  mythread = omp_get_thread_num();
69 #else
70  mythread = 0;
71 #endif
72  u_long_i = 123432 + (rand_i + 1)*labs(X->Def.initial_iv) + mythread + nthreads * myrank;
73  dsfmt_init_gen_rand(&dsfmt, u_long_i);
74 
75  if (X->Def.iInitialVecType == 0) {
76 
77  StartTimer(3101);
78 #pragma omp for
79  for (i = 1; i <= i_max; i++)
80  v1[i][rand_i] = 2.0*(dsfmt_genrand_close_open(&dsfmt) - 0.5) + 2.0*(dsfmt_genrand_close_open(&dsfmt) - 0.5)*I;
81  }/*if (X->Def.iInitialVecType == 0)*/
82  else {
83 #pragma omp for
84  for (i = 1; i <= i_max; i++)
85  v1[i][rand_i] = 2.0*(dsfmt_genrand_close_open(&dsfmt) - 0.5);
86  }
87  StopTimer(3101);
88  }/*#pragma omp parallel*/
89  /*
90  Normalize v
91  */
92  dnorm = 0.0;
93 #pragma omp parallel for default(none) private(i) \
94 shared(v1, i_max, rand_i) reduction(+:dnorm)
95  for (i = 1; i <= i_max; i++)
96  dnorm += real(conj(v1[i][rand_i])*v1[i][rand_i]);
97  dnorm = SumMPI_d(dnorm);
98  dnorm = sqrt(dnorm);
99  global_1st_norm[rand_i] = dnorm;
100 #pragma omp parallel for default(none) private(i) shared(v1,rand_i) firstprivate(i_max, dnorm)
101  for (i = 1; i <= i_max; i++) v1[i][rand_i] = v1[i][rand_i] / dnorm;
102  }/*for (rand_i = 0; rand_i < NumAve; rand_i++)*/
103 
104  TimeKeeperWithRandAndStep(X, "%s_TimeKeeper.dat", "set %d step %d:TPQ begins: %s", "a", rand_i, step_i);
108  X->Def.istep = 0;
109  StartTimer(3300);
110  iret = expec_cisajs(X, NumAve, v0, v1);
111  StopTimer(3300);
112  if (iret != 0) return -1;
113 
114  StartTimer(3400);
115  iret = expec_cisajscktaltdc(X, NumAve, v0, v1);
116  StopTimer(3400);
117  if (iret != 0) return -1;
118 
119 #pragma omp parallel for default(none) private(i,rand_i) shared(v0,v1,i_max,NumAve)
120  for (i = 1; i <= i_max; i++)
121  for (rand_i = 0; rand_i < NumAve; rand_i++) v0[i][rand_i] = v1[i][rand_i];
122  StartTimer(3102);
123  if(expec_energy_flct(X, NumAve, v0, v1) !=0){
124  StopTimer(3102);
125  return -1;
126  }
127  StopTimer(3102);
128 
129  for (rand_i = 0; rand_i < NumAve; rand_i++) {
130 #pragma omp parallel for default(none) private(i) shared(v0, v1, list_1,rand_i) \
131 firstprivate(i_max, Ns, LargeValue, myrank)
132  for (i = 1; i <= i_max; i++) {
133  v0[i][rand_i] = LargeValue * v1[i][rand_i] - v0[i][rand_i] / Ns;
134  }
135 
136  dnorm = 0.0;
137 #pragma omp parallel for default(none) private(i) shared(v0,rand_i) \
138 firstprivate(i_max) reduction(+:dnorm)
139  for (i = 1; i <= i_max; i++)
140  dnorm += real(conj(v0[i][rand_i])*v0[i][rand_i]);
141  dnorm = SumMPI_d(dnorm);
142  dnorm = sqrt(dnorm);
143  global_norm[rand_i] = dnorm;
144 #pragma omp parallel for default(none) private(i) shared(v0,rand_i) firstprivate(i_max, dnorm)
145  for (i = 1; i <= i_max; i++) v0[i][rand_i] = v0[i][rand_i] / dnorm;
146  }/*for (rand_i = 0; rand_i < NumAve; rand_i++)*/
147  TimeKeeperWithRandAndStep(X, "%s_TimeKeeper.dat", "set %d step %d:TPQ finishes: %s", "a", rand_i, step_i);
148  return 0;
149 }
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
int expec_cisajscktaltdc(struct BindStruct *X, int nstate, std::complex< double > **Xvec, std::complex< double > **vec)
Parent function to calculate two-body green&#39;s functions.
double * global_1st_norm
Definition: global.cpp:46
int expec_energy_flct(struct BindStruct *X, int nstate, std::complex< double > **tmp_v0, std::complex< double > **tmp_v1)
Parent function to calculate expected values of energy and physical quantities.
int NumAve
Definition: global.cpp:43
std::complex< double > ** v0
Definition: global.cpp:20
std::complex< double > I(0.0, 1.0)
std::complex< double > ** v1
Definition: global.cpp:21
int NsiteMPI
Total number of sites, differ from DefineList::Nsite.
Definition: struct.hpp:57
int TimeKeeperWithRandAndStep(struct BindStruct *X, const char *cFileName, const char *cTimeKeeper_Message, const char *cWriteType, const int irand, const int istep)
Functions for writing a time log.
Definition: log.cpp:117
Bind.
Definition: struct.hpp:394
int nthreads
Number of Threads, defined in InitializeMPI()
Definition: global.cpp:74
double * global_norm
Definition: global.cpp:45
int FirstMultiply(struct BindStruct *X)
Multiplication at the first step for TPQ mode ( is the random or inputted vector).
int myrank
Process ID, defined in InitializeMPI()
Definition: global.cpp:73
int expec_cisajs(struct BindStruct *X, int nstate, std::complex< double > **Xvec, std::complex< double > **vec)
function of calculation for one body green&#39;s function
int step_i
Definition: global.cpp:44
double LargeValue
Definition: global.cpp:42
void StopTimer(int n)
function for calculating elapse time [elapse time=StartTimer-StopTimer]
Definition: time.cpp:83
int istep
Index of TPQ step ???
Definition: struct.hpp:78
double SumMPI_d(double norm)
MPI wrapper function to obtain sum of Double across processes.
Definition: wrapperMPI.cpp:222
long int initial_iv
Seed of random number for initial guesss of wavefunctions.
Definition: struct.hpp:76
int iInitialVecType
Switch for type of inital vectors. 0:complex type, 1: real type. default value is set as 0 in readdef...
Definition: struct.hpp:197
struct CheckList Check
Size of the Hilbert space.
Definition: struct.hpp:396
long int idim_max
The dimension of the Hilbert space of this process.
Definition: struct.hpp:305
void StartTimer(int n)
function for initializing elapse time [start]
Definition: time.cpp:71