From d0629f18c287910fd42e4590f89416937b18853c Mon Sep 17 00:00:00 2001 From: Gilles Gouaillardet Date: Wed, 11 Jan 2017 09:19:27 +0900 Subject: [PATCH] coll/libnbc: optimize size one communicators simply "return" with ompi_request_empty if the communicator size is 1 Signed-off-by: Gilles Gouaillardet --- ompi/mca/coll/libnbc/nbc_iallgather.c | 6 +++++- ompi/mca/coll/libnbc/nbc_iallreduce.c | 24 ++++++++++++++---------- ompi/mca/coll/libnbc/nbc_ibcast.c | 7 ++++++- ompi/mca/coll/libnbc/nbc_ireduce.c | 13 +++++++------ 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/ompi/mca/coll/libnbc/nbc_iallgather.c b/ompi/mca/coll/libnbc/nbc_iallgather.c index 9f0fea3706..c6cf9d69b4 100644 --- a/ompi/mca/coll/libnbc/nbc_iallgather.c +++ b/ompi/mca/coll/libnbc/nbc_iallgather.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. @@ -74,6 +74,10 @@ int ompi_coll_libnbc_iallgather(const void* sendbuf, int sendcount, MPI_Datatype return res; } } + if (1 == p) { + *request = &ompi_request_empty; + return OMPI_SUCCESS; + } #ifdef NBC_CACHE_SCHEDULE /* search schedule in communicator specific tree */ diff --git a/ompi/mca/coll/libnbc/nbc_iallreduce.c b/ompi/mca/coll/libnbc/nbc_iallreduce.c index 0b624f90c4..0e267d11dc 100644 --- a/ompi/mca/coll/libnbc/nbc_iallreduce.c +++ b/ompi/mca/coll/libnbc/nbc_iallreduce.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. * * Author(s): Torsten Hoefler @@ -82,6 +82,19 @@ int ompi_coll_libnbc_iallreduce(const void* sendbuf, void* recvbuf, int count, M 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)) { + NBC_Return_handle (handle); + return res; + } + } + *request = &ompi_request_empty; + return OMPI_SUCCESS; + } + res = NBC_Init_handle (comm, &handle, libnbc_module); if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { return res; @@ -94,15 +107,6 @@ int ompi_coll_libnbc_iallreduce(const void* sendbuf, void* recvbuf, int count, M 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; diff --git a/ompi/mca/coll/libnbc/nbc_ibcast.c b/ompi/mca/coll/libnbc/nbc_ibcast.c index 840e6cdce9..b2ef870dce 100644 --- a/ompi/mca/coll/libnbc/nbc_ibcast.c +++ b/ompi/mca/coll/libnbc/nbc_ibcast.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. @@ -58,6 +58,11 @@ int ompi_coll_libnbc_ibcast(void *buffer, int count, MPI_Datatype datatype, int rank = ompi_comm_rank (comm); p = ompi_comm_size (comm); + if (1 == p) { + *request = &ompi_request_empty; + return OMPI_SUCCESS; + } + res = ompi_datatype_type_size(datatype, &size); if (MPI_SUCCESS != res) { NBC_Error("MPI Error in ompi_datatype_type_size() (%i)", res); diff --git a/ompi/mca/coll/libnbc/nbc_ireduce.c b/ompi/mca/coll/libnbc/nbc_ireduce.c index cf3f18b19e..342c15fc29 100644 --- a/ompi/mca/coll/libnbc/nbc_ireduce.c +++ b/ompi/mca/coll/libnbc/nbc_ireduce.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. * * Author(s): Torsten Hoefler @@ -80,12 +80,13 @@ int ompi_coll_libnbc_ireduce(const void* sendbuf, void* recvbuf, int count, MPI_ } /* only one node -> copy data */ - if ((p == 1) && !inplace) { - res = NBC_Copy (sendbuf, count, datatype, recvbuf, count, datatype, comm); - if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) { - return res; + if (p == 1) { + if (!inplace) { + 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; }