HPhi++  3.1.0
FirstMultiply.cpp File Reference

Multiplication \( v_0 = H v_1 \) at the first step for TPQ mode ( \( v_1 \) is the random or inputted vector). More...

#include "FirstMultiply.hpp"
#include "expec_energy_flct.hpp"
#include "common/setmemory.hpp"
#include "wrapperMPI.hpp"
#include "CalcTime.hpp"
#include "mltplyCommon.hpp"
#include "expec_cisajs.hpp"
#include "expec_cisajscktaltdc.hpp"

Go to the source code of this file.

Functions

int FirstMultiply (struct BindStruct *X)
 Multiplication \( v_0 = H v_1 \) at the first step for TPQ mode ( \( v_1 \) is the random or inputted vector). More...
 

Detailed Description

Multiplication \( v_0 = H v_1 \) at the first step for TPQ mode ( \( v_1 \) is the random or inputted vector).

Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)
Version
0.1

Definition in file FirstMultiply.cpp.

Function Documentation

◆ FirstMultiply()

int FirstMultiply ( struct BindStruct X)

Multiplication \( v_0 = H v_1 \) at the first step for TPQ mode ( \( v_1 \) is the random or inputted vector).

Parameters
rand_i[in] A rundom number seed for giving the initial vector \( v_1 \).
X[in] Struct to get information of the vector \( v_1 \) for the first step calculation.
Return values
-1fail the multiplication \( v_0 = H v_1 \).
0succeed the multiplication \( v_0 = H v_1 \).
Version
0.1
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)

Compute expectation value at infinite temperature

Definition at line 42 of file FirstMultiply.cpp.

Referenced by CalcByTPQ().

42  {
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
int nthreads
Number of Threads, defined in InitializeMPI()
Definition: global.cpp:74
double * global_norm
Definition: global.cpp:45
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