1 /* Copyright (c) 2013-2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "colls_private.h"
8 //#include <star-reduction.c>
11 smpi_coll_tuned_reduce_flat_tree(void *sbuf, void *rbuf, int count,
12 MPI_Datatype dtype, MPI_Op op,
13 int root, MPI_Comm comm)
15 int i, tag = COLL_TAG_REDUCE;
23 rank = smpi_comm_rank(comm);
24 size = smpi_comm_size(comm);
26 /* If not root, send data to the root. */
27 extent = smpi_datatype_get_extent(dtype);
30 smpi_mpi_send(sbuf, count, dtype, root, tag, comm);
34 /* Root receives and reduces messages. Allocate buffer to receive
38 origin = (char *) smpi_get_tmp_recvbuffer(count * extent);
41 /* Initialize the receive buffer. */
42 if (rank == (size - 1))
43 smpi_mpi_sendrecv(sbuf, count, dtype, rank, tag,
44 rbuf, count, dtype, rank, tag, comm, &status);
46 smpi_mpi_recv(rbuf, count, dtype, size - 1, tag, comm, &status);
48 /* Loop receiving and calling reduction function (C or Fortran). */
50 for (i = size - 2; i >= 0; --i) {
54 smpi_mpi_recv(origin, count, dtype, i, tag, comm, &status);
58 /* Call reduction function. */
59 smpi_op_apply(op, inbuf, rbuf, &count, &dtype);
64 smpi_free_tmp_buffer(origin);