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_over_Ensemble_par.cc 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /**********************************************************
  2. This software is part of J.-S. Caux's ABACUS library.
  3. Copyright (c) J.-S. Caux.
  4. -----------------------------------------------------------
  5. File: LiebLin_DSF_over_Ensemble_par.cc
  6. Purpose: main function for ABACUS for LiebLin gas, averaging over an Ensemble, parallel implementation.
  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. if (argc != 10) { // provide some info
  15. cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
  16. cout << endl << "Usage of LiebLin_DSF_Tgt0 executable: " << endl;
  17. cout << endl << "Provide the following arguments:" << endl << endl;
  18. cout << "char whichDSF \t\t Which structure factor should be calculated ? Options are: "
  19. "d for rho rho, g for psi psi{dagger}, o for psi{dagger} psi" << endl;
  20. cout << "DP c_int \t\t Value of the interaction parameter: use positive real values only" << endl;
  21. cout << "DP L \t\t\t Length of the system: use positive real values only" << endl;
  22. cout << "int N \t\t\t Number of particles: use positive integer values only" << endl;
  23. cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over: "
  24. "recommended values: -2*N and 2*N" << endl;
  25. cout << "DP kBT \t\t Temperature (positive only of course)" << endl;
  26. cout << "int Max_Secs \t\t Allowed computational time: (in seconds)" << endl;
  27. cout << "bool refine \t\t Is this a refinement of earlier calculations ? (0 == false, 1 == true)" << endl;
  28. cout << endl << "EXAMPLE: " << endl << endl;
  29. cout << "LiebLin_DSF_over_Ensemble d 1.0 100.0 100 0 200 0.56 10 600 0" << endl << endl;
  30. }
  31. else { // (argc == 10), correct nr of arguments
  32. char whichDSF = *argv[1];
  33. DP c_int = atof(argv[2]);
  34. DP L = atof(argv[3]);
  35. int N = atoi(argv[4]);
  36. int iKmin = atoi(argv[5]);
  37. int iKmax = atoi(argv[6]);
  38. DP kBT = atof(argv[7]);
  39. int Max_Secs = atoi(argv[8]);
  40. bool refine = (atoi(argv[9]) == 1);
  41. if (refine == false) ABACUSerror("Please run the serial version of LiebLin_DSF_over_Ensemble first.");
  42. MPI::Init(argc, argv);
  43. DP tstart = MPI::Wtime();
  44. int rank = MPI::COMM_WORLD.Get_rank();
  45. int nr_processors = MPI::COMM_WORLD.Get_size();
  46. if (nr_processors < 2) ABACUSerror("Give at least 2 processors to ABACUS parallel !");
  47. // Start by constructing (or loading) the state ensemble.
  48. LiebLin_Diagonal_State_Ensemble ensemble;
  49. stringstream ensfilestrstream;
  50. ensfilestrstream << "LiebLin_c_int_" << c_int << "_L_" << L << "_N_" << N << "_kBT_" << kBT << ".ens";
  51. string ensfilestr = ensfilestrstream.str();
  52. const char* ensfile_Cstr = ensfilestr.c_str();
  53. if (!refine) { // Construct the state ensemble
  54. ensemble = LiebLin_Thermal_Saddle_Point_Ensemble (c_int, L, N, kBT);
  55. ensemble.Save(ensfile_Cstr); // Save the ensemble
  56. }
  57. else { // load the ensemble data
  58. ensemble.Load(c_int, L, N, ensfile_Cstr);
  59. }
  60. MPI_Barrier (MPI::COMM_WORLD);
  61. // Now perform the DSF calculation over each state in the ensemble
  62. int Max_Secs_used = Max_Secs/ensemble.nstates;
  63. DP supercycle_time = 600.0; // allotted time per supercycle
  64. if (Max_Secs_used <= supercycle_time) ABACUSerror("Please allow more time in LiebLin_DSF_par.");
  65. // Main loop over ensemble:
  66. for (int ns = 0; ns < ensemble.nstates; ++ns) {
  67. tstart = MPI::Wtime();
  68. DP tnow = MPI::Wtime();
  69. string defaultScanStatename = ensemble.state[ns].label;
  70. while (tnow - tstart < Max_Secs_used - supercycle_time) { // space for one more supercycle
  71. if (rank == 0)
  72. // Split up thread list into chunks, one per processor
  73. Prepare_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename, nr_processors);
  74. // Barrier synchronization, to make sure other processes wait for process of rank 0
  75. // to have finished splitting up the thr file into pieces before starting:
  76. MPI_Barrier (MPI::COMM_WORLD);
  77. // then everybody gets going on their own chunk !
  78. Scan_LiebLin (whichDSF, ensemble.state[ns], ensemble.state[ns].label, iKmin, iKmax, supercycle_time, 1.0e+6, refine, rank, nr_processors);
  79. // Another barrier synchronization
  80. MPI_Barrier (MPI::COMM_WORLD);
  81. // Now that everybody is done, digest data into unique files
  82. if (rank == 0)
  83. Wrapup_Parallel_Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, defaultScanStatename, nr_processors);
  84. // Another barrier synchronization
  85. MPI_Barrier (MPI::COMM_WORLD);
  86. tnow = MPI::Wtime();
  87. } // while (tnow - tstart...
  88. } // for ns
  89. MPI_Barrier (MPI::COMM_WORLD);
  90. // Final wrapup of the data
  91. if (rank == 0) {
  92. // Evaluate the f-sumrule
  93. stringstream FSR_stringstream; string FSR_string;
  94. Data_File_Name (FSR_stringstream, whichDSF, c_int, L, N, iKmin, iKmax, kBT, 0.0, "");
  95. FSR_stringstream << "_ns_" << ensemble.nstates << ".fsr";
  96. FSR_string = FSR_stringstream.str(); const char* FSR_Cstr = FSR_string.c_str();
  97. DP Chem_Pot = 0.0;
  98. Evaluate_F_Sumrule (whichDSF, c_int, L, N, kBT, ensemble.nstates, Chem_Pot, iKmin, iKmax, FSR_Cstr);
  99. }
  100. MPI_Barrier (MPI::COMM_WORLD);
  101. } // correct nr of arguments
  102. MPI::Finalize();
  103. return(0);
  104. }