1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
|
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2015 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2011-2012 FUJITSU LIMITED. All rights reserved.
* Copyright (c) 2017 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include "mpi.h"
#include "ompi/mca/mca.h"
#include "ompi/constants.h"
#include "coll_tuned.h"
/* need to include our own topo prototypes so we can malloc data on the comm correctly */
#include "ompi/mca/coll/base/coll_base_topo.h"
/* also need the dynamic rule structures */
#include "coll_tuned_dynamic_rules.h"
#include <stdlib.h>
#include <stdio.h>
#include "ompi/mca/coll/base/coll_base_util.h"
ompi_coll_alg_rule_t* ompi_coll_tuned_mk_alg_rules (int n_alg)
{
int i;
ompi_coll_alg_rule_t* alg_rules;
alg_rules = (ompi_coll_alg_rule_t *) calloc (n_alg, sizeof (ompi_coll_alg_rule_t));
if (!alg_rules) return (alg_rules);
/* set all we can at this point */
for (i=0;i<n_alg;i++) {
alg_rules[i].alg_rule_id = i;
}
return (alg_rules);
}
ompi_coll_com_rule_t* ompi_coll_tuned_mk_com_rules (int n_com_rules, int alg_rule_id)
{
int i;
ompi_coll_com_rule_t * com_rules;
com_rules = (ompi_coll_com_rule_t *) calloc (n_com_rules, sizeof (ompi_coll_com_rule_t));
if (!com_rules) return (com_rules);
for (i=0;i<n_com_rules;i++) {
com_rules[i].mpi_comsize = 0; /* unknown */
com_rules[i].alg_rule_id = alg_rule_id;
com_rules[i].com_rule_id = i;
com_rules[i].n_msg_sizes = 0; /* unknown */
com_rules[i].msg_rules = (ompi_coll_msg_rule_t *) NULL;
}
return (com_rules);
}
ompi_coll_msg_rule_t* ompi_coll_tuned_mk_msg_rules (int n_msg_rules, int alg_rule_id, int com_rule_id, int mpi_comsize)
{
int i;
ompi_coll_msg_rule_t *msg_rules;
msg_rules = (ompi_coll_msg_rule_t *) calloc (n_msg_rules, sizeof (ompi_coll_msg_rule_t));
if (!msg_rules) return (msg_rules);
for( i = 0; i < n_msg_rules; i++ ) {
msg_rules[i].mpi_comsize = mpi_comsize;
msg_rules[i].alg_rule_id = alg_rule_id;
msg_rules[i].com_rule_id = com_rule_id;
msg_rules[i].msg_rule_id = i;
msg_rules[i].msg_size = 0; /* unknown */
msg_rules[i].result_alg = 0; /* unknown */
msg_rules[i].result_topo_faninout = 0; /* unknown */
msg_rules[i].result_segsize = 0; /* unknown */
msg_rules[i].result_max_requests = 0; /* unknown & default */
}
return (msg_rules);
}
/*
* Debug / IO routines
*
*/
int ompi_coll_tuned_dump_msg_rule (ompi_coll_msg_rule_t* msg_p)
{
if (!msg_p) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Message rule was a NULL ptr?!\n"));
return (-1);
}
OPAL_OUTPUT((ompi_coll_tuned_stream,"alg_id %3d\tcom_id %3d\tcom_size %3d\tmsg_id %3d\t", msg_p->alg_rule_id,
msg_p->com_rule_id, msg_p->mpi_comsize, msg_p->msg_rule_id));
OPAL_OUTPUT((ompi_coll_tuned_stream,"msg_size %10lu -> algorithm %2d\ttopo in/out %2d\tsegsize %5ld\tmax_requests %4d\n",
msg_p->msg_size, msg_p->result_alg, msg_p->result_topo_faninout, msg_p->result_segsize,
msg_p->result_max_requests));
return (0);
}
int ompi_coll_tuned_dump_com_rule (ompi_coll_com_rule_t* com_p)
{
int i;
if (!com_p) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Com rule was a NULL ptr?!\n"));
return (-1);
}
OPAL_OUTPUT((ompi_coll_tuned_stream, "alg_id %3d\tcom_id %3d\tcom_size %3d\t", com_p->alg_rule_id, com_p->com_rule_id, com_p->mpi_comsize));
if (!com_p->n_msg_sizes) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"no msgsizes defined\n"));
return (0);
}
OPAL_OUTPUT((ompi_coll_tuned_stream,"number of message sizes %3d\n", com_p->n_msg_sizes));
for (i=0;i<com_p->n_msg_sizes;i++) {
ompi_coll_tuned_dump_msg_rule (&(com_p->msg_rules[i]));
}
return (0);
}
int ompi_coll_tuned_dump_alg_rule (ompi_coll_alg_rule_t* alg_p)
{
int i;
if (!alg_p) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Algorithm rule was a NULL ptr?!\n"));
return (-1);
}
OPAL_OUTPUT((ompi_coll_tuned_stream,"alg_id %3d\t", alg_p->alg_rule_id));
if (!alg_p->n_com_sizes) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"no coms defined\n"));
return (0);
}
OPAL_OUTPUT((ompi_coll_tuned_stream,"number of com sizes %3d\n", alg_p->n_com_sizes));
for (i=0;i<alg_p->n_com_sizes;i++) {
ompi_coll_tuned_dump_com_rule (&(alg_p->com_rules[i]));
}
return (0);
}
int ompi_coll_tuned_dump_all_rules (ompi_coll_alg_rule_t* alg_p, int n_rules)
{
int i;
if (!alg_p) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Algorithm rule was a NULL ptr?!\n"));
return (-1);
}
OPAL_OUTPUT((ompi_coll_tuned_stream,"Number of algorithm rules %3d\n", n_rules));
for (i=0;i<n_rules;i++) {
ompi_coll_tuned_dump_alg_rule (&(alg_p[i]));
}
return (0);
}
/*
* Memory free routines
*
*/
int ompi_coll_tuned_free_msg_rules_in_com_rule (ompi_coll_com_rule_t* com_p)
{
int rc=0;
ompi_coll_msg_rule_t* msg_p;
if (!com_p) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"attempt to free NULL com_rule ptr\n"));
return (-1);
}
if (com_p->n_msg_sizes) {
msg_p = com_p->msg_rules;
if (!msg_p) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"attempt to free NULL msg_rules when msg count was %d\n", com_p->n_msg_sizes));
rc = -1; /* some error */
}
else {
/* ok, memory exists for the msg rules so free that first */
free (com_p->msg_rules);
com_p->msg_rules = (ompi_coll_msg_rule_t*) NULL;
}
} /* if we have msg rules to free as well */
return (rc);
}
int ompi_coll_tuned_free_coms_in_alg_rule (ompi_coll_alg_rule_t* alg_p)
{
int rc=0;
int i;
ompi_coll_com_rule_t* com_p;
if (!alg_p) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"attempt to free NULL alg_rule ptr\n"));
return (-1);
}
if (alg_p->n_com_sizes) {
com_p = alg_p->com_rules;
if (!com_p) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"attempt to free NULL com_rules when com count was %d\n", alg_p->n_com_sizes));
} else {
/* ok, memory exists for the com rules so free their message rules first */
for( i = 0; i < alg_p->n_com_sizes; i++ ) {
com_p = &(alg_p->com_rules[i]);
ompi_coll_tuned_free_msg_rules_in_com_rule (com_p);
}
/* we are now free to free the com rules themselives */
free (alg_p->com_rules);
alg_p->com_rules = (ompi_coll_com_rule_t*) NULL;
}
} /* if we have msg rules to free as well */
return (rc);
}
int ompi_coll_tuned_free_all_rules (ompi_coll_alg_rule_t* alg_p, int n_algs)
{
int i;
int rc = 0;
for( i = 0; i < n_algs; i++ ) {
rc += ompi_coll_tuned_free_coms_in_alg_rule (&(alg_p[i]));
}
free (alg_p);
return (rc);
}
/*
* query functions
* i.e. the functions that get me the algorithm, topo fanin/out and segment size fast
* and also get the rules that are needed by each communicator as needed
*
*/
/*
* This function is used to get the pointer to the nearest (less than or equal)
* com rule for this MPI collective (alg_id) for a given
* MPI communicator size. The complete rule base must be presented.
*
* If no rule exits returns NULL, else the com rule ptr
* (which can be used in the coll_tuned_get_target_method_params() call)
*
*/
ompi_coll_com_rule_t* ompi_coll_tuned_get_com_rule_ptr (ompi_coll_alg_rule_t* rules, int alg_id, int mpi_comsize)
{
ompi_coll_alg_rule_t* alg_p = (ompi_coll_alg_rule_t*) NULL;
ompi_coll_com_rule_t* com_p = (ompi_coll_com_rule_t*) NULL;
ompi_coll_com_rule_t* best_com_p = (ompi_coll_com_rule_t*) NULL;
int i;
if (!rules) { /* no rule base no resulting com rule */
return ((ompi_coll_com_rule_t*)NULL);
}
alg_p = &(rules[alg_id]); /* get the algorithm rule pointer */
if (!alg_p->n_com_sizes) { /* check for count of communicator sizes */
return ((ompi_coll_com_rule_t*)NULL); /* no com sizes so no rule */
}
/* ok have some com sizes, now to find the one closest to my mpi_comsize */
/* make a copy of the first com rule */
best_com_p = com_p = alg_p->com_rules;
i = 0;
while( i < alg_p->n_com_sizes ) {
if (com_p->mpi_comsize > mpi_comsize) {
break;
}
best_com_p = com_p;
/* go to the next entry */
com_p++;
i++;
}
OPAL_OUTPUT((ompi_coll_tuned_stream,"Selected the following com rule id %d\n", best_com_p->com_rule_id));
ompi_coll_tuned_dump_com_rule (best_com_p);
return (best_com_p);
}
/*
* This function takes a com_rule ptr (from the communicators coll tuned data structure)
* (Which is chosen for a particular MPI collective)
* and a (total_)msg_size and it returns (0) and a algorithm to use and a recommended topo faninout and segment size
* all based on the user supplied rules
*
* Just like the above functions it uses a less than or equal msg size
* (hense config file must have a default defined for '0' if we reach this point)
* else if no rules match we return '0' + '0,0' or used fixed decision table with no topo chand and no segmentation
* of users data.. shame.
*
* On error return 0 so we default to fixed rules anyway :)
*
*/
int ompi_coll_tuned_get_target_method_params (ompi_coll_com_rule_t* base_com_rule, size_t mpi_msgsize, int *result_topo_faninout,
int* result_segsize, int* max_requests)
{
ompi_coll_msg_rule_t* msg_p = (ompi_coll_msg_rule_t*) NULL;
ompi_coll_msg_rule_t* best_msg_p = (ompi_coll_msg_rule_t*) NULL;
int i;
/* No rule or zero rules */
if( (NULL == base_com_rule) || (0 == base_com_rule->n_msg_sizes)) {
return (0);
}
/* ok have some msg sizes, now to find the one closest to my mpi_msgsize */
/* make a copy of the first msg rule */
best_msg_p = msg_p = base_com_rule->msg_rules;
i = 0;
while (i<base_com_rule->n_msg_sizes) {
/* OPAL_OUTPUT((ompi_coll_tuned_stream,"checking mpi_msgsize %d against com_id %d msg_id %d index %d msg_size %d", */
/* mpi_msgsize, msg_p->com_rule_id, msg_p->msg_rule_id, i, msg_p->msg_size)); */
if (msg_p->msg_size <= mpi_msgsize) {
best_msg_p = msg_p;
/* OPAL_OUTPUT((ompi_coll_tuned_stream(":ok\n")); */
}
else {
/* OPAL_OUTPUT((ompi_coll_tuned_stream(":nop\n")); */
break;
}
/* go to the next entry */
msg_p++;
i++;
}
OPAL_OUTPUT((ompi_coll_tuned_stream,"Selected the following msg rule id %d\n", best_msg_p->msg_rule_id));
ompi_coll_tuned_dump_msg_rule (best_msg_p);
/* return the segment size */
*result_topo_faninout = best_msg_p->result_topo_faninout;
/* return the segment size */
*result_segsize = best_msg_p->result_segsize;
/* return the maximum requests */
*max_requests = best_msg_p->result_max_requests;
/* return the algorithm/method to use */
return (best_msg_p->result_alg);
}
|