1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2 /*
3 * Copyright (c) 2004-2017 The University of Tennessee and The University
4 * of Tennessee Research Foundation. All rights
5 * reserved.
6 * Copyright (c) 2015 Research Organization for Information Science
7 * and Technology (RIST). All rights reserved.
8 * $COPYRIGHT$
9 *
10 * Additional copyrights may follow
11 *
12 * $HEADER$
13 */
14
15 #include "ompi_config.h"
16
17 #include "mpi.h"
18 #include "ompi/constants.h"
19 #include "ompi/datatype/ompi_datatype.h"
20 #include "ompi/communicator/communicator.h"
21 #include "ompi/mca/coll/coll.h"
22 #include "ompi/mca/coll/base/coll_tags.h"
23 #include "ompi/mca/pml/pml.h"
24 #include "coll_tuned.h"
25 #include "ompi/mca/coll/base/coll_base_topo.h"
26 #include "ompi/mca/coll/base/coll_base_util.h"
27
28 /* alltoall algorithm variables */
29 static int coll_tuned_alltoall_forced_algorithm = 0;
30 static int coll_tuned_alltoall_segment_size = 0;
31 static int coll_tuned_alltoall_max_requests;
32 static int coll_tuned_alltoall_tree_fanout;
33 static int coll_tuned_alltoall_chain_fanout;
34
35 /* valid values for coll_tuned_alltoall_forced_algorithm */
36 static mca_base_var_enum_value_t alltoall_algorithms[] = {
37 {0, "ignore"},
38 {1, "linear"},
39 {2, "pairwise"},
40 {3, "modified_bruck"},
41 {4, "linear_sync"},
42 {5, "two_proc"},
43 {0, NULL}
44 };
45
46 /* The following are used by dynamic and forced rules */
47
48 /* publish details of each algorithm and if its forced/fixed/locked in */
49 /* as you add methods/algorithms you must update this and the query/map routines */
50
51 /* this routine is called by the component only */
52 /* this makes sure that the mca parameters are set to their initial values and perms */
53 /* module does not call this they call the forced_getvalues routine instead */
54
ompi_coll_tuned_alltoall_intra_check_forced_init(coll_tuned_force_algorithm_mca_param_indices_t * mca_param_indices)55 int ompi_coll_tuned_alltoall_intra_check_forced_init (coll_tuned_force_algorithm_mca_param_indices_t *mca_param_indices)
56 {
57 mca_base_var_enum_t*new_enum;
58 int cnt;
59
60 for( cnt = 0; NULL != alltoall_algorithms[cnt].string; cnt++ );
61 ompi_coll_tuned_forced_max_algorithms[ALLTOALL] = cnt;
62
63 (void) mca_base_component_var_register(&mca_coll_tuned_component.super.collm_version,
64 "alltoall_algorithm_count",
65 "Number of alltoall algorithms available",
66 MCA_BASE_VAR_TYPE_INT, NULL, 0,
67 MCA_BASE_VAR_FLAG_DEFAULT_ONLY,
68 OPAL_INFO_LVL_5,
69 MCA_BASE_VAR_SCOPE_CONSTANT,
70 &ompi_coll_tuned_forced_max_algorithms[ALLTOALL]);
71
72 /* MPI_T: This variable should eventually be bound to a communicator */
73 coll_tuned_alltoall_forced_algorithm = 0;
74 (void) mca_base_var_enum_create("coll_tuned_alltoall_algorithms", alltoall_algorithms, &new_enum);
75 mca_param_indices->algorithm_param_index =
76 mca_base_component_var_register(&mca_coll_tuned_component.super.collm_version,
77 "alltoall_algorithm",
78 "Which alltoall algorithm is used. Can be locked down to choice of: 0 ignore, 1 basic linear, 2 pairwise, 3: modified bruck, 4: linear with sync, 5:two proc only.",
79 MCA_BASE_VAR_TYPE_INT, new_enum, 0, MCA_BASE_VAR_FLAG_SETTABLE,
80 OPAL_INFO_LVL_5,
81 MCA_BASE_VAR_SCOPE_ALL,
82 &coll_tuned_alltoall_forced_algorithm);
83 OBJ_RELEASE(new_enum);
84 if (mca_param_indices->algorithm_param_index < 0) {
85 return mca_param_indices->algorithm_param_index;
86 }
87
88 coll_tuned_alltoall_segment_size = 0;
89 mca_param_indices->segsize_param_index =
90 mca_base_component_var_register(&mca_coll_tuned_component.super.collm_version,
91 "alltoall_algorithm_segmentsize",
92 "Segment size in bytes used by default for alltoall algorithms. Only has meaning if algorithm is forced and supports segmenting. 0 bytes means no segmentation.",
93 MCA_BASE_VAR_TYPE_INT, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE,
94 OPAL_INFO_LVL_5,
95 MCA_BASE_VAR_SCOPE_ALL,
96 &coll_tuned_alltoall_segment_size);
97
98 coll_tuned_alltoall_tree_fanout = ompi_coll_tuned_init_tree_fanout; /* get system wide default */
99 mca_param_indices->tree_fanout_param_index =
100 mca_base_component_var_register(&mca_coll_tuned_component.super.collm_version,
101 "alltoall_algorithm_tree_fanout",
102 "Fanout for n-tree used for alltoall algorithms. Only has meaning if algorithm is forced and supports n-tree topo based operation.",
103 MCA_BASE_VAR_TYPE_INT, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE,
104 OPAL_INFO_LVL_5,
105 MCA_BASE_VAR_SCOPE_ALL,
106 &coll_tuned_alltoall_tree_fanout);
107
108 coll_tuned_alltoall_chain_fanout = ompi_coll_tuned_init_chain_fanout; /* get system wide default */
109 mca_param_indices->chain_fanout_param_index =
110 mca_base_component_var_register(&mca_coll_tuned_component.super.collm_version,
111 "alltoall_algorithm_chain_fanout",
112 "Fanout for chains used for alltoall algorithms. Only has meaning if algorithm is forced and supports chain topo based operation.",
113 MCA_BASE_VAR_TYPE_INT, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE,
114 OPAL_INFO_LVL_5,
115 MCA_BASE_VAR_SCOPE_ALL,
116 &coll_tuned_alltoall_chain_fanout);
117
118 coll_tuned_alltoall_max_requests = 0; /* no limit for alltoall by default */
119 mca_param_indices->max_requests_param_index =
120 mca_base_component_var_register(&mca_coll_tuned_component.super.collm_version,
121 "alltoall_algorithm_max_requests",
122 "Maximum number of outstanding send or recv requests. Only has meaning for synchronized algorithms.",
123 MCA_BASE_VAR_TYPE_INT, NULL, 0, MCA_BASE_VAR_FLAG_SETTABLE,
124 OPAL_INFO_LVL_5,
125 MCA_BASE_VAR_SCOPE_ALL,
126 &coll_tuned_alltoall_max_requests);
127 if (mca_param_indices->max_requests_param_index < 0) {
128 return mca_param_indices->max_requests_param_index;
129 }
130
131 if (coll_tuned_alltoall_max_requests < 0) {
132 if( 0 == ompi_comm_rank( MPI_COMM_WORLD ) ) {
133 opal_output( 0, "Maximum outstanding requests must be positive number greater than 1. Switching to system level default %d \n",
134 ompi_coll_tuned_init_max_requests );
135 }
136 coll_tuned_alltoall_max_requests = 0;
137 }
138
139 return (MPI_SUCCESS);
140 }
141
ompi_coll_tuned_alltoall_intra_do_this(const void * sbuf,int scount,struct ompi_datatype_t * sdtype,void * rbuf,int rcount,struct ompi_datatype_t * rdtype,struct ompi_communicator_t * comm,mca_coll_base_module_t * module,int algorithm,int faninout,int segsize,int max_requests)142 int ompi_coll_tuned_alltoall_intra_do_this(const void *sbuf, int scount,
143 struct ompi_datatype_t *sdtype,
144 void* rbuf, int rcount,
145 struct ompi_datatype_t *rdtype,
146 struct ompi_communicator_t *comm,
147 mca_coll_base_module_t *module,
148 int algorithm, int faninout, int segsize,
149 int max_requests)
150 {
151 OPAL_OUTPUT((ompi_coll_tuned_stream,"coll:tuned:alltoall_intra_do_this selected algorithm %d topo faninout %d segsize %d",
152 algorithm, faninout, segsize));
153
154 switch (algorithm) {
155 case (0):
156 return ompi_coll_tuned_alltoall_intra_dec_fixed(sbuf, scount, sdtype, rbuf, rcount, rdtype, comm, module);
157 case (1):
158 return ompi_coll_base_alltoall_intra_basic_linear(sbuf, scount, sdtype, rbuf, rcount, rdtype, comm, module);
159 case (2):
160 return ompi_coll_base_alltoall_intra_pairwise(sbuf, scount, sdtype, rbuf, rcount, rdtype, comm, module);
161 case (3):
162 return ompi_coll_base_alltoall_intra_bruck(sbuf, scount, sdtype, rbuf, rcount, rdtype, comm, module);
163 case (4):
164 return ompi_coll_base_alltoall_intra_linear_sync(sbuf, scount, sdtype, rbuf, rcount, rdtype, comm, module, max_requests);
165 case (5):
166 return ompi_coll_base_alltoall_intra_two_procs(sbuf, scount, sdtype, rbuf, rcount, rdtype, comm, module);
167 } /* switch */
168 OPAL_OUTPUT((ompi_coll_tuned_stream,"coll:tuned:alltoall_intra_do_this attempt to select algorithm %d when only 0-%d is valid?",
169 algorithm, ompi_coll_tuned_forced_max_algorithms[ALLTOALL]));
170 return (MPI_ERR_ARG);
171 }
172