You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LiebLin_DSF_GeneralState_par_Run.cc 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /**********************************************************
  2. This software is part of J.-S. Caux's ABACUS library.
  3. Copyright (c) J.-S. Caux.
  4. -----------------------------------------------------------
  5. File: LiebLin_DSF_GeneralState_par_Run.cc
  6. Purpose: Parallel version of ABACUS using MPICH.
  7. ***********************************************************/
  8. #include "ABACUS.h"
  9. #include "mpi.h"
  10. using namespace std;
  11. using namespace ABACUS;
  12. int main(int argc, char *argv[])
  13. {
  14. char whichDSF;
  15. DP c_int, L, kBT;
  16. int N, iKmin, iKmax, Max_Secs, paralevel;
  17. DP target_sumrule = 1.0e+6; // effectively deactivated here
  18. bool refine = true; // always true for parallel mode
  19. char* Ix2filenameprefix;
  20. if (argc < 10) { // provide some info
  21. cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
  22. cout << endl << "Usage of LiebLin_DSF_par executable: " << endl;
  23. cout << endl << "This function runs ABACUS in parallel mode, starting from a preexisting "
  24. "serial run (obtained using the LiebLin_DSF executable) using the same model parameters." << endl;
  25. cout << endl << "Provide the following arguments:" << endl << endl;
  26. cout << "char whichDSF \t\t Which structure factor should be calculated ? Options are: "
  27. "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
  28. cout << "DP c_int \t\t Value of the interaction parameter: use positive real values only" << endl;
  29. cout << "DP L \t\t\t Length of the system: use positive real values only" << endl;
  30. cout << "int N \t\t\t Number of particles: use positive integer values only" << endl;
  31. cout << "char* defaultScanStatename:\t\t file [].Ix2 contains the quantum numbers defining the "
  32. "AveragingState; used as defaultScanStatename" << endl;
  33. cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over: "
  34. "recommended values: -2*N and 2*N" << endl;
  35. cout << "int paralevel" << endl;
  36. cout << "rank[i], nr_processors[i] \t rank and nr_processors of each earlier paralevels." << endl;
  37. cout << "int Max_Secs \t\t Allowed computational time: (in seconds)" << endl;
  38. return(0);
  39. }
  40. int n = 1;
  41. whichDSF = *argv[n++];
  42. c_int = atof(argv[n++]);
  43. L = atof(argv[n++]);
  44. N = atoi(argv[n++]);
  45. Ix2filenameprefix = argv[n++];
  46. iKmin = atoi(argv[n++]);
  47. iKmax = atoi(argv[n++]);
  48. paralevel = atoi(argv[n++]); // paralevel == 1 means that we have one layer of parallelization, so no previous rank and nr_processors to specify
  49. if (argc != 10 + 2*(paralevel - 1)) ABACUSerror("Wrong nr of arguments in LiebLin_DSF_par_Prepare.");
  50. Vect<int> rank_lower_paralevels(paralevel - 1);
  51. Vect<int> nr_processors_lower_paralevels(paralevel - 1);
  52. for (int i = 0; i < paralevel - 1; ++i) {
  53. rank_lower_paralevels[i] = atoi(argv[n++]);
  54. nr_processors_lower_paralevels[i] = atoi(argv[n++]);
  55. }
  56. Max_Secs = atoi(argv[n++]);
  57. if (Max_Secs <= 120) ABACUSerror("Please allow more time in LiebLin_DSF_par_Run.");
  58. int Max_Secs_used = Max_Secs - 120;
  59. MPI::Init(argc, argv);
  60. DP tstart = MPI::Wtime();
  61. int rank_here = MPI::COMM_WORLD.Get_rank();
  62. int nr_processors_here = MPI::COMM_WORLD.Get_size();
  63. // Read the Ix2 from the file:
  64. Vect<int> Ix2_input(N);
  65. ifstream Ix2_input_file;
  66. stringstream filenamestrstream;
  67. filenamestrstream << Ix2filenameprefix;
  68. string defaultScanStatename = filenamestrstream.str();
  69. filenamestrstream << ".Ix2";
  70. string filenamestr = filenamestrstream.str();
  71. const char* filename_Cstr = filenamestr.c_str();
  72. Ix2_input_file.open(filename_Cstr);
  73. if (Ix2_input_file.fail()) {
  74. cout << filename_Cstr << endl;
  75. ABACUSerror("Could not open Ix2 input file in LiebLin_DSF_GeneralState");
  76. }
  77. for (int i = 0; i < N; ++i) {
  78. Ix2_input_file >> Ix2_input[i];
  79. }
  80. // Now define the AveragingState
  81. LiebLin_Bethe_State AveragingState(c_int, L, N);
  82. AveragingState.Ix2 = Ix2_input;
  83. AveragingState.Compute_All(true);
  84. Vect<int> rank (paralevel);
  85. Vect<int> nr_processors (paralevel);
  86. for (int i = 0; i < paralevel - 1; ++i) {
  87. rank[i] = rank_lower_paralevels[i];
  88. nr_processors[i] = nr_processors_lower_paralevels[i];
  89. }
  90. rank[paralevel-1] = rank_here;
  91. nr_processors[paralevel-1] = nr_processors_here;
  92. if (nr_processors_here < 2) ABACUSerror("Give at least 2 processors to ABACUS parallel !");
  93. refine = true;
  94. // ASSUMPTION: preexisting files (raw, thr, ...) exist for the run.
  95. DP tnow = MPI::Wtime();
  96. if (Max_Secs_used > 0) {
  97. // Barrier synchronization
  98. MPI_Barrier (MPI::COMM_WORLD);
  99. // then everybody gets going on their own chunk !
  100. Scan_LiebLin (whichDSF, AveragingState, defaultScanStatename, iKmin, iKmax, Max_Secs,
  101. target_sumrule, refine, paralevel, rank, nr_processors);
  102. // Another barrier synchronization
  103. MPI_Barrier (MPI::COMM_WORLD);
  104. tnow = MPI::Wtime();
  105. } // while (tnow - tstart...
  106. MPI::Finalize();
  107. return(0);
  108. }