Skip to content

Commit 7b505b2

Browse files
author
Burlen Loring
committed
coll tuned dynamic rules file alltoall_algorithm_max_requests
Teach the dynamic rules file reader to look for the alltoall_algorithm_max_requests tuning parameter. To keep the dynamic rules file format backward compatible the alltoall_algorithm_max_requests is optional. When not present in the rule definition the value of the corresponding MCA variable is used instead. Resolves #12589 Signed-off-by: Burlen Loring <[email protected]>
1 parent c393881 commit 7b505b2

File tree

3 files changed

+106
-41
lines changed

3 files changed

+106
-41
lines changed

ompi/mca/coll/base/coll_base_util.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,30 @@ int ompi_coll_base_file_peek_next_char_is(FILE *fptr, int *fileline, int expecte
482482
} while (1);
483483
}
484484

485+
/**
486+
* return 1 if the next non-space to read on the current line is a digit.
487+
* otherwise return 0.
488+
*/
489+
int ompi_coll_base_file_peek_next_char_isdigit(FILE *fptr)
490+
{
491+
do {
492+
int next = fgetc(fptr);
493+
494+
if ((' ' == next) || ('\t' == next)) {
495+
continue; /* discard space and tab. keep everything else */
496+
}
497+
498+
ungetc(next, fptr); /* put the char back into the stream */
499+
500+
if (isdigit(next)) {
501+
return 1; /* next is a digit */
502+
}
503+
else {
504+
return 0; /* next is not a digit */
505+
}
506+
} while (1);
507+
}
508+
485509
/**
486510
* There are certainly simpler implementation for this function when performance
487511
* is not a critical point. But, as this function is used during the collective

ompi/mca/coll/base/coll_base_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ int ompi_coll_base_file_getnext_string(FILE *fptr, int *fileline, char** val);
195195
* eat the value, otherwise put it back into the file.
196196
*/
197197
int ompi_coll_base_file_peek_next_char_is(FILE *fptr, int *fileline, int expected);
198+
int ompi_coll_base_file_peek_next_char_isdigit(FILE *fptr);
198199

199200
/* Miscellaneous function */
200201
const char* mca_coll_base_colltype_to_str(int collid);

ompi/mca/coll/tuned/coll_tuned_dynamic_file.c

Lines changed: 81 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,24 @@
4242
static int fileline=0; /* used for verbose error messages */
4343

4444
#define getnext(fptr, pval) ompi_coll_base_file_getnext_long(fptr, &fileline, pval)
45+
#define isnext_digit(fptr) ompi_coll_base_file_peek_next_char_isdigit(fptr)
4546

4647
/*
4748
* Reads a rule file called fname
48-
* Builds the algorithm rule table for a max of n_collectives
49+
* The rule file defines a set of sets of rules. The outer set is keyed on
50+
* communicator size while the inner set is keyed on message size. When a
51+
* communicator is constructed its size is used to look up the nested set of
52+
* message size keyed rules. When a collective is called the message size
53+
* determined from its call arguments are used to lookup a specific rule in the
54+
* inner set.
55+
*
56+
* Rules for communicator and message sizes 0 and N (where N is the larger than
57+
* largest key you provide) can be specified to fall back to the fixed decision
58+
* framework above and below the communicator and message size ranges of
59+
* interest.
4960
*
5061
* If an error occurs it removes rule table and then exits with a very verbose
51-
* error message (this stops the user using a half baked rule table
62+
* error message. this stops the user using a half baked rule table.
5263
*
5364
* Returns the number of actual collectives that a rule exists for
5465
* (note 0 is NOT an error)
@@ -57,7 +68,16 @@ static int fileline=0; /* used for verbose error messages */
5768

