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 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
|
/**
Copyright (c) 2011 Mellanox Technologies. All rights reserved.
Copyright (c) 2017 IBM Corporation. All rights reserved.
$COPYRIGHT$
Additional copyrights may follow
$HEADER$
*/
#include "ompi_config.h"
#include "ompi/constants.h"
#include "scoll_mpi.h"
#include "scoll_mpi_dtypes.h"
#define INCOMPATIBLE_SHMEM_OMPI_COLL_APIS 1
int mca_scoll_mpi_barrier(struct oshmem_group_t *group, long *pSync, int alg)
{
mca_scoll_mpi_module_t *mpi_module;
int rc;
MPI_COLL_VERBOSE(20,"RUNNING MPI BARRIER");
mpi_module = (mca_scoll_mpi_module_t *) group->g_scoll.scoll_barrier_module;
rc = mpi_module->comm->c_coll->coll_barrier(mpi_module->comm, mpi_module->comm->c_coll->coll_barrier_module);
if (OMPI_SUCCESS != rc){
MPI_COLL_VERBOSE(20,"RUNNING FALLBACK BARRIER");
PREVIOUS_SCOLL_FN(mpi_module, barrier, group,
pSync,
SCOLL_DEFAULT_ALG);
}
return rc;
}
int mca_scoll_mpi_broadcast(struct oshmem_group_t *group,
int PE_root,
void *target,
const void *source,
size_t nlong,
long *pSync,
bool nlong_type,
int alg)
{
mca_scoll_mpi_module_t *mpi_module;
ompi_datatype_t* dtype;
int rc;
void* buf;
int root;
MPI_COLL_VERBOSE(20,"RUNNING MPI BCAST");
mpi_module = (mca_scoll_mpi_module_t *) group->g_scoll.scoll_broadcast_module;
if (group->my_pe == PE_root) {
buf = (void *) source;
} else {
buf = target;
}
dtype = &ompi_mpi_char.dt;
root = oshmem_proc_group_find_id(group, PE_root);
/* Open SHMEM specification has the following constrains (page 85):
* "If using C/C++, nelems must be of type integer. If you are using Fortran, it must be a
* default integer value". And also fortran signature says "INTEGER".
* Since ompi coll components doesn't support size_t at the moment,
* and considering this contradiction, we cast size_t to int here
* in case if the value is less than INT_MAX and fallback to previous module otherwise. */
if (OPAL_UNLIKELY(!nlong_type || (INT_MAX < nlong))) {
#ifdef INCOMPATIBLE_SHMEM_OMPI_COLL_APIS
MPI_COLL_VERBOSE(20,"RUNNING FALLBACK BCAST");
PREVIOUS_SCOLL_FN(mpi_module, broadcast, group,
PE_root,
target,
source,
nlong,
pSync,
nlong_type,
SCOLL_DEFAULT_ALG);
return rc;
#else
MPI_COLL_ERROR(20, "variable broadcast length, or exceeds INT_MAX: %zu", nlong);
return OSHMEM_ERR_NOT_SUPPORTED;
#endif
}
/* Do nothing on zero-length request */
if (OPAL_UNLIKELY(!nlong)) {
return OSHMEM_SUCCESS;
}
rc = mpi_module->comm->c_coll->coll_bcast(buf, nlong, dtype, root, mpi_module->comm, mpi_module->comm->c_coll->coll_bcast_module);
if (OMPI_SUCCESS != rc){
MPI_COLL_VERBOSE(20,"RUNNING FALLBACK BCAST");
PREVIOUS_SCOLL_FN(mpi_module, broadcast, group,
PE_root,
target,
source,
nlong,
pSync,
nlong_type,
SCOLL_DEFAULT_ALG);
}
return rc;
}
int mca_scoll_mpi_collect(struct oshmem_group_t *group,
void *target,
const void *source,
size_t nlong,
long *pSync,
bool nlong_type,
int alg)
{
ompi_datatype_t* stype = &ompi_mpi_char.dt;
ompi_datatype_t* rtype = &ompi_mpi_char.dt;
mca_scoll_mpi_module_t *mpi_module;
int rc;
int len;
int i;
void *sbuf, *rbuf;
int *disps, *recvcounts;
MPI_COLL_VERBOSE(20,"RUNNING MPI ALLGATHER");
mpi_module = (mca_scoll_mpi_module_t *) group->g_scoll.scoll_collect_module;
if (nlong_type == true) {
/* Do nothing on zero-length request */
if (OPAL_UNLIKELY(!nlong)) {
return OSHMEM_SUCCESS;
}
sbuf = (void *) source;
rbuf = target;
/* Open SHMEM specification has the following constrains (page 85):
* "If using C/C++, nelems must be of type integer. If you are using Fortran, it must be a
* default integer value". And also fortran signature says "INTEGER".
* Since ompi coll components doesn't support size_t at the moment,
* and considering this contradiction, we cast size_t to int here
* in case if the value is less than INT_MAX and fallback to previous module otherwise. */
#ifdef INCOMPATIBLE_SHMEM_OMPI_COLL_APIS
if (INT_MAX < nlong) {
MPI_COLL_VERBOSE(20,"RUNNING FALLBACK COLLECT");
PREVIOUS_SCOLL_FN(mpi_module, collect, group,
target,
source,
nlong,
pSync,
nlong_type,
SCOLL_DEFAULT_ALG);
return rc;
}
rc = mpi_module->comm->c_coll->coll_allgather(sbuf, (int)nlong, stype, rbuf, (int)nlong, rtype, mpi_module->comm, mpi_module->comm->c_coll->coll_allgather_module);
#else
rc = mpi_module->comm->c_coll->coll_allgather(sbuf, nlong, stype, rbuf, nlong, rtype, mpi_module->comm, mpi_module->comm->c_coll->coll_allgather_module);
#endif
if (OMPI_SUCCESS != rc){
MPI_COLL_VERBOSE(20,"RUNNING FALLBACK FCOLLECT");
PREVIOUS_SCOLL_FN(mpi_module, collect, group,
target,
source,
nlong,
pSync,
nlong_type,
SCOLL_DEFAULT_ALG);
}
} else {
if (INT_MAX < nlong) {
MPI_COLL_VERBOSE(20,"RUNNING FALLBACK COLLECT");
PREVIOUS_SCOLL_FN(mpi_module, collect, group,
target,
source,
nlong,
pSync,
nlong_type,
SCOLL_DEFAULT_ALG);
return rc;
}
len = nlong;
disps = malloc(group->proc_count * sizeof(*disps));
if (disps == NULL) {
rc = OSHMEM_ERR_OUT_OF_RESOURCE;
goto complete;
}
recvcounts = malloc(group->proc_count * sizeof(*recvcounts));
if (recvcounts == NULL) {
rc = OSHMEM_ERR_OUT_OF_RESOURCE;
goto failed_mem;
}
rc = mpi_module->comm->c_coll->coll_allgather(&len, sizeof(len), stype, recvcounts,
sizeof(len), rtype, mpi_module->comm,
mpi_module->comm->c_coll->coll_allgather_module);
if (rc != OSHMEM_SUCCESS) {
goto failed_allgather;
}
disps[0] = 0;
for (i = 1; i < group->proc_count; i++) {
disps[i] = disps[i - 1] + recvcounts[i - 1];
}
rc = mpi_module->comm->c_coll->coll_allgatherv(source, nlong, stype, target, recvcounts,
disps, rtype, mpi_module->comm,
mpi_module->comm->c_coll->coll_allgatherv_module);
failed_allgather:
free(recvcounts);
failed_mem:
free(disps);
}
complete:
return rc;
}
int mca_scoll_mpi_reduce(struct oshmem_group_t *group,
struct oshmem_op_t *op,
void *target,
const void *source,
size_t nlong,
long *pSync,
void *pWrk,
int alg)
{
mca_scoll_mpi_module_t *mpi_module;
struct ompi_datatype_t* dtype;
struct ompi_op_t *h_op;
int rc;
size_t count;
MPI_COLL_VERBOSE(20,"RUNNING MPI REDUCE");
void *sbuf, *rbuf;
mpi_module = (mca_scoll_mpi_module_t *) group->g_scoll.scoll_reduce_module;
dtype = shmem_dtype_to_ompi_dtype(op);
h_op = shmem_op_to_ompi_op(op->op);
count = nlong/op->dt_size;
rbuf = target;
sbuf = (source == target) ? MPI_IN_PLACE : (void*)source;
/* Do nothing on zero-length request */
if (OPAL_UNLIKELY(!nlong)) {
return OSHMEM_SUCCESS;
}
/* Open SHMEM specification has the following constrains (page 85):
* "If using C/C++, nelems must be of type integer. If you are using Fortran, it must be a
* default integer value". And also fortran signature says "INTEGER".
* Since ompi coll components doesn't support size_t at the moment,
* and considering this contradiction, we cast size_t to int here
* in case if the value is less than INT_MAX and fallback to previous module otherwise. */
#ifdef INCOMPATIBLE_SHMEM_OMPI_COLL_APIS
if (INT_MAX < count) {
MPI_COLL_VERBOSE(20,"RUNNING FALLBACK REDUCE");
PREVIOUS_SCOLL_FN(mpi_module, reduce, group,
op,
target,
source,
nlong,
pSync,
pWrk,
SCOLL_DEFAULT_ALG);
return rc;
}
rc = mpi_module->comm->c_coll->coll_allreduce(sbuf, rbuf, (int)count, dtype, h_op, mpi_module->comm, mpi_module->comm->c_coll->coll_allreduce_module);
#else
rc = mpi_module->comm->c_coll->coll_allreduce(sbuf, rbuf, count, dtype, h_op, mpi_module->comm, mpi_module->comm->c_coll->coll_allreduce_module);
#endif
if (OMPI_SUCCESS != rc){
MPI_COLL_VERBOSE(20,"RUNNING FALLBACK REDUCE");
PREVIOUS_SCOLL_FN(mpi_module, reduce, group,
op,
target,
source,
nlong,
pSync,
pWrk,
SCOLL_DEFAULT_ALG);
}
return rc;
}
|