HΦ  3.2.0
FirstMultiply.c
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.h"
17 #include "expec_energy_flct.h"
18 #include "common/setmemory.h"
19 #include "wrapperMPI.h"
20 #include "CalcTime.h"
21 
31 int FirstMultiply(int rand_i, struct BindStruct *X) {
41 
42  long int i, i_max;
43  double complex dnorm;
44  double Ns;
45  long unsigned int u_long_i;
46  dsfmt_t dsfmt;
47  int mythread;
48 
49  Ns = 1.0*X->Def.NsiteMPI;
50  i_max = X->Check.idim_max;
51 
52 #pragma omp parallel default(none) private(i, mythread, u_long_i, dsfmt) \
53  shared(v0, v1, nthreads, myrank, rand_i, X, stdoutMPI, cLogCheckInitComplex, cLogCheckInitReal) \
54  firstprivate(i_max)
55  {
56 #pragma omp for
57  for (i = 1; i <= i_max; i++) {
58  v0[i] = 0.0;
59  v1[i] = 0.0;
60  }
61 
62  /*
63  Initialise MT
64  */
65 #ifdef _OPENMP
66  mythread = omp_get_thread_num();
67 #else
68  mythread = 0;
69 #endif
70  u_long_i = 123432 + (rand_i + 1)*labs(X->Def.initial_iv) + mythread + nthreads * myrank;
71  dsfmt_init_gen_rand(&dsfmt, u_long_i);
72 
73  if (X->Def.iInitialVecType == 0) {
74 
75  StartTimer(3101);
76 #pragma omp for
77  for (i = 1; i <= i_max; i++)
78  v1[i] = 2.0*(dsfmt_genrand_close_open(&dsfmt) - 0.5) + 2.0*(dsfmt_genrand_close_open(&dsfmt) - 0.5)*I;
79  }/*if (X->Def.iInitialVecType == 0)*/
80  else {
81 #pragma omp for
82  for (i = 1; i <= i_max; i++)
83  v1[i] = 2.0*(dsfmt_genrand_close_open(&dsfmt) - 0.5);
84  }
85  StopTimer(3101);
86 
87  }/*#pragma omp parallel*/
88  /*
89  Normalize v
90  */
91  dnorm=0.0;
92 #pragma omp parallel for default(none) private(i) shared(v1, i_max) reduction(+: dnorm)
93  for(i=1;i<=i_max;i++){
94  dnorm += conj(v1[i])*v1[i];
95  }
96  dnorm = SumMPI_dc(dnorm);
97  dnorm=sqrt(dnorm);
98  global_1st_norm = dnorm;
99 #pragma omp parallel for default(none) private(i) shared(v0,v1) firstprivate(i_max, dnorm)
100  for(i=1;i<=i_max;i++){
101  v1[i] = v1[i]/dnorm;
102  v0[i] = v1[i];
103  }
104 
106 
107  StartTimer(3102);
108  if(expec_energy_flct(X) !=0){
109  StopTimer(3102);
110  return -1;
111  }
112  StopTimer(3102);
113 #pragma omp parallel for default(none) private(i) shared(v0, v1, list_1) firstprivate(i_max, Ns, LargeValue, myrank)
114  for(i = 1; i <= i_max; i++){
115  v0[i]=LargeValue*v1[i]-v0[i]/Ns;
116  }
117 
118  dnorm=0.0;
119 #pragma omp parallel for default(none) private(i) shared(v0) firstprivate(i_max) reduction(+: dnorm)
120  for(i=1;i<=i_max;i++){
121  dnorm += conj(v0[i])*v0[i];
122  }
123  dnorm = SumMPI_dc(dnorm);
124  dnorm=sqrt(dnorm);
125  global_norm = dnorm;
126 #pragma omp parallel for default(none) private(i) shared(v0) firstprivate(i_max, dnorm)
127  for(i=1;i<=i_max;i++){
128  v0[i] = v0[i]/dnorm;
129  }
131  return 0;
132 }
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.h:410
void StartTimer(int n)
function for initializing elapse time [start]
Definition: time.c:71
double complex SumMPI_dc(double complex norm)
MPI wrapper function to obtain sum of Double complex across processes.
Definition: wrapperMPI.c:205
unsigned long int idim_max
The dimension of the Hilbert space of this process.
Definition: struct.h:303
const char * cTPQStepEnd
Definition: LogMessage.c:80
void StopTimer(int n)
function for calculating elapse time [elapse time=StartTimer-StopTimer]
Definition: time.c:83
double complex * v1
Definition: global.h:35
const char * cTPQStep
Definition: LogMessage.c:79
int FirstMultiply(int rand_i, struct BindStruct *X)
Multiplication at the first step for TPQ mode ( is the random or inputted vector).
Definition: FirstMultiply.c:40
double global_norm
Definition: global.h:67
int nthreads
Number of Threads, defined in InitializeMPI()
Definition: global.h:164
Bind.
Definition: struct.h:409
unsigned int NsiteMPI
Total number of sites, differ from DefineList::Nsite.
Definition: struct.h:57
const char * cFileNameTimeKeep
Definition: global.c:23
struct EDMainCalStruct X
Definition: struct.h:432
long int initial_iv
Seed of random number for initial guesss of wavefunctions.
Definition: struct.h:76
int myrank
Process ID, defined in InitializeMPI()
Definition: global.h:163
int expec_energy_flct(struct BindStruct *X)
Parent function to calculate expected values of energy and physical quantities.
int iInitialVecType
Switch for type of inital vectors. 0:complex type, 1: real type. default value is set as 0 in readdef...
Definition: struct.h:195
double global_1st_norm
Definition: global.h:68
double complex * v0
Definition: global.h:34
struct CheckList Check
Size of the Hilbert space.
Definition: struct.h:411
int step_i
Definition: global.h:66
double LargeValue
Definition: global.h:64
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.c:117