64 {
65 #ifndef MAX
66 # define MAX 100
67 #endif
68 #ifndef SEED
69 # define SEED 0
70 #endif
72
75 double EnergyRange1;
76 #ifdef GPU
77 constexpr magma_trans_t transC = MagmaConjTrans;
78 constexpr magma_trans_t transN = MagmaNoTrans;
79 #else
80 char transC = 'C', transN = 'N';
81 #endif
82
83 if( !Initialize(argc, argv, Nargs_common) ) {
84 std::cerr << "Error: Initialization failed." << std::endl;
85 std::exit(EX_USAGE);
86 }
88
89
90 debug_print(
"# Checking for the directory structure.");
91 std::ofstream OutMultiFractal, OutSample, OutParam;
92
93
94
95
96
97#ifdef GPU
98 magma_init();
99 magma_queue_t queue = NULL;
100 magma_int_t dev = 0;
101 magma_getdevice( &dev );
102 magma_queue_create( dev, &queue );
103#else
105#endif
106
107
108 debug_print(
"# Calculating translation-invariant sectors.");
110
111
112
115 std::vector<double> Op1EigenValue(dim_max);
116 std::vector<double> Op2EigenValue(dim_max);
119 matrix<Complex_t> Overlap(dim_max, dim_max);
120 std::vector<double> aveOverlap(NDIV);
121#ifndef GPU
122 matrix<Complex_t> Op1_tot(dim_max, dim_max);
123 matrix<Complex_t> Op2_tot(dim_max, dim_max);
124 #define dOp1 Op1
125 #define dOp2 Op2
126 #define dOp1_tot Op1_tot
127 #define dOp2_tot Op2_tot
128 #define dOverlap Overlap
129#endif
130
131
132#ifdef GPU
133
136 Integer_t const LDT = magma_roundup(dim_max, GPU_UNIT);
139 matrix_gpu<Complex_t> dOp1_tot(LDT, dim_max);
140 matrix_gpu<Complex_t> dOp2_tot(LDT, dim_max);
141 matrix_gpu<Complex_t> dOverlap(LDT, dim_max);
142
143
144
146
147#endif
148
149 double start, t_int, end, temp_t;
150 double T_diag=0, T_post=0, T_pre=0;
151 init_genrand(SEED);
154 generateLocal_op(Op1,
dloc_op, -1);
155 generateLocal_op(Op2,
dloc_op, -1);
156 }
158 std::cout << "(init_genrand): time=" << std::fixed << (end-start) << std::endl;
159
160
161
162
163
164
165
166
167
169 end = start;
171
172 generateLocal_op(Op1,
dloc_op, -1);
173 generateLocal_op(Op2,
dloc_op, -1);
174
176
177 #ifdef GPU
180 #endif
181
183
185 {
186 std::stringstream
buff(
"");
187 buff <<
"/ProcessedData/Sample_No" << repetition;
188 outDirName +=
buff.str();
189 outDirName = std::regex_replace(outDirName, std::regex("//"), "/");
190 filesystem::create_directories(outDirName);
191 }
192
195 debug_print(
"# (rep,n)=(" << repetition <<
"," << n <<
")");
196 debug_print(
"# Constructing global matrices in the sector.");
198 {
201 #ifdef GPU
202 magma_queue_sync(queue);
203 #endif
204 }
206
207 debug_print(
"# Calculating overlaps of eigenvectors.");
209 {
210 if(
Diagonalize(dim_sub, dOp1_tot, Op1EigenValue) != 0) {
211 std::cerr << "# Warning: Failed in diagonalizing Op1 for (rep,n) = (" << repetition << "," << n << ")" << std::endl;
212 failed += 1;
213 continue;
214 }
215 if(
Diagonalize(dim_sub, dOp2_tot, Op2EigenValue) != 0) {
216 std::cerr << "# Warning: Failed in diagonalizing Op2 for (rep,n) = (" << repetition << "," << n << ")" << std::endl;
217 failed += 1;
218 continue;
219 }
220 matrixProduct_gemm(transC, transN, dim_sub, dim_sub, dim_sub, dOp1_tot, dOp2_tot, dOverlap,
GPUconf);
221 #ifdef GPU
222 magma_getmatrix(dim_sub, dim_sub,
sizeof(
Complex_t), dOverlap.ptr(), dOverlap.LD(), &*Overlap.begin(), Overlap.LD(), queue);
223 #endif
224 EnergyRange1 = Op1EigenValue[dim_sub-1] - Op1EigenValue[0];
225 }
227
230 {
231 std::stringstream
buff(
"");
232 buff <<
"/MultiFractal" << PRECISION <<
"_vsOp_N" << n <<
".txt";
233 std::string filename(outDirName); filename +=
buff.str();
234 OutMultiFractal.open(filename);
checkIsFileOpen(OutMultiFractal,filename);
235 OutMultiFractal
236 << "# 1.(Energy) 2.(deg.2) 3.(deg.3) ...\n" << std::endl
237 << std::scientific;
238 printMultiFractalDimensions(OutMultiFractal, dim_sub, 8, Op2EigenValue, Overlap, dim_sub);
239 OutMultiFractal.close();
240 }
241 {
242 #pragma omp parallel for
243 for (size_t i = 0; i < dim_sub; ++i) for (size_t j = 0; j < dim_sub; ++j) {
244 Overlap.at(i,j) = conj(Overlap.at(i,j))*Overlap.at(i,j);
245 }
246 auto [BinAverage, BinDataNum] = coarseGrainingMatrixByEnergy(NDIV, dim_sub, Op1EigenValue, Op2EigenValue, Overlap);
247 auto [mean, sigma, DOS] =
OverlapSqVsEnergy(NDIV, dim_sub, Op1EigenValue, Op2EigenValue, Overlap);
248
249 {
250 std::stringstream
buff(
"");
buff <<
"/OverlapSq" << PRECISION <<
"_vsOp_N" << n <<
".txt";
251 std::string filename(outDirName+
buff.str());
253 OutSample << "# 1.(Energy2) 2.(Energy1) 3.(Overlap^2) 4.(Num. data) 5.(Dos of Op2)\n" << std::endl
254 << std::scientific;
255 for(size_t bin2 = 0;bin2 < NDIV; ++bin2) for(size_t bin1 = 0;bin1 < NDIV; ++bin1) {
256 if( isnan(real(BinAverage.at(bin1,bin2))) ) continue;
257 OutSample << std::setw(13) << (bin2+0.5)/(double)NDIV << " "
258 << std::setw(13) << (bin1+0.5)/(double)NDIV << " "
259 << std::setw(13) << real(BinAverage.at(bin1,bin2)) << " "
260 << std::setw(5) << BinDataNum.at(bin1,bin2) << " "
261 << std::setw(13) << DOS.at(bin2)
262 << "\n" << std::noshowpos;
263 }
264 OutSample.close();
265 }
266 {
267 std::stringstream
buff(
"");
buff <<
"/Parameter" << PRECISION <<
"_vsOp_N" << n <<
".txt";
268 std::string filename(outDirName+
buff.str());
270 OutParam << "# 1.(Energy1) 2.(mean) 3.(width) 4.(Strength sigma) 5.(density of states)\n" << std::endl
271 << std::scientific;
272 for(size_t bin2 = 0;bin2 < NDIV; ++bin2) {
273 if(DOS[bin2] == 0) continue;
274 OutParam << std::setw(13) << (bin2+0.5)/(double)NDIV << " "
275 << std::setw(13) << mean[bin2] << " "
276 << std::setw(13) << sigma[bin2] << " "
277 << std::setw(13) << EnergyRange1*sqrt(sigma[bin2]/DOS[bin2]/M_PI) << " "
278 << std::setw(13) << DOS[bin2]
279 << "\n" << std::noshowpos;
280 }
281 OutParam.close();
282 }
283 }
285
286 }
287 if(repetition%10 == 9) {
289 std::cerr << "(total=" << std::setw(6) << repetition+1
290 << "): timeINT=" << std::setprecision(6) << std::setw(8) << (end-t_int)
291 << ", timeTOT=" << std::setprecision(6) << std::setw(8) << (end-start)
292 << ", T_construct=" << std::setprecision(6) << std::setw(10) << T_pre << "(" << std::setprecision(3) << 100*T_pre /(end-start) << "%)"
293 << ", T_diag=" << std::setprecision(6) << std::setw(8) << T_diag << "(" << std::setprecision(3) << 100*T_diag/(end-start) << "%)"
294 << ", T_process=" << std::setprecision(6) << std::setw(8) << T_post << "(" << std::setprecision(3) << 100*T_post/(end-start) << "%)"
295 << ", failed=" << failed
296 << std::endl;
297 }
298 }
299
300 Finalize(argc, argv);
301 #ifdef GPU
302 magma_finalize();
303 #endif
304 return 0;
305}
double getETtime()
Definition EnergySpectrum.c:14
std::vector< TransSector > Sector(n_max+1)
Definition mytypes.hpp:147
bool checkIsFileOpen(std::ifstream &file, std::string const &filename)
Definition file_util.hpp:22
debug_print("# Determining GPU configuration.")
GPUconfig GPUconf(dim3(nBlock, nBlock, 1), dim3(nThread, nThread, 1), 0, queue)
Integer_t const num_op
Definition setVariablesForEnsemble.cpp:39
baseDirName
Definition setVariablesForEnsemble.cpp:50
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 n_max
Definition setVariablesForEnsemble.cpp:27
Integer_t Diagonalize(Integer_t const dim, matrix< Complex_t< double > > &Hamiltonian, std::vector< double > &Eigenvalue)
Definition statmech.cpp:56
std::tuple< std::vector< double >, std::vector< double >, std::vector< double > > OverlapSqVsEnergy(Integer_t const NDIV, Integer_t const dim, std::vector< double > const &Energy1, std::vector< double > const &Energy2, matrix< Type > const &OverlapSq)
Definition statmech.cpp:346
std::stringstream buff("")