From d5cc61332edae35867a41bb38ad9401faaab2716 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Mon, 18 Mar 2019 16:10:01 +0100 Subject: [PATCH] Change malloc/free to new/delete. --- src/smpi/colls/allgather/allgather-2dmesh.cpp | 8 +- src/smpi/colls/allgather/allgather-3dmesh.cpp | 8 +- .../colls/allgather/allgather-NTSLR-NB.cpp | 10 +-- .../colls/allgather/allgather-SMP-NTS.cpp | 8 +- .../colls/allgather/allgather-mvapich-smp.cpp | 13 +-- .../colls/allgather/allgather-smp-simple.cpp | 13 ++- .../allgather/allgather-spreading-simple.cpp | 13 +-- .../colls/allreduce/allreduce-mvapich-rs.cpp | 11 ++- .../colls/allreduce/allreduce-rab-rdb.cpp | 12 ++- src/smpi/colls/alltoall/alltoall-2dmesh.cpp | 14 ++-- src/smpi/colls/alltoall/alltoall-3dmesh.cpp | 14 ++-- .../colls/alltoall/alltoall-basic-linear.cpp | 5 +- src/smpi/colls/alltoall/alltoall-bruck.cpp | 9 +-- .../alltoall-mvapich-scatter-dest.cpp | 10 +-- src/smpi/colls/alltoallv/alltoallv-bruck.cpp | 80 +++++++++---------- .../alltoallv/alltoallv-ompi-basic-linear.cpp | 4 +- src/smpi/colls/bcast/bcast-NTSB.cpp | 27 ++----- src/smpi/colls/bcast/bcast-NTSL-Isend.cpp | 24 ++---- src/smpi/colls/bcast/bcast-NTSL.cpp | 24 ++---- src/smpi/colls/bcast/bcast-SMP-binary.cpp | 12 +-- src/smpi/colls/bcast/bcast-SMP-linear.cpp | 12 +-- .../bcast-arrival-pattern-aware-wait.cpp | 25 ++---- .../bcast/bcast-arrival-pattern-aware.cpp | 24 ++---- .../colls/bcast/bcast-flattree-pipeline.cpp | 11 +-- src/smpi/colls/bcast/bcast-flattree.cpp | 9 +-- src/smpi/colls/bcast/bcast-mvapich-smp.cpp | 11 +-- .../bcast/bcast-scatter-LR-allgather.cpp | 11 ++- .../bcast/bcast-scatter-rdb-allgather.cpp | 22 ++--- src/smpi/colls/gather/gather-mvapich.cpp | 12 +-- src/smpi/colls/reduce/reduce-NTSL.cpp | 24 ++---- .../reduce/reduce-arrival-pattern-aware.cpp | 27 ++----- .../colls/reduce/reduce-mvapich-knomial.cpp | 17 ++-- .../colls/reduce/reduce-scatter-gather.cpp | 14 ++-- .../reduce_scatter/reduce_scatter-mpich.cpp | 14 ++-- .../reduce_scatter/reduce_scatter-ompi.cpp | 59 ++++++-------- .../scatter/scatter-mvapich-two-level.cpp | 24 +++--- src/smpi/colls/smpi_coll.cpp | 16 ++-- src/smpi/colls/smpi_default_selector.cpp | 4 +- 38 files changed, 257 insertions(+), 398 deletions(-) diff --git a/src/smpi/colls/allgather/allgather-2dmesh.cpp b/src/smpi/colls/allgather/allgather-2dmesh.cpp index 02bd09be0b..0cfecd05d7 100644 --- a/src/smpi/colls/allgather/allgather-2dmesh.cpp +++ b/src/smpi/colls/allgather/allgather-2dmesh.cpp @@ -115,7 +115,6 @@ Coll_allgather_2dmesh::allgather(const void *send_buff, int send_count, MPI_Data send_type, void *recv_buff, int recv_count, MPI_Datatype recv_type, MPI_Comm comm) { - MPI_Request *req, *req_ptr; MPI_Aint extent; int i, src, dst, rank, num_procs; @@ -140,9 +139,8 @@ Coll_allgather_2dmesh::allgather(const void *send_buff, int send_count, MPI_Data if (Y > X) num_reqs = Y; - req = (MPI_Request *) xbt_malloc(num_reqs * sizeof(MPI_Request)); - - req_ptr = req; + MPI_Request* req = new MPI_Request[num_reqs]; + MPI_Request* req_ptr = req; // do local allgather/local copy recv_offset = rank * block_size; @@ -193,7 +191,7 @@ Coll_allgather_2dmesh::allgather(const void *send_buff, int send_count, MPI_Data Request::waitall(X - 1, req, MPI_STATUSES_IGNORE); - free(req); + delete[] req; return MPI_SUCCESS; } diff --git a/src/smpi/colls/allgather/allgather-3dmesh.cpp b/src/smpi/colls/allgather/allgather-3dmesh.cpp index 38ef2b05ea..8d99c071a8 100644 --- a/src/smpi/colls/allgather/allgather-3dmesh.cpp +++ b/src/smpi/colls/allgather/allgather-3dmesh.cpp @@ -101,7 +101,6 @@ int Coll_allgather_3dmesh::allgather(const void *send_buff, int send_count, int recv_count, MPI_Datatype recv_type, MPI_Comm comm) { - MPI_Request *req, *req_ptr; MPI_Aint extent; int i, src, dst, rank, num_procs, block_size, my_z_base; @@ -133,9 +132,8 @@ int Coll_allgather_3dmesh::allgather(const void *send_buff, int send_count, block_size = extent * send_count; - req = (MPI_Request *) xbt_malloc(num_reqs * sizeof(MPI_Request)); - - req_ptr = req; + MPI_Request* req = new MPI_Request[num_reqs]; + MPI_Request* req_ptr = req; // do local allgather/local copy recv_offset = rank * block_size; @@ -206,7 +204,7 @@ int Coll_allgather_3dmesh::allgather(const void *send_buff, int send_count, } Request::waitall(Z - 1, req, MPI_STATUSES_IGNORE); - free(req); + delete[] req; return MPI_SUCCESS; } diff --git a/src/smpi/colls/allgather/allgather-NTSLR-NB.cpp b/src/smpi/colls/allgather/allgather-NTSLR-NB.cpp index 608e02658b..f05db0c18a 100644 --- a/src/smpi/colls/allgather/allgather-NTSLR-NB.cpp +++ b/src/smpi/colls/allgather/allgather-NTSLR-NB.cpp @@ -26,10 +26,8 @@ Coll_allgather_NTSLR_NB::allgather(const void *sbuf, int scount, MPI_Datatype st size = comm->size(); rextent = rtype->get_extent(); sextent = stype->get_extent(); - MPI_Request *rrequest_array; - MPI_Request *srequest_array; - rrequest_array = (MPI_Request *) xbt_malloc(size * sizeof(MPI_Request)); - srequest_array = (MPI_Request *) xbt_malloc(size * sizeof(MPI_Request)); + MPI_Request* rrequest_array = new MPI_Request[size]; + MPI_Request* srequest_array = new MPI_Request[size]; // irregular case use default MPI fucntions if (scount * sextent != rcount * rextent) { @@ -66,8 +64,8 @@ Coll_allgather_NTSLR_NB::allgather(const void *sbuf, int scount, MPI_Datatype st Request::wait(&srequest_array[i], &status2); } - free(rrequest_array); - free(srequest_array); + delete[] rrequest_array; + delete[] srequest_array; return MPI_SUCCESS; } diff --git a/src/smpi/colls/allgather/allgather-SMP-NTS.cpp b/src/smpi/colls/allgather/allgather-SMP-NTS.cpp index 9e5986b6e9..0e4e3dba1c 100644 --- a/src/smpi/colls/allgather/allgather-SMP-NTS.cpp +++ b/src/smpi/colls/allgather/allgather-SMP-NTS.cpp @@ -84,8 +84,8 @@ int Coll_allgather_SMP_NTS::allgather(const void *sbuf, int scount, // root of each SMP if (intra_rank == 0) { - MPI_Request *rrequest_array = xbt_new(MPI_Request, inter_comm_size - 1); - MPI_Request *srequest_array = xbt_new(MPI_Request, inter_comm_size - 1); + MPI_Request* rrequest_array = new MPI_Request[inter_comm_size - 1]; + MPI_Request* srequest_array = new MPI_Request[inter_comm_size - 1]; src = ((inter_rank - 1 + inter_comm_size) % inter_comm_size) * num_core; dst = ((inter_rank + 1) % inter_comm_size) * num_core; @@ -133,8 +133,8 @@ int Coll_allgather_SMP_NTS::allgather(const void *sbuf, int scount, } Request::waitall(inter_comm_size - 1, srequest_array, MPI_STATUSES_IGNORE); - xbt_free(rrequest_array); - xbt_free(srequest_array); + delete[] rrequest_array; + delete[] srequest_array; } // last rank of each SMP else if (intra_rank == (num_core_in_current_smp - 1)) { diff --git a/src/smpi/colls/allgather/allgather-mvapich-smp.cpp b/src/smpi/colls/allgather/allgather-mvapich-smp.cpp index 1a624ebf7e..993efeafe6 100644 --- a/src/smpi/colls/allgather/allgather-mvapich-smp.cpp +++ b/src/smpi/colls/allgather/allgather-mvapich-smp.cpp @@ -105,18 +105,13 @@ int Coll_allgather_mvapich2_smp::allgather(const void *sendbuf,int sendcnt, MPI_ /*When data in each socket is different*/ if (comm->is_uniform() != 1) { - int *displs = NULL; - int *recvcnts = NULL; int *node_sizes = NULL; int i = 0; node_sizes = comm->get_non_uniform_map(); - displs = static_cast(xbt_malloc(sizeof (int) * leader_comm_size)); - recvcnts = static_cast(xbt_malloc(sizeof (int) * leader_comm_size)); - if (not displs || not recvcnts) { - return MPI_ERR_OTHER; - } + int* displs = new int[leader_comm_size]; + int* recvcnts = new int[leader_comm_size]; recvcnts[0] = node_sizes[0] * recvcnt; displs[0] = 0; @@ -134,8 +129,8 @@ int Coll_allgather_mvapich2_smp::allgather(const void *sendbuf,int sendcnt, MPI_ recvbuf, recvcnts, displs, recvtype, leader_comm); - xbt_free(displs); - xbt_free(recvcnts); + delete[] displs; + delete[] recvcnts; } else { void* sendtmpbuf=((char*)recvbuf)+recvtype->get_extent()*(recvcnt*local_size)*leader_comm->rank(); diff --git a/src/smpi/colls/allgather/allgather-smp-simple.cpp b/src/smpi/colls/allgather/allgather-smp-simple.cpp index 06bf8d8f46..dcaaecd19e 100644 --- a/src/smpi/colls/allgather/allgather-smp-simple.cpp +++ b/src/smpi/colls/allgather/allgather-smp-simple.cpp @@ -73,12 +73,10 @@ int Coll_allgather_smp_simple::allgather(const void *send_buf, int scount, if (intra_rank == 0) { - MPI_Request *reqs, *req_ptr; int num_req = (inter_comm_size - 1) * 2; - reqs = (MPI_Request *) xbt_malloc(num_req * sizeof(MPI_Request)); - req_ptr = reqs; - MPI_Status *stat; - stat = (MPI_Status *) xbt_malloc(num_req * sizeof(MPI_Status)); + MPI_Request* reqs = new MPI_Request[num_req]; + MPI_Request* req_ptr = reqs; + MPI_Status* stat = new MPI_Status[num_req]; for (i = 1; i < inter_comm_size; i++) { @@ -105,9 +103,8 @@ int Coll_allgather_smp_simple::allgather(const void *send_buf, int scount, //MPIC_Irecv((recv_buf+recv_offset), (rcount * num_core), rtype, src, tag, comm, req_ptr++); } Request::waitall(num_req, reqs, stat); - free(reqs); - free(stat); - + delete[] reqs; + delete[] stat; } //INTRA-BCAST (use flat tree) diff --git a/src/smpi/colls/allgather/allgather-spreading-simple.cpp b/src/smpi/colls/allgather/allgather-spreading-simple.cpp index af20e8f6b0..a1f55ca2f6 100644 --- a/src/smpi/colls/allgather/allgather-spreading-simple.cpp +++ b/src/smpi/colls/allgather/allgather-spreading-simple.cpp @@ -78,7 +78,6 @@ Coll_allgather_spreading_simple::allgather(const void *send_buff, int send_count MPI_Datatype recv_type, MPI_Comm comm) { - MPI_Request *reqs, *req_ptr; MPI_Aint extent; int i, src, dst, rank, num_procs, num_reqs; int tag = COLL_TAG_ALLGATHER; @@ -90,14 +89,8 @@ Coll_allgather_spreading_simple::allgather(const void *send_buff, int send_count extent = send_type->get_extent(); num_reqs = (2 * num_procs) - 2; - reqs = (MPI_Request *) xbt_malloc(num_reqs * sizeof(MPI_Request)); - if (not reqs) { - printf("allgather-spreading-simple.c:40: cannot allocate memory\n"); - MPI_Finalize(); - exit(0); - } - - req_ptr = reqs; + MPI_Request* reqs = new MPI_Request[num_reqs]; + MPI_Request* req_ptr = reqs; Request::sendrecv(send_buff, send_count, send_type, rank, tag, (char *) recv_buff + rank * recv_count * extent, recv_count, recv_type, rank, tag, comm, &status); @@ -118,7 +111,7 @@ Coll_allgather_spreading_simple::allgather(const void *send_buff, int send_count } Request::waitall(num_reqs, reqs, MPI_STATUSES_IGNORE); - free(reqs); + delete[] reqs; return MPI_SUCCESS; } diff --git a/src/smpi/colls/allreduce/allreduce-mvapich-rs.cpp b/src/smpi/colls/allreduce/allreduce-mvapich-rs.cpp index d5102b1ff5..1a74de8434 100644 --- a/src/smpi/colls/allreduce/allreduce-mvapich-rs.cpp +++ b/src/smpi/colls/allreduce/allreduce-mvapich-rs.cpp @@ -35,8 +35,7 @@ int Coll_allreduce_mvapich2_rs::allreduce(const void *sendbuf, int mpi_errno = MPI_SUCCESS; int newrank = 0; int mask, pof2, i, send_idx, recv_idx, last_idx, send_cnt; - int dst, is_commutative, rem, newdst, - recv_cnt, *cnts, *disps; + int dst, is_commutative, rem, newdst, recv_cnt; MPI_Aint true_lb, true_extent, extent; void *tmp_buf, *tmp_buf_free; @@ -152,8 +151,8 @@ int Coll_allreduce_mvapich2_rs::allreduce(const void *sendbuf, /* for the reduce-scatter, calculate the count that each process receives and the displacement within the buffer */ - cnts = (int *)xbt_malloc(pof2 * sizeof (int)); - disps = (int *)xbt_malloc(pof2 * sizeof (int)); + int* cnts = new int[pof2]; + int* disps = new int[pof2]; for (i = 0; i < (pof2 - 1); i++) { cnts[i] = count / pof2; @@ -267,8 +266,8 @@ int Coll_allreduce_mvapich2_rs::allreduce(const void *sendbuf, mask >>= 1; } - xbt_free(disps); - xbt_free(cnts); + delete[] disps; + delete[] cnts; } } diff --git a/src/smpi/colls/allreduce/allreduce-rab-rdb.cpp b/src/smpi/colls/allreduce/allreduce-rab-rdb.cpp index 4c9f338d98..90a44d2680 100644 --- a/src/smpi/colls/allreduce/allreduce-rab-rdb.cpp +++ b/src/smpi/colls/allreduce/allreduce-rab-rdb.cpp @@ -13,8 +13,7 @@ int Coll_allreduce_rab_rdb::allreduce(const void *sbuff, void *rbuff, int count, { int tag = COLL_TAG_ALLREDUCE; unsigned int mask, pof2, i, recv_idx, last_idx, send_idx, send_cnt; - int dst, newrank, rem, newdst, - recv_cnt, *cnts, *disps; + int dst, newrank, rem, newdst, recv_cnt; MPI_Aint extent; MPI_Status status; void *tmp_buf = NULL; @@ -81,8 +80,8 @@ int Coll_allreduce_rab_rdb::allreduce(const void *sbuff, void *rbuff, int count, // reduce-scatter, calculate the count that each process receives // and the displacement within the buffer - cnts = (int *) xbt_malloc(pof2 * sizeof(int)); - disps = (int *) xbt_malloc(pof2 * sizeof(int)); + int* cnts = new int[pof2]; + int* disps = new int[pof2]; for (i = 0; i < (pof2 - 1); i++) cnts[i] = count / pof2; @@ -177,9 +176,8 @@ int Coll_allreduce_rab_rdb::allreduce(const void *sbuff, void *rbuff, int count, mask >>= 1; } - free(cnts); - free(disps); - + delete[] cnts; + delete[] disps; } // In the non-power-of-two case, all odd-numbered processes of // rank < 2 * rem send the result to (rank-1), the ranks who didn't diff --git a/src/smpi/colls/alltoall/alltoall-2dmesh.cpp b/src/smpi/colls/alltoall/alltoall-2dmesh.cpp index e27e5ded26..41c2cef9d5 100644 --- a/src/smpi/colls/alltoall/alltoall-2dmesh.cpp +++ b/src/smpi/colls/alltoall/alltoall-2dmesh.cpp @@ -60,8 +60,7 @@ int Coll_alltoall_2dmesh::alltoall(const void *send_buff, int send_count, void *recv_buff, int recv_count, MPI_Datatype recv_type, MPI_Comm comm) { - MPI_Status *statuses, s; - MPI_Request *reqs, *req_ptr;; + MPI_Status s; MPI_Aint extent; char *tmp_buff1, *tmp_buff2; @@ -89,10 +88,9 @@ int Coll_alltoall_2dmesh::alltoall(const void *send_buff, int send_count, if (Y > X) num_reqs = Y; - statuses = (MPI_Status *) xbt_malloc(num_reqs * sizeof(MPI_Status)); - reqs = (MPI_Request *) xbt_malloc(num_reqs * sizeof(MPI_Request)); - - req_ptr = reqs; + MPI_Status* statuses = new MPI_Status[num_reqs]; + MPI_Request* reqs = new MPI_Request[num_reqs]; + MPI_Request* req_ptr = reqs; count = send_count * num_procs; @@ -168,8 +166,8 @@ int Coll_alltoall_2dmesh::alltoall(const void *send_buff, int send_count, Request::send(tmp_buff2, send_count * Y, send_type, dst, tag, comm); } Request::waitall(X - 1, reqs, statuses); - free(reqs); - free(statuses); + delete[] reqs; + delete[] statuses; smpi_free_tmp_buffer(tmp_buff1); smpi_free_tmp_buffer(tmp_buff2); return MPI_SUCCESS; diff --git a/src/smpi/colls/alltoall/alltoall-3dmesh.cpp b/src/smpi/colls/alltoall/alltoall-3dmesh.cpp index 3870c52499..58f8afea5b 100644 --- a/src/smpi/colls/alltoall/alltoall-3dmesh.cpp +++ b/src/smpi/colls/alltoall/alltoall-3dmesh.cpp @@ -52,9 +52,8 @@ int Coll_alltoall_3dmesh::alltoall(const void *send_buff, int send_count, void *recv_buff, int recv_count, MPI_Datatype recv_type, MPI_Comm comm) { - MPI_Request *reqs, *req_ptr; MPI_Aint extent; - MPI_Status status, *statuses; + MPI_Status status; int i, j, src, dst, rank, num_procs, num_reqs, X, Y, Z, block_size, count; int my_z, two_dsize, my_row_base, my_col_base, my_z_base, src_row_base; int src_z_base, send_offset, recv_offset, tag = COLL_TAG_ALLTOALL; @@ -86,10 +85,9 @@ int Coll_alltoall_3dmesh::alltoall(const void *send_buff, int send_count, tmp_buff1 = (char *) smpi_get_tmp_sendbuffer(block_size * num_procs * two_dsize); tmp_buff2 = (char *) smpi_get_tmp_recvbuffer(block_size * two_dsize); - statuses = (MPI_Status *) xbt_malloc(num_reqs * sizeof(MPI_Status)); - reqs = (MPI_Request *) xbt_malloc(num_reqs * sizeof(MPI_Request)); - - req_ptr = reqs; + MPI_Status* statuses = new MPI_Status[num_reqs]; + MPI_Request* reqs = new MPI_Request[num_reqs]; + MPI_Request* req_ptr = reqs; recv_offset = (rank % two_dsize) * block_size * num_procs; @@ -179,8 +177,8 @@ int Coll_alltoall_3dmesh::alltoall(const void *send_buff, int send_count, Request::waitall(Z - 1, reqs, statuses); - free(reqs); - free(statuses); + delete[] reqs; + delete[] statuses; smpi_free_tmp_buffer(tmp_buff1); smpi_free_tmp_buffer(tmp_buff2); return MPI_SUCCESS; diff --git a/src/smpi/colls/alltoall/alltoall-basic-linear.cpp b/src/smpi/colls/alltoall/alltoall-basic-linear.cpp index 06c538251a..c8aeff2c0e 100644 --- a/src/smpi/colls/alltoall/alltoall-basic-linear.cpp +++ b/src/smpi/colls/alltoall/alltoall-basic-linear.cpp @@ -20,7 +20,6 @@ int Coll_alltoall_basic_linear::alltoall(const void *sendbuf, int sendcount, MPI int i; int count; MPI_Aint lb = 0, sendext = 0, recvext = 0; - MPI_Request *requests; /* Initialize. */ int rank = comm->rank(); @@ -33,7 +32,7 @@ int Coll_alltoall_basic_linear::alltoall(const void *sendbuf, int sendcount, MPI static_cast(recvbuf) + rank * recvcount * recvext, recvcount, recvtype); if (err == MPI_SUCCESS && size > 1) { /* Initiate all send/recv to/from others. */ - requests = xbt_new(MPI_Request, 2 * (size - 1)); + MPI_Request* requests = new MPI_Request[2 * (size - 1)]; /* Post all receives first -- a simple optimization */ count = 0; for (i = (rank + 1) % size; i != rank; i = (i + 1) % size) { @@ -59,7 +58,7 @@ int Coll_alltoall_basic_linear::alltoall(const void *sendbuf, int sendcount, MPI if(requests[i]!=MPI_REQUEST_NULL) Request::unref(&requests[i]); } - xbt_free(requests); + delete[] requests; } return err; } diff --git a/src/smpi/colls/alltoall/alltoall-bruck.cpp b/src/smpi/colls/alltoall/alltoall-bruck.cpp index c2ea5ed9ba..9c2f5bcd46 100644 --- a/src/smpi/colls/alltoall/alltoall-bruck.cpp +++ b/src/smpi/colls/alltoall/alltoall-bruck.cpp @@ -41,7 +41,6 @@ Coll_alltoall_bruck::alltoall(const void *send_buff, int send_count, MPI_Aint extent; MPI_Datatype new_type; - int *blocks_length, *disps; int i, src, dst, rank, num_procs, count, block, position; int pack_size, tag = COLL_TAG_ALLTOALL, pof2 = 1; @@ -56,8 +55,8 @@ Coll_alltoall_bruck::alltoall(const void *send_buff, int send_count, extent = recv_type->get_extent(); tmp_buff = (char *) smpi_get_tmp_sendbuffer(num_procs * recv_count * extent); - disps = (int *) xbt_malloc(sizeof(int) * num_procs); - blocks_length = (int *) xbt_malloc(sizeof(int) * num_procs); + int* disps = new int[num_procs]; + int* blocks_length = new int[num_procs]; Request::sendrecv(send_ptr + rank * send_count * extent, (num_procs - rank) * send_count, send_type, rank, tag, @@ -98,8 +97,8 @@ Coll_alltoall_bruck::alltoall(const void *send_buff, int send_count, pof2 *= 2; } - free(disps); - free(blocks_length); + delete[] disps; + delete[] blocks_length; Request::sendrecv(recv_ptr + (rank + 1) * recv_count * extent, (num_procs - rank - 1) * recv_count, send_type, diff --git a/src/smpi/colls/alltoall/alltoall-mvapich-scatter-dest.cpp b/src/smpi/colls/alltoall/alltoall-mvapich-scatter-dest.cpp index 5d77d38c6c..e4dc8a0c75 100644 --- a/src/smpi/colls/alltoall/alltoall-mvapich-scatter-dest.cpp +++ b/src/smpi/colls/alltoall/alltoall-mvapich-scatter-dest.cpp @@ -57,8 +57,6 @@ int Coll_alltoall_mvapich2_scatter_dest::alltoall( MPI_Aint sendtype_extent = 0, recvtype_extent = 0; int mpi_errno=MPI_SUCCESS; int dst, rank; - MPI_Request *reqarray; - MPI_Status *starray; if (recvcount == 0) return MPI_SUCCESS; @@ -93,9 +91,9 @@ int Coll_alltoall_mvapich2_scatter_dest::alltoall( /* FIXME: This should use the memory macros (there are storage leaks here if there is an error, for example) */ - reqarray= (MPI_Request*)xbt_malloc(2*bblock*sizeof(MPI_Request)); + MPI_Request* reqarray = new MPI_Request[2 * bblock]; - starray=(MPI_Status *)xbt_malloc(2*bblock*sizeof(MPI_Status)); + MPI_Status* starray = new MPI_Status[2 * bblock]; for (ii=0; iirank(); @@ -43,52 +42,47 @@ int Coll_alltoallv_bruck::alltoallv(const void *sendbuf, const int *sendcounts, if (err == MPI_SUCCESS && size > 1) { /* Initiate all send/recv to/from others. */ - int bblock = 4;//MPIR_PARAM_ALLTOALL_THROTTLE - //if (bblock == 0) bblock = comm_size; + int bblock = 4; // MPIR_PARAM_ALLTOALL_THROTTLE + // if (bblock == 0) bblock = comm_size; + // MPI_Request* requests = new MPI_Request[2 * (bblock - 1)]; + int ii, ss, dst; + /* post only bblock isends/irecvs at a time as suggested by Tony Ladd */ + for (ii = 0; ii < size; ii += bblock) { + MPI_Request* requests = new MPI_Request[2 * bblock]; - // requests = xbt_new(MPI_Request, 2 * (bblock - 1)); - int ii, ss, dst; - /* post only bblock isends/irecvs at a time as suggested by Tony Ladd */ - for (ii=0; ii skip request creation [src = %d, recvcount = %d]", - rank, i, recvcounts[dst]); - continue; - } - - requests[count]=Request::irecv((char *)recvbuf + recvdisps[dst] * recvext, recvcounts[dst], - recvtype, dst, system_tag, comm ); - count++; - } - /* Now create all sends */ - for ( i=0; i skip request creation [dst = %d, sendcount = %d]", - rank, i, sendcounts[dst]); - continue; - } - requests[count]=Request::isend((char *)sendbuf + senddisps[dst] * sendext, sendcounts[dst], - sendtype, dst, system_tag, comm); - count++; - } - /* Wait for them all. */ - //Colls::startall(count, requests); - XBT_DEBUG("<%d> wait for %d requests", rank, count); - Request::waitall(count, requests, MPI_STATUSES_IGNORE); - xbt_free(requests); - - } + /* do the communication -- post ss sends and receives: */ + for (i = 0; i < ss; i++) { + dst = (rank + i + ii) % size; + if (dst == rank) { + XBT_DEBUG("<%d> skip request creation [src = %d, recvcount = %d]", rank, i, recvcounts[dst]); + continue; + } + requests[count] = + Request::irecv((char*)recvbuf + recvdisps[dst] * recvext, recvcounts[dst], recvtype, dst, system_tag, comm); + count++; + } + /* Now create all sends */ + for (i = 0; i < ss; i++) { + dst = (rank - i - ii + size) % size; + if (dst == rank) { + XBT_DEBUG("<%d> skip request creation [dst = %d, sendcount = %d]", rank, i, sendcounts[dst]); + continue; + } + requests[count] = + Request::isend((char*)sendbuf + senddisps[dst] * sendext, sendcounts[dst], sendtype, dst, system_tag, comm); + count++; + } + /* Wait for them all. */ + // Colls::startall(count, requests); + XBT_DEBUG("<%d> wait for %d requests", rank, count); + Request::waitall(count, requests, MPI_STATUSES_IGNORE); + delete[] requests; + } } return MPI_SUCCESS; } diff --git a/src/smpi/colls/alltoallv/alltoallv-ompi-basic-linear.cpp b/src/smpi/colls/alltoallv/alltoallv-ompi-basic-linear.cpp index 5b646c6a9e..de140a36ee 100644 --- a/src/smpi/colls/alltoallv/alltoallv-ompi-basic-linear.cpp +++ b/src/smpi/colls/alltoallv/alltoallv-ompi-basic-linear.cpp @@ -30,7 +30,7 @@ Coll_alltoallv_ompi_basic_linear::alltoallv(const void *sbuf, const int *scounts MPI_Request *preq; size = comm->size(); rank = comm->rank(); - MPI_Request *ireqs= static_cast(xbt_malloc(sizeof(MPI_Request) * size * 2)); + MPI_Request* ireqs = new MPI_Request[size * 2]; XBT_DEBUG( "coll:tuned:alltoallv_intra_basic_linear rank %d", rank); @@ -101,7 +101,7 @@ Coll_alltoallv_ompi_basic_linear::alltoallv(const void *sbuf, const int *scounts if(ireqs[i]!=MPI_REQUEST_NULL) Request::unref(&ireqs[i]); } - free(ireqs); + delete[] ireqs; return MPI_SUCCESS; } diff --git a/src/smpi/colls/bcast/bcast-NTSB.cpp b/src/smpi/colls/bcast/bcast-NTSB.cpp index 545705b51d..9a112c331a 100644 --- a/src/smpi/colls/bcast/bcast-NTSB.cpp +++ b/src/smpi/colls/bcast/bcast-NTSB.cpp @@ -17,11 +17,6 @@ int Coll_bcast_NTSB::bcast(void *buf, int count, MPI_Datatype datatype, int rank, size; int i; - MPI_Request *send_request_array; - MPI_Request *recv_request_array; - MPI_Status *send_status_array; - MPI_Status *recv_status_array; - MPI_Aint extent; extent = datatype->get_extent(); @@ -97,16 +92,10 @@ int Coll_bcast_NTSB::bcast(void *buf, int count, MPI_Datatype datatype, // pipelining else { - send_request_array = - (MPI_Request *) xbt_malloc(2 * (size + pipe_length) * sizeof(MPI_Request)); - recv_request_array = - (MPI_Request *) xbt_malloc((size + pipe_length) * sizeof(MPI_Request)); - send_status_array = - (MPI_Status *) xbt_malloc(2 * (size + pipe_length) * sizeof(MPI_Status)); - recv_status_array = - (MPI_Status *) xbt_malloc((size + pipe_length) * sizeof(MPI_Status)); - - + MPI_Request* send_request_array = new MPI_Request[2 * (size + pipe_length)]; + MPI_Request* recv_request_array = new MPI_Request[size + pipe_length]; + MPI_Status* send_status_array = new MPI_Status[2 * (size + pipe_length)]; + MPI_Status* recv_status_array = new MPI_Status[size + pipe_length]; /* case: root */ if (rank == 0) { @@ -169,10 +158,10 @@ int Coll_bcast_NTSB::bcast(void *buf, int count, MPI_Datatype datatype, Request::waitall((2 * pipe_length), send_request_array, send_status_array); } - free(send_request_array); - free(recv_request_array); - free(send_status_array); - free(recv_status_array); + delete[] send_request_array; + delete[] recv_request_array; + delete[] send_status_array; + delete[] recv_status_array; } /* end pipeline */ /* when count is not divisible by block size, use default BCAST for the remainder */ diff --git a/src/smpi/colls/bcast/bcast-NTSL-Isend.cpp b/src/smpi/colls/bcast/bcast-NTSL-Isend.cpp index f480649155..57857c07d2 100644 --- a/src/smpi/colls/bcast/bcast-NTSL-Isend.cpp +++ b/src/smpi/colls/bcast/bcast-NTSL-Isend.cpp @@ -19,10 +19,6 @@ int Coll_bcast_NTSL_Isend::bcast(void *buf, int count, MPI_Datatype datatype, int tag = COLL_TAG_BCAST; MPI_Status status; MPI_Request request; - MPI_Request *send_request_array; - MPI_Request *recv_request_array; - MPI_Status *send_status_array; - MPI_Status *recv_status_array; int rank, size; int i; MPI_Aint extent; @@ -76,14 +72,10 @@ int Coll_bcast_NTSL_Isend::bcast(void *buf, int count, MPI_Datatype datatype, /* pipeline bcast */ else { - send_request_array = - (MPI_Request *) xbt_malloc((size + pipe_length) * sizeof(MPI_Request)); - recv_request_array = - (MPI_Request *) xbt_malloc((size + pipe_length) * sizeof(MPI_Request)); - send_status_array = - (MPI_Status *) xbt_malloc((size + pipe_length) * sizeof(MPI_Status)); - recv_status_array = - (MPI_Status *) xbt_malloc((size + pipe_length) * sizeof(MPI_Status)); + MPI_Request* send_request_array = new MPI_Request[size + pipe_length]; + MPI_Request* recv_request_array = new MPI_Request[size + pipe_length]; + MPI_Status* send_status_array = new MPI_Status[size + pipe_length]; + MPI_Status* recv_status_array = new MPI_Status[size + pipe_length]; /* root send data */ if (rank == 0) { @@ -117,10 +109,10 @@ int Coll_bcast_NTSL_Isend::bcast(void *buf, int count, MPI_Datatype datatype, Request::waitall((pipe_length), send_request_array, send_status_array); } - free(send_request_array); - free(recv_request_array); - free(send_status_array); - free(recv_status_array); + delete[] send_request_array; + delete[] recv_request_array; + delete[] send_status_array; + delete[] recv_status_array; } /* end pipeline */ /* when count is not divisible by block size, use default BCAST for the remainder */ diff --git a/src/smpi/colls/bcast/bcast-NTSL.cpp b/src/smpi/colls/bcast/bcast-NTSL.cpp index 56a5886959..97e55c82f6 100644 --- a/src/smpi/colls/bcast/bcast-NTSL.cpp +++ b/src/smpi/colls/bcast/bcast-NTSL.cpp @@ -19,10 +19,6 @@ int Coll_bcast_NTSL::bcast(void *buf, int count, MPI_Datatype datatype, int tag = COLL_TAG_BCAST; MPI_Status status; MPI_Request request; - MPI_Request *send_request_array; - MPI_Request *recv_request_array; - MPI_Status *send_status_array; - MPI_Status *recv_status_array; int rank, size; int i; MPI_Aint extent; @@ -76,14 +72,10 @@ int Coll_bcast_NTSL::bcast(void *buf, int count, MPI_Datatype datatype, /* pipeline bcast */ else { - send_request_array = - (MPI_Request *) xbt_malloc((size + pipe_length) * sizeof(MPI_Request)); - recv_request_array = - (MPI_Request *) xbt_malloc((size + pipe_length) * sizeof(MPI_Request)); - send_status_array = - (MPI_Status *) xbt_malloc((size + pipe_length) * sizeof(MPI_Status)); - recv_status_array = - (MPI_Status *) xbt_malloc((size + pipe_length) * sizeof(MPI_Status)); + MPI_Request* send_request_array = new MPI_Request[size + pipe_length]; + MPI_Request* recv_request_array = new MPI_Request[size + pipe_length]; + MPI_Status* send_status_array = new MPI_Status[size + pipe_length]; + MPI_Status* recv_status_array = new MPI_Status[size + pipe_length]; /* root send data */ if (rank == 0) { @@ -117,10 +109,10 @@ int Coll_bcast_NTSL::bcast(void *buf, int count, MPI_Datatype datatype, Request::waitall((pipe_length), send_request_array, send_status_array); } - free(send_request_array); - free(recv_request_array); - free(send_status_array); - free(recv_status_array); + delete[] send_request_array; + delete[] recv_request_array; + delete[] send_status_array; + delete[] recv_status_array; } /* end pipeline */ /* when count is not divisible by block size, use default BCAST for the remainder */ diff --git a/src/smpi/colls/bcast/bcast-SMP-binary.cpp b/src/smpi/colls/bcast/bcast-SMP-binary.cpp index 3b7d4ebfea..3ce7918c13 100644 --- a/src/smpi/colls/bcast/bcast-SMP-binary.cpp +++ b/src/smpi/colls/bcast/bcast-SMP-binary.cpp @@ -16,8 +16,6 @@ int Coll_bcast_SMP_binary::bcast(void *buf, int count, int tag = COLL_TAG_BCAST; MPI_Status status; MPI_Request request; - MPI_Request *request_array; - MPI_Status *status_array; int rank, size; int i; MPI_Aint extent; @@ -123,10 +121,8 @@ int Coll_bcast_SMP_binary::bcast(void *buf, int count, // pipeline bcast else { - request_array = - (MPI_Request *) xbt_malloc((size + pipe_length) * sizeof(MPI_Request)); - status_array = - (MPI_Status *) xbt_malloc((size + pipe_length) * sizeof(MPI_Status)); + MPI_Request* request_array = new MPI_Request[size + pipe_length]; + MPI_Status* status_array = new MPI_Status[size + pipe_length]; // case ROOT-of-each-SMP if (rank % host_num_core == 0) { @@ -215,8 +211,8 @@ int Coll_bcast_SMP_binary::bcast(void *buf, int count, } } - free(request_array); - free(status_array); + delete[] request_array; + delete[] status_array; } // when count is not divisible by block size, use default BCAST for the remainder diff --git a/src/smpi/colls/bcast/bcast-SMP-linear.cpp b/src/smpi/colls/bcast/bcast-SMP-linear.cpp index 4f1a90ebf4..a8c6bec048 100644 --- a/src/smpi/colls/bcast/bcast-SMP-linear.cpp +++ b/src/smpi/colls/bcast/bcast-SMP-linear.cpp @@ -16,8 +16,6 @@ int Coll_bcast_SMP_linear::bcast(void *buf, int count, int tag = COLL_TAG_BCAST; MPI_Status status; MPI_Request request; - MPI_Request *request_array; - MPI_Status *status_array; int rank, size; int i; MPI_Aint extent; @@ -99,10 +97,8 @@ int Coll_bcast_SMP_linear::bcast(void *buf, int count, } // pipeline bcast else { - request_array = - (MPI_Request *) xbt_malloc((size + pipe_length) * sizeof(MPI_Request)); - status_array = - (MPI_Status *) xbt_malloc((size + pipe_length) * sizeof(MPI_Status)); + MPI_Request* request_array = new MPI_Request[size + pipe_length]; + MPI_Status* status_array = new MPI_Status[size + pipe_length]; // case ROOT of each SMP if (rank % num_core == 0) { @@ -164,8 +160,8 @@ int Coll_bcast_SMP_linear::bcast(void *buf, int count, } } } - free(request_array); - free(status_array); + delete[] request_array; + delete[] status_array; } // when count is not divisible by block size, use default BCAST for the remainder diff --git a/src/smpi/colls/bcast/bcast-arrival-pattern-aware-wait.cpp b/src/smpi/colls/bcast/bcast-arrival-pattern-aware-wait.cpp index e764c4b2b2..46e6125f26 100644 --- a/src/smpi/colls/bcast/bcast-arrival-pattern-aware-wait.cpp +++ b/src/smpi/colls/bcast/bcast-arrival-pattern-aware-wait.cpp @@ -24,11 +24,6 @@ int Coll_bcast_arrival_pattern_aware_wait::bcast(void *buf, int count, { MPI_Status status; MPI_Request request; - MPI_Request *send_request_array; - MPI_Request *recv_request_array; - MPI_Status *send_status_array; - MPI_Status *recv_status_array; - MPI_Status temp_status_array[BCAST_ARRIVAL_PATTERN_AWARE_MAX_NODE]; @@ -98,14 +93,10 @@ int Coll_bcast_arrival_pattern_aware_wait::bcast(void *buf, int count, /* start pipeline bcast */ - send_request_array = - (MPI_Request *) xbt_malloc((size + pipe_length) * sizeof(MPI_Request)); - recv_request_array = - (MPI_Request *) xbt_malloc((size + pipe_length) * sizeof(MPI_Request)); - send_status_array = - (MPI_Status *) xbt_malloc((size + pipe_length) * sizeof(MPI_Status)); - recv_status_array = - (MPI_Status *) xbt_malloc((size + pipe_length) * sizeof(MPI_Status)); + MPI_Request* send_request_array = new MPI_Request[size + pipe_length]; + MPI_Request* recv_request_array = new MPI_Request[size + pipe_length]; + MPI_Status* send_status_array = new MPI_Status[size + pipe_length]; + MPI_Status* recv_status_array = new MPI_Status[size + pipe_length]; /* root */ if (rank == 0) { @@ -239,10 +230,10 @@ int Coll_bcast_arrival_pattern_aware_wait::bcast(void *buf, int count, } } - free(send_request_array); - free(recv_request_array); - free(send_status_array); - free(recv_status_array); + delete[] send_request_array; + delete[] recv_request_array; + delete[] send_status_array; + delete[] recv_status_array; /* end pipeline */ /* when count is not divisible by block size, use default BCAST for the remainder */ diff --git a/src/smpi/colls/bcast/bcast-arrival-pattern-aware.cpp b/src/smpi/colls/bcast/bcast-arrival-pattern-aware.cpp index 778379264f..1552b72b19 100644 --- a/src/smpi/colls/bcast/bcast-arrival-pattern-aware.cpp +++ b/src/smpi/colls/bcast/bcast-arrival-pattern-aware.cpp @@ -21,10 +21,6 @@ int Coll_bcast_arrival_pattern_aware::bcast(void *buf, int count, int tag = -COLL_TAG_BCAST; MPI_Status status; MPI_Request request; - MPI_Request *send_request_array; - MPI_Request *recv_request_array; - MPI_Status *send_status_array; - MPI_Status *recv_status_array; MPI_Status temp_status_array[MAX_NODE]; @@ -163,14 +159,10 @@ int Coll_bcast_arrival_pattern_aware::bcast(void *buf, int count, } /* pipeline bcast */ else { - send_request_array = - (MPI_Request *) xbt_malloc((size + pipe_length) * sizeof(MPI_Request)); - recv_request_array = - (MPI_Request *) xbt_malloc((size + pipe_length) * sizeof(MPI_Request)); - send_status_array = - (MPI_Status *) xbt_malloc((size + pipe_length) * sizeof(MPI_Status)); - recv_status_array = - (MPI_Status *) xbt_malloc((size + pipe_length) * sizeof(MPI_Status)); + MPI_Request* send_request_array = new MPI_Request[size + pipe_length]; + MPI_Request* recv_request_array = new MPI_Request[size + pipe_length]; + MPI_Status* send_status_array = new MPI_Status[size + pipe_length]; + MPI_Status* recv_status_array = new MPI_Status[size + pipe_length]; if (rank == 0) { //double start2 = MPI_Wtime(); @@ -350,10 +342,10 @@ int Coll_bcast_arrival_pattern_aware::bcast(void *buf, int count, } - free(send_request_array); - free(recv_request_array); - free(send_status_array); - free(recv_status_array); + delete[] send_request_array; + delete[] recv_request_array; + delete[] send_status_array; + delete[] recv_status_array; } /* end pipeline */ /* when count is not divisible by block size, use default BCAST for the remainder */ diff --git a/src/smpi/colls/bcast/bcast-flattree-pipeline.cpp b/src/smpi/colls/bcast/bcast-flattree-pipeline.cpp index 81406c8d91..07e4384538 100644 --- a/src/smpi/colls/bcast/bcast-flattree-pipeline.cpp +++ b/src/smpi/colls/bcast/bcast-flattree-pipeline.cpp @@ -31,11 +31,8 @@ Coll_bcast_flattree_pipeline::bcast(void *buff, int count, rank = comm->rank(); num_procs = comm->size(); - MPI_Request *request_array; - MPI_Status *status_array; - - request_array = (MPI_Request *) xbt_malloc(pipe_length * sizeof(MPI_Request)); - status_array = (MPI_Status *) xbt_malloc(pipe_length * sizeof(MPI_Status)); + MPI_Request* request_array = new MPI_Request[pipe_length]; + MPI_Status* status_array = new MPI_Status[pipe_length]; if (rank != root) { for (i = 0; i < pipe_length; i++) { @@ -58,8 +55,8 @@ Coll_bcast_flattree_pipeline::bcast(void *buff, int count, } - free(request_array); - free(status_array); + delete[] request_array; + delete[] status_array; return MPI_SUCCESS; } diff --git a/src/smpi/colls/bcast/bcast-flattree.cpp b/src/smpi/colls/bcast/bcast-flattree.cpp index 7178f2a21b..175c8751f9 100644 --- a/src/smpi/colls/bcast/bcast-flattree.cpp +++ b/src/smpi/colls/bcast/bcast-flattree.cpp @@ -11,9 +11,6 @@ int Coll_bcast_flattree::bcast(void *buff, int count, MPI_Datatype data_type, int root, MPI_Comm comm) { - MPI_Request *req_ptr; - MPI_Request *reqs; - int i, rank, num_procs; int tag = COLL_TAG_BCAST; @@ -25,8 +22,8 @@ Coll_bcast_flattree::bcast(void *buff, int count, MPI_Datatype data_type, } else { - reqs = (MPI_Request *) xbt_malloc((num_procs - 1) * sizeof(MPI_Request)); - req_ptr = reqs; + MPI_Request* reqs = new MPI_Request[num_procs - 1]; + MPI_Request* req_ptr = reqs; // Root sends data to all others for (i = 0; i < num_procs; i++) { @@ -38,7 +35,7 @@ Coll_bcast_flattree::bcast(void *buff, int count, MPI_Datatype data_type, // wait on all requests Request::waitall(num_procs - 1, reqs, MPI_STATUSES_IGNORE); - free(reqs); + delete[] reqs; } return MPI_SUCCESS; } diff --git a/src/smpi/colls/bcast/bcast-mvapich-smp.cpp b/src/smpi/colls/bcast/bcast-mvapich-smp.cpp index b65ef8e0ee..d7f6a3bf53 100644 --- a/src/smpi/colls/bcast/bcast-mvapich-smp.cpp +++ b/src/smpi/colls/bcast/bcast-mvapich-smp.cpp @@ -177,8 +177,6 @@ int Coll_bcast_mvapich2_knomial_intra_node::bcast(void *buffer, { int local_size = 0, rank; int mpi_errno = MPI_SUCCESS; - MPI_Request *reqarray = NULL; - MPI_Status *starray = NULL; int src, dst, mask, relative_rank; int k; if (MV2_Bcast_function==NULL){ @@ -196,10 +194,9 @@ int Coll_bcast_mvapich2_knomial_intra_node::bcast(void *buffer, local_size = comm->size(); rank = comm->rank(); + MPI_Request* reqarray = new MPI_Request[2 * mv2_intra_node_knomial_factor]; - reqarray=(MPI_Request *)xbt_malloc(2 * mv2_intra_node_knomial_factor * sizeof (MPI_Request)); - - starray=(MPI_Status *)xbt_malloc(2 * mv2_intra_node_knomial_factor * sizeof (MPI_Status)); + MPI_Status* starray = new MPI_Status[2 * mv2_intra_node_knomial_factor]; /* intra-node k-nomial bcast */ if (local_size > 1) { @@ -240,8 +237,8 @@ int Coll_bcast_mvapich2_knomial_intra_node::bcast(void *buffer, mask /= mv2_intra_node_knomial_factor; } } - xbt_free(reqarray); - xbt_free(starray); + delete[] reqarray; + delete[] starray; return mpi_errno; } diff --git a/src/smpi/colls/bcast/bcast-scatter-LR-allgather.cpp b/src/smpi/colls/bcast/bcast-scatter-LR-allgather.cpp index 88c6b7d393..1a3cb9b2bd 100644 --- a/src/smpi/colls/bcast/bcast-scatter-LR-allgather.cpp +++ b/src/smpi/colls/bcast/bcast-scatter-LR-allgather.cpp @@ -78,7 +78,7 @@ Coll_bcast_scatter_LR_allgather::bcast(void *buff, int count, MPI_Status status; int i, src, dst, rank, num_procs; int mask, relative_rank, curr_size, recv_size, send_size, nbytes; - int scatter_size, left, right, next_src, *recv_counts, *disps; + int scatter_size, left, right, next_src; int tag = COLL_TAG_BCAST; rank = comm->rank(); @@ -139,8 +139,8 @@ Coll_bcast_scatter_LR_allgather::bcast(void *buff, int count, } // done scatter now do allgather - recv_counts = (int *) xbt_malloc(sizeof(int) * num_procs); - disps = (int *) xbt_malloc(sizeof(int) * num_procs); + int* recv_counts = new int[num_procs]; + int* disps = new int[num_procs]; for (i = 0; i < num_procs; i++) { recv_counts[i] = nbytes - i * scatter_size; @@ -172,9 +172,8 @@ Coll_bcast_scatter_LR_allgather::bcast(void *buff, int count, next_src = (num_procs + next_src - 1) % num_procs; } - - free(recv_counts); - free(disps); + delete[] recv_counts; + delete[] disps; return MPI_SUCCESS; } diff --git a/src/smpi/colls/bcast/bcast-scatter-rdb-allgather.cpp b/src/smpi/colls/bcast/bcast-scatter-rdb-allgather.cpp index 2bd91dfb9e..d8cb946f76 100644 --- a/src/smpi/colls/bcast/bcast-scatter-rdb-allgather.cpp +++ b/src/smpi/colls/bcast/bcast-scatter-rdb-allgather.cpp @@ -162,15 +162,15 @@ Coll_bcast_scatter_rdb_allgather::bcast ( } else { - tmp_buf=(void*)xbt_malloc(nbytes); - - /* TODO: Pipeline the packing and communication */ - position = 0; - if (rank == root) { - mpi_errno = datatype->pack(buffer, count, tmp_buf, nbytes, - &position, comm); - if (mpi_errno) xbt_die("crash while packing %d", mpi_errno); - } + tmp_buf = new unsigned char[nbytes]; + + /* TODO: Pipeline the packing and communication */ + position = 0; + if (rank == root) { + mpi_errno = datatype->pack(buffer, count, tmp_buf, nbytes, &position, comm); + if (mpi_errno) + xbt_die("crash while packing %d", mpi_errno); + } } @@ -334,8 +334,8 @@ Coll_bcast_scatter_rdb_allgather::bcast ( } fn_exit: -/* xbt_free(tmp_buf);*/ - return mpi_errno; + /* delete[] static_cast(tmp_buf); */ + return mpi_errno; } } diff --git a/src/smpi/colls/gather/gather-mvapich.cpp b/src/smpi/colls/gather/gather-mvapich.cpp index 7d0a4e3056..48946ed8c3 100644 --- a/src/smpi/colls/gather/gather-mvapich.cpp +++ b/src/smpi/colls/gather/gather-mvapich.cpp @@ -303,12 +303,8 @@ int Coll_gather_mvapich2_two_level::gather(const void *sendbuf, node_sizes = comm->get_non_uniform_map(); if (leader_comm_rank == leader_root) { - displs = static_cast(xbt_malloc(sizeof(int) * leader_comm_size)); - recvcnts = static_cast(xbt_malloc(sizeof(int) * leader_comm_size)); - if (not displs || not recvcnts) { - mpi_errno = MPI_ERR_OTHER; - return mpi_errno; - } + displs = new int[leader_comm_size]; + recvcnts = new int[leader_comm_size]; } if (root == leader_of_root) { @@ -342,8 +338,8 @@ int Coll_gather_mvapich2_two_level::gather(const void *sendbuf, leader_root, leader_comm); } if (leader_comm_rank == leader_root) { - xbt_free(displs); - xbt_free(recvcnts); + delete[] displs; + delete[] recvcnts; } } } else { diff --git a/src/smpi/colls/reduce/reduce-NTSL.cpp b/src/smpi/colls/reduce/reduce-NTSL.cpp index e07d5acc38..e8f6dec702 100644 --- a/src/smpi/colls/reduce/reduce-NTSL.cpp +++ b/src/smpi/colls/reduce/reduce-NTSL.cpp @@ -20,10 +20,6 @@ int Coll_reduce_NTSL::reduce(const void *buf, void *rbuf, int count, { int tag = COLL_TAG_REDUCE; MPI_Status status; - MPI_Request *send_request_array; - MPI_Request *recv_request_array; - MPI_Status *send_status_array; - MPI_Status *recv_status_array; int rank, size; int i; MPI_Aint extent; @@ -88,14 +84,10 @@ int Coll_reduce_NTSL::reduce(const void *buf, void *rbuf, int count, /* pipeline */ else { - send_request_array = - (MPI_Request *) xbt_malloc((size + pipe_length) * sizeof(MPI_Request)); - recv_request_array = - (MPI_Request *) xbt_malloc((size + pipe_length) * sizeof(MPI_Request)); - send_status_array = - (MPI_Status *) xbt_malloc((size + pipe_length) * sizeof(MPI_Status)); - recv_status_array = - (MPI_Status *) xbt_malloc((size + pipe_length) * sizeof(MPI_Status)); + MPI_Request* send_request_array = new MPI_Request[size + pipe_length]; + MPI_Request* recv_request_array = new MPI_Request[size + pipe_length]; + MPI_Status* send_status_array = new MPI_Status[size + pipe_length]; + MPI_Status* recv_status_array = new MPI_Status[size + pipe_length]; /* root recv data */ if (rank == root) { @@ -135,10 +127,10 @@ int Coll_reduce_NTSL::reduce(const void *buf, void *rbuf, int count, Request::waitall((pipe_length), send_request_array, send_status_array); } - free(send_request_array); - free(recv_request_array); - free(send_status_array); - free(recv_status_array); + delete[] send_request_array; + delete[] recv_request_array; + delete[] send_status_array; + delete[] recv_status_array; } /* end pipeline */ /* when count is not divisible by block size, use default BCAST for the remainder */ diff --git a/src/smpi/colls/reduce/reduce-arrival-pattern-aware.cpp b/src/smpi/colls/reduce/reduce-arrival-pattern-aware.cpp index 63454dcc5f..8f0b20260e 100644 --- a/src/smpi/colls/reduce/reduce-arrival-pattern-aware.cpp +++ b/src/smpi/colls/reduce/reduce-arrival-pattern-aware.cpp @@ -29,10 +29,6 @@ int Coll_reduce_arrival_pattern_aware::reduce(const void *buf, void *rbuf, int tag = -COLL_TAG_REDUCE; MPI_Status status; MPI_Request request; - MPI_Request *send_request_array; - MPI_Request *recv_request_array; - MPI_Status *send_status_array; - MPI_Status *recv_status_array; MPI_Status temp_status_array[MAX_NODE]; @@ -190,14 +186,10 @@ int Coll_reduce_arrival_pattern_aware::reduce(const void *buf, void *rbuf, else { // printf("node %d start\n",rank); - send_request_array = - (MPI_Request *) xbt_malloc((size + pipe_length) * sizeof(MPI_Request)); - recv_request_array = - (MPI_Request *) xbt_malloc((size + pipe_length) * sizeof(MPI_Request)); - send_status_array = - (MPI_Status *) xbt_malloc((size + pipe_length) * sizeof(MPI_Status)); - recv_status_array = - (MPI_Status *) xbt_malloc((size + pipe_length) * sizeof(MPI_Status)); + MPI_Request* send_request_array = new MPI_Request[size + pipe_length]; + MPI_Request* recv_request_array = new MPI_Request[size + pipe_length]; + MPI_Status* send_status_array = new MPI_Status[size + pipe_length]; + MPI_Status* recv_status_array = new MPI_Status[size + pipe_length]; if (rank == 0) { sent_count = 0; @@ -319,13 +311,10 @@ int Coll_reduce_arrival_pattern_aware::reduce(const void *buf, void *rbuf, } } /* non-root */ - - - - free(send_request_array); - free(recv_request_array); - free(send_status_array); - free(recv_status_array); + delete[] send_request_array; + delete[] recv_request_array; + delete[] send_status_array; + delete[] recv_status_array; //printf("node %d done\n",rank); } /* end pipeline */ diff --git a/src/smpi/colls/reduce/reduce-mvapich-knomial.cpp b/src/smpi/colls/reduce/reduce-mvapich-knomial.cpp index 25b6757a22..02328fbef6 100644 --- a/src/smpi/colls/reduce/reduce-mvapich-knomial.cpp +++ b/src/smpi/colls/reduce/reduce-mvapich-knomial.cpp @@ -136,9 +136,6 @@ int Coll_reduce_mvapich2_knomial::reduce ( MPI_Status status; int recv_iter=0, dst=-1, expected_send_count, expected_recv_count; int *src_array=NULL; - void **tmp_buf=NULL; - MPI_Request *requests=NULL; - if (count == 0) return MPI_SUCCESS; @@ -176,11 +173,11 @@ int Coll_reduce_mvapich2_knomial::reduce ( &dst, &expected_send_count, &expected_recv_count, &src_array); if(expected_recv_count > 0 ) { - tmp_buf = static_cast(xbt_malloc(sizeof(void *)*expected_recv_count)); - requests = static_cast(xbt_malloc(sizeof(MPI_Request)*expected_recv_count)); - for(k=0; k < expected_recv_count; k++ ) { - tmp_buf[k] = smpi_get_tmp_sendbuffer(count * std::max(extent, true_extent)); - tmp_buf[k] = (void *)((char*)tmp_buf[k] - true_lb); + void** tmp_buf = new void*[expected_recv_count]; + MPI_Request* requests = new MPI_Request[expected_recv_count]; + for (k = 0; k < expected_recv_count; k++) { + tmp_buf[k] = smpi_get_tmp_sendbuffer(count * std::max(extent, true_extent)); + tmp_buf[k] = (void*)((char*)tmp_buf[k] - true_lb); } while(recv_iter < expected_recv_count) { @@ -206,8 +203,8 @@ int Coll_reduce_mvapich2_knomial::reduce ( for(k=0; k < expected_recv_count; k++ ) { smpi_free_tmp_buffer(tmp_buf[k]); } - xbt_free(tmp_buf); - xbt_free(requests); + delete[] tmp_buf; + delete[] requests; } if(src_array != NULL) { diff --git a/src/smpi/colls/reduce/reduce-scatter-gather.cpp b/src/smpi/colls/reduce/reduce-scatter-gather.cpp index 5bfa4edff5..07eb4bdd30 100644 --- a/src/smpi/colls/reduce/reduce-scatter-gather.cpp +++ b/src/smpi/colls/reduce/reduce-scatter-gather.cpp @@ -75,8 +75,8 @@ int Coll_reduce_scatter_gather::reduce(const 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++) @@ -252,8 +252,8 @@ int Coll_reduce_scatter_gather::reduce(const 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++) @@ -404,10 +404,8 @@ int Coll_reduce_scatter_gather::reduce(const 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); + delete[] cnts; + delete[] disps; return 0; } diff --git a/src/smpi/colls/reduce_scatter/reduce_scatter-mpich.cpp b/src/smpi/colls/reduce_scatter/reduce_scatter-mpich.cpp index 1b590b7802..74bc22566a 100644 --- a/src/smpi/colls/reduce_scatter/reduce_scatter-mpich.cpp +++ b/src/smpi/colls/reduce_scatter/reduce_scatter-mpich.cpp @@ -29,7 +29,6 @@ int Coll_reduce_scatter_mpich_pair::reduce_scatter(const void *sendbuf, void *re { int rank, comm_size, i; MPI_Aint extent, true_extent, true_lb; - int *disps; void *tmp_recvbuf; int mpi_errno = MPI_SUCCESS; int total_count, dst, src; @@ -44,7 +43,7 @@ int Coll_reduce_scatter_mpich_pair::reduce_scatter(const void *sendbuf, void *re is_commutative = 1; } - disps = (int*)xbt_malloc( comm_size * sizeof(int)); + int* disps = new int[comm_size]; total_count = 0; for (i=0; i= 0) { - int *tmp_disps = NULL, *tmp_rcounts = NULL; int mask, send_index, recv_index, last_index; /* recalculate disps and rcounts to account for the special "remainder" processes that are no longer doing anything */ - tmp_rcounts = (int*) xbt_malloc(tmp_size * sizeof(int)); - if (NULL == tmp_rcounts) { - err = MPI_ERR_OTHER; - goto cleanup; - } - tmp_disps = (int*) xbt_malloc(tmp_size * sizeof(int)); - if (NULL == tmp_disps) { - xbt_free(tmp_rcounts); - err = MPI_ERR_OTHER; - goto cleanup; - } + int* tmp_rcounts = new int[tmp_size]; + int* tmp_disps = new int[tmp_size]; for (i = 0 ; i < tmp_size ; ++i) { if (i < remain) { @@ -221,9 +210,9 @@ Coll_reduce_scatter_ompi_basic_recursivehalving::reduce_scatter(const void *sbuf COLL_TAG_REDUCE_SCATTER, comm); if (MPI_SUCCESS != err) { - xbt_free(tmp_rcounts); - xbt_free(tmp_disps); - goto cleanup; + delete[] tmp_rcounts; + delete[] tmp_disps; + goto cleanup; } } if (recv_count > 0 && send_count != 0) { @@ -232,9 +221,9 @@ Coll_reduce_scatter_ompi_basic_recursivehalving::reduce_scatter(const void *sbuf COLL_TAG_REDUCE_SCATTER, comm); if (MPI_SUCCESS != err) { - xbt_free(tmp_rcounts); - xbt_free(tmp_disps); - goto cleanup; + delete[] tmp_rcounts; + delete[] tmp_disps; + goto cleanup; } } if (send_count > 0 && recv_count != 0) { @@ -262,14 +251,14 @@ Coll_reduce_scatter_ompi_basic_recursivehalving::reduce_scatter(const void *sbuf rcounts[rank], dtype, rbuf, rcounts[rank], dtype); if (MPI_SUCCESS != err) { - xbt_free(tmp_rcounts); - xbt_free(tmp_disps); - goto cleanup; + delete[] tmp_rcounts; + delete[] tmp_disps; + goto cleanup; } } - xbt_free(tmp_rcounts); - xbt_free(tmp_disps); + delete[] tmp_rcounts; + delete[] tmp_disps; } /* Now fix up the non-power of two case, by having the odd @@ -292,7 +281,7 @@ Coll_reduce_scatter_ompi_basic_recursivehalving::reduce_scatter(const void *sbuf } cleanup: - if (NULL != disps) xbt_free(disps); + delete[] disps; if (NULL != recv_buf_free) smpi_free_tmp_buffer(recv_buf_free); if (NULL != result_buf_free) smpi_free_tmp_buffer(result_buf_free); @@ -369,7 +358,7 @@ Coll_reduce_scatter_ompi_ring::reduce_scatter(const void *sbuf, void *rbuf, cons ) { int ret, line, rank, size, i, k, recv_from, send_to, total_count, max_block_count; - int inbi, *displs = NULL; + int inbi; char *tmpsend = NULL, *tmprecv = NULL, *accumbuf = NULL, *accumbuf_free = NULL; char *inbuf_free[2] = {NULL, NULL}, *inbuf[2] = {NULL, NULL}; ptrdiff_t true_lb, true_extent, lb, extent, max_real_segsize; @@ -384,8 +373,8 @@ Coll_reduce_scatter_ompi_ring::reduce_scatter(const void *sbuf, void *rbuf, cons /* Determine the maximum number of elements per node, corresponding block size, and displacements array. */ - displs = (int*) xbt_malloc(size * sizeof(int)); - if (NULL == displs) { ret = -1; line = __LINE__; goto error_hndl; } + int* displs = new int[size]; + displs[0] = 0; total_count = rcounts[0]; max_block_count = rcounts[0]; @@ -401,7 +390,7 @@ Coll_reduce_scatter_ompi_ring::reduce_scatter(const void *sbuf, void *rbuf, cons ret = Datatype::copy((char*)sbuf, total_count, dtype, (char*)rbuf, total_count, dtype); if (ret < 0) { line = __LINE__; goto error_hndl; } } - xbt_free(displs); + delete[] displs; return MPI_SUCCESS; } @@ -505,7 +494,7 @@ Coll_reduce_scatter_ompi_ring::reduce_scatter(const void *sbuf, void *rbuf, cons ret = Datatype::copy(tmprecv, rcounts[rank], dtype, (char*)rbuf, rcounts[rank], dtype); if (ret < 0) { line = __LINE__; goto error_hndl; } - if (NULL != displs) xbt_free(displs); + delete[] displs; if (NULL != accumbuf_free) smpi_free_tmp_buffer(accumbuf_free); if (NULL != inbuf_free[0]) smpi_free_tmp_buffer(inbuf_free[0]); if (NULL != inbuf_free[1]) smpi_free_tmp_buffer(inbuf_free[1]); @@ -515,7 +504,7 @@ Coll_reduce_scatter_ompi_ring::reduce_scatter(const void *sbuf, void *rbuf, cons error_hndl: XBT_DEBUG( "%s:%4d\tRank %d Error occurred %d\n", __FILE__, line, rank, ret); - if (NULL != displs) xbt_free(displs); + delete[] displs; if (NULL != accumbuf_free) smpi_free_tmp_buffer(accumbuf_free); if (NULL != inbuf_free[0]) smpi_free_tmp_buffer(inbuf_free[0]); if (NULL != inbuf_free[1]) smpi_free_tmp_buffer(inbuf_free[1]); diff --git a/src/smpi/colls/scatter/scatter-mvapich-two-level.cpp b/src/smpi/colls/scatter/scatter-mvapich-two-level.cpp index c485a88601..613a3068d8 100644 --- a/src/smpi/colls/scatter/scatter-mvapich-two-level.cpp +++ b/src/smpi/colls/scatter/scatter-mvapich-two-level.cpp @@ -150,8 +150,8 @@ int Coll_scatter_mvapich2_two_level_direct::scatter(const void *sendbuf, if (root != leader_of_root) { if (leader_comm_rank == leader_root) { - displs = static_cast(xbt_malloc(sizeof(int) * leader_comm_size)); - sendcnts = static_cast(xbt_malloc(sizeof(int) * leader_comm_size)); + displs = new int[leader_comm_size]; + sendcnts = new int[leader_comm_size]; sendcnts[0] = node_sizes[0] * nbytes; displs[0] = 0; @@ -164,8 +164,8 @@ int Coll_scatter_mvapich2_two_level_direct::scatter(const void *sendbuf, leader_root, leader_comm); } else { if (leader_comm_rank == leader_root) { - displs = static_cast(xbt_malloc(sizeof(int) * leader_comm_size)); - sendcnts = static_cast(xbt_malloc(sizeof(int) * leader_comm_size)); + displs = new int[leader_comm_size]; + sendcnts = new int[leader_comm_size]; sendcnts[0] = node_sizes[0] * sendcnt; displs[0] = 0; @@ -178,8 +178,8 @@ int Coll_scatter_mvapich2_two_level_direct::scatter(const void *sendbuf, leader_comm); } if (leader_comm_rank == leader_root) { - xbt_free(displs); - xbt_free(sendcnts); + delete[] displs; + delete[] sendcnts; } } else { if (leader_of_root != root) { @@ -326,8 +326,8 @@ int Coll_scatter_mvapich2_two_level_binomial::scatter(const void *sendbuf, if (root != leader_of_root) { if (leader_comm_rank == leader_root) { - displs = static_cast(xbt_malloc(sizeof(int) * leader_comm_size)); - sendcnts = static_cast(xbt_malloc(sizeof(int) * leader_comm_size)); + displs = new int[leader_comm_size]; + sendcnts = new int[leader_comm_size]; sendcnts[0] = node_sizes[0] * nbytes; displs[0] = 0; @@ -340,8 +340,8 @@ int Coll_scatter_mvapich2_two_level_binomial::scatter(const void *sendbuf, leader_root, leader_comm); } else { if (leader_comm_rank == leader_root) { - displs = static_cast(xbt_malloc(sizeof(int) * leader_comm_size)); - sendcnts = static_cast(xbt_malloc(sizeof(int) * leader_comm_size)); + displs = new int[leader_comm_size]; + sendcnts = new int[leader_comm_size]; sendcnts[0] = node_sizes[0] * sendcnt; displs[0] = 0; @@ -354,8 +354,8 @@ int Coll_scatter_mvapich2_two_level_binomial::scatter(const void *sendbuf, leader_comm); } if (leader_comm_rank == leader_root) { - xbt_free(displs); - xbt_free(sendcnts); + delete[] displs; + delete[] sendcnts; } } else { if (leader_of_root != root) { diff --git a/src/smpi/colls/smpi_coll.cpp b/src/smpi/colls/smpi_coll.cpp index ffb2dd4504..4cd2155046 100644 --- a/src/smpi/colls/smpi_coll.cpp +++ b/src/smpi/colls/smpi_coll.cpp @@ -150,8 +150,8 @@ int Colls::scan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype data Datatype::copy(sendbuf, count, datatype, recvbuf, count, datatype); // Send/Recv buffers to/from others - MPI_Request *requests = xbt_new(MPI_Request, size - 1); - void **tmpbufs = xbt_new(void *, rank); + MPI_Request* requests = new MPI_Request[size - 1]; + void** tmpbufs = new void*[rank]; int index = 0; for (int other = 0; other < rank; other++) { tmpbufs[index] = smpi_get_tmp_sendbuffer(count * dataext); @@ -191,8 +191,8 @@ int Colls::scan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype data for(index = 0; index < size-1; index++) { Request::unref(&requests[index]); } - xbt_free(tmpbufs); - xbt_free(requests); + delete[] tmpbufs; + delete[] requests; return MPI_SUCCESS; } @@ -208,8 +208,8 @@ int Colls::exscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype da datatype->extent(&lb, &dataext); // Send/Recv buffers to/from others - MPI_Request *requests = xbt_new(MPI_Request, size - 1); - void **tmpbufs = xbt_new(void *, rank); + MPI_Request* requests = new MPI_Request[size - 1]; + void** tmpbufs = new void*[rank]; int index = 0; for (int other = 0; other < rank; other++) { tmpbufs[index] = smpi_get_tmp_sendbuffer(count * dataext); @@ -258,8 +258,8 @@ int Colls::exscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype da for(index = 0; index < size-1; index++) { Request::unref(&requests[index]); } - xbt_free(tmpbufs); - xbt_free(requests); + delete[] tmpbufs; + delete[] requests; return MPI_SUCCESS; } diff --git a/src/smpi/colls/smpi_default_selector.cpp b/src/smpi/colls/smpi_default_selector.cpp index 8c5db82f05..5b1febbe1e 100644 --- a/src/smpi/colls/smpi_default_selector.cpp +++ b/src/smpi/colls/smpi_default_selector.cpp @@ -38,7 +38,7 @@ int Coll_reduce_scatter_default::reduce_scatter(const void *sendbuf, void *recvb /* arbitrarily choose root as rank 0 */ int size = comm->size(); int count = 0; - int *displs = xbt_new(int, size); + int* displs = new int[size]; for (int i = 0; i < size; i++) { displs[i] = count; count += recvcounts[i]; @@ -48,7 +48,7 @@ int Coll_reduce_scatter_default::reduce_scatter(const void *sendbuf, void *recvb int ret = Coll_reduce_default::reduce(sendbuf, tmpbuf, count, datatype, op, 0, comm); if(ret==MPI_SUCCESS) ret = Colls::scatterv(tmpbuf, recvcounts, displs, datatype, recvbuf, recvcounts[rank], datatype, 0, comm); - xbt_free(displs); + delete[] displs; smpi_free_tmp_buffer(tmpbuf); return ret; } -- 2.20.1