StatMech
Loading...
Searching...
No Matches
Fluc_randHOp.cpp File Reference

Functions

int main (int argc, char **argv)
 

Variables

namespace filesystem = std::experimental::filesystem
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)
57 {
60
61 Integer_t dim_sub; //全ヒルベルト空間の次元
62 Integer_t ndata, info, failed=0; // カウンタ
63 double gE, EnergyRange, OpRange, OpMin;
64 double Fluc, MaxFluc, MaxPos; // ETHの指標
65
66 if( !Initialize(argc, argv, Nargs_common) ) {
67 std::cerr << "Error: Initialization failed." << std::endl;
68 std::exit(EX_USAGE);
69 }
70 debug_print("# Successfully initialized.");
71
72 //******************** Check for the directory structure ********************
73 debug_print("# Checking for the directory structure.");
75 std::ofstream OutSample;
76 //******************** (END) Check for the directory structure ********************
77
78 //***************************************************************************
79 //******************** Allocation & Initialization **************************
80 //***************************************************************************
81#ifdef GPU
82 magma_init();
83 magma_queue_t queue = NULL;
84 magma_int_t dev = 0;
85 magma_getdevice( &dev );
86 magma_queue_create( dev, &queue );
87#else
88 void* GPUconf = nullptr;
89#endif
90
91 //******************** Translation invariance ********************
92 debug_print("# Calculating translation-invariant sectors.");
94 for(Integer_t n = n_max;n >= n_min; --n) {
95 OutMeasure[n] << "# (n=" << n << ") dim=" << Sector[n].dim() << "\n"
96 << "# 1.(Sample No.) 2.(Fluc_2) 3.(Fluc_infty) 4.(Pos_max_flux) 5.(ndata)\n"
97 << std::endl << std::scientific;
98 }
99 //******************** (END)Translation invariance ********************
100
101 //********** Allocate CPU memories **********//
102 debug_print("# Allocating CPU memories.");
103 Integer_t const dim_max = SectorDimension(Sector[n_max]);
104 std::vector<Integer_t> NdataInShell(dim_max);
105 std::vector<double> eigenEnergy(dim_max);
106 std::vector<double> EXPvalue(dim_max);
107 std::vector<double> MCAverage(dim_max);
108 matrix<Complex_t> h(dloc_h , dloc_h );
109 matrix<Complex_t> loc(dloc_op, dloc_op);
110#ifndef GPU
111 matrix<Complex_t> h_tot(dim_max, dim_max);
112 matrix<Complex_t> loc_tot(dim_max, dim_max);
113 #define dh h
114 #define dloc loc
115 #define dh_tot h_tot
116 #define dloc_tot loc_tot
117#endif
118 //********** (END) Allocate CPU memories **********//
119
120#ifdef GPU
121 //********** Allocate GPU memories **********//
122 debug_print("# Allocating GPU memories.");
123 constexpr Integer_t GPU_UNIT = 32;
124 Integer_t const LDT = magma_roundup(dim_max, GPU_UNIT);
125 matrix_gpu<Complex_t> dh(dloc_h , dloc_h );
126 matrix_gpu<Complex_t> dloc(dloc_op, dloc_op);
127 matrix_gpu<Complex_t> dh_tot(LDT, dim_max);
128 matrix_gpu<Complex_t> dloc_tot(LDT, dim_max);
129 //********** (END) Allocate GPU memories **********//
130
131 //********** Determine GPU configuration **********//
133 //********** (END) Determine GPU configuration **********//
134#endif // #ifdef GPU
135
136 double start, t_int, end, temp_t;
137 double T_diag=0, T_post=0, T_pre=0;
138 init_genrand(SEED);
139 start = getETtime();
140 for(Integer_t repetition = 0;repetition < repMin; ++repetition) {
141 generateLocal_h( h, dloc_h, -1);
142 generateLocal_op(loc, dloc_op, -1);
143 }
144 end = getETtime();
145 std::cout << "(init_genrand): time=" << std::fixed << (end-start) << std::endl;
146 //***************************************************************************
147 //******************** (END) Allocation & Initialization ********************
148 //***************************************************************************
149
150 start = getETtime();
151 end = start;
152 for(Integer_t repetition = repMin;repetition <= repMax; ++repetition) {
153 // 局所ハミルトニアンと局所物理量をランダムにとる ******************************//
154 generateLocal_h( h, dloc_h, -1);
155 generateLocal_op(loc, dloc_op, -1);
156 #ifdef GPU
157 magma_setmatrix(dloc_h, dloc_h, sizeof(Complex_t), &*h.begin(), dloc_h, dh.ptr(), dloc_h, GPUconf.queue());
158 magma_setmatrix(dloc_op, dloc_op, sizeof(Complex_t), &*loc.begin(), dloc_op, dloc.ptr(), dloc_op, GPUconf.queue());
159 #endif
160
161 if(repetition < 10000) {
163 }
164 for(Integer_t n = n_max;n >= n_min; --n) {
165 debug_print("# (rep,n)=(" << repetition << "," << n << ")");
166 debug_print("# Constructing global matrices in the sector.");
167 temp_t = getETtime();
168 {
169 dim_sub = constructGlobal_h( dh_tot, dh, num_h, Sector.at(n), GPUconf);
170 constructGlobal_op(dloc_tot, dloc, num_op, Sector.at(n), GPUconf);
171 #ifdef GPU
172 magma_queue_sync(queue);
173 #endif
174 }
175 T_pre += getETtime() -temp_t;
176
177 debug_print("# Calculating eigenstate expectation values.");
178 temp_t = getETtime();
179 info = EigenExpValue(EXPvalue, eigenEnergy, dim_sub, dh_tot, dloc_tot, GPUconf);
180 if(info != 0) {
182 continue;
183 }
184 debug_print("# Calculating the spectral range of the observable.");
185 OpRange = SpectralRange(OpMin, dim_sub, dloc_tot);
186 T_diag += getETtime() -temp_t;
187
188 debug_print("# Calculating measures of the ETH.");
189 temp_t = getETtime();
190 {
191 EnergyRange = eigenEnergy[dim_sub-1] -eigenEnergy[0];
192 gE = eigenEnergy[0];
193 for(Integer_t i = 0;i < dim_sub; ++i) {
194 eigenEnergy[i] = (eigenEnergy[i] -gE)/EnergyRange;
195 // EXPvalue[i] /= OpRange;
196 }
197
198 // Calculate Microcanonical averages with energy corresponding to each eigenstate.
199 MCAverage.resize(dim_sub); NdataInShell.resize(dim_sub);
200 std::fill( MCAverage.begin(), MCAverage.end(), 0.0);
201 std::fill(NdataInShell.begin(), NdataInShell.end(), 0.0);
202 for(Integer_t i = 0;i < dim_sub; ++i) {
203 MCAverage[i] = MicroCanonicalAverage(NdataInShell[i], eigenEnergy[i], dE, dim_sub, eigenEnergy, EXPvalue, i);
204 }
205
206 ndata = MeasureOfETH(Fluc, MaxFluc, MaxPos, Emin, Emax, dim_sub, eigenEnergy, EXPvalue, MCAverage);
207 }
208 T_post += getETtime() -temp_t;
209
210 OutMeasure[n] << std::setw(6) << repetition << " " << std::showpos
211 << std::setw(13) << Fluc << " "
212 << std::setw(13) << MaxFluc << " "
213 << std::setw(13) << MaxPos << " " << std::noshowpos << ndata << "\n";
214 if(repetition < 10000) {
215 for(Integer_t i = 0;i < dim_sub; ++i) {
216 OutSample << std::setw(2) << n << " " << std::showpos
217 << std::setw(13) << eigenEnergy[i]*EnergyRange+gE << " "
218 << std::setw(13) << eigenEnergy[i] << " "
219 << std::setw(13) << EXPvalue[i] << "\n" << std::noshowpos;
220 }
221 }
222 }
223 if(repetition < 10000) OutSample.close();
224 if(repetition%10 == 9) {
225 t_int = end; end = getETtime();
226 std::cerr << "(total=" << std::setw(6) << repetition+1
227 << "): timeINT=" << std::setprecision(6) << std::setw(8) << (end-t_int)
228 << ", timeTOT=" << std::setprecision(6) << std::setw(8) << (end-start)
229 << ", T_construct=" << std::setprecision(6) << std::setw(10) << T_pre << "(" << std::setprecision(1) << 100*T_pre /(end-start) << "%)"
230 << ", T_diag=" << std::setprecision(6) << std::setw(8) << T_diag << "(" << std::setprecision(1) << 100*T_diag/(end-start) << "%)"
231 << ", T_process=" << std::setprecision(6) << std::setw(8) << T_post << "(" << std::setprecision(1) << 100*T_post/(end-start) << "%)"
232 << std::endl;
233 for(Integer_t n = n_min;n <= n_max; ++n) OutMeasure[n].flush();
234 }
235 }
236
237 Finalize(argc, argv);
238 #ifdef GPU
239 magma_finalize();
240 #endif
241 return 0;
242}
double getETtime()
Definition EnergySpectrum.c:14
std::ofstream OutMeasure[n_max+1]
Definition MeasureOfETH_CreateOutputFiles.cpp:1
std::vector< TransSector > Sector(n_max+1)
Definition mytypes.hpp:147
void queue(magma_queue_t x)
Definition mytypes.hpp:297
Calculate the microcanonical averages with respect to a given sorted vector 'eigVal'.
Definition MicroCanonicalAverage.hpp:25
debug_print("# Determining GPU configuration.")
GPUconfig GPUconf(dim3(nBlock, nBlock, 1), dim3(nThread, nThread, 1), 0, queue)
MKL_INT Integer_t
Definition mytypes.hpp:359
Integer_t const num_op
Definition setVariablesForEnsemble.cpp:39
Integer_t const num_h
Definition setVariablesForEnsemble.cpp:38
Integer_t const repMin
Definition setVariablesForEnsemble.cpp:31
Integer_t const n_min
Definition setVariablesForEnsemble.cpp:28
Integer_t const repMax
Definition setVariablesForEnsemble.cpp:32
Integer_t const dloc_op
Definition setVariablesForEnsemble.cpp:41
Integer_t const dloc_h
Definition setVariablesForEnsemble.cpp:40
Integer_t const n_max
Definition setVariablesForEnsemble.cpp:27
constexpr double Emin
Definition setVariablesForMCAverage.cpp:4
constexpr double Emax
Definition setVariablesForMCAverage.cpp:5
double const dE
Definition setVariablesForMCAverage.cpp:2
Integer_t EigenExpValue(std::vector< double > &EXPvalue, std::vector< double > &Eigenvalue, Integer_t const dim, matrix< Complex_t< double > > &Hamiltonian, const matrix< Complex_t< double > > &Operator, void *GPUconf)
Definition statmech.cpp:120
Integer_t MeasureOfETH(double &Fluc_2, double &Fluc_inf, double &MaxPos, double const Emin, double const Emax, Integer_t const dim, const std::vector< double > &eigenEnergy, const std::vector< double > &EXPvalue, const std::vector< double > &MCAverage)
Definition statmech.cpp:244
double SpectralRange(double &OpMin, Integer_t const dim, matrix< Complex_t< double > > &Operator)
Definition statmech.cpp:49

Variable Documentation

◆ filesystem

namespace filesystem = std::experimental::filesystem