diff --git a/CMake/GOMCManageMPI.cmake b/CMake/GOMCManageMPI.cmake index 39ef133ce..3da7dd03e 100644 --- a/CMake/GOMCManageMPI.cmake +++ b/CMake/GOMCManageMPI.cmake @@ -38,7 +38,7 @@ if(GOMC_MPI) if(GOMC_THREAD_MPI) message(STATUS "MPI is not compatible with thread-MPI. Disabling thread-MPI.") set(GOMC_THREAD_MPI OFF CACHE BOOL - "Build a thread-MPI-based multithreaded version of GROMACS (not compatible with MPI)" FORCE) + "Build a thread-MPI-based multithreaded version of GOMC (not compatible with MPI)" FORCE) endif() # Test the CMAKE_C_COMPILER for being an MPI (wrapper) compiler @@ -116,14 +116,14 @@ if(GOMC_MPI) if(OPENMPI_VERSION VERSION_LESS "1.4.1") MESSAGE(WARNING "CMake found OpenMPI version ${OPENMPI_VERSION} on your system. " - "There are known problems with GROMACS and OpenMPI version < 1.4.1. " + "There are known problems with GOMC and OpenMPI version < 1.4.1. " "Please consider updating your OpenMPI if your MPI wrapper compilers " "are using the above OpenMPI version.") endif() if(OPENMPI_VERSION VERSION_EQUAL "1.8.6") MESSAGE(WARNING "CMake found OpenMPI version ${OPENMPI_VERSION} on your system. " - "This OpenMPI version is known to leak memory with GROMACS," + "This OpenMPI version is known to leak memory with GOMC," "please update to a more recent version. ") endif() unset(OPENMPI_VERSION) @@ -154,7 +154,7 @@ if(GOMC_MPI) # This test works correctly even with 1.5a1 MESSAGE(WARNING "CMake found MVAPICH2 version ${MVAPICH2_VERSION} on your system. " - "There are known problems with GROMACS and MVAPICH2 version < 1.5. " + "There are known problems with GOMC and MVAPICH2 version < 1.5. " "Please consider updating your MVAPICH2 if your MPI wrapper compilers " "are using the above MVAPICH2 version.") endif() diff --git a/src/ConfigSetup.cpp b/src/ConfigSetup.cpp index b9ec6876c..558b5d30c 100644 --- a/src/ConfigSetup.cpp +++ b/src/ConfigSetup.cpp @@ -166,7 +166,7 @@ bool ConfigSetup::CheckString(string str1, string str2) return (str1 == str2); } -void ConfigSetup::Init(const char *fileName) +void ConfigSetup::Init(const char *fileName, MultiSim const*const& multisim) { std::vector line; @@ -265,845 +265,7 @@ void ConfigSetup::Init(const char *fileName) } #endif else if(CheckString(line[0], "Temperature")) { - sys.T.inKelvin = stringtod(line[1]); - printf("%-40s %-4.4f K\n", "Info: Input Temperature", sys.T.inKelvin); - } else if(CheckString(line[0], "Potential")) { - if(CheckString(line[1], "VDW")) { - sys.ff.VDW_KIND = sys.ff.VDW_STD_KIND; - printf("%-40s %-s \n", "Info: Non-truncated potential", "Active"); - } else if(CheckString(line[1], "SHIFT")) { - sys.ff.VDW_KIND = sys.ff.VDW_SHIFT_KIND; - printf("%-40s %-s \n", "Info: Shift truncated potential", "Active"); - } else if(CheckString(line[1], "SWITCH")) { - sys.ff.VDW_KIND = sys.ff.VDW_SWITCH_KIND; - printf("%-40s %-s \n", "Info: Switch truncated potential", "Active"); - } else if(CheckString(line[1], "EXP6")) { - sys.ff.VDW_KIND = sys.ff.VDW_EXP6_KIND; - printf("%-40s %-s \n", "Info: Exp-6 Non-truncated potential", "Active"); - } - } else if(CheckString(line[0], "LRC")) { - sys.ff.doTailCorr = checkBool(line[1]); - if(sys.ff.doTailCorr) - printf("%-40s %-s \n", "Info: Long Range Correction", "Active"); - else - printf("%-40s %-s \n", "Info: Long Range Correction", "Inactive"); - } else if(CheckString(line[0], "Rswitch")) { - sys.ff.rswitch = stringtod(line[1]); - printf("%-40s %-4.4f \n", "Info: Switch distance", sys.ff.rswitch); - } else if(CheckString(line[0], "ExchangeVolumeDim")) { - if(line.size() == 4) { - XYZ temp; - temp.x = stringtod(line[1]); - temp.y = stringtod(line[2]); - temp.z = stringtod(line[3]); - sys.memcVal.subVol = temp; - sys.intraMemcVal.subVol = temp; - printf("%-40s %-4.3f %-4.3f %-4.3f A\n", - "Info: Exchange Sub-Volume Dimensions", temp.x, temp.y, temp.z); - sys.memcVal.readVol = true; - sys.intraMemcVal.readVol = true; - } - } else if(CheckString(line[0], "ExchangeRatio")) { - if(line.size() >= 2) { - printf("%-41s", "Info: ExchangeRatio"); - for(uint i = 1; i < line.size(); i++) { - uint val = stringtoi(line[i]); - sys.memcVal.exchangeRatio.push_back(val); - sys.intraMemcVal.exchangeRatio.push_back(val); - printf("%-5d", val); - } - std::cout << endl; - sys.memcVal.readRatio = true; - sys.intraMemcVal.readRatio = true; - } - } else if(CheckString(line[0], "ExchangeLargeKind")) { - if(line.size() >= 2) { - printf("%-41s", "Info: Exchange Large Kind"); - for(uint i = 1; i < line.size(); i++) { - std::string resName = line[i]; - sys.memcVal.largeKind.push_back(resName); - sys.intraMemcVal.largeKind.push_back(resName); - printf("%-5s", resName.c_str()); - } - std::cout << endl; - sys.memcVal.readLK = true; - sys.intraMemcVal.readLK = true; - } - } else if(CheckString(line[0], "ExchangeSmallKind")) { - if(line.size() >= 2) { - printf("%-41s", "Info: Exchange Small Kind"); - for(uint i = 1; i < line.size(); i++) { - std::string resName = line[i]; - sys.memcVal.smallKind.push_back(resName); - sys.intraMemcVal.smallKind.push_back(resName); - printf("%-5s", resName.c_str()); - } - std::cout << endl; - sys.memcVal.readSK = true; - sys.intraMemcVal.readSK = true; - } - } else if(CheckString(line[0], "SmallKindBackBone")) { - if((line.size() % 2) == 0) { - std::cout << "Error: Two atom names must be defined for the backbone of each small molecule kind!\n"; - exit(EXIT_FAILURE); - } - if(line.size() >= 3) { - printf("%-41s", "Info: Atom Names in BackBone of Small Molecule Kind "); - for(uint i = 1; i < line.size() - 1; i += 2) { - if(i != 1) { - printf(" , "); - } - std::string atom1 = line[i]; - std::string atom2 = line[i + 1]; - sys.memcVal.smallBBAtom1.push_back(atom1); - sys.memcVal.smallBBAtom2.push_back(atom2); - sys.intraMemcVal.smallBBAtom1.push_back(atom1); - sys.intraMemcVal.smallBBAtom2.push_back(atom2); - printf("%-s - %-s", atom1.c_str(), atom2.c_str()); - } - std::cout << endl; - sys.memcVal.readSmallBB = true; - sys.intraMemcVal.readSmallBB = true; - } - } else if(CheckString(line[0], "LargeKindBackBone")) { - if((line.size() % 2) == 0) { - std::cout << "Error: Two atom names must be defined for the backbone of each large molecule kind!\n"; - exit(EXIT_FAILURE); - } - if(line.size() >= 3) { - printf("%-41s", "Info: Atom Names in BackBone of Large Molecule Kind "); - for(uint i = 1; i < line.size() - 1; i += 2) { - if(i != 1) { - printf(" , "); - } - std::string atom1 = line[i]; - std::string atom2 = line[i + 1]; - sys.memcVal.largeBBAtom1.push_back(atom1); - sys.memcVal.largeBBAtom2.push_back(atom2); - sys.intraMemcVal.largeBBAtom1.push_back(atom1); - sys.intraMemcVal.largeBBAtom2.push_back(atom2); - printf("%-s - %-s", atom1.c_str(), atom2.c_str()); - } - std::cout << endl; - sys.memcVal.readLargeBB = true; - sys.intraMemcVal.readLargeBB = true; - } - } else if(CheckString(line[0], "VDWGeometricSigma")) { - sys.ff.vdwGeometricSigma = checkBool(line[1]); - if(sys.ff.vdwGeometricSigma) - printf("%-40s %-s A\n", "Info: Geometric mean to combine LJ sigma", "Active"); - } else if(CheckString(line[0], "Rcut")) { - sys.ff.cutoff = stringtod(line[1]); - printf("%-40s %-4.4f A\n", "Info: Cutoff", sys.ff.cutoff); - } else if(CheckString(line[0], "RcutLow")) { - sys.ff.cutoffLow = stringtod(line[1]); - printf("%-40s %-4.4f A\n", "Info: Short Range Cutoff", sys.ff.cutoffLow); - } else if(CheckString(line[0], "Exclude")) { - if(line[1] == sys.exclude.EXC_ONETWO) { - sys.exclude.EXCLUDE_KIND = sys.exclude.EXC_ONETWO_KIND; - printf("%-40s %-s \n", "Info: Exclude", "ONE-TWO"); - } else if(line[1] == sys.exclude.EXC_ONETHREE) { - sys.exclude.EXCLUDE_KIND = sys.exclude.EXC_ONETHREE_KIND; - printf("%-40s %-s \n", "Info: Exclude", "ONE-THREE"); - } else if(line[1] == sys.exclude.EXC_ONEFOUR) { - sys.exclude.EXCLUDE_KIND = sys.exclude.EXC_ONEFOUR_KIND; - printf("%-40s %-s \n", "Info: Exclude", "ONE-FOUR"); - } - } else if(CheckString(line[0], "Ewald")) { - sys.elect.ewald = checkBool(line[1]); - sys.elect.readEwald = true; - if(sys.elect.ewald) { - printf("%-40s %-s \n", "Info: Ewald Summation", "Active"); - } - } else if(CheckString(line[0], "ElectroStatic")) { - sys.elect.enable = checkBool(line[1]); - sys.elect.readElect = true; - } else if(CheckString(line[0], "Tolerance")) { - sys.elect.tolerance = stringtod(line[1]); - printf("%-40s %-1.3E \n", "Info: Ewald Summation Tolerance", - sys.elect.tolerance); - } else if(CheckString(line[0], "RcutCoulomb")) { - if(line.size() == 3) { - uint b = stringtoi(line[1]); - if(b < BOX_TOTAL) { - sys.elect.cutoffCoulomb[b] = stringtod(line[2]); - sys.elect.cutoffCoulombRead[b] = true; - printf("%s %-d %-27s %4.4f A\n", "Info: Box ", b, " CutoffCoulomb", sys.elect.cutoffCoulomb[b]); - } else { - std::cout << "Error: This simulation requires only " << BOX_TOTAL << - " sets of Coulomb Cutoff!" << std::endl; - exit(EXIT_FAILURE); - } - } - } else if(CheckString(line[0], "CachedFourier")) { - sys.elect.cache = checkBool(line[1]); - sys.elect.readCache = true; - if(sys.elect.cache) { - printf("%-40s %-s \n", "Info: Cache Ewald Fourier", "Active"); - } else { - printf("%-40s %-s \n", "Info: Cache Ewald Fourier", "Inactive"); - } - } else if(CheckString(line[0], "1-4scaling")) { - sys.elect.oneFourScale = stringtod(line[1]); - } else if(CheckString(line[0], "Dielectric")) { - sys.elect.dielectric = stringtod(line[1]); - printf("%-40s %-4.4f \n", "Info: Dielectric", sys.elect.dielectric); - } else if(CheckString(line[0], "RunSteps")) { - sys.step.total = stringtoi(line[1]); - printf("%-40s %-lu \n", "Info: Total number of steps", sys.step.total); - if(sys.step.total == 0) { - in.restart.recalcTrajectory = true; - printf("%-40s %-s \n", "Info: Recalculate Trajectory", "Active"); - } - } else if(CheckString(line[0], "EqSteps")) { - sys.step.equil = stringtoi(line[1]); - printf("%-40s %-lu \n", "Info: Number of equilibration steps", - sys.step.equil); - } else if(CheckString(line[0], "AdjSteps")) { - sys.step.adjustment = stringtoi(line[1]); - printf("%-40s %-lu \n", "Info: Move adjustment frequency", - sys.step.adjustment); - } else if(CheckString(line[0], "PressureCalc")) { - sys.step.pressureCalc = checkBool(line[1]); - if(line.size() == 3) - sys.step.pressureCalcFreq = stringtoi(line[2]); - - if(sys.step.pressureCalc && (line.size() == 2)) { - std::cout << "Error: Pressure calculation frequency is not specified!\n"; - exit(EXIT_FAILURE); - } - if(!sys.step.pressureCalc) - printf("%-40s %-s \n", "Info: Pressure calculation", "Inactive"); - else { - printf("%-40s %-lu \n", "Info: Pressure calculation frequency", - sys.step.pressureCalcFreq); - } - } else if(CheckString(line[0], "DisFreq")) { - sys.moves.displace = stringtod(line[1]); - printf("%-40s %-4.4f \n", "Info: Displacement move frequency", - sys.moves.displace); - } else if(CheckString(line[0],"MultiParticleFreq")) { - sys.moves.multiParticle = stringtod(line[1]); - if(sys.moves.multiParticle > 0.00) { - sys.moves.multiParticleEnabled = true; - } - printf("%-40s %-4.4f \n", - "Info: Multi-Particle move frequency", - sys.moves.multiParticle); - } else if(CheckString(line[0],"IntraSwapFreq")) { - sys.moves.intraSwap = stringtod(line[1]); - printf("%-40s %-4.4f \n", "Info: Intra-Swap move frequency", - sys.moves.intraSwap); - } else if(CheckString(line[0], "RegrowthFreq")) { - sys.moves.regrowth = stringtod(line[1]); - printf("%-40s %-4.4f \n", "Info: Regrowth move frequency", - sys.moves.regrowth); - } else if(CheckString(line[0], "CrankShaftFreq")) { - sys.moves.crankShaft = stringtod(line[1]); - printf("%-40s %-4.4f \n", "Info: Crank-Shaft move frequency", - sys.moves.crankShaft); - } else if(CheckString(line[0], "RotFreq")) { - sys.moves.rotate = stringtod(line[1]); - printf("%-40s %-4.4f \n", "Info: Rotation move frequency", - sys.moves.rotate); - } else if(CheckString(line[0], "IntraMEMC-1Freq")) { - sys.moves.intraMemc = stringtod(line[1]); - printf("%-40s %-4.4f \n", "Info: IntraMEMC-1 move frequency", - sys.moves.intraMemc); - if(sys.moves.intraMemc > 0.0) { - sys.intraMemcVal.enable = true; - sys.intraMemcVal.MEMC1 = true; - } - } else if(CheckString(line[0], "IntraMEMC-2Freq")) { - sys.moves.intraMemc = stringtod(line[1]); - printf("%-40s %-4.4f \n", "Info: IntraMEMC-2 move frequency", - sys.moves.intraMemc); - if(sys.moves.intraMemc > 0.0) { - sys.intraMemcVal.enable = true; - sys.intraMemcVal.MEMC2 = true; - } - } else if(CheckString(line[0], "IntraMEMC-3Freq")) { - sys.moves.intraMemc = stringtod(line[1]); - printf("%-40s %-4.4f \n", "Info: IntraMEMC-3 move frequency", - sys.moves.intraMemc); - if(sys.moves.intraMemc > 0.0) { - sys.intraMemcVal.enable = true; - sys.intraMemcVal.MEMC3 = true; - } - } -#ifdef VARIABLE_VOLUME - else if(CheckString(line[0], "VolFreq")) { - sys.moves.volume = stringtod(line[1]); - printf("%-40s %-4.4f \n", "Info: Volume move frequency", - sys.moves.volume); - } else if(CheckString(line[0], "useConstantArea")) { - sys.volume.cstArea = checkBool(line[1]); - if(sys.volume.cstArea) - printf("Info: Volume change using constant X-Y area.\n"); - else - printf("Info: Volume change using constant ratio.\n"); - } else if(CheckString(line[0], "FixVolBox0")) { - sys.volume.cstVolBox0 = checkBool(line[1]); - if(sys.volume.cstVolBox0) - printf("%-40s %-d \n", "Info: Fix volume box", 0); - } -#endif -#if ENSEMBLE == GEMC || ENSEMBLE == GCMC - else if(CheckString(line[0], "SwapFreq")) { - sys.moves.transfer = stringtod(line[1]); - printf("%-40s %-4.4f \n", "Info: Molecule swap move frequency", - sys.moves.transfer); - } else if(CheckString(line[0], "MEMC-1Freq")) { - sys.moves.memc = stringtod(line[1]); - printf("%-40s %-4.4f \n", "Info: MEMC-1 move frequency", - sys.moves.memc); - if(sys.moves.memc > 0.0) { - sys.memcVal.enable = true; - sys.memcVal.MEMC1 = true; - } - } else if(CheckString(line[0], "MEMC-2Freq")) { - sys.moves.memc = stringtod(line[1]); - printf("%-40s %-4.4f \n", "Info: MEMC-2 move frequency", - sys.moves.memc); - if(sys.moves.memc > 0.0) { - sys.memcVal.enable = true; - sys.memcVal.MEMC2 = true; - } - } else if(CheckString(line[0], "MEMC-3Freq")) { - sys.moves.memc = stringtod(line[1]); - printf("%-40s %-4.4f \n", "Info: MEMC-3 move frequency", - sys.moves.memc); - if(sys.moves.memc > 0.0) { - sys.memcVal.enable = true; - sys.memcVal.MEMC3 = true; - } - } else if(CheckString(line[0], "CFCMCFreq")) { - sys.moves.cfcmc = stringtod(line[1]); - printf("%-40s %-4.4f \n", "Info: CFCMC move frequency", - sys.moves.cfcmc); - if(sys.moves.cfcmc > 0.0) { - sys.cfcmcVal.enable = true; - } - } else if(CheckString(line[0], "LambdaCoulomb")) { - if(line.size() > 1) { - sys.cfcmcVal.readLambdaCoulomb = true; - printf("%-41s", "Info: Lambda Coulomb"); - for(uint i = 1; i < line.size(); i++) { - double val = stringtod(line[i]); - sys.cfcmcVal.lambdaCoulomb.push_back(val); - printf("%-6.3f", val); - } - std::cout << endl; - } - } else if(CheckString(line[0], "LambdaVDW")) { - if(line.size() > 1) { - sys.cfcmcVal.readLambdaVDW = true; - printf("%-41s", "Info: Lambda VDW"); - for(uint i = 1; i < line.size(); i++) { - double val = stringtod(line[i]); - sys.cfcmcVal.lambdaVDW.push_back(val); - printf("%-6.3f", val); - } - std::cout << endl; - } - } else if(CheckString(line[0], "RelaxingSteps")) { - if(line.size() > 1) { - sys.cfcmcVal.readRelaxSteps = true; - sys.cfcmcVal.relaxSteps = stringtoi(line[1]); - printf("%-40s %-4d \n", "Info: CFCMC Relaxing Steps", - sys.cfcmcVal.relaxSteps); - } - } else if(CheckString(line[0], "HistFlatness")) { - if(line.size() > 1) { - sys.cfcmcVal.readHistFlatness = true; - sys.cfcmcVal.histFlatness = stringtod(line[1]); - printf("%-40s %-4.4f \n", "Info: CFCMC Histogram Flatness", - sys.cfcmcVal.histFlatness); - } - } else if(CheckString(line[0], "MultiParticleRelaxing")) { - if(line.size() > 1) { - sys.cfcmcVal.MPEnable = checkBool(line[1]); - sys.cfcmcVal.readMPEnable = true; - if(sys.cfcmcVal.MPEnable) { - sys.moves.multiParticleEnabled = sys.cfcmcVal.MPEnable; - printf("%-40s %s \n", "Info: CFCMC Relaxing using MultiParticle", - "Active"); - } else { - printf("%-40s %s \n", "Info: CFCMC Relaxing using MultiParticle", - "Inactive"); - } - } - } else if(CheckString(line[0], "ScalePower")) { - if(line.size() > 1) { - sys.cfcmcVal.scalePower = stringtoi(line[1]); - sys.cfcmcVal.scalePowerRead = true; - printf("%-40s %-4d \n", "Info: Soft-core scaling power(p)", - sys.cfcmcVal.scalePower); - } - } else if(CheckString(line[0], "ScaleAlpha")) { - if(line.size() > 1) { - sys.cfcmcVal.scaleAlpha = stringtod(line[1]); - sys.cfcmcVal.scaleAlphaRead = true; - printf("%-40s %-4.4f \n", "Info: Soft-core softness(alpha)", - sys.cfcmcVal.scaleAlpha); - } - } else if(CheckString(line[0], "MinSigma")) { - if(line.size() > 1) { - sys.cfcmcVal.scaleSigma = stringtod(line[1]); - sys.cfcmcVal.scaleSigmaRead = true; - printf("%-40s %-4.4f A \n", "Info: Soft-core minimum sigma", - sys.cfcmcVal.scaleSigma); - } - } else if(CheckString(line[0], "ScaleCoulomb")) { - if(line.size() > 1) { - sys.cfcmcVal.scaleCoulomb = checkBool(line[1]); - sys.cfcmcVal.scaleCoulombRead = true; - if(sys.cfcmcVal.scaleCoulomb) { - printf("%-40s %s \n", "Info: Soft-core for Coulombic interaction", - "Active"); - } else { - printf("%-40s %s \n", "Info: Soft-core for Coulombic interaction", - "Inactive"); - } - } - } -#endif - else if(CheckString(line[0], "CellBasisVector1")) { - uint box = stringtoi(line[1]); - if(box < BOX_TOTAL) { - if(!sys.volume.readCellBasis[box][0]) { - XYZ temp; - temp.x = stringtod(line[2]); - temp.y = stringtod(line[3]); - temp.z = stringtod(line[4]); - sys.volume.axis[box].Set(0, temp); - sys.volume.readCellBasis[box][0] = true; - sys.volume.hasVolume = sys.volume.ReadCellBasis(); - } - } else { - std::cout << "Error: This simulation requires only " << BOX_TOTAL << - " sets of Cell Basis Vector!" << std::endl; - exit(EXIT_FAILURE); - } - } else if(CheckString(line[0], "CellBasisVector2")) { - uint box = stringtoi(line[1]); - if(box < BOX_TOTAL) { - if(!sys.volume.readCellBasis[box][1]) { - XYZ temp; - temp.x = stringtod(line[2]); - temp.y = stringtod(line[3]); - temp.z = stringtod(line[4]); - sys.volume.axis[box].Set(1, temp); - sys.volume.readCellBasis[box][1] = true; - sys.volume.hasVolume = sys.volume.ReadCellBasis(); - } - } else { - std::cout << "Error: This simulation requires only " << BOX_TOTAL << - " sets of Cell Basis Vector!" << std::endl; - exit(EXIT_FAILURE); - } - } else if(CheckString(line[0], "CellBasisVector3")) { - uint box = stringtoi(line[1]); - if(box < BOX_TOTAL) { - if(!sys.volume.readCellBasis[box][2]) { - XYZ temp; - temp.x = stringtod(line[2]); - temp.y = stringtod(line[3]); - temp.z = stringtod(line[4]); - sys.volume.axis[box].Set(2, temp); - sys.volume.readCellBasis[box][2] = true; - sys.volume.hasVolume = sys.volume.ReadCellBasis(); - } - } else { - std::cout << "Error: This simulation requires only " << BOX_TOTAL << - " sets of Cell Basis Vector!" << std::endl; - exit(EXIT_FAILURE); - } - } -#ifdef VARIABLE_PARTICLE_NUMBER - else if(CheckString(line[0], "CBMC_First")) { - sys.cbmcTrials.nonbonded.first = stringtoi(line[1]); - printf("%-40s %-4d \n", "Info: CBMC First atom trials", - sys.cbmcTrials.nonbonded.first); - } else if(CheckString(line[0], "CBMC_Nth")) { - sys.cbmcTrials.nonbonded.nth = stringtoi(line[1]); - printf("%-40s %-4d \n", "Info: CBMC Secondary atom trials", - sys.cbmcTrials.nonbonded.nth); - } else if(CheckString(line[0], "CBMC_Ang")) { - sys.cbmcTrials.bonded.ang = stringtoi(line[1]); - printf("%-40s %-4d \n", "Info: CBMC Angle trials", - sys.cbmcTrials.bonded.ang); - } else if(CheckString(line[0], "CBMC_Dih")) { - sys.cbmcTrials.bonded.dih = stringtoi(line[1]); - printf("%-40s %-4d \n", "Info: CBMC Dihedral trials", - sys.cbmcTrials.bonded.dih); - } -#endif -#if ENSEMBLE == GCMC - else if(CheckString(line[0], "ChemPot")) { - if(line.size() != 3) { - std::cout << "Error: Chemical potential parameters are not specified!\n"; - exit(EXIT_FAILURE); - } - std::string resName = line[1]; - double val = stringtod(line[2]); - sys.chemPot.cp[resName] = val; - printf("%-40s %-6s %-6.4f K\n", "Info: Chemical potential", - resName.c_str(), val); - } else if(CheckString(line[0], "Fugacity")) { - if(line.size() != 3) { - std::cout << "Error: Fugacity parameters are not specified!\n"; - exit(EXIT_FAILURE); - } - sys.chemPot.isFugacity = true; - std::string resName = line[1]; - double val = stringtod(line[2]); - sys.chemPot.cp[resName] = val * unit::BAR_TO_K_MOLECULE_PER_A3; - printf("%-40s %-6s %-6.4f bar\n", "Info: Fugacity", resName.c_str(), - val); - } -#endif -#if ENSEMBLE == NVT || ENSEMBLE == NPT - else if(CheckString(line[0], "LambdaCoulomb")) { - if(line.size() > 1) { - sys.freeEn.readLambdaCoulomb = true; - printf("%-41s", "Info: Lambda Coulomb"); - for(uint i = 1; i < line.size(); i++) { - double val = stringtod(line[i]); - sys.freeEn.lambdaCoulomb.push_back(val); - printf("%-6.3f", val); - } - std::cout << endl; - } - } else if(CheckString(line[0], "LambdaVDW")) { - if(line.size() > 1) { - sys.freeEn.readLambdaVDW = true; - printf("%-41s", "Info: Lambda VDW"); - for(uint i = 1; i < line.size(); i++) { - double val = stringtod(line[i]); - sys.freeEn.lambdaVDW.push_back(val); - printf("%-6.3f", val); - } - std::cout << endl; - } - } else if(CheckString(line[0], "FreeEnergyCalc")) { - if(line.size() > 1) { - sys.freeEn.enable = checkBool(line[1]); - if(sys.freeEn.enable){ - printf("%-40s %-s \n", "Info: Free Energy Calculation", "Active"); - if(line.size() > 2) { - sys.freeEn.frequency = stringtoi(line[2]); - sys.freeEn.freqRead = true; - printf("%-40s %-4d \n", "Info: Free Energy Frequency", - sys.freeEn.frequency); - } - } else { - printf("%-40s %-s \n", "Info: Free Energy Calculation", "Inactive"); - } - } - } else if (CheckString(line[0], "MoleculeType")) { - if(line.size() > 1) { - sys.freeEn.molType = line[1]; - sys.freeEn.molTypeRead = true; - if(line.size() > 2) { - sys.freeEn.molIndex = stringtoi(line[2]); - sys.freeEn.molIndexRead = true; - printf("%-40s %-d in %-s \n", "Info: Free Energy Calc for Molecule", - sys.freeEn.molIndex, sys.freeEn.molType.c_str()); - } - } - } else if (CheckString(line[0], "InitialState")) { - if(line.size() > 1) { - sys.freeEn.iState = stringtoi(line[1]); - sys.freeEn.iStateRead = true; - printf("%-40s %-d \n", "Info: Free Energy Calc Lambda state", - sys.freeEn.iState); - } - } else if(CheckString(line[0], "ScalePower")) { - if(line.size() > 1) { - sys.freeEn.scalePower = stringtoi(line[1]); - sys.freeEn.scalePowerRead = true; - printf("%-40s %-4d \n", "Info: Soft-core scaling power(p)", - sys.freeEn.scalePower); - } - } else if(CheckString(line[0], "ScaleAlpha")) { - if(line.size() > 1) { - sys.freeEn.scaleAlpha = stringtod(line[1]); - sys.freeEn.scaleAlphaRead = true; - printf("%-40s %-4.4f \n", "Info: Soft-core softness(alpha)", - sys.freeEn.scaleAlpha); - } - } else if(CheckString(line[0], "MinSigma")) { - if(line.size() > 1) { - sys.freeEn.scaleSigma = stringtod(line[1]); - sys.freeEn.scaleSigmaRead = true; - printf("%-40s %-4.4f \n", "Info: Soft-core minimum sigma", - sys.freeEn.scaleSigma); - } - } else if(CheckString(line[0], "ScaleCoulomb")) { - if(line.size() > 1) { - sys.freeEn.scaleCoulomb = checkBool(line[1]); - sys.freeEn.scaleCoulombRead = true; - if(sys.freeEn.scaleCoulomb) { - printf("%-40s %s \n", "Info: Soft-core for Coulombic interaction", - "Active"); - } else { - printf("%-40s %s \n", "Info: Soft-core for Coulombic interaction", - "Inactive"); - } - } - } -#endif - else if(CheckString(line[0], "OutputName")) { - out.statistics.settings.uniqueStr.val = line[1]; - printf("%-40s %-s \n", "Info: Output name", line[1].c_str()); - } else if(CheckString(line[0], "CheckpointFreq")) { - out.checkpoint.enable = checkBool(line[1]); - if(line.size() == 3) - out.checkpoint.frequency = stringtoi(line[2]); - if(out.checkpoint.enable) - printf("%-40s %-lu \n", "Info: Checkpoint frequency", - out.checkpoint.frequency); - else - printf("%-40s %-s \n", "Info: Saving checkpoint", "Inactive"); - } else if(CheckString(line[0], "CoordinatesFreq")) { - out.state.settings.enable = checkBool(line[1]); - if(line.size() == 3) - out.state.settings.frequency = stringtoi(line[2]); - - if(out.state.settings.enable && (line.size() == 2)) - out.state.settings.frequency = (ulong)sys.step.total / 10; - - if(out.state.settings.enable) { - printf("%-40s %-lu \n", "Info: Coordinate frequency", - out.state.settings.frequency); - } else - printf("%-40s %-s \n", "Info: Printing coordinate", "Inactive"); - } else if(CheckString(line[0], "RestartFreq")) { - out.restart.settings.enable = checkBool(line[1]); - if(line.size() == 3) - out.restart.settings.frequency = stringtoi(line[2]); - - if(out.restart.settings.enable && (line.size() == 2)) - out.restart.settings.frequency = (ulong)sys.step.total; - - if(out.restart.settings.enable) { - printf("%-40s %-lu \n", "Info: Restart frequency", - out.restart.settings.frequency); - } else - printf("%-40s %-s \n", "Info: Printing restart coordinate", "Inactive"); - } else if(CheckString(line[0], "ConsoleFreq")) { - out.console.enable = checkBool(line[1]); - if(line.size() == 3) - out.console.frequency = stringtoi(line[2]); - - if(out.console.enable && (line.size() == 2)) { - if(sys.step.total > 1000) { - out.console.frequency = (ulong)sys.step.total / 1000; - } else { - out.console.frequency = (ulong)sys.step.total / 100; - } - } - if(out.console.enable) { - printf("%-40s %-lu \n", "Info: Console output frequency", - out.console.frequency); - } else - printf("%-40s %-s \n", "Info: Console output", "Inactive"); - } else if(CheckString(line[0], "BlockAverageFreq")) { - out.statistics.settings.block.enable = checkBool(line[1]); - if(line.size() == 3) - out.statistics.settings.block.frequency = stringtoi(line[2]); - - if(out.statistics.settings.block.enable && (line.size() == 2)) - out.statistics.settings.block.frequency = (ulong)sys.step.total / 100; - - if(out.statistics.settings.block.enable) { - printf("%-40s %-lu \n", "Info: Average output frequency", - out.statistics.settings.block.frequency); - } else - printf("%-40s %-s \n", "Info: Average output", "Inactive"); - } -#if ENSEMBLE == GCMC - else if(CheckString(line[0], "HistogramFreq")) { - out.statistics.settings.hist.enable = checkBool(line[1]); - if(line.size() == 3) - out.statistics.settings.hist.frequency = stringtoi(line[2]); - - if(out.statistics.settings.hist.enable && (line.size() == 2)) { - if(sys.step.total > 1000) { - out.statistics.settings.hist.frequency = (ulong)sys.step.total / 1000; - } else { - out.statistics.settings.hist.frequency = (ulong)sys.step.total / 100; - } - } - - if(out.statistics.settings.hist.enable) { - printf("%-40s %-lu \n", "Info: Histogram output frequency", - out.statistics.settings.hist.frequency); - } else - printf("%-40s %-s \n", "Info: Histogram output", "Inactive"); - } else if(CheckString(line[0], "DistName")) { - out.state.files.hist.histName = line[1]; - } else if(CheckString(line[0], "HistName")) { - out.state.files.hist.sampleName = line[1]; - } else if(CheckString(line[0], "RunNumber")) { - out.state.files.hist.number = line[1]; - } else if(CheckString(line[0], "RunLetter")) { - out.state.files.hist.letter = line[1]; - } else if(CheckString(line[0], "SampleFreq")) { - out.state.files.hist.stepsPerHistSample = stringtoi(line[1]); - printf("%-40s %-d \n", "Info: Histogram sample frequency", - out.state.files.hist.stepsPerHistSample); - } -#endif - else if(CheckString(line[0], "OutEnergy")) { - out.statistics.vars.energy.block = checkBool(line[1]); - out.statistics.vars.energy.fluct = checkBool(line[2]); - } else if(CheckString(line[0], "OutPressure")) { - out.statistics.vars.pressure.block = checkBool(line[1]); - out.statistics.vars.pressure.fluct = checkBool(line[2]); - } -#ifdef VARIABLE_PARTICLE_NUMBER - else if(CheckString(line[0], "OutMolNum")) { - out.statistics.vars.molNum.block = checkBool(line[1]); - out.statistics.vars.molNum.fluct = checkBool(line[2]); - } -#endif - else if(CheckString(line[0], "OutDensity")) { - out.statistics.vars.density.block = checkBool(line[1]); - out.statistics.vars.density.fluct = checkBool(line[2]); - } else if(CheckString(line[0], "OutSurfaceTension")) { - out.statistics.vars.surfaceTension.block = checkBool(line[1]); - out.statistics.vars.surfaceTension.fluct = checkBool(line[2]); - } -#ifdef VARIABLE_VOLUME - else if(CheckString(line[0], "OutVolume")) { - out.statistics.vars.volume.block = checkBool(line[1]); - out.statistics.vars.volume.fluct = checkBool(line[2]); - } -#endif - else if(CheckString(line[0], "Random_Seed")) { - in.prng.seed = stringtoi(line[1]); - if("INTSEED" == in.prng.kind) - printf("%-40s %-s \n", "Info: Constant seed", "Active"); - else - printf("Warning: Constant seed set, but will be ignored.\n"); - } else { - cout << "Warning: Unknown input " << line[0] << "!" << endl; - } - // Clear and get ready for the next line - line.clear(); - } - - //*********** Fill in the default values if not specified ***********// - fillDefaults(); - - //*********** Verify inputs ***********// - verifyInputs(); - printf("%-40s %-s\n\n", "Finished Reading Input File:", fileName); -} - -#if GOMC_LIB_MPI -void ConfigSetup::Init(const char *fileName, MultiSim *& multisim) -{ - std::vector line; - - reader.Open(fileName); - printf("\n%-40s %-s\n", "Reading Input File:", fileName); - while(reader.readNextLine(line)) { - if(line.size() == 0) - continue; - - if(CheckString(line[0], "Restart")) { - in.restart.enable = checkBool(line[1]); - if(in.restart.enable) { - printf("%-40s %-s \n", "Info: Restart simulation", "Active"); - } - } else if(CheckString(line[0], "RestartCheckpoint")) { - in.restart.restartFromCheckpoint = checkBool(line[1]); - if(in.restart.restartFromCheckpoint) { - printf("%-40s %-s \n", "Info: Restart checkpoint", "Active"); - } - } else if(CheckString(line[0], "FirstStep")) { - in.restart.step = stringtoi(line[1]); - } else if(CheckString(line[0], "PRNG")) { - in.prng.kind = line[1]; - if("RANDOM" == line[1]) - printf("%-40s %-s \n", "Info: Random seed", "Active"); - } else if(CheckString(line[0], "ParaTypeCHARMM")) { - if(checkBool(line[1])) { - in.ffKind.numOfKinds++; - in.ffKind.isEXOTIC = false; - in.ffKind.isMARTINI = false; - in.ffKind.isCHARMM = true; - printf("%-40s %-s \n", "Info: PARAMETER file", "CHARMM format!"); - } - } else if(CheckString(line[0], "ParaTypeEXOTIC")) { - if(checkBool(line[1])) { - in.ffKind.numOfKinds++; - in.ffKind.isCHARMM = false; - in.ffKind.isMARTINI = false; - in.ffKind.isEXOTIC = true; - printf("%-40s %-s \n", "Info: PARAMETER file", "MIE format!"); - } - } else if(CheckString(line[0], "ParaTypeMIE")) { - if(checkBool(line[1])) { - in.ffKind.numOfKinds++; - in.ffKind.isCHARMM = false; - in.ffKind.isMARTINI = false; - in.ffKind.isEXOTIC = true; - printf("%-40s %-s \n", "Info: PARAMETER file", "MIE format!"); - } - } else if(CheckString(line[0], "ParaTypeMARTINI")) { - if(checkBool(line[1])) { - in.ffKind.numOfKinds ++; - in.ffKind.isEXOTIC = false; - in.ffKind.isMARTINI = true; - in.ffKind.isCHARMM = true; - printf("%-40s %-s \n", "Info: PARAMETER file", "MARTINI using CHARMM format!"); - } - } else if(CheckString(line[0], "Parameters")) { - in.files.param.name = line[1]; - } else if(CheckString(line[0], "Coordinates")) { - uint boxnum = stringtoi(line[1]); - if(boxnum >= BOX_TOTAL) { - std::cout << "Error: Simulation requires " << BOX_TOTAL << " PDB file(s)!\n"; - exit(EXIT_FAILURE); - } - in.files.pdb.name[boxnum] = line[2]; - } else if(CheckString(line[0], "Structure")) { - uint boxnum = stringtoi(line[1]); - if(boxnum >= BOX_TOTAL) { - std::cout << "Error: Simulation requires " << BOX_TOTAL << " PSF file(s)!\n"; - exit(EXIT_FAILURE); - } - in.files.psf.name[boxnum] = line[2]; - } -#if ENSEMBLE == GEMC - else if(CheckString(line[0], "GEMC")) { - if(CheckString(line[1], "NVT")) { - sys.gemc.kind = mv::GEMC_NVT; - printf("Info: Running NVT_GEMC\n"); - } else if(CheckString(line[1], "NPT")) { - sys.gemc.kind = mv::GEMC_NPT; - printf("Info: Running NPT_GEMC\n"); - } - } else if(CheckString(line[0], "Pressure")) { - sys.gemc.pressure = stringtod(line[1]); - printf("%-40s %-4.4f bar\n", "Info: Input Pressure", sys.gemc.pressure); - sys.gemc.pressure *= unit::BAR_TO_K_MOLECULE_PER_A3; - } -#endif -#if ENSEMBLE == NPT - else if(CheckString(line[0], "Pressure")) { - sys.gemc.kind = mv::GEMC_NPT; - sys.gemc.pressure = stringtod(line[1]); - printf("%-40s %-4.4f bar\n", "Info: Input Pressure", sys.gemc.pressure); - sys.gemc.pressure *= unit::BAR_TO_K_MOLECULE_PER_A3; - } -#endif - else if(CheckString(line[0], "Temperature")) { - if (line.size() > 2){ + if (line.size() > 2 && multisim != NULL){ sys.T.inKelvin = stringtod(line[multisim->worldRank+1]); } else { sys.T.inKelvin = stringtod(line[1]); @@ -1583,7 +745,7 @@ void ConfigSetup::Init(const char *fileName, MultiSim *& multisim) #endif #if ENSEMBLE == GCMC else if(CheckString(line[0], "ChemPot")) { - if (line.size() > 3){ + if (line.size() > 3 && multisim != NULL){ std::string resName = line[1]; double val = stringtod(line[2 + multisim->worldRank]); sys.chemPot.cp[resName] = val; @@ -1853,7 +1015,6 @@ void ConfigSetup::Init(const char *fileName, MultiSim *& multisim) verifyInputs(); printf("%-40s %-s\n\n", "Finished Reading Input File:", fileName); } -#endif void ConfigSetup::fillDefaults(void) { diff --git a/src/ConfigSetup.h b/src/ConfigSetup.h index b1ba6ca6d..c7a8432e7 100644 --- a/src/ConfigSetup.h +++ b/src/ConfigSetup.h @@ -27,10 +27,8 @@ along with this program, also can be found at . #endif #include "GOMC_Config.h" //For PT -#if GOMC_LIB_MPI #include "ParallelTemperingPreprocessor.h" #include //for prefixing uniqueVal with the pathToReplicaDirectory -#endif #ifdef WIN32 #define OS_SEP '\\' #else @@ -389,10 +387,7 @@ class ConfigSetup config_setup::Output out; config_setup::SystemVals sys; ConfigSetup(void); - void Init(const char *fileName); - #if GOMC_LIB_MPI - void Init(const char *fileName, MultiSim *& multisim); - #endif + void Init(const char *fileName, MultiSim const*const& multisim); private: void fillDefaults(void); bool checkBool(string str); diff --git a/src/Main.cpp b/src/Main.cpp index 8bbeac23b..807a48870 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -28,8 +28,6 @@ along with this program, also can be found at . #define HOSTNAME #endif - - namespace { std::ostream& PrintTime(std::ostream& stream); @@ -50,78 +48,8 @@ void PrintGPUHardwareInfo(); int main(int argc, char *argv[]) { #if GOMC_LIB_MPI - string inputFileStringMPI; - fstream inputFileReaderMPI; - MultiSim * multisim; - int worldSize; - int worldRank; - ParallelTemperingPreprocessor pt; - - //std::streambuf * savedCOUT; - //CHECK IF ARGS/FILE PROVIDED IN CMD LINE - if (argc < 2) { - std::cout << "Error: Input parameter file (*.dat or *.conf) not specified on command line!\n"; - exit(EXIT_FAILURE); - } else { - if(argc == 2) { - //FIRST PARAMETER WILL BE FILE NAME - inputFileStringMPI = argv[1]; - } else { - //SECOND PARAMETER WILL BE FILE NAME - inputFileStringMPI = argv[2]; - - if(argv[1][0] == '+' && argv[1][1] == 'p') { - // placeholder - } else { - std::cout << "Error: Undefined command to set number of threads!\n"; - std::cout << "Use +p# command to set number of threads.\n"; - exit(EXIT_FAILURE); - } - } - - //OPEN FILE - inputFileReaderMPI.open(inputFileStringMPI.c_str(), ios::in | ios::out); - - //CHECK IF FILE IS OPENED...IF NOT OPENED EXCEPTION REASON FIRED - if (!inputFileReaderMPI.is_open()) { - std::cout << "Error: Cannot open/find " << inputFileStringMPI << - " in the directory provided!\n"; - exit(EXIT_FAILURE); - } - - //CLOSE FILE TO NOW PASS TO SIMULATION - inputFileReaderMPI.close(); - - // Initialize the MPI environment - MPI_Init(NULL, NULL); - - // Get the number of processes - MPI_Comm_size(MPI_COMM_WORLD, &worldSize); - - // Get the rank of the process - MPI_Comm_rank(MPI_COMM_WORLD, &worldRank); - - std::string pathToReplicaDirectory; - if(pt.checkIfParallelTempering(inputFileStringMPI)){ - pt.checkIfValid(inputFileStringMPI); - if(worldSize > pt.getNumberOfReplicas(inputFileStringMPI)){ - std::cout << "You may not request more processes (" << worldSize - << ") than there are replicas(" << pt.getNumberOfReplicas(inputFileStringMPI) << ")! Exiting!\n"; - } else { - #if ENSEMBLE == GCMC - pathToReplicaDirectory = pt.setupReplicaDirectoriesAndRedirectSTDOUTToFile ( pt.getMultiSimFolderName(inputFileStringMPI).c_str(), - pt.getTemperature(inputFileStringMPI.c_str(), worldRank).c_str(), - pt.getChemicalPotential(inputFileStringMPI.c_str(), worldRank).c_str() - ); - #else - pathToReplicaDirectory = pt.setupReplicaDirectoriesAndRedirectSTDOUTToFile ( pt.getMultiSimFolderName(inputFileStringMPI).c_str(), - pt.getTemperature(inputFileStringMPI.c_str(), worldRank).c_str() - ); - #endif - multisim = new MultiSim(worldSize, worldRank, pathToReplicaDirectory); - } - } - } + ParallelTemperingPreprocessor pt(argc, argv); + MultiSim * multisim = pt.checkIfValidRank() ? new MultiSim(pt) : NULL; #endif #ifndef NDEBUG PrintDebugMode(); @@ -186,7 +114,7 @@ int main(int argc, char *argv[]) //ONCE FILE FOUND PASS STRING TO SIMULATION CLASS TO READ AND //HANDLE PDB|PSF FILE #if GOMC_LIB_MPI - if(worldSize <= pt.getNumberOfReplicas(inputFileStringMPI)){ + if(multisim != NULL){ Simulation sim(inputFileString.c_str(), multisim); sim.RunSimulation(); PrintSimulationFooter(); @@ -306,6 +234,7 @@ uint ReadNum(char *argv) return thread; } + } void PrintHardwareInfo() diff --git a/src/ParallelTemperingPreprocessor.cpp b/src/ParallelTemperingPreprocessor.cpp index b8fc9d908..e6a84cce5 100644 --- a/src/ParallelTemperingPreprocessor.cpp +++ b/src/ParallelTemperingPreprocessor.cpp @@ -6,12 +6,88 @@ along with this program, also can be found at . ********************************************************************************/ #include "ParallelTemperingPreprocessor.h" -ParallelTemperingPreprocessor::ParallelTemperingPreprocessor(){} +ParallelTemperingPreprocessor::ParallelTemperingPreprocessor( int argc, + char *argv[]){ + // Initialize the MPI environment + MPI_Init(NULL, NULL); -bool ParallelTemperingPreprocessor::checkIfParallelTempering(std::string inputFileString){ + // Get the number of processes + MPI_Comm_size(MPI_COMM_WORLD, &worldSize); + + // Get the rank of the process + MPI_Comm_rank(MPI_COMM_WORLD, &worldRank); + + //CHECK IF ARGS/FILE PROVIDED IN CMD LINE + if (argc < 2) { + std::cout << "Error: Input parameter file (*.dat or *.conf) not specified on command line!\n"; + MPI_Finalize(); + exit(EXIT_FAILURE); + } else { + if(argc == 2) { + //FIRST PARAMETER WILL BE FILE NAME + inputFileStringMPI = argv[1]; + } else { + //SECOND PARAMETER WILL BE FILE NAME + inputFileStringMPI = argv[2]; + + if(argv[1][0] == '+' && argv[1][1] == 'p') { + // placeholder + } else { + std::cout << "Error: Undefined command to set number of threads!\n"; + std::cout << "Use +p# command to set number of threads.\n"; + MPI_Finalize(); + exit(EXIT_FAILURE); + } + } + //OPEN FILE + inputFileReaderMPI.open(inputFileStringMPI.c_str(), ios::in | ios::out); + + //CHECK IF FILE IS OPENED...IF NOT OPENED EXCEPTION REASON FIRED + if (!inputFileReaderMPI.is_open()) { + std::cout << "Error: Cannot open/find " << inputFileStringMPI << + " in the directory provided!\n"; + MPI_Finalize(); + exit(EXIT_FAILURE); + } + + //CLOSE FILE TO NOW PASS TO SIMULATION + inputFileReaderMPI.close(); + + if(checkIfParallelTempering(inputFileStringMPI.c_str())){ + checkIfValid(inputFileStringMPI.c_str()); + if(worldRank >= getNumberOfReplicas(inputFileStringMPI.c_str())){ + std::cout << "You may not request more processes (" << worldSize + << ") than there are replicas(" << getNumberOfReplicas(inputFileStringMPI.c_str()) + << ")! Exiting this process[" << worldRank << "]!\n"; + MPI_Finalize(); + exit(EXIT_FAILURE); + } else { + #if ENSEMBLE == GCMC + pathToReplicaDirectory = setupReplicaDirectoriesAndRedirectSTDOUTToFile ( getMultiSimFolderName(inputFileStringMPI.c_str()), + getTemperature(inputFileStringMPI.c_str(), worldRank), + getChemicalPotential(inputFileStringMPI.c_str(), worldRank)); + #else + pathToReplicaDirectory = setupReplicaDirectoriesAndRedirectSTDOUTToFile ( getMultiSimFolderName(inputFileStringMPI.c_str()), + getTemperature(inputFileStringMPI.c_str(), worldRank)); + #endif + } + } + } +} + +bool ParallelTemperingPreprocessor::checkIfValidRank(){ + if (worldRank >= getNumberOfReplicas(inputFileStringMPI.c_str())){ + return false; + } else { + return true; + } +} + + +bool ParallelTemperingPreprocessor::checkIfParallelTempering(const char *fileName){ InputFileReader reader; std::vector line; - reader.Open(inputFileString); + reader.Open(fileName); bool isParallelTemperingInTemperature = false; bool isParallelTemperingInChemicalPotential = false; bool isParallelTemperingInFreeEnergyCoulomb = false; @@ -40,10 +116,10 @@ bool ParallelTemperingPreprocessor::checkIfParallelTempering(std::string inputFi isParallelTemperingInFreeEnergyCoulomb || isParallelTemperingInFreeEnergyVDW; } -void ParallelTemperingPreprocessor::checkIfValid(std::string inputFileString){ +void ParallelTemperingPreprocessor::checkIfValid(const char *fileName){ InputFileReader reader; std::vector line; - reader.Open(inputFileString); + reader.Open(fileName); int numberOfTemperatures = 0; vector < int > numberOfChemPots; int numberOfLambdaCoulombs = 0; @@ -86,10 +162,10 @@ void ParallelTemperingPreprocessor::checkIfValid(std::string inputFileString){ } } -int ParallelTemperingPreprocessor::getNumberOfReplicas(std::string inputFileString){ +int ParallelTemperingPreprocessor::getNumberOfReplicas(const char *fileName){ InputFileReader reader; std::vector line; - reader.Open(inputFileString); + reader.Open(fileName); int numberOfTemperatures = 0; vector < int > numberOfChemPots; int numberOfLambdaCoulombs = 0; @@ -123,10 +199,10 @@ int ParallelTemperingPreprocessor::getNumberOfReplicas(std::string inputFileStri return numberOfReplicas; } -std::string ParallelTemperingPreprocessor::getMultiSimFolderName(std::string inputFileString){ +std::string ParallelTemperingPreprocessor::getMultiSimFolderName(const char *fileName){ InputFileReader reader; std::vector line; - reader.Open(inputFileString); + reader.Open(fileName); string folderName; while(reader.readNextLine(line)) { @@ -154,10 +230,10 @@ std::string ParallelTemperingPreprocessor::getMultiSimFolderName(std::string inp return folderName; } -std::string ParallelTemperingPreprocessor::getTemperature(std::string inputFileString, int world_rank){ +std::string ParallelTemperingPreprocessor::getTemperature(const char *fileName, int worldRank){ InputFileReader reader; std::vector line; - reader.Open(inputFileString); + reader.Open(fileName); string temperature; @@ -166,7 +242,7 @@ std::string ParallelTemperingPreprocessor::getTemperature(std::string inputFileS continue; } else if(line[0] == "Temperature"){ if (line.size() > 2){ - temperature = line[world_rank+1]; + temperature = line[worldRank+1]; } else { temperature = line[1]; } @@ -179,10 +255,10 @@ std::string ParallelTemperingPreprocessor::getTemperature(std::string inputFileS -std::string ParallelTemperingPreprocessor::getChemicalPotential(std::string inputFileString, int world_rank){ +std::string ParallelTemperingPreprocessor::getChemicalPotential(const char *fileName, int worldRank){ InputFileReader reader; std::vector line; - reader.Open(inputFileString); + reader.Open(fileName); std::stringstream chemPotStream; std::string resName; std::string val; @@ -193,7 +269,7 @@ std::string ParallelTemperingPreprocessor::getChemicalPotential(std::string inpu } else if(CheckString(line[0], "ChemPot")) { if (line.size() > 3){ resName = line[1]; - val = line[2 + world_rank]; + val = line[2 + worldRank]; chemPotStream << "_" << resName << "_" << val; } else if(line.size() != 3) { std::cout << "Error: Chemical potential parameters are not specified!\n"; @@ -232,17 +308,18 @@ std::string ParallelTemperingPreprocessor::mkdirWrapper(std::string multisimDire << replicaDirectoryName << OS_SEP; std::string replicaDirectoryPath = replicaStream.str(); - printf("Creating directory : %s\n", multisimDirectoryName.c_str()); + //printf("Creating directory : %s\n", multisimDirectoryName.c_str()); mkdir(multisimDirectoryName.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); mkdir(replicaDirectoryPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); std::string pathToReplicaDirectory = replicaStream.str(); replicaStream << "ConsoleOut.dat"; - std::string pathToReplicaLogFile = replicaStream.str(); - //std::ofstream out(pathToReplicaLogFile); - //std::streambuf * coutbuf; - //auto coutbuf = std::cout.rdbuf(out.rdbuf()); //save and redirect - freopen(pathToReplicaLogFile.c_str(),"w",stdout); + std::string pathToReplicaLogFile = replicaStream.str(); + if(worldRank == 0){ + std::cout << "Monitor progress of your simulation by navigating to a replica output directory and issuing:\n" + << "\t$ tail -f \"YourUniqueFileName\".console" << std::endl; + } + freopen(pathToReplicaLogFile.c_str(),"w",stdout); return pathToReplicaDirectory; } @@ -260,6 +337,6 @@ bool ParallelTemperingPreprocessor::CheckString(string str1, string str2) return (str1 == str2); } -MultiSim::MultiSim(int worldSize, int worldRank, std::string pathToReplicaDirectory) : - worldSize(worldSize), worldRank(worldRank), pathToReplicaDirectory(pathToReplicaDirectory) +MultiSim::MultiSim(ParallelTemperingPreprocessor & pt) : + worldSize(pt.worldSize), worldRank(pt.worldRank), pathToReplicaDirectory(pt.pathToReplicaDirectory) {} \ No newline at end of file diff --git a/src/ParallelTemperingPreprocessor.h b/src/ParallelTemperingPreprocessor.h index f53a03621..378afe5a4 100644 --- a/src/ParallelTemperingPreprocessor.h +++ b/src/ParallelTemperingPreprocessor.h @@ -25,27 +25,33 @@ along with this program, also can be found at . class ParallelTemperingPreprocessor { public: -explicit ParallelTemperingPreprocessor(); -bool checkIfParallelTempering(std::string inputFileString); -void checkIfValid(std::string inputFileString); -int getNumberOfReplicas(std::string inputFileString); -std::string getMultiSimFolderName(std::string inputFileString); -std::string getTemperature(std::string inputFileString, int world_rank); -std::string getChemicalPotential(std::string inputFileString, int world_rank); + +explicit ParallelTemperingPreprocessor( int argc, + char *argv[]); +bool checkIfValidRank(); +bool checkIfParallelTempering(const char *fileName); +void checkIfValid(const char *fileName); +int getNumberOfReplicas(const char *fileName); +std::string getMultiSimFolderName(const char *fileName); +std::string getTemperature(const char *fileName, int worldRank); +std::string getChemicalPotential(const char *fileName, int worldRank); std::string setupReplicaDirectoriesAndRedirectSTDOUTToFile(std::string multiSimTitle, std::string temperature); std::string setupReplicaDirectoriesAndRedirectSTDOUTToFile(std::string multiSimTitle, std::string temperature, std::string chemPot); -std::string mkdirWrapper(std::string multisimDirectoryName, string replicaDirectoryName); +std::string mkdirWrapper(std::string multisimDirectoryName, std::string replicaDirectoryName); bool CheckString(string str1, string str2); private: + friend class MultiSim; + std::string inputFileStringMPI; + fstream inputFileReaderMPI; + std::string pathToReplicaDirectory; + int worldSize, worldRank; }; class MultiSim { public: -explicit MultiSim(int worldSize, int worldRank, std::string pathToReplicaDirectory); -int worldSize, worldRank; -std::string pathToReplicaDirectory; - - +explicit MultiSim(ParallelTemperingPreprocessor & pt); +const int worldSize, worldRank; +const std::string pathToReplicaDirectory; private: }; #endif /*ParallelTemperingPreprocessor_H*/ \ No newline at end of file diff --git a/src/Setup.h b/src/Setup.h index 8dfdfda52..0c956f771 100644 --- a/src/Setup.h +++ b/src/Setup.h @@ -16,9 +16,7 @@ along with this program, also can be found at . #include "PRNGSetup.h" #include "MolSetup.h" #include "GOMC_Config.h" //For PT -#if GOMC_LIB_MPI #include "ParallelTemperingPreprocessor.h" -#endif class Setup { public: @@ -29,27 +27,7 @@ class Setup PRNGSetup prng; //4 MolSetup mol; //5 - void Init(char const*const configFileName) - { - //Read in all config data - config.Init(configFileName); - //Read in FF data. - ff.Init(config.in.files.param.name, config.in.ffKind.isCHARMM); - //Read PDB data - pdb.Init(config.in.restart, config.in.files.pdb.name); - //Initialize PRNG - prng.Init(config.in.restart, config.in.prng, config.in.files.seed.name); - - //Read molecule data from psf - if(mol.Init(config.in.restart, config.in.files.psf.name) != 0) { - exit(EXIT_FAILURE); - } - mol.AssignKinds(pdb.atoms, ff); - - } - - #if GOMC_LIB_MPI - void Init(char const*const configFileName, MultiSim *& multisim) + void Init(char const*const configFileName, MultiSim const*const& multisim) { //Read in all config data config.Init(configFileName, multisim); @@ -67,7 +45,6 @@ class Setup mol.AssignKinds(pdb.atoms, ff); } - #endif }; #endif diff --git a/src/Simulation.cpp b/src/Simulation.cpp index 1ea8c6b47..92d72e929 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -12,39 +12,7 @@ along with this program, also can be found at . #include #include -Simulation::Simulation(char const*const configFileName) -{ - startStep = 0; - //NOTE: - //IMPORTANT! Keep this order... - //as system depends on staticValues, and cpu sometimes depends on both. - set.Init(configFileName); - totalSteps = set.config.sys.step.total; - staticValues = new StaticVals(set); - system = new System(*staticValues); - staticValues->Init(set, *system); - system->Init(set, startStep); - //recal Init for static value for initializing ewald since ewald is - //initialized in system - staticValues->InitOver(set, *system); - cpu = new CPUSide(*system, *staticValues); - cpu->Init(set.pdb, set.config.out, set.config.sys.step.equil, - totalSteps, startStep); - - //Dump combined PSF - PSFOutput psfOut(staticValues->mol, *system, set.mol.kindMap, - set.pdb.atoms.resKindNames); - psfOut.PrintPSF(set.config.out.state.files.psf.name); - std::cout << "Printed combined psf to file " - << set.config.out.state.files.psf.name << '\n'; - - if(totalSteps == 0) { - frameSteps = set.pdb.GetFrameSteps(set.config.in.files.pdb.name); - } -} - -#if GOMC_LIB_MPI -Simulation::Simulation(char const*const configFileName, MultiSim *& multisim) +Simulation::Simulation(char const*const configFileName, MultiSim const*const& multisim) { startStep = 0; //NOTE: @@ -74,7 +42,6 @@ Simulation::Simulation(char const*const configFileName, MultiSim *& multisim) frameSteps = set.pdb.GetFrameSteps(set.config.in.files.pdb.name); } } -#endif Simulation::~Simulation() { diff --git a/src/Simulation.h b/src/Simulation.h index 46d18d5d4..b8a5874fd 100644 --- a/src/Simulation.h +++ b/src/Simulation.h @@ -13,16 +13,12 @@ along with this program, also can be found at . #include "StaticVals.h" #include "BasicTypes.h" #include "GOMC_Config.h" //For PT -#if GOMC_LIB_MPI #include "ParallelTemperingPreprocessor.h" -#endif + class Simulation { public: - explicit Simulation(char const*const configFileName); - #if GOMC_LIB_MPI - explicit Simulation(char const*const configFileName, MultiSim *& multisim); - #endif + explicit Simulation(char const*const configFileName, MultiSim const*const& multisim = NULL); ~Simulation(); void RunSimulation(void);