瀏覽代碼

StarPU-MPI: Add testcase

Nathalie Furmento 14 年之前
父節點
當前提交
3f0741ddca
共有 2 個文件被更改,包括 127 次插入0 次删除
  1. 8 0
      mpi/Makefile.am
  2. 119 0
      mpi/tests/insert_task.c

+ 8 - 0
mpi/Makefile.am

@@ -131,6 +131,7 @@ check_PROGRAMS +=				\
 	tests/ring_async_implicit			\
 	tests/ring_async_implicit			\
 	tests/block_interface				\
 	tests/block_interface				\
 	tests/block_interface_pinned			\
 	tests/block_interface_pinned			\
+	tests/insert_task				\
 	tests/multiple_send
 	tests/multiple_send
 
 
 testbin_PROGRAMS =				\
 testbin_PROGRAMS =				\
@@ -146,6 +147,7 @@ testbin_PROGRAMS =				\
 	tests/ring_async_implicit			\
 	tests/ring_async_implicit			\
 	tests/block_interface				\
 	tests/block_interface				\
 	tests/block_interface_pinned			\
 	tests/block_interface_pinned			\
+	tests/insert_task				\
 	tests/multiple_send
 	tests/multiple_send
 
 
 tests_mpi_isend_LDADD =					\
 tests_mpi_isend_LDADD =					\
@@ -220,6 +222,12 @@ tests_block_interface_pinned_LDADD =			\
 tests_block_interface_pinned_SOURCES =			\
 tests_block_interface_pinned_SOURCES =			\
 	tests/block_interface_pinned.c
 	tests/block_interface_pinned.c
 
 
+tests_insert_task_LDADD =				\
+	libstarpumpi.la
+
+tests_insert_task_SOURCES =				\
+	tests/insert_task.c
+
 tests_multiple_send_LDADD =				\
 tests_multiple_send_LDADD =				\
 	libstarpumpi.la
 	libstarpumpi.la
 
 

+ 119 - 0
mpi/tests/insert_task.c

@@ -0,0 +1,119 @@
+/*
+ * StarPU
+ * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (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>
+#include <math.h>
+
+void func_cpu(void *descr[], __attribute__ ((unused)) void *_args)
+{
+	unsigned *x = (unsigned *)STARPU_VARIABLE_GET_PTR(descr[0]);
+	unsigned *y = (unsigned *)STARPU_VARIABLE_GET_PTR(descr[1]);
+
+        fprintf(stdout, "VALUES: %d %d\n", *x, *y);
+        *x = (*x + *y) / 2;
+}
+
+starpu_codelet mycodelet = {
+	.where = STARPU_CPU,
+	.cpu_func = func_cpu,
+        .nbuffers = 2
+};
+
+#define X     4
+#define Y     5
+
+/* Returns the MPI node number where data indexes index is */
+int my_distrib(int x, int y, int nb_nodes) {
+        return x % nb_nodes;
+}
+
+
+int main(int argc, char **argv)
+{
+        int rank, size, x, y, loop;
+        int value=0;
+        unsigned matrix[X][Y];
+        starpu_data_handle data_handles[X][Y];
+
+	starpu_init(NULL);
+	starpu_mpi_initialize_extended(1, &rank, &size);
+
+        for(x = 0; x < X; x++) {
+                for (y = 0; y < Y; y++) {
+                        matrix[x][y] = (rank+1)*10 + value;
+                        value++;
+                }
+        }
+#if 0
+        for(x = 0; x < X; x++) {
+                fprintf(stdout, "[%d] ", rank);
+                for (y = 0; y < Y; y++) {
+                        fprintf(stdout, "%3d ", matrix[x][y]);
+                }
+                fprintf(stdout, "\n");
+        }
+#endif
+
+        for(x = 0; x < X; x++) {
+                for (y = 0; y < Y; y++) {
+                        int mpi_rank = my_distrib(x, y, size);
+                        if (mpi_rank == rank) {
+                                //fprintf(stderr, "[%d] Owning data[%d][%d]\n", rank, x, y);
+                                starpu_variable_data_register(&data_handles[x][y], 0, (uintptr_t)&(matrix[x][y]), sizeof(unsigned));
+                        }
+                        else if (rank == mpi_rank+1 || rank == mpi_rank-1) {
+                                /* I don't own that index, but will need it for my computations */
+                                //fprintf(stderr, "[%d] Neighbour of data[%d][%d]\n", rank, x, y);
+                                starpu_variable_data_register(&data_handles[x][y], -1, (uintptr_t)NULL, sizeof(unsigned));
+                        }
+                        else {
+                                /* 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_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handles[1][1], STARPU_R, data_handles[0][1], 0);
+        starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handles[3][1], STARPU_R, data_handles[0][1], 0);
+        starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handles[0][1], STARPU_R, data_handles[0][0], 0);
+        starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handles[3][1], STARPU_R, data_handles[0][1], 0);
+
+        fprintf(stderr, "Waiting ...\n");
+        starpu_task_wait_for_all();
+
+        for(x = 0; x < X; x++) {
+                for (y = 0; y < Y; y++) {
+                        if (!data_handles[x][y])
+                                starpu_data_release(data_handles[x][y]);
+                }
+        }
+	starpu_mpi_shutdown();
+	starpu_shutdown();
+
+#if 0
+        for(x = 0; x < X; x++) {
+                fprintf(stdout, "[%d] ", rank);
+                for (y = 0; y < Y; y++) {
+                        fprintf(stdout, "%3d ", matrix[x][y]);
+                }
+                fprintf(stdout, "\n");
+        }
+#endif
+
+	return 0;
+}