소스 검색

mpi/tests: new testcase for synchronous and early received communications

Nathalie Furmento 10 년 전
부모
커밋
36dd54c315
2개의 변경된 파일101개의 추가작업 그리고 0개의 파일을 삭제
  1. 4 0
      mpi/tests/Makefile.am
  2. 97 0
      mpi/tests/sync.c

+ 4 - 0
mpi/tests/Makefile.am

@@ -117,6 +117,7 @@ starpu_mpi_TESTS =				\
 	mpi_reduction				\
 	user_defined_datatype			\
 	tags					\
+	sync					\
 	gather					\
 	gather2					\
 	policy_register				\
@@ -165,6 +166,7 @@ noinst_PROGRAMS =				\
 	mpi_reduction				\
 	user_defined_datatype			\
 	tags					\
+	sync					\
 	gather					\
 	gather2					\
 	policy_register				\
@@ -256,6 +258,8 @@ user_defined_datatype_LDADD =			\
 	../src/libstarpumpi-@STARPU_EFFECTIVE_VERSION@.la
 tags_LDADD =			\
 	../src/libstarpumpi-@STARPU_EFFECTIVE_VERSION@.la
+sync_LDADD =			\
+	../src/libstarpumpi-@STARPU_EFFECTIVE_VERSION@.la
 gather_LDADD =			\
 	../src/libstarpumpi-@STARPU_EFFECTIVE_VERSION@.la
 gather2_LDADD =			\

+ 97 - 0
mpi/tests/sync.c

@@ -0,0 +1,97 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 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"
+
+int main(int argc, char **argv)
+{
+	int size, n, x=789;
+	int rank, other_rank;
+	int ret;
+	starpu_data_handle_t data[2];
+
+        MPI_Init(&argc, &argv);
+        MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+        MPI_Comm_size(MPI_COMM_WORLD, &size);
+
+        if (size % 2)
+        {
+		FPRINTF(stderr, "We need a even number of processes.\n");
+                MPI_Finalize();
+                return STARPU_TEST_SKIPPED;
+        }
+
+	other_rank = rank%2 == 0 ? rank+1 : rank-1;
+	FPRINTF_MPI(stderr, "rank %d exchanging with rank %d\n", rank, other_rank);
+
+	if (rank % 2)
+	{
+		MPI_Send(&rank, 1, MPI_INT, other_rank, 10, MPI_COMM_WORLD);
+		FPRINTF(stderr, "[%d] sending %d\n", rank, rank);
+	}
+	else
+	{
+		MPI_Recv(&x, 1, MPI_INT, other_rank, 10, MPI_COMM_WORLD, NULL);
+		FPRINTF(stderr, "[%d] received %d\n", rank, x);
+	}
+
+        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");
+
+	if (rank % 2)
+	{
+		starpu_variable_data_register(&data[0], STARPU_MAIN_RAM, (uintptr_t)&rank, sizeof(unsigned));
+		starpu_variable_data_register(&data[1], STARPU_MAIN_RAM, (uintptr_t)&rank, sizeof(unsigned));
+		starpu_mpi_data_register(data[1], 22, 0);
+	}
+	else
+		starpu_variable_data_register(&data[0], -1, (uintptr_t)NULL, sizeof(unsigned));
+	starpu_mpi_data_register(data[0], 12, 0);
+
+	if (rank % 2)
+	{
+		starpu_mpi_req req;
+		starpu_mpi_issend(data[1], &req, other_rank, 22, MPI_COMM_WORLD);
+		starpu_mpi_send(data[0], other_rank, 12, MPI_COMM_WORLD);
+		starpu_mpi_wait(&req, NULL);
+	}
+	else
+	{
+		int *xx;
+
+		starpu_mpi_recv(data[0], other_rank, 12, MPI_COMM_WORLD, NULL);
+		xx = (int *)starpu_variable_get_local_ptr(data[0]);
+		FPRINTF_MPI(stderr, "received %d\n", *xx);
+		STARPU_ASSERT_MSG(x==*xx, "Received value %d is incorrect (should be %d)\n", *xx, x);
+
+		starpu_variable_data_register(&data[1], -1, (uintptr_t)NULL, sizeof(unsigned));
+		starpu_mpi_data_register(data[1], 22, 0);
+		starpu_mpi_recv(data[0],  other_rank, 22, MPI_COMM_WORLD, NULL);
+		xx = (int *)starpu_variable_get_local_ptr(data[0]);
+		STARPU_ASSERT_MSG(x==*xx, "Received value %d is incorrect (should be %d)\n", *xx, x);
+	}
+
+	starpu_data_unregister(data[0]);
+	starpu_data_unregister(data[1]);
+
+	starpu_mpi_shutdown();
+	starpu_shutdown();
+        MPI_Finalize();
+	return 0;
+}