Sfoglia il codice sorgente

Provide helper functions which tell the MPI lib to release a tag when an
asynchronous communication is terminated.

Cédric Augonnet 15 anni fa
parent
commit
dde612872a
5 ha cambiato i file con 142 aggiunte e 5 eliminazioni
  1. 12 4
      mpi/Makefile.am
  2. 1 1
      mpi/starpu_mpi.c
  3. 6 0
      mpi/starpu_mpi.h
  4. 46 0
      mpi/starpu_mpi_helper.c
  5. 77 0
      mpi/tests/mpi_detached_tag.c

+ 12 - 4
mpi/Makefile.am

@@ -42,6 +42,7 @@ noinst_HEADERS =					\
 
 libstarpumpi_la_SOURCES =				\
 	starpu_mpi.c					\
+	starpu_mpi_helper.c				\
 	starpu_mpi_datatype.c
 
 mpiexamplebindir=$(libdir)/starpu/mpi/
@@ -50,9 +51,10 @@ mpiexamplebin_PROGRAMS =				\
 	tests/pingpong					\
 	tests/mpi_test					\
 	tests/mpi_isend					\
+	tests/mpi_irecv					\
 	tests/mpi_isend_detached			\
 	tests/mpi_irecv_detached			\
-	tests/mpi_irecv					\
+	tests/mpi_detached_tag				\
 	tests/ring					\
 	tests/ring_async				\
 	tests/block_interface				\
@@ -64,6 +66,12 @@ tests_mpi_isend_LDADD =					\
 tests_mpi_isend_SOURCES =				\
 	tests/mpi_isend.c
 
+tests_mpi_irecv_LDADD =					\
+	libstarpumpi.la
+
+tests_mpi_irecv_SOURCES =				\
+	tests/mpi_irecv.c
+
 tests_mpi_isend_detached_LDADD =			\
 	libstarpumpi.la
 
@@ -76,11 +84,11 @@ tests_mpi_irecv_detached_LDADD =			\
 tests_mpi_irecv_detached_SOURCES =			\
 	tests/mpi_irecv_detached.c
 
-tests_mpi_irecv_LDADD =					\
+tests_mpi_detached_tag_LDADD =				\
 	libstarpumpi.la
 
-tests_mpi_irecv_SOURCES =				\
-	tests/mpi_irecv.c
+tests_mpi_detached_tag_SOURCES =			\
+	tests/mpi_detached_tag.c
 
 tests_pingpong_LDADD =					\
 	libstarpumpi.la

+ 1 - 1
mpi/starpu_mpi.c

@@ -19,7 +19,7 @@
 
 /* TODO find a better way to select the polling method (perhaps during the
  * configuration) */
-#define USE_STARPU_ACTIVITY	1
+//#define USE_STARPU_ACTIVITY	1
 
 static void submit_mpi_req(void *arg);
 static void handle_request_termination(struct starpu_mpi_req_s *req);

+ 6 - 0
mpi/starpu_mpi.h

@@ -73,4 +73,10 @@ int starpu_mpi_test(struct starpu_mpi_req_s *req, int *flag, MPI_Status *status)
 int starpu_mpi_initialize(void);
 int starpu_mpi_shutdown(void);
 
+/* Some helper functions */
+
+/* When the transfer is completed, the tag is unlocked */
+int starpu_mpi_isend_detached_unlock_tag(starpu_data_handle data_handle, struct starpu_mpi_req_s *req, int dest, int mpi_tag, MPI_Comm comm, starpu_tag_t tag);
+int starpu_mpi_irecv_detached_unlock_tag(starpu_data_handle data_handle, struct starpu_mpi_req_s *req, int source, int mpi_tag, MPI_Comm comm, starpu_tag_t tag);
+
 #endif // __STARPU_MPI_H__

+ 46 - 0
mpi/starpu_mpi_helper.c

@@ -0,0 +1,46 @@
+/*
+ * StarPU
+ * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#include <starpu_mpi.h>
+
+static void starpu_mpi_unlock_tag_callback(void *arg)
+{
+	starpu_tag_t *tagptr = arg;
+
+	starpu_tag_notify_from_apps(*tagptr);
+
+	free(tagptr);
+}
+
+int starpu_mpi_isend_detached_unlock_tag(starpu_data_handle data_handle, struct starpu_mpi_req_s *req,
+				int dest, int mpi_tag, MPI_Comm comm, starpu_tag_t tag)
+{
+	starpu_tag_t *tagptr = malloc(sizeof(starpu_tag_t));
+	*tagptr = tag;
+	
+	return starpu_mpi_isend_detached(data_handle, req, dest, mpi_tag, comm,
+						starpu_mpi_unlock_tag_callback, tagptr);
+}
+
+
+int starpu_mpi_irecv_detached_unlock_tag(starpu_data_handle data_handle, struct starpu_mpi_req_s *req, int source, int mpi_tag, MPI_Comm comm, starpu_tag_t tag)
+{
+	starpu_tag_t *tagptr = malloc(sizeof(starpu_tag_t));
+	*tagptr = tag;
+	
+	return starpu_mpi_irecv_detached(data_handle, req, source, mpi_tag, comm,
+						starpu_mpi_unlock_tag_callback, tagptr);
+}

+ 77 - 0
mpi/tests/mpi_detached_tag.c

@@ -0,0 +1,77 @@
+/*
+ * StarPU
+ * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#include <starpu_mpi.h>
+
+#define NITER	2048
+#define SIZE	16
+
+float *tab;
+starpu_data_handle tab_handle;
+
+int main(int argc, char **argv)
+{
+	MPI_Init(NULL, NULL);
+
+	int rank, size;
+
+	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+	MPI_Comm_size(MPI_COMM_WORLD, &size);
+
+	if (size != 2)
+	{
+		if (rank == 0)
+			fprintf(stderr, "We need exactly 2 processes.\n");
+
+		MPI_Finalize();
+		return 0;
+	}
+
+	starpu_init(NULL);
+	starpu_mpi_initialize();
+
+	tab = malloc(SIZE*sizeof(float));
+
+	starpu_register_vector_data(&tab_handle, 0, (uintptr_t)tab, SIZE, sizeof(float));
+
+	unsigned nloops = NITER;
+	unsigned loop;
+
+	int other_rank = (rank + 1)%2;
+
+	for (loop = 0; loop < nloops; loop++)
+	{
+		struct starpu_mpi_req_s req;
+		starpu_tag_t tag = (starpu_tag_t)loop;
+
+		if ((loop % 2) == rank)
+		{
+			starpu_mpi_isend_detached_unlock_tag(tab_handle, &req, other_rank, loop, MPI_COMM_WORLD, tag);
+		}
+		else {
+			starpu_mpi_irecv_detached_unlock_tag(tab_handle, &req, other_rank, loop, MPI_COMM_WORLD, tag);
+		}
+
+		starpu_tag_wait(tag);
+	}
+	
+	starpu_mpi_shutdown();
+	starpu_shutdown();
+
+	MPI_Finalize();
+
+	return 0;
+}