Remove gmx::File (except for File::exists())
[alexxy/gromacs.git] / src / programs / mdrun / tests / moduletest.cpp
index 718e4c647bc30eca1b20d60aa1c4a1d1c2021759..b793af46c56d853cbbeb4e3a69ef496b1ca47ca3 100644 (file)
@@ -50,7 +50,8 @@
 #include "gromacs/options/options.h"
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/basenetwork.h"
-#include "gromacs/utility/file.h"
+#include "gromacs/utility/gmxmpi.h"
+#include "gromacs/utility/textwriter.h"
 #include "programs/mdrun/mdrun_main.h"
 
 #include "testutils/cmdlinetest.h"
@@ -119,6 +120,7 @@ SimulationRunner::SimulationRunner(IntegrationTestFixture *fixture) :
 void
 SimulationRunner::useEmptyMdpFile()
 {
+    // TODO When removing the group scheme, update actual and potential users of useEmptyMdpFile
     useStringAsMdpFile("cutoff-scheme = Group\n");
 }
 
@@ -131,13 +133,13 @@ SimulationRunner::useStringAsMdpFile(const char *mdpString)
 void
 SimulationRunner::useStringAsMdpFile(const std::string &mdpString)
 {
-    gmx::File::writeFileFromString(mdpInputFileName_, mdpString);
+    gmx::TextWriter::writeFileFromString(mdpInputFileName_, mdpString);
 }
 
 void
 SimulationRunner::useStringAsNdxFile(const char *ndxString)
 {
-    gmx::File::writeFileFromString(ndxFileName_, ndxString);
+    gmx::TextWriter::writeFileFromString(ndxFileName_, ndxString);
 }
 
 void
@@ -148,6 +150,12 @@ SimulationRunner::useTopGroAndNdxFromDatabase(const char *name)
     ndxFileName_ = fixture_->fileManager_.getInputFilePath((std::string(name) + ".ndx").c_str());
 }
 
+void
+SimulationRunner::useGroFromDatabase(const char *name)
+{
+    groFileName_ = fixture_->fileManager_.getInputFilePath((std::string(name) + ".gro").c_str());
+}
+
 int
 SimulationRunner::callGromppOnThisRank()
 {
@@ -167,15 +175,23 @@ SimulationRunner::callGromppOnThisRank()
 int
 SimulationRunner::callGrompp()
 {
+    int returnValue = 0;
 #ifdef GMX_LIB_MPI
-    // When compiled with external MPI, only call one instance of the
-    // grompp function
-    if (0 != gmx_node_rank())
+    // When compiled with external MPI, we're trying to run mdrun with
+    // MPI, but we need to make sure that we only do grompp on one
+    // rank
+    if (0 == gmx_node_rank())
+#endif
     {
-        return 0;
+        returnValue = callGromppOnThisRank();
     }
+#ifdef GMX_LIB_MPI
+    // Make sure rank zero has written the .tpr file before other
+    // ranks try to read it. Thread-MPI and serial do this just fine
+    // on their own.
+    MPI_Barrier(MPI_COMM_WORLD);
 #endif
-    return callGromppOnThisRank();
+    return returnValue;
 }
 
 int
@@ -185,6 +201,7 @@ SimulationRunner::callMdrun(const CommandLine &callerRef)
        to this function. Passing a non-const reference might make it
        easier to write code that incorrectly re-uses callerRef after
        the call to this function. */
+
     CommandLine caller(callerRef);
     caller.addOption("-s", tprFileName_);
 
@@ -200,9 +217,22 @@ SimulationRunner::callMdrun(const CommandLine &callerRef)
         caller.addOption("-nsteps", nsteps_);
     }
 
+#ifdef GMX_MPI
+#  ifdef GMX_GPU
+#    ifdef GMX_THREAD_MPI
+    int         numGpusNeeded = g_numThreads;
+#    else   /* Must be real MPI */
+    int         numGpusNeeded = gmx_node_num();
+#    endif
+    std::string gpuIdString(numGpusNeeded, '0');
+    caller.addOption("-gpu_id", gpuIdString.c_str());
+#  endif
+#endif
+
 #ifdef GMX_THREAD_MPI
     caller.addOption("-nt", g_numThreads);
 #endif
+
 #ifdef GMX_OPENMP
     caller.addOption("-ntomp", g_numOpenMPThreads);
 #endif