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

Functions

Integer_t Bin (double x)
 
int main (int argc, char **argv)
 

Variables

namespace filesystem = std::experimental::filesystem
 

Function Documentation

◆ Bin()

Integer_t Bin ( double  x)
59 {
60 Integer_t res = (Integer_t)(x*NDIV);
61 return (res==NDIV ? res-1: res);
62};
MKL_INT Integer_t
Definition mytypes.hpp:359

◆ main()

int main ( int  argc,
char **  argv 
)
64 {
65 #ifndef MAX
66 # define MAX 100
67 #endif
68 #ifndef SEED
69 # define SEED 0
70 #endif
72
73 Integer_t dim_sub; //全ヒルベルト空間の次元
74 Integer_t failed=0; // カウンタ
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 }
87 debug_print("# Successfully initialized.");
88
89 //******************** Check for the directory structure ********************
90 debug_print("# Checking for the directory structure.");
91 std::ofstream OutMultiFractal, OutSample, OutParam;
92 //******************** (END) Check for the directory structure ********************
93
94 //***************************************************************************
95 //******************** Allocation & Initialization **************************
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
104 void* GPUconf = nullptr;
105#endif
106
107 //******************** Translation invariance ********************
108 debug_print("# Calculating translation-invariant sectors.");
110 //******************** (END)Translation invariance ********************
111
112 //********** Allocate CPU memories **********//
113 debug_print("# Allocating CPU memories.");
114 Integer_t const dim_max = SectorDimension(Sector[n_max]);
115 std::vector<double> Op1EigenValue(dim_max);
116 std::vector<double> Op2EigenValue(dim_max);
117 matrix<Complex_t> Op1(dloc_op, dloc_op);
118 matrix<Complex_t> Op2(dloc_op, dloc_op);
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 //********** (END) Allocate CPU memories **********//
131
132#ifdef GPU
133 //********** Allocate GPU memories **********//
134 debug_print("# Allocating GPU memories.");
135 constexpr Integer_t GPU_UNIT = 32;
136 Integer_t const LDT = magma_roundup(dim_max, GPU_UNIT);
137 matrix_gpu<Complex_t> dOp1(dloc_op, dloc_op);
138 matrix_gpu<Complex_t> dOp2(dloc_op, dloc_op);
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 //********** (END) Allocate GPU memories **********//
143
144 //********** Determine GPU configuration **********//
146 //********** (END) Determine GPU configuration **********//
147#endif // #ifdef GPU
148
149 double start, t_int, end, temp_t;
150 double T_diag=0, T_post=0, T_pre=0;
151 init_genrand(SEED);
152 start = getETtime();
153 for(Integer_t repetition = 0;repetition < repMin; ++repetition) {
154 generateLocal_op(Op1, dloc_op, -1);
155 generateLocal_op(Op2, dloc_op, -1);
156 }
157 end = getETtime();
158 std::cout << "(init_genrand): time=" << std::fixed << (end-start) << std::endl;
159 //***************************************************************************
160 //******************** (END) Allocation & Initialization ********************
161 //***************************************************************************
162// #ifndef NDEBUG
163// std::string InFilename("/Users/Shoki/GitHub/temp/matrix.txt");
164// std::ifstream InFile(InFilename); checkIsFileOpen(InFile, InFilename);
165// debug_print("Input: " << InFilename);
166// #endif
167
168 start = getETtime();
169 end = start;
170 for(Integer_t repetition = repMin;repetition <= repMax; ++repetition) {
171 // 局所ハミルトニアンと局所物理量をランダムにとる ******************************//
172 generateLocal_op(Op1, dloc_op, -1);
173 generateLocal_op(Op2, dloc_op, -1);
174
175 debug_print("# rep=" << repetition);
176
177 #ifdef GPU
178 magma_setmatrix(dloc_op, dloc_op, sizeof(Complex_t), &*Op1.begin(), dloc_op, dOp1.ptr(), dloc_op, queue);
179 magma_setmatrix(dloc_op, dloc_op, sizeof(Complex_t), &*Op2.begin(), dloc_op, dOp2.ptr(), dloc_op, queue);
180 #endif
181
182 debug_print("# rep=" << repetition);
183
184 std::string outDirName(baseDirName);
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
193 debug_print("# rep=" << repetition);
194 for(Integer_t n = n_max;n >= n_min; --n) {
195 debug_print("# (rep,n)=(" << repetition << "," << n << ")");
196 debug_print("# Constructing global matrices in the sector.");
197 temp_t = getETtime();
198 {
199 dim_sub = constructGlobal_op(dOp1_tot, dOp1, num_op, Sector.at(n), GPUconf);
200 constructGlobal_h( dOp2_tot, dOp2, num_op, Sector.at(n), GPUconf);
201 #ifdef GPU
202 magma_queue_sync(queue);
203 #endif
204 }
205 T_pre += getETtime() -temp_t;
206
207 debug_print("# Calculating overlaps of eigenvectors.");
208 temp_t = getETtime();
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 }
226 T_diag += getETtime() -temp_t;
227
228 debug_print("# Writing results to a file.");
229 temp_t = getETtime();
230 { // Calculate Multti-fractal dimensions
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());
252 OutSample.open(filename); checkIsFileOpen(OutSample,filename);
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());
269 OutParam.open(filename); checkIsFileOpen(OutParam,filename);
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 }
284 T_post += getETtime() -temp_t;
285
286 }
287 if(repetition%10 == 9) {
288 t_int = end; end = getETtime();
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("")

Variable Documentation

◆ filesystem

namespace filesystem = std::experimental::filesystem