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 #pragma omp parallel sections
215 {
216 #pragma omp section
217 {
218 std::stringstream
buff(
"");
219 buff <<
"/EigenMatrixElements" << PRECISION <<
"_N" << n <<
".txt";
220 std::string filename(outDirName); filename +=
buff.str();
222 OutMatElems << std::right << std::scientific << std::setprecision(6);
223 OutMatElems << " \n";
224 if(argc >
Nargs) loc_tot.printAbs(OutMatElems, dim_sub, dim_sub,
"Lower");
225 else loc_tot.print(OutMatElems, dim_sub, dim_sub, "Lower");
226 }
227 #pragma omp section
228 {
229 info =
EigenValues(OpEigenValue, dim_sub, dloc_tot);
230 if(info != 0) {
232 }
233 OpRange = OpEigenValue[dim_sub-1] - OpEigenValue[0];
234 std::stringstream
buff(
"");
235 buff <<
"/OperatorEigenValues" << PRECISION <<
"_N" << n <<
".txt";
236 std::string filename(outDirName); filename +=
buff.str();
238 OutOpEigV << std::right << std::scientific << std::showpos << std::setprecision(6);;
239 OutOpEigV << "# dim = " << dim_sub << "\n";
240 for(int i = 0;i < OpEigenValue.size(); ++i) OutOpEigV << OpEigenValue[i] << "\n";
241 OutOpEigV.close();
242 }
243 #pragma omp section
244 {
245 std::stringstream
buff(
"");
246 buff <<
"/EigenEnergies" << PRECISION <<
"_N" << n <<
".txt";
247 std::string filename(outDirName); filename +=
buff.str();
249 OutEnergy << std::right << std::scientific << std::showpos << std::setprecision(6);
250 OutEnergy << "# dim = " << dim_sub << "\n";
251 for(int i = 0;i < eigenEnergy.size(); ++i) OutEnergy << eigenEnergy[i] << "\n";
252 OutEnergy.close();
253 }
254 }
255 OutMatElems.seekp(0, std::ios_base::beg);
256 OutMatElems << "# OpRange= " << OpRange << std::endl;
257 OutMatElems.close();
259
260 }
261 if(repetition%10 == 9) {
263 std::cerr << "(total=" << std::setw(6) << repetition+1
264 << "): timeINT=" << std::setprecision(6) << std::setw(8) << (end-t_int)
265 << ", timeTOT=" << std::setprecision(6) << std::setw(8) << (end-start)
266 << ", T_construct=" << std::setprecision(6) << std::setw(10) << T_pre << "(" << std::setprecision(1) << 100*T_pre /(end-start) << "%)"
267 << ", T_diag=" << std::setprecision(6) << std::setw(8) << T_diag << "(" << std::setprecision(1) << 100*T_diag/(end-start) << "%)"
268 << ", T_process=" << std::setprecision(6) << std::setw(8) << T_post << "(" << std::setprecision(1) << 100*T_post/(end-start) << "%)"
269 << std::endl;
270 }
271 }
272
273 Finalize(argc, argv);
274 #ifdef GPU
275 magma_finalize();
276 #endif
277 return 0;
278}
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
constexpr int Nargs
Definition setVariablesForEnsemble.cpp:14
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("")