Merge branch release-5-1
[alexxy/gromacs.git] / src / programs / mdrun / tests / moduletest.cpp
index 5e1726a7ee0668e39cad941a24c97ecb3dec2487..56dfa17725a922c24a5e71dd294755fd45718a60 100644 (file)
 
 #include "config.h"
 
+#include <cstdio>
+
 #include "gromacs/gmxpreprocess/grompp.h"
+#include "gromacs/hardware/detecthardware.h"
 #include "gromacs/options/basicoptions.h"
 #include "gromacs/options/ioptionscontainer.h"
 #include "gromacs/utility/basedefinitions.h"
@@ -230,13 +233,37 @@ SimulationRunner::callMdrun(const CommandLine &callerRef)
 #endif
 
 #ifdef GMX_THREAD_MPI
-    caller.addOption("-nt", g_numThreads);
+    caller.addOption("-ntmpi", g_numThreads);
 #endif
 
 #ifdef GMX_OPENMP
     caller.addOption("-ntomp", g_numOpenMPThreads);
 #endif
 
+#if defined GMX_GPU
+    /* TODO Ideally, with real MPI, we could call
+     * gmx_collect_hardware_mpi() here and find out how many nodes
+     * mdrun will run on. For now, we assume that we're running on one
+     * node regardless of the number of ranks, because that's true in
+     * Jenkins and for most developers running the tests. */
+    int numberOfNodes = 1;
+#if defined GMX_THREAD_MPI
+    /* Can't use gmx_node_num() because it is only valid after spawn of thread-MPI threads */
+    int numberOfRanks = g_numThreads;
+#elif defined GMX_LIB_MPI
+    int numberOfRanks = gmx_node_num();
+#else
+    int numberOfRanks = 1;
+#endif
+    if (numberOfRanks > numberOfNodes && !gmx_multiple_gpu_per_node_supported())
+    {
+        if (gmx_node_rank() == 0)
+        {
+            fprintf(stderr, "GROMACS in this build configuration cannot run on more than one GPU per node,\n so with %d ranks and %d nodes, this test will disable GPU support", numberOfRanks, numberOfNodes);
+        }
+        caller.addOption("-nb", "cpu");
+    }
+#endif
     return gmx_mdrun(caller.argc(), caller.argv());
 }