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.
|
2015-01-09 07:44:01 +03:00
|
|
|
* Copyright (c) 2014-2015 Research Organization for Information Science
|
2014-10-10 10:19:37 +04:00
|
|
|
* and Technology (RIST). All rights reserved.
|
2015-01-09 07:44:01 +03:00
|
|
|
* Copyright (c) 2015 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2012-06-26 02:38:06 +04:00
|
|
|
*
|
|
|
|
* Author(s): Torsten Hoefler <htor@cs.indiana.edu>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "nbc_internal.h"
|
|
|
|
|
|
|
|
/* an reduce_csttare schedule can not be cached easily because the contents
|
|
|
|
* ot the recvcounts array may change, so a comparison of the address
|
|
|
|
* would not be sufficient ... we simply do not cache it */
|
|
|
|
|
|
|
|
/* binomial reduce to rank 0 followed by a linear scatter ...
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
2014-10-10 10:19:37 +04:00
|
|
|
int ompi_coll_libnbc_ireduce_scatter(void* sendbuf, void* recvbuf, int *recvcounts, MPI_Datatype datatype,
|
2012-06-28 02:08:19 +04:00
|
|
|
MPI_Op op, 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) {
|
2015-07-09 01:51:29 +03:00
|
|
|
int peer, rank, maxr, p, res, count;
|
2012-06-26 02:38:06 +04:00
|
|
|
MPI_Aint ext;
|
|
|
|
char *redbuf, *sbuf, inplace;
|
|
|
|
NBC_Schedule *schedule;
|
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-07-09 01:51:29 +03:00
|
|
|
rank = ompi_comm_rank (comm);
|
|
|
|
p = ompi_comm_size (comm);
|
2015-01-09 07:44:01 +03: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for (int r = 0 ; r < p ; ++r) {
|
|
|
|
count += recvcounts[r];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p == 1 || 0 == count) {
|
|
|
|
if (!inplace) {
|
2015-01-09 07:44:01 +03:00
|
|
|
/* single node not in_place: copy data to recvbuf */
|
|
|
|
res = NBC_Copy(sendbuf, recvcounts[0], datatype, recvbuf, recvcounts[0], datatype, comm);
|
2015-07-09 01:51:29 +03:00
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
return res;
|
|
|
|
}
|
2015-01-09 07:44:01 +03:00
|
|
|
}
|
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
*request = &ompi_request_empty;
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
2015-06-24 06:59:57 +03: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;
|
|
|
|
}
|
2012-06-26 02:38:06 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
maxr = (int) ceil ((log((double) p) / LOG2));
|
2012-06-26 02:38:06 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
handle->tmpbuf = malloc (ext * count * 2);
|
|
|
|
if (OPAL_UNLIKELY(NULL == handle->tmpbuf)) {
|
|
|
|
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
|
|
|
redbuf = (char *) handle->tmpbuf + ext * count;
|
2015-06-24 06:59:57 +03: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;
|
|
|
|
}
|
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
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
for (int r = 1, firstred = 1 ; r <= maxr ; ++r) {
|
|
|
|
if ((rank % (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
|
|
|
peer = rank + (1 << (r - 1));
|
|
|
|
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)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this cannot be done until handle->tmpbuf is unused :-( so barrier after the op */
|
|
|
|
if (firstred) {
|
2012-06-26 02:38:06 +04:00
|
|
|
/* take reduce data from the sendbuf in the first round -> save copy */
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_op (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 {
|
|
|
|
/* perform the reduce in my local buffer */
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_op (redbuf - (intptr_t) handle->tmpbuf, true, redbuf - (intptr_t) handle->tmpbuf, true,
|
|
|
|
0, true, count, datatype, op, schedule, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
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
|
|
|
peer = rank - (1 << (r - 1));
|
|
|
|
if (firstred) {
|
2012-06-26 02:38:06 +04:00
|
|
|
/* we have to send the senbuf */
|
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 send an already reduced value from redbuf */
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_send (redbuf - (intptr_t) handle->tmpbuf, true, count, datatype, peer, schedule, false);
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
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
|
|
|
/* leave the game */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2012-06-26 02:38:06 +04:00
|
|
|
res = NBC_Sched_barrier(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
|
|
|
}
|
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
/* rank 0 is root and sends - all others receive */
|
|
|
|
if (rank == 0) {
|
|
|
|
for (long int r = 1, offset = 0 ; r < p ; ++r) {
|
2012-06-26 02:38:06 +04:00
|
|
|
offset += recvcounts[r-1];
|
2015-07-09 01:51:29 +03:00
|
|
|
sbuf = redbuf + offset * ext;
|
2012-06-26 02:38:06 +04:00
|
|
|
/* root sends the right buffer to the right receiver */
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_send (sbuf - (intptr_t) handle->tmpbuf, true, recvcounts[r], datatype, r, schedule,
|
|
|
|
false);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return res;
|
|
|
|
}
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
2015-07-09 01:51:29 +03:00
|
|
|
|
|
|
|
res = NBC_Sched_copy (redbuf - (intptr_t) handle->tmpbuf, true, recvcounts[0], datatype, recvbuf, false,
|
|
|
|
recvcounts[0], datatype, schedule, false);
|
|
|
|
} else {
|
|
|
|
res = NBC_Sched_recv (recvbuf, false, recvcounts[rank], datatype, 0, schedule, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return res;
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_commit (schedule);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return res;
|
|
|
|
}
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Start (handle, schedule);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return res;
|
|
|
|
}
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
*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
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
int ompi_coll_libnbc_ireduce_scatter_inter (void* sendbuf, void* recvbuf, int *recvcounts, MPI_Datatype datatype,
|
|
|
|
MPI_Op op, struct ompi_communicator_t *comm, ompi_request_t ** request,
|
|
|
|
struct mca_coll_base_module_2_1_0_t *module) {
|
|
|
|
int rank, res, count, rsize;
|
2013-10-02 18:26:23 +04:00
|
|
|
MPI_Aint ext;
|
|
|
|
NBC_Schedule *schedule;
|
|
|
|
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
|
|
|
|
|
|
|
count = 0;
|
2015-07-09 01:51:29 +03:00
|
|
|
for (int r = 0 ; r < rsize ; ++r) {
|
|
|
|
count += recvcounts[r];
|
|
|
|
}
|
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
|
|
|
if (count > 0) {
|
|
|
|
handle->tmpbuf = malloc (2 * 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
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
/* make sure the schedule is released with the handle on error */
|
|
|
|
handle->schedule = schedule;
|
2013-10-02 18:26:23 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
/* 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);
|
|
|
|
return res;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
if (0 == rank) {
|
|
|
|
res = NBC_Sched_recv ((void *) 0, true, count, datatype, 0, schedule, true);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
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 ((void *)(ext * count), true, count, datatype, peer, schedule, true);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return res;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_op ((void *) 0, true, (void *)(ext * count), true, (void *) 0, true, count, datatype,
|
|
|
|
op, schedule, true);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return res;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* exchange data with remote root for scatter phase (we *could* use the local communicator to do the scatter) */
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_recv ((void *)(ext * count), true, count, datatype, 0, schedule, false);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return res;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_send ((void *) 0, true, count, datatype, 0, schedule, true);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return res;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
|
|
|
|
/* scatter */
|
2015-07-09 01:51:29 +03:00
|
|
|
for (int peer = 0, offset = ext * count ; peer < rsize ; ++peer) {
|
|
|
|
res = NBC_Sched_send ((void *)(uintptr_t) offset, true, recvcounts[peer], datatype, peer, schedule,
|
|
|
|
false);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-10-02 18:26:23 +04:00
|
|
|
offset += recvcounts[peer] * ext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* receive my block */
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_recv (recvbuf, false, recvcounts[rank], datatype, 0, schedule, false);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return res;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_commit (schedule);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return res;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Start (handle, schedule);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return res;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
*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
|
|
|
}
|