1 /* Copyright (c) 2013-2023. 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.hpp"
8 //#include <star-reduction.c>
9 namespace simgrid::smpi {
10 int reduce__flat_tree(const void *sbuf, void *rbuf, int count,
11 MPI_Datatype dtype, MPI_Op op,
12 int root, MPI_Comm comm)
14 int i, tag = COLL_TAG_REDUCE;
18 unsigned char* origin = nullptr;
19 const unsigned char* inbuf;
25 /* If not root, send data to the root. */
26 extent = dtype->get_extent();
29 Request::send(sbuf, count, dtype, root, tag, comm);
33 /* Root receives and reduces messages. Allocate buffer to receive
37 origin = smpi_get_tmp_recvbuffer(count * extent);
39 /* Initialize the receive buffer. */
40 if (rank == (size - 1))
41 Request::sendrecv(sbuf, count, dtype, rank, tag,
42 rbuf, count, dtype, rank, tag, comm, &status);
44 Request::recv(rbuf, count, dtype, size - 1, tag, comm, &status);
46 /* Loop receiving and calling reduction function (C or Fortran). */
48 for (i = size - 2; i >= 0; --i) {
50 inbuf = static_cast<const unsigned char*>(sbuf);
52 Request::recv(origin, count, dtype, i, tag, comm, &status);
56 /* Call reduction function. */
57 if(op!=MPI_OP_NULL) op->apply( inbuf, rbuf, &count, dtype);
61 smpi_free_tmp_buffer(origin);
66 } // namespace simgrid::smpi