2015-07-09 01:51:29 +03:00
|
|
|
/* -*- Mode: C; c-basic-offset:2 ; indent-tabs-mode:nil -*- */
|
2012-06-26 02:38:06 +04:00
|
|
|
/*
|
2013-10-02 18:26:23 +04:00
|
|
|
* 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.
|
2015-07-09 01:51:29 +03:00
|
|
|
* Copyright (c) 2013-2015 Los Alamos National Security, LLC. All rights
|
2013-10-02 18:26:23 +04:00
|
|
|
* reserved.
|
2014-10-10 10:19:37 +04:00
|
|
|
* Copyright (c) 2014 Research Organization for Information Science
|
|
|
|
* and Technology (RIST). All rights reserved.
|
2012-06-26 02:38:06 +04:00
|
|
|
*
|
|
|
|
* Author(s): Torsten Hoefler <htor@cs.indiana.edu>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "nbc_internal.h"
|
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
static inline int red_sched_binomial (int rank, int p, int root, void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
|
|
|
|
MPI_Op op, void *redbuf, NBC_Schedule *schedule, NBC_Handle *handle);
|
|
|
|
static inline int red_sched_chain (int rank, int p, int root, void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
|
|
|
|
MPI_Op op, int ext, int size, NBC_Schedule *schedule, NBC_Handle *handle, int fragsize);
|
2012-06-26 02:38:06 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
static inline int red_sched_linear (int rank, int rsize, int root, void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
|
|
|
|
MPI_Op op, NBC_Schedule *schedule, NBC_Handle *handle);
|
2013-10-02 18:26:23 +04:00
|
|
|
|
2012-06-26 02:38:06 +04:00
|
|
|
#ifdef NBC_CACHE_SCHEDULE
|
|
|
|
/* tree comparison function for schedule cache */
|
|
|
|
int NBC_Reduce_args_compare(NBC_Reduce_args *a, NBC_Reduce_args *b, void *param) {
|
2015-07-09 01:51:29 +03:00
|
|
|
if ((a->sendbuf == b->sendbuf) &&
|
2012-06-26 02:38:06 +04:00
|
|
|
(a->recvbuf == b->recvbuf) &&
|
2015-06-24 06:59:57 +03:00
|
|
|
(a->count == b->count) &&
|
2012-06-26 02:38:06 +04:00
|
|
|
(a->datatype == b->datatype) &&
|
|
|
|
(a->op == b->op) &&
|
2015-07-09 01:51:29 +03:00
|
|
|
(a->root == b->root)) {
|
|
|
|
return 0;
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
2015-07-09 01:51:29 +03:00
|
|
|
|
|
|
|
if (a->sendbuf < b->sendbuf) {
|
2012-06-26 02:38:06 +04:00
|
|
|
return -1;
|
2013-10-02 18:26:23 +04:00
|
|
|
}
|
2015-07-09 01:51:29 +03:00
|
|
|
|
|
|
|
return 1;
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* the non-blocking reduce */
|
2014-10-10 10:19:37 +04:00
|
|
|
int ompi_coll_libnbc_ireduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype,
|
2012-06-28 02:08:19 +04:00
|
|
|
MPI_Op op, int root, struct ompi_communicator_t *comm, ompi_request_t ** request,
|
2014-10-10 10:19:37 +04:00
|
|
|
struct mca_coll_base_module_2_1_0_t *module) {
|
2012-06-26 02:38:06 +04:00
|
|
|
int rank, p, res, segsize, size;
|
|
|
|
MPI_Aint ext;
|
|
|
|
NBC_Schedule *schedule;
|
|
|
|
char *redbuf=NULL, inplace;
|
|
|
|
enum { NBC_RED_BINOMIAL, NBC_RED_CHAIN } alg;
|
2012-06-28 02:08:19 +04:00
|
|
|
NBC_Handle *handle;
|
|
|
|
ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module;
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2012-06-26 02:38:06 +04:00
|
|
|
NBC_IN_PLACE(sendbuf, recvbuf, inplace);
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
rank = ompi_comm_rank (comm);
|
|
|
|
p = ompi_comm_size (comm);
|
|
|
|
|
2012-06-26 02:38:06 +04:00
|
|
|
res = MPI_Type_extent(datatype, &ext);
|
2015-07-09 01:51:29 +03:00
|
|
|
if (MPI_SUCCESS != res) {
|
|
|
|
NBC_Error("MPI Error in MPI_Type_extent() (%i)", res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-06-26 02:38:06 +04:00
|
|
|
res = MPI_Type_size(datatype, &size);
|
2015-07-09 01:51:29 +03:00
|
|
|
if (MPI_SUCCESS != res) {
|
|
|
|
NBC_Error("MPI Error in MPI_Type_size() (%i)", res);
|
|
|
|
return res;
|
|
|
|
}
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2012-06-26 02:38:06 +04:00
|
|
|
/* only one node -> copy data */
|
2015-07-09 01:51:29 +03:00
|
|
|
if ((p == 1) && !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;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = NBC_Init_handle (comm, &handle, libnbc_module);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
return res;
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2012-06-26 02:38:06 +04:00
|
|
|
/* algorithm selection */
|
2015-07-09 01:51:29 +03:00
|
|
|
if (p > 4 || size * count < 65536) {
|
2012-06-26 02:38:06 +04:00
|
|
|
alg = NBC_RED_BINOMIAL;
|
|
|
|
if(rank == root) {
|
|
|
|
/* root reduces in receivebuffer */
|
2015-07-09 01:51:29 +03:00
|
|
|
handle->tmpbuf = malloc (ext * count);
|
2012-06-26 02:38:06 +04:00
|
|
|
} else {
|
|
|
|
/* recvbuf may not be valid on non-root nodes */
|
2015-07-09 01:51:29 +03:00
|
|
|
handle->tmpbuf = malloc (ext * count * 2);
|
|
|
|
redbuf = (char*) handle->tmpbuf + ext * count;
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
|
|
|
} else {
|
2015-07-09 01:51:29 +03:00
|
|
|
handle->tmpbuf = malloc (ext * count);
|
2012-06-26 02:38:06 +04:00
|
|
|
alg = NBC_RED_CHAIN;
|
|
|
|
segsize = 16384/2;
|
|
|
|
}
|
2015-07-09 01:51:29 +03:00
|
|
|
|
|
|
|
if (OPAL_UNLIKELY(NULL == handle->tmpbuf)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
2012-06-26 02:38:06 +04:00
|
|
|
|
|
|
|
#ifdef NBC_CACHE_SCHEDULE
|
2015-07-09 01:51:29 +03:00
|
|
|
NBC_Reduce_args *args, *found, search;
|
|
|
|
|
2012-06-26 02:38:06 +04:00
|
|
|
/* search schedule in communicator specific tree */
|
2015-07-09 01:51:29 +03:00
|
|
|
search.sendbuf = sendbuf;
|
|
|
|
search.recvbuf = recvbuf;
|
|
|
|
search.count = count;
|
|
|
|
search.datatype = datatype;
|
|
|
|
search.op = op;
|
|
|
|
search.root = root;
|
|
|
|
found = (NBC_Reduce_args *) hb_tree_search ((hb_tree *) libnbc_module->NBC_Dict[NBC_REDUCE], &search);
|
|
|
|
if (NULL == found) {
|
2012-06-26 02:38:06 +04:00
|
|
|
#endif
|
2015-07-09 01:51:29 +03:00
|
|
|
schedule = OBJ_NEW(NBC_Schedule);
|
|
|
|
if (OPAL_UNLIKELY(NULL == schedule)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
2012-06-26 02:38:06 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
/* make sure the schedule is released with the handle on error */
|
|
|
|
handle->schedule = schedule;
|
2012-06-26 02:38:06 +04:00
|
|
|
|
|
|
|
switch(alg) {
|
|
|
|
case NBC_RED_BINOMIAL:
|
|
|
|
res = red_sched_binomial(rank, p, root, sendbuf, recvbuf, count, datatype, op, redbuf, schedule, handle);
|
|
|
|
break;
|
|
|
|
case NBC_RED_CHAIN:
|
|
|
|
res = red_sched_chain(rank, p, root, sendbuf, recvbuf, count, datatype, op, ext, size, schedule, handle, segsize);
|
|
|
|
break;
|
|
|
|
}
|
2015-07-09 01:51:29 +03:00
|
|
|
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return res;
|
|
|
|
}
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2012-06-26 02:38:06 +04:00
|
|
|
res = NBC_Sched_commit(schedule);
|
2015-07-09 01:51:29 +03:00
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return res;
|
|
|
|
}
|
2012-06-26 02:38:06 +04:00
|
|
|
#ifdef NBC_CACHE_SCHEDULE
|
|
|
|
/* save schedule to tree */
|
2015-07-09 01:51:29 +03:00
|
|
|
args = (NBC_Reduce_args *) malloc (sizeof (args));
|
|
|
|
if (NULL != args) {
|
|
|
|
args->sendbuf = sendbuf;
|
|
|
|
args->recvbuf = recvbuf;
|
|
|
|
args->count = count;
|
|
|
|
args->datatype = datatype;
|
|
|
|
args->op = op;
|
|
|
|
args->root = root;
|
|
|
|
args->schedule = schedule;
|
|
|
|
res = hb_tree_insert ((hb_tree *) libnbc_module->NBC_Dict[NBC_REDUCE], args, args, 0);
|
|
|
|
if (0 == res) {
|
|
|
|
OBJ_RETAIN(schedule);
|
|
|
|
|
|
|
|
/* increase number of elements for Reduce */
|
|
|
|
if (++libnbc_module->NBC_Dict_size[NBC_REDUCE] > NBC_SCHED_DICT_UPPER) {
|
|
|
|
NBC_SchedCache_dictwipe ((hb_tree *) libnbc_module->NBC_Dict[NBC_REDUCE],
|
|
|
|
&libnbc_module->NBC_Dict_size[NBC_REDUCE]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NBC_Error("error in dict_insert() (%i)", res);
|
|
|
|
free (args);
|
|
|
|
}
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* found schedule */
|
2015-07-09 01:51:29 +03:00
|
|
|
schedule = found->schedule;
|
|
|
|
OBJ_RETAIN(schedule);
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
|
|
|
#endif
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2012-06-26 02:38:06 +04:00
|
|
|
res = NBC_Start(handle, schedule);
|
2015-07-09 01:51:29 +03:00
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
*request = (ompi_request_t *) handle;
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2012-06-26 02:38:06 +04:00
|
|
|
/* tmpbuf is freed with the handle */
|
2015-07-09 01:51:29 +03:00
|
|
|
return OMPI_SUCCESS;
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
|
|
|
|
2013-10-02 18:26:23 +04:00
|
|
|
int ompi_coll_libnbc_ireduce_inter(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype,
|
|
|
|
MPI_Op op, int root, struct ompi_communicator_t *comm, ompi_request_t ** request,
|
2014-10-10 10:19:37 +04:00
|
|
|
struct mca_coll_base_module_2_1_0_t *module) {
|
2013-10-02 18:26:23 +04:00
|
|
|
int rank, res, rsize;
|
|
|
|
NBC_Schedule *schedule;
|
|
|
|
MPI_Aint ext;
|
|
|
|
NBC_Handle *handle;
|
|
|
|
ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module;
|
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
rank = ompi_comm_rank (comm);
|
|
|
|
rsize = ompi_comm_remote_size (comm);
|
2013-10-02 18:26:23 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
res = MPI_Type_extent (datatype, &ext);
|
|
|
|
if (MPI_SUCCESS != res) {
|
|
|
|
NBC_Error("MPI Error in MPI_Type_extent() (%i)", res);
|
|
|
|
return res;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Init_handle(comm, &handle, libnbc_module);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
return res;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
handle->tmpbuf = malloc (ext * count);
|
|
|
|
if (OPAL_UNLIKELY(NULL == handle->tmpbuf)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
schedule = OBJ_NEW(NBC_Schedule);
|
|
|
|
if (OPAL_UNLIKELY(NULL == schedule)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
|
|
|
|
res = red_sched_linear (rank, rsize, root, sendbuf, recvbuf, count, datatype, op, schedule, handle);
|
2015-07-09 01:51:29 +03:00
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
|
|
|
|
res = NBC_Sched_commit(schedule);
|
2015-07-09 01:51:29 +03:00
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
|
|
|
|
res = NBC_Start(handle, schedule);
|
2015-07-09 01:51:29 +03:00
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*request = (ompi_request_t *) handle;
|
2013-10-02 18:26:23 +04:00
|
|
|
|
|
|
|
/* tmpbuf is freed with the handle */
|
2015-07-09 01:51:29 +03:00
|
|
|
return OMPI_SUCCESS;
|
2013-10-02 18:26:23 +04:00
|
|
|
}
|
|
|
|
|
2012-06-26 02:38:06 +04:00
|
|
|
|
|
|
|
/* binomial reduce
|
|
|
|
* working principle:
|
|
|
|
* - each node gets a virtual rank vrank
|
2015-06-24 06:59:57 +03:00
|
|
|
* - the 'root' node get vrank 0
|
2012-06-26 02:38:06 +04:00
|
|
|
* - node 0 gets the vrank of the 'root'
|
|
|
|
* - all other ranks stay identical (they do not matter)
|
|
|
|
*
|
|
|
|
* Algorithm:
|
|
|
|
* pairwise exchange
|
2015-06-24 06:59:57 +03:00
|
|
|
* round r:
|
2012-06-26 02:38:06 +04:00
|
|
|
* grp = rank % 2^r
|
|
|
|
* if grp == 0: receive from rank + 2^(r-1) if it exists and reduce value
|
|
|
|
* if grp == 1: send to rank - 2^(r-1) and exit function
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
2012-06-26 02:38:06 +04:00
|
|
|
* do this for R=log_2(p) rounds
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
2012-06-26 02:38:06 +04:00
|
|
|
*/
|
|
|
|
#define RANK2VRANK(rank, vrank, root) \
|
|
|
|
{ \
|
|
|
|
vrank = rank; \
|
|
|
|
if (rank == 0) vrank = root; \
|
|
|
|
if (rank == root) vrank = 0; \
|
|
|
|
}
|
|
|
|
#define VRANK2RANK(rank, vrank, root) \
|
|
|
|
{ \
|
|
|
|
rank = vrank; \
|
|
|
|
if (vrank == 0) rank = root; \
|
|
|
|
if (vrank == root) rank = 0; \
|
|
|
|
}
|
2015-07-09 01:51:29 +03:00
|
|
|
static inline int red_sched_binomial (int rank, int p, int root, void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
|
|
|
|
MPI_Op op, void *redbuf, NBC_Schedule *schedule, NBC_Handle *handle) {
|
|
|
|
int vrank, vpeer, peer, res, maxr;
|
2012-06-26 02:38:06 +04:00
|
|
|
|
|
|
|
RANK2VRANK(rank, vrank, root);
|
2012-08-07 14:41:53 +04:00
|
|
|
maxr = (int)ceil((log((double)p)/LOG2));
|
2012-06-26 02:38:06 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
for (int r = 1, firstred = 1 ; r <= maxr ; ++r) {
|
|
|
|
if ((vrank % (1 << r)) == 0) {
|
2012-06-26 02:38:06 +04:00
|
|
|
/* we have to receive this round */
|
2015-07-09 01:51:29 +03:00
|
|
|
vpeer = vrank + (1 << (r - 1));
|
2012-06-26 02:38:06 +04:00
|
|
|
VRANK2RANK(peer, vpeer, root)
|
2015-07-09 01:51:29 +03:00
|
|
|
if (peer < p) {
|
2012-06-26 02:38:06 +04:00
|
|
|
/* we have to wait until we have the data */
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_recv (0, true, count, datatype, peer, schedule, true);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-06-26 02:38:06 +04:00
|
|
|
/* perform the reduce in my local buffer */
|
2015-07-09 01:51:29 +03:00
|
|
|
/* this cannot be done until handle->tmpbuf is unused :-( so barrier after the op */
|
|
|
|
if (firstred) {
|
|
|
|
if (rank == root) {
|
2015-06-24 06:59:57 +03:00
|
|
|
/* root is the only one who reduces in the receivebuffer
|
2012-06-26 02:38:06 +04:00
|
|
|
* take data from sendbuf in first round - save copy */
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_op (recvbuf, false, sendbuf, false, 0, true, count, datatype, op, schedule, true);
|
2012-06-26 02:38:06 +04:00
|
|
|
} else {
|
2015-06-24 06:59:57 +03:00
|
|
|
/* all others may not have a receive buffer
|
2012-06-26 02:38:06 +04:00
|
|
|
* take data from sendbuf in first round - save copy */
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_op ((char *) redbuf - (intptr_t) handle->tmpbuf, true, sendbuf, false, 0, true, count,
|
|
|
|
datatype, op, schedule, true);
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
|
|
|
firstred = 0;
|
|
|
|
} else {
|
|
|
|
if(rank == root) {
|
|
|
|
/* root is the only one who reduces in the receivebuffer */
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_op (recvbuf, false, recvbuf, false, 0, true, count, datatype, op, schedule, true);
|
2012-06-26 02:38:06 +04:00
|
|
|
} else {
|
|
|
|
/* all others may not have a receive buffer */
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_op ((char *) redbuf - (intptr_t) handle->tmpbuf, true, (char *) redbuf - (intptr_t) handle->tmpbuf,
|
|
|
|
true, 0, true, count, datatype, op, schedule, true);
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
|
|
|
}
|
2015-07-09 01:51:29 +03:00
|
|
|
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
return res;
|
|
|
|
}
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* we have to send this round */
|
2015-07-09 01:51:29 +03:00
|
|
|
vpeer = vrank - (1 << (r - 1));
|
2012-06-26 02:38:06 +04:00
|
|
|
VRANK2RANK(peer, vpeer, root)
|
2015-07-09 01:51:29 +03:00
|
|
|
if (firstred) {
|
2012-06-26 02:38:06 +04:00
|
|
|
/* we did not reduce anything */
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_send (sendbuf, false, count, datatype, peer, schedule, false);
|
2012-06-26 02:38:06 +04:00
|
|
|
} else {
|
|
|
|
/* we have to use the redbuf the root (which works in receivebuf) is never sending .. */
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_send ((char *) redbuf - (intptr_t) handle->tmpbuf, true, count, datatype, peer, schedule,
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
return res;
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
2015-07-09 01:51:29 +03:00
|
|
|
|
2012-06-26 02:38:06 +04:00
|
|
|
/* leave the game */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
return OMPI_SUCCESS;
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
|
|
|
|
2015-06-24 06:59:57 +03:00
|
|
|
/* chain send ... */
|
2015-07-09 01:51:29 +03:00
|
|
|
static inline int red_sched_chain (int rank, int p, int root, void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
|
|
|
|
MPI_Op op, int ext, int size, NBC_Schedule *schedule, NBC_Handle *handle, int fragsize) {
|
|
|
|
int res, vrank, rpeer, speer, numfrag, fragcount, thiscount;
|
2012-06-26 02:38:06 +04:00
|
|
|
long offset;
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2012-06-26 02:38:06 +04:00
|
|
|
RANK2VRANK(rank, vrank, root);
|
|
|
|
VRANK2RANK(rpeer, vrank+1, root);
|
|
|
|
VRANK2RANK(speer, vrank-1, root);
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
if (0 == count) {
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
numfrag = count * size / fragsize;
|
|
|
|
if ((count * size) % fragsize != 0) {
|
|
|
|
numfrag++;
|
|
|
|
}
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
fragcount = count / numfrag;
|
2012-06-26 02:38:06 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
for (int fragnum = 0 ; fragnum < numfrag ; ++fragnum) {
|
|
|
|
offset = fragnum * fragcount * ext;
|
2012-06-26 02:38:06 +04:00
|
|
|
thiscount = fragcount;
|
2015-07-09 01:51:29 +03:00
|
|
|
if(fragnum == numfrag - 1) {
|
2012-06-26 02:38:06 +04:00
|
|
|
/* last fragment may not be full */
|
2015-07-09 01:51:29 +03:00
|
|
|
thiscount = count - fragcount * fragnum;
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* last node does not recv */
|
2015-07-09 01:51:29 +03:00
|
|
|
if (vrank != p-1) {
|
|
|
|
res = NBC_Sched_recv ((char *) offset, true, thiscount, datatype, rpeer, schedule, true);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-06-26 02:38:06 +04:00
|
|
|
/* root reduces into receivebuf */
|
|
|
|
if(vrank == 0) {
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_op ((char *) recvbuf + offset, false, (char *) sendbuf + offset, false, (char *) offset, true,
|
|
|
|
thiscount, datatype, op, schedule, true);
|
2012-06-26 02:38:06 +04:00
|
|
|
} else {
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_op ((char *) offset, true, (char *) sendbuf + offset, false, (char *) offset, true, thiscount,
|
|
|
|
datatype, op, schedule, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
return res;
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* root does not send */
|
2015-07-09 01:51:29 +03:00
|
|
|
if (vrank != 0) {
|
2012-06-26 02:38:06 +04:00
|
|
|
/* rank p-1 has to send out of sendbuffer :) */
|
2015-07-09 01:51:29 +03:00
|
|
|
/* the barrier here seems awkward but isn't!!!! */
|
|
|
|
if (vrank == p-1) {
|
|
|
|
res = NBC_Sched_send ((char *) sendbuf + offset, false, thiscount, datatype, speer, schedule, true);
|
2012-06-26 02:38:06 +04:00
|
|
|
} else {
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_send ((char *) offset, true, thiscount, datatype, speer, schedule, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
return res;
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
return OMPI_SUCCESS;
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
|
|
|
|
/* simple linear algorithm for intercommunicators */
|
2015-07-09 01:51:29 +03:00
|
|
|
static inline int red_sched_linear (int rank, int rsize, int root, void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
|
|
|
|
MPI_Op op, NBC_Schedule *schedule, NBC_Handle *handle) {
|
|
|
|
int res;
|
2013-10-02 18:26:23 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
if (0 == count) {
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
|
|
|
|
if (MPI_ROOT == root) {
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_recv (recvbuf, false, count, datatype, 0, schedule, true);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
return res;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
for (int peer = 1 ; peer < rsize ; ++peer) {
|
|
|
|
res = NBC_Sched_recv (0, true, count, datatype, peer, schedule, true);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
return res;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_op (recvbuf, false, 0, true, recvbuf, false, count, datatype, op, schedule, true);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
return res;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
}
|
|
|
|
} else if (MPI_PROC_NULL != root) {
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_send (sendbuf, false, count, datatype, root, schedule, false);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
return res;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
}
|
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
return OMPI_SUCCESS;
|
2013-10-02 18:26:23 +04:00
|
|
|
}
|