diff --git a/ompi/mca/coll/base/coll_base_alltoallv.c b/ompi/mca/coll/base/coll_base_alltoallv.c index efe054d696f..d9f821ed28d 100644 --- a/ompi/mca/coll/base/coll_base_alltoallv.c +++ b/ompi/mca/coll/base/coll_base_alltoallv.c @@ -14,7 +14,7 @@ * Copyright (c) 2013 Los Alamos National Security, LLC. All Rights * reserved. * Copyright (c) 2013 FUJITSU LIMITED. All rights reserved. - * Copyright (c) 2014-2016 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * @@ -45,17 +45,16 @@ mca_coll_base_alltoallv_intra_basic_inplace(const void *rbuf, const int *rcounts int i, j, size, rank, err=MPI_SUCCESS; ompi_request_t *req; char *allocated_buffer, *tmp_buffer; - size_t max_size, rdtype_size; - OPAL_PTRDIFF_TYPE ext, gap; + size_t max_size; + OPAL_PTRDIFF_TYPE ext, gap = 0; /* Initialize. */ size = ompi_comm_size(comm); rank = ompi_comm_rank(comm); - ompi_datatype_type_size(rdtype, &rdtype_size); /* If only one process, we're done. */ - if (1 == size || 0 == rdtype_size) { + if (1 == size) { return MPI_SUCCESS; } @@ -67,6 +66,10 @@ mca_coll_base_alltoallv_intra_basic_inplace(const void *rbuf, const int *rcounts } /* The gap will always be the same as we are working on the same datatype */ + if (OPAL_UNLIKELY(0 == max_size)) { + return MPI_SUCCESS; + } + /* Allocate a temporary buffer */ allocated_buffer = calloc (max_size, 1); if (NULL == allocated_buffer) { @@ -78,7 +81,7 @@ mca_coll_base_alltoallv_intra_basic_inplace(const void *rbuf, const int *rcounts /* in-place alltoallv slow algorithm (but works) */ for (i = 0 ; i < size ; ++i) { for (j = i+1 ; j < size ; ++j) { - if (i == rank && rcounts[j]) { + if (i == rank && 0 != rcounts[j]) { /* Copy the data into the temporary buffer */ err = ompi_datatype_copy_content_same_ddt (rdtype, rcounts[j], tmp_buffer, (char *) rbuf + rdisps[j] * ext); @@ -93,7 +96,7 @@ mca_coll_base_alltoallv_intra_basic_inplace(const void *rbuf, const int *rcounts j, MCA_COLL_BASE_TAG_ALLTOALLV, MCA_PML_BASE_SEND_STANDARD, comm)); if (MPI_SUCCESS != err) { goto error_hndl; } - } else if (j == rank && rcounts[i]) { + } else if (j == rank && 0 != rcounts[i]) { /* Copy the data into the temporary buffer */ err = ompi_datatype_copy_content_same_ddt (rdtype, rcounts[i], tmp_buffer, (char *) rbuf + rdisps[i] * ext); diff --git a/ompi/mca/coll/libnbc/Makefile.am b/ompi/mca/coll/libnbc/Makefile.am index 4d3e90186a9..83984b1185b 100644 --- a/ompi/mca/coll/libnbc/Makefile.am +++ b/ompi/mca/coll/libnbc/Makefile.am @@ -12,6 +12,8 @@ # Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. # Copyright (c) 2013 Los Alamos National Security, LLC. All rights # reserved. +# Copyright (c) 2017 Research Organization for Information Science +# and Technology (RIST). All rights reserved. # $COPYRIGHT$ # # Additional copyrights may follow @@ -37,7 +39,6 @@ sources = \ nbc_ialltoallw.c \ nbc_ibarrier.c \ nbc_ibcast.c \ - nbc_ibcast_inter.c \ nbc_iexscan.c \ nbc_igather.c \ nbc_igatherv.c \ diff --git a/ompi/mca/coll/libnbc/nbc.c b/ompi/mca/coll/libnbc/nbc.c index 7949fe1b90f..da1f4548a04 100644 --- a/ompi/mca/coll/libnbc/nbc.c +++ b/ompi/mca/coll/libnbc/nbc.c @@ -10,7 +10,7 @@ * rights reserved. * Copyright (c) 2015 Los Alamos National Security, LLC. All rights * reserved. - * Copyright (c) 2015-2016 Research Organization for Information Science + * Copyright (c) 2015-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * * Author(s): Torsten Hoefler @@ -709,6 +709,25 @@ int NBC_Start(NBC_Handle *handle, NBC_Schedule *schedule) { return OMPI_SUCCESS; } +int NBC_Schedule_request(NBC_Schedule *schedule, ompi_communicator_t *comm, ompi_coll_libnbc_module_t *module, ompi_request_t **request, void *tmpbuf) { + int res; + NBC_Handle *handle; + res = NBC_Init_handle (comm, &handle, module); + if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { + return res; + } + handle->tmpbuf = tmpbuf; + + res = NBC_Start (handle, schedule); + if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { + NBC_Return_handle (handle); + return res; + } + + *request = (ompi_request_t *) handle; + return OMPI_SUCCESS; +} + #ifdef NBC_CACHE_SCHEDULE void NBC_SchedCache_args_delete_key_dummy(void *k) { /* do nothing because the key and the data element are identical :-) diff --git a/ompi/mca/coll/libnbc/nbc_iallgather.c b/ompi/mca/coll/libnbc/nbc_iallgather.c index 9f0fea3706d..a1b512c1822 100644 --- a/ompi/mca/coll/libnbc/nbc_iallgather.c +++ b/ompi/mca/coll/libnbc/nbc_iallgather.c @@ -50,7 +50,6 @@ int ompi_coll_libnbc_iallgather(const void* sendbuf, int sendcount, MPI_Datatype #ifdef NBC_CACHE_SCHEDULE NBC_Allgather_args *args, *found, search; #endif - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; NBC_IN_PLACE(sendbuf, recvbuf, inplace); @@ -147,20 +146,12 @@ int ompi_coll_libnbc_iallgather(const void* sendbuf, int sendcount, MPI_Datatype } #endif - res = NBC_Init_handle (comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start (handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - OMPI_COLL_LIBNBC_REQUEST_RETURN(handle); - return res; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } @@ -172,7 +163,6 @@ int ompi_coll_libnbc_iallgather_inter(const void* sendbuf, int sendcount, MPI_Da MPI_Aint rcvext; NBC_Schedule *schedule; char *rbuf; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; res = ompi_datatype_type_extent(recvtype, &rcvext); @@ -213,19 +203,11 @@ int ompi_coll_libnbc_iallgather_inter(const void* sendbuf, int sendcount, MPI_Da return res; } - res = NBC_Init_handle (comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start (handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - OMPI_COLL_LIBNBC_REQUEST_RETURN(handle); - return res; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } diff --git a/ompi/mca/coll/libnbc/nbc_iallgatherv.c b/ompi/mca/coll/libnbc/nbc_iallgatherv.c index ea3c3634403..4b9697f9040 100644 --- a/ompi/mca/coll/libnbc/nbc_iallgatherv.c +++ b/ompi/mca/coll/libnbc/nbc_iallgatherv.c @@ -11,7 +11,7 @@ * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013-2015 Los Alamos National Security, LLC. All rights * reserved. - * Copyright (c) 2014-2016 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * */ @@ -37,7 +37,6 @@ int ompi_coll_libnbc_iallgatherv(const void* sendbuf, int sendcount, MPI_Datatyp MPI_Aint rcvext; NBC_Schedule *schedule; char *rbuf, *sbuf, inplace; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; NBC_IN_PLACE(sendbuf, recvbuf, inplace); @@ -96,20 +95,12 @@ int ompi_coll_libnbc_iallgatherv(const void* sendbuf, int sendcount, MPI_Datatyp return res; } - res = NBC_Init_handle (comm, &handle, libnbc_module); + res = NBC_Schedule_request (schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start (handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - return res; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } @@ -120,7 +111,6 @@ int ompi_coll_libnbc_iallgatherv_inter(const void* sendbuf, int sendcount, MPI_D int res, rsize; MPI_Aint rcvext; NBC_Schedule *schedule; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; rsize = ompi_comm_remote_size (comm); @@ -165,19 +155,11 @@ int ompi_coll_libnbc_iallgatherv_inter(const void* sendbuf, int sendcount, MPI_D return res; } - res = NBC_Init_handle (comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start (handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - return res; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } diff --git a/ompi/mca/coll/libnbc/nbc_iallreduce.c b/ompi/mca/coll/libnbc/nbc_iallreduce.c index 0b624f90c44..f444c6aa716 100644 --- a/ompi/mca/coll/libnbc/nbc_iallreduce.c +++ b/ompi/mca/coll/libnbc/nbc_iallreduce.c @@ -21,13 +21,13 @@ #include static inline int allred_sched_diss(int rank, int p, int count, MPI_Datatype datatype, ptrdiff_t gap, const void *sendbuf, - void *recvbuf, MPI_Op op, char inplace, NBC_Schedule *schedule, NBC_Handle *handle); + void *recvbuf, MPI_Op op, char inplace, NBC_Schedule *schedule, void *tmpbuf); static inline int allred_sched_ring(int rank, int p, int count, MPI_Datatype datatype, const void *sendbuf, void *recvbuf, MPI_Op op, int size, int ext, NBC_Schedule *schedule, - NBC_Handle *handle); + void *tmpbuf); static inline int allred_sched_linear(int rank, int p, const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, ptrdiff_t gap, MPI_Op op, int ext, int size, - NBC_Schedule *schedule, NBC_Handle *handle); + NBC_Schedule *schedule, void *tmpbuf); #ifdef NBC_CACHE_SCHEDULE /* tree comparison function for schedule cache */ @@ -61,7 +61,7 @@ int ompi_coll_libnbc_iallreduce(const void* sendbuf, void* recvbuf, int count, M #endif enum { NBC_ARED_BINOMIAL, NBC_ARED_RING } alg; char inplace; - NBC_Handle *handle; + void *tmpbuf = NULL; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; ptrdiff_t span, gap; @@ -82,27 +82,24 @@ int ompi_coll_libnbc_iallreduce(const void* sendbuf, void* recvbuf, int count, M return res; } - res = NBC_Init_handle (comm, &handle, libnbc_module); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - return res; + if (1 == p) { + if (!inplace) { + /* for a single node - copy data to receivebuf */ + res = NBC_Copy(sendbuf, count, datatype, recvbuf, count, datatype, comm); + if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { + return res; + } + } + *request = &ompi_request_empty; + return OMPI_SUCCESS; } span = opal_datatype_span(&datatype->super, count, &gap); - handle->tmpbuf = malloc (span); - if (OPAL_UNLIKELY(NULL == handle->tmpbuf)) { - NBC_Return_handle (handle); + tmpbuf = malloc (span); + if (OPAL_UNLIKELY(NULL == tmpbuf)) { return OMPI_ERR_OUT_OF_RESOURCE; } - if ((p == 1) && !inplace) { - /* for a single node - copy data to receivebuf */ - res = NBC_Copy(sendbuf, count, datatype, recvbuf, count, datatype, comm); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - return res; - } - } - /* algorithm selection */ if(p < 4 || size*count < 65536 || !ompi_op_is_commute(op) || inplace) { alg = NBC_ARED_BINOMIAL; @@ -122,30 +119,29 @@ int ompi_coll_libnbc_iallreduce(const void* sendbuf, void* recvbuf, int count, M #endif schedule = OBJ_NEW(NBC_Schedule); if (NULL == schedule) { - NBC_Return_handle (handle); + free(tmpbuf); return OMPI_ERR_OUT_OF_RESOURCE; } - /* ensure the schedule is released with the handle on error */ - handle->schedule = schedule; - switch(alg) { case NBC_ARED_BINOMIAL: - res = allred_sched_diss(rank, p, count, datatype, gap, sendbuf, recvbuf, op, inplace, schedule, handle); + res = allred_sched_diss(rank, p, count, datatype, gap, sendbuf, recvbuf, op, inplace, schedule, tmpbuf); break; case NBC_ARED_RING: - res = allred_sched_ring(rank, p, count, datatype, sendbuf, recvbuf, op, size, ext, schedule, handle); + res = allred_sched_ring(rank, p, count, datatype, sendbuf, recvbuf, op, size, ext, schedule, tmpbuf); break; } if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } res = NBC_Sched_commit(schedule); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } @@ -180,15 +176,13 @@ int ompi_coll_libnbc_iallreduce(const void* sendbuf, void* recvbuf, int count, M } #endif - res = NBC_Start (handle, schedule); + res = NBC_Schedule_request (schedule, comm, libnbc_module, request, tmpbuf); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - *request = (ompi_request_t *) handle; - - /* tmpbuf is freed with the handle */ return OMPI_SUCCESS; } @@ -200,7 +194,7 @@ int ompi_coll_libnbc_iallreduce_inter(const void* sendbuf, void* recvbuf, int co size_t size; MPI_Aint ext; NBC_Schedule *schedule; - NBC_Handle *handle; + void *tmpbuf = NULL; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; ptrdiff_t span, gap; @@ -219,49 +213,40 @@ int ompi_coll_libnbc_iallreduce_inter(const void* sendbuf, void* recvbuf, int co return res; } - res = NBC_Init_handle (comm, &handle, libnbc_module); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - return res; - } - span = opal_datatype_span(&datatype->super, count, &gap); - handle->tmpbuf = malloc (span); - if (OPAL_UNLIKELY(NULL == handle->tmpbuf)) { - NBC_Return_handle (handle); + tmpbuf = malloc (span); + if (OPAL_UNLIKELY(NULL == tmpbuf)) { return OMPI_ERR_OUT_OF_RESOURCE; } schedule = OBJ_NEW(NBC_Schedule); if (OPAL_UNLIKELY(NULL == schedule)) { - NBC_Return_handle (handle); + free(tmpbuf); return OMPI_ERR_OUT_OF_RESOURCE; } - /* ensure the schedule is released with the handle on error */ - handle->schedule = schedule; - res = allred_sched_linear (rank, rsize, sendbuf, recvbuf, count, datatype, gap, op, - ext, size, schedule, handle); + ext, size, schedule, tmpbuf); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } res = NBC_Sched_commit(schedule); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - res = NBC_Start(handle, schedule); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, tmpbuf); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - *request = (ompi_request_t *) handle; - - /* tmpbuf is freed with the handle */ return OMPI_SUCCESS; } @@ -302,7 +287,7 @@ int ompi_coll_libnbc_iallreduce_inter(const void* sendbuf, void* recvbuf, int co if (vrank == root) rank = 0; \ } static inline int allred_sched_diss(int rank, int p, int count, MPI_Datatype datatype, ptrdiff_t gap, const void *sendbuf, void *recvbuf, - MPI_Op op, char inplace, NBC_Schedule *schedule, NBC_Handle *handle) { + MPI_Op op, char inplace, NBC_Schedule *schedule, void *tmpbuf) { int root, vrank, maxr, vpeer, peer, res; char *rbuf, *lbuf, *buf; int tmprbuf, tmplbuf; @@ -322,7 +307,7 @@ static inline int allred_sched_diss(int rank, int p, int count, MPI_Datatype dat rbuf = recvbuf; tmprbuf = false; if (inplace) { - res = NBC_Copy(rbuf, count, datatype, ((char *)handle->tmpbuf) - gap, count, datatype, MPI_COMM_SELF); + res = NBC_Copy(rbuf, count, datatype, ((char *)tmpbuf) - gap, count, datatype, MPI_COMM_SELF); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { return res; } @@ -341,7 +326,7 @@ static inline int allred_sched_diss(int rank, int p, int count, MPI_Datatype dat return res; } - /* this cannot be done until handle->tmpbuf is unused :-( so barrier after the op */ + /* this cannot be done until tmpbuf is unused :-( so barrier after the op */ if (firstred && !inplace) { /* perform the reduce with the senbuf */ res = NBC_Sched_op (sendbuf, false, rbuf, tmprbuf, count, datatype, op, schedule, true); @@ -417,7 +402,7 @@ static inline int allred_sched_diss(int rank, int p, int count, MPI_Datatype dat } static inline int allred_sched_ring (int r, int p, int count, MPI_Datatype datatype, const void *sendbuf, void *recvbuf, MPI_Op op, - int size, int ext, NBC_Schedule *schedule, NBC_Handle *handle) { + int size, int ext, NBC_Schedule *schedule, void *tmpbuf) { int segsize, *segsizes, *segoffsets; /* segment sizes and offsets per segment (number of segments == number of nodes */ int speer, rpeer; /* send and recvpeer */ int res = OMPI_SUCCESS; @@ -617,7 +602,7 @@ static inline int allred_sched_ring (int r, int p, int count, MPI_Datatype datat } static inline int allred_sched_linear(int rank, int rsize, const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, - ptrdiff_t gap, MPI_Op op, int ext, int size, NBC_Schedule *schedule, NBC_Handle *handle) { + ptrdiff_t gap, MPI_Op op, int ext, int size, NBC_Schedule *schedule, void *tmpbuf) { int res; if (0 == count) { diff --git a/ompi/mca/coll/libnbc/nbc_ialltoall.c b/ompi/mca/coll/libnbc/nbc_ialltoall.c index c9df894cc01..4cf83ae6306 100644 --- a/ompi/mca/coll/libnbc/nbc_ialltoall.c +++ b/ompi/mca/coll/libnbc/nbc_ialltoall.c @@ -8,7 +8,7 @@ * Copyright (c) 2013-2015 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2014 NVIDIA Corporation. All rights reserved. - * Copyright (c) 2014-2016 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * * Author(s): Torsten Hoefler @@ -24,7 +24,7 @@ static inline int a2a_sched_pairwise(int rank, int p, MPI_Aint sndext, MPI_Aint int recvcount, MPI_Datatype recvtype, MPI_Comm comm); static inline int a2a_sched_diss(int rank, int p, MPI_Aint sndext, MPI_Aint rcvext, NBC_Schedule* schedule, const void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, - int recvcount, MPI_Datatype recvtype, MPI_Comm comm, NBC_Handle *handle); + int recvcount, MPI_Datatype recvtype, MPI_Comm comm, void* tmpbuf); static inline int a2a_sched_inplace(int rank, int p, NBC_Schedule* schedule, void* buf, int count, MPI_Datatype type, MPI_Aint ext, ptrdiff_t gap, MPI_Comm comm); @@ -62,7 +62,7 @@ int ompi_coll_libnbc_ialltoall(const void* sendbuf, int sendcount, MPI_Datatype #endif char *rbuf, *sbuf, inplace; enum {NBC_A2A_LINEAR, NBC_A2A_PAIRWISE, NBC_A2A_DISS, NBC_A2A_INPLACE} alg; - NBC_Handle *handle; + void *tmpbuf = NULL; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; ptrdiff_t span, gap; @@ -115,17 +115,11 @@ int ompi_coll_libnbc_ialltoall(const void* sendbuf, int sendcount, MPI_Datatype } } - res = NBC_Init_handle(comm, &handle, libnbc_module); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - return res; - } - /* allocate temp buffer if we need one */ if (alg == NBC_A2A_INPLACE) { span = opal_datatype_span(&recvtype->super, recvcount, &gap); - handle->tmpbuf = malloc(span); - if (OPAL_UNLIKELY(NULL == handle->tmpbuf)) { - NBC_Return_handle (handle); + tmpbuf = malloc(span); + if (OPAL_UNLIKELY(NULL == tmpbuf)) { return OMPI_ERR_OUT_OF_RESOURCE; } } else if (alg == NBC_A2A_DISS) { @@ -136,21 +130,19 @@ int ompi_coll_libnbc_ialltoall(const void* sendbuf, int sendcount, MPI_Datatype res = PMPI_Pack_size (sendcount, sendtype, comm, &datasize); if (MPI_SUCCESS != res) { NBC_Error("MPI Error in PMPI_Pack_size() (%i)", res); - NBC_Return_handle (handle); return res; } } /* allocate temporary buffers */ if ((p & 1) == 0) { - handle->tmpbuf = malloc (datasize * p * 2); + tmpbuf = malloc (datasize * p * 2); } else { /* we cannot divide p by two, so alloc more to be safe ... */ - handle->tmpbuf = malloc (datasize * (p / 2 + 1) * 2 * 2); + tmpbuf = malloc (datasize * (p / 2 + 1) * 2 * 2); } - if (OPAL_UNLIKELY(NULL == handle->tmpbuf)) { - NBC_Return_handle (handle); + if (OPAL_UNLIKELY(NULL == tmpbuf)) { return OMPI_ERR_OUT_OF_RESOURCE; } @@ -161,29 +153,29 @@ int ompi_coll_libnbc_ialltoall(const void* sendbuf, int sendcount, MPI_Datatype if (NBC_Type_intrinsic(sendtype)) { #endif /* OPAL_CUDA_SUPPORT */ /* contiguous - just copy (1st copy) */ - memcpy (handle->tmpbuf, (char *) sendbuf + datasize * rank, datasize * (p - rank)); + memcpy (tmpbuf, (char *) sendbuf + datasize * rank, datasize * (p - rank)); if (rank != 0) { - memcpy ((char *) handle->tmpbuf + datasize * (p - rank), sendbuf, datasize * rank); + memcpy ((char *) tmpbuf + datasize * (p - rank), sendbuf, datasize * rank); } } else { int pos=0; /* non-contiguous - pack */ - res = PMPI_Pack ((char *) sendbuf + rank * sendcount * sndext, (p - rank) * sendcount, sendtype, handle->tmpbuf, + res = PMPI_Pack ((char *) sendbuf + rank * sendcount * sndext, (p - rank) * sendcount, sendtype, tmpbuf, (p - rank) * datasize, &pos, comm); if (OPAL_UNLIKELY(MPI_SUCCESS != res)) { NBC_Error("MPI Error in PMPI_Pack() (%i)", res); - NBC_Return_handle (handle); + free(tmpbuf); return res; } if (rank != 0) { pos = 0; - res = PMPI_Pack(sendbuf, rank * sendcount, sendtype, (char *) handle->tmpbuf + datasize * (p - rank), + res = PMPI_Pack(sendbuf, rank * sendcount, sendtype, (char *) tmpbuf + datasize * (p - rank), rank * datasize, &pos, comm); if (OPAL_UNLIKELY(MPI_SUCCESS != res)) { NBC_Error("MPI Error in PMPI_Pack() (%i)", res); - NBC_Return_handle (handle); + free(tmpbuf); return res; } } @@ -204,13 +196,10 @@ int ompi_coll_libnbc_ialltoall(const void* sendbuf, int sendcount, MPI_Datatype /* not found - generate new schedule */ schedule = OBJ_NEW(NBC_Schedule); if (OPAL_UNLIKELY(NULL == schedule)) { - NBC_Return_handle (handle); + free(tmpbuf); return OMPI_ERR_OUT_OF_RESOURCE; } - /* ensure the schedule is released with the handle on error */ - handle->schedule = schedule; - switch(alg) { case NBC_A2A_INPLACE: res = a2a_sched_inplace(rank, p, schedule, recvbuf, recvcount, recvtype, rcvext, gap, comm); @@ -219,7 +208,7 @@ int ompi_coll_libnbc_ialltoall(const void* sendbuf, int sendcount, MPI_Datatype res = a2a_sched_linear(rank, p, sndext, rcvext, schedule, sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm); break; case NBC_A2A_DISS: - res = a2a_sched_diss(rank, p, sndext, rcvext, schedule, sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm, handle); + res = a2a_sched_diss(rank, p, sndext, rcvext, schedule, sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm, tmpbuf); break; case NBC_A2A_PAIRWISE: res = a2a_sched_pairwise(rank, p, sndext, rcvext, schedule, sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm); @@ -227,13 +216,15 @@ int ompi_coll_libnbc_ialltoall(const void* sendbuf, int sendcount, MPI_Datatype } if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } res = NBC_Sched_commit(schedule); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } @@ -269,14 +260,13 @@ int ompi_coll_libnbc_ialltoall(const void* sendbuf, int sendcount, MPI_Datatype } #endif - res = NBC_Start (handle, schedule); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, tmpbuf); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } @@ -288,7 +278,6 @@ int ompi_coll_libnbc_ialltoall_inter (const void* sendbuf, int sendcount, MPI_Da MPI_Aint sndext, rcvext; NBC_Schedule *schedule; char *rbuf, *sbuf; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; rsize = ompi_comm_remote_size (comm); @@ -337,20 +326,12 @@ int ompi_coll_libnbc_ialltoall_inter (const void* sendbuf, int sendcount, MPI_Da return res; } - res = NBC_Init_handle (comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start (handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - return res; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } @@ -413,7 +394,7 @@ static inline int a2a_sched_linear(int rank, int p, MPI_Aint sndext, MPI_Aint rc static inline int a2a_sched_diss(int rank, int p, MPI_Aint sndext, MPI_Aint rcvext, NBC_Schedule* schedule, const void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, - MPI_Datatype recvtype, MPI_Comm comm, NBC_Handle *handle) { + MPI_Datatype recvtype, MPI_Comm comm, void* tmpbuf) { int res, speer, rpeer, datasize, offset, virtp; char *rbuf, *rtmpbuf, *stmpbuf; @@ -433,13 +414,13 @@ static inline int a2a_sched_diss(int rank, int p, MPI_Aint sndext, MPI_Aint rcve /* allocate temporary buffers */ if ((p & 1) == 0) { - rtmpbuf = (char *) handle->tmpbuf + datasize * p; - stmpbuf = (char *) handle->tmpbuf + datasize * (p + p / 2); + rtmpbuf = (char *)tmpbuf + datasize * p; + stmpbuf = (char *)tmpbuf + datasize * (p + p / 2); } else { /* we cannot divide p by two, so alloc more to be safe ... */ virtp = (p / 2 + 1) * 2; - rtmpbuf = (char *) handle->tmpbuf + datasize * p; - stmpbuf = (char *) handle->tmpbuf + datasize * (p + virtp / 2); + rtmpbuf = (char *)tmpbuf + datasize * p; + stmpbuf = (char *)tmpbuf + datasize * (p + virtp / 2); } /* phase 2 - communicate */ @@ -451,7 +432,7 @@ static inline int a2a_sched_diss(int rank, int p, MPI_Aint sndext, MPI_Aint rcve /* copy data to sendbuffer (2nd copy) - could be avoided using iovecs */ /*printf("[%i] round %i: copying element %i to buffer %lu\n", rank, r, i, (unsigned long)(stmpbuf+offset));*/ res = NBC_Sched_copy((void *)(intptr_t)(i * datasize), true, datasize, MPI_BYTE, stmpbuf + offset - - (intptr_t) handle->tmpbuf, true, datasize, MPI_BYTE, schedule, false); + (intptr_t)tmpbuf, true, datasize, MPI_BYTE, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { return res; } @@ -463,12 +444,12 @@ static inline int a2a_sched_diss(int rank, int p, MPI_Aint sndext, MPI_Aint rcve /* add p because modulo does not work with negative values */ rpeer = ((rank - r) + p) % p; - res = NBC_Sched_recv (rtmpbuf - (intptr_t) handle->tmpbuf, true, offset, MPI_BYTE, rpeer, schedule, false); + res = NBC_Sched_recv (rtmpbuf - (intptr_t)tmpbuf, true, offset, MPI_BYTE, rpeer, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { return res; } - res = NBC_Sched_send (stmpbuf - (intptr_t) handle->tmpbuf, true, offset, MPI_BYTE, speer, schedule, true); + res = NBC_Sched_send (stmpbuf - (intptr_t)tmpbuf, true, offset, MPI_BYTE, speer, schedule, true); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { return res; } @@ -479,7 +460,7 @@ static inline int a2a_sched_diss(int rank, int p, MPI_Aint sndext, MPI_Aint rcve /* test if bit r is set in rank number i */ if (i & r) { /* copy data to tmpbuffer (3rd copy) - could be avoided using iovecs */ - res = NBC_Sched_copy (rtmpbuf + offset - (intptr_t) handle->tmpbuf, true, datasize, MPI_BYTE, + res = NBC_Sched_copy (rtmpbuf + offset - (intptr_t)tmpbuf, true, datasize, MPI_BYTE, (void *)(intptr_t)(i * datasize), true, datasize, MPI_BYTE, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { @@ -491,8 +472,7 @@ static inline int a2a_sched_diss(int rank, int p, MPI_Aint sndext, MPI_Aint rcve } } - /* phase 3 - reorder - data is now in wrong order in handle->tmpbuf - - * reorder it into recvbuf */ + /* phase 3 - reorder - data is now in wrong order in tmpbuf - reorder it into recvbuf */ for (int i = 0 ; i < p; ++i) { rbuf = (char *) recvbuf + ((rank - i + p) % p) * recvcount * rcvext; res = NBC_Sched_unpack ((void *)(intptr_t) (i * datasize), true, recvcount, recvtype, rbuf, false, schedule, diff --git a/ompi/mca/coll/libnbc/nbc_ialltoallv.c b/ompi/mca/coll/libnbc/nbc_ialltoallv.c index d39838124d8..6d187b51b97 100644 --- a/ompi/mca/coll/libnbc/nbc_ialltoallv.c +++ b/ompi/mca/coll/libnbc/nbc_ialltoallv.c @@ -5,7 +5,7 @@ * Corporation. All rights reserved. * Copyright (c) 2006 The Technical University of Chemnitz. All * rights reserved. - * Copyright (c) 2014-2016 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2015 Los Alamos National Security, LLC. All rights * reserved. @@ -46,7 +46,7 @@ int ompi_coll_libnbc_ialltoallv(const void* sendbuf, const int *sendcounts, cons NBC_Schedule *schedule; char *rbuf, *sbuf, inplace; ptrdiff_t gap, span; - NBC_Handle *handle; + void * tmpbuf = NULL; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; NBC_IN_PLACE(sendbuf, recvbuf, inplace); @@ -60,11 +60,6 @@ int ompi_coll_libnbc_ialltoallv(const void* sendbuf, const int *sendcounts, cons return res; } - res = NBC_Init_handle (comm, &handle, libnbc_module); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - return res; - } - /* copy data to receivbuffer */ if (inplace) { int count = 0; @@ -74,9 +69,12 @@ int ompi_coll_libnbc_ialltoallv(const void* sendbuf, const int *sendcounts, cons } } span = opal_datatype_span(&recvtype->super, count, &gap); - handle->tmpbuf = malloc(span); - if (OPAL_UNLIKELY(NULL == handle->tmpbuf)) { - NBC_Return_handle (handle); + if (OPAL_UNLIKELY(0 == span)) { + *request = &ompi_request_empty; + return MPI_SUCCESS; + } + tmpbuf = malloc(span); + if (OPAL_UNLIKELY(NULL == tmpbuf)) { return OMPI_ERR_OUT_OF_RESOURCE; } sendcounts = recvcounts; @@ -99,7 +97,7 @@ int ompi_coll_libnbc_ialltoallv(const void* sendbuf, const int *sendcounts, cons schedule = OBJ_NEW(NBC_Schedule); if (OPAL_UNLIKELY(NULL == schedule)) { - NBC_Return_handle (handle); + free(tmpbuf); return OMPI_ERR_OUT_OF_RESOURCE; } @@ -113,27 +111,25 @@ int ompi_coll_libnbc_ialltoallv(const void* sendbuf, const int *sendcounts, cons recvbuf, recvcounts, rdispls, rcvext, recvtype); } if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); OBJ_RELEASE(schedule); + free(tmpbuf); return res; } res = NBC_Sched_commit (schedule); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - res = NBC_Start(handle, schedule); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, tmpbuf); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } @@ -146,7 +142,6 @@ int ompi_coll_libnbc_ialltoallv_inter (const void* sendbuf, const int *sendcount int res, rsize; MPI_Aint sndext, rcvext; NBC_Schedule *schedule; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; @@ -196,21 +191,12 @@ int ompi_coll_libnbc_ialltoallv_inter (const void* sendbuf, const int *sendcount return res; } - res = NBC_Init_handle(comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start(handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - OBJ_RELEASE(schedule); - return res; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } @@ -336,13 +322,15 @@ static inline int a2av_sched_inplace(int rank, int p, NBC_Schedule *schedule, if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { return res; } - res = NBC_Sched_send ((void *)(-gap), true , counts[peer], type, peer, schedule, false); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - return res; - } - res = NBC_Sched_recv (tbuf, false , counts[peer], type, peer, schedule, true); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - return res; + if (0 != counts[peer]) { + res = NBC_Sched_send ((void *)(-gap), true , counts[peer], type, peer, schedule, false); + if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { + return res; + } + res = NBC_Sched_recv (tbuf, false , counts[peer], type, peer, schedule, true); + if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { + return res; + } } } diff --git a/ompi/mca/coll/libnbc/nbc_ialltoallw.c b/ompi/mca/coll/libnbc/nbc_ialltoallw.c index ec29a3a355f..1e095a65234 100644 --- a/ompi/mca/coll/libnbc/nbc_ialltoallw.c +++ b/ompi/mca/coll/libnbc/nbc_ialltoallw.c @@ -5,7 +5,7 @@ * Corporation. All rights reserved. * Copyright (c) 2006 The Technical University of Chemnitz. All * rights reserved. - * Copyright (c) 2014-2016 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2015 Los Alamos National Security, LLC. All rights * reserved. @@ -45,7 +45,7 @@ int ompi_coll_libnbc_ialltoallw(const void* sendbuf, const int *sendcounts, cons NBC_Schedule *schedule; char *rbuf, *sbuf, inplace; ptrdiff_t span=0; - NBC_Handle *handle; + void *tmpbuf = NULL; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; NBC_IN_PLACE(sendbuf, recvbuf, inplace); @@ -53,11 +53,6 @@ int ompi_coll_libnbc_ialltoallw(const void* sendbuf, const int *sendcounts, cons rank = ompi_comm_rank (comm); p = ompi_comm_size (comm); - res = NBC_Init_handle (comm, &handle, libnbc_module); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - return res; - } - /* copy data to receivbuffer */ if (inplace) { ptrdiff_t lgap, lspan; @@ -67,9 +62,12 @@ int ompi_coll_libnbc_ialltoallw(const void* sendbuf, const int *sendcounts, cons span = lspan; } } - handle->tmpbuf = malloc(span); - if (OPAL_UNLIKELY(NULL == handle->tmpbuf)) { - NBC_Return_handle (handle); + if (OPAL_UNLIKELY(0 == span)) { + *request = &ompi_request_empty; + return OMPI_SUCCESS; + } + tmpbuf = malloc(span); + if (OPAL_UNLIKELY(NULL == tmpbuf)) { return OMPI_ERR_OUT_OF_RESOURCE; } sendcounts = recvcounts; @@ -86,7 +84,7 @@ int ompi_coll_libnbc_ialltoallw(const void* sendbuf, const int *sendcounts, cons schedule = OBJ_NEW(NBC_Schedule); if (OPAL_UNLIKELY(NULL == schedule)) { - NBC_Return_handle (handle); + free(tmpbuf); return OMPI_ERR_OUT_OF_RESOURCE; } @@ -99,26 +97,25 @@ int ompi_coll_libnbc_ialltoallw(const void* sendbuf, const int *sendcounts, cons recvbuf, recvcounts, rdispls, recvtypes); } if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); OBJ_RELEASE(schedule); + free(tmpbuf); return res; } res = NBC_Sched_commit (schedule); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - res = NBC_Start (handle, schedule); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, tmpbuf); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } @@ -131,7 +128,6 @@ int ompi_coll_libnbc_ialltoallw_inter (const void* sendbuf, const int *sendcount int res, rsize; NBC_Schedule *schedule; char *rbuf, *sbuf; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; rsize = ompi_comm_remote_size (comm); @@ -168,20 +164,12 @@ int ompi_coll_libnbc_ialltoallw_inter (const void* sendbuf, const int *sendcount return res; } - res = NBC_Init_handle (comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start (handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - return res; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } @@ -193,12 +181,14 @@ static inline int a2aw_sched_linear(int rank, int p, NBC_Schedule *schedule, int res; for (int i = 0; i < p; i++) { + ptrdiff_t gap, span; if (i == rank) { continue; } /* post send */ - if (sendcounts[i] != 0) { + span = opal_datatype_span(&sendtypes[i]->super, sendcounts[i], &gap); + if (OPAL_LIKELY(0 < span)) { char *sbuf = (char *) sendbuf + sdispls[i]; res = NBC_Sched_send (sbuf, false, sendcounts[i], sendtypes[i], i, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { @@ -206,7 +196,8 @@ static inline int a2aw_sched_linear(int rank, int p, NBC_Schedule *schedule, } } /* post receive */ - if (recvcounts[i] != 0) { + span = opal_datatype_span(&recvtypes[i]->super, recvcounts[i], &gap); + if (OPAL_LIKELY(0 < span)) { char *rbuf = (char *) recvbuf + rdispls[i]; res = NBC_Sched_recv (rbuf, false, recvcounts[i], recvtypes[i], i, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { diff --git a/ompi/mca/coll/libnbc/nbc_ibarrier.c b/ompi/mca/coll/libnbc/nbc_ibarrier.c index 9d2c2f2c450..97838c549c5 100644 --- a/ompi/mca/coll/libnbc/nbc_ibarrier.c +++ b/ompi/mca/coll/libnbc/nbc_ibarrier.c @@ -7,7 +7,7 @@ * rights reserved. * Copyright (c) 2013-2015 Los Alamos National Security, LLC. All rights * reserved. - * Copyright (c) 2014 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2015 Mellanox Technologies. All rights reserved. * diff --git a/ompi/mca/coll/libnbc/nbc_ibcast.c b/ompi/mca/coll/libnbc/nbc_ibcast.c index 840e6cdce9b..229a783ab63 100644 --- a/ompi/mca/coll/libnbc/nbc_ibcast.c +++ b/ompi/mca/coll/libnbc/nbc_ibcast.c @@ -52,7 +52,6 @@ int ompi_coll_libnbc_ibcast(void *buffer, int count, MPI_Datatype datatype, int NBC_Bcast_args *args, *found, search; #endif enum { NBC_BCAST_LINEAR, NBC_BCAST_BINOMIAL, NBC_BCAST_CHAIN } alg; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; rank = ompi_comm_rank (comm); @@ -155,20 +154,12 @@ int ompi_coll_libnbc_ibcast(void *buffer, int count, MPI_Datatype datatype, int } #endif - res = NBC_Init_handle (comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start (handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - return res; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } @@ -323,3 +314,55 @@ static inline int bcast_sched_chain(int rank, int p, int root, NBC_Schedule *sch return OMPI_SUCCESS; } + +int ompi_coll_libnbc_ibcast_inter(void *buffer, int count, MPI_Datatype datatype, int root, + struct ompi_communicator_t *comm, ompi_request_t ** request, + struct mca_coll_base_module_2_1_0_t *module) { + int res; + NBC_Schedule *schedule; + ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; + + schedule = OBJ_NEW(NBC_Schedule); + if (OPAL_UNLIKELY(NULL == schedule)) { + return OMPI_ERR_OUT_OF_RESOURCE; + } + + if (root != MPI_PROC_NULL) { + /* send to all others */ + if (root == MPI_ROOT) { + int remsize; + + remsize = ompi_comm_remote_size (comm); + + for (int peer = 0 ; peer < remsize ; ++peer) { + /* send msg to peer */ + res = NBC_Sched_send (buffer, false, count, datatype, peer, schedule, false); + if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { + OBJ_RELEASE(schedule); + return res; + } + } + } else { + /* recv msg from root */ + res = NBC_Sched_recv (buffer, false, count, datatype, root, schedule, false); + if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { + OBJ_RELEASE(schedule); + return res; + } + } + } + + res = NBC_Sched_commit (schedule); + if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { + OBJ_RELEASE(schedule); + return res; + } + + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); + if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { + OBJ_RELEASE(schedule); + return res; + } + + return OMPI_SUCCESS; +} diff --git a/ompi/mca/coll/libnbc/nbc_ibcast_inter.c b/ompi/mca/coll/libnbc/nbc_ibcast_inter.c deleted file mode 100644 index 8188ec65732..00000000000 --- a/ompi/mca/coll/libnbc/nbc_ibcast_inter.c +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- Mode: C; c-basic-offset:2 ; indent-tabs-mode:nil -*- */ -/* - * Copyright (c) 2006 The Trustees of Indiana University and Indiana - * University Research and Technology - * Corporation. All rights reserved. - * Copyright (c) 2006 The Technical University of Chemnitz. All - * rights reserved. - * Copyright (c) 2014-2015 Research Organization for Information Science - * and Technology (RIST). All rights reserved. - * Copyright (c) 2015 Los Alamos National Security, LLC. All rights - * reserved. - * - * Author(s): Torsten Hoefler - * - */ -#include "nbc_internal.h" - -int ompi_coll_libnbc_ibcast_inter(void *buffer, int count, MPI_Datatype datatype, int root, - struct ompi_communicator_t *comm, ompi_request_t ** request, - struct mca_coll_base_module_2_1_0_t *module) { - int res; - NBC_Schedule *schedule; - NBC_Handle *handle; - ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; - - schedule = OBJ_NEW(NBC_Schedule); - if (OPAL_UNLIKELY(NULL == schedule)) { - return OMPI_ERR_OUT_OF_RESOURCE; - } - - if (root != MPI_PROC_NULL) { - /* send to all others */ - if (root == MPI_ROOT) { - int remsize; - - remsize = ompi_comm_remote_size (comm); - - for (int peer = 0 ; peer < remsize ; ++peer) { - /* send msg to peer */ - res = NBC_Sched_send (buffer, false, count, datatype, peer, schedule, false); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - OBJ_RELEASE(schedule); - return res; - } - } - } else { - /* recv msg from root */ - res = NBC_Sched_recv (buffer, false, count, datatype, root, schedule, false); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - OBJ_RELEASE(schedule); - return res; - } - } - } - - res = NBC_Sched_commit (schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - OBJ_RELEASE(schedule); - return res; - } - - res = NBC_Init_handle (comm, &handle, libnbc_module); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - OBJ_RELEASE(schedule); - return res; - } - - res = NBC_Start(handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - return res; - } - - *request = (ompi_request_t *) handle; - - return OMPI_SUCCESS; -} diff --git a/ompi/mca/coll/libnbc/nbc_iexscan.c b/ompi/mca/coll/libnbc/nbc_iexscan.c index d43edebcc60..d1245caa636 100644 --- a/ompi/mca/coll/libnbc/nbc_iexscan.c +++ b/ompi/mca/coll/libnbc/nbc_iexscan.c @@ -7,7 +7,7 @@ * rights reserved. * Copyright (c) 2013-2015 Los Alamos National Security, LLC. All rights * reserved. - * Copyright (c) 2014-2015 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * * Author(s): Torsten Hoefler @@ -51,7 +51,7 @@ int ompi_coll_libnbc_iexscan(const void* sendbuf, void* recvbuf, int count, MPI_ NBC_Scan_args *args, *found, search; #endif char inplace; - NBC_Handle *handle; + void *tmpbuf = NULL; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; NBC_IN_PLACE(sendbuf, recvbuf, inplace); @@ -59,25 +59,19 @@ int ompi_coll_libnbc_iexscan(const void* sendbuf, void* recvbuf, int count, MPI_ rank = ompi_comm_rank (comm); p = ompi_comm_size (comm); - res = NBC_Init_handle(comm, &handle, libnbc_module); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - return res; - } - span = opal_datatype_span(&datatype->super, count, &gap); if (0 < rank) { - handle->tmpbuf = malloc(span); - if (handle->tmpbuf == NULL) { - NBC_Return_handle (handle); + tmpbuf = malloc(span); + if (NULL == tmpbuf) { return OMPI_ERR_OUT_OF_RESOURCE; } if (inplace) { - res = NBC_Copy(recvbuf, count, datatype, (char *)handle->tmpbuf-gap, count, datatype, comm); + res = NBC_Copy(recvbuf, count, datatype, (char *)tmpbuf-gap, count, datatype, comm); } else { - res = NBC_Copy(sendbuf, count, datatype, (char *)handle->tmpbuf-gap, count, datatype, comm); + res = NBC_Copy(sendbuf, count, datatype, (char *)tmpbuf-gap, count, datatype, comm); } if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + free(tmpbuf); return res; } } @@ -94,18 +88,16 @@ int ompi_coll_libnbc_iexscan(const void* sendbuf, void* recvbuf, int count, MPI_ #endif schedule = OBJ_NEW(NBC_Schedule); if (OPAL_UNLIKELY(NULL == schedule)) { - NBC_Return_handle (handle); + free(tmpbuf); return OMPI_ERR_OUT_OF_RESOURCE; } - /* make sure the schedule is released with the handle on error */ - handle->schedule = schedule; - if (rank != 0) { res = NBC_Sched_recv (recvbuf, false, count, datatype, rank-1, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } @@ -113,7 +105,8 @@ int ompi_coll_libnbc_iexscan(const void* sendbuf, void* recvbuf, int count, MPI_ /* we have to wait until we have the data */ res = NBC_Sched_barrier(schedule); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } @@ -121,14 +114,16 @@ int ompi_coll_libnbc_iexscan(const void* sendbuf, void* recvbuf, int count, MPI_ datatype, op, schedule, true); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } /* send reduced data onward */ res = NBC_Sched_send ((void *)(-gap), true, count, datatype, rank + 1, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } } @@ -139,14 +134,16 @@ int ompi_coll_libnbc_iexscan(const void* sendbuf, void* recvbuf, int count, MPI_ res = NBC_Sched_send (sendbuf, false, count, datatype, 1, schedule, false); } if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } } res = NBC_Sched_commit(schedule); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } @@ -181,14 +178,12 @@ int ompi_coll_libnbc_iexscan(const void* sendbuf, void* recvbuf, int count, MPI_ } #endif - res = NBC_Start (handle, schedule); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, tmpbuf); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - *request = (ompi_request_t *) handle; - - /* tmpbuf is freed with the handle */ return OMPI_SUCCESS; } diff --git a/ompi/mca/coll/libnbc/nbc_igather.c b/ompi/mca/coll/libnbc/nbc_igather.c index edb334a7ea1..72b85a439e2 100644 --- a/ompi/mca/coll/libnbc/nbc_igather.c +++ b/ompi/mca/coll/libnbc/nbc_igather.c @@ -8,7 +8,7 @@ * Copyright (c) 2013 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. - * Copyright (c) 2014-2016 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2015 Los Alamos National Security, LLC. All rights * reserved. @@ -47,7 +47,6 @@ int ompi_coll_libnbc_igather(const void* sendbuf, int sendcount, MPI_Datatype se MPI_Aint rcvext = 0; NBC_Schedule *schedule; char *rbuf, inplace = 0; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; rank = ompi_comm_rank (comm); @@ -157,20 +156,12 @@ int ompi_coll_libnbc_igather(const void* sendbuf, int sendcount, MPI_Datatype se } #endif - res = NBC_Init_handle (comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start (handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - return res; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } @@ -182,7 +173,6 @@ int ompi_coll_libnbc_igather_inter (const void* sendbuf, int sendcount, MPI_Data MPI_Aint rcvext = 0; NBC_Schedule *schedule; char *rbuf; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; rsize = ompi_comm_remote_size (comm); @@ -226,19 +216,11 @@ int ompi_coll_libnbc_igather_inter (const void* sendbuf, int sendcount, MPI_Data return res; } - res = NBC_Init_handle (comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start (handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - return res; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } diff --git a/ompi/mca/coll/libnbc/nbc_igatherv.c b/ompi/mca/coll/libnbc/nbc_igatherv.c index 1b55002c4b2..15ff1c3c3ef 100644 --- a/ompi/mca/coll/libnbc/nbc_igatherv.c +++ b/ompi/mca/coll/libnbc/nbc_igatherv.c @@ -8,7 +8,7 @@ * Copyright (c) 2013 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. - * Copyright (c) 2014-2016 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2015 Los Alamos National Security, LLC. All rights * reserved. @@ -32,7 +32,6 @@ int ompi_coll_libnbc_igatherv(const void* sendbuf, int sendcount, MPI_Datatype s MPI_Aint rcvext = 0; NBC_Schedule *schedule; char *rbuf, inplace = 0; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; rank = ompi_comm_rank (comm); @@ -92,20 +91,12 @@ int ompi_coll_libnbc_igatherv(const void* sendbuf, int sendcount, MPI_Datatype s return res; } - res = NBC_Init_handle (comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start (handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - return res; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } @@ -117,7 +108,6 @@ int ompi_coll_libnbc_igatherv_inter (const void* sendbuf, int sendcount, MPI_Dat MPI_Aint rcvext; NBC_Schedule *schedule; char *rbuf; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; rsize = ompi_comm_remote_size (comm); @@ -161,19 +151,11 @@ int ompi_coll_libnbc_igatherv_inter (const void* sendbuf, int sendcount, MPI_Dat return res; } - res = NBC_Init_handle (comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start (handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - return res; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } diff --git a/ompi/mca/coll/libnbc/nbc_ineighbor_allgather.c b/ompi/mca/coll/libnbc/nbc_ineighbor_allgather.c index e9ae7b388a9..5ccdbc4356f 100644 --- a/ompi/mca/coll/libnbc/nbc_ineighbor_allgather.c +++ b/ompi/mca/coll/libnbc/nbc_ineighbor_allgather.c @@ -5,7 +5,7 @@ * Corporation. All rights reserved. * Copyright (c) 2006 The Technical University of Chemnitz. All * rights reserved. - * Copyright (c) 2014-2015 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2015 Los Alamos National Security, LLC. All rights * reserved. @@ -44,7 +44,6 @@ int ompi_coll_libnbc_ineighbor_allgather(const void *sbuf, int scount, MPI_Datat ompi_request_t ** request, struct mca_coll_base_module_2_1_0_t *module) { int res, indegree, outdegree, *srcs, *dsts; MPI_Aint rcvext; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; NBC_Schedule *schedule; @@ -149,20 +148,11 @@ int ompi_coll_libnbc_ineighbor_allgather(const void *sbuf, int scount, MPI_Datat } #endif - res = NBC_Init_handle(comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start(handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - OBJ_RELEASE(schedule); - return res; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } diff --git a/ompi/mca/coll/libnbc/nbc_ineighbor_allgatherv.c b/ompi/mca/coll/libnbc/nbc_ineighbor_allgatherv.c index 50d85ee406a..ee18644f8a5 100644 --- a/ompi/mca/coll/libnbc/nbc_ineighbor_allgatherv.c +++ b/ompi/mca/coll/libnbc/nbc_ineighbor_allgatherv.c @@ -5,7 +5,7 @@ * Corporation. All rights reserved. * Copyright (c) 2006 The Technical University of Chemnitz. All * rights reserved. - * Copyright (c) 2014-2015 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2015 Los Alamos National Security, LLC. All rights * reserved. @@ -45,7 +45,6 @@ int ompi_coll_libnbc_ineighbor_allgatherv(const void *sbuf, int scount, MPI_Data struct mca_coll_base_module_2_1_0_t *module) { int res, indegree, outdegree, *srcs, *dsts; MPI_Aint rcvext; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; NBC_Schedule *schedule; @@ -151,20 +150,11 @@ int ompi_coll_libnbc_ineighbor_allgatherv(const void *sbuf, int scount, MPI_Data } #endif - res = NBC_Init_handle(comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start (handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - OBJ_RELEASE(schedule); - return OMPI_ERR_OUT_OF_RESOURCE; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } diff --git a/ompi/mca/coll/libnbc/nbc_ineighbor_alltoall.c b/ompi/mca/coll/libnbc/nbc_ineighbor_alltoall.c index 3d8b34a1918..51e3231be87 100644 --- a/ompi/mca/coll/libnbc/nbc_ineighbor_alltoall.c +++ b/ompi/mca/coll/libnbc/nbc_ineighbor_alltoall.c @@ -5,7 +5,7 @@ * Corporation. All rights reserved. * Copyright (c) 2006 The Technical University of Chemnitz. All * rights reserved. - * Copyright (c) 2014-2015 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2015 Los Alamos National Security, LLC. All rights * reserved. @@ -41,7 +41,6 @@ int ompi_coll_libnbc_ineighbor_alltoall(const void *sbuf, int scount, MPI_Dataty ompi_request_t ** request, struct mca_coll_base_module_2_1_0_t *module) { int res, indegree, outdegree, *srcs, *dsts; MPI_Aint sndext, rcvext; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; NBC_Schedule *schedule; @@ -153,19 +152,11 @@ int ompi_coll_libnbc_ineighbor_alltoall(const void *sbuf, int scount, MPI_Dataty } #endif - res = NBC_Init_handle (comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start (handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - return OMPI_ERR_OUT_OF_RESOURCE; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } diff --git a/ompi/mca/coll/libnbc/nbc_ineighbor_alltoallv.c b/ompi/mca/coll/libnbc/nbc_ineighbor_alltoallv.c index 52983b1632b..2b30ffd9be0 100644 --- a/ompi/mca/coll/libnbc/nbc_ineighbor_alltoallv.c +++ b/ompi/mca/coll/libnbc/nbc_ineighbor_alltoallv.c @@ -5,7 +5,7 @@ * Corporation. All rights reserved. * Copyright (c) 2006 The Technical University of Chemnitz. All * rights reserved. - * Copyright (c) 2014-2015 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2015 Los Alamos National Security, LLC. All rights * reserved. @@ -45,7 +45,6 @@ int ompi_coll_libnbc_ineighbor_alltoallv(const void *sbuf, const int *scounts, c struct mca_coll_base_module_2_1_0_t *module) { int res, indegree, outdegree, *srcs, *dsts; MPI_Aint sndext, rcvext; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; NBC_Schedule *schedule; @@ -158,19 +157,11 @@ int ompi_coll_libnbc_ineighbor_alltoallv(const void *sbuf, const int *scounts, c } #endif - res = NBC_Init_handle(comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start (handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - return res; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } diff --git a/ompi/mca/coll/libnbc/nbc_ineighbor_alltoallw.c b/ompi/mca/coll/libnbc/nbc_ineighbor_alltoallw.c index 8bab6a00811..8907e7cd3a2 100644 --- a/ompi/mca/coll/libnbc/nbc_ineighbor_alltoallw.c +++ b/ompi/mca/coll/libnbc/nbc_ineighbor_alltoallw.c @@ -5,7 +5,7 @@ * Corporation. All rights reserved. * Copyright (c) 2006 The Technical University of Chemnitz. All * rights reserved. - * Copyright (c) 2014-2015 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2015 Los Alamos National Security, LLC. All rights * reserved. @@ -43,7 +43,6 @@ int ompi_coll_libnbc_ineighbor_alltoallw(const void *sbuf, const int *scounts, c struct ompi_communicator_t *comm, ompi_request_t ** request, struct mca_coll_base_module_2_1_0_t *module) { int res, indegree, outdegree, *srcs, *dsts; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; NBC_Schedule *schedule; @@ -143,19 +142,11 @@ int ompi_coll_libnbc_ineighbor_alltoallw(const void *sbuf, const int *scounts, c } #endif - res = NBC_Init_handle(comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start(handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - return res; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } diff --git a/ompi/mca/coll/libnbc/nbc_internal.h b/ompi/mca/coll/libnbc/nbc_internal.h index 915e4e232a9..33ad6dc4a4a 100644 --- a/ompi/mca/coll/libnbc/nbc_internal.h +++ b/ompi/mca/coll/libnbc/nbc_internal.h @@ -258,6 +258,7 @@ void NBC_SchedCache_args_delete_key_dummy(void *k); int NBC_Start(NBC_Handle *handle, NBC_Schedule *schedule); int NBC_Init_handle(struct ompi_communicator_t *comm, ompi_coll_libnbc_request_t **request, ompi_coll_libnbc_module_t *module); +int NBC_Schedule_request(NBC_Schedule *schedule, ompi_communicator_t *comm, ompi_coll_libnbc_module_t *module, ompi_request_t **request, void *tmpbuf); void NBC_Return_handle(ompi_coll_libnbc_request_t *request); static inline int NBC_Type_intrinsic(MPI_Datatype type); int NBC_Create_fortran_handle(int *fhandle, NBC_Handle **handle); diff --git a/ompi/mca/coll/libnbc/nbc_ireduce.c b/ompi/mca/coll/libnbc/nbc_ireduce.c index cf78d073b16..c2e730921e8 100644 --- a/ompi/mca/coll/libnbc/nbc_ireduce.c +++ b/ompi/mca/coll/libnbc/nbc_ireduce.c @@ -20,12 +20,12 @@ #include "nbc_internal.h" static inline int red_sched_binomial (int rank, int p, int root, const void *sendbuf, void *redbuf, char tmpredbuf, int count, MPI_Datatype datatype, - MPI_Op op, char inplace, NBC_Schedule *schedule, NBC_Handle *handle); + MPI_Op op, char inplace, NBC_Schedule *schedule, void *tmpbuf); static inline int red_sched_chain (int rank, int p, int root, const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, - MPI_Op op, int ext, size_t size, NBC_Schedule *schedule, NBC_Handle *handle, int fragsize); + MPI_Op op, int ext, size_t size, NBC_Schedule *schedule, void *tmpbuf, int fragsize); static inline int red_sched_linear (int rank, int rsize, int root, const void *sendbuf, void *recvbuf, void *tmpbuf, int count, MPI_Datatype datatype, - MPI_Op op, NBC_Schedule *schedule, NBC_Handle *handle); + MPI_Op op, NBC_Schedule *schedule); #ifdef NBC_CACHE_SCHEDULE /* tree comparison function for schedule cache */ @@ -56,9 +56,9 @@ int ompi_coll_libnbc_ireduce(const void* sendbuf, void* recvbuf, int count, MPI_ MPI_Aint ext; NBC_Schedule *schedule; char *redbuf=NULL, inplace; + void *tmpbuf; char tmpredbuf = 0; enum { NBC_RED_BINOMIAL, NBC_RED_CHAIN } alg; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; ptrdiff_t span, gap; @@ -90,11 +90,6 @@ int ompi_coll_libnbc_ireduce(const void* sendbuf, void* recvbuf, int count, MPI_ return OMPI_SUCCESS; } - res = NBC_Init_handle (comm, &handle, libnbc_module); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - return res; - } - span = opal_datatype_span(&datatype->super, count, &gap); /* algorithm selection */ @@ -102,23 +97,22 @@ int ompi_coll_libnbc_ireduce(const void* sendbuf, void* recvbuf, int count, MPI_ alg = NBC_RED_BINOMIAL; if(rank == root) { /* root reduces in receivebuffer */ - handle->tmpbuf = malloc (span); + tmpbuf = malloc (span); redbuf = recvbuf; } else { /* recvbuf may not be valid on non-root nodes */ ptrdiff_t span_align = OPAL_ALIGN(span, datatype->super.align, ptrdiff_t); - handle->tmpbuf = malloc (span_align + span); + tmpbuf = malloc (span_align + span); redbuf = (char*)span_align - gap; tmpredbuf = 1; } } else { - handle->tmpbuf = malloc (span); + tmpbuf = malloc (span); alg = NBC_RED_CHAIN; segsize = 16384/2; } - if (OPAL_UNLIKELY(NULL == handle->tmpbuf)) { - NBC_Return_handle (handle); + if (OPAL_UNLIKELY(NULL == tmpbuf)) { return OMPI_ERR_OUT_OF_RESOURCE; } @@ -137,30 +131,29 @@ int ompi_coll_libnbc_ireduce(const void* sendbuf, void* recvbuf, int count, MPI_ #endif schedule = OBJ_NEW(NBC_Schedule); if (OPAL_UNLIKELY(NULL == schedule)) { - NBC_Return_handle (handle); + free(tmpbuf); return OMPI_ERR_OUT_OF_RESOURCE; } - /* make sure the schedule is released with the handle on error */ - handle->schedule = schedule; - switch(alg) { case NBC_RED_BINOMIAL: - res = red_sched_binomial(rank, p, root, sendbuf, redbuf, tmpredbuf, count, datatype, op, inplace, schedule, handle); + res = red_sched_binomial(rank, p, root, sendbuf, redbuf, tmpredbuf, count, datatype, op, inplace, schedule, tmpbuf); break; case NBC_RED_CHAIN: - res = red_sched_chain(rank, p, root, sendbuf, recvbuf, count, datatype, op, ext, size, schedule, handle, segsize); + res = red_sched_chain(rank, p, root, sendbuf, recvbuf, count, datatype, op, ext, size, schedule, tmpbuf, segsize); break; } if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } res = NBC_Sched_commit(schedule); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } #ifdef NBC_CACHE_SCHEDULE @@ -195,15 +188,13 @@ int ompi_coll_libnbc_ireduce(const void* sendbuf, void* recvbuf, int count, MPI_ } #endif - res = NBC_Start(handle, schedule); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, tmpbuf); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - *request = (ompi_request_t *) handle; - - /* tmpbuf is freed with the handle */ return OMPI_SUCCESS; } @@ -212,52 +203,46 @@ int ompi_coll_libnbc_ireduce_inter(const void* sendbuf, void* recvbuf, int count struct mca_coll_base_module_2_1_0_t *module) { int rank, res, rsize; NBC_Schedule *schedule; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; ptrdiff_t span, gap; + void *tmpbuf; rank = ompi_comm_rank (comm); rsize = ompi_comm_remote_size (comm); - res = NBC_Init_handle(comm, &handle, libnbc_module); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - return res; - } - span = opal_datatype_span(&datatype->super, count, &gap); - handle->tmpbuf = malloc (span); - if (OPAL_UNLIKELY(NULL == handle->tmpbuf)) { - NBC_Return_handle (handle); + tmpbuf = malloc (span); + if (OPAL_UNLIKELY(NULL == tmpbuf)) { return OMPI_ERR_OUT_OF_RESOURCE; } schedule = OBJ_NEW(NBC_Schedule); if (OPAL_UNLIKELY(NULL == schedule)) { - NBC_Return_handle (handle); + free(tmpbuf); return OMPI_ERR_OUT_OF_RESOURCE; } - res = red_sched_linear (rank, rsize, root, sendbuf, recvbuf, (void *)(-gap), count, datatype, op, schedule, handle); + res = red_sched_linear (rank, rsize, root, sendbuf, recvbuf, (void *)(-gap), count, datatype, op, schedule); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return OMPI_ERR_OUT_OF_RESOURCE; } res = NBC_Sched_commit(schedule); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - return OMPI_ERR_OUT_OF_RESOURCE; + OBJ_RELEASE(schedule); + free(tmpbuf); + return res; } - res = NBC_Start(handle, schedule); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, tmpbuf); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return OMPI_ERR_OUT_OF_RESOURCE; } - *request = (ompi_request_t *) handle; - - /* tmpbuf is freed with the handle */ return OMPI_SUCCESS; } @@ -294,9 +279,9 @@ int ompi_coll_libnbc_ireduce_inter(const void* sendbuf, void* recvbuf, int count if (vrank == root) rank = 0; \ } static inline int red_sched_binomial (int rank, int p, int root, const void *sendbuf, void *redbuf, char tmpredbuf, int count, MPI_Datatype datatype, - MPI_Op op, char inplace, NBC_Schedule *schedule, NBC_Handle *handle) { + MPI_Op op, char inplace, NBC_Schedule *schedule, void *tmpbuf) { int vroot, vrank, vpeer, peer, res, maxr; - char *rbuf, *lbuf, *buf, tmpbuf; + char *rbuf, *lbuf, *buf; int tmprbuf, tmplbuf; ptrdiff_t gap; (void)opal_datatype_span(&datatype->super, count, &gap); @@ -325,7 +310,7 @@ static inline int red_sched_binomial (int rank, int p, int root, const void *sen rbuf = redbuf; tmprbuf = tmpredbuf; if (inplace) { - res = NBC_Copy(rbuf, count, datatype, ((char *)handle->tmpbuf)-gap, count, datatype, MPI_COMM_SELF); + res = NBC_Copy(rbuf, count, datatype, ((char *)tmpbuf)-gap, count, datatype, MPI_COMM_SELF); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { return res; } @@ -338,6 +323,7 @@ static inline int red_sched_binomial (int rank, int p, int root, const void *sen vpeer = vrank + (1 << (r - 1)); VRANK2RANK(peer, vpeer, vroot) if (peer < p) { + int tbuf; /* we have to wait until we have the data */ res = NBC_Sched_recv (rbuf, tmprbuf, count, datatype, peer, schedule, true); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { @@ -345,7 +331,7 @@ static inline int red_sched_binomial (int rank, int p, int root, const void *sen } /* perform the reduce in my local buffer */ - /* this cannot be done until handle->tmpbuf is unused :-( so barrier after the op */ + /* this cannot be done until tmpbuf is unused :-( so barrier after the op */ if (firstred && !inplace) { /* perform the reduce with the senbuf */ res = NBC_Sched_op (sendbuf, false, rbuf, tmprbuf, count, datatype, op, schedule, true); @@ -360,7 +346,7 @@ static inline int red_sched_binomial (int rank, int p, int root, const void *sen } /* swap left and right buffers */ buf = rbuf; rbuf = lbuf ; lbuf = buf; - tmpbuf = tmprbuf; tmprbuf = tmplbuf; tmplbuf = tmpbuf; + tbuf = tmprbuf; tmprbuf = tmplbuf; tmplbuf = tbuf; } } else { /* we have to send this round */ @@ -396,7 +382,7 @@ static inline int red_sched_binomial (int rank, int p, int root, const void *sen /* chain send ... */ static inline int red_sched_chain (int rank, int p, int root, const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, - MPI_Op op, int ext, size_t size, NBC_Schedule *schedule, NBC_Handle *handle, int fragsize) { + MPI_Op op, int ext, size_t size, NBC_Schedule *schedule, void *tmpbuf, int fragsize) { int res, vrank, rpeer, speer, numfrag, fragcount, thiscount; long offset; @@ -474,7 +460,7 @@ static inline int red_sched_chain (int rank, int p, int root, const void *sendbu /* simple linear algorithm for intercommunicators */ static inline int red_sched_linear (int rank, int rsize, int root, const void *sendbuf, void *recvbuf, void *tmpbuf, int count, MPI_Datatype datatype, - MPI_Op op, NBC_Schedule *schedule, NBC_Handle *handle) { + MPI_Op op, NBC_Schedule *schedule) { int res; char *rbuf, *lbuf, *buf; int tmprbuf, tmplbuf; diff --git a/ompi/mca/coll/libnbc/nbc_ireduce_scatter.c b/ompi/mca/coll/libnbc/nbc_ireduce_scatter.c index 58ce5334191..b19f95626a8 100644 --- a/ompi/mca/coll/libnbc/nbc_ireduce_scatter.c +++ b/ompi/mca/coll/libnbc/nbc_ireduce_scatter.c @@ -7,7 +7,7 @@ * rights reserved. * Copyright (c) 2013-2015 Los Alamos National Security, LLC. All rights * reserved. - * Copyright (c) 2014-2016 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2015 The University of Tennessee and The University * of Tennessee Research Foundation. All rights @@ -45,7 +45,7 @@ int ompi_coll_libnbc_ireduce_scatter(const void* sendbuf, void* recvbuf, const i ptrdiff_t gap, span, span_align; char *sbuf, inplace; NBC_Schedule *schedule; - NBC_Handle *handle; + void *tmpbuf; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; char *rbuf, *lbuf, *buf; @@ -78,18 +78,12 @@ int ompi_coll_libnbc_ireduce_scatter(const void* sendbuf, void* recvbuf, const i return OMPI_SUCCESS; } - res = NBC_Init_handle (comm, &handle, libnbc_module); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - return res; - } - maxr = (int) ceil ((log((double) p) / LOG2)); span = opal_datatype_span(&datatype->super, count, &gap); span_align = OPAL_ALIGN(span, datatype->super.align, ptrdiff_t); - handle->tmpbuf = malloc (span_align + span); - if (OPAL_UNLIKELY(NULL == handle->tmpbuf)) { - NBC_Return_handle (handle); + tmpbuf = malloc (span_align + span); + if (OPAL_UNLIKELY(NULL == tmpbuf)) { return OMPI_ERR_OUT_OF_RESOURCE; } @@ -98,13 +92,10 @@ int ompi_coll_libnbc_ireduce_scatter(const void* sendbuf, void* recvbuf, const i schedule = OBJ_NEW(NBC_Schedule); if (OPAL_UNLIKELY(NULL == schedule)) { - NBC_Return_handle (handle); + free(tmpbuf); return OMPI_ERR_OUT_OF_RESOURCE; } - /* make sure the schedule is released with the handle on error */ - handle->schedule = schedule; - for (int r = 1, firstred = 1 ; r <= maxr ; ++r) { if ((rank % (1 << r)) == 0) { /* we have to receive this round */ @@ -113,11 +104,12 @@ int ompi_coll_libnbc_ireduce_scatter(const void* sendbuf, void* recvbuf, const i /* we have to wait until we have the data */ res = NBC_Sched_recv(rbuf, true, count, datatype, peer, schedule, true); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - /* this cannot be done until handle->tmpbuf is unused :-( so barrier after the op */ + /* this cannot be done until tmpbuf is unused :-( so barrier after the op */ if (firstred) { /* take reduce data from the sendbuf in the first round -> save copy */ res = NBC_Sched_op (sendbuf, false, rbuf, true, count, datatype, op, schedule, true); @@ -128,7 +120,8 @@ int ompi_coll_libnbc_ireduce_scatter(const void* sendbuf, void* recvbuf, const i } if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } /* swap left and right buffers */ @@ -145,7 +138,8 @@ int ompi_coll_libnbc_ireduce_scatter(const void* sendbuf, void* recvbuf, const i res = NBC_Sched_send (lbuf, true, count, datatype, peer, schedule, false); } if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } @@ -156,7 +150,8 @@ int ompi_coll_libnbc_ireduce_scatter(const void* sendbuf, void* recvbuf, const i res = NBC_Sched_barrier(schedule); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } @@ -169,7 +164,8 @@ int ompi_coll_libnbc_ireduce_scatter(const void* sendbuf, void* recvbuf, const i res = NBC_Sched_send (sbuf, true, recvcounts[r], datatype, r, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } } @@ -181,25 +177,25 @@ int ompi_coll_libnbc_ireduce_scatter(const void* sendbuf, void* recvbuf, const i } if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } res = NBC_Sched_commit (schedule); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - res = NBC_Start (handle, schedule); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, tmpbuf); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - *request = (ompi_request_t *) handle; - - /* tmpbuf is freed with the handle */ return OMPI_SUCCESS; } @@ -210,7 +206,7 @@ int ompi_coll_libnbc_ireduce_scatter_inter (const void* sendbuf, void* recvbuf, MPI_Aint ext; ptrdiff_t gap, span, span_align; NBC_Schedule *schedule; - NBC_Handle *handle; + void *tmpbuf = NULL; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; rank = ompi_comm_rank (comm); @@ -231,32 +227,24 @@ int ompi_coll_libnbc_ireduce_scatter_inter (const void* sendbuf, void* recvbuf, span = opal_datatype_span(&datatype->super, count, &gap); span_align = OPAL_ALIGN(span, datatype->super.align, ptrdiff_t); - res = NBC_Init_handle(comm, &handle, libnbc_module); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - return res; - } - if (count > 0) { - handle->tmpbuf = malloc (span_align + span); - if (OPAL_UNLIKELY(NULL == handle->tmpbuf)) { - NBC_Return_handle (handle); + tmpbuf = malloc (span_align + span); + if (OPAL_UNLIKELY(NULL == tmpbuf)) { return OMPI_ERR_OUT_OF_RESOURCE; } } schedule = OBJ_NEW(NBC_Schedule); if (OPAL_UNLIKELY(NULL == schedule)) { - NBC_Return_handle (handle); + free(tmpbuf); return OMPI_ERR_OUT_OF_RESOURCE; } - /* make sure the schedule is released with the handle on error */ - handle->schedule = schedule; - /* send my data to the remote root */ res = NBC_Sched_send(sendbuf, false, count, datatype, 0, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } @@ -266,7 +254,8 @@ int ompi_coll_libnbc_ireduce_scatter_inter (const void* sendbuf, void* recvbuf, rbuf = (char *)(span_align-gap); res = NBC_Sched_recv (lbuf, true, count, datatype, 0, schedule, true); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } @@ -274,14 +263,16 @@ int ompi_coll_libnbc_ireduce_scatter_inter (const void* sendbuf, void* recvbuf, char *tbuf; res = NBC_Sched_recv (rbuf, true, count, datatype, peer, schedule, true); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } res = NBC_Sched_op (lbuf, true, rbuf, true, count, datatype, op, schedule, true); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } tbuf = lbuf; lbuf = rbuf; rbuf = tbuf; @@ -291,14 +282,16 @@ int ompi_coll_libnbc_ireduce_scatter_inter (const void* sendbuf, void* recvbuf, res = NBC_Sched_copy (lbuf, true, recvcounts[0], datatype, recvbuf, false, recvcounts[0], datatype, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } for (int peer = 1, offset = recvcounts[0] * ext; peer < lsize ; ++peer) { res = NBC_Sched_local_send (lbuf + offset, true, recvcounts[peer], datatype, peer, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } @@ -308,25 +301,25 @@ int ompi_coll_libnbc_ireduce_scatter_inter (const void* sendbuf, void* recvbuf, /* receive my block */ res = NBC_Sched_local_recv (recvbuf, false, recvcounts[rank], datatype, 0, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } } res = NBC_Sched_commit (schedule); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - res = NBC_Start (handle, schedule); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, tmpbuf); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - *request = (ompi_request_t *) handle; - - /* tmpbuf is freed with the handle */ return OMPI_SUCCESS; } diff --git a/ompi/mca/coll/libnbc/nbc_ireduce_scatter_block.c b/ompi/mca/coll/libnbc/nbc_ireduce_scatter_block.c index f05c9d5cb09..aec2f79d211 100644 --- a/ompi/mca/coll/libnbc/nbc_ireduce_scatter_block.c +++ b/ompi/mca/coll/libnbc/nbc_ireduce_scatter_block.c @@ -8,7 +8,7 @@ * Copyright (c) 2012 Sandia National Laboratories. All rights reserved. * Copyright (c) 2013-2015 Los Alamos National Security, LLC. All rights * reserved. - * Copyright (c) 2014-2016 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * * Author(s): Torsten Hoefler @@ -43,7 +43,7 @@ int ompi_coll_libnbc_ireduce_scatter_block(const void* sendbuf, void* recvbuf, i ptrdiff_t gap, span; char *redbuf, *sbuf, inplace; NBC_Schedule *schedule; - NBC_Handle *handle; + void *tmpbuf = NULL; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; NBC_IN_PLACE(sendbuf, recvbuf, inplace); @@ -57,20 +57,11 @@ int ompi_coll_libnbc_ireduce_scatter_block(const void* sendbuf, void* recvbuf, i return (MPI_SUCCESS == res) ? MPI_ERR_SIZE : res; } - res = NBC_Init_handle(comm, &handle, libnbc_module); - if (OMPI_SUCCESS != res) { - return res; - } - schedule = OBJ_NEW(NBC_Schedule); if (NULL == schedule) { - OMPI_COLL_LIBNBC_REQUEST_RETURN(handle); return OMPI_ERR_OUT_OF_RESOURCE; } - /* make sure the schedule is released with the handle on error */ - handle->schedule = schedule; - maxr = (int)ceil((log((double)p)/LOG2)); count = p * recvcount; @@ -81,23 +72,22 @@ int ompi_coll_libnbc_ireduce_scatter_block(const void* sendbuf, void* recvbuf, i span = opal_datatype_span(&datatype->super, count, &gap); span_align = OPAL_ALIGN(span, datatype->super.align, ptrdiff_t); - handle->tmpbuf = malloc (span_align + span); - if (NULL == handle->tmpbuf) { - OMPI_COLL_LIBNBC_REQUEST_RETURN(handle); + tmpbuf = malloc (span_align + span); + if (NULL == tmpbuf) { OBJ_RELEASE(schedule); return OMPI_ERR_OUT_OF_RESOURCE; } rbuf = (void *)(-gap); lbuf = (char *)(span_align - gap); - redbuf = (char *) handle->tmpbuf + span_align - gap; + redbuf = (char *) tmpbuf + span_align - gap; /* copy data to redbuf if we only have a single node */ if ((p == 1) && !inplace) { res = NBC_Copy (sendbuf, count, datatype, redbuf, count, datatype, comm); if (OMPI_SUCCESS != res) { - NBC_Return_handle (handle); OBJ_RELEASE(schedule); + free(tmpbuf); return res; } } @@ -110,7 +100,8 @@ int ompi_coll_libnbc_ireduce_scatter_block(const void* sendbuf, void* recvbuf, i /* we have to wait until we have the data */ res = NBC_Sched_recv (rbuf, true, count, datatype, peer, schedule, true); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } @@ -124,7 +115,8 @@ int ompi_coll_libnbc_ireduce_scatter_block(const void* sendbuf, void* recvbuf, i } if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } /* swap left and right buffers */ @@ -142,7 +134,8 @@ int ompi_coll_libnbc_ireduce_scatter_block(const void* sendbuf, void* recvbuf, i } if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } @@ -153,7 +146,8 @@ int ompi_coll_libnbc_ireduce_scatter_block(const void* sendbuf, void* recvbuf, i res = NBC_Sched_barrier(schedule); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } @@ -161,7 +155,8 @@ int ompi_coll_libnbc_ireduce_scatter_block(const void* sendbuf, void* recvbuf, i if (rank != 0) { res = NBC_Sched_recv (recvbuf, false, recvcount, datatype, 0, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } } else { @@ -171,7 +166,8 @@ int ompi_coll_libnbc_ireduce_scatter_block(const void* sendbuf, void* recvbuf, i /* root sends the right buffer to the right receiver */ res = NBC_Sched_send (sbuf, true, recvcount, datatype, r, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } } @@ -181,7 +177,8 @@ int ompi_coll_libnbc_ireduce_scatter_block(const void* sendbuf, void* recvbuf, i datatype, schedule, false); } if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } } @@ -189,19 +186,18 @@ int ompi_coll_libnbc_ireduce_scatter_block(const void* sendbuf, void* recvbuf, i res = NBC_Sched_commit (schedule); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - res = NBC_Start (handle, schedule); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, tmpbuf); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - *request = (ompi_request_t *) handle; - - /* tmpbuf is freed with the handle */ return OMPI_SUCCESS; } @@ -212,7 +208,7 @@ int ompi_coll_libnbc_ireduce_scatter_block_inter(const void *sendbuf, void *recv MPI_Aint ext; ptrdiff_t gap, span, span_align; NBC_Schedule *schedule; - NBC_Handle *handle; + void *tmpbuf = NULL; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; rank = ompi_comm_rank (comm); @@ -225,37 +221,29 @@ int ompi_coll_libnbc_ireduce_scatter_block_inter(const void *sendbuf, void *recv return res; } - res = NBC_Init_handle(comm, &handle, libnbc_module); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - return res; - } - count = rcount * lsize; span = opal_datatype_span(&dtype->super, count, &gap); span_align = OPAL_ALIGN(span, dtype->super.align, ptrdiff_t); if (count > 0) { - handle->tmpbuf = malloc (span_align + span); - if (NULL == handle->tmpbuf) { - NBC_Return_handle (handle); + tmpbuf = malloc (span_align + span); + if (NULL == tmpbuf) { return OMPI_ERR_OUT_OF_RESOURCE; } } schedule = OBJ_NEW(NBC_Schedule); if (NULL == schedule) { - NBC_Return_handle (handle); + free(tmpbuf); return OMPI_ERR_OUT_OF_RESOURCE; } - /* make sure the schedule is released with the handle on error */ - handle->schedule = schedule; - /* send my data to the remote root */ res = NBC_Sched_send (sendbuf, false, count, dtype, 0, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } @@ -265,7 +253,8 @@ int ompi_coll_libnbc_ireduce_scatter_block_inter(const void *sendbuf, void *recv rbuf = (char *)(span_align-gap); res = NBC_Sched_recv (lbuf, true, count, dtype, 0, schedule, true); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } @@ -273,14 +262,16 @@ int ompi_coll_libnbc_ireduce_scatter_block_inter(const void *sendbuf, void *recv char *tbuf; res = NBC_Sched_recv (rbuf, true, count, dtype, peer, schedule, true); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } res = NBC_Sched_op (lbuf, true, rbuf, true, count, dtype, op, schedule, true); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } tbuf = lbuf; lbuf = rbuf; rbuf = tbuf; @@ -290,13 +281,15 @@ int ompi_coll_libnbc_ireduce_scatter_block_inter(const void *sendbuf, void *recv res = NBC_Sched_copy (lbuf, true, rcount, dtype, recvbuf, false, rcount, dtype, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } for (int peer = 1 ; peer < lsize ; ++peer) { res = NBC_Sched_local_send (lbuf + ext * rcount * peer, true, rcount, dtype, peer, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } } @@ -304,7 +297,8 @@ int ompi_coll_libnbc_ireduce_scatter_block_inter(const void *sendbuf, void *recv /* receive my block */ res = NBC_Sched_local_recv(recvbuf, false, rcount, dtype, 0, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } } @@ -313,18 +307,17 @@ int ompi_coll_libnbc_ireduce_scatter_block_inter(const void *sendbuf, void *recv res = NBC_Sched_commit(schedule); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - res = NBC_Start(handle, schedule); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, tmpbuf); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - *request = (ompi_request_t *) handle; - - /* tmpbuf is freed with the handle */ return OMPI_SUCCESS; } diff --git a/ompi/mca/coll/libnbc/nbc_iscan.c b/ompi/mca/coll/libnbc/nbc_iscan.c index 5b8b0bbdc1d..2047ad8665e 100644 --- a/ompi/mca/coll/libnbc/nbc_iscan.c +++ b/ompi/mca/coll/libnbc/nbc_iscan.c @@ -5,7 +5,7 @@ * Corporation. All rights reserved. * Copyright (c) 2006 The Technical University of Chemnitz. All * rights reserved. - * Copyright (c) 2014-2015 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2015 Los Alamos National Security, LLC. All rights * reserved. @@ -47,8 +47,8 @@ int ompi_coll_libnbc_iscan(const void* sendbuf, void* recvbuf, int count, MPI_Da int rank, p, res; ptrdiff_t gap, span; NBC_Schedule *schedule; + void *tmpbuf = NULL; char inplace; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; NBC_IN_PLACE(sendbuf, recvbuf, inplace); @@ -64,11 +64,6 @@ int ompi_coll_libnbc_iscan(const void* sendbuf, void* recvbuf, int count, MPI_Da } } - res = NBC_Init_handle(comm, &handle, libnbc_module); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - return res; - } - #ifdef NBC_CACHE_SCHEDULE NBC_Scan_args *args, *found, search; @@ -83,34 +78,32 @@ int ompi_coll_libnbc_iscan(const void* sendbuf, void* recvbuf, int count, MPI_Da #endif schedule = OBJ_NEW(NBC_Schedule); if (OPAL_UNLIKELY(NULL == schedule)) { - NBC_Return_handle (handle); return OMPI_ERR_OUT_OF_RESOURCE; } - /* ensure the schedule is released with the handle */ - handle->schedule = schedule; - if(rank != 0) { span = opal_datatype_span(&datatype->super, count, &gap); - handle->tmpbuf = malloc (span); - if (NULL == handle->tmpbuf) { - NBC_Return_handle (handle); + tmpbuf = malloc (span); + if (NULL == tmpbuf) { + OBJ_RELEASE(schedule); return OMPI_ERR_OUT_OF_RESOURCE; } /* we have to wait until we have the data */ res = NBC_Sched_recv ((void *)(-gap), true, count, datatype, rank-1, schedule, true); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } /* perform the reduce in my local buffer */ - /* this cannot be done until handle->tmpbuf is unused :-( so barrier after the op */ + /* this cannot be done until tmpbuf is unused :-( so barrier after the op */ res = NBC_Sched_op ((void *)(-gap), true, recvbuf, false, count, datatype, op, schedule, true); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } } @@ -118,14 +111,16 @@ int ompi_coll_libnbc_iscan(const void* sendbuf, void* recvbuf, int count, MPI_Da if (rank != p-1) { res = NBC_Sched_send (recvbuf, false, count, datatype, rank+1, schedule, false); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } } res = NBC_Sched_commit (schedule); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } @@ -160,14 +155,12 @@ int ompi_coll_libnbc_iscan(const void* sendbuf, void* recvbuf, int count, MPI_Da } #endif - res = NBC_Start(handle, schedule); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, tmpbuf); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); + OBJ_RELEASE(schedule); + free(tmpbuf); return res; } - *request = (ompi_request_t *) handle; - - /* tmpbuf is freed with the handle */ return OMPI_SUCCESS; } diff --git a/ompi/mca/coll/libnbc/nbc_iscatter.c b/ompi/mca/coll/libnbc/nbc_iscatter.c index 20481ad057a..c2c90c15401 100644 --- a/ompi/mca/coll/libnbc/nbc_iscatter.c +++ b/ompi/mca/coll/libnbc/nbc_iscatter.c @@ -10,7 +10,7 @@ * Copyright (c) 2013 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. - * Copyright (c) 2014-2016 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * * Author(s): Torsten Hoefler @@ -48,7 +48,6 @@ int ompi_coll_libnbc_iscatter(const void* sendbuf, int sendcount, MPI_Datatype s MPI_Aint sndext = 0; NBC_Schedule *schedule; char *sbuf, inplace = 0; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; @@ -154,20 +153,12 @@ int ompi_coll_libnbc_iscatter(const void* sendbuf, int sendcount, MPI_Datatype s } #endif - res = NBC_Init_handle(comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start(handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - return res; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } @@ -179,7 +170,6 @@ int ompi_coll_libnbc_iscatter_inter(const void* sendbuf, int sendcount, MPI_Data MPI_Aint sndext; NBC_Schedule *schedule; char *sbuf; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; rsize = ompi_comm_remote_size (comm); @@ -223,19 +213,11 @@ int ompi_coll_libnbc_iscatter_inter(const void* sendbuf, int sendcount, MPI_Data return res; } - res = NBC_Init_handle(comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start(handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - return res; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } diff --git a/ompi/mca/coll/libnbc/nbc_iscatterv.c b/ompi/mca/coll/libnbc/nbc_iscatterv.c index 14ad8a5336c..991e7b72fb5 100644 --- a/ompi/mca/coll/libnbc/nbc_iscatterv.c +++ b/ompi/mca/coll/libnbc/nbc_iscatterv.c @@ -10,7 +10,7 @@ * Copyright (c) 2013 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. - * Copyright (c) 2014-2016 Research Organization for Information Science + * Copyright (c) 2014-2017 Research Organization for Information Science * and Technology (RIST). All rights reserved. * * Author(s): Torsten Hoefler @@ -31,7 +31,6 @@ int ompi_coll_libnbc_iscatterv(const void* sendbuf, const int *sendcounts, const MPI_Aint sndext; NBC_Schedule *schedule; char *sbuf, inplace = 0; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; rank = ompi_comm_rank (comm); @@ -89,20 +88,12 @@ int ompi_coll_libnbc_iscatterv(const void* sendbuf, const int *sendcounts, const return res; } - res = NBC_Init_handle (comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start (handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - return res; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; } @@ -114,7 +105,6 @@ int ompi_coll_libnbc_iscatterv_inter (const void* sendbuf, const int *sendcounts MPI_Aint sndext; NBC_Schedule *schedule; char *sbuf; - NBC_Handle *handle; ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module; rsize = ompi_comm_remote_size (comm); @@ -157,19 +147,11 @@ int ompi_coll_libnbc_iscatterv_inter (const void* sendbuf, const int *sendcounts return res; } - res = NBC_Init_handle(comm, &handle, libnbc_module); + res = NBC_Schedule_request(schedule, comm, libnbc_module, request, NULL); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { OBJ_RELEASE(schedule); return res; } - res = NBC_Start(handle, schedule); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - NBC_Return_handle (handle); - return res; - } - - *request = (ompi_request_t *) handle; - return OMPI_SUCCESS; }