Explorar el Código

return -ENODEV when starpu_init is called more than once with MPI Master Slave

Corentin Salingue hace 8 años
padre
commit
8104359b27
Se han modificado 3 ficheros con 36 adiciones y 27 borrados
  1. 11 5
      src/core/workers.c
  2. 5 0
      src/drivers/mp_common/sink_common.c
  3. 20 22
      src/drivers/mpi/driver_mpi_common.c

+ 11 - 5
src/core/workers.c

@@ -891,8 +891,8 @@ static void _starpu_launch_drivers(struct _starpu_machine_config *pconfig)
                     &worker_set_zero->mutex);
         STARPU_PTHREAD_MUTEX_UNLOCK(&worker_set_zero->mutex);
 
-        worker_set_zero.started = 1;
-        worker_set_zero.worker_thread = mpi_worker_set[0].worker_thread;
+        worker_set_zero->started = 1;
+        worker_set_zero->worker_thread = mpi_worker_set[0].worker_thread;
 
     }
 
@@ -1186,9 +1186,15 @@ int starpu_initialize(struct starpu_conf *user_conf, int *argc, char ***argv)
 #	endif
 
 #   ifdef STARPU_USE_MPI_MASTER_SLAVE
-	/* In MPI case we look at the rank to know if we are a sink */
-	if (_starpu_mpi_common_mp_init() && !_starpu_mpi_common_is_src_node())
-		setenv("STARPU_SINK", "STARPU_MPI_MS", 1);
+	if (_starpu_mpi_common_mp_init() == -ENODEV)
+    {
+        initialized = UNINITIALIZED;
+        return -ENODEV;
+    }
+
+    /* In MPI case we look at the rank to know if we are a sink */
+    if (!_starpu_mpi_common_is_src_node())
+        setenv("STARPU_SINK", "STARPU_MPI_MS", 1);
 #   endif
 
 	/* If StarPU was configured to use MP sinks, we have to control the

+ 5 - 0
src/drivers/mp_common/sink_common.c

@@ -19,6 +19,7 @@
 #include <common/config.h>
 #include <common/utils.h>
 #include <drivers/mp_common/mp_common.h>
+#include <drivers/mpi/driver_mpi_common.h>
 #include <datawizard/interfaces/data_interface.h>
 #include <common/barrier.h>
 #include <core/workers.h>
@@ -318,6 +319,10 @@ void _starpu_sink_common_worker(void)
 	/* Deinitialize the node and release it */
 	_starpu_mp_common_node_destroy(node);
 
+#ifdef STARPU_USE_MPI_MASTER_SLAVE
+    _starpu_mpi_common_mp_deinit();
+#endif
+
 	exit(0);
 }
 

+ 20 - 22
src/drivers/mpi/driver_mpi_common.c

@@ -27,8 +27,8 @@
 
 #define DRIVER_MPI_MASTER_NODE_DEFAULT 0
 
-static int mpi_initialized;
-static int extern_initialized;
+static int mpi_initialized = 0;
+static int extern_initialized = 0;
 static int src_node_id;
 
 static void _starpu_mpi_set_src_node_id()
@@ -61,37 +61,37 @@ static void _starpu_mpi_set_src_node_id()
 
 int _starpu_mpi_common_mp_init()
 {
-    //Here we supposed the programmer has already called this function
+    //Here we supposed the programmer called two times starpu_init.
     if (mpi_initialized)
-        return 0;
+        return -ENODEV;
+
+    mpi_initialized = 1;
 
     if (MPI_Initialized(&extern_initialized) != MPI_SUCCESS)
         STARPU_ABORT_MSG("Cannot check if MPI is initialized or not !");
 
     //Here MPI_Init or MPI_Init_thread is already called
-    if (extern_initialized)
-        return 1;
+    if (!extern_initialized)
+    {
 
 #if defined(STARPU_MPI_MASTER_SLAVE_MULTIPLE_THREAD)
-    int required = MPI_THREAD_MULTIPLE;
+        int required = MPI_THREAD_MULTIPLE;
 #else
-    int required = MPI_THREAD_FUNNELED;
+        int required = MPI_THREAD_FUNNELED;
 #endif
 
-    int thread_support;
-	if (MPI_Init_thread(_starpu_get_argc(), _starpu_get_argv(), required, &thread_support) != MPI_SUCCESS)
-        return 0;
+        int thread_support;
+        STARPU_ASSERT(MPI_Init_thread(_starpu_get_argc(), _starpu_get_argv(), required, &thread_support) == MPI_SUCCESS);
 
-    if (thread_support != required)
-    {
-        if (required == MPI_THREAD_MULTIPLE)
-            fprintf(stderr, "MPI doesn't support MPI_THREAD_MULTIPLE option. MPI Master-Slave can have problems if multiple slaves are launched. \n");
-        if (required == MPI_THREAD_FUNNELED)
-            fprintf(stderr, "MPI doesn't support MPI_THREAD_FUNNELED option. Many errors can occur. \n");
+        if (thread_support != required)
+        {
+            if (required == MPI_THREAD_MULTIPLE)
+                fprintf(stderr, "MPI doesn't support MPI_THREAD_MULTIPLE option. MPI Master-Slave can have problems if multiple slaves are launched. \n");
+            if (required == MPI_THREAD_FUNNELED)
+                fprintf(stderr, "MPI doesn't support MPI_THREAD_FUNNELED option. Many errors can occur. \n");
+        }
     }
-
-	mpi_initialized = 1;
-
+    
     /* Find which node is the master */
     _starpu_mpi_set_src_node_id();
 
@@ -102,8 +102,6 @@ void _starpu_mpi_common_mp_deinit()
 {
     if (!extern_initialized)
         MPI_Finalize();    
-
-    mpi_initialized = 0;
 }
 
 int _starpu_mpi_common_is_src_node()