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.

Heis_DSF_par_Run.cc 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**********************************************************
  2. This software is part of J.-S. Caux's ABACUS library.
  3. Copyright (c) J.-S. Caux.
  4. -----------------------------------------------------------
  5. File: Heis_DSF_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 Delta;
  16. int N, M, iKmin, iKmax, Max_Secs, supercycle_time, paralevel;
  17. DP target_sumrule = 1.0e+6; // effectively deactivated here
  18. bool refine = true; // always true for parallel mode
  19. if (argc < 10) { // provide some info
  20. cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
  21. cout << endl << "Usage of Heis_DSF_par_Run executable: " << endl;
  22. cout << endl << "This function runs ABACUS in parallel mode, starting from a preexisting "
  23. "serial run (obtained using the Heis_DSF executable) using the same model parameters." << endl;
  24. cout << endl << "Provide the following arguments:" << endl << endl;
  25. cout << "char whichDSF \t\t Which structure factor should be calculated ? Options are: "
  26. "m for S- S+, z for Sz Sz, p for S+ S-." << endl;
  27. cout << "DP Delta \t\t Value of the anisotropy: use positive real values only" << endl;
  28. cout << "int N \t\t\t Length (number of sites) of the system: use positive even integer values only" << endl;
  29. cout << "int M \t\t\t Number of down spins: use positive integer values between 1 and N/2" << endl;
  30. cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over: "
  31. "recommended values: 0 and 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. cout << endl << "EXAMPLE: " << endl << endl;
  37. cout << "mpiexec -np 8 Heis_DSF_par_Run z 1 128 64 0 128 [**UPDATE]" << endl << endl;
  38. return(0);
  39. }
  40. //else { // (argc == 9) correct nr of arguments
  41. int n = 1;
  42. whichDSF = *argv[n++];
  43. Delta = atof(argv[n++]);
  44. N = atoi(argv[n++]);
  45. M = atoi(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 Heis_DSF_par_Run.");
  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. supercycle_time = atoi(argv[n++]);
  58. if (Max_Secs <= supercycle_time) ABACUSerror("Please allow more time in Heis_DSF_par_Run.");
  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. Vect<int> rank (paralevel);
  64. Vect<int> nr_processors (paralevel);
  65. for (int i = 0; i < paralevel - 1; ++i) {
  66. rank[i] = rank_lower_paralevels[i];
  67. nr_processors[i] = nr_processors_lower_paralevels[i];
  68. }
  69. rank[paralevel-1] = rank_here;
  70. nr_processors[paralevel-1] = nr_processors_here;
  71. if (nr_processors_here < 2) ABACUSerror("Give at least 2 processors to ABACUS parallel !");
  72. refine = true;
  73. // ASSUMPTION: preexisting files (raw, thr, ...) exist for the run.
  74. DP tnow = MPI::Wtime();
  75. string defaultScanStatename = "";
  76. while (tnow - tstart < Max_Secs - supercycle_time - 120) { // space for one more supercycle, + 2 minutes safety
  77. // Barrier synchronization, to make sure other processes wait for process of rank 0
  78. // to have finished splitting up the thr file into pieces before starting:
  79. MPI_Barrier (MPI::COMM_WORLD);
  80. // then everybody gets going on their own chunk !
  81. Scan_Heis (whichDSF, Delta, N, M, iKmin, iKmax,
  82. supercycle_time, target_sumrule, refine, paralevel, rank, nr_processors);
  83. // Another barrier synchronization
  84. MPI_Barrier (MPI::COMM_WORLD);
  85. // Now that everybody is done, digest data into unique files
  86. // Another barrier synchronization
  87. MPI_Barrier (MPI::COMM_WORLD);
  88. tnow = MPI::Wtime();
  89. } // while (tnow - tstart...
  90. MPI::Finalize();
  91. return(0);
  92. }