Split MPI initialization from t_commrec construction
authorMark Abraham <mark.j.abraham@gmail.com>
Fri, 27 Sep 2013 17:07:06 +0000 (19:07 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 1 Oct 2013 17:16:27 +0000 (19:16 +0200)
Change-Id: I24d5488f0f21eb0528d32f08e1d4a22bf45e95ec

cmake/legacy_and_external.supp
src/gromacs/gmxlib/main.cpp
src/gromacs/gmxlib/network.c
src/gromacs/legacyheaders/network.h
src/gromacs/utility/init.cpp

index 4a40100eef0c6d3f21a464c9ad8b995b2725ce83..6ef044bf493244d1adde80d8f7f813da0485a0b5 100644 (file)
@@ -23,7 +23,7 @@
    fun:malloc
    fun:ompi_proc_all
    ...
-   fun:gmx_finalize_par
+   fun:gmx_finalize_mpi
 }
 {
    MPI_Init/Addr4
index 4ff83bf311b06f46f57507278e27d13d6aaac554..616ce581f5858dd9168c7e001d6987307fd9e1eb 100644 (file)
@@ -541,13 +541,11 @@ t_commrec *init_par_threads(const t_commrec *cro)
     {
         gmx_comm("Initializing threads without comm");
     }
-    /* once threads will be used together with MPI, we'll
-       fill the cr structure with distinct data here. This might even work: */
-    cr->sim_nodeid = gmx_setup(0, NULL, &cr->nnodes);
 
-    cr->mpi_comm_mysim   = MPI_COMM_WORLD;
-    cr->mpi_comm_mygroup = cr->mpi_comm_mysim;
-    cr->nodeid           = cr->sim_nodeid;
+    gmx_do_mpi_init(0, NULL);
+    gmx_fill_commrec_from_mpi(cr);
+
+    // TODO cr->duty should not be initialized here
     cr->duty             = (DUTY_PP | DUTY_PME);
 
     return cr;
index 2ccfdb3df274733668c8f194be69c573912ea572..70a16c388590737f0759f5b3baf179b3646c9412 100644 (file)
@@ -64,11 +64,28 @@ gmx_bool gmx_mpi_initialized(void)
 #endif
 }
 
-int gmx_setup(int gmx_unused *argc, char gmx_unused ***argv, int *nnodes)
+void gmx_do_mpi_init(int gmx_unused *argc, char gmx_unused ***argv)
 {
 #ifndef GMX_MPI
-    gmx_call("gmx_setup");
-    return 0;
+    gmx_call("gmx_do_mpi_init");
+#else
+    if (!gmx_mpi_initialized())
+    {
+#ifdef GMX_LIB_MPI
+#ifdef GMX_FAHCORE
+        (void) fah_MPI_Init(argc, argv);
+#else
+        (void) MPI_Init(argc, argv);
+#endif
+#endif
+    }
+#endif
+}
+
+void gmx_fill_commrec_from_mpi(t_commrec *cr)
+{
+#ifndef GMX_MPI
+    gmx_call("gmx_fill_commrec_from_mpi");
 #else
     char   buf[256];
     int    resultlen;             /* actual length of node name      */
@@ -77,16 +94,8 @@ int gmx_setup(int gmx_unused *argc, char gmx_unused ***argv, int *nnodes)
     int    mpi_my_rank;
     char   mpi_hostname[MPI_MAX_PROCESSOR_NAME];
 
-    /* Call the MPI routines */
-#ifdef GMX_LIB_MPI
-#ifdef GMX_FAHCORE
-    (void) fah_MPI_Init(argc, argv);
-#else
-    (void) MPI_Init(argc, argv);
-#endif
-#endif
-    (void) MPI_Comm_size( MPI_COMM_WORLD, &mpi_num_nodes );
-    (void) MPI_Comm_rank( MPI_COMM_WORLD, &mpi_my_rank );
+    mpi_num_nodes = gmx_node_num();
+    mpi_my_rank   = gmx_node_rank();
     (void) MPI_Get_processor_name( mpi_hostname, &resultlen );
 
 #ifdef GMX_LIB_MPI
@@ -97,9 +106,11 @@ int gmx_setup(int gmx_unused *argc, char gmx_unused ***argv, int *nnodes)
     }
 #endif
 
-    *nnodes = mpi_num_nodes;
-
-    return mpi_my_rank;
+    cr->nnodes           = mpi_num_nodes;
+    cr->nodeid           = mpi_my_rank;
+    cr->sim_nodeid       = mpi_my_rank;
+    cr->mpi_comm_mysim   = MPI_COMM_WORLD;
+    cr->mpi_comm_mygroup = MPI_COMM_WORLD;
 #endif
 }
 
@@ -769,17 +780,16 @@ void gmx_sumli_sim(int nr, gmx_large_int_t r[], const gmx_multisim_t *ms)
 }
 
 
-void gmx_finalize_par(void)
+void gmx_finalize_mpi(void)
 {
 #ifndef GMX_MPI
     /* Compiled without MPI, no MPI finalizing needed */
     return;
 #else
-    int initialized, finalized;
+    int finalized;
     int ret;
 
-    MPI_Initialized(&initialized);
-    if (!initialized)
+    if (!gmx_mpi_initialized())
     {
         return;
     }
index 727f6f0998480b3dbb7c1a1f3ff821c71bae18d1..0d2d2735d1d9bdabdd48b612e0de05e03377b6f3 100644 (file)
 extern "C" {
 #endif
 
-int gmx_setup(int *argc, char ***argv, int *nnodes);
-/* Initializes the parallel communication, return the ID of the node */
+void gmx_do_mpi_init(int *argc, char ***argv);
+/* Initializes the MPI parallel communication */
+
+void gmx_fill_commrec_from_mpi(t_commrec *cr);
+/* Continues t_commrec construction */
 
 int gmx_node_num(void);
 /* return the number of nodes in the ring */
@@ -121,7 +124,7 @@ void gmx_sumd_sim(int nr, double r[], const gmx_multisim_t *ms);
 void gmx_abort(int nodeid, int nnodes, int errorno);
 /* Abort the parallel run */
 
-void gmx_finalize_par(void);
+void gmx_finalize_mpi(void);
 /* Finish the parallel run in an ordered manner */
 
 #ifdef GMX_DOUBLE
index 2c34d946a203f2e1ce1d85930a513bc418f3df5d..e5fe7494b622f88b9805194f017bed860e848ee9 100644 (file)
@@ -100,8 +100,8 @@ ProgramInfo &init(const char *realBinaryName, int *argc, char ***argv)
     // in CommandLineModuleManager.
     t_commrec cr;
     std::memset(&cr, 0, sizeof(cr));
-    cr.nodeid = gmx_setup(argc, argv, &cr.nnodes);
-    cr.mpi_comm_mygroup = MPI_COMM_WORLD;
+    gmx_do_mpi_init(argc, argv);
+    gmx_fill_commrec_from_mpi(&cr);
     if (PAR(&cr))
     {
         broadcastArguments(&cr, argc, argv);
@@ -117,7 +117,7 @@ ProgramInfo &init(int *argc, char ***argv)
 
 void finalize()
 {
-    gmx_finalize_par();
+    gmx_finalize_mpi();
 }
 
 } // namespace gmx