1 /*
2 * Copyright (c) 2004-2005 The Regents of the University of California.
3 * All rights reserved.
4 * Copyright (c) 2004-2006 The University of Tennessee and The University
5 * of Tennessee Research Foundation. All rights
6 * reserved.
7 * Copyright (c) 2006 Cisco Systems, Inc. All rights reserved.
8 * Copyright (c) 2007 Los Alamos National Security, LLC. All rights
9 * reserved.
10 * Copyright (c) 2016 Intel, Inc. All rights reserved.
11 * Copyright (c) 2017 Research Organization for Information Science
12 * and Technology (RIST). All rights reserved.
13 * $COPYRIGHT$
14 *
15 * Additional copyrights may follow
16 *
17 * $HEADER$
18 */
19
20 #include "ompi_config.h"
21
22 #include <stdlib.h>
23
24 #include "ompi/constants.h"
25 #include "ompi/mca/pml/pml.h"
26 #include "ompi/communicator/communicator.h"
27 #include "ompi/runtime/mpiruntime.h"
28 #include "ompi/mca/coll/base/coll_base_util.h"
29
30 int
ompi_init_preconnect_mpi(void)31 ompi_init_preconnect_mpi(void)
32 {
33 int comm_size = ompi_comm_size(MPI_COMM_WORLD);
34 int comm_rank = ompi_comm_rank(MPI_COMM_WORLD);
35 int param, next, prev, i, ret = OMPI_SUCCESS;
36 char inbuf[1], outbuf[1];
37 const bool *value = NULL;
38
39 param = mca_base_var_find("ompi", "mpi", NULL, "preconnect_mpi");
40 if (0 > param) return OMPI_SUCCESS;
41 ret = mca_base_var_get_value(param, &value, NULL, NULL);
42 if (OMPI_SUCCESS != ret || (NULL != value && 0 == value[0])) {
43 return OMPI_SUCCESS;
44 }
45
46 inbuf[0] = outbuf[0] = '\0';
47
48 /* Each iteration, every process sends to its neighbor i hops to
49 the right and receives from its neighbor i hops to the left.
50 Because send_complete is used, there will only ever be one
51 outstanding send and one outstanding receive in the network at
52 a time for any given process. This limits any "flooding"
53 effect that can occur with other connection algorithms. While
54 the flooding algorithms may be a more efficient use of
55 resources, they can overwhelm the out-of-band connection system
56 used to wire up some networks, leading to poor performance and
57 hangs. */
58 for (i = 1 ; i <= comm_size / 2 ; ++i) {
59 next = (comm_rank + i) % comm_size;
60 prev = (comm_rank - i + comm_size) % comm_size;
61
62 ret = ompi_coll_base_sendrecv_actual(outbuf, 1, MPI_CHAR,
63 next, 1,
64 inbuf, 1, MPI_CHAR,
65 prev, 1,
66 MPI_COMM_WORLD, MPI_STATUS_IGNORE);
67 if(OMPI_SUCCESS != ret) return ret;
68 }
69
70 return ret;
71 }
72