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;
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;
Request::waitall(X - 1, req, MPI_STATUSES_IGNORE);
- free(req);
+ delete[] req;
return MPI_SUCCESS;
}
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;
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;
}
Request::waitall(Z - 1, req, MPI_STATUSES_IGNORE);
- free(req);
+ delete[] req;
return MPI_SUCCESS;
}
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) {
Request::wait(&srequest_array[i], &status2);
}
- free(rrequest_array);
- free(srequest_array);
+ delete[] rrequest_array;
+ delete[] srequest_array;
return MPI_SUCCESS;
}
// 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;
}
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)) {
/*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<int *>(xbt_malloc(sizeof (int) * leader_comm_size));
- recvcnts = static_cast<int *>(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;
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();
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++) {
//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)
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;
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);
}
Request::waitall(num_reqs, reqs, MPI_STATUSES_IGNORE);
- free(reqs);
+ delete[] reqs;
return MPI_SUCCESS;
}
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;
/* 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;
mask >>= 1;
}
- xbt_free(disps);
- xbt_free(cnts);
+ delete[] disps;
+ delete[] cnts;
}
}
{
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;
// 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;
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
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;
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;
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;
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;
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;
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;
int i;
int count;
MPI_Aint lb = 0, sendext = 0, recvext = 0;
- MPI_Request *requests;
/* Initialize. */
int rank = comm->rank();
static_cast<char *>(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) {
if(requests[i]!=MPI_REQUEST_NULL)
Request::unref(&requests[i]);
}
- xbt_free(requests);
+ delete[] requests;
}
return err;
}
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;
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,
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,
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;
/* 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; ii<comm_size; ii+=bblock) {
ss = comm_size-ii < bblock ? comm_size-ii : bblock;
}
}
/* --END ERROR HANDLING-- */
- xbt_free(starray);
- xbt_free(reqarray);
+ delete[] starray;
+ delete[] reqarray;
return (mpi_errno);
}
MPI_Aint lb;
MPI_Aint sendext = 0;
MPI_Aint recvext = 0;
- MPI_Request *requests;
// FIXME: check implementation
rank = comm->rank();
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<size; ii+=bblock) {
- requests = xbt_new(MPI_Request, 2 * (bblock ));
+ ss = size - ii < bblock ? size - ii : bblock;
+ count = 0;
- ss = size-ii < bblock ? size-ii : bblock;
- count = 0;
-
- /* 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);
- 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;
}
MPI_Request *preq;
size = comm->size();
rank = comm->rank();
- MPI_Request *ireqs= static_cast<MPI_Request*>(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);
if(ireqs[i]!=MPI_REQUEST_NULL)
Request::unref(&ireqs[i]);
}
- free(ireqs);
+ delete[] ireqs;
return MPI_SUCCESS;
}
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();
// 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) {
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 */
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;
/* 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) {
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 */
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;
/* 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) {
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 */
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;
// 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) {
}
}
- 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
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;
}
// 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) {
}
}
}
- 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
{
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];
/* 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) {
}
}
- 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 */
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];
}
/* 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();
}
- 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 */
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++) {
}
- free(request_array);
- free(status_array);
+ delete[] request_array;
+ delete[] status_array;
return MPI_SUCCESS;
}
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;
}
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++) {
// wait on all requests
Request::waitall(num_procs - 1, reqs, MPI_STATUSES_IGNORE);
- free(reqs);
+ delete[] reqs;
}
return MPI_SUCCESS;
}
{
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){
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) {
mask /= mv2_intra_node_knomial_factor;
}
}
- xbt_free(reqarray);
- xbt_free(starray);
+ delete[] reqarray;
+ delete[] starray;
return mpi_errno;
}
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();
}
// 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;
next_src = (num_procs + next_src - 1) % num_procs;
}
-
- free(recv_counts);
- free(disps);
+ delete[] recv_counts;
+ delete[] disps;
return MPI_SUCCESS;
}
}
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);
+ }
}
}
fn_exit:
-/* xbt_free(tmp_buf);*/
- return mpi_errno;
+ /* delete[] static_cast<unsigned char*>(tmp_buf); */
+ return mpi_errno;
}
}
node_sizes = comm->get_non_uniform_map();
if (leader_comm_rank == leader_root) {
- displs = static_cast<int*>(xbt_malloc(sizeof(int) * leader_comm_size));
- recvcnts = static_cast<int*>(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) {
leader_root, leader_comm);
}
if (leader_comm_rank == leader_root) {
- xbt_free(displs);
- xbt_free(recvcnts);
+ delete[] displs;
+ delete[] recvcnts;
}
}
} else {
{
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;
/* 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) {
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 */
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];
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;
}
} /* 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 */
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;
&dst, &expected_send_count, &expected_recv_count, &src_array);
if(expected_recv_count > 0 ) {
- tmp_buf = static_cast<void**>(xbt_malloc(sizeof(void *)*expected_recv_count));
- requests = static_cast<MPI_Request*>(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) {
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) {
} 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++)
} 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++)
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;
}
{
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;
is_commutative = 1;
}
- disps = (int*)xbt_malloc( comm_size * sizeof(int));
+ int* disps = new int[comm_size];
total_count = 0;
for (i=0; i<comm_size; i++) {
}
if (total_count == 0) {
- xbt_free(disps);
- return MPI_ERR_COUNT;
+ delete[] disps;
+ return MPI_ERR_COUNT;
}
if (sendbuf != MPI_IN_PLACE) {
if (mpi_errno) return(mpi_errno);
}
- xbt_free(disps);
+ delete[] disps;
smpi_free_tmp_buffer(tmp_recvbuf);
return MPI_SUCCESS;
{
int rank, comm_size, i;
MPI_Aint extent, true_extent, true_lb;
- int *disps;
void *tmp_recvbuf, *tmp_results;
int mpi_errno = MPI_SUCCESS;
int dis[2], blklens[2], total_count, dst;
is_commutative = 1;
}
- disps = (int*)xbt_malloc( comm_size * sizeof(int));
+ int* disps = new int[comm_size];
total_count = 0;
for (i=0; i<comm_size; i++) {
recvcounts[rank], datatype);
if (mpi_errno) return(mpi_errno);
- xbt_free(disps);
+ delete[] disps;
smpi_free_tmp_buffer(tmp_recvbuf);
smpi_free_tmp_buffer(tmp_results);
return MPI_SUCCESS;
)
{
int i, rank, size, count, err = MPI_SUCCESS;
- int tmp_size=1, remain = 0, tmp_rank, *disps = NULL;
+ int tmp_size = 1, remain = 0, tmp_rank;
ptrdiff_t true_lb, true_extent, lb, extent, buf_size;
char *recv_buf = NULL, *recv_buf_free = NULL;
char *result_buf = NULL, *result_buf_free = NULL;
THROWF(arg_error,0, " reduce_scatter ompi_basic_recursivehalving can only be used for commutative operations! ");
/* Find displacements and the like */
- disps = (int*) xbt_malloc(sizeof(int) * size);
- if (NULL == disps) return MPI_ERR_OTHER;
+ int* disps = new int[size];
disps[0] = 0;
for (i = 0; i < (size - 1); ++i) {
/* short cut the trivial case */
if (0 == count) {
- xbt_free(disps);
- return MPI_SUCCESS;
+ delete[] disps;
+ return MPI_SUCCESS;
}
/* get datatype information */
/* For ranks not kicked out by the above code, perform the
recursive halving */
if (tmp_rank >= 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) {
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) {
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) {
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
}
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);
)
{
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;
/* 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];
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;
}
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]);
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]);
if (root != leader_of_root) {
if (leader_comm_rank == leader_root) {
- displs = static_cast<int*>(xbt_malloc(sizeof(int) * leader_comm_size));
- sendcnts = static_cast<int*>(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;
leader_root, leader_comm);
} else {
if (leader_comm_rank == leader_root) {
- displs = static_cast<int*>(xbt_malloc(sizeof(int) * leader_comm_size));
- sendcnts = static_cast<int*>(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;
leader_comm);
}
if (leader_comm_rank == leader_root) {
- xbt_free(displs);
- xbt_free(sendcnts);
+ delete[] displs;
+ delete[] sendcnts;
}
} else {
if (leader_of_root != root) {
if (root != leader_of_root) {
if (leader_comm_rank == leader_root) {
- displs = static_cast<int*>(xbt_malloc(sizeof(int) * leader_comm_size));
- sendcnts = static_cast<int*>(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;
leader_root, leader_comm);
} else {
if (leader_comm_rank == leader_root) {
- displs = static_cast<int*>(xbt_malloc(sizeof(int) * leader_comm_size));
- sendcnts = static_cast<int*>(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;
leader_comm);
}
if (leader_comm_rank == leader_root) {
- xbt_free(displs);
- xbt_free(sendcnts);
+ delete[] displs;
+ delete[] sendcnts;
}
} else {
if (leader_of_root != root) {
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);
for(index = 0; index < size-1; index++) {
Request::unref(&requests[index]);
}
- xbt_free(tmpbufs);
- xbt_free(requests);
+ delete[] tmpbufs;
+ delete[] requests;
return MPI_SUCCESS;
}
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);
for(index = 0; index < size-1; index++) {
Request::unref(&requests[index]);
}
- xbt_free(tmpbufs);
- xbt_free(requests);
+ delete[] tmpbufs;
+ delete[] requests;
return MPI_SUCCESS;
}
/* 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];
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;
}