HΦ  3.2.0
FirstMultiply.c 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.h"
#include "expec_energy_flct.h"
#include "common/setmemory.h"
#include "wrapperMPI.h"
#include "CalcTime.h"
+ Include dependency graph for FirstMultiply.c:

Go to the source code of this file.

Functions

int FirstMultiply (int rand_i, 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.c.

Function Documentation

◆ FirstMultiply()

int FirstMultiply ( int  rand_i,
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)

Definition at line 40 of file FirstMultiply.c.

Referenced by CalcByTPQ().

40  {
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
double global_norm
Definition: global.h:67
int nthreads
Number of Threads, defined in InitializeMPI()
Definition: global.h:164
unsigned int NsiteMPI
Total number of sites, differ from DefineList::Nsite.
Definition: struct.h:57
const char * cFileNameTimeKeep
Definition: global.c:23
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
+ Here is the caller graph for this function: