/* StarPU --- Runtime system for heterogeneous multicore architectures. * * Copyright (C) 2011, 2012, 2013, 2014 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 #include "helper.h" /* Returns the MPI node number where data indexes index is */ int my_distrib(int x, int y, int nb_nodes) { return (x+y) % nb_nodes; } void cpu_codelet(void *descr[], void *_args) { float *block; unsigned nx = STARPU_MATRIX_GET_NY(descr[0]); unsigned ld = STARPU_MATRIX_GET_LD(descr[0]); unsigned i,j; int rank; float factor; block = (float *)STARPU_MATRIX_GET_PTR(descr[0]); starpu_codelet_unpack_args(_args, &rank); factor = block[0]; //FPRINTF_MPI("rank %d factor %f\n", rank, factor); for (j = 0; j < nx; j++) { for (i = 0; i < nx; i++) { //FPRINTF_MPI("rank %d factor %f --> %f %f\n", rank, factor, block[j+i*ld], block[j+i*ld]*factor); block[j+i*ld] *= factor; } } } static struct starpu_codelet cl = { .cpu_funcs = {cpu_codelet, NULL}, .nbuffers = 1, .modes = {STARPU_RW}, }; void scallback(void *arg STARPU_ATTRIBUTE_UNUSED) { char *msg = arg; FPRINTF_MPI("Sending completed for <%s>\n", msg); } void rcallback(void *arg STARPU_ATTRIBUTE_UNUSED) { char *msg = arg; FPRINTF_MPI("Reception completed for <%s>\n", msg); } int main(int argc, char **argv) { int rank, nodes; float ***bmat = NULL; starpu_data_handle_t *data_handles; unsigned i,j,x,y; unsigned nblocks=4; unsigned block_size=2; unsigned size = nblocks*block_size; unsigned ld = size / nblocks; int ret = starpu_init(NULL); STARPU_CHECK_RETURN_VALUE(ret, "starpu_init"); ret = starpu_mpi_init(&argc, &argv, 1); STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init"); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &nodes); if (rank == 0) { /* Allocate the matrix */ int block_number=10; bmat = malloc(nblocks * sizeof(float *)); for(x=0 ; x