Pārlūkot izejas kodu

mpi: starpu_mpi_data_register() which sets the rank and tag of a data, and also allows to automatically clear the MPI communication cache when unregistering the data

Nathalie Furmento 11 gadi atpakaļ
vecāks
revīzija
052b036292

+ 9 - 8
doc/doxygen/chapters/16mpi_support.doxy

@@ -234,10 +234,13 @@ The list of functions is described in \ref MPIInsertTask "MPI Insert Task".
 
 Here an stencil example showing how to use starpu_mpi_task_insert(). One
 first needs to define a distribution function which specifies the
-locality of the data. Note that that distribution information needs to
-be given to StarPU by calling starpu_data_set_rank(). A MPI tag
-should also be defined for each data handle by calling
-starpu_data_set_tag().
+locality of the data. Note that the data needs to be registered to MPI
+by calling starpu_mpi_data_register(). This function allows to set
+the distribution information and the MPI tag which should be used when
+communicating the data. The function starpu_mpi_data_register() should
+be prefered to starpu_data_set_rank() and starpu_data_set_tag() as
+it also allows to automatically clear the MPI communication cache
+when unregistering the data.
 
 \code{.c}
 /* Returns the MPI node number where data is */
@@ -284,8 +287,7 @@ data which will be needed by the tasks that we will execute.
                 /* I know it's useless to allocate anything for this */
                 data_handles[x][y] = NULL;
             if (data_handles[x][y]) {
-                starpu_data_set_rank(data_handles[x][y], mpi_rank);
-                starpu_data_set_tag(data_handles[x][y], x*X+y);
+                starpu_mpi_data_register(data_handles[x][y], x*X+y, mpi_rank);
             }
         }
     }
@@ -458,8 +460,7 @@ for(x = 0; x < nblocks ;  x++)
         data_handles[x] = NULL;
     }
     if (data_handles[x]) {
-        starpu_data_set_rank(data_handles[x], mpi_rank);
-        starpu_data_set_tag(data_handles[x], x*nblocks+y);
+        starpu_mpi_data_register(data_handles[x], x*nblocks+y, mpi_rank);
     }
 }
 

+ 6 - 0
doc/doxygen/chapters/api/mpi.doxy

@@ -200,6 +200,12 @@ Tell StarPU-MPI which MPI tag to use when exchanging the data.
 \ingroup API_MPI_Support
 Returns the MPI tag to be used when exchanging the data.
 
+\fn int starpu_mpi_data_register(starpu_data_handle_t handle, int tag, int rank)
+\ingroup API_MPI_Support
+Calling this function should be prefered to calling both
+starpu_data_set_rank() and starpu_data_set_tag() as it also allows to
+automatically clear the MPI communication cache when unregistering the data.
+
 \fn int starpu_data_set_rank(starpu_data_handle_t handle, int rank)
 \ingroup API_MPI_Support
 Tell StarPU-MPI which MPI node "owns" a given data, that is, the node

+ 3 - 1
mpi/include/starpu_mpi.h

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2009-2012  Université de Bordeaux 1
- * Copyright (C) 2010, 2011, 2012, 2013  Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011, 2012, 2013, 2014  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -74,6 +74,8 @@ void starpu_mpi_cache_flush_all_data(MPI_Comm comm);
 int starpu_mpi_get_communication_tag(void);
 void starpu_mpi_set_communication_tag(int tag);
 
+void starpu_mpi_data_register(starpu_data_handle_t data_handle,int tag, int rank);
+
 #ifdef __cplusplus
 }
 #endif

+ 14 - 0
mpi/src/starpu_mpi.c

@@ -25,6 +25,7 @@
 #include <common/config.h>
 #include <common/thread.h>
 #include <datawizard/interfaces/data_interface.h>
+#include <datawizard/coherency.h>
 
 static void _starpu_mpi_add_sync_point_in_fxt(void);
 static void _starpu_mpi_submit_new_mpi_request(void *arg);
@@ -1622,3 +1623,16 @@ int starpu_mpi_shutdown(void)
 
 	return 0;
 }
+
+void _starpu_mpi_clear_cache(starpu_data_handle_t data_handle)
+{
+	starpu_mpi_cache_flush(MPI_COMM_WORLD, data_handle);
+}
+
+void starpu_mpi_data_register(starpu_data_handle_t data_handle, int tag, int rank)
+{
+	_starpu_data_set_rank(data_handle, rank);
+	_starpu_data_set_tag(data_handle, tag);
+	_starpu_data_set_unregister_hook(data_handle, _starpu_mpi_clear_cache);
+
+}