namespace simgrid{
namespace smpi{
-int Coll_scatter_ompi_binomial::scatter(void* sbuf, int scount, MPI_Datatype sdtype, void* rbuf, int rcount,
+int Coll_scatter_ompi_binomial::scatter(const void* sbuf, int scount, MPI_Datatype sdtype, void* rbuf, int rcount,
MPI_Datatype rdtype, int root, MPI_Comm comm)
{
int line = -1;
int vrank;
int size;
int total_send = 0;
- char *ptmp = NULL;
- char *tempbuf = NULL;
+ unsigned char* ptmp = nullptr;
+ unsigned char* tempbuf = nullptr;
+ const unsigned char* cptmp; // const ptmp
int err;
ompi_coll_tree_t* bmtree;
MPI_Status status;
if (rank == root) {
if (0 == root) {
/* root on 0, just use the send buffer */
- ptmp = (char*)sbuf;
+ ptmp = nullptr; // unused
+ cptmp = static_cast<const unsigned char*>(sbuf);
if (rbuf != MPI_IN_PLACE) {
/* local copy to rbuf */
err = Datatype::copy(sbuf, scount, sdtype, rbuf, rcount, rdtype);
}
} else {
/* root is not on 0, allocate temp buffer for send */
- tempbuf = (char*)smpi_get_tmp_sendbuffer(strue_extent + (scount * size - 1) * sextent);
- if (NULL == tempbuf) {
+ tempbuf = smpi_get_tmp_sendbuffer(strue_extent + (scount * size - 1) * sextent);
+ if (nullptr == tempbuf) {
err = MPI_ERR_OTHER;
line = __LINE__;
goto err_hndl;
}
- ptmp = tempbuf - slb;
+ ptmp = tempbuf - slb;
+ cptmp = ptmp;
/* and rotate data so they will eventually in the right place */
err = Datatype::copy((char*)sbuf + sextent * root * scount, scount * (size - root), sdtype, ptmp,
} else if (not(vrank % 2)) {
/* non-root, non-leaf nodes, allocate temp buffer for recv
* the most we need is rcount*size/2 */
- tempbuf = (char*)smpi_get_tmp_recvbuffer(rtrue_extent + (rcount * size - 1) * rextent);
- if (NULL == tempbuf) {
+ tempbuf = smpi_get_tmp_recvbuffer(rtrue_extent + (rcount * size - 1) * rextent);
+ if (nullptr == tempbuf) {
err = MPI_ERR_OTHER;
line = __LINE__;
goto err_hndl;
}
- ptmp = tempbuf - rlb;
+ ptmp = tempbuf - rlb;
+ cptmp = ptmp;
sdtype = rdtype;
scount = rcount;
total_send = scount;
} else {
/* leaf nodes, just use rbuf */
- ptmp = (char*)rbuf;
+ ptmp = static_cast<unsigned char*>(rbuf);
+ cptmp = ptmp;
}
if (not(vrank % 2)) {
mycount = size - vkid;
mycount *= scount;
- Request::send(ptmp + total_send * sextent, mycount, sdtype, bmtree->tree_next[i], COLL_TAG_SCATTER, comm);
+ Request::send(cptmp + total_send * sextent, mycount, sdtype, bmtree->tree_next[i], COLL_TAG_SCATTER, comm);
total_send += mycount;
}
Request::recv(ptmp, rcount, rdtype, bmtree->tree_prev, COLL_TAG_SCATTER, comm, &status);
}
- if (NULL != tempbuf)
- smpi_free_tmp_buffer(tempbuf);
+ smpi_free_tmp_buffer(tempbuf);
// not FIXME : store the tree, as done in ompi, instead of calculating it each time ?
ompi_coll_tuned_topo_destroy_tree(&bmtree);
return MPI_SUCCESS;
err_hndl:
- if (NULL != tempbuf)
- free(tempbuf);
+ smpi_free_tmp_buffer(tempbuf);
XBT_DEBUG("%s:%4d\tError occurred %d, rank %2d", __FILE__, line, err, rank);
return err;
* Accepts: - same arguments as MPI_Scatter()
* Returns: - MPI_SUCCESS or error code
*/
-int Coll_scatter_ompi_basic_linear::scatter(void* sbuf, int scount, MPI_Datatype sdtype, void* rbuf, int rcount,
+int Coll_scatter_ompi_basic_linear::scatter(const void* sbuf, int scount, MPI_Datatype sdtype, void* rbuf, int rcount,
MPI_Datatype rdtype, int root, MPI_Comm comm)
{
int i, rank, size, err;