/********************************************************** This software is part of J.-S. Caux's ABACUS library. Copyright (c) J.-S. Caux. ----------------------------------------------------------- File: LiebLin_DSF_par_Run.cc Purpose: Parallel version of ABACUS using MPICH. ***********************************************************/ #include "ABACUS.h" #include "mpi.h" using namespace std; using namespace ABACUS; int main(int argc, char *argv[]) { char whichDSF; DP c_int, L, kBT; int N, iKmin, iKmax, Max_Secs, paralevel; DP target_sumrule = 1.0e+6; // effectively deactivated here bool refine = true; // always true for parallel mode if (argc < 10) { // provide some info cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl; cout << endl << "Usage of LiebLin_DSF_par_Run executable: " << endl; 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; cout << endl << "Provide the following arguments:" << endl << endl; 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; cout << "DP c_int \t\t Value of the interaction parameter: use positive real values only" << endl; cout << "DP L \t\t\t Length of the system: use positive real values only" << endl; cout << "int N \t\t\t Number of particles: use positive integer values only" << endl; cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over: " "recommended values: -2*N and 2*N" << endl; cout << "DP kBT \t\t Temperature (positive only of course)" << endl; cout << "int paralevel" << endl; cout << "rank[i], nr_processors[i] \t rank and nr_processors of each earlier paralevels." << endl; cout << "int Max_Secs \t\t Allowed computational time: (in seconds)" << endl; cout << endl << "EXAMPLE: " << endl << endl; cout << "mpiexec -np 8 LiebLin_DSF_par_Run d 1.0 100.0 100 0 400 0.0 1 3600" << endl << endl; return(0); } int n = 1; whichDSF = *argv[n++]; c_int = atof(argv[n++]); L = atof(argv[n++]); N = atoi(argv[n++]); iKmin = atoi(argv[n++]); iKmax = atoi(argv[n++]); kBT = atof(argv[n++]); paralevel = atoi(argv[n++]); // paralevel == 1 means that we have one layer of parallelization, so no previous rank and nr_processors to specify if (argc != 10 + 2*(paralevel - 1)) ABACUSerror("Wrong nr of arguments in LiebLin_DSF_par_Run."); Vect rank_lower_paralevels(paralevel - 1); Vect nr_processors_lower_paralevels(paralevel - 1); for (int i = 0; i < paralevel - 1; ++i) { rank_lower_paralevels[i] = atoi(argv[n++]); nr_processors_lower_paralevels[i] = atoi(argv[n++]); } Max_Secs = atoi(argv[n++]); if (Max_Secs < 120) ABACUSerror("Please allow more time in LiebLin_DSF_par_Run."); int Max_Secs_used = Max_Secs - 120; MPI::Init(argc, argv); DP tstart = MPI::Wtime(); int rank_here = MPI::COMM_WORLD.Get_rank(); int nr_processors_here = MPI::COMM_WORLD.Get_size(); Vect rank (paralevel); Vect nr_processors (paralevel); for (int i = 0; i < paralevel - 1; ++i) { rank[i] = rank_lower_paralevels[i]; nr_processors[i] = nr_processors_lower_paralevels[i]; } rank[paralevel-1] = rank_here; nr_processors[paralevel-1] = nr_processors_here; if (nr_processors_here < 2) ABACUSerror("Give at least 2 processors to ABACUS parallel !"); refine = true; // ASSUMPTION: preexisting files (raw, thr, ...) exist for the run. DP tnow = MPI::Wtime(); string defaultScanStatename = ""; if (Max_Secs_used > 0) { // space for 2 minutes safety // Barrier synchronization MPI_Barrier (MPI::COMM_WORLD); // then everybody gets going on their own chunk ! Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT, Max_Secs_used, target_sumrule, refine, paralevel, rank, nr_processors); // Another barrier synchronization MPI_Barrier (MPI::COMM_WORLD); tnow = MPI::Wtime(); } MPI::Finalize(); return(0); }