StatMech
Loading...
Searching...
No Matches
EigenExpValue copy.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 
)
53 {
55
56 Integer_t dim_sub; //全ヒルベルト空間の次元
57 Integer_t info, failed=0; // カウンタ
58 double gE, EnergyRange, OpRange, OpMin;
59
60 if( !Initialize(argc, argv, Nargs_common) ) {
61 std::cerr << "Error: Initialization failed." << std::endl;
62 std::exit(EX_USAGE);
63 }
64 debug_print("# Successfully initialized.");
65
66 //******************** Check for the directory structure ********************
67 debug_print("# Checking for the directory structure.");
68 std::ofstream OutFs;
69 //******************** (END) Check for the directory structure ********************
70
71 //***************************************************************************
72 //******************** Allocation & Initialization **************************
73 //***************************************************************************
74#ifdef GPU
75 magma_init();
76 magma_queue_t queue = NULL;
77 magma_int_t dev = 0;
78 magma_getdevice( &dev );
79 magma_queue_create( dev, &queue );
80#else
81 void* GPUconf = nullptr;
82#endif
83
84 //******************** Translation invariance ********************
85 debug_print("# Calculating translation-invariant sectors.");
87 //******************** (END)Translation invariance ********************
88
89 //********** Allocate CPU memories **********//
90 debug_print("# Allocating CPU memories.");
91 Integer_t const dim_max = SectorDimension(Sector[n_max]);
92 std::vector<Integer_t> NdataInShell(dim_max);
93 std::vector<double> eigenEnergy(dim_max);
94 std::vector<double> EXPvalue(dim_max);
95 matrix<Complex_t> h(dloc_h , dloc_h );
96 matrix<Complex_t> loc(dloc_op, dloc_op);
97#ifndef GPU
98 matrix<Complex_t> h_tot(dim_max, dim_max);
99 matrix<Complex_t> loc_tot(dim_max, dim_max);
100 #define dh h
101 #define dloc loc
102 #define dh_tot h_tot
103 #define dloc_tot loc_tot
104#endif
105 //********** (END) Allocate CPU memories **********//
106
107#ifdef GPU
108 //********** Allocate GPU memories **********//
109 debug_print("# Allocating GPU memories.");
110 constexpr Integer_t GPU_UNIT = 32;
111 Integer_t const LDT = magma_roundup(dim_max, GPU_UNIT);
112 matrix_gpu<Complex_t> dh(dloc_h , dloc_h );
113 matrix_gpu<Complex_t> dloc(dloc_op, dloc_op);
114 matrix_gpu<Complex_t> dh_tot(LDT, dim_max);
115 matrix_gpu<Complex_t> dloc_tot(LDT, dim_max);
116 //********** (END) Allocate GPU memories **********//
117
118 //********** Determine GPU configuration **********//
120 //********** (END) Determine GPU configuration **********//
121#endif // #ifdef GPU
122
123 double start, t_int, end, temp_t;
124 double T_diag=0, T_post=0, T_pre=0;
125 init_genrand(SEED);
126 start = getETtime();
127 for(Integer_t repetition = 0;repetition < repMin; ++repetition) {
128 generateLocal_h( h, dloc_h, -1);
129 generateLocal_op(loc, dloc_op, -1);
130 }
131 end = getETtime();
132 std::cout << "(init_genrand): time=" << std::fixed << (end-start) << std::endl;
133 //***************************************************************************
134 //******************** (END) Allocation & Initialization ********************
135 //***************************************************************************
136
137 start = getETtime();
138 end = start;
139 for(Integer_t repetition = repMin;repetition <= repMax; ++repetition) {
140 // 局所ハミルトニアンと局所物理量をランダムにとる ******************************//
141 generateLocal_h( h, dloc_h, -1);
142 generateLocal_op(loc, dloc_op, -1);
143 h.print(dloc_h, dloc_h);
144 loc.print(dloc_op, dloc_op);
145
146 debug_print("# Seting matrix to GPU.");
147 #ifdef GPU
148 magma_setmatrix(dloc_h, dloc_h, sizeof(Complex_t), &*h.begin(), dloc_h, dh.ptr(), dloc_h, queue);
149 magma_setmatrix(dloc_op, dloc_op, sizeof(Complex_t), &*loc.begin(), dloc_op, dloc.ptr(), dloc_op, queue);
150 #endif
151 debug_print("# Set matrix to GPU.");
152
153 std::string outDirName(baseDirName);
154 {
155 std::stringstream buff;
156 buff << "/RawData/Sample_No" << repetition;
157 outDirName += buff.str();
158 outDirName = std::regex_replace(outDirName, std::regex("//"), "/");
159 filesystem::create_directories(outDirName);
160 }
161
162 for(size_t n = n_max;n >= n_min; --n) {
163 debug_print("# (rep,n)=(" << repetition << "," << n << ")");
164 debug_print("# Constructing global matrices in the sector.");
165 temp_t = getETtime();
166 {
167 dim_sub = constructGlobal_h( dh_tot, dh, num_h, Sector.at(n),GPUconf);
168 constructGlobal_op(dloc_tot, dloc, num_op, Sector.at(n),GPUconf);
169 #ifdef GPU
170 magma_queue_sync(queue);
171 #endif
172 }
173 T_pre += getETtime() -temp_t;
174
175 // magma_queue_sync(queue);
176 // std::cerr << "(N=" << n << ") isnan_kernel(dh_tot) before" << std::endl;
177 // isnan_kernel<<<conf.dimGrid(),conf.dimBlock(),conf.shared(),conf.stream()>>>(dim_sub, dh_tot.ptr(), dh_tot.LD());
178 // magma_queue_sync(queue);
179 // std::cerr << "(N=" << n << ") isnan_kernel(dloc_tot) before" << std::endl;
180 // isnan_kernel<<<conf.dimGrid(),conf.dimBlock(),conf.shared(),conf.stream()>>>(dim_sub, dloc_tot.ptr(), dloc_tot.LD());
181 // magma_queue_sync(queue);
182
183 temp_t = getETtime();
184 {
185 debug_print("# Calculating eigenstate expectation values.");
186 info = EigenExpValue(EXPvalue, eigenEnergy, dim_sub, dh_tot, dloc_tot,GPUconf);
187 if(info != 0) {
189 continue;
190 }
191 EnergyRange = eigenEnergy[dim_sub-1] - eigenEnergy[0];
192 gE = eigenEnergy[0];
193 debug_print("# Calculating the spectral range of the observable.");
194 OpRange = SpectralRange(OpMin, dim_sub, dloc_tot);
195 }
196 T_diag += getETtime() -temp_t;
197
198 // magma_queue_sync(queue);
199 // std::cerr << "(N=" << n << ") isnan_kernel(dh_tot) after" << std::endl;
200 // isnan_kernel<<<conf.dimGrid(),conf.dimBlock(),conf.shared(),conf.stream()>>>(dim_sub, dh_tot.ptr(), dh_tot.LD());
201 // magma_queue_sync(queue);
202 // std::cerr << "(N=" << n << ") isnan_kernel(dloc_tot) after" << std::endl;
203 // isnan_kernel<<<conf.dimGrid(),conf.dimBlock(),conf.shared(),conf.stream()>>>(dim_sub, dloc_tot.ptr(), dloc_tot.LD());
204 // magma_queue_sync(queue);
205
206 temp_t = getETtime();
207 {
208 debug_print("# Writing results to a file.");
209 std::stringstream buff("");
210 buff << "/EigenExpValue" << PRECISION << "_N" << n << ".txt";
211 std::string filename(outDirName); filename += buff.str();
212 OutFs.open(filename); checkIsFileOpen(OutFs, filename);
213 OutFs << std::right << std::showpos << std::scientific << std::setprecision(6);
214 OutFs << "# energyRange= " << EnergyRange << "\n"
215 << "# gE= " << gE << "\n"
216 << "# OpRange= " << OpRange << "\n"
217 << "# OpMin= " << OpMin << "\n"
218 << "# 1.(Normalized energy) 2.(Energy) 3.(Exp value)" << "\n\n";
219 for(size_t j = 0;j < dim_sub; ++j) {
220 OutFs << (eigenEnergy[j] - gE)/EnergyRange << " "
221 << eigenEnergy[j] << " "
222 << EXPvalue[j] << std::endl;
223 }
224 OutFs.close();
225 }
226 T_post += getETtime() -temp_t;
227 }
228 if(repetition%10 == 9) {
229 t_int = end; end = getETtime();
230 std::cerr << "(total=" << std::setw(6) << repetition+1
231 << "): timeINT=" << std::setprecision(6) << std::setw(8) << (end-t_int)
232 << ", timeTOT=" << std::setprecision(6) << std::setw(8) << (end-start)
233 << ", T_construct=" << std::setprecision(6) << std::setw(10) << T_pre << "(" << std::setprecision(1) << 100*T_pre /(end-start) << "%)"
234 << ", T_diag=" << std::setprecision(6) << std::setw(8) << T_diag << "(" << std::setprecision(1) << 100*T_diag/(end-start) << "%)"
235 << ", T_process=" << std::setprecision(6) << std::setw(8) << T_post << "(" << std::setprecision(1) << 100*T_post/(end-start) << "%)"
236 << std::endl;
237 }
238 }
239
240 Finalize(argc, argv);
241 #ifdef GPU
242 magma_finalize();
243 #endif
244 return 0;
245}
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)
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 EigenExpValue(std::vector< double > &EXPvalue, std::vector< double > &Eigenvalue, Integer_t const dim, matrix< Complex_t< double > > &Hamiltonian, const matrix< Complex_t< double > > &Operator, void *GPUconf)
Definition statmech.cpp:120
double SpectralRange(double &OpMin, Integer_t const dim, matrix< Complex_t< double > > &Operator)
Definition statmech.cpp:49
std::stringstream buff("")

Variable Documentation

◆ filesystem

namespace filesystem = std::experimental::filesystem