122 {
125 std::exit(EX_USAGE);
126 }
127
140 std::cout <<
"# dloc_h=" <<
dloc_h <<
", dloc_op=" <<
dloc_op <<
"\n";
141
144 double gE, EnergyRange, OpRange, OpMin;
145 double Fluc, MaxFluc, MaxPos;
146 double const cutoff = 0.45;
147 double const dE = 0.02;
150
151 std::stringstream
buff;
152
154 std::cerr <<
"Error: n_min(" <<
n_min <<
") > n_max(" <<
n_max <<
")." << std::endl;
155 std::exit(EX_USAGE);
156 }
157 if(!Initialize(argc, argv)) {
158 std::cerr << "Error: Initialization failed." << std::endl;
159 std::exit(EX_USAGE);
160 }
161#ifndef NDEBUG
163 std::cerr << "# Successfully initialized." << std::endl;
164#endif
165
166
167#ifndef NDEBUG
168 std::cerr << "# Checking for the directory structure." << std::endl;
169#endif
170 std::string d_str1(argv[6]);
171 d_str1 += "/LocalRandomMatrix/";
172 d_str1 += QUOTE(ENSEMBLE);
173 std::string d_str2(d_str1);
175 buff.clear(std::stringstream::goodbit);
176 buff <<
"/" << TYPE <<
"randHOp" << PRECISION <<
"_"
179 d_str1 +=
buff.str();
180 filesystem::create_directories(d_str1);
181
184 buff.clear(std::stringstream::goodbit);
185 buff <<
"/" << TYPE <<
"Structure" << PRECISION <<
"_"
186 <<
"Local" <<
num_h <<
"_Seed" << seed <<
"_Min" <<
n_min <<
"_Max" <<
n_max;
187 d_str2 +=
buff.str();
188 filesystem::create_directories(d_str2);
189 }
190
194 buff.clear(std::stringstream::goodbit);
195 buff <<
"/MeasureOfETH_N" << n <<
"_" <<
div <<
".txt";
196 std::string filename(d_str1);
197 filename +=
buff.str();
200 std::cerr << "Can't open a file" << filename << "." << std::endl;
201 std::exit(EX_CANTCREAT);
202 }
204 }
205
206 std::ofstream OutSample;
207
208
209
210
211
212#ifdef GPU
213 magma_init();
214 magma_queue_t queue = NULL;
215 magma_int_t dev = 0;
216 magma_getdevice(&dev);
217 magma_queue_create(dev, &queue);
218#else
220#endif
221
222
223#ifndef NDEBUG
224 std::cerr << "# Calculating translation-invariant sectors." << std::endl;
225#endif
230#ifdef GPU
231 Sector[n].copyToGPU(queue);
232#endif
233 std::cout <<
"(n=" << n <<
", k=" <<
wave_number <<
") num_EqClass = " <<
Sector[n].dim()
234 <<
", 2^n/n =" << pow(
dim_loc, n) / n <<
"\n";
236 << "# 1.(Sample No.) 2.(Fluc_2) 3.(Fluc_infty) 4.(Pos_max_flux) 5.(ndata)\n"
237 << std::endl
238 << std::scientific;
239 }
240
241
242
243#if !defined(NDEBUG) && defined(MAGMA)
244 std::cerr << "# Allocating CPU memories." << std::endl;
245#endif
247 std::vector<Integer_t> NdataInShell(dim_max);
248 std::vector<double> eigenEnergy(dim_max);
249 std::vector<double> EXPvalue(dim_max);
250 std::vector<double> MCAverage(dim_max);
253#ifndef GPU
254 matrix<Complex_t> h_tot(dim_max, dim_max);
255 matrix<Complex_t> loc_tot(dim_max, dim_max);
256 #define dh_tot h_tot
257 #define dloc_tot loc_tot
258#endif
259
260
261#ifdef GPU
262
263 #ifndef NDEBUG
264 std::cerr << "# Allocating GPU memories." << std::endl;
265 #endif
267 Integer_t const LDT = magma_roundup(dim_max, GPU_UNIT);
270 matrix_gpu<Complex_t> dh_tot(LDT, dim_max);
271 matrix_gpu<Complex_t> dloc_tot(LDT, dim_max);
272
273
274
275 #ifndef NDEBUG
276 std::cerr << "# Determining GPU configuration." << std::endl;
277 #endif
279 struct cudaFuncAttributes
attr;
280 cudaFuncGetAttributes(&
attr, GlobFuncPtr);
285
286 std::cout <<
"# constSizeBytes = " <<
attr.constSizeBytes <<
"\n"
287 <<
"# maxThreadsPerBlock = " <<
attr.maxThreadsPerBlock <<
"\n"
288 <<
"# (dim_max=" << dim_max <<
") nBlock=" <<
nBlock <<
", nThread= " <<
nThread
290 magma_queue_sync(queue);
291
292#endif
293
294 double start, t_int, end, temp_t;
295 double T_diag = 0, T_post = 0, T_pre = 0;
296 init_genrand(seed);
299 generateLocal_h(h,
dloc_h, -1);
300 generateLocal_op(loc,
dloc_op, -1);
301 }
303 std::cout << "(init_genrand): time=" << std::fixed << (end - start) << std::endl;
304
305
306
307
309 end = start;
311
312#ifndef NDEBUG
314 std::cerr <<
"# (GPU, rep= " << std::setw(6) << repetition <<
") size=" <<
Usage.
size
317 <<
", dt=" <<
Usage.
dt << std::endl;
318#endif
319 generateLocal_h(h,
dloc_h, -1);
320 generateLocal_op(loc,
dloc_op, -1);
321#ifdef GPU
323 queue);
326#endif
327
328 if(repetition < 10000) {
329
331 buff.clear(std::stringstream::goodbit);
332 buff <<
"/Sample_No" << repetition <<
".txt";
333 std::string filename(d_str2);
334 filename += "/RawData";
335 filesystem::create_directory(filename);
336 filename +=
buff.str();
337 OutSample.open(filename);
338 if(OutSample.fail()) {
339 std::cerr << "Can't open a file" << filename;
340 std::exit(EX_CANTCREAT);
341 }
343 << "\n"
345 << "# 1.(System size) 2.(Energy density) 3.(Relative Pos) 4.(Exp. value)\n"
346 << std::endl
347 << std::scientific;
348
349 }
351#ifndef NDEBUG
352 std::cout << "# (rep,n)=(" << repetition << "," << n << ")" << std::endl;
353 std::cerr << "# Constructing global matrices in the sector." << std::endl;
354#endif
355 dim_sub =
Sector[n].dim();
357#ifdef GPU
358 constructGlobal_h(dh_tot, dh,
num_h,
Sector.at(n), conf);
359 constructGlobal_op(dloc_tot, dloc,
num_op,
Sector.at(n), conf);
360 magma_queue_sync(conf.queue());
361#else
364#endif
366
367#ifndef NDEBUG
368 std::cerr << "# Calculating eigenstate expectation values." << std::endl;
369#endif
371 info =
EigenExpValue(EXPvalue, eigenEnergy, dim_sub, dh_tot, dloc_tot, conf.queue());
372 if(info != 0) {
373 failed += 1;
375 buff.clear(std::stringstream::goodbit);
376 buff <<
"/Failed_N" << n <<
"_No" << repetition <<
".txt";
377 std::string filename(d_str1);
378 filename +=
buff.str();
379 std::ofstream ErrFp;
380 ErrFp.open(filename);
381 if(!ErrFp.is_open()) {
382 std::cerr << "# Warning: Can't open a file " << filename << ". Continue..."
383 << std::endl;
384 }
385 else {
386 ErrFp << "# info=" << info
387 << "\n\n"
388 "# seed="
389 << seed <<
", div=" <<
div <<
", N=" << n <<
", repetition=" << repetition
390 << "\n"
391 "# Local Hamiltonian\n";
393 ErrFp << "\n";
394 ErrFp << "# Local operator\n";
396 ErrFp << "\n";
397 if(
Sector[n].dim() < 110) {
398 ErrFp << "# Total Hamiltonian\n";
399 dh_tot.print(ErrFp, dim_sub, dim_sub, queue);
400 ErrFp << "# Total operator\n";
401 dloc_tot.print(ErrFp, dim_sub, dim_sub, queue);
402 }
403 ErrFp.close();
404 }
405 continue;
406 }
407#ifndef NDEBUG
408 std::cerr << "# Calculating the spectral range of the observable." << std::endl;
409#endif
412
413#ifndef NDEBUG
414 std::cerr << "# Calculating measures of the ETH." << std::endl;
415#endif
417 for(
Integer_t i = 0; i < dim_sub; ++i) EXPvalue[i] /= OpRange;
418 EnergyRange = eigenEnergy[dim_sub - 1] - eigenEnergy[0];
419 gE = eigenEnergy[0];
421 eigenEnergy[i] = (eigenEnergy[i] - gE) / EnergyRange;
422
423 MCAverage.resize(dim);
424 NdataInShell.resize(dim);
425 std::fill(MCAverage.begin(), MCAverage.end(), 0.0);
426 std::fill(NdataInShell.begin(), NdataInShell.end(), 0.0);
429 eigenEnergy, EXPvalue, i);
430 }
431
433 MCAverage);
435
436 OutMeasure[n] << std::setw(6) << repetition <<
" " << std::showpos << std::setw(13)
437 << Fluc << " " << std::setw(13) << MaxFluc << " " << std::setw(13)
438 << MaxPos << " " << std::noshowpos << ndata << "\n";
439 if(repetition < 10000) {
441 OutSample << std::setw(2) << n << " " << std::showpos << std::setw(13)
442 << eigenEnergy[i] * EnergyRange + gE << " " << std::setw(13)
443 << eigenEnergy[i] << " " << std::setw(13) << EXPvalue[i] << "\n"
444 << std::noshowpos;
445 }
446 }
447 }
448 if(repetition < 10000) OutSample.close();
449 if(repetition % 10 == 9) {
450 t_int = end;
452 std::cerr << "(total=" << std::setw(6) << repetition + 1
453 << "): timeINT=" << std::setprecision(6) << std::setw(8) << (end - t_int)
454 << ", timeTOT=" << std::setprecision(6) << std::setw(8) << (end - start)
455 << ", T_construct=" << std::setprecision(6) << std::setw(10) << T_pre << "("
456 << std::setprecision(1) << 100 * T_pre / (end - start) << "%)"
457 << ", T_diag=" << std::setprecision(6) << std::setw(8) << T_diag << "("
458 << std::setprecision(1) << 100 * T_diag / (end - start) << "%)"
459 << ", T_process=" << std::setprecision(6) << std::setw(8) << T_post << "("
460 << std::setprecision(1) << 100 * T_post / (end - start) << "%)" << std::endl;
462 }
463 }
464
465 Finalize(argc, argv);
466 return 0;
467}
__global__ void MatrixElementsInSector(void)
Definition generateRM.cuh:61
double getETtime()
Definition EnergySpectrum.c:14
std::ofstream OutMeasure[n_max+1]
Definition MeasureOfETH_CreateOutputFiles.cpp:1
statm_t Usage
Definition Fluc_randHOp.cpp:55
void read_off_memory_status(statm_t &result)
Definition Fluc_randHOp.cpp:98
std::string const USAGE_commom
Definition Fluc_randHOp.cpp:91
int const N_ARGS
Definition generateRM.hpp:16
std::string const USAGE_sp
Definition generateRM.hpp:17
std::vector< TransSector > Sector(n_max+1)
constexpr Integer_t wave_number
Definition TranslationInvariantSectors.cpp:1
Definition mytypes.hpp:147
Definition mytypes.hpp:272
Calculate the microcanonical averages with respect to a given sorted vector 'eigVal'.
Definition MicroCanonicalAverage.hpp:25
struct cudaFuncAttributes attr
Definition getAttributesOfMatrixElementsInSector.cpp:2
Integer_t const nBlock
Definition getAttributesOfMatrixElementsInSector.cpp:5
Integer_t const nThread
Definition getAttributesOfMatrixElementsInSector.cpp:4
GPUconfig GPUconf(dim3(nBlock, nBlock, 1), dim3(nThread, nThread, 1), 0, queue)
MKL_INT Integer_t
Definition mytypes.hpp:359
constexpr Integer_t dim_loc
Definition setVariablesForEnsemble.cpp:36
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 div
Definition setVariablesForEnsemble.cpp:29
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 cutoff
Definition setVariablesForMCAverage.cpp:3
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
Definition Fluc_randHOp.cpp:94
unsigned long dt
Definition Fluc_randHOp.cpp:95
unsigned long lib
Definition Fluc_randHOp.cpp:95
unsigned long text
Definition Fluc_randHOp.cpp:95
unsigned long resident
Definition Fluc_randHOp.cpp:95
unsigned long share
Definition Fluc_randHOp.cpp:95
unsigned long size
Definition Fluc_randHOp.cpp:95
unsigned long data
Definition Fluc_randHOp.cpp:95
std::stringstream buff("")