Skip to content

Commit 32095be

Browse files
committed
coll/{base,basic}: move reduce_scatter_block from basic to base
Signed-off-by: Gilles Gouaillardet <[email protected]>
1 parent db45d61 commit 32095be

File tree

3 files changed

+87
-51
lines changed

3 files changed

+87
-51
lines changed

ompi/mca/coll/base/coll_base_functions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ int ompi_coll_base_reduce_scatter_intra_basic_recursivehalving(REDUCESCATTER_ARG
250250
int ompi_coll_base_reduce_scatter_intra_ring(REDUCESCATTER_ARGS);
251251

252252
/* Reduce_scatter_block */
253+
int ompi_coll_base_reduce_scatter_block_basic(REDUCESCATTERBLOCK_ARGS);
253254
int ompi_coll_base_reduce_scatter_block_intra_recursivedoubling(REDUCESCATTERBLOCK_ARGS);
254255

255256
/* Scan */

ompi/mca/coll/base/coll_base_reduce_scatter_block.c

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
22
/*
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.
318
* Copyright (c) 2018 Siberian State University of Telecommunications
419
* and Information Sciences. All rights reserved.
520
* $COPYRIGHT$
@@ -18,12 +33,81 @@
1833
#include "ompi/communicator/communicator.h"
1934
#include "ompi/mca/coll/coll.h"
2035
#include "ompi/mca/coll/base/coll_tags.h"
36+
#include "ompi/mca/coll/base/coll_base_functions.h"
2137
#include "ompi/mca/pml/pml.h"
2238
#include "ompi/op/op.h"
2339
#include "ompi/mca/coll/base/coll_base_functions.h"
2440
#include "coll_base_topo.h"
2541
#include "coll_base_util.h"
2642

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+
}
27111
/*
28112
* ompi_rounddown: Rounds a number down to nearest multiple.
29113
* rounddown(10,4) = 8, rounddown(6,3) = 6, rounddown(14,3) = 12

ompi/mca/coll/basic/coll_basic_reduce_scatter_block.c

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved.
1313
* Copyright (c) 2012 Oak Ridge National Labs. All rights reserved.
1414
* Copyright (c) 2012 Sandia National Laboratories. All rights reserved.
15-
* Copyright (c) 2014-2016 Research Organization for Information Science
15+
* Copyright (c) 2014-2018 Research Organization for Information Science
1616
* and Technology (RIST). All rights reserved.
1717
* $COPYRIGHT$
1818
*
@@ -57,58 +57,9 @@ mca_coll_basic_reduce_scatter_block_intra(const void *sbuf, void *rbuf, int rcou
5757
struct ompi_communicator_t *comm,
5858
mca_coll_base_module_t *module)
5959
{
60-
int rank, size, count, err = OMPI_SUCCESS;
61-
ptrdiff_t gap, span;
62-
char *recv_buf = NULL, *recv_buf_free = NULL;
63-
64-
/* Initialize */
65-
rank = ompi_comm_rank(comm);
66-
size = ompi_comm_size(comm);
67-
68-
/* short cut the trivial case */
69-
count = rcount * size;
70-
if (0 == count) {
71-
return OMPI_SUCCESS;
72-
}
73-
74-
/* get datatype information */
75-
span = opal_datatype_span(&dtype->super, count, &gap);
76-
77-
/* Handle MPI_IN_PLACE */
78-
if (MPI_IN_PLACE == sbuf) {
79-
sbuf = rbuf;
80-
}
81-
82-
if (0 == rank) {
83-
/* temporary receive buffer. See coll_basic_reduce.c for
84-
details on sizing */
85-
recv_buf_free = (char*) malloc(span);
86-
if (NULL == recv_buf_free) {
87-
err = OMPI_ERR_OUT_OF_RESOURCE;
88-
goto cleanup;
89-
}
90-
recv_buf = recv_buf_free - gap;
91-
}
92-
93-
/* reduction */
94-
err =
95-
comm->c_coll->coll_reduce(sbuf, recv_buf, count, dtype, op, 0,
96-
comm, comm->c_coll->coll_reduce_module);
97-
98-
/* scatter */
99-
if (MPI_SUCCESS == err) {
100-
err = comm->c_coll->coll_scatter(recv_buf, rcount, dtype,
101-
rbuf, rcount, dtype, 0,
102-
comm, comm->c_coll->coll_scatter_module);
103-
}
104-
105-
cleanup:
106-
if (NULL != recv_buf_free) free(recv_buf_free);
107-
108-
return err;
60+
return ompi_coll_base_reduce_scatter_block_basic(sbuf, rbuf, rcount, dtype, op, comm, module);
10961
}
11062

111-
11263
/*
11364
* reduce_scatter_block_inter
11465
*

0 commit comments

Comments
 (0)