ABACUS/src/EXECS/LiebLin_Catalogue_Fixed_c_N...

143 lines
4.5 KiB
C++

/**********************************************************
This software is part of J.-S. Caux's ABACUS library.
Copyright (c) J.-S. Caux.
-----------------------------------------------------------
File: LiebLin_Catalogue_Fixed_c_Nscaling.cc
Purpose: Produces sets of data files for correlations, increasing system size at fixed c.
***********************************************************/
#include <omp.h>
#include "ABACUS.h"
using namespace std;
using namespace ABACUS;
int main(int argc, char* argv[])
{
if (argc != 8) { // provide some info
cout << endl << "Welcome to ABACUS\t(copyright J.-S. Caux)." << endl;
cout << endl << "Usage of LiebLin_Catalogue_Fixed_c_k_Nscaling executable: " << 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 << "int kfactmax \t\t max momentum factor: max momentum will be set to kfact * kF/4" << endl;
cout << "DP kBT \t\t Temperature (positive only of course)" << endl;
cout << "DP target_sumrule \t sumrule saturation you're satisfied with" << endl;
cout << "int Hrs \t\t Allowed computational time (hours)" << endl;
cout << "int Mns \t\t Allowed computational time (minutes)" << endl;
}
else { // correct nr of arguments
int ia = 1;
char whichDSF = *argv[ia++];
DP c_int = atof(argv[ia++]);
int kfact = atoi(argv[ia++]);
DP kBT = atof(argv[ia++]);
DP target_sumrule = atof(argv[ia++]);
int Max_Secs = 3600*atoi(argv[ia++]) + 60*atoi(argv[ia++]);
double StartTime = omp_get_wtime();
double ActualTime = omp_get_wtime();
int Secs_left = Max_Secs;
int iN = 0;
int nN = 16;
Vect<int> Nv(nN);
// Multiples of 32 up to 256
for (int i = 1; i <= 8; ++i) Nv[i-1] = 32*i;
// Then steps of 64 up to 512
for (int i = 1; i <= 4; ++i) Nv[7+i] = 256 + 64*i;
// Then steps of 128 up to 1024
for (int i = 1; i <= 4; ++i) Nv[11+i] = 512 + 128*i;
for (int iN = 0; iN < nN; ++iN) {
int N = Nv[iN];
DP L = N;
int iKmin = 0;
int iKmax = (kfact * N)/8;
DP srsat = 0.0;
bool refine = false;
stringstream SRC_stringstream; string SRC_string;
Data_File_Name (SRC_stringstream, whichDSF, c_int, L, N, iKmin, iKmax, kBT, 0.0, "");
SRC_stringstream << ".src";
SRC_string = SRC_stringstream.str(); const char* SRC_Cstr = SRC_string.c_str();
fstream srcfile;
srcfile.open(SRC_Cstr, fstream::in);
if (srcfile.fail()) {
srsat = 0.0;
refine = false;
}
else {
srcfile >> srsat;
refine = true;
}
srcfile.close();
ActualTime = omp_get_wtime();
Secs_left = int(Max_Secs - (ActualTime - StartTime));
Scan_Info resulting_info;
if (srsat < target_sumrule && Secs_left > Max_Secs/2) {
// Improve the icmin calculation by one chunk:
cout << "---\nTime left = " << Secs_left << " seconds." << endl;
if (srsat > 0) {
cout << "Continue with N = " << N << ". Sumrule previously achieved: " << srsat << endl;
} else {
cout << "Start with N = " << N << "." << endl;
}
resulting_info = Scan_LiebLin (whichDSF, c_int, L, N, iKmin, iKmax, kBT,
Secs_left, target_sumrule, refine);
cout << "Done with N = " << N
<< ". Sumrule obtained: " << resulting_info.sumrule_obtained
<< endl;
}
if (resulting_info.sumrule_obtained > target_sumrule) {
// Move files to storage, keeping a copy of the .src file in the current directory
string command1 = "mkdir -p ../store/data/N_" + to_string(N);
system(command1.c_str());
string command2 = "mv *_N_" + to_string(N) + "* ../store/data/N_" + to_string(N) + "/";
system(command2.c_str());
string command3 = "cp ../store/data/N_" + to_string(N) + "/*src .";
system(command3.c_str());
}
ActualTime = omp_get_wtime();
Secs_left = int(Max_Secs - (ActualTime - StartTime));
if (Secs_left < 30) {
if (resulting_info.sumrule_obtained > target_sumrule) {
cout << "---\nBreaking out after completing N = " << N
<< " since time left = " << Secs_left << " seconds." << endl;
}
else {
cout << "---\nBreaking out while working on N = " << N
<< " since allocated time is exhausted." << endl;
}
break;
}
} // while there is time
} // else if arguments given OK
return(0);
}