StatMech
Loading...
Searching...
No Matches
Fluc_randHOp.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 
)
59 {
60 #define USAGE_opt "(Opt1).dE (Opt2).repMin (Opt3).repMax "
61 #define Nargs_opt 3
64
65 Integer_t dim_sub; //全ヒルベルト空間の次元
66 Integer_t ndata, info, failed=0; // カウンタ
67 double gE, EnergyRange, OpRange, OpEigMin, OpEigMax, s;
68 double Fluc, MaxFluc, MaxPos;
69
70 if( num_h!=2 || num_op !=2 ) {
71 std::cerr << "Error: Currently, num_h and num_op must be two." << std::endl;
72 std::exit(EX_USAGE);
73 }
74 if( !Initialize(argc, argv, Nargs_common) ) {
75 std::cerr << "Error: Initialization failed." << std::endl;
76 std::exit(EX_USAGE);
77 }
78 debug_print("# Successfully initialized.");
79
80 //******************** Check for the directory structure ********************
81 debug_print("# Checking for the directory structure.");
83 std::ofstream OutSample;
84 //******************** (END) Check for the directory structure ********************
85
86 //***************************************************************************
87 //******************** Allocation & Initialization **************************
88 //***************************************************************************
89#ifdef GPU
90 magma_init();
91 magma_queue_t queue = NULL;
92 magma_int_t dev = 0;
93 magma_getdevice( &dev );
94 magma_queue_create( dev, &queue );
95#else
96 void* GPUconf = nullptr;
97#endif
98
99 //******************** Translation invariance ********************
100 debug_print("# Calculating translation-invariant sectors.");
102 for(Integer_t n = n_max;n >= n_min; --n) {
103 OutMeasure[n] << "# (n=" << n << ") dim=" << Sector[n].dim() << "\n"
104 << "# 1.(Sample No.) 2.(Fluc_2) 3.(Fluc_infty) 4.(Pos_max_flux) 5.(ndata)\n"
105 << std::endl << std::scientific;
106 }
107 //******************** (END)Translation invariance ********************
108
109 //******************** SU(2) structure ********************
110 debug_print("# Calculating multiplicity of irreducible representations of SU(2) algebra.");
111 std::vector<std::vector<Integer_t>> multiplicity(n_max+1);
112 {
113 Integer_t numUpSpins;
114 std::vector<Integer_t> numBasisWithFixedM, spin(n_max);
115 for (Integer_t n = n_max;n >= n_min; --n) {
116 if(Sector[n].momentum() == 0) dim_sub = Sector[n].dim() - Sector[n].parityOp().numPairs;
117 else dim_sub = Sector[n].dim();
118
119 spin.resize(n);
120 numBasisWithFixedM.resize(n+1);
121 std::fill(numBasisWithFixedM.begin(), numBasisWithFixedM.end(), 0);
122 for(Integer_t j = 0;j < dim_sub; ++j) {
123 i_to_spin(Sector[n].representative(j), spin, 2, n);
124 numUpSpins = std::accumulate(spin.begin(), spin.end(), 0);
125 numBasisWithFixedM.at(numUpSpins) += 1;
126 }
127
128 multiplicity[n].resize(n/2+1);
129 multiplicity[n][n/2] = numBasisWithFixedM[n];
130 for(Integer_t j = n-1;j >= (n+1)/2; --j) {
131 multiplicity[n][ j-(n+1)/2 ] = numBasisWithFixedM[j] - numBasisWithFixedM[j+1];
132 }
133
134 print(numBasisWithFixedM, numBasisWithFixedM.size());
135 print(multiplicity[n], multiplicity[n].size());
136 }
137 }
138 //******************** (END) SU(2) structure ********************
139
140 //********** Allocate CPU memories **********//
141 debug_print("# Allocating CPU memories.");
142 Integer_t const dim_max = n_max+1;
143 std::vector<Integer_t> NdataInShell(dim_max);
144 std::vector<double> eigenEnergy(dim_max);
145 std::vector<double> EXPvalue(dim_max);
146 std::vector<double> MCAverage(dim_max);
147 std::vector<std::tuple<double,double,Integer_t>> Data;
148 if(n_max >= 3) Data.reserve(n_max*n_max); else Data.reserve(4);
149 matrix<Complex_t> h(dloc_h , dloc_h );
150 matrix<Complex_t> loc(dloc_op, dloc_op);
151 matrix<Complex_t> h_tot(dim_max, dim_max);
152 matrix<Complex_t> loc_tot(dim_max, dim_max);
153#ifndef GPU
154 #define dh_tot h_tot
155 #define dloc_tot loc_tot
156#endif
157 //********** (END) Allocate CPU memories **********//
158
159#ifdef GPU
160 //********** Allocate GPU memories **********//
161 debug_print("# Allocating GPU memories.");
162 constexpr Integer_t GPU_UNIT = 32;
163 Integer_t const LDT = magma_roundup(dim_max, GPU_UNIT);
164 matrix_gpu<Complex_t> dh(dloc_h , dloc_h );
165 matrix_gpu<Complex_t> dloc(dloc_op, dloc_op);
166 matrix_gpu<Complex_t> dh_tot(LDT, dim_max);
167 matrix_gpu<Complex_t> dloc_tot(LDT, dim_max);
168 //********** (END) Allocate GPU memories **********//
169
170 #inlude "PBC_TI/Framework/Fragments/getAttributesOfMatrixElementsInSector.cpp"
171#endif // #ifdef GPU
172
173 double start, t_int, end, temp_t;
174 double T_diag=0, T_post=0, T_pre=0;
175 init_genrand(SEED);
176 start = getETtime();
177 for(Integer_t repetition = 0;repetition < repMin; ++repetition) {
178 generateLocal_h( h, dloc_h, -1);
179 generateLocal_op(loc, dloc_op, -1);
180 }
181 end = getETtime();
182 std::cout << "(init_genrand): time=" << std::fixed << (end-start) << std::endl;
183 //***************************************************************************
184 //******************** (END) Allocation & Initialization ********************
185 //***************************************************************************
186
187 start = getETtime();
188 end = start;
189 for(Integer_t repetition = repMin;repetition <= repMax; ++repetition) {
190 // 局所ハミルトニアンと局所物理量をランダムにとる ******************************//
191 generateLocal_h( h, dloc_h, -1);
192 generateLocal_op(loc, dloc_op, -1);
193 #ifdef GPU
194 magma_setmatrix(dloc_h, dloc_h, sizeof(Complex_t), &*h.begin(), dloc_h, dh.ptr(), dloc_h, queue);
195 magma_setmatrix(dloc_op, dloc_op, sizeof(Complex_t), &*loc.begin(), dloc_op, dloc.ptr(), dloc_op, queue);
196 #endif
197
198 if(repetition < 10000) {
200 }
201 for(Integer_t n = n_max;n >= n_min; --n) {
202 debug_print("# (rep,n)=(" << repetition << "," << n << ")");
203 debug_print("# Constructing global matrices in the sector.");
204 Data.resize(0); OpEigMin = NAN; OpEigMax = NAN;
205 for(Integer_t Sint = n/2;Sint >= 0; --Sint) {
206 s = n/2.0 - Sint;
207 temp_t = getETtime();
208 #ifdef GPU
209 // constructGlobal_h( dh_tot, dh, num_h, Sector.at(n), conf);
210 // constructGlobal_op(dloc_tot, dloc, num_op, Sector.at(n), conf);
211 // magma_queue_sync(queue);
212 dim_sub = constructGlobal_h( h_tot, h, s, Sector.at(n));
213 constructGlobal_h( loc_tot, loc, s, Sector.at(n));
214 magma_setmatrix(dim_sub, dim_sub, sizeof(Complex_t), &*h_tot.begin(), h_tot.LD(), dh_tot.ptr(), dh_tot.LD(), queue);
215 magma_setmatrix(dim_sub, dim_sub, sizeof(Complex_t), &*loc_tot.begin(), loc_tot.LD(), dloc_tot.ptr(), dh_tot.LD(), queue);
216 #else
217 dim_sub = constructGlobal_h( h_tot, h, s, Sector.at(n));
218 constructGlobal_h( loc_tot, loc, s, Sector.at(n));
219 #endif
220 T_pre += getETtime() -temp_t;
221
222
223 debug_print("# Calculating eigenstate expectation values." << dim_sub << " " << dh_tot.LD());
224 temp_t = getETtime();
225 info = EigenExpValue(EXPvalue, eigenEnergy, dim_sub, dh_tot, dloc_tot, conf.queue());
226 if(info != 0) {
228 continue;
229 }
230 for(Integer_t j = 0;j < dim_sub; ++j) {
231 Data.push_back( std::tie(eigenEnergy[j], EXPvalue[j], multiplicity[n][Sint]) );
232 }
233 debug_print("# Calculating the spectral range of the observable.");
234 Diagonalize(dim_sub, dloc_tot, eigenEnergy);
235 OpEigMin = std::fmin(OpEigMin, eigenEnergy[0]);
236 OpEigMax = std::fmin(OpEigMax, eigenEnergy[dim_sub-1]);
237 T_diag += getETtime() -temp_t;
238 }
239
240 if(Data.size() != (size_t)( (n/2+1)*( (n+1)/2+1 ) )) {
241 std::cerr << "Error:: Data.size(" << Data.size() << ") != (n/2+1)*( (n+1)/2+1 ) = " << (n/2+1)*( (n+1)/2+1 ) << std::endl;
242 std::exit(1);
243 }
244
245 std::sort(Data.begin(), Data.end());
246 OpRange = OpEigMax - OpEigMin;
247
248 debug_print("# Calculating measures of the ETH.");
249 temp_t = getETtime();
250 EnergyRange = std::get<0>(Data[Data.size()-1]) - std::get<0>(Data[0]);
251 gE = std::get<0>(Data[0]);
252 for(Integer_t i = 0;i < Data.size(); ++i) {
253 std::get<0>(Data[i]) = (std::get<0>(Data[i]) -gE)/EnergyRange;
254 std::get<1>(Data[i]) = std::get<1>(Data[i])/OpRange;
255 }
256 MicroCanonicalAverage(MCAverage, NdataInShell, dE, Data);
257 ndata = MeasureOfETH(Fluc, MaxFluc, MaxPos, Emin, Emax, MCAverage, Data);
258 T_post += getETtime() -temp_t;
259
260 OutMeasure[n] << std::setw(6) << repetition << " " << std::showpos
261 << std::setw(13) << Fluc << " "
262 << std::setw(13) << MaxFluc << " "
263 << std::setw(13) << MaxPos << " " << std::noshowpos << ndata << "\n";
264 if(repetition < 10000) {
265 for(Integer_t i = 0;i < dim_sub; ++i) {
266 OutSample << std::setw(2) << n << " " << std::showpos
267 << std::setw(13) << std::get<0>(Data[i])*EnergyRange+gE << " "
268 << std::setw(13) << std::get<0>(Data[i]) << " "
269 << std::setw(13) << std::get<1>(Data[i]) << "\n" << std::noshowpos;
270 }
271 }
272 }
273 if(repetition < 10000) OutSample.close();
274 if(repetition%10 == 9) {
275 t_int = end; end = getETtime();
276 std::cerr << "(total=" << std::setw(6) << repetition+1
277 << "): timeINT=" << std::setprecision(6) << std::setw(8) << (end-t_int)
278 << ", timeTOT=" << std::setprecision(6) << std::setw(8) << (end-start)
279 << ", T_construct=" << std::setprecision(6) << std::setw(10) << T_pre << "(" << std::setprecision(1) << 100*T_pre /(end-start) << "%)"
280 << ", T_diag=" << std::setprecision(6) << std::setw(8) << T_diag << "(" << std::setprecision(1) << 100*T_diag/(end-start) << "%)"
281 << ", T_process=" << std::setprecision(6) << std::setw(8) << T_post << "(" << std::setprecision(1) << 100*T_post/(end-start) << "%)"
282 << std::endl;
283 for(Integer_t n = n_min;n <= n_max; ++n) OutMeasure[n].flush();
284 }
285 }
286
287 Finalize(argc, argv);
288 return 0;
289}
double getETtime()
Definition EnergySpectrum.c:14
std::ofstream OutMeasure[n_max+1]
Definition MeasureOfETH_CreateOutputFiles.cpp:1
std::vector< TransSector > Sector(n_max+1)
Definition mytypes.hpp:147
Calculate the microcanonical averages with respect to a given sorted vector 'eigVal'.
Definition MicroCanonicalAverage.hpp:25
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
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
constexpr double Emin
Definition setVariablesForMCAverage.cpp:4
constexpr double Emax
Definition setVariablesForMCAverage.cpp:5
double const dE
Definition setVariablesForMCAverage.cpp:2
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
Integer_t MeasureOfETH(double &Fluc_2, double &Fluc_inf, double &MaxPos, double const Emin, double const Emax, Integer_t const dim, const std::vector< double > &eigenEnergy, const std::vector< double > &EXPvalue, const std::vector< double > &MCAverage)
Definition statmech.cpp:244
Integer_t Diagonalize(Integer_t const dim, matrix< Complex_t< double > > &Hamiltonian, std::vector< double > &Eigenvalue)
Definition statmech.cpp:56
__constant__ int size
Definition testEigenOnGPU.cu:4
void i_to_spin(int i, int *spin, int dim_loc, int n)
Definition translation.c:78

Variable Documentation

◆ filesystem

namespace filesystem = std::experimental::filesystem