Browse Source

mpi/tests: new testcase for synchronous and early data

Nathalie Furmento 10 years ago
parent
commit
f3cedf67e0
2 changed files with 241 additions and 0 deletions
  1. 6 0
      mpi/tests/Makefile.am
  2. 235 0
      mpi/tests/mpi_earlyrecv2_sync.c

+ 6 - 0
mpi/tests/Makefile.am

@@ -83,6 +83,7 @@ starpu_mpi_TESTS =				\
 	mpi_isend				\
 	mpi_earlyrecv				\
 	mpi_earlyrecv2				\
+	mpi_earlyrecv2_sync			\
 	mpi_irecv				\
 	mpi_isend_detached			\
 	mpi_irecv_detached			\
@@ -129,6 +130,7 @@ noinst_PROGRAMS =				\
 	mpi_isend				\
 	mpi_earlyrecv				\
 	mpi_earlyrecv2				\
+	mpi_earlyrecv2_sync			\
 	mpi_irecv				\
 	mpi_isend_detached			\
 	mpi_irecv_detached			\
@@ -178,6 +180,8 @@ mpi_earlyrecv_LDADD =					\
 	../src/libstarpumpi-@STARPU_EFFECTIVE_VERSION@.la
 mpi_earlyrecv2_LDADD =					\
 	../src/libstarpumpi-@STARPU_EFFECTIVE_VERSION@.la
+mpi_earlyrecv2_sync_LDADD =					\
+	../src/libstarpumpi-@STARPU_EFFECTIVE_VERSION@.la
 mpi_irecv_LDADD =					\
 	../src/libstarpumpi-@STARPU_EFFECTIVE_VERSION@.la
 mpi_isend_detached_LDADD =			\
@@ -282,6 +286,8 @@ user_defined_datatype_SOURCES += ../../examples/interface/complex_interface.c
 
 mpi_earlyrecv2_SOURCES = mpi_earlyrecv2.c
 mpi_earlyrecv2_SOURCES += ../../examples/interface/complex_interface.c
+mpi_earlyrecv2_sync_SOURCES = mpi_earlyrecv2_sync.c
+mpi_earlyrecv2_sync_SOURCES += ../../examples/interface/complex_interface.c
 
 showcheck:
 	-cat $(TEST_LOGS) /dev/null

+ 235 - 0
mpi/tests/mpi_earlyrecv2_sync.c

