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_MosesState_par_Run.cc 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /**********************************************************
  2. This software is part of J.-S. Caux's ABACUS library.
  3. Copyright (c) J.-S. Caux.
  4. -----------------------------------------------------------
  5. File: LiebLin_DSF_par.cc
  6. Purpose: Parallel version of ABACUS using MPICH.
  7. ***********************************************************/
  8. #include "ABACUS.h"
  9. #include "mpi.h"
  10. using namespace ABACUS;
  11. int main(int argc, char *argv[])
  12. {
  13. char whichDSF;
  14. DP c_int, L;
  15. int N, Nl, DIl, DIr, iKmin, iKmax, Max_Secs, supercycle_time, paralevel;
  16. DP target_sumrule = 1.0e+6; // effectively deactivated here
  17. bool refine = true; // always true for parallel mode
  18. DP kBT = 0.0; // dummy
  19. if (argc < 13) { // provide some info
  20. cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
  21. cout << endl << "Usage of LiebLin_DSF_MosesState_par_Run executable: " << endl;
  22. cout << endl << "This function runs ABACUS in parallel mode, starting from a preexisting serial run (obtained using the LiebLin_DSF executable) using the same model parameters." << endl;
  23. cout << endl << "Provide the following arguments:" << endl << endl;
  24. cout << "char whichDSF \t\t Which structure factor should be calculated ? Options are: d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
  25. cout << "DP c_int \t\t Value of the interaction parameter: use positive real values only" << endl;
  26. cout << "DP L \t\t\t Length of the system: use positive real values only" << endl;
  27. cout << "int N \t\t\t Number of particles: use positive integer values only" << endl;
  28. cout << "int Nl \t\t\t Number of particles in left Fermi sea (Nr is then N - Nl)" << endl;
  29. cout << "int DIl \t\t shift of left sea as compared to its ground state position" << endl;
  30. cout << "int DIr \t\t shift of right sea as compared to its ground state position" << endl;
  31. cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over: recommended values: -2*N and 2*N" << endl;
  32. cout << "int paralevel" << endl;
  33. cout << "rank[i], nr_processors[i] \t rank and nr_processors of each earlier paralevels." << endl;
  34. cout << "int Max_Secs \t\t Allowed computational time: (in seconds)" << endl;
  35. cout << "int supercycle_time \t\t time for one supercycle (in seconds)" << endl;
  36. return(0);
  37. }
  38. //else { // correct nr of arguments
  39. int n = 1;
  40. whichDSF = *argv[n++];
  41. c_int = atof(argv[n++]);
  42. L = atof(argv[n++]);
  43. N = atoi(argv[n++]);
  44. Nl = atoi(argv[n++]);
  45. DIl = atoi(argv[n++]);
  46. DIr = atoi(argv[n++]);
  47. iKmin = atoi(argv[n++]);
  48. iKmax = atoi(argv[n++]);
  49. paralevel = atoi(argv[n++]); // paralevel == 1 means that we have one layer of parallelization, so no previous rank and nr_processors to specify
  50. if (argc != 13 + 2*(paralevel - 1)) ABACUSerror("Wrong nr of arguments in LiebLin_DSF_par_Prepare.");
  51. Vect<int> rank_lower_paralevels(paralevel - 1);
  52. Vect<int> nr_processors_lower_paralevels(paralevel - 1);
  53. for (int i = 0; i < paralevel - 1; ++i) {
  54. rank_lower_paralevels[i] = atoi(argv[n++]);
  55. nr_processors_lower_paralevels[i] = atoi(argv[n++]);
  56. }
  57. Max_Secs = atoi(argv[n++]);
  58. supercycle_time = atoi(argv[n++]);
  59. //}
  60. //DP supercycle_time = 600.0; // allotted time per supercycle
  61. if (Max_Secs <= supercycle_time) ABACUSerror("Please allow more time in LiebLin_DSF_par_Run.");
  62. MPI::Init(argc, argv);
  63. DP tstart = MPI::Wtime();
  64. int rank_here = MPI::COMM_WORLD.Get_rank();
  65. int nr_processors_here = MPI::COMM_WORLD.Get_size();
  66. //cout << "rank " << rank_here << " out of " << nr_processors_here << " ready to go." << endl;
  67. Vect<int> rank (paralevel);
  68. Vect<int> nr_processors (paralevel);
  69. for (int i = 0; i < paralevel - 1; ++i) {
  70. rank[i] = rank_lower_paralevels[i];
  71. nr_processors[i] = nr_processors_lower_paralevels[i];
  72. }
  73. rank[paralevel-1] = rank_here;
  74. nr_processors[paralevel-1] = nr_processors_here;
  75. if (nr_processors_here < 2) ABACUSerror("Give at least 2 processors to ABACUS parallel !");
  76. refine = true;
  77. // ASSUMPTION: preexisting files (raw, thr, ...) exist for the run.
  78. DP tnow = MPI::Wtime();
  79. // Define the Moses state:
  80. LiebLin_Bethe_State MosesState (c_int, L, N);
  81. // Split the sea:
  82. for (int i = 0; i < Nl; ++i) MosesState.Ix2[i] += 2 * DIl;
  83. for (int i = Nl; i < N; ++i) MosesState.Ix2[i] += 2 * DIr;
  84. MosesState.Compute_All (true);
  85. // Handy default name:
  86. stringstream defaultScanStatename_strstream;
  87. defaultScanStatename_strstream << "Moses_Nl_" << Nl << "_DIl_" << DIl << "_DIr_" << DIr;
  88. string defaultScanStatename = defaultScanStatename_strstream.str();
  89. //cout << "rank " << rank_here << " out of " << nr_processors_here << " waiting at barrier." << endl;
  90. MPI_Barrier (MPI::COMM_WORLD);
  91. while (tnow - tstart < Max_Secs - supercycle_time - 120) { // space for one more supercycle, + 2 minutes safety
  92. //if (rank == 0)
  93. // Split up thread list into chunks, one per processor
  94. //Prepare_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iK_UL, fixed_iK, iKneeded, nr_processors);
  95. //Prepare_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename, nr_processors);
  96. // Barrier synchronization, to make sure other processes wait for process of rank 0
  97. // to have finished splitting up the thr file into pieces before starting:
  98. MPI_Barrier (MPI::COMM_WORLD);
  99. // then everybody gets going on their own chunk !
  100. //Scan_LiebLin (whichDSF, c_int, L, N, iK_UL, fixed_iK, iKneeded,
  101. //Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, supercycle_time, target_sumrule, refine, paralevel, rank, nr_processors);
  102. Scan_LiebLin (whichDSF, MosesState, defaultScanStatename, iKmin, iKmax, supercycle_time, target_sumrule, refine, paralevel, rank, nr_processors);
  103. // Another barrier synchronization
  104. MPI_Barrier (MPI::COMM_WORLD);
  105. // Now that everybody is done, digest data into unique files
  106. //if (rank == 0)
  107. //Wrapup_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iK_UL, fixed_iK, iKneeded, nr_processors);
  108. //Wrapup_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename, nr_processors);
  109. // Another barrier synchronization
  110. MPI_Barrier (MPI::COMM_WORLD);
  111. tnow = MPI::Wtime();
  112. } // while (tnow - tstart...
  113. MPI::Finalize();
  114. return(0);
  115. }