X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b7ed19dfcc221d7b3eca182abb5c4a3946671172..5089a0a98b27f5eeee62321dff4f025f1648f025:/src/smpi/colls/reduce/reduce-scatter-gather.cpp diff --git a/src/smpi/colls/reduce/reduce-scatter-gather.cpp b/src/smpi/colls/reduce/reduce-scatter-gather.cpp index b8ac14235c..fa74378474 100644 --- a/src/smpi/colls/reduce/reduce-scatter-gather.cpp +++ b/src/smpi/colls/reduce/reduce-scatter-gather.cpp @@ -1,19 +1,20 @@ -/* Copyright (c) 2013-2014. The SimGrid Team. +/* Copyright (c) 2013-2019. 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 "../colls_private.hpp" /* reduce Author: MPICH */ - -int Coll_reduce_scatter_gather::reduce(void *sendbuf, void *recvbuf, - int count, MPI_Datatype datatype, - MPI_Op op, int root, MPI_Comm comm) +namespace simgrid{ +namespace smpi{ +int reduce__scatter_gather(const void *sendbuf, void *recvbuf, + int count, MPI_Datatype datatype, + MPI_Op op, int root, MPI_Comm comm) { MPI_Status status; int comm_size, rank, pof2, rem, newrank; @@ -22,7 +23,7 @@ int Coll_reduce_scatter_gather::reduce(void *sendbuf, void *recvbuf, int dst, send_cnt, recv_cnt, newroot, newdst_tree_root; int newroot_tree_root, new_count; int tag = COLL_TAG_REDUCE,temporary_buffer=0; - void *send_ptr, *recv_ptr, *tmp_buf; + unsigned char *send_ptr, *recv_ptr, *tmp_buf; cnts = NULL; disps = NULL; @@ -33,13 +34,13 @@ int Coll_reduce_scatter_gather::reduce(void *sendbuf, void *recvbuf, return 0; rank = comm->rank(); comm_size = comm->size(); - + extent = datatype->get_extent(); /* 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) { + if (rank != root && not recvbuf) { temporary_buffer=1; recvbuf = (void *)smpi_get_tmp_recvbuffer(count * extent); } @@ -51,9 +52,9 @@ int Coll_reduce_scatter_gather::reduce(void *sendbuf, void *recvbuf, if (count < comm_size) { new_count = comm_size; - 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); + send_ptr = smpi_get_tmp_sendbuffer(new_count * extent); + recv_ptr = smpi_get_tmp_recvbuffer(new_count * extent); + tmp_buf = smpi_get_tmp_sendbuffer(new_count * extent); memcpy(send_ptr, sendbuf != MPI_IN_PLACE ? sendbuf : recvbuf, extent * count); //if ((rank != root)) @@ -74,8 +75,8 @@ int Coll_reduce_scatter_gather::reduce(void *sendbuf, void *recvbuf, } else /* rank >= 2*rem */ newrank = rank - rem; - cnts = (int *) xbt_malloc(pof2 * sizeof(int)); - disps = (int *) xbt_malloc(pof2 * sizeof(int)); + cnts = new int[pof2]; + disps = new int[pof2]; if (newrank != -1) { for (i = 0; i < (pof2 - 1); i++) @@ -110,20 +111,14 @@ int Coll_reduce_scatter_gather::reduce(void *sendbuf, void *recvbuf, } /* Send data from recvbuf. Recv into tmp_buf */ - Request::sendrecv((char *) recv_ptr + - disps[send_idx] * extent, - send_cnt, datatype, - dst, tag, - (char *) tmp_buf + - disps[recv_idx] * extent, - recv_cnt, datatype, dst, tag, comm, &status); + Request::sendrecv(recv_ptr + disps[send_idx] * extent, send_cnt, datatype, dst, tag, + tmp_buf + disps[recv_idx] * extent, recv_cnt, datatype, dst, tag, comm, &status); /* tmp_buf contains data received in this step. recvbuf contains data accumulated so far */ - if(op!=MPI_OP_NULL) op->apply( (char *) tmp_buf + disps[recv_idx] * extent, - (char *) recv_ptr + disps[recv_idx] * extent, - &recv_cnt, datatype); + if (op != MPI_OP_NULL) + op->apply(tmp_buf + disps[recv_idx] * extent, recv_ptr + disps[recv_idx] * extent, &recv_cnt, datatype); /* update send_idx for next iteration */ send_idx = recv_idx; @@ -206,14 +201,10 @@ int Coll_reduce_scatter_gather::reduce(void *sendbuf, void *recvbuf, } if (newdst_tree_root == newroot_tree_root) { - Request::send((char *) recv_ptr + - disps[send_idx] * extent, - send_cnt, datatype, dst, tag, comm); + Request::send(recv_ptr + disps[send_idx] * extent, send_cnt, datatype, dst, tag, comm); break; } else { - Request::recv((char *) recv_ptr + - disps[recv_idx] * extent, - recv_cnt, datatype, dst, tag, comm, &status); + Request::recv(recv_ptr + disps[recv_idx] * extent, recv_cnt, datatype, dst, tag, comm, &status); } if (newrank > newdst) @@ -230,7 +221,7 @@ int Coll_reduce_scatter_gather::reduce(void *sendbuf, void *recvbuf, else /* (count >= comm_size) */ { - tmp_buf = (void *) smpi_get_tmp_sendbuffer(count * extent); + tmp_buf = smpi_get_tmp_sendbuffer(count * extent); //if ((rank != root)) Request::sendrecv(sendbuf != MPI_IN_PLACE ? sendbuf : recvbuf, count, datatype, rank, tag, @@ -251,8 +242,8 @@ int Coll_reduce_scatter_gather::reduce(void *sendbuf, void *recvbuf, } else /* rank >= 2*rem */ newrank = rank - rem; - cnts = (int *) xbt_malloc(pof2 * sizeof(int)); - disps = (int *) xbt_malloc(pof2 * sizeof(int)); + cnts = new int[pof2]; + disps = new int[pof2]; if (newrank != -1) { for (i = 0; i < (pof2 - 1); i++) @@ -287,20 +278,15 @@ int Coll_reduce_scatter_gather::reduce(void *sendbuf, void *recvbuf, } /* Send data from recvbuf. Recv into tmp_buf */ - Request::sendrecv((char *) recvbuf + - disps[send_idx] * extent, - send_cnt, datatype, - dst, tag, - (char *) tmp_buf + - disps[recv_idx] * extent, - recv_cnt, datatype, dst, tag, comm, &status); + Request::sendrecv(static_cast(recvbuf) + disps[send_idx] * extent, send_cnt, datatype, dst, tag, + tmp_buf + disps[recv_idx] * extent, recv_cnt, datatype, dst, tag, comm, &status); /* tmp_buf contains data received in this step. recvbuf contains data accumulated so far */ - if(op!=MPI_OP_NULL) op->apply( (char *) tmp_buf + disps[recv_idx] * extent, - (char *) recvbuf + disps[recv_idx] * extent, - &recv_cnt, datatype); + if (op != MPI_OP_NULL) + op->apply(tmp_buf + disps[recv_idx] * extent, static_cast(recvbuf) + disps[recv_idx] * extent, + &recv_cnt, datatype); /* update send_idx for next iteration */ send_idx = recv_idx; @@ -402,11 +388,12 @@ int Coll_reduce_scatter_gather::reduce(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) - free(disps); + if (temporary_buffer == 1) + smpi_free_tmp_buffer(static_cast(recvbuf)); + delete[] cnts; + delete[] disps; return 0; } +} +}