MPI_Aint s_extent;
int i, rank, nprocs;
int nbytes, send_size, s_offset, r_offset;
- void *recv, *send, *tmp;
/*
#ifdef MPICH2_REDUCTION
MPI_User_function * uop = MPIR_Op_table[op % 16 - 1];
send_size = (count + nprocs) / nprocs;
nbytes = send_size * s_extent;
- send = (void *) smpi_get_tmp_sendbuffer(s_extent * send_size * nprocs);
- recv = (void *) smpi_get_tmp_recvbuffer(s_extent * send_size * nprocs);
- tmp = (void *) smpi_get_tmp_sendbuffer(nbytes);
+ void* send = smpi_get_tmp_sendbuffer(s_extent * send_size * nprocs);
+ void* recv = smpi_get_tmp_recvbuffer(s_extent * send_size * nprocs);
+ void* tmp = smpi_get_tmp_sendbuffer(nbytes);
memcpy(send, sbuff, s_extent * count);
smpi_free_tmp_buffer(tmp);
smpi_free_tmp_buffer(send);
} else {
- send = const_cast<void*>(sbuff);
+ const void* send = sbuff;
send_size = count / nprocs;
nbytes = send_size * s_extent;
r_offset = rank * nbytes;
- recv = (void *) smpi_get_tmp_recvbuffer(s_extent * send_size * nprocs);
+ void* recv = smpi_get_tmp_recvbuffer(s_extent * send_size * nprocs);
Colls::alltoall(send, send_size, dtype, recv, send_size, dtype, comm);
first_segment_count = scount;
COLL_TUNED_COMPUTED_SEGCOUNT((size_t)first_segment_size, typelng, first_segment_count);
- Request::recv(const_cast<void*>(sbuf), 0, MPI_BYTE, root, COLL_TAG_GATHER, comm, MPI_STATUS_IGNORE);
+ Request::recv(nullptr, 0, MPI_BYTE, root, COLL_TAG_GATHER, comm, MPI_STATUS_IGNORE);
Request::send(sbuf, first_segment_count, sdtype, root, COLL_TAG_GATHER, comm);
int ret;
int rank, size, io_root;
int segcount = count;
- void *use_this_sendbuf = NULL, *use_this_recvbuf = NULL;
size_t typelng;
rank = comm->rank();
operations for non-commutative ops.
*/
io_root = size - 1;
- use_this_sendbuf = const_cast<void*>(sendbuf);
- use_this_recvbuf = recvbuf;
+ const void* use_this_sendbuf = sendbuf;
+ void* use_this_recvbuf = recvbuf;
+ void* tmp_sendbuf = nullptr;
+ void* tmp_recvbuf = nullptr;
if (io_root != root) {
ptrdiff_t text, ext;
- char *tmpbuf = NULL;
ext=datatype->get_extent();
text=datatype->get_extent();
if ((root == rank) && (MPI_IN_PLACE == sendbuf)) {
- tmpbuf = (char *) smpi_get_tmp_sendbuffer(text + (count - 1) * ext);
- if (NULL == tmpbuf) {
- return MPI_ERR_INTERN;
- }
- Datatype::copy (
- (char*)recvbuf, count, datatype,
- (char*)tmpbuf, count, datatype);
- use_this_sendbuf = tmpbuf;
+ tmp_sendbuf = smpi_get_tmp_sendbuffer(text + (count - 1) * ext);
+ if (NULL == tmp_sendbuf) {
+ return MPI_ERR_INTERN;
+ }
+ Datatype::copy(recvbuf, count, datatype, tmp_sendbuf, count, datatype);
+ use_this_sendbuf = tmp_sendbuf;
} else if (io_root == rank) {
- tmpbuf = (char *) smpi_get_tmp_recvbuffer(text + (count - 1) * ext);
- if (NULL == tmpbuf) {
- return MPI_ERR_INTERN;
- }
- use_this_recvbuf = tmpbuf;
+ tmp_recvbuf = smpi_get_tmp_recvbuffer(text + (count - 1) * ext);
+ if (NULL == tmp_recvbuf) {
+ return MPI_ERR_INTERN;
+ }
+ use_this_recvbuf = tmp_recvbuf;
}
}
COLL_TAG_REDUCE, comm,
MPI_STATUS_IGNORE);
if (MPI_IN_PLACE == sendbuf) {
- smpi_free_tmp_buffer(use_this_sendbuf);
+ smpi_free_tmp_buffer(tmp_sendbuf);
}
} else if (io_root == rank) {
Request::send(use_this_recvbuf, count, datatype, root,
COLL_TAG_REDUCE,
comm);
- smpi_free_tmp_buffer(use_this_recvbuf);
+ smpi_free_tmp_buffer(tmp_recvbuf);
}
}
int root, MPI_Comm comm
)
{
+ std::unique_ptr<unsigned char[]> tmp_buf;
if(comm->rank()!=root){
- sbuf=xbt_malloc(rcount*rdtype->get_extent());
- scount=rcount;
- sdtype=rdtype;
+ tmp_buf.reset(new unsigned char[rcount * rdtype->get_extent()]);
+ sbuf = tmp_buf.get();
+ scount = rcount;
+ sdtype = rdtype;
}
- int ret= Coll_scatter_ompi_binomial::scatter (sbuf, scount, sdtype,
- rbuf, rcount, rdtype,
- root, comm);
- if(comm->rank()!=root){
- xbt_free(const_cast<void*>(sbuf));
- }
- return ret;
+ return Coll_scatter_ompi_binomial::scatter(sbuf, scount, sdtype, rbuf, rcount, rdtype, root, comm);
}
}
}
MPI_Aint lb = 0;
MPI_Aint dataext = 0;
- void* sendtmpbuf = const_cast<void *>(sendbuf);
+ const void* real_sendbuf = sendbuf;
int rank = comm->rank();
int size = comm->size();
if (size <= 0)
return MPI_ERR_COMM;
+ void* tmp_sendbuf = nullptr;
if( sendbuf == MPI_IN_PLACE ) {
- sendtmpbuf = static_cast<void *>(smpi_get_tmp_sendbuffer(count*datatype->get_extent()));
- Datatype::copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
+ tmp_sendbuf = smpi_get_tmp_sendbuffer(count * datatype->get_extent());
+ Datatype::copy(recvbuf, count, datatype, tmp_sendbuf, count, datatype);
+ real_sendbuf = tmp_sendbuf;
}
if(rank == root){
if(rank != root) {
// Send buffer to root
MPI_Request* requests = new MPI_Request[1];
- requests[0]=Request::isend(sendtmpbuf, count, datatype, root, system_tag, comm);
+ requests[0] = Request::isend(real_sendbuf, count, datatype, root, system_tag, comm);
(*request)->set_nbc_requests(requests, 1);
} else {
datatype->extent(&lb, &dataext);
// Local copy from root
- if (sendtmpbuf != nullptr && recvbuf != nullptr)
- Datatype::copy(sendtmpbuf, count, datatype, recvbuf, count, datatype);
+ if (real_sendbuf != nullptr && recvbuf != nullptr)
+ Datatype::copy(real_sendbuf, count, datatype, recvbuf, count, datatype);
// Receive buffers from senders
MPI_Request *requests = new MPI_Request[size - 1];
int index = 0;
(*request)->set_nbc_requests(requests, size - 1);
}
if( sendbuf == MPI_IN_PLACE ) {
- smpi_free_tmp_buffer(sendtmpbuf);
+ smpi_free_tmp_buffer(tmp_sendbuf);
}
return MPI_SUCCESS;
}
if ((communicator_size > small_comm_size) &&
(block_size < small_block_size)) {
- if(rank!=root){
- sbuf=xbt_malloc(rcount*rdtype->get_extent());
- scount=rcount;
- sdtype=rdtype;
- }
- int ret=Coll_scatter_ompi_binomial::scatter (sbuf, scount, sdtype,
- rbuf, rcount, rdtype,
- root, comm);
- if(rank!=root){
- xbt_free(const_cast<void*>(sbuf));
- }
- return ret;
+ std::unique_ptr<unsigned char[]> tmp_buf;
+ if (rank != root) {
+ tmp_buf.reset(new unsigned char[rcount * rdtype->get_extent()]);
+ sbuf = tmp_buf.get();
+ scount = rcount;
+ sdtype = rdtype;
+ }
+ return Coll_scatter_ompi_binomial::scatter(sbuf, scount, sdtype, rbuf, rcount, rdtype, root, comm);
}
return Coll_scatter_ompi_basic_linear::scatter (sbuf, scount, sdtype,
rbuf, rcount, rdtype,