+/* 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"
/*
MPI_Op op, int root, MPI_Comm comm)
{
MPI_Status status;
- int comm_size, rank, type_size, pof2, rem, newrank;
+ int comm_size, rank, pof2, rem, newrank;
int mask, *cnts, *disps, i, j, send_idx = 0;
int recv_idx, last_idx = 0, newdst;
int dst, send_cnt, recv_cnt, newroot, newdst_tree_root;
int newroot_tree_root, new_count;
- int tag = 4321;
+ int tag = COLL_TAG_REDUCE;
void *send_ptr, *recv_ptr, *tmp_buf;
cnts = NULL;
comm_size = smpi_comm_size(comm);
extent = smpi_datatype_get_extent(datatype);
- type_size = smpi_datatype_size(datatype);
/* find nearest power-of-two less than or equal to comm_size */
pof2 = 1;
send_ptr = (void *) xbt_malloc(new_count * extent);
recv_ptr = (void *) xbt_malloc(new_count * extent);
tmp_buf = (void *) xbt_malloc(new_count * extent);
- memcpy(send_ptr, sendbuf, extent * new_count);
+ memcpy(send_ptr, sendbuf, extent * count);
//if ((rank != root))
smpi_mpi_sendrecv(send_ptr, new_count, datatype, rank, tag,
newrank = -1;
} else {
smpi_mpi_recv(tmp_buf, count, datatype, rank + 1, tag, comm, &status);
- star_reduction(op, tmp_buf, recv_ptr, &new_count, &datatype);
+ smpi_op_apply(op, tmp_buf, recv_ptr, &new_count, &datatype);
newrank = rank / 2;
}
} else /* rank >= 2*rem */
/* tmp_buf contains data received in this step.
recvbuf contains data accumulated so far */
- star_reduction(op, (char *) tmp_buf + disps[recv_idx] * extent,
+ smpi_op_apply(op, (char *) tmp_buf + disps[recv_idx] * extent,
(char *) recv_ptr + disps[recv_idx] * extent,
&recv_cnt, &datatype);
}
- else if (count >= comm_size) {
+ else /* (count >= comm_size) */ {
tmp_buf = (void *) xbt_malloc(count * extent);
//if ((rank != root))
else {
smpi_mpi_recv(tmp_buf, count, datatype, rank + 1, tag, comm, &status);
- star_reduction(op, tmp_buf, recvbuf, &count, &datatype);
+ smpi_op_apply(op, tmp_buf, recvbuf, &count, &datatype);
newrank = rank / 2;
}
} else /* rank >= 2*rem */
/* tmp_buf contains data received in this step.
recvbuf contains data accumulated so far */
- star_reduction(op, (char *) tmp_buf + disps[recv_idx] * extent,
+ smpi_op_apply(op, (char *) tmp_buf + disps[recv_idx] * extent,
(char *) recvbuf + disps[recv_idx] * extent,
&recv_cnt, &datatype);
}
}
}
+ if (tmp_buf)
+ free(tmp_buf);
if (cnts)
free(cnts);
if (disps)