ABACUS/src/EXECS/Heis_DSF_par.cc

119 lines
4.1 KiB
C++

/**********************************************************
This software is part of J.-S. Caux's ABACUS library.
Copyright (c) J.-S. Caux.
-----------------------------------------------------------
File: Heis_DSF_par.cc
Purpose: Parallel version of ABACUS using MPICH.
***********************************************************/
#include "ABACUS.h"
#include "mpi.h"
using namespace ABACUS;
int main(int argc, char *argv[])
{
char whichDSF;
DP Delta;
int N, M, iKneeded, iKmin, iKmax, Max_Secs;
DP target_sumrule = 1.0e+6; // effectively deactivated here
bool refine;
if (argc != 8) { // provide some info
cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
cout << endl << "Usage of Heis_DSF_par executable: " << endl;
cout << endl << "This function runs ABACUS in parallel mode, starting from a preexisting serial run (obtained using the Heis_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: m for S- S+, z for Sz Sz, p for S+ S-." << endl;
cout << "DP Delta \t\t Value of the anisotropy: use positive real values only" << endl;
cout << "int N \t\t\t Length (number of sites) of the system: use positive even integer values only" << endl;
cout << "int M \t\t\t Number of down spins: use positive integer values between 1 and N/2" << endl;
cout << "int iKmin" << endl << "int iKmax \t\t Min and max momentum integers to scan over: recommended values: 0 and N" << endl;
cout << "int Max_Secs \t\t Allowed computational time: (in seconds)" << endl;
cout << endl << "EXAMPLE: " << endl << endl;
cout << "mpiexec -np 8 Heis_DSF_par z 1.0 100 40 0 100 600" << endl << endl;
return(0);
}
else { // (argc == 8) correct nr of arguments
whichDSF = *argv[1];
Delta = atof(argv[2]);
N = atoi(argv[3]);
M = atoi(argv[4]);
iKmin = atoi(argv[5]);
iKmax = atoi(argv[6]);
Max_Secs = atoi(argv[7]);
}
DP supercycle_time = 600.0; // allotted time per supercycle
if (Max_Secs <= supercycle_time + 300) ABACUSerror("Please allow more time in Heis_DSF_par.");
MPI::Init(argc, argv);
DP tstart = MPI::Wtime();
int rank = MPI::COMM_WORLD.Get_rank();
int nr_processors = MPI::COMM_WORLD.Get_size();
if (nr_processors < 2) ABACUSerror("Give at least 2 processors to ABACUS parallel !");
refine = true;
// ASSUMPTION: preexisting files (raw, thr, ...) exist for the run.
// IMPORTANT PRECONDITION: no flags are being raised in General_Scan in parallel mode, so
// the preinitializing serial run must be extensive enough to have flagged all base/type s necessary.
DP tnow = MPI::Wtime();
while (tnow - tstart < Max_Secs - supercycle_time - 300) { // space for one more supercycle, + 5 minutes safety
//cout << "rank " << rank << " ready to prepare." << endl;
if (rank == 0)
// Split up thread list into chunks, one per processor
Prepare_Parallel_Scan_Heis (whichDSF, Delta, N, M, iKmin, iKmax, nr_processors);
//cout << "rank " << rank << " done preparing, ready to scan." << endl;
// Barrier synchronization, to make sure other processes wait for process of rank 0
// to have finished splitting up the thr file into pieces before starting:
MPI_Barrier (MPI::COMM_WORLD);
// then everybody gets going on their own chunk !
Scan_Heis (whichDSF, Delta, N, M, iKmin, iKmax,
supercycle_time, target_sumrule, refine, rank, nr_processors);
//cout << "rank " << rank << " finished scanning, reached wrapup stage." << endl;
// Another barrier synchronization
MPI_Barrier (MPI::COMM_WORLD);
// Now that everybody is done, digest data into unique files
if (rank == 0)
Wrapup_Parallel_Scan_Heis (whichDSF, Delta, N, M, iKmin, iKmax, nr_processors);
//cout << "rank " << rank << " passed wrapup stage." << endl;
// Another barrier synchronization
MPI_Barrier (MPI::COMM_WORLD);
tnow = MPI::Wtime();
} // while (tnow - tstart...
MPI::Finalize();
return(0);
}