HΦ  3.2.0
HPhiMain.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 #include <sz.h>
19 #include <HPhiTrans.h>
20 #include <output_list.h>
21 #include <diagonalcalc.h>
22 #include <CalcByLanczos.h>
23 #include <CalcByLOBPCG.h>
24 #include <CalcByFullDiag.h>
25 #include <CalcByTPQ.h>
26 #include <CalcSpectrum.h>
27 #include <check.h>
28 #include "CalcByTEM.h"
29 #include "readdef.h"
30 #include "StdFace_main.h"
31 #include "wrapperMPI.h"
32 #include "splash.h"
33 #include "CalcTime.h"
34 
177 int main(int argc, char* argv[]){
178 
179  int mode=0;
180  char cFileListName[D_FileNameMax];
181 
182  stdoutMPI = stdout;
183  if(JudgeDefType(argc, argv, &mode)!=0){
184  exitMPI(-1);
185  }
186 
187  if (mode == STANDARD_DRY_MODE) {
188  myrank = 0;
189  nproc = 1;
190  stdoutMPI = stdout;
191  splash();
192  }
193  else InitializeMPI(argc, argv);
194 
195  //Timer
196  InitTimer();
197  if (mode != STANDARD_DRY_MODE) StartTimer(0);
198 
199  //MakeDirectory for output
200  struct stat tmpst;
201  if (myrank == 0) {
202  if (stat(cParentOutputFolder, &tmpst) != 0) {
203  if (mkdir(cParentOutputFolder, 0777) != 0) {
204  fprintf(stdoutMPI, "%s", cErrOutput);
205  exitMPI(-1);
206  }
207  }
208  }/*if (myrank == 0)*/
209 
210  strcpy(cFileListName, argv[2]);
211 
212  if(mode==STANDARD_MODE || mode == STANDARD_DRY_MODE){
213  if (myrank == 0) StdFace_main(argv[2]);
214  strcpy(cFileListName, "namelist.def");
215  if (mode == STANDARD_DRY_MODE){
216  fprintf(stdout, "Dry run is Finished. \n\n");
217  return 0;
218  }
219  }
220 
221  setmem_HEAD(&X.Bind);
222  if(ReadDefFileNInt(cFileListName, &(X.Bind.Def), &(X.Bind.Boost))!=0){
223  fprintf(stdoutMPI, "%s", cErrDefFile);
224  exitMPI(-1);
225  }
226 
227  if (X.Bind.Def.nvec < X.Bind.Def.k_exct){
228  fprintf(stdoutMPI, "%s", cErrnvec);
230  exitMPI(-1);
231  }
232  fprintf(stdoutMPI, "%s", cProFinishDefFiles);
233 
234  /*ALLOCATE-------------------------------------------*/
235  setmem_def(&X.Bind, &X.Bind.Boost);
236  /*-----------------------------------------------------*/
237 
238  /*Read Def files.*/
240  if(ReadDefFileIdxPara(&(X.Bind.Def), &(X.Bind.Boost))!=0){
241  fprintf(stdoutMPI, "%s", cErrIndices);
242  exitMPI(-1);
243  }
245  fprintf(stdoutMPI, "%s", cProFinishDefCheck);
246 
247  /*Set convergence Factor*/
249 
250  /*---------------------------*/
251  if(HPhiTrans(&(X.Bind))!=0) {
252  exitMPI(-1);
253  }
254 
255  //Start Calculation
256  if(X.Bind.Def.iFlgCalcSpec == CALCSPEC_NOT) {
257 
258  if(check(&(X.Bind))==MPIFALSE){
259  exitMPI(-1);
260  }
261 
262  /*LARGE VECTORS ARE ALLOCATED*/
263  if (setmem_large(&X.Bind) != 0) {
265  exitMPI(-1);
266  }
267 
268  StartTimer(1000);
269  if(sz(&(X.Bind), list_1, list_2_1, list_2_2)!=0){
270  exitMPI(-1);
271  }
272 
273  StopTimer(1000);
274  if(X.Bind.Def.WRITE==1){
275  output_list(&(X.Bind));
276  exitMPI(-2);
277  }
278  StartTimer(2000);
279  diagonalcalc(&(X.Bind));
280  StopTimer(2000);
281 
282  switch (X.Bind.Def.iCalcType) {
283  case Lanczos:
284  StartTimer(4000);
285  if (CalcByLanczos(&X) != TRUE) {
286  StopTimer(4000);
287  exitMPI(-3);
288  }
289  StopTimer(4000);
290  break;
291 
292  case CG:
293  if (CalcByLOBPCG(&X) != TRUE) {
294  exitMPI(-3);
295  }
296  break;
297 
298  case FullDiag:
299  StartTimer(5000);
300  if (X.Bind.Def.iFlgScaLAPACK ==0 && nproc != 1) {
301  fprintf(stdoutMPI, "Error: Full Diagonalization by LAPACK is only allowed for one process.\n");
302  FinalizeMPI();
303  }
304  if (CalcByFullDiag(&X) != TRUE) {
305  FinalizeMPI();
306  }
307  StopTimer(5000);
308  break;
309 
310  case TPQCalc:
311  StartTimer(3000);
313  StopTimer(3000);
314  exitMPI(-3);
315  }
316  StopTimer(3000);
317  break;
318 
319  case TimeEvolution:
320  if(CalcByTEM(X.Bind.Def.Param.ExpecInterval, &X)!=0){
321  exitMPI(-3);
322  }
323  break;
324 
325  default:
326  StopTimer(0);
327  exitMPI(-3);
328  }
329  }
330  else{
331  StartTimer(6000);
332  if (CalcSpectrum(&X) != TRUE) {
333  StopTimer(6000);
334  exitMPI(-3);
335  }
336  StopTimer(6000);
337  }
338 
339  StopTimer(0);
340  OutputTimer(&(X.Bind));
341  FinalizeMPI();
342  return 0;
343 }
void exitMPI(int errorcode)
MPI Abortation wrapper.
Definition: wrapperMPI.c:86
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
int JudgeDefType(const int argc, char *argv[], int *mode)
function of judging a type of define files.
Definition: readdef.c:2316
const char * cReadDefStart
Definition: LogMessage.c:29
void SetConvergenceFactor(struct DefineList *X)
function to set convergence factors
Definition: readdef.c:2446
int sz(struct BindStruct *X, long unsigned int *list_1_, long unsigned int *list_2_1_, long unsigned int *list_2_2_)
generating Hilbert space
Definition: sz.c:63
void StopTimer(int n)
function for calculating elapse time [elapse time=StartTimer-StopTimer]
Definition: time.c:83
char * cErrnvec
Definition: ErrorMessage.c:26
int CalcByTEM(const int ExpecInterval, struct EDMainCalStruct *X)
main function of time evolution calculation
Definition: CalcByTEM.c:53
int NumAve
Definition: global.h:65
#define D_FileNameMax
Definition: global.h:23
char * cErrDefFile
Definition: ErrorMessage.c:24
int ReadDefFileIdxPara(struct DefineList *X, struct BoostList *xBoost)
function of reading def files to get keyword index
Definition: readdef.c:980
void setmem_def(struct BindStruct *X, struct BoostList *xBoost)
Set size of memories for Def and Phys in BindStruct.
Definition: xsetmem.c:55
int CalcByLanczos(struct EDMainCalStruct *X)
A main function to calculate eigenvalues and eigenvectors by Lanczos method.
Definition: CalcByLanczos.c:54
int iFlgScaLAPACK
ScaLAPACK mode ( only for FullDiag )
Definition: struct.h:235
unsigned int nvec
Read from Calcmod in readdef.h.
Definition: struct.h:46
int ReadDefFileNInt(char *xNameListFile, struct DefineList *X, struct BoostList *xBoost)
Function of reading information about "ModPara" file and total number of parameters from other def fi...
Definition: readdef.c:460
int check(struct BindStruct *X)
A program to check size of dimension for Hilbert-space.
Definition: check.c:51
int CalcByLOBPCG(struct EDMainCalStruct *X)
Driver routine for LOB(P)CG method.
Definition: CalcByLOBPCG.c:638
int setmem_large(struct BindStruct *X)
Set size of memories for Hamiltonian (Ham, L_vec), vectors(vg, v0, v1, v2, vec, alpha, beta), lists (list_1, list_2_1, list_2_2, list_Diagonal) and Phys(BindStruct.PhysList) struct in the case of Full Diag mode.
Definition: xsetmem.c:157
#define TRUE
Definition: global.h:26
const char * cReadDefFinish
Definition: LogMessage.c:30
void InitTimer()
function for initializing Timer[]
Definition: time.c:53
int iErrCodeMem
Error Message in HPhiMain.c.
Definition: ErrorMessage.c:20
int ExpecInterval
Definition: struct.h:36
void splash()
Print logo mark and version number.
Definition: splash.c:25
int nproc
Number of processors, defined in InitializeMPI()
Definition: global.h:162
int CalcByFullDiag(struct EDMainCalStruct *X)
Parent function for FullDiag mode.
int diagonalcalc(struct BindStruct *X)
Calculate diagonal components and obtain the list, list_diagonal.
Definition: diagonalcalc.c:85
int CalcByTPQ(const int NumAve, const int ExpecInterval, struct EDMainCalStruct *X)
A main function to calculate physical quqntities by TPQ method.
Definition: CalcByTPQ.c:52
struct BoostList Boost
For Boost.
Definition: struct.h:414
#define MPIFALSE
Definition: global.h:24
char * cErrnvecShow
Definition: ErrorMessage.c:27
long unsigned int * list_2_1
Definition: global.h:49
void setmem_HEAD(struct BindStruct *X)
Set size of memories headers of output files.
Definition: xsetmem.c:41
void OutputTimer(struct BindStruct *X)
function for outputting elapse time for each function
Definition: time.c:95
void FinalizeMPI()
MPI Finitialization wrapper.
Definition: wrapperMPI.c:74
int CalcSpectrum(struct EDMainCalStruct *X)
A main function to calculate spectrum.
Definition: CalcSpectrum.c:90
char * cErrLargeMem
Definition: ErrorMessage.c:35
char * cErrOutput
Definition: ErrorMessage.c:23
struct ParamList Param
Definition: struct.h:241
long unsigned int * list_1
Definition: global.h:47
int main(int argc, char *argv[])
Main program for HPhi.
Definition: HPhiMain.c:177
const char * cProFinishDefCheck
const char * cFileNameTimeKeep
Definition: global.c:23
long unsigned int * list_2_2
Definition: global.h:50
struct EDMainCalStruct X
Definition: struct.h:432
const char * cProFinishDefFiles
int WRITE
It is ALWAYS 0 ???
Definition: struct.h:54
const char * cParentOutputFolder
Definition: global.c:20
char * cErrIndices
Definition: ErrorMessage.c:28
int myrank
Process ID, defined in InitializeMPI()
Definition: global.h:163
int iFlgCalcSpec
Input parameter CalcSpec in teh CalcMod file.
Definition: struct.h:216
int HPhiTrans(struct BindStruct *X)
Function of checking transfers not to count the same type of operators. .
Definition: HPhiTrans.c:45
int output_list(struct BindStruct *X)
Output list_1 for canonical ensembles.
Definition: output_list.c:40
void StdFace_main(char *fname)
Main routine for the standard mode.
void InitializeMPI(int argc, char *argv[])
MPI initialization wrapper Process ID (myrank), Number of processes (nproc), Number of threads (nthre...
Definition: wrapperMPI.c:43
struct BindStruct Bind
Binded struct.
Definition: struct.h:420
int TimeKeeper(struct BindStruct *X, const char *cFileName, const char *cTimeKeeper_Message, const char *cWriteType)
Functions for writing a time log.
Definition: log.c:42
int iCalcType
Switch for calculation type. 0:Lanczos, 1:TPQCalc, 2:FullDiag.
Definition: struct.h:192
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()
Definition: global.h:165
unsigned int k_exct
Read from Calcmod in readdef.h.
Definition: struct.h:47