|
14 | 14 | * reserved. |
15 | 15 | * Copyright (c) 2015-2016 Research Organization for Information Science |
16 | 16 | * and Technology (RIST). All rights reserved. |
| 17 | + * Copyright (c) 2019 Mellanox Technologies. All rights reserved. |
17 | 18 | * $COPYRIGHT$ |
18 | 19 | * |
19 | 20 | * Additional copyrights may follow |
@@ -273,5 +274,114 @@ ompi_coll_base_scatter_intra_basic_linear(const void *sbuf, int scount, |
273 | 274 | return MPI_SUCCESS; |
274 | 275 | } |
275 | 276 |
|
276 | | - |
277 | 277 | /* copied function (with appropriate renaming) ends here */ |
| 278 | + |
| 279 | +/* |
| 280 | + * Use isends for distributing the data with periodic sync by blocking send. |
| 281 | + * Blocking send acts like a local resources flush, because it ensures |
| 282 | + * progression until the message is sent/(copied to some sort of transmit buffer). |
| 283 | + */ |
| 284 | +int |
| 285 | +ompi_coll_base_scatter_intra_linear_nb(const void *sbuf, int scount, |
| 286 | + struct ompi_datatype_t *sdtype, |
| 287 | + void *rbuf, int rcount, |
| 288 | + struct ompi_datatype_t *rdtype, |
| 289 | + int root, |
| 290 | + struct ompi_communicator_t *comm, |
| 291 | + mca_coll_base_module_t *module, |
| 292 | + int max_reqs) |
| 293 | +{ |
| 294 | + int i, rank, size, err, line, nreqs; |
| 295 | + ptrdiff_t incr; |
| 296 | + char *ptmp; |
| 297 | + ompi_request_t **reqs = NULL, **preq; |
| 298 | + |
| 299 | + rank = ompi_comm_rank(comm); |
| 300 | + size = ompi_comm_size(comm); |
| 301 | + |
| 302 | + /* If not root, receive data. */ |
| 303 | + if (rank != root) { |
| 304 | + err = MCA_PML_CALL(recv(rbuf, rcount, rdtype, root, |
| 305 | + MCA_COLL_BASE_TAG_SCATTER, |
| 306 | + comm, MPI_STATUS_IGNORE)); |
| 307 | + if (MPI_SUCCESS != err) { |
| 308 | + line = __LINE__; goto err_hndl; |
| 309 | + } |
| 310 | + |
| 311 | + return MPI_SUCCESS; |
| 312 | + } |
| 313 | + |
| 314 | + if (max_reqs <= 1) { |
| 315 | + max_reqs = 0; |
| 316 | + nreqs = size - 1; /* no send for myself */ |
| 317 | + } else { |
| 318 | + /* We use blocking MPI_Send (which does not need a request) |
| 319 | + * every max_reqs send operation (which is size/max_reqs at most), |
| 320 | + * therefore no need to allocate requests for these sends. */ |
| 321 | + nreqs = size - (size / max_reqs); |
| 322 | + } |
| 323 | + |
| 324 | + reqs = ompi_coll_base_comm_get_reqs(module->base_data, nreqs); |
| 325 | + if (NULL == reqs) { |
| 326 | + err = OMPI_ERR_OUT_OF_RESOURCE; |
| 327 | + line = __LINE__; goto err_hndl; |
| 328 | + } |
| 329 | + |
| 330 | + err = ompi_datatype_type_extent(sdtype, &incr); |
| 331 | + if (OMPI_SUCCESS != err) { |
| 332 | + line = __LINE__; goto err_hndl; |
| 333 | + } |
| 334 | + incr *= scount; |
| 335 | + |
| 336 | + /* I am the root, loop sending data. */ |
| 337 | + for (i = 0, ptmp = (char *)sbuf, preq = reqs; i < size; ++i, ptmp += incr) { |
| 338 | + /* simple optimization */ |
| 339 | + if (i == rank) { |
| 340 | + if (MPI_IN_PLACE != rbuf) { |
| 341 | + err = ompi_datatype_sndrcv(ptmp, scount, sdtype, rbuf, rcount, |
| 342 | + rdtype); |
| 343 | + } |
| 344 | + } else { |
| 345 | + if (!max_reqs || (i % max_reqs)) { |
| 346 | + err = MCA_PML_CALL(isend(ptmp, scount, sdtype, i, |
| 347 | + MCA_COLL_BASE_TAG_SCATTER, |
| 348 | + MCA_PML_BASE_SEND_STANDARD, |
| 349 | + comm, preq++)); |
| 350 | + } else { |
| 351 | + err = MCA_PML_CALL(send(ptmp, scount, sdtype, i, |
| 352 | + MCA_COLL_BASE_TAG_SCATTER, |
| 353 | + MCA_PML_BASE_SEND_STANDARD, |
| 354 | + comm)); |
| 355 | + } |
| 356 | + } |
| 357 | + if (MPI_SUCCESS != err) { |
| 358 | + line = __LINE__; goto err_hndl; |
| 359 | + } |
| 360 | + } |
| 361 | + |
| 362 | + err = ompi_request_wait_all(preq - reqs, reqs, MPI_STATUSES_IGNORE); |
| 363 | + if (MPI_SUCCESS != err) { |
| 364 | + line = __LINE__; goto err_hndl; |
| 365 | + } |
| 366 | + |
| 367 | + return MPI_SUCCESS; |
| 368 | + |
| 369 | +err_hndl: |
| 370 | + if (NULL != reqs) { |
| 371 | + /* find a real error code */ |
| 372 | + if (MPI_ERR_IN_STATUS == err) { |
| 373 | + for (i = 0; i < nreqs; i++) { |
| 374 | + if (MPI_REQUEST_NULL == reqs[i]) continue; |
| 375 | + if (MPI_ERR_PENDING == reqs[i]->req_status.MPI_ERROR) continue; |
| 376 | + err = reqs[i]->req_status.MPI_ERROR; |
| 377 | + break; |
| 378 | + } |
| 379 | + } |
| 380 | + ompi_coll_base_free_reqs(reqs, nreqs); |
| 381 | + } |
| 382 | + OPAL_OUTPUT((ompi_coll_base_framework.framework_output, |
| 383 | + "%s:%4d\tError occurred %d, rank %2d", __FILE__, line, err, rank)); |
| 384 | + (void)line; /* silence compiler warning */ |
| 385 | + return err; |
| 386 | +} |
| 387 | + |
0 commit comments