Browse Source

mpi: Initialisation functions starpu_mpi_initialize_extended() and starpu_mpi_initialize() have been made deprecated. One should now use starpu_mpi_init() which will initialise MPI if is not already done.

Nathalie Furmento 12 years ago
parent
commit
822f75f6a1
4 changed files with 59 additions and 43 deletions
  1. 5 1
      ChangeLog
  2. 12 11
      doc/chapters/mpi-support.texi
  3. 4 2
      mpi/include/starpu_mpi.h
  4. 38 29
      mpi/src/starpu_mpi.c

+ 5 - 1
ChangeLog

@@ -36,13 +36,17 @@ New features:
   * SOCL
         - Manual mapping of commands on specific devices is now possible
   * New interface: COO matrix.
-  * MPI: 
+  * MPI:
         - Communication statistics for MPI can only be enabled at
 	  execution time by defining the environment variable
 	  STARPU_COMM_STATS
         - Communication cache mechanism is enabled by default, and can
 	  only be disabled at execution time by setting the
 	  environment variable STARPU_MPI_CACHE to 0.
+        - Initialisation functions starpu_mpi_initialize_extended()
+  	  and starpu_mpi_initialize() have been made deprecated. One
+	  should now use starpu_mpi_init() which will initialise MPI
+	  if is not already done.
 
 Changes:
   * Fix the block filter functions.

+ 12 - 11
doc/chapters/mpi-support.texi

@@ -44,25 +44,26 @@ Also pass the @code{--static} option if the application is to be linked statical
 
 @subsection Initialisation
 
+@deftypefun int starpu_mpi_init (int *@var{argc}, char ***@var{argv})
+Initializes the starpumpi library. If MPI is not already initialized,
+it will be by calling @code{MPI_Init(argc, argv)}.
+@end deftypefun
+
 @deftypefun int starpu_mpi_initialize (void)
-Initializes the starpumpi library. This must be called between calling
-@code{starpu_init} and other @code{starpu_mpi} functions. This
-function does not call @code{MPI_Init}, it should be called beforehand.
+This function has been made deprecated. One should use instead the
+function @code{starpu_mpi_init()} defined above.
 @end deftypefun
 
 @deftypefun int starpu_mpi_initialize_extended (int *@var{rank}, int *@var{world_size})
-Initializes the starpumpi library. This must be called between calling
-@code{starpu_init} and other @code{starpu_mpi} functions.
-This function calls @code{MPI_Init}, and therefore should be prefered
-to the previous one for MPI implementations which are not thread-safe.
-Returns the current MPI node rank and world size.
+This function has been made deprecated. One should use instead the
+function @code{starpu_mpi_init()} defined above.
 @end deftypefun
 
 @deftypefun int starpu_mpi_shutdown (void)
 Cleans the starpumpi library. This must be called between calling
-@code{starpu_mpi} functions and @code{starpu_shutdown}.
-@code{MPI_Finalize} will be called if StarPU-MPI has been initialized
-by calling @code{starpu_mpi_initialize_extended}.
+@code{starpu_mpi} functions and @code{starpu_shutdown()}.
+@code{MPI_Finalize()} will be called if StarPU-MPI has been initialized
+by @code{starpu_mpi_init()}.
 @end deftypefun
 
 @deftypefun void starpu_mpi_comm_amounts_retrieve (size_t *@var{comm_amounts})

+ 4 - 2
mpi/include/starpu_mpi.h

@@ -39,8 +39,10 @@ int starpu_mpi_irecv_detached(starpu_data_handle_t data_handle, int source, int
 int starpu_mpi_wait(starpu_mpi_req *req, MPI_Status *status);
 int starpu_mpi_test(starpu_mpi_req *req, int *flag, MPI_Status *status);
 int starpu_mpi_barrier(MPI_Comm comm);
-int starpu_mpi_initialize(void);
-int starpu_mpi_initialize_extended(int *rank, int *world_size);
+int starpu_mpi_init(int *argc, char ***argv);
+
+int starpu_mpi_initialize(void) STARPU_DEPRECATED;
+int starpu_mpi_initialize_extended(int *rank, int *world_size) STARPU_DEPRECATED;
 int starpu_mpi_shutdown(void);
 
 int starpu_mpi_insert_task(MPI_Comm comm, struct starpu_codelet *codelet, ...);

+ 38 - 29
mpi/src/starpu_mpi.c

@@ -657,28 +657,26 @@ static void handle_new_request(struct _starpu_mpi_req *req)
         _STARPU_MPI_LOG_OUT();
 }
 