5869
int ompi_coll_tuned_read_rules_config_file (char *fname, ompi_coll_alg_rule_t** rules, int n_collectives)
5970
{
60-
long CI, NCS, CS, ALG, NMS, FANINOUT, X, MS, SS;
71+
long NCOL = 0, /* number of collectives for which rules are provided */
72+
COLID = 0, /* identifies the collective type to associate the rules with */
73+
NCOMSIZES = 0, /* number of sets of message size rules. the key is communicator size */
74+
COMSIZE = 0, /* communicator size, the key identifying a specific set of message size rules. */
75+
NMSGSIZES = 0, /* number of message size rules in the set. */
76+
MSGSIZE = 0, /* message size, the key identifying a specific rule in the set. */
77+
ALG = 0, /* the collective specific algorithm to use */
78+
FANINOUT = 0, /* algorithm specific tuning parameter */
79+
SEGSIZE = 0, /* algorithm specific tuning parameter */
80+
MAXREQ = 0; /* algorithm specific tuning parameter */
6181
FILE *fptr = (FILE*) NULL;
6282
int x, ncs, nms;
6383

@@ -103,106 +123,126 @@ int ompi_coll_tuned_read_rules_config_file (char *fname, ompi_coll_alg_rule_t**
103123
goto on_file_error;
104124
}
105125

106-
if( (getnext(fptr, &X) < 0) || (X < 0) ) {
126+
/* get the number of collectives for which rules are provided in the file */
127+
if( (getnext(fptr, &NCOL) < 0) || (NCOL < 0) ) {
107128
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read number of collectives in configuration file around line %d\n", fileline));
108129
goto on_file_error;
109130
}
110-
if (X>n_collectives) {
111-
OPAL_OUTPUT((ompi_coll_tuned_stream,"Number of collectives in configuration file %ld is greater than number of MPI collectives possible %d ??? error around line %d\n", X, n_collectives, fileline));
131+
if (NCOL>n_collectives) {
132+
OPAL_OUTPUT((ompi_coll_tuned_stream,"Number of collectives in configuration file %ld is greater than number of MPI collectives possible %d ??? error around line %d\n", NCOL, n_collectives, fileline));
112133
goto on_file_error;
113134
}
114135

115-
for (x=0;x<X;x++) { /* for each collective */
136+
for (x=0;x<NCOL;x++) { /* for each collective */
116137

117-
if( (getnext(fptr, &CI) < 0) || (CI < 0) ) {
138+
/* get the collective for which rules are being provided */
139+
if( (getnext(fptr, &COLID) < 0) || (COLID < 0) ) {
118140
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read next Collective id in configuration file around line %d\n", fileline));
119141
goto on_file_error;
120142
}
121-
if (CI>=n_collectives) {
122-
OPAL_OUTPUT((ompi_coll_tuned_stream,"Collective id in configuration file %ld is greater than MPI collectives possible %d. Error around line %d\n", CI, n_collectives, fileline));
143+
if (COLID>=n_collectives) {
144+
OPAL_OUTPUT((ompi_coll_tuned_stream,"Collective id in configuration file %ld is greater than MPI collectives possible %d. Error around line %d\n", COLID, n_collectives, fileline));
123145
goto on_file_error;
124146
}
125147

126-
if (alg_rules[CI].alg_rule_id != CI) {
127-
OPAL_OUTPUT((ompi_coll_tuned_stream, "Internal error in handling collective ID %ld\n", CI));
148+
if (alg_rules[COLID].alg_rule_id != COLID) {
149+
OPAL_OUTPUT((ompi_coll_tuned_stream, "Internal error in handling collective ID %ld\n", COLID));
128150
goto on_file_error;
129151
}
130-
OPAL_OUTPUT((ompi_coll_tuned_stream, "Reading dynamic rule for collective ID %ld\n", CI));
131-
alg_p = &alg_rules[CI];
152+
OPAL_OUTPUT((ompi_coll_tuned_stream, "Reading dynamic rule for collective ID %ld\n", COLID));
153+
alg_p = &alg_rules[COLID];
132154

133-
alg_p->alg_rule_id = CI;
155+
alg_p->alg_rule_id = COLID;
134156
alg_p->n_com_sizes = 0;
135157
alg_p->com_rules = (ompi_coll_com_rule_t *) NULL;
136158

137-
if( (getnext (fptr, &NCS) < 0) || (NCS < 0) ) {
138-
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read count of communicators for collective ID %ld at around line %d\n", CI, fileline));
159+
/* get the number of communicator sizes for which a set of rules are to be provided */
160+
if( (getnext (fptr, &NCOMSIZES) < 0) || (NCOMSIZES < 0) ) {
161+
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read count of communicators for collective ID %ld at around line %d\n", COLID, fileline));
139162
goto on_file_error;
140163
}
141-
OPAL_OUTPUT((ompi_coll_tuned_stream, "Read communicator count %ld for dynamic rule for collective ID %ld\n", NCS, CI));
142-
alg_p->n_com_sizes = NCS;
143-
alg_p->com_rules = ompi_coll_tuned_mk_com_rules (NCS, CI);
164+
OPAL_OUTPUT((ompi_coll_tuned_stream, "Read communicator count %ld for dynamic rule for collective ID %ld\n", NCOMSIZES, COLID));
165+
alg_p->n_com_sizes = NCOMSIZES;
166+
alg_p->com_rules = ompi_coll_tuned_mk_com_rules (NCOMSIZES, COLID);
144167
if (NULL == alg_p->com_rules) {
145168
OPAL_OUTPUT((ompi_coll_tuned_stream,"Cannot allocate com rules for file [%s]\n", fname));
146169
goto on_file_error;
147170
}
148171

149-
for (ncs=0;ncs<NCS;ncs++) { /* for each comm size */
172+
for (ncs=0;ncs<NCOMSIZES;ncs++) { /* for each comm size */
150173

151174
com_p = &(alg_p->com_rules[ncs]);
152175

153-
if( (getnext (fptr, &CS) < 0) || (CS < 0) ) {
154-
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read communicator size for collective ID %ld com rule %d at around line %d\n", CI, ncs, fileline));
176+
/* get the communicator size to associate the set of rules with */
177+
if( (getnext (fptr, &COMSIZE) < 0) || (COMSIZE < 0) ) {
178+
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read communicator size for collective ID %ld com rule %d at around line %d\n", COLID, ncs, fileline));
155179
goto on_file_error;
156180
}
157181

158-
com_p->mpi_comsize = CS;
182+
com_p->mpi_comsize = COMSIZE;
159183

160-
if( (getnext (fptr, &NMS) < 0) || (NMS < 0) ) {
161-
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read number of message sizes for collective ID %ld com rule %d at around line %d\n", CI, ncs, fileline));
184+
/* get the number of message sizes to specify rules for. inner set size */
185+
if( (getnext (fptr, &NMSGSIZES) < 0) || (NMSGSIZES < 0) ) {
186+
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read number of message sizes for collective ID %ld com rule %d at around line %d\n", COLID, ncs, fileline));
162187
goto on_file_error;
163188
}
164189
OPAL_OUTPUT((ompi_coll_tuned_stream, "Read message count %ld for dynamic rule for collective ID %ld and comm size %ld\n",
165-
NMS, CI, CS));
166-
com_p->n_msg_sizes = NMS;
167-
com_p->msg_rules = ompi_coll_tuned_mk_msg_rules (NMS, CI, ncs, CS);
190+
NMSGSIZES, COLID, COMSIZE));
191+
com_p->n_msg_sizes = NMSGSIZES;
192+
com_p->msg_rules = ompi_coll_tuned_mk_msg_rules (NMSGSIZES, COLID, ncs, COMSIZE);
168193
if (NULL == com_p->msg_rules) {
169194
OPAL_OUTPUT((ompi_coll_tuned_stream,"Cannot allocate msg rules for file [%s]\n", fname));
170195
goto on_file_error;
171196
}
172197

173198
msg_p = com_p->msg_rules;
174199

175-
for (nms=0;nms<NMS;nms++) { /* for each msg size */
200+
for (nms=0;nms<NMSGSIZES;nms++) { /* for each msg size */
176201

177202
msg_p = &(com_p->msg_rules[nms]);
178203

179-
if( (getnext (fptr, &MS) < 0) || (MS < 0) ) {
180-
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read message size for collective ID %ld com rule %d msg rule %d at around line %d\n", CI, ncs, nms, fileline));
204+
/* read the message size to associate the rule with */
205+
if( (getnext (fptr, &MSGSIZE) < 0) || (MSGSIZE < 0) ) {
206+
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read message size for collective ID %ld com rule %d msg rule %d at around line %d\n", COLID, ncs, nms, fileline));
181207
goto on_file_error;
182208
}
183-
msg_p->msg_size = (size_t)MS;
209+
msg_p->msg_size = (size_t)MSGSIZE;
184210

211+
/* read the collective specific algorithm identifier */
185212
if( (getnext (fptr, &ALG) < 0) || (ALG < 0) ) {
186-
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read target algorithm method for collective ID %ld com rule %d msg rule %d at around line %d\n", CI, ncs, nms, fileline));
213+
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read target algorithm method for collective ID %ld com rule %d msg rule %d at around line %d\n", COLID, ncs, nms, fileline));
187214
goto on_file_error;
188215
}
189216
msg_p->result_alg = ALG;
190217

218+
/* read faninout tuning parameter. required */
191219
if( (getnext (fptr, &FANINOUT) < 0) || (FANINOUT < 0) ) {
192-
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read fan in/out topo for collective ID %ld com rule %d msg rule %d at around line %d\n", CI, ncs, nms, fileline));
220+
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read fan in/out topo for collective ID %ld com rule %d msg rule %d at around line %d\n", COLID, ncs, nms, fileline));
193221
goto on_file_error;
194222
}
195223
msg_p->result_topo_faninout = FANINOUT;
196224

197-
if( (getnext (fptr, &SS) < 0) || (SS < 0) ) {
198-
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read target segment size for collective ID %ld com rule %d msg rule %d at around line %d\n", CI, ncs, nms, fileline));
225+
/* read segsize tuning parameter. required */
226+
if( (getnext (fptr, &SEGSIZE) < 0) || (SEGSIZE < 0) ) {
227+
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read target segment size for collective ID %ld com rule %d msg rule %d at around line %d\n", COLID, ncs, nms, fileline));
199228
goto on_file_error;
200229
}
201-
msg_p->result_segsize = SS;
230+
msg_p->result_segsize = SEGSIZE;
231+
232+
/* read the max requests tuning parameter. optional */
233+
msg_p->result_max_requests = ompi_coll_tuned_alltoall_max_requests;
234+
if( isnext_digit(fptr) ) {
235+
if( (getnext (fptr, &MAXREQ) < 0) || (MAXREQ < 0) ) {
236+
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read max requests for collective ID %ld com rule %d msg rule %d at around line %d\n", COLID, ncs, nms, fileline));
237+
goto on_file_error;
238+
}
239+
msg_p->result_max_requests = MAXREQ;
240+
}
202241

203-
if (!nms && MS) {
242+
/* check the first rule is for 0 size. look-up depends on this */
243+
if (!nms && MSGSIZE) {
204244
OPAL_OUTPUT((ompi_coll_tuned_stream,"All algorithms must specify a rule for message size of zero upwards always first!\n"));
205-
OPAL_OUTPUT((ompi_coll_tuned_stream,"Message size was %lu for collective ID %ld com rule %d msg rule %d at around line %d\n", MS, CI, ncs, nms, fileline));
245+
OPAL_OUTPUT((ompi_coll_tuned_stream,"Message size was %lu for collective ID %ld com rule %d msg rule %d at around line %d\n", MSGSIZE, COLID, ncs, nms, fileline));
206246
goto on_file_error;
207247
}
208248

@@ -219,7 +259,7 @@ int ompi_coll_tuned_read_rules_config_file (char *fname, ompi_coll_alg_rule_t**
219259
} /* comm size */
220260

221261
total_alg_count++;
222-
OPAL_OUTPUT((ompi_coll_tuned_stream, "Done reading dynamic rule for collective ID %ld\n", CI));
262+
OPAL_OUTPUT((ompi_coll_tuned_stream, "Done reading dynamic rule for collective ID %ld\n", COLID));
223263

224264
} /* per collective */
225265

0 commit comments

Comments
 (0)