57 {
58 #define MAXDATA 100
59 #define SEED 0
61
64 double OpRange;
65
66 if( !Initialize(argc, argv, Nargs_common) ) {
67 std::cerr << "Error: Initialization failed." << std::endl;
68 std::exit(EX_USAGE);
69 }
71
72
73 debug_print(
"# Checking for the directory structure.");
74 std::ofstream OutMatElems, OutEnergy, OutOpEigV;
75
76
77
78
79
80#ifdef GPU
81 magma_init();
82 magma_queue_t queue = NULL;
83 magma_int_t dev = 0;
84 magma_getdevice( &dev );
85 magma_queue_create( dev, &queue );
86#else
88#endif
89
90
91 debug_print(
"# Calculating translation-invariant sectors.");
93
94
95
98 std::vector<Integer_t> NdataInShell(dim_max);
99 std::vector<double> eigenEnergy(dim_max);
100 std::vector<double> MCAverage(dim_max);
101 std::vector<double> OpEigenValue(dim_max);
104 matrix<Complex_t> loc_tot(dim_max, dim_max);
105#ifndef GPU
106 matrix<Complex_t> h_tot(dim_max, dim_max);
107 #define dh h
108 #define dloc loc
109 #define dh_tot h_tot
110
111 matrix<Complex_t> dloc_tot(dim_max, dim_max);
112#endif
113
114
115#ifdef GPU
116
119 Integer_t const LDT = magma_roundup(dim_max, GPU_UNIT);
122 matrix_gpu<Complex_t> dh_tot(LDT, dim_max);
123 matrix_gpu<Complex_t> dloc_tot(LDT, dim_max);
124
125
126
128
129#endif
130
131 double start, t_int, end, temp_t;
132 double T_diag=0, T_post=0, T_pre=0;
133 init_genrand(SEED);
136 generateLocal_h( h,
dloc_h, -1);
137 generateLocal_op(loc,
dloc_op, -1);
138 }
140 std::cout << "(init_genrand): time=" << std::fixed << (end-start) << std::endl;
141
142
143
144
145
146
147
148
149
151 end = start;
153
154 generateLocal_h( h,
dloc_h, -1);
155 generateLocal_op(loc,
dloc_op, -1);
156
157 #ifdef GPU
160 #endif
162 {
163 std::stringstream
buff;
164 buff <<
"/RawData/Sample_No" << repetition;
165 outDirName +=
buff.str();
166 outDirName = std::regex_replace(outDirName, std::regex("//"), "/");
167 filesystem::create_directories(outDirName);
168 }
169
171 debug_print(
"# (rep,n)=(" << repetition <<
"," << n <<
")");
172 debug_print(
"# Constructing global matrices in the sector.");
174 {
177 #ifdef GPU
178 magma_queue_sync(queue);
179 #endif
180 }
182
183 debug_print(
"# Calculating eigenstate matrix elements.");
185 {
187 if(info != 0) {
189 continue;
190 }
191 #ifdef GPU
192 magma_getmatrix(dim_sub, dim_sub,
sizeof(
Complex_t), dloc_tot.ptr(), dloc_tot.LD(), &*loc_tot.begin(), loc_tot.LD(),
GPUconf.
queue());
193 #else
194 loc_tot.copy(dloc_tot);
195 #endif
196 }
198
199#ifndef NDEBUG
200 if(dim_sub < 200) {
202 h.print(std::cout, 4, 4,
"All",
GPUconf);
204 loc.print(std::cout, 4, 4,
"All",
GPUconf);
206 loc_tot.print(dim_sub, dim_sub);
208 dloc_tot.print(std::cout, dim_sub, dim_sub,
"All",
GPUconf);
209 }
210#endif
211
214 double gE = eigenEnergy.at(0);
215 double EnergyRange = eigenEnergy.at(dim_sub-1) - gE;
216 #pragma omp parallel sections
217 {
218 #pragma omp section
219 {
220 std::stringstream
buff(
"");
221 buff <<
"/OffDiagonalElements" << PRECISION <<
"_N" << n <<
".txt";
222 std::string filename(outDirName); filename +=
buff.str();
224 OutMatElems << std::right << std::scientific << std::setprecision(6);
225 OutMatElems << " \n";
226
227
229 OutMatElems << (eigenEnergy.at(j) - gE) / EnergyRange << " "
230 << (eigenEnergy.at(k) - gE) / EnergyRange << " "
231 << eigenEnergy.at(j) << " "
232 << eigenEnergy.at(k) << " "
233 << real(fabs(loc_tot.at(j,k))) << "\n";
234 }
235 }
236 #pragma omp section
237 {
238 info =
EigenValues(OpEigenValue, dim_sub, dloc_tot);
239 if(info != 0) {
241 }
242 OpRange = OpEigenValue[dim_sub-1] - OpEigenValue[0];
243 std::stringstream
buff(
"");
244 buff <<
"/OperatorEigenValues" << PRECISION <<
"_N" << n <<
".txt";
245 std::string filename(outDirName); filename +=
buff.str();
247 OutOpEigV << std::right << std::scientific << std::showpos << std::setprecision(6);;
248 OutOpEigV << "# dim = " << dim_sub << "\n";
249 for(int i = 0;i < OpEigenValue.size(); ++i) OutOpEigV << OpEigenValue[i] << "\n";
250 OutOpEigV.close();
251 }
252 #pragma omp section
253 {
254 std::stringstream
buff(
"");
255 buff <<
"/EigenEnergies" << PRECISION <<
"_N" << n <<
".txt";
256 std::string filename(outDirName); filename +=
buff.str();
258 OutEnergy << std::right << std::scientific << std::showpos << std::setprecision(6);
259 OutEnergy << "# dim = " << dim_sub << "\n";
260 for(int i = 0;i < eigenEnergy.size(); ++i) OutEnergy << eigenEnergy[i] << "\n";
261 OutEnergy.close();
262 }
263 }
264 OutMatElems.seekp(0, std::ios_base::beg);
265 OutMatElems << "# OpRange= " << OpRange << std::endl;
266 OutMatElems.close();
268
269 }
270 if(repetition%10 == 9) {
272 std::cerr << "(total=" << std::setw(6) << repetition+1
273 << "): timeINT=" << std::setprecision(6) << std::setw(8) << (end-t_int)
274 << ", timeTOT=" << std::setprecision(6) << std::setw(8) << (end-start)
275 << ", T_construct=" << std::setprecision(6) << std::setw(10) << T_pre << "(" << std::setprecision(1) << 100*T_pre /(end-start) << "%)"
276 << ", T_diag=" << std::setprecision(6) << std::setw(8) << T_diag << "(" << std::setprecision(1) << 100*T_diag/(end-start) << "%)"
277 << ", T_process=" << std::setprecision(6) << std::setw(8) << T_post << "(" << std::setprecision(1) << 100*T_post/(end-start) << "%)"
278 << std::endl;
279 }
280 }
281
282 Finalize(argc, argv);
283 #ifdef GPU
284 magma_finalize();
285 #endif
286 return 0;
287}
double getETtime()
Definition EnergySpectrum.c:14
std::vector< TransSector > Sector(n_max+1)
Definition mytypes.hpp:147
void queue(magma_queue_t x)
Definition mytypes.hpp:297
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)
MKL_INT Integer_t
Definition mytypes.hpp:359
Integer_t const num_op
Definition setVariablesForEnsemble.cpp:39
baseDirName
Definition setVariablesForEnsemble.cpp:50
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
Integer_t EigenValues(std::vector< double > &Eigenvalue, Integer_t const dim, matrix< Complex_t< double > > &Hamiltonian)
Definition statmech.cpp:19
Integer_t EigenMatrixElements(std::vector< double > &Eigenvalue, Integer_t const dim, matrix< Complex_t< double > > &Hamiltonian, matrix< Complex_t< double > > &Operator, void *GPUconf)
Definition statmech.cpp:89
std::stringstream buff("")