2 //#include <star-reduction.c>
5 smpi_coll_tuned_reduce_flat_tree(void *sbuf, void *rbuf, int count,
6 MPI_Datatype dtype, MPI_Op op,
7 int root, MPI_Comm comm)
17 MPI_Comm_rank(comm, &rank);
18 MPI_Comm_size(comm, &size);
20 /* If not root, send data to the root. */
21 MPI_Type_extent(dtype, &extent);
24 MPI_Send(sbuf, count, dtype, root, tag, comm);
28 /* Root receives and reduces messages. Allocate buffer to receive
32 origin = (char *) malloc(count * extent);
35 /* Initialize the receive buffer. */
36 if (rank == (size - 1))
37 MPI_Sendrecv(sbuf, count, dtype, rank, tag,
38 rbuf, count, dtype, rank, tag, comm, &status);
40 MPI_Recv(rbuf, count, dtype, size - 1, tag, comm, &status);
42 /* Loop receiving and calling reduction function (C or Fortran). */
44 for (i = size - 2; i >= 0; --i) {
48 MPI_Recv(origin, count, dtype, i, tag, comm, &status);
52 /* Call reduction function. */
53 star_reduction(op, inbuf, rbuf, &count, &dtype);