|
1 | 1 | /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ |
2 | 2 | /* |
| 3 | + * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana |
| 4 | + * University Research and Technology |
| 5 | + * Corporation. All rights reserved. |
| 6 | + * Copyright (c) 2004-2017 The University of Tennessee and The University |
| 7 | + * of Tennessee Research Foundation. All rights |
| 8 | + * reserved. |
| 9 | + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, |
| 10 | + * University of Stuttgart. All rights reserved. |
| 11 | + * Copyright (c) 2004-2005 The Regents of the University of California. |
| 12 | + * All rights reserved. |
| 13 | + * Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved. |
| 14 | + * Copyright (c) 2012 Oak Ridge National Labs. All rights reserved. |
| 15 | + * Copyright (c) 2012 Sandia National Laboratories. All rights reserved. |
| 16 | + * Copyright (c) 2014-2018 Research Organization for Information Science |
| 17 | + * and Technology (RIST). All rights reserved. |
3 | 18 | * Copyright (c) 2018 Siberian State University of Telecommunications |
4 | 19 | * and Information Sciences. All rights reserved. |
5 | 20 | * $COPYRIGHT$ |
|
18 | 33 | #include "ompi/communicator/communicator.h" |
19 | 34 | #include "ompi/mca/coll/coll.h" |
20 | 35 | #include "ompi/mca/coll/base/coll_tags.h" |
| 36 | +#include "ompi/mca/coll/base/coll_base_functions.h" |
21 | 37 | #include "ompi/mca/pml/pml.h" |
22 | 38 | #include "ompi/op/op.h" |
23 | 39 | #include "ompi/mca/coll/base/coll_base_functions.h" |
24 | 40 | #include "coll_base_topo.h" |
25 | 41 | #include "coll_base_util.h" |
26 | 42 |
|
| 43 | +/* |
| 44 | + * ompi_reduce_scatter_block_basic |
| 45 | + * |
| 46 | + * Function: - reduce then scatter |
| 47 | + * Accepts: - same as MPI_Reduce_scatter_block() |
| 48 | + * Returns: - MPI_SUCCESS or error code |
| 49 | + * |
| 50 | + * Algorithm: |
| 51 | + * reduce and scatter (needs to be cleaned |
| 52 | + * up at some point) |
| 53 | + */ |
| 54 | +int |
| 55 | +ompi_coll_base_reduce_scatter_block_basic(const void *sbuf, void *rbuf, int rcount, |
| 56 | + struct ompi_datatype_t *dtype, |
| 57 | + struct ompi_op_t *op, |
| 58 | + struct ompi_communicator_t *comm, |
| 59 | + mca_coll_base_module_t *module) |
| 60 | +{ |
| 61 | + int rank, size, count, err = OMPI_SUCCESS; |
| 62 | + ptrdiff_t gap, span; |
| 63 | + char *recv_buf = NULL, *recv_buf_free = NULL; |
| 64 | + |
| 65 | + /* Initialize */ |
| 66 | + rank = ompi_comm_rank(comm); |
| 67 | + size = ompi_comm_size(comm); |
| 68 | + |
| 69 | + /* short cut the trivial case */ |
| 70 | + count = rcount * size; |
| 71 | + if (0 == count) { |
| 72 | + return OMPI_SUCCESS; |
| 73 | + } |
| 74 | + |
| 75 | + /* get datatype information */ |
| 76 | + span = opal_datatype_span(&dtype->super, count, &gap); |
| 77 | + |
| 78 | + /* Handle MPI_IN_PLACE */ |
| 79 | + if (MPI_IN_PLACE == sbuf) { |
| 80 | + sbuf = rbuf; |
| 81 | + } |
| 82 | + |
| 83 | + if (0 == rank) { |
| 84 | + /* temporary receive buffer. See coll_basic_reduce.c for |
| 85 | + details on sizing */ |
| 86 | + recv_buf_free = (char*) malloc(span); |
| 87 | + if (NULL == recv_buf_free) { |
| 88 | + err = OMPI_ERR_OUT_OF_RESOURCE; |
| 89 | + goto cleanup; |
| 90 | + } |
| 91 | + recv_buf = recv_buf_free - gap; |
| 92 | + } |
| 93 | + |
| 94 | + /* reduction */ |
| 95 | + err = |
| 96 | + comm->c_coll->coll_reduce(sbuf, recv_buf, count, dtype, op, 0, |
| 97 | + comm, comm->c_coll->coll_reduce_module); |
| 98 | + |
| 99 | + /* scatter */ |
| 100 | + if (MPI_SUCCESS == err) { |
| 101 | + err = comm->c_coll->coll_scatter(recv_buf, rcount, dtype, |
| 102 | + rbuf, rcount, dtype, 0, |
| 103 | + comm, comm->c_coll->coll_scatter_module); |
| 104 | + } |
| 105 | + |
| 106 | + cleanup: |
| 107 | + if (NULL != recv_buf_free) free(recv_buf_free); |
| 108 | + |
| 109 | + return err; |
| 110 | +} |
27 | 111 | /* |
28 | 112 | * ompi_rounddown: Rounds a number down to nearest multiple. |
29 | 113 | * rounddown(10,4) = 8, rounddown(6,3) = 6, rounddown(14,3) = 12 |
|
0 commit comments