1 /* Copyright (c) 2013-2017. 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>
12 Coll_reduce_flat_tree::reduce(void *sbuf, void *rbuf, int count,
13 MPI_Datatype dtype, MPI_Op op,
14 int root, MPI_Comm comm)
16 int i, tag = COLL_TAG_REDUCE;
27 /* If not root, send data to the root. */
28 extent = dtype->get_extent();
31 Request::send(sbuf, count, dtype, root, tag, comm);
35 /* Root receives and reduces messages. Allocate buffer to receive
39 origin = (char *) smpi_get_tmp_recvbuffer(count * extent);
42 /* Initialize the receive buffer. */
43 if (rank == (size - 1))
44 Request::sendrecv(sbuf, count, dtype, rank, tag,
45 rbuf, count, dtype, rank, tag, comm, &status);
47 Request::recv(rbuf, count, dtype, size - 1, tag, comm, &status);
49 /* Loop receiving and calling reduction function (C or Fortran). */
51 for (i = size - 2; i >= 0; --i) {
53 inbuf = static_cast<char*>(sbuf);
55 Request::recv(origin, count, dtype, i, tag, comm, &status);
59 /* Call reduction function. */
60 if(op!=MPI_OP_NULL) op->apply( inbuf, rbuf, &count, dtype);
65 smpi_free_tmp_buffer(origin);