1
1
openmpi/ompi/mca/coll/libnbc/nbc_igatherv.c

178 строки
5.4 KiB
C
Исходник Обычный вид История

2015-07-09 01:51:29 +03:00
/* -*- 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.
2014-10-10 10:19:37 +04:00
* Copyright (c) 2006 The Technical University of Chemnitz. All
* rights reserved.
* Copyright (c) 2013 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
2014-10-10 10:19:37 +04:00
* Copyright (c) 2014 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
2015-07-09 01:51:29 +03:00
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
* reserved.
*
* Author(s): Torsten Hoefler <htor@cs.indiana.edu>
*
*/
#include "nbc_internal.h"
/* an gatherv 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 */
2014-10-10 10:19:37 +04:00
int ompi_coll_libnbc_igatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype,
void* recvbuf, int *recvcounts, int *displs, MPI_Datatype recvtype,
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) {
2015-07-09 01:51:29 +03:00
int rank, p, res;
MPI_Aint rcvext = 0;
NBC_Schedule *schedule;
char *rbuf, inplace;
NBC_Handle *handle;
ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module;
NBC_IN_PLACE(sendbuf, recvbuf, inplace);
2015-07-09 01:51:29 +03:00
rank = ompi_comm_rank (comm);
p = ompi_comm_size (comm);
if (rank == root) {
res = MPI_Type_extent(recvtype, &rcvext);
2015-07-09 01:51:29 +03:00
if (MPI_SUCCESS != res) {
NBC_Error("MPI Error in MPI_Type_extent() (%i)", res);
return res;
}
}
2015-07-09 01:51:29 +03:00
schedule = OBJ_NEW(NBC_Schedule);
if (OPAL_UNLIKELY(NULL == schedule)) {
return OMPI_ERR_OUT_OF_RESOURCE;
}
/* send to root */
2015-07-09 01:51:29 +03:00
if (rank != root) {
/* send msg to root */
2015-07-09 01:51:29 +03:00
res = NBC_Sched_send (sendbuf, false, sendcount, sendtype, root, schedule, false);
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
OBJ_RELEASE(schedule);
return res;
}
} else {
2015-07-09 01:51:29 +03:00
for (int i = 0 ; i < p ; ++i) {
rbuf = (char *) recvbuf + displs[i] * rcvext;
if (i == root) {
if (!inplace) {
/* if I am the root - just copy the message */
2015-07-09 01:51:29 +03:00
res = NBC_Copy (sendbuf, sendcount, sendtype, rbuf, recvcounts[i], recvtype,
comm);
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
OBJ_RELEASE(schedule);
return res;
}
}
} else {
/* root receives message to the right buffer */
2015-07-09 01:51:29 +03:00
res = NBC_Sched_recv (rbuf, false, recvcounts[i], recvtype, i, schedule, false);
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
OBJ_RELEASE(schedule);
return res;
}
}
}
}
2015-06-24 06:59:57 +03:00
2015-07-09 01:51:29 +03:00
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;
}
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
2015-07-09 01:51:29 +03:00
return OMPI_SUCCESS;
}
int ompi_coll_libnbc_igatherv_inter (void* sendbuf, int sendcount, MPI_Datatype sendtype,
void* recvbuf, int *recvcounts, int *displs, MPI_Datatype recvtype,
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) {
2015-07-09 01:51:29 +03:00
int res, rsize;
MPI_Aint rcvext;
NBC_Schedule *schedule;
char *rbuf;
NBC_Handle *handle;
ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module;
2015-07-09 01:51:29 +03:00
rsize = ompi_comm_size (comm);
if (MPI_ROOT == root) {
res = MPI_Type_extent(recvtype, &rcvext);
2015-07-09 01:51:29 +03:00
if (MPI_SUCCESS != res) {
NBC_Error("MPI Error in MPI_Type_extent() (%i)", res);
return res;
}
}
2015-07-09 01:51:29 +03:00
schedule = OBJ_NEW(NBC_Schedule);
if (OPAL_UNLIKELY(NULL == schedule)) {
return OMPI_ERR_OUT_OF_RESOURCE;
}
/* send to root */
if (MPI_ROOT != root && MPI_PROC_NULL != root) {
/* send msg to root */
2015-07-09 01:51:29 +03:00
res = NBC_Sched_send (sendbuf, false, sendcount, sendtype, root, schedule, false);
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
OBJ_RELEASE(schedule);
return res;
}
} else if (MPI_ROOT == root) {
2015-07-09 01:51:29 +03:00
for (int i = 0 ; i < rsize ; ++i) {
rbuf = (char *) recvbuf + displs[i] * rcvext;
/* root receives message to the right buffer */
2015-07-09 01:51:29 +03:00
res = NBC_Sched_recv (rbuf, false, recvcounts[i], recvtype, i, schedule, false);
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
OBJ_RELEASE(schedule);
return res;
}
}
}
2015-07-09 01:51:29 +03:00
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;
}
2015-07-09 01:51:29 +03:00
*request = (ompi_request_t *) handle;
2015-07-09 01:51:29 +03:00
return OMPI_SUCCESS;
}