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

Functions

int main (int argc, char **argv)
 

Variables

namespace filesystem = std::experimental::filesystem
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)
57 {
58 #define MAXDATA 100
59 #define SEED 0
61
62 Integer_t dim_sub; //全ヒルベルト空間の次元
63 Integer_t info=0, failed=0; // カウンタ
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 }
70 debug_print("# Successfully initialized.");
71
72 //******************** Check for the directory structure ********************
73 debug_print("# Checking for the directory structure.");
74 std::ofstream OutMatElems, OutEnergy, OutOpEigV;
75 //******************** (END) Check for the directory structure ********************
76
77 //***************************************************************************
78 //******************** Allocation & Initialization **************************
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
87 void* GPUconf = nullptr;
88#endif
89
90 //******************** Translation invariance ********************
91 debug_print("# Calculating translation-invariant sectors.");
93 //******************** (END)Translation invariance ********************
94
95 //********** Allocate CPU memories **********//
96 debug_print("# Allocating CPU memories.");
97 Integer_t const dim_max = SectorDimension(Sector[n_max]);
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);
102 matrix<Complex_t> h(dloc_h , dloc_h );
103 matrix<Complex_t> loc(dloc_op, dloc_op);
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 // #define dloc_tot loc_tot
111 matrix<Complex_t> dloc_tot(dim_max, dim_max);
112#endif
113 //********** (END) Allocate CPU memories **********//
114
115#ifdef GPU
116 //********** Allocate GPU memories **********//
117 debug_print("# Allocating GPU memories.");
118 constexpr Integer_t GPU_UNIT = 32;
119 Integer_t const LDT = magma_roundup(dim_max, GPU_UNIT);
120 matrix_gpu<Complex_t> dh(dloc_h , dloc_h );
121 matrix_gpu<Complex_t> dloc(dloc_op, dloc_op);
122 matrix_gpu<Complex_t> dh_tot(LDT, dim_max);
123 matrix_gpu<Complex_t> dloc_tot(LDT, dim_max);
124 //********** (END) Allocate GPU memories **********//
125
126 //********** Determine GPU configuration **********//
128 //********** (END) Determine GPU configuration **********//
129#endif // #ifdef GPU
130
131 double start, t_int, end, temp_t;
132 double T_diag=0, T_post=0, T_pre=0;
133 init_genrand(SEED);
134 start = getETtime();
135 for(Integer_t repetition = 0;repetition < repMin; ++repetition) {
136 generateLocal_h( h, dloc_h, -1);
137 generateLocal_op(loc, dloc_op, -1);
138 }
139 end = getETtime();
140 std::cout << "(init_genrand): time=" << std::fixed << (end-start) << std::endl;
141 //***************************************************************************
142 //******************** (END) Allocation & Initialization ********************
143 //***************************************************************************
144// #ifndef NDEBUG
145// std::string InFilename("/Users/Shoki/GitHub/temp/matrix.txt");
146// std::ifstream InFile(InFilename); checkIsFileOpen(InFile, InFilename);
147// debug_print("Input: " << InFilename);
148// #endif
149
150 start = getETtime();
151 end = start;
152 for(Integer_t repetition = repMin;repetition <= repMax; ++repetition) {
153 // 局所ハミルトニアンと局所物理量をランダムにとる ******************************//
154 generateLocal_h( h, dloc_h, -1);
155 generateLocal_op(loc, dloc_op, -1);
156
157 #ifdef GPU
158 magma_setmatrix(dloc_h, dloc_h, sizeof(Complex_t), &*h.begin(), dloc_h, dh.ptr(), dloc_h, GPUconf.queue());
159 magma_setmatrix(dloc_op, dloc_op, sizeof(Complex_t), &*loc.begin(), dloc_op, dloc.ptr(), dloc_op, GPUconf.queue());
160 #endif
161 std::string outDirName(baseDirName);
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
170 for(Integer_t n = n_max;n >= n_min; --n) {
171 debug_print("# (rep,n)=(" << repetition << "," << n << ")");
172 debug_print("# Constructing global matrices in the sector.");
173 temp_t = getETtime();
174 {
175 dim_sub = constructGlobal_h( dh_tot, dh, num_h, Sector.at(n), GPUconf);
176 constructGlobal_op(dloc_tot, dloc, num_op, Sector.at(n), GPUconf);
177 #ifdef GPU
178 magma_queue_sync(queue);
179 #endif
180 }
181 T_pre += getETtime() -temp_t;
182
183 debug_print("# Calculating eigenstate matrix elements.");
184 temp_t = getETtime();
185 {
186 info = EigenMatrixElements(eigenEnergy, dim_sub, dh_tot, dloc_tot, GPUconf);
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 }
197 T_diag += getETtime() -temp_t;
198
199#ifndef NDEBUG
200 if(dim_sub < 200) {
201 debug_print("# h");
202 h.print(std::cout, 4, 4, "All", GPUconf);
203 debug_print("# loc");
204 loc.print(std::cout, 4, 4, "All", GPUconf);
205 debug_print("# loc_tot");
206 loc_tot.print(dim_sub, dim_sub);
207 debug_print("# dloc_tot");
208 dloc_tot.print(std::cout, dim_sub, dim_sub, "All", GPUconf);
209 }
210#endif
211
212 debug_print("# Writing results to a file.");
213 temp_t = getETtime();
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();
223 OutMatElems.open(filename); checkIsFileOpen(OutMatElems, filename);
224 OutMatElems << std::right << std::scientific << std::setprecision(6);
225 OutMatElems << " \n";
226 // if(argc > Nargs) loc_tot.printAbs(OutMatElems, dim_sub, dim_sub, "Lower");
227 // else loc_tot.print(OutMatElems, dim_sub, dim_sub, "Lower");
228 for(Integer_t j = 0; j < dim_sub; ++j) for(Integer_t k = 0; k < j; ++k) {
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();
246 OutOpEigV.open(filename); checkIsFileOpen(OutOpEigV, filename);
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();
257 OutEnergy.open(filename); checkIsFileOpen(OutEnergy, filename);
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();
267 T_post += getETtime() -temp_t;
268
269 }
270 if(repetition%10 == 9) {
271 t_int = end; end = getETtime();
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("")

Variable Documentation

◆ filesystem

namespace filesystem = std::experimental::filesystem