1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
/*
* Copyright (c) 2011-2018 Mellanox Technologies. All rights reserved.
* Copyright (c) 2014 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2014 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include "scoll_mpi.h"
#include "opal/util/show_help.h"
#include "oshmem/proc/proc.h"
#include "oshmem/runtime/runtime.h"
#include "ompi/mca/coll/base/base.h"
#include "opal/util/timings.h"
int mca_scoll_mpi_init_query(bool enable_progress_threads, bool enable_mpi_threads)
{
return OSHMEM_SUCCESS;
}
static void mca_scoll_mpi_module_clear(mca_scoll_mpi_module_t *mpi_module)
{
mpi_module->previous_barrier = NULL;
mpi_module->previous_broadcast = NULL;
mpi_module->previous_reduce = NULL;
mpi_module->previous_collect = NULL;
mpi_module->previous_alltoall = NULL;
}
static void mca_scoll_mpi_module_construct(mca_scoll_mpi_module_t *mpi_module)
{
mca_scoll_mpi_module_clear(mpi_module);
}
static void mca_scoll_mpi_module_destruct(mca_scoll_mpi_module_t *mpi_module)
{
OBJ_RELEASE(mpi_module->previous_barrier_module);
OBJ_RELEASE(mpi_module->previous_broadcast_module);
OBJ_RELEASE(mpi_module->previous_reduce_module);
OBJ_RELEASE(mpi_module->previous_collect_module);
OBJ_RELEASE(mpi_module->previous_alltoall_module);
mca_scoll_mpi_module_clear(mpi_module);
/* Free ompi_comm */
if (mpi_module->comm != &(ompi_mpi_comm_world.comm) && (NULL != mpi_module->comm)) {
ompi_comm_free(&mpi_module->comm);
}
}
#define MPI_SAVE_PREV_SCOLL_API(__api) do {\
mpi_module->previous_ ## __api = osh_group->g_scoll.scoll_ ## __api;\
mpi_module->previous_ ## __api ## _module = osh_group->g_scoll.scoll_ ## __api ## _module;\
if (!osh_group->g_scoll.scoll_ ## __api || !osh_group->g_scoll.scoll_ ## __api ## _module) {\
MPI_COLL_VERBOSE(1, "no underlying " # __api"; disqualifying myself");\
return OSHMEM_ERROR;\
}\
OBJ_RETAIN(mpi_module->previous_ ## __api ## _module);\
} while(0)
static int mca_scoll_mpi_save_coll_handlers(mca_scoll_base_module_t *module, oshmem_group_t *osh_group)
{
mca_scoll_mpi_module_t* mpi_module = (mca_scoll_mpi_module_t*) module;
MPI_SAVE_PREV_SCOLL_API(barrier);
MPI_SAVE_PREV_SCOLL_API(broadcast);
MPI_SAVE_PREV_SCOLL_API(reduce);
MPI_SAVE_PREV_SCOLL_API(collect);
MPI_SAVE_PREV_SCOLL_API(alltoall);
return OSHMEM_SUCCESS;
}
/*
* Initialize module on the communicator
*/
static int mca_scoll_mpi_module_enable(mca_scoll_base_module_t *module,
oshmem_group_t *osh_group)
{
if (OSHMEM_SUCCESS != mca_scoll_mpi_save_coll_handlers(module, osh_group)){
MPI_COLL_ERROR("MPI module enable failed - aborting to prevent inconsistent application state");
/* There's no modules available */
opal_show_help("help-oshmem-scoll-mpi.txt",
"module_enable:fatal", true,
"MPI module enable failed - aborting to prevent inconsistent application state");
oshmem_shmem_abort(-1);
return OSHMEM_ERROR;
}
return OSHMEM_SUCCESS;
}
/*
* Invoked when there's a new communicator that has been created.
* Look at the communicator and decide which set of functions and
* priority we want to return.
*/
mca_scoll_base_module_t *
mca_scoll_mpi_comm_query(oshmem_group_t *osh_group, int *priority)
{
mca_scoll_base_module_t *module;
mca_scoll_mpi_module_t *mpi_module;
int err, i;
int tag;
ompi_group_t* world_group, *new_group;
ompi_communicator_t* newcomm = NULL;
*priority = 0;
mca_scoll_mpi_component_t *cm;
cm = &mca_scoll_mpi_component;
int* ranks;
if (!cm->mpi_enable){
return NULL;
}
if ((osh_group->proc_count < 2) || (osh_group->proc_count < cm->mpi_np)) {
return NULL;
}
OPAL_TIMING_ENV_INIT(comm_query);
/* Create OMPI_Comm object and store ptr to it in group obj*/
if (NULL == oshmem_group_all) {
osh_group->ompi_comm = &(ompi_mpi_comm_world.comm);
OPAL_TIMING_ENV_NEXT(comm_query, "ompi_mpi_comm_world");
} else {
err = ompi_comm_group(&(ompi_mpi_comm_world.comm), &world_group);
if (OPAL_UNLIKELY(OMPI_SUCCESS != err)) {
return NULL;
}
OPAL_TIMING_ENV_NEXT(comm_query, "ompi_comm_group");
ranks = (int*) malloc(osh_group->proc_count * sizeof(int));
if (OPAL_UNLIKELY(NULL == ranks)) {
return NULL;
}
tag = 1;
OPAL_TIMING_ENV_NEXT(comm_query, "malloc");
/* Fill the map "group_rank-to-world_rank" in order to create a new proc group */
for (i = 0; i < osh_group->proc_count; i++) {
ranks[i] = oshmem_proc_pe_vpid(osh_group, i);
}
OPAL_TIMING_ENV_NEXT(comm_query, "build_ranks");
err = ompi_group_incl(world_group, osh_group->proc_count, ranks, &new_group);
if (OPAL_UNLIKELY(OMPI_SUCCESS != err)) {
free(ranks);
return NULL;
}
OPAL_TIMING_ENV_NEXT(comm_query, "ompi_group_incl");
err = ompi_comm_create_group(&(ompi_mpi_comm_world.comm), new_group, tag, &newcomm);
if (OPAL_UNLIKELY(OMPI_SUCCESS != err)) {
free(ranks);
return NULL;
}
OPAL_TIMING_ENV_NEXT(comm_query, "ompi_comm_create_group");
err = ompi_group_free(&new_group);
if (OPAL_UNLIKELY(OMPI_SUCCESS != err)) {
free(ranks);
return NULL;
}
OPAL_TIMING_ENV_NEXT(comm_query, "ompi_group_free");
free(ranks);
osh_group->ompi_comm = newcomm;
OPAL_TIMING_ENV_NEXT(comm_query, "set_group_comm");
}
mpi_module = OBJ_NEW(mca_scoll_mpi_module_t);
if (!mpi_module){
return NULL;
}
mpi_module->comm = osh_group->ompi_comm;
mpi_module->super.scoll_module_enable = mca_scoll_mpi_module_enable;
mpi_module->super.scoll_barrier = mca_scoll_mpi_barrier;
mpi_module->super.scoll_broadcast = mca_scoll_mpi_broadcast;
mpi_module->super.scoll_reduce = mca_scoll_mpi_reduce;
mpi_module->super.scoll_collect = mca_scoll_mpi_collect;
mpi_module->super.scoll_alltoall = NULL;
*priority = cm->mpi_priority;
module = &mpi_module->super;
return module;
}
OBJ_CLASS_INSTANCE(mca_scoll_mpi_module_t,
mca_scoll_base_module_t,
mca_scoll_mpi_module_construct,
mca_scoll_mpi_module_destruct);
|