X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e7c0c67af63b3979a597a66e5e1c8b0435fc6e19..1687df79d61a9418bba830bbd0ab7de16e457090:/src/smpi/colls/reduce-scatter-gather.c diff --git a/src/smpi/colls/reduce-scatter-gather.c b/src/smpi/colls/reduce-scatter-gather.c index 4dbcbf1327..38db76025b 100644 --- a/src/smpi/colls/reduce-scatter-gather.c +++ b/src/smpi/colls/reduce-scatter-gather.c @@ -1,3 +1,9 @@ +/* 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" /* @@ -10,12 +16,12 @@ int smpi_coll_tuned_reduce_scatter_gather(void *sendbuf, void *recvbuf, 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,temporary_buffer=0; void *send_ptr, *recv_ptr, *tmp_buf; cnts = NULL; @@ -27,10 +33,16 @@ int smpi_coll_tuned_reduce_scatter_gather(void *sendbuf, void *recvbuf, return 0; rank = smpi_comm_rank(comm); comm_size = smpi_comm_size(comm); + - extent = smpi_datatype_get_extent(datatype); - type_size = smpi_datatype_size(datatype); + extent = smpi_datatype_get_extent(datatype); + /* If I'm not the root, then my recvbuf may not be valid, therefore + I have to allocate a temporary one */ + if (rank != root && !recvbuf) { + temporary_buffer=1; + recvbuf = (void *)smpi_get_tmp_recvbuffer(count * extent); + } /* find nearest power-of-two less than or equal to comm_size */ pof2 = 1; while (pof2 <= comm_size) @@ -39,10 +51,10 @@ int smpi_coll_tuned_reduce_scatter_gather(void *sendbuf, void *recvbuf, if (count < comm_size) { new_count = comm_size; - 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); + send_ptr = (void *) smpi_get_tmp_sendbuffer(new_count * extent); + recv_ptr = (void *) smpi_get_tmp_recvbuffer(new_count * extent); + tmp_buf = (void *) smpi_get_tmp_sendbuffer(new_count * extent); + memcpy(send_ptr, sendbuf != MPI_IN_PLACE ? sendbuf : recvbuf, extent * count); //if ((rank != root)) smpi_mpi_sendrecv(send_ptr, new_count, datatype, rank, tag, @@ -56,7 +68,7 @@ int smpi_coll_tuned_reduce_scatter_gather(void *sendbuf, void *recvbuf, 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 */ @@ -109,7 +121,7 @@ int smpi_coll_tuned_reduce_scatter_gather(void *sendbuf, void *recvbuf, /* 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); @@ -212,16 +224,16 @@ int smpi_coll_tuned_reduce_scatter_gather(void *sendbuf, void *recvbuf, } } memcpy(recvbuf, recv_ptr, extent * count); - free(send_ptr); - free(recv_ptr); + smpi_free_tmp_buffer(send_ptr); + smpi_free_tmp_buffer(recv_ptr); } - else if (count >= comm_size) { - tmp_buf = (void *) xbt_malloc(count * extent); + else /* (count >= comm_size) */ { + tmp_buf = (void *) smpi_get_tmp_sendbuffer(count * extent); //if ((rank != root)) - smpi_mpi_sendrecv(sendbuf, count, datatype, rank, tag, + smpi_mpi_sendrecv(sendbuf != MPI_IN_PLACE ? sendbuf : recvbuf, count, datatype, rank, tag, recvbuf, count, datatype, rank, tag, comm, &status); rem = comm_size - pof2; @@ -233,7 +245,7 @@ int smpi_coll_tuned_reduce_scatter_gather(void *sendbuf, void *recvbuf, 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 */ @@ -286,7 +298,7 @@ int smpi_coll_tuned_reduce_scatter_gather(void *sendbuf, void *recvbuf, /* 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); @@ -388,6 +400,9 @@ int smpi_coll_tuned_reduce_scatter_gather(void *sendbuf, void *recvbuf, } } } + if (tmp_buf) + smpi_free_tmp_buffer(tmp_buf); + if(temporary_buffer==1) smpi_free_tmp_buffer(recvbuf); if (cnts) free(cnts); if (disps)