+struct _starpu_mpi_argc_argv {
+	int *argc;
+	char ***argv;
+};
+
 static void *progress_thread_func(void *arg)
 {
-        int initialize_mpi = *((int *) arg);
-
-        _STARPU_DEBUG("Initialize mpi: %d\n", initialize_mpi);
+	struct _starpu_mpi_argc_argv *argc_argv = (struct _starpu_mpi_argc_argv *) arg;
+	int flag;
 
-        if (initialize_mpi) {
-#ifdef STARPU_DEVEL
-#warning get real argc and argv from the application
-#endif
-                int argc = 0;
-                char **argv = NULL;
-                int thread_support;
-                _STARPU_DEBUG("Calling MPI_Init_thread\n");
-                if (MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &thread_support) != MPI_SUCCESS) {
-                        fprintf(stderr,"MPI_Init_thread failed\n");
+	MPI_Initialized(&flag);
+	_STARPU_DEBUG("MPI_Initialized %d\n", flag);
+	if (flag == 0)
+	{
+                _STARPU_DEBUG("Calling MPI_Init\n");
+		fprintf(stderr, "calling MPI_Init\n");
+                if (MPI_Init(argc_argv->argc, argc_argv->argv) != MPI_SUCCESS) {
+                        fprintf(stderr,"MPI_Init failed\n");
                         exit(1);
                 }
-                if (thread_support == MPI_THREAD_FUNNELED)
-                        fprintf(stderr,"Warning: MPI only has funneled thread support, not serialized, hoping this will work\n");
-                if (thread_support < MPI_THREAD_FUNNELED)
-                        fprintf(stderr,"Warning: MPI does not have thread support!\n");
         }
 
 	/* notify the main thread that the progression thread is ready */
@@ -730,13 +728,14 @@ static void *progress_thread_func(void *arg)
 	STARPU_ASSERT(_starpu_mpi_req_list_empty(new_requests));
         STARPU_ASSERT(posted_requests == 0);
 
-        if (initialize_mpi) {
+        if (flag == 0) {
                 _STARPU_MPI_DEBUG("Calling MPI_Finalize()\n");
                 MPI_Finalize();
         }
 
 	_STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
 
+	free(argc_argv);
 	return NULL;
 }
 
@@ -780,7 +779,7 @@ static void _starpu_mpi_add_sync_point_in_fxt(void)
 }
 
 static
-int _starpu_mpi_initialize(int initialize_mpi, int *rank, int *world_size)
+int _starpu_mpi_initialize(int *argc, char ***argv)
 {
 	_STARPU_PTHREAD_MUTEX_INIT(&mutex, NULL);
 	_STARPU_PTHREAD_COND_INIT(&cond_progression, NULL);
@@ -792,20 +791,16 @@ int _starpu_mpi_initialize(int initialize_mpi, int *rank, int *world_size)
 
         _STARPU_PTHREAD_MUTEX_INIT(&mutex_posted_requests, NULL);
 
-	_STARPU_PTHREAD_CREATE(&progress_thread, NULL,
-			       progress_thread_func, (void *)&initialize_mpi);
+	struct _starpu_mpi_argc_argv *argc_argv = malloc(sizeof(struct _starpu_mpi_argc_argv));
+	argc_argv->argc = argc;
+	argc_argv->argv = argv;
+	_STARPU_PTHREAD_CREATE(&progress_thread, NULL, progress_thread_func, argc_argv);
 
 	_STARPU_PTHREAD_MUTEX_LOCK(&mutex);
 	while (!running)
 		_STARPU_PTHREAD_COND_WAIT(&cond_progression, &mutex);
 	_STARPU_PTHREAD_MUTEX_UNLOCK(&mutex);
 
-        if (rank && world_size) {
-                _STARPU_DEBUG("Calling MPI_Comm_rank\n");
-                MPI_Comm_rank(MPI_COMM_WORLD, rank);
-                MPI_Comm_size(MPI_COMM_WORLD, world_size);
-        }
-
 #ifdef STARPU_USE_FXT
 	int prank;
 	MPI_Comm_rank(MPI_COMM_WORLD, &prank);
@@ -823,14 +818,28 @@ int _starpu_mpi_initialize(int initialize_mpi, int *rank, int *world_size)
 	return 0;
 }
 
+int starpu_mpi_init(int *argc, char ***argv)
+{
+        return _starpu_mpi_initialize(argc, argv);
+}
+
 int starpu_mpi_initialize(void)
 {
-        return _starpu_mpi_initialize(0, NULL, NULL);
+        return _starpu_mpi_initialize(NULL, NULL);
 }
 
 int starpu_mpi_initialize_extended(int *rank, int *world_size)
 {
-        return _starpu_mpi_initialize(1, rank, world_size);
+	int ret;
+
+        ret = _starpu_mpi_initialize(NULL, NULL);
+	if (ret == 0)
+	{
+		_STARPU_DEBUG("Calling MPI_Comm_rank\n");
+		MPI_Comm_rank(MPI_COMM_WORLD, rank);
+		MPI_Comm_size(MPI_COMM_WORLD, world_size);
+	}
+	return ret;
 }
 
 int starpu_mpi_shutdown(void)