@@ -0,0 +1,235 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2009, 2010  Université de Bordeaux
+ * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015  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
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU 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>
+#include "helper.h"
+#include <unistd.h>
+#include <interface/complex_interface.h>
+
+#define NB 4
+
+typedef void (*check_func)(starpu_data_handle_t handle, int i, int rank, int *error);
+
+int exchange(int rank, starpu_data_handle_t *handles, check_func func)
+{
+	int other_rank = rank%2 == 0 ? rank+1 : rank-1;
+	int i;
+	int ret=0;
+	starpu_mpi_req req[NB];
+
+	memset(req, 0, NB*sizeof(starpu_mpi_req));
+
+	if (rank%2)
+	{
+#if 1
+		starpu_mpi_issend(handles[0], &req[0], other_rank, 0, MPI_COMM_WORLD);
+		starpu_mpi_isend(handles[NB-1], &req[NB-1], other_rank, NB-1, MPI_COMM_WORLD);
+		starpu_mpi_issend(handles[NB-2], &req[NB-2], other_rank, NB-2, MPI_COMM_WORLD);
+
+		for(i=1 ; i<NB-2 ; i++)
+#else
+		for(i=0 ; i<NB ; i++)
+#endif
+		{
+			if (i%2)
+				starpu_mpi_issend(handles[i], &req[i], other_rank, i, MPI_COMM_WORLD);
+			else
+				starpu_mpi_isend(handles[i], &req[i], other_rank, i, MPI_COMM_WORLD);
+		}
+		for(i=0 ; i<NB ; i++)
+		{
+			starpu_mpi_wait(&req[i], MPI_STATUS_IGNORE);
+		}
+	}
+	else
+	{
+#if 1
+		starpu_mpi_irecv(handles[0], &req[0], other_rank, 0, MPI_COMM_WORLD);
+		STARPU_ASSERT(req[0] != NULL);
+		starpu_mpi_irecv(handles[1], &req[1], other_rank, 1, MPI_COMM_WORLD);
+		STARPU_ASSERT(req[1] != NULL);
+
+		// We sleep to make sure that the data for the tag 8 and the tag 9 will be received before the recv are posted
+		usleep(2000000);
+		for(i=2 ; i<NB ; i++)
+#else
+		for(i=0 ; i<NB ; i++)
+#endif
+		{
+			starpu_mpi_irecv(handles[i], &req[i], other_rank, i, MPI_COMM_WORLD);
+			STARPU_ASSERT(req[i] != NULL);
+		}
+
+		for(i=0 ; i<NB ; i++)
+		{
+			starpu_mpi_wait(&req[i], MPI_STATUS_IGNORE);
+			if (func)
+				func(handles[i], i, rank, &ret);
+		}
+	}
+	return ret;
+}
+
+void check_variable(starpu_data_handle_t handle, int i, int rank, int *error)
+{
+	int other_rank = rank%2 == 0 ? rank+1 : rank-1;
+
+	int *rvalue = (int *)starpu_data_get_local_ptr(handle);
+	if (*rvalue != i*other_rank)
+	{
+		FPRINTF_MPI(stderr, "Incorrect received value: %d != %d\n", *rvalue, i*other_rank);
+		*error = 1;
+	}
+	else
+	{
+		FPRINTF_MPI(stderr, "Correct received value: %d == %d\n", *rvalue, i*other_rank);
+	}
+}
+
+int exchange_variable(int rank)
+{
+	int ret, i;
+	starpu_data_handle_t tab_handle[NB];
+	int value[NB];
+
+	ret = starpu_init(NULL);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
+	ret = starpu_mpi_init(NULL, NULL, 0);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
+
+	FPRINTF_MPI(stderr, "Exchanging variable data\n");
+
+	for(i=0 ; i<NB ; i++)
+	{
+		value[i]=i*rank;
+		starpu_variable_data_register(&tab_handle[i], STARPU_MAIN_RAM, (uintptr_t)&value[i], sizeof(int));
+		starpu_mpi_data_register(tab_handle[i], i, rank);
+	}
+	ret = exchange(rank, tab_handle, check_variable);
+	for(i=0 ; i<NB ; i++)
+		starpu_data_unregister(tab_handle[i]);
+
+	starpu_mpi_shutdown();
+	starpu_shutdown();
+
+	return ret;
+}
+
+int exchange_void(int rank)
+{
+	int ret, i;
+	starpu_data_handle_t tab_handle[NB];
+
+	ret = starpu_init(NULL);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
+	ret = starpu_mpi_init(NULL, NULL, 0);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
+
+	FPRINTF_MPI(stderr, "Exchanging void data\n");
+
+	for(i=0 ; i<NB ; i++)
+	{
+		starpu_void_data_register(&tab_handle[i]);
+		starpu_mpi_data_register(tab_handle[i], i, rank);
+	}
+	ret = exchange(rank, tab_handle, NULL);
+	for(i=0 ; i<NB ; i++)
+		starpu_data_unregister(tab_handle[i]);
+
+	starpu_mpi_shutdown();
+	starpu_shutdown();
+
+	return ret;
+}
+
+void check_complex(starpu_data_handle_t handle, int i, int rank, int *error)
+{
+	double *real = starpu_complex_get_real(handle);
+	double *imaginary = starpu_complex_get_imaginary(handle);
+
+	int other_rank = rank%2 == 0 ? rank+1 : rank-1;
+
+	if ((*real != ((i*other_rank)+12)) || (*imaginary != ((i*other_rank)+45)))
+	{
+		FPRINTF_MPI(stderr, "Incorrect received value: %f != %d || %f != %d\n", *real, ((i*other_rank)+12), *imaginary, ((i*other_rank)+45));
+		*error = 1;
+	}
+	else
+	{
+		FPRINTF_MPI(stderr, "Correct received value: %f == %d || %f == %d\n", *real, ((i*other_rank)+12), *imaginary, ((i*other_rank)+45));
+	}
+}
+
+int exchange_complex(int rank)
+{
+	int ret, i;
+	starpu_data_handle_t handle[NB];
+	double real[NB];
+	double imaginary[NB];
+
+	ret = starpu_init(NULL);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
+	ret = starpu_mpi_init(NULL, NULL, 0);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
+
+	FPRINTF_MPI(stderr, "Exchanging complex data\n");
+
+	for(i=0 ; i<NB ; i++)
+	{
+		real[i] = (i*rank)+12;
+		imaginary[i] = (i*rank)+45;
+		starpu_complex_data_register(&handle[i], STARPU_MAIN_RAM, &real[i], &imaginary[i], 1);
+		starpu_mpi_data_register(handle[i], i, rank);
+	}
+	ret = exchange(rank, handle, check_complex);
+	for(i=0 ; i<NB ; i++)
+		starpu_data_unregister(handle[i]);
+
+	starpu_mpi_shutdown();
+	starpu_shutdown();
+
+	return ret;
+}
+
+int main(int argc, char **argv)
+{
+	int ret=0, rank, size;
+
+	MPI_Init(&argc, &argv);
+	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+	MPI_Comm_size(MPI_COMM_WORLD, &size);
+
+	if (size%2 != 0)
+	{
+		if (rank == 0)
+			FPRINTF(stderr, "We need a even number of processes.\n");
+
+		MPI_Finalize();
+		return STARPU_TEST_SKIPPED;
+	}
+
+	ret = exchange_variable(rank);
+	ret = exchange_variable(rank);
+//	if (ret == 0)
+//	ret = exchange_void(rank);
+//	if (ret == 0)
+//		ret = exchange_complex(rank);
+
+	MPI_Finalize();
+
+	return ret;
+}