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.
|
2015-12-29 21:12:19 +03:00
|
|
|
* Copyright (c) 2015 Mellanox Technologies. All rights reserved.
|
2012-06-26 02:38:06 +04:00
|
|
|
*
|
|
|
|
* Author(s): Torsten Hoefler <htor@cs.indiana.edu>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "nbc_internal.h"
|
|
|
|
|
|
|
|
/* Dissemination implementation of MPI_Ibarrier */
|
|
|
|
int ompi_coll_libnbc_ibarrier(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
|
|
|
{
|
2015-07-09 01:51:29 +03:00
|
|
|
int rank, p, maxround, res, recvpeer, sendpeer;
|
2012-06-26 02:38:06 +04:00
|
|
|
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);
|
|
|
|
p = ompi_comm_size (comm);
|
2012-06-26 02:38:06 +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 (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
|
|
|
|
|
|
|
#ifdef NBC_CACHE_SCHEDULE
|
|
|
|
/* there only one argument set per communicator -> hang it directly at
|
|
|
|
* the tree-position, NBC_Dict_size[...] is 0 for not initialized and
|
|
|
|
* 1 for initialized. NBC_Dict[...] is a pointer to the schedule in
|
|
|
|
* this case */
|
2015-07-09 01:51:29 +03:00
|
|
|
if (libnbc_module->NBC_Dict_size[NBC_BARRIER] == 0) {
|
2012-06-26 02:38:06 +04:00
|
|
|
/* we did not init it yet */
|
|
|
|
#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
|
|
|
/* ensure the schedule is released with the handle on error */
|
|
|
|
handle->schedule = schedule;
|
2012-06-26 02:38:06 +04:00
|
|
|
|
2012-08-07 14:41:53 +04:00
|
|
|
maxround = (int)ceil((log((double)p)/LOG2)-1);
|
2012-06-26 02:38:06 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
for (int round = 0 ; round <= maxround ; ++round) {
|
|
|
|
sendpeer = (rank + (1 << round)) % p;
|
2012-06-26 02:38:06 +04:00
|
|
|
/* add p because modulo does not work with negative values */
|
2015-07-09 01:51:29 +03:00
|
|
|
recvpeer = ((rank - (1 << round)) + p) % p;
|
2012-06-26 02:38:06 +04:00
|
|
|
|
|
|
|
/* send msg to sendpeer */
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_send ((void *) 0, true, 1, MPI_BYTE, sendpeer, schedule, false);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
2012-06-26 02:38:06 +04:00
|
|
|
|
|
|
|
/* recv msg from recvpeer */
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_recv ((void *) 1, true, 1, MPI_BYTE, recvpeer, schedule, false);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
2012-06-26 02:38:06 +04:00
|
|
|
|
|
|
|
/* end communication round */
|
2015-07-09 01:51:29 +03:00
|
|
|
if (round < maxround) {
|
|
|
|
res = NBC_Sched_barrier (schedule);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
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
|
|
|
}
|
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 OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
2012-06-26 02:38:06 +04:00
|
|
|
|
|
|
|
#ifdef NBC_CACHE_SCHEDULE
|
|
|
|
/* add it */
|
2015-07-09 01:51:29 +03:00
|
|
|
libnbc_module->NBC_Dict[NBC_BARRIER] = (hb_tree *) schedule;
|
|
|
|
libnbc_module->NBC_Dict_size[NBC_BARRIER] = 1;
|
2012-06-26 02:38:06 +04:00
|
|
|
} else {
|
|
|
|
/* we found it */
|
2015-07-09 01:51:29 +03:00
|
|
|
handle->schedule = schedule = (NBC_Schedule *) libnbc_module->NBC_Dict[NBC_BARRIER];
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|
2015-07-09 01:51:29 +03:00
|
|
|
OBJ_RETAIN(schedule);
|
2012-06-26 02:38:06 +04:00
|
|
|
#endif
|
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Start (handle, schedule);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
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
|
|
|
*request = (ompi_request_t *) handle;
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
2013-10-02 18:26:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int ompi_coll_libnbc_ibarrier_inter(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
|
|
|
{
|
2015-07-09 01:51:29 +03:00
|
|
|
int rank, res, rsize;
|
2013-10-02 18:26:23 +04:00
|
|
|
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 = 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 (2);
|
|
|
|
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
|
|
|
/* ensure the schedule is released with the handle on error */
|
|
|
|
handle->schedule = schedule;
|
2013-10-02 18:26:23 +04:00
|
|
|
|
|
|
|
if (0 == rank) {
|
2015-07-09 01:51:29 +03:00
|
|
|
for (int peer = 1 ; peer < rsize ; ++peer) {
|
|
|
|
res = NBC_Sched_recv (0, true, 1, MPI_BYTE, peer, schedule, false);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* synchronize with the remote root */
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_recv (0, true, 1, MPI_BYTE, 0, schedule, false);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
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
|
|
|
res = NBC_Sched_send (0, true, 1, MPI_BYTE, 0, schedule, false);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
|
|
|
|
if (0 == rank) {
|
|
|
|
/* wait for the remote root */
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_barrier (schedule);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
2013-10-02 18:26:23 +04:00
|
|
|
|
|
|
|
/* inform remote peers that all local peers have entered the barrier */
|
2015-12-12 10:27:31 +03:00
|
|
|
for (int peer = 1; peer < rsize ; ++peer) {
|
2015-07-09 01:51:29 +03:00
|
|
|
res = NBC_Sched_send (0, true, 1, MPI_BYTE, peer, schedule, false);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
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
|
|
|
res = NBC_Sched_commit (schedule);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
NBC_Return_handle (handle);
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = NBC_Start (handle, schedule);
|
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
|
|
|
|
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
|
|
|
*request = (ompi_request_t *) handle;
|
2013-10-02 18:26:23 +04:00
|
|
|
|
2015-07-09 01:51:29 +03:00
|
|
|
return OMPI_SUCCESS;
|
2012-06-26 02:38:06 +04:00
|
|
|
}
|