|
@@ -16,17 +16,19 @@
|
|
|
|
|
|
#include <starpu_mpi.h>
|
|
|
#include <math.h>
|
|
|
+#include "helper.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);
|
|
|
+ FPRINTF(stdout, "VALUES: %d %d\n", *x, *y);
|
|
|
*x = (*x + *y) / 2;
|
|
|
}
|
|
|
|
|
|
-struct starpu_codelet mycodelet = {
|
|
|
+struct starpu_codelet mycodelet =
|
|
|
+{
|
|
|
.where = STARPU_CPU,
|
|
|
.cpu_func = func_cpu,
|
|
|
.nbuffers = 2
|
|
@@ -36,7 +38,8 @@ struct starpu_codelet mycodelet = {
|
|
|
#define Y 5
|
|
|
|
|
|
|
|
|
-int my_distrib(int x, int y, int nb_nodes) {
|
|
|
+int my_distrib(int x, int y, int nb_nodes)
|
|
|
+{
|
|
|
return x % nb_nodes;
|
|
|
}
|
|
|
|
|
@@ -44,42 +47,53 @@ int my_distrib(int x, int y, int nb_nodes) {
|
|
|
int main(int argc, char **argv)
|
|
|
{
|
|
|
int rank, size, x, y;
|
|
|
- int value=0;
|
|
|
+ int ret,value=0;
|
|
|
unsigned matrix[X][Y];
|
|
|
starpu_data_handle_t data_handles[X][Y];
|
|
|
|
|
|
- starpu_init(NULL);
|
|
|
- starpu_mpi_initialize_extended(&rank, &size);
|
|
|
+ ret = starpu_init(NULL);
|
|
|
+ STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
|
|
|
+ ret = starpu_mpi_initialize_extended(&rank, &size);
|
|
|
+ STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_initialize_extended");
|
|
|
|
|
|
- for(x = 0; x < X; x++) {
|
|
|
- for (y = 0; y < Y; y++) {
|
|
|
+ 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]);
|
|
|
+ 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");
|
|
|
+ FPRINTF(stdout, "\n");
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
- for(x = 0; x < X; x++) {
|
|
|
- for (y = 0; y < Y; y++) {
|
|
|
+ for(x = 0; x < X; x++)
|
|
|
+ {
|
|
|
+ for (y = 0; y < Y; y++)
|
|
|
+ {
|
|
|
int mpi_rank = my_distrib(x, y, size);
|
|
|
- if (mpi_rank == rank) {
|
|
|
-
|
|
|
+ if (mpi_rank == rank)
|
|
|
+ {
|
|
|
+
|
|
|
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) {
|
|
|
+ else if (rank == mpi_rank+1 || rank == mpi_rank-1)
|
|
|
+ {
|
|
|
|
|
|
-
|
|
|
+
|
|
|
starpu_variable_data_register(&data_handles[x][y], -1, (uintptr_t)NULL, sizeof(unsigned));
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
|
|
|
data_handles[x][y] = NULL;
|
|
|
}
|
|
@@ -91,16 +105,22 @@ int main(int argc, char **argv)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- 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);
|
|
|
+ ret = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handles[1][1], STARPU_R, data_handles[0][1], 0);
|
|
|
+ STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_insert_task");
|
|
|
+ ret = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handles[3][1], STARPU_R, data_handles[0][1], 0);
|
|
|
+ STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_insert_task");
|
|
|
+ ret = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handles[0][1], STARPU_R, data_handles[0][0], 0);
|
|
|
+ STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_insert_task");
|
|
|
+ ret = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handles[3][1], STARPU_R, data_handles[0][1], 0);
|
|
|
+ STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_insert_task");
|
|
|
|
|
|
- fprintf(stderr, "Waiting ...\n");
|
|
|
+ FPRINTF(stderr, "Waiting ...\n");
|
|
|
starpu_task_wait_for_all();
|
|
|
|
|
|
- for(x = 0; x < X; x++) {
|
|
|
- for (y = 0; y < Y; y++) {
|
|
|
+ for(x = 0; x < X; x++)
|
|
|
+ {
|
|
|
+ for (y = 0; y < Y; y++)
|
|
|
+ {
|
|
|
if (data_handles[x][y])
|
|
|
starpu_data_unregister(data_handles[x][y]);
|
|
|
}
|
|
@@ -109,12 +129,14 @@ int main(int argc, char **argv)
|
|
|
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]);
|
|
|
+ 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");
|
|
|
+ FPRINTF(stdout, "\n");
|
|
|
}
|
|
|
#endif
|
|
|
|