HΦ  3.2.0
time.c
Go to the documentation of this file.
1 /* HPhi - Quantum Lattice Model Simulator */
2 /* Copyright (C) 2015 The University of Tokyo */
3 
4 /* This program is free software: you can redistribute it and/or modify */
5 /* it under the terms of the GNU General Public License as published by */
6 /* the Free Software Foundation, either version 3 of the License, or */
7 /* (at your option) any later version. */
8 
9 /* This program is distributed in the hope that it will be useful, */
10 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
11 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
12 /* GNU General Public License for more details. */
13 
14 /* You should have received a copy of the GNU General Public License */
15 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 /*-------------------------------------------------------------*/
17 /*-------------------------------------------------------------
18  * HPhi
19  * timer program
20  * "-lrt" option is needed for clock_gettime().
21  *-------------------------------------------------------------
22  * original code written by Satoshi Morita
23  *-------------------------------------------------------------*/
24 
25 #include "Common.h"
26 #include "FileIO.h"
27 #include "CalcTime.h"
28 
29 #ifdef MPI
30 #include <mpi.h>
31 #endif
32 
39 void StampTime(FILE *fp, char *str, int num){
40 #ifdef MPI
41  char str1[256];
42  sprintf(str1, "%-50s [%04d] %12.5lf\n", str, num, Timer[num]);
43  fprintf(fp, "%s", str1);
44 #endif
45 }
46 
53 void InitTimer() {
54 #ifdef MPI
55  int i;
56  int NTimer=10000;
57  Timer = (double*)malloc((NTimer)*sizeof(double));
58  TimerStart = (double*)malloc((NTimer)*sizeof(double));
59  for(i=0;i<NTimer;i++) Timer[i]=0.0;
60  for(i=0;i<NTimer;i++) TimerStart[i]=0.0;
61 #endif
62  return;
63 }
71 void StartTimer(int n) {
72 #ifdef MPI
73  TimerStart[n]=MPI_Wtime();
74 #endif
75  return;
76 }
83 void StopTimer(int n) {
84 #ifdef MPI
85  Timer[n] += MPI_Wtime() - TimerStart[n];
86 #endif
87  return;
88 }
95 void OutputTimer(struct BindStruct *X) {
96 
97 #ifdef MPI
98  char fileName[D_FileNameMax];
99  FILE *fp;
100  sprintf(fileName, "CalcTimer.dat"); //TBC
101  childfopenMPI(fileName,"w", &fp);
102  //fp = fopen(fileName, "w");
103  //fp = childfopenMPI(fileName, "w");
104  StampTime(fp, "All", 0);
105  StampTime(fp, " sz", 1000);
106  StampTime(fp, " diagonalcalc", 2000);
107  if(X->Def.iFlgCalcSpec == CALCSPEC_NOT){
108  if(X->Def.iCalcType==TPQCalc) {
109  StampTime(fp, " CalcByTPQ", 3000);
110  StampTime(fp, " FirstMultiply", 3100);
111  StampTime(fp, " rand in FirstMultiply", 3101);
112  StampTime(fp, " mltply in FirstMultiply", 3102);
113  StampTime(fp, " expec_energy_flct ", 3200);
114  StampTime(fp, " calc flctuation in expec_energy_flct ", 3201);
115  StampTime(fp, " mltply in expec_energy_flct ", 3202);
116  StampTime(fp, " expec_onebody ", 3300);
117  StampTime(fp, " expec_twobody ", 3400);
118  StampTime(fp, " Multiply ", 3500);
119  StampTime(fp, " FileIO ", 3600);
120  }
121  else if(X->Def.iCalcType==Lanczos){
122  StampTime(fp, " CalcByLanczos", 4000);
123  StampTime(fp, " LanczosEigenValue", 4100);
124  StampTime(fp, " mltply in LanczosEigenValue", 4101);
125  StampTime(fp, " vec12 in LanczosEigenValue", 4102);
126  StampTime(fp, " DSEVvalue in LanczosEigenValue", 4103);
127  StampTime(fp, " LanczosEigenVector", 4200);
128  StampTime(fp, " mltply in LanczosEigenVector", 4201);
129  StampTime(fp, " expec_energy_flct", 4300);
130  StampTime(fp, " calc flctuation in expec_energy_flct ", 4301);
131  StampTime(fp, " mltply in expec_energy_flct ", 4302);
132  StampTime(fp, " CGEigenVector", 4400);
133  StampTime(fp, " mltply in CGEigenVector ", 4401);
134  StampTime(fp, " expec_onebody ", 4500);
135  StampTime(fp, " expec_twobody ", 4600);
136  StampTime(fp, " expec_TotalSz ", 4700);
137  StampTime(fp, " FileIO ", 4800);
138  StampTime(fp, " Read Input Eigenvec ", 4801);
139  }
140  else if(X->Def.iCalcType==FullDiag){
141  StampTime(fp, " CalcByFullDiag", 5000);
142  StampTime(fp, " MakeHam", 5100);
143  StampTime(fp, " LapackDiag", 5200);
144  StampTime(fp, " CalcPhys", 5300);
145  StampTime(fp, " calc flctuation in expec_energy_flct ", 5301);
146  StampTime(fp, " mltply in expec_energy_flct ", 5302);
147  StampTime(fp, " Output", 5400);
148  StampTime(fp, " OutputHam", 5500);
149  }
150  }
151  else{
152  StampTime(fp, " CalcSpectrum by Lanczos method", 6000);
153  StampTime(fp, " Make excited state", 6100);
154  StampTime(fp, " Read origin state", 6101);
155  StampTime(fp, " Multiply excited operator", 6102);
156  StampTime(fp, " Calculate spectrum", 6200);
157  if(X->Def.iCalcType==Lanczos){
158  StampTime(fp, " Read vector for recalculation", 6201);
159  StampTime(fp, " Read tridiagonal components for recalculation", 6202);
160  StampTime(fp, " Calculate tridiagonal components", 6203);
161  StampTime(fp, " Output tridiagonal components", 6204);
162  StampTime(fp, " Calculate spectrum by Lanczos method", 6205);
163  StampTime(fp, " Output vectors for recalculation", 6206);
164  }
165  else if(X->Def.iCalcType==FullDiag){
166  StampTime(fp, " MakeHam", 6301);
167  StampTime(fp, " lapackdiag", 6302);
168  StampTime(fp, " Calculate v1", 6303);
169  StampTime(fp, " Calculate spectrum", 6304);
170  }
171  }
172 
173  fprintf(fp,"================================================\n");
174 
175  StampTime(fp,"All mltply",1);
176  StampTime(fp," diagonal", 100);
177 
178  switch(X->Def.iCalcModel){
179  case HubbardGC:
180  StampTime(fp," HubbardGC", 200);
181  StampTime(fp," trans in HubbardGC", 210);
182  StampTime(fp," double", 211);
183  StampTime(fp," single", 212);
184  StampTime(fp," inner", 213);
185  StampTime(fp," interall in HubbardGC", 220);
186  StampTime(fp," interPE", 221);
187  StampTime(fp," inner", 222);
188  StampTime(fp," pairhopp in HubbardGC", 230);
189  StampTime(fp," interPE", 231);
190  StampTime(fp," inner", 232);
191  StampTime(fp," exchange in HubbardGC", 240);
192  StampTime(fp," interPE", 241);
193  StampTime(fp," inner", 242);
194  break;
195 
196  case Hubbard:
197  StampTime(fp," Hubbard", 300);
198  StampTime(fp," trans in Hubbard", 310);
199  StampTime(fp," double", 311);
200  StampTime(fp," single", 312);
201  StampTime(fp," inner", 313);
202  StampTime(fp," interall in Hubbard", 320);
203  StampTime(fp," interPE", 321);
204  StampTime(fp," inner", 322);
205  StampTime(fp," pairhopp in Hubbard", 330);
206  StampTime(fp," interPE", 331);
207  StampTime(fp," inner", 332);
208  StampTime(fp," exchange in Hubbard", 340);
209  StampTime(fp," interPE", 341);
210  StampTime(fp," inner", 342);
211  break;
212 
213  case Spin:
214  fprintf(fp,"\n");
215  StampTime(fp," Spin", 400);
216  StampTime(fp," interall in Spin", 410);
217  StampTime(fp," double", 411);
218  StampTime(fp," single1", 412);
219  StampTime(fp," single2", 413);
220  StampTime(fp," inner", 414);
221  StampTime(fp," exchange in Spin", 420);
222  StampTime(fp," double", 421);
223  StampTime(fp," single1", 422);
224  StampTime(fp," single2", 423);
225  StampTime(fp," inner", 424);
226  break;
227 
228  case SpinGC:
229  StampTime(fp," SpinGC", 500);
230  StampTime(fp," trans in SpinGC", 510);
231  StampTime(fp," double", 511);
232  StampTime(fp," inner", 512);
233  StampTime(fp," interall in SpinGC", 520);
234  StampTime(fp," double", 521);
235  StampTime(fp," single", 522);
236  StampTime(fp," inner", 523);
237  StampTime(fp," exchange in SpinGC", 530);
238  StampTime(fp," double", 531);
239  StampTime(fp," single", 532);
240  StampTime(fp," inner", 533);
241  StampTime(fp," pairlift in SpinGC", 540);
242  StampTime(fp," double", 541);
243  StampTime(fp," single", 542);
244  StampTime(fp," inner", 543);
245  break;
246 
247  default:
248  break;
249  }
250  fprintf(fp,"================================================\n");
251 
252  fclose(fp);
253  free(Timer);
254  free(TimerStart);
255 #endif
256  return;
257 }
258 
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.h:410
void StartTimer(int n)
function for initializing elapse time [start]
Definition: time.c:71
void StopTimer(int n)
function for calculating elapse time [elapse time=StartTimer-StopTimer]
Definition: time.c:83
#define D_FileNameMax
Definition: global.h:23
int childfopenMPI(const char *_cPathChild, const char *_cmode, FILE **_fp)
Only the root process open file in output/ directory.
Definition: FileIO.c:27
void InitTimer()
function for initializing Timer[]
Definition: time.c:53
void StampTime(FILE *fp, char *str, int num)
function for displaying elapse time
Definition: time.c:39
Bind.
Definition: struct.h:409
void OutputTimer(struct BindStruct *X)
function for outputting elapse time for each function
Definition: time.c:95
struct EDMainCalStruct X
Definition: struct.h:432
double * TimerStart
Definition: global.h:149
double * Timer
Definition: global.h:148
int iCalcModel
Switch for model. 0:Hubbard, 1:Spin, 2:Kondo, 3:HubbardGC, 4:SpinGC, 5:KondoGC, 6:HubbardNConserved.
Definition: struct.h:198
int iFlgCalcSpec
Input parameter CalcSpec in teh CalcMod file.
Definition: struct.h:216
int iCalcType
Switch for calculation type. 0:Lanczos, 1:TPQCalc, 2:FullDiag.
Definition: struct.h:192