Преглед на файлове

StarPU-MPI: add new testcase

Nathalie Furmento преди 14 години
родител
ревизия
0d717d6f41
променени са 2 файла, в които са добавени 146 реда и са изтрити 1 реда
  1. 9 1
      mpi/Makefile.am
  2. 137 0
      mpi/tests/insert_task_block.c

+ 9 - 1
mpi/Makefile.am

@@ -121,7 +121,7 @@ examples_mpi_lu_plu_example_double_SOURCES =	\
 	$(top_srcdir)/examples/common/blas.c
 endif
 
-check_PROGRAMS +=				\
+check_PROGRAMS +=					\
 	tests/pingpong					\
 	tests/mpi_test					\
 	tests/mpi_isend					\
@@ -135,6 +135,7 @@ check_PROGRAMS +=				\
 	tests/block_interface				\
 	tests/block_interface_pinned			\
 	tests/insert_task				\
+	tests/insert_task_block				\
 	tests/multiple_send
 
 testbin_PROGRAMS =				\
@@ -151,6 +152,7 @@ testbin_PROGRAMS =				\
 	tests/block_interface				\
 	tests/block_interface_pinned			\
 	tests/insert_task				\
+	tests/insert_task_block				\
 	tests/multiple_send
 
 tests_mpi_isend_LDADD =					\
@@ -231,6 +233,12 @@ tests_insert_task_LDADD =				\
 tests_insert_task_SOURCES =				\
 	tests/insert_task.c
 
+tests_insert_task_block_LDADD =				\
+	libstarpumpi.la
+
+tests_insert_task_block_SOURCES =			\
+	tests/insert_task_block.c
+
 tests_multiple_send_LDADD =				\
 	libstarpumpi.la
 

+ 137 - 0
mpi/tests/insert_task_block.c

@@ -0,0 +1,137 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2011  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 <math.h>
+
+void func_cpu(void *descr[], __attribute__ ((unused)) void *_args)
+{
+	unsigned *matrix = (unsigned **)STARPU_MATRIX_GET_PTR(descr[0]);
+	int nx = (int)STARPU_MATRIX_GET_NX(descr[0]);
+	int ny = (int)STARPU_MATRIX_GET_NY(descr[0]);
+	int ld = (int)STARPU_MATRIX_GET_LD(descr[0]);
+
+        int i, j;
+        unsigned sum=0;
+
+	for (i = 0; i < nx; i++) {
+		for (j = 0; j < ny; j++) {
+                        sum += matrix[i+j*ld];
+                }
+        }
+	for (i = 0; i < nx; i++) {
+		for (j = 0; j < ny; j++) {
+                        matrix[i+j*ld] = sum;///(nx*ny);
+                }
+        }
+}
+
+starpu_codelet mycodelet = {
+	.where = STARPU_CPU,
+	.cpu_func = func_cpu,
+        .nbuffers = 1
+};
+
+#define SIZE       6
+#define BLOCKS     3
+
+/* 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[SIZE][SIZE];
+        starpu_data_handle data_handles[SIZE][SIZE];
+
+	starpu_init(NULL);
+	starpu_mpi_initialize_extended(1, &rank, &size);
+
+        for(x = 0; x < SIZE; x++) {
+                for (y = 0; y < SIZE; y++) {
+                        matrix[x][y] = rank*100 + value;
+                        value++;
+                }
+        }
+#if 1
+        for(x = 0; x < SIZE; x++) {
+                fprintf(stdout, "[%d] ", rank);
+                for (y = 0; y < SIZE; y++) {
+                        fprintf(stdout, "%3d ", matrix[x][y]);
+                }
+                fprintf(stdout, "\n");
+        }
+#endif
+
+        for(x = 0; x < BLOCKS ;  x++) {
+                for (y = 0; y < BLOCKS; 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_matrix_data_register(&data_handles[x][y], 0, (uintptr_t)&(matrix[(SIZE/BLOCKS)*x][(SIZE/BLOCKS)*y]),
+                                                            SIZE, SIZE/BLOCKS, SIZE/BLOCKS, sizeof(float));
+                        }
+                        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_matrix_data_register(&data_handles[x][y], -1, (uintptr_t)&(matrix[(SIZE/BLOCKS)*x][(SIZE/BLOCKS)*y]),
+                                                            SIZE, SIZE/BLOCKS, SIZE/BLOCKS, sizeof(float));
+                        }
+                        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);
+                }
+        }
+
+        for(x = 0; x < BLOCKS; x++) {
+                for (y = 0; y < BLOCKS; y++) {
+                        starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet,
+                                               STARPU_RW, data_handles[x][y],
+                                               0);
+                }
+        }
+
+        fprintf(stderr, "Waiting ...\n");
+        starpu_task_wait_for_all();
+
+        for(x = 0; x < BLOCKS; x++) {
+                for (y = 0; y < BLOCKS; y++) {
+                        if (!data_handles[x][y])
+                                starpu_data_release(data_handles[x][y]);
+                }
+        }
+	starpu_mpi_shutdown();
+	starpu_shutdown();
+
+#if 1
+        for(x = 0; x < SIZE; x++) {
+                fprintf(stdout, "[%d] ", rank);
+                for (y = 0; y < SIZE; y++) {
+                        fprintf(stdout, "%3d ", matrix[x][y]);
+                }
+                fprintf(stdout, "\n");
+        }
+#endif
+
+	return 0;
+}