-#include "colls.h"
+/* Copyright (c) 2013-2014. The SimGrid Team.
+ * All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "colls_private.h"
//#include <star-reduction.c>
int
MPI_Datatype dtype, MPI_Op op,
int root, MPI_Comm comm)
{
- int i, tag = 4321;
+ int i, tag = COLL_TAG_REDUCE;
int size;
int rank;
MPI_Aint extent;
char *inbuf;
MPI_Status status;
- MPI_Comm_rank(comm, &rank);
- MPI_Comm_size(comm, &size);
+ rank = smpi_comm_rank(comm);
+ size = smpi_comm_size(comm);
/* If not root, send data to the root. */
- MPI_Type_extent(dtype, &extent);
+ extent = smpi_datatype_get_extent(dtype);
if (rank != root) {
- MPI_Send(sbuf, count, dtype, root, tag, comm);
+ smpi_mpi_send(sbuf, count, dtype, root, tag, comm);
return 0;
}
messages. */
if (size > 1)
- origin = (char *) malloc(count * extent);
+ origin = (char *) smpi_get_tmp_recvbuffer(count * extent);
/* Initialize the receive buffer. */
if (rank == (size - 1))
- MPI_Sendrecv(sbuf, count, dtype, rank, tag,
+ smpi_mpi_sendrecv(sbuf, count, dtype, rank, tag,
rbuf, count, dtype, rank, tag, comm, &status);
else
- MPI_Recv(rbuf, count, dtype, size - 1, tag, comm, &status);
+ smpi_mpi_recv(rbuf, count, dtype, size - 1, tag, comm, &status);
/* Loop receiving and calling reduction function (C or Fortran). */
if (rank == i)
inbuf = sbuf;
else {
- MPI_Recv(origin, count, dtype, i, tag, comm, &status);
+ smpi_mpi_recv(origin, count, dtype, i, tag, comm, &status);
inbuf = origin;
}
/* Call reduction function. */
- star_reduction(op, inbuf, rbuf, &count, &dtype);
+ smpi_op_apply(op, inbuf, rbuf, &count, &dtype);
}
if (origin)
- free(origin);
+ smpi_free_tmp_buffer(origin);
/* All done */
return 0;