1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
/* 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 <mpi.h>
#include <starpu.h>
#include <starpu_mpi.h>
int starpu_mpi_scatter_detached(starpu_data_handle_t *data_handles, int count, int root, MPI_Comm comm)
{
int rank;
int x;
MPI_Comm_rank(comm, &rank);
for(x = 0; x < count ; x++)
{
if (data_handles[x])
{
int owner = starpu_data_get_rank(data_handles[x]);
int mpi_tag = starpu_data_get_tag(data_handles[x]);
STARPU_ASSERT(mpi_tag >= 0);
if ((rank == root) && (owner != root))
{
//fprintf(stderr, "[%d] Sending data[%d] to %d\n", rank, x, owner);
starpu_mpi_isend_detached(data_handles[x], owner, mpi_tag, comm, NULL, NULL);
}
if ((rank != root) && (owner == rank))
{
//fprintf(stderr, "[%d] Receiving data[%d] from %d\n", rank, x, root);
starpu_mpi_irecv_detached(data_handles[x], root, mpi_tag, comm, NULL, NULL);
}
}
}
return 0;
}
int starpu_mpi_gather_detached(starpu_data_handle_t *data_handles, int count, int root, MPI_Comm comm)
{
int rank;
int x;
MPI_Comm_rank(comm, &rank);
for(x = 0; x < count ; x++)
{
if (data_handles[x])
{
int owner = starpu_data_get_rank(data_handles[x]);
int mpi_tag = starpu_data_get_tag(data_handles[x]);
STARPU_ASSERT(mpi_tag >= 0);
if ((rank == root) && (owner != root))
{
//fprintf(stderr, "[%d] Receiving data[%d] from %d\n", rank, x, owner);
starpu_mpi_irecv_detached(data_handles[x], owner, mpi_tag, comm, NULL, NULL);
}
if ((rank != root) && (owner == rank))
{
//fprintf(stderr, "[%d] Sending data[%d] to %d\n", rank, x, root);
starpu_mpi_isend_detached(data_handles[x], root, mpi_tag, comm, NULL, NULL);
}
}
}
return 0;
}
|