Explorar o código

mpi/tests: new test for node selection policy when several nodes own W data

Nathalie Furmento %!s(int64=10) %!d(string=hai) anos
pai
achega
9a4ef14ed7
Modificáronse 2 ficheiros con 177 adicións e 0 borrados
  1. 4 0
      mpi/tests/Makefile.am
  2. 173 0
      mpi/tests/policy_selection.c

+ 4 - 0
mpi/tests/Makefile.am

@@ -125,6 +125,7 @@ starpu_mpi_TESTS =				\
 	policy_register_many			\
 	policy_register_toomany			\
 	policy_unregister			\
+	policy_selection			\
 	early_request				\
 	starpu_redefine
 
@@ -176,6 +177,7 @@ noinst_PROGRAMS =				\
 	policy_register_many			\
 	policy_register_toomany			\
 	policy_unregister			\
+	policy_selection			\
 	early_request				\
 	starpu_redefine
 
@@ -279,6 +281,8 @@ policy_register_toomany_LDADD =			\
 	../src/libstarpumpi-@STARPU_EFFECTIVE_VERSION@.la
 policy_unregister_LDADD =			\
 	../src/libstarpumpi-@STARPU_EFFECTIVE_VERSION@.la
+policy_selection_LDADD =			\
+	../src/libstarpumpi-@STARPU_EFFECTIVE_VERSION@.la
 early_request_LDADD =					\
 	../src/libstarpumpi-@STARPU_EFFECTIVE_VERSION@.la
 starpu_redefine_LDADD =					\

+ 173 - 0
mpi/tests/policy_selection.c

@@ -0,0 +1,173 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2015  CNRS
+ *
+ * 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"
+
+void func_cpu(void *descr[], void *_args)
+{
+	(void)descr;
+	(void)_args;
+}
+
+struct starpu_codelet mycodelet_2 =
+{
+	.cpu_funcs = {func_cpu},
+	.nbuffers = 2,
+	.modes = {STARPU_W, STARPU_W}
+};
+struct starpu_codelet mycodelet_3 =
+{
+	.cpu_funcs = {func_cpu},
+	.nbuffers = 3,
+	.modes = {STARPU_R, STARPU_W, STARPU_W}
+};
+
+int main(int argc, char **argv)
+{
+	int ret;
+	int rank, size;
+	int policy;
+	struct starpu_task *task;
+	starpu_data_handle_t handles[3];
+
+	MPI_Init(&argc, &argv);
+	starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
+	starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
+
+	if (size < 3)
+	{
+		if (rank == 0)
+			FPRINTF(stderr, "We need at least 3 processes.\n");
+
+		MPI_Finalize();
+		return STARPU_TEST_SKIPPED;
+	}
+
+	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");
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
+
+	if (rank == 0)
+	{
+		starpu_variable_data_register(&handles[0], STARPU_MAIN_RAM, (uintptr_t)&policy, sizeof(int));
+	}
+	else
+	{
+		starpu_variable_data_register(&handles[0], -1, (uintptr_t)NULL, sizeof(int));
+	}
+	starpu_mpi_data_register(handles[0], 10, 0);
+
+	if (rank == 1)
+	{
+		starpu_variable_data_register(&handles[1], STARPU_MAIN_RAM, (uintptr_t)&policy, sizeof(int));
+	}
+	else
+	{
+		starpu_variable_data_register(&handles[1], -1, (uintptr_t)NULL, sizeof(int));
+	}
+	starpu_mpi_data_register(handles[1], 20, 1);
+
+	if (rank == 2)
+	{
+	     starpu_variable_data_register(&handles[2], STARPU_MAIN_RAM, (uintptr_t)&policy, sizeof(int));
+	}
+	else
+	{
+	     starpu_variable_data_register(&handles[2], -1, (uintptr_t)NULL, sizeof(int));
+	}
+	starpu_mpi_data_register(handles[2], 30, 2);
+
+	// Force the execution on node 1
+	task = starpu_mpi_task_build(MPI_COMM_WORLD, &mycodelet_3,
+				     STARPU_R, handles[2],
+				     STARPU_W, handles[0], STARPU_W, handles[1],
+				     STARPU_EXECUTE_ON_NODE, 1,
+				     0);
+	FPRINTF_MPI(stderr, "Task %p\n", task);
+	if (rank == 1)
+	{
+		STARPU_ASSERT_MSG(task, "Task should be executed by rank 1\n");
+		task->destroy = 0;
+		starpu_task_destroy(task);
+	}
+	else
+	{
+		STARPU_ASSERT_MSG(task == NULL, "Task should be executed by rank 1\n");
+	}
+
+	// Force the execution on node 1
+	task = starpu_mpi_task_build(MPI_COMM_WORLD, &mycodelet_2,
+				     STARPU_W, handles[0], STARPU_W, handles[1],
+				     STARPU_EXECUTE_ON_NODE, 1,
+				     0);
+	FPRINTF_MPI(stderr, "Task %p\n", task);
+	if (rank == 1)
+	{
+		STARPU_ASSERT_MSG(task, "Task should be executed by rank 1\n");
+		task->destroy = 0;
+		starpu_task_destroy(task);
+	}
+	else
+	{
+		STARPU_ASSERT_MSG(task == NULL, "Task should be executed by rank 1\n");
+	}
+
+	// Let StarPU choose the node
+	task = starpu_mpi_task_build(MPI_COMM_WORLD, &mycodelet_3,
+				     STARPU_R, handles[2],
+				     STARPU_W, handles[0], STARPU_W, handles[1],
+				     0);
+	FPRINTF_MPI(stderr, "Task %p\n", task);
+	if (rank == 2)
+	{
+		STARPU_ASSERT_MSG(task, "Task should be executed by rank 2\n");
+		task->destroy = 0;
+		starpu_task_destroy(task);
+	}
+	else
+	{
+		STARPU_ASSERT_MSG(task == NULL, "Task should be executed by rank 2\n");
+	}
+
+	// Let StarPU choose the node
+	task = starpu_mpi_task_build(MPI_COMM_WORLD, &mycodelet_2,
+				     STARPU_W, handles[0], STARPU_W, handles[1],
+				     0);
+	FPRINTF_MPI(stderr, "Task %p\n", task);
+	if (rank == 0)
+	{
+		STARPU_ASSERT_MSG(task, "Task should be executed by rank 0\n");
+		task->destroy = 0;
+		starpu_task_destroy(task);
+	}
+	else
+	{
+		STARPU_ASSERT_MSG(task == NULL, "Task should be executed by rank 0\n");
+	}
+
+	starpu_data_unregister(handles[0]);
+	starpu_data_unregister(handles[1]);
+	starpu_data_unregister(handles[2]);
+
+	starpu_mpi_shutdown();
+	starpu_shutdown();
+	MPI_Finalize();
+
+	return 0;
+}