/* StarPU --- Runtime system for heterogeneous multicore architectures. * * Copyright (C) 2013, 2014, 2015, 2016, 2017 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 #include #include "helper.h" typedef void (*check_func)(starpu_data_handle_t handle_s, starpu_data_handle_t handle_r, int *error); void send_recv_and_check(int rank, int node, starpu_data_handle_t handle_s, int tag_s, starpu_data_handle_t handle_r, int tag_r, int *error, check_func func) { int ret; MPI_Status status; if (rank == 0) { ret = starpu_mpi_send(handle_s, node, tag_s, MPI_COMM_WORLD); STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_send"); ret = starpu_mpi_recv(handle_r, node, tag_r, MPI_COMM_WORLD, &status); STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_recv"); assert(func); func(handle_s, handle_r, error); } else if (rank == 1) { ret = starpu_mpi_recv(handle_s, node, tag_s, MPI_COMM_WORLD, &status); STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_recv"); ret = starpu_mpi_send(handle_s, node, tag_r, MPI_COMM_WORLD); STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_send"); } } /* * Void */ void check_void(starpu_data_handle_t handle_s, starpu_data_handle_t handle_r, int *error) { (void)error; FPRINTF_MPI(stderr, "Success with void value\n"); } void exchange_void(int rank, int *error) { STARPU_SKIP_IF_VALGRIND; if (rank == 0) { starpu_data_handle_t void_handle[2]; starpu_void_data_register(&void_handle[0]); starpu_void_data_register(&void_handle[1]); send_recv_and_check(rank, 1, void_handle[0], 0x42, void_handle[1], 0x1337, error, check_void); starpu_data_unregister(void_handle[0]); starpu_data_unregister(void_handle[1]); } else if (rank == 1) { starpu_data_handle_t void_handle; starpu_void_data_register(&void_handle); send_recv_and_check(rank, 0, void_handle, 0x42, NULL, 0x1337, NULL, NULL); starpu_data_unregister(void_handle); } } /* * Variable */ void check_variable(starpu_data_handle_t handle_s, starpu_data_handle_t handle_r, int *error) { float *v_s, *v_r; STARPU_ASSERT(starpu_variable_get_elemsize(handle_s) == starpu_variable_get_elemsize(handle_r)); v_s = (float *)starpu_variable_get_local_ptr(handle_s); v_r = (float *)starpu_variable_get_local_ptr(handle_r); if (*v_s == *v_r) { FPRINTF_MPI(stderr, "Success with variable value: %f == %f\n", *v_s, *v_r); } else { *error = 1; FPRINTF_MPI(stderr, "Error with variable value: %f != %f\n", *v_s, *v_r); } } void exchange_variable(int rank, int *error) { if (rank == 0) { float v = 42.12; starpu_data_handle_t variable_handle[2]; starpu_variable_data_register(&variable_handle[0], STARPU_MAIN_RAM, (uintptr_t)&v, sizeof(v)); starpu_variable_data_register(&variable_handle[1], -1, (uintptr_t)NULL, sizeof(v)); send_recv_and_check(rank, 1, variable_handle[0], 0x42, variable_handle[1], 0x1337, error, check_variable); starpu_data_unregister(variable_handle[0]); starpu_data_unregister(variable_handle[1]); } else if (rank == 1) { starpu_data_handle_t variable_handle; starpu_variable_data_register(&variable_handle, -1, (uintptr_t)NULL, sizeof(float)); send_recv_and_check(rank, 0, variable_handle, 0x42, NULL, 0x1337, NULL, NULL); starpu_data_unregister(variable_handle); } } /* * Vector */ void check_vector(starpu_data_handle_t handle_s, starpu_data_handle_t handle_r, int *error) { int i; int nx; int *v_r, *v_s; STARPU_ASSERT(starpu_vector_get_elemsize(handle_s) == starpu_vector_get_elemsize(handle_r)); STARPU_ASSERT(starpu_vector_get_nx(handle_s) == starpu_vector_get_nx(handle_r)); nx = starpu_vector_get_nx(handle_r); v_r = (int *)starpu_vector_get_local_ptr(handle_r); v_s = (int *)starpu_vector_get_local_ptr(handle_s); for(i=0 ; i %d] value: %c == %c\n", x, y, index, matrix_s[index], matrix_r[index]); } else { *error = 1; FPRINTF_MPI(stderr, "Error with matrix[%d,%d --> %d] value: %c != %c\n", x, y, index, matrix_s[index], matrix_r[index]); } } } } void exchange_matrix(int rank, int *error) { int nx=3; int ny=2; if (rank == 0) { char *matrix, n='a'; int x, y; starpu_data_handle_t matrix_handle[2]; matrix = (char*)malloc(nx*ny*sizeof(char)); assert(matrix); for(y=0 ; y %d] value: %f == %f\n", x, y, z, index, block_s[index], block_r[index]); } else { *error = 1; FPRINTF_MPI(stderr, "Error with block[%d,%d,%d --> %d] value: %f != %f\n", x, y, z, index, block_s[index], block_r[index]); } } } starpu_data_release(handle_s); starpu_data_release(handle_r); } void exchange_block(int rank, int *error) { int nx=3; int ny=2; int nz=4; if (rank == 0) { float *block, n=1.0; int x, y, z; starpu_data_handle_t block_handle[2]; block = (float*)malloc(nx*ny*nz*sizeof(float)); assert(block); for(z=0 ; z