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

Classes

struct  statm_t
 

Functions

void read_off_memory_status (statm_t &result)
 
int main (int argc, char **argv)
 

Variables

namespace filesystem = std::experimental::filesystem
 
statm_t Usage
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)
84 {
85 #define USAGE_commom "Usage: 1.This 2.n_max 3.n_min 4.division No. 5.Output dir "
86 #define Nargs_common 5
87 #define USAGE_opt "(Opt1).dE (Opt2).repMin (Opt3).repMax "
88 #define Nargs_opt 3
91
92 Integer_t dim_sub; //全ヒルベルト空間の次元
93 Integer_t ndata, info, failed=0; // カウンタ
94 double gE, EnergyRange, OpRange, OpMin;
95 double Fluc, MaxFluc, MaxPos; // ETHの指標
96 debug_print("# Successfully initialized.");
97 //******************** Check for the directory structure ********************
98 debug_print("# Checking for the directory structure.");
100 std::ofstream OutSample;
101 //******************** (END) Check for the directory structure ********************
102
103 //***************************************************************************
104 //******************** Allocation & Initialization **************************
105 //***************************************************************************
106#ifdef GPU
107 magma_init();
108 magma_queue_t queue = NULL;
109 magma_int_t dev = 0;
110 magma_getdevice( &dev );
111 magma_queue_create( dev, &queue );
112#else
113 void* GPUconf = nullptr;
114#endif
115
116 //******************** Translation invariance ********************
117 debug_print("# Calculating translation-invariant sectors.");
119 for(Integer_t n = n_max;n >= n_min; --n) {
120 OutMeasure[n] << "# (n=" << n << ") dim=" << Sector[n].dim() << "\n"
121 << "# 1.(Sample No.) 2.(Fluc_2) 3.(Fluc_infty) 4.(Pos_max_flux) 5.(ndata)\n"
122 << std::endl << std::scientific;
123 }
124 //******************** (END)Translation invariance ********************
125
126 //********** Allocate CPU memories **********//
127 debug_print("# Allocating CPU memories.");
128 Integer_t const dim_max = Sector[n_max].dim();
129 std::vector<Integer_t> NdataInShell(dim_max);
130 std::vector<double> eigenEnergy(dim_max);
131 std::vector<double> EXPvalue(dim_max);
132 std::vector<double> MCAverage(dim_max);
133#ifndef GPU
134 matrix<Complex_t> h_tot(dim_max, dim_max);
135 matrix<Complex_t> loc_tot(dim_max, dim_max);
136 #define dh_tot h_tot
137 #define dloc_tot loc_tot
138#endif
139 //********** (END) Allocate CPU memories **********//
140
141#ifdef GPU
142 //********** Allocate GPU memories **********//
143 debug_print("# Allocating GPU memories.");
144 constexpr Integer_t GPU_UNIT = 32;
145 Integer_t const LDT = magma_roundup(dim_max, GPU_UNIT);
146 matrix_gpu<Complex_t> dh_tot(LDT, dim_max);
147 matrix_gpu<Complex_t> dloc_tot(LDT, dim_max);
148 //********** (END) Allocate GPU memories **********//
149
150 //********** Determine GPU configuration **********//
152 //********** (END) Determine GPU configuration **********//
153#endif // #ifdef GPU
154
155 double start, t_int, end, temp_t;
156 double T_diag=0, T_post=0, T_pre=0;
157 init_genrand(SEED);
158 start = getETtime();
159 for(Integer_t repetition = 0;repetition < repMin; ++repetition) {
160 for(Integer_t n = n_min;n <= n_max; ++n) {
161 RandomMatrix_GUE(h_tot, Sector[n].dim());
162 RandomMatrix_GUE(loc_tot, Sector[n].dim());
163 }
164 }
165 end = getETtime();
166 std::cout << "(init_genrand): time=" << std::fixed << (end-start) << std::endl;
167 //***************************************************************************
168 //******************** (END) Allocation & Initialization ********************
169 //***************************************************************************
170
171 start = getETtime();
172 end = start;
173 for(Integer_t repetition = repMin;repetition <= repMax; ++repetition) {
174 // 局所ハミルトニアンと局所物理量をランダムにとる ******************************//
175 #if !defined(NDEBUG) && defined(__linux__)
177 std::cerr << "# (GPU, rep= " << std::setw(6) << repetition
178 << ") size=" << Usage.size
179 << ", resident=" << Usage.resident
180 << ", share=" << Usage.share
181 << ", text=" << Usage.text
182 << ", lib=" << Usage.lib
183 << ", data=" << Usage.data
184 << ", dt=" << Usage.dt
185 << std::endl;
186 #endif
187
188 if(repetition < 10000) {
190 }
191 for(Integer_t n = n_max;n >= n_min; --n) {
192 debug_print("# (rep,n)=(" << repetition << "," << n << ")");
193 debug_print("# Constructing global matrices in the sector.");
194 dim_sub = Sector[n].dim();
195 temp_t = getETtime();
196 {
197 RandomMatrix_GUE(h_tot, dim_sub);
198 RandomMatrix_GUE(loc_tot, dim_sub);
199 #ifdef GPU
200 magma_setmatrix(dim_sub, dim_sub, sizeof(Complex_t), &*h_tot.begin(), dim_sub, dh_tot.ptr(), dim_sub, GPUconf.queue());
201 magma_setmatrix(dim_sub, dim_sub, sizeof(Complex_t), &*loc_tot.begin(), dim_sub, dloc_tot.ptr(), dim_sub, GPUconf.queue());
202 #endif
203 }
204 T_pre += getETtime() -temp_t;
205
206 debug_print("# Calculating eigenstate expectation values.");
207 temp_t = getETtime();
208 info = EigenExpValue(EXPvalue, eigenEnergy, dim_sub, dh_tot, dloc_tot, GPUconf);
209 if(info != 0) {
210 failed += 1;
211 std::stringstream buff("");
212 buff << "/Failed " << PRECISION << "_N" << n << "_No" << repetition << ".txt";
213 std::string filename(baseDirName); filename += buff.str();
214 std::ofstream ErrFs;
215 ErrFs.open(filename);
216 if( !ErrFs.is_open() ) {
217 std::cerr << "# Warning: Can't open a file " << filename << ". Continue..." << std::endl;
218 } else {
219 ErrFs << "# info=" << info << "\n\n"
220 "# N=" << n << ", repetition=" << repetition << "\n";
221 if(dim_sub < 20) {
222 ErrFs << "# Total Hamiltonian\n";
223 dh_tot.print( ErrFs,dim_sub,dim_sub,"All", GPUconf);
224 ErrFs << "# Total operator\n";
225 dloc_tot.print(ErrFs,dim_sub,dim_sub,"All", GPUconf);
226 }
227 ErrFs.close();
228 }
229 continue;
230 }
231 debug_print("# Calculating the spectral range of the observable.");
232 OpRange = SpectralRange(OpMin, dim_sub, dloc_tot);
233 T_diag += getETtime() -temp_t;
234
235 debug_print("# Calculating measures of the ETH.");
236 temp_t = getETtime();
237 {
238 EnergyRange = eigenEnergy[dim_sub-1] -eigenEnergy[0];
239 gE = eigenEnergy[0];
240 for(Integer_t i = 0;i < dim_sub; ++i) {
241 eigenEnergy[i] = (eigenEnergy[i] -gE)/EnergyRange;
242 EXPvalue[i] /= OpRange;
243 }
244
245 // Calculate Microcanonical averages with energy corresponding to each eigenstate.
246 MCAverage.resize(dim_sub); NdataInShell.resize(dim_sub);
247 std::fill( MCAverage.begin(), MCAverage.end(), 0.0);
248 std::fill(NdataInShell.begin(), NdataInShell.end(), 0.0);
249 for(Integer_t i = 0;i < dim_sub; ++i) {
250 MCAverage[i] = MicroCanonicalAverage(NdataInShell[i], eigenEnergy[i], dE, dim_sub, eigenEnergy, EXPvalue, i);
251 }
252
253 ndata = MeasureOfETH(Fluc, MaxFluc, MaxPos, Emin, Emax, dim_sub, eigenEnergy, EXPvalue, MCAverage);
254 }
255 T_post += getETtime() -temp_t;
256
257 OutMeasure[n] << std::setw(6) << repetition << " " << std::showpos
258 << std::setw(13) << Fluc << " "
259 << std::setw(13) << MaxFluc << " "
260 << std::setw(13) << MaxPos << " " << std::noshowpos << ndata << "\n";
261 if(repetition < 10000) {
262 for(Integer_t i = 0;i < dim_sub; ++i) {
263 OutSample << std::setw(2) << n << " " << std::showpos
264 << std::setw(13) << eigenEnergy[i]*EnergyRange+gE << " "
265 << std::setw(13) << eigenEnergy[i] << " "
266 << std::setw(13) << EXPvalue[i] << "\n" << std::noshowpos;
267 }
268 }
269 }
270 if(repetition < 10000) OutSample.close();
271 if(repetition%10 == 9) {
272 t_int = end; end = getETtime();
273 std::cerr << "(total=" << std::setw(6) << repetition+1
274 << "): timeINT=" << std::setprecision(6) << std::setw(8) << (end-t_int)
275 << ", timeTOT=" << std::setprecision(6) << std::setw(8) << (end-start)
276 << ", T_construct=" << std::setprecision(6) << std::setw(10) << T_pre << "(" << std::setprecision(1) << 100*T_pre /(end-start) << "%)"
277 << ", T_diag=" << std::setprecision(6) << std::setw(8) << T_diag << "(" << std::setprecision(1) << 100*T_diag/(end-start) << "%)"
278 << ", T_process=" << std::setprecision(6) << std::setw(8) << T_post << "(" << std::setprecision(1) << 100*T_post/(end-start) << "%)"
279 << std::endl;
280 for(Integer_t n = n_min;n <= n_max; ++n) OutMeasure[n].flush();
281 }
282 }
283
284 return 0;
285}
double getETtime()
Definition EnergySpectrum.c:14
std::ofstream OutMeasure[n_max+1]
Definition MeasureOfETH_CreateOutputFiles.cpp:1
statm_t Usage
Definition Fluc_randHOp.cpp:55
void read_off_memory_status(statm_t &result)
Definition Fluc_randHOp.cpp:98
std::vector< TransSector > Sector(n_max+1)
Definition mytypes.hpp:147
void queue(magma_queue_t x)
Definition mytypes.hpp:297
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
baseDirName
Definition setVariablesForEnsemble.cpp:50
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 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
double SpectralRange(double &OpMin, Integer_t const dim, matrix< Complex_t< double > > &Operator)
Definition statmech.cpp:49
unsigned long dt
Definition Fluc_randHOp.cpp:95
unsigned long lib
Definition Fluc_randHOp.cpp:95
unsigned long text
Definition Fluc_randHOp.cpp:95
unsigned long resident
Definition Fluc_randHOp.cpp:95
unsigned long share
Definition Fluc_randHOp.cpp:95
unsigned long size
Definition Fluc_randHOp.cpp:95
unsigned long data
Definition Fluc_randHOp.cpp:95
std::stringstream buff("")

◆ read_off_memory_status()

void read_off_memory_status ( statm_t result)
58 {
59 const char* statm_path = "/proc/self/statm";
60
61 FILE *f = fopen(statm_path,"r");
62 if(!f){
63 perror(statm_path);
64 abort();
65 }
66 if(7 != fscanf(f,"%ld %ld %ld %ld %ld %ld %ld",
67 &result.size,&result.resident,&result.share,&result.text,&result.lib,&result.data,&result.dt))
68 {
69 perror(statm_path);
70 abort();
71 }
72 fclose(f);
73 }

Variable Documentation

◆ filesystem

namespace filesystem = std::experimental::filesystem

◆ Usage

statm_t Usage