X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/1b4e20873a7bd405842f3d8d1e6dd1d518db5535..25dd0abaeebc08a4441684ff533c1668bd7e976d:/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 af317fb967..57161ff817 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" /* @@ -27,9 +33,15 @@ 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); + 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) { + 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) @@ -38,9 +50,9 @@ 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); + 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, extent * count); //if ((rank != root)) @@ -211,13 +223,13 @@ 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 /* (count >= comm_size) */ { - tmp_buf = (void *) xbt_malloc(count * extent); + tmp_buf = (void *) smpi_get_tmp_sendbuffer(count * extent); //if ((rank != root)) smpi_mpi_sendrecv(sendbuf, count, datatype, rank, tag, @@ -388,7 +400,7 @@ int smpi_coll_tuned_reduce_scatter_gather(void *sendbuf, void *recvbuf, } } if (tmp_buf) - free(tmp_buf); + smpi_free_tmp_buffer(tmp_buf); if (cnts) free(cnts); if (disps)