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 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2020 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) 2006 University of Houston. All rights reserved.
* Copyright (c) 2008-2022 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) 2010-2011 Oak Ridge National Labs. All rights reserved.
* Copyright (c) 2012 Los Alamos National Security, LLC.
* All rights reserved.
* Copyright (c) 2016-2019 Intel, Inc. All rights reserved.
* Copyright (c) 2018 Amazon.com, Inc. or its affiliates. All Rights reserved.
* Copyright (c) 2018-2021 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include <stdlib.h>
#include <stdarg.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include "opal/util/show_help.h"
#include "ompi/runtime/ompi_rte.h"
#include "ompi/errhandler/errhandler_predefined.h"
#include "ompi/errhandler/errcode.h"
#include "ompi/communicator/communicator.h"
#include "ompi/file/file.h"
#include "ompi/win/win.h"
#include "ompi/instance/instance.h"
#include "opal/util/printf.h"
#include "opal/util/output.h"
#include "ompi/runtime/mpiruntime.h"
/*
* Local functions
*/
static void backend_abort(int fatal, char *type, struct ompi_communicator_t *comm,
char *name, int *error_code, va_list arglist);
static void backend_abort_aggregate(int fatal, char *type,
struct ompi_communicator_t *comm,
char *name, int *error_code,
va_list arglist);
static void backend_abort_no_aggregate(int fatal, char *type,
struct ompi_communicator_t *comm,
char *name, int *error_code,
va_list arglist);
static void out(char *str, char *arg);
void ompi_mpi_errors_are_fatal_comm_handler(struct ompi_communicator_t **comm,
int *error_code, ...)
{
char *name;
struct ompi_communicator_t *abort_comm;
va_list arglist;
va_start(arglist, error_code);
if ( (NULL != comm) && (NULL != *comm) ) {
name = (*comm)->c_name;
abort_comm = *comm;
} else {
name = NULL;
abort_comm = NULL;
}
backend_abort(true, "communicator", abort_comm, name, error_code, arglist);
va_end(arglist);
}
void ompi_mpi_errors_are_fatal_file_handler(struct ompi_file_t **file,
int *error_code, ...)
{
char *name;
struct ompi_communicator_t *abort_comm;
va_list arglist;
va_start(arglist, error_code);
if (NULL != file) {
name = (*file)->f_filename;
abort_comm = (*file)->f_comm;
} else {
name = NULL;
abort_comm = NULL;
}
backend_abort(true, "file", abort_comm, name, error_code, arglist);
va_end(arglist);
}
void ompi_mpi_errors_are_fatal_win_handler(struct ompi_win_t **win,
int *error_code, ...)
{
char *name;
struct ompi_communicator_t *abort_comm = NULL;
va_list arglist;
va_start(arglist, error_code);
if (NULL != win) {
name = (*win)->w_name;
} else {
name = NULL;
}
backend_abort(true, "win", abort_comm, name, error_code, arglist);
va_end(arglist);
}
void ompi_mpi_errors_abort_comm_handler(struct ompi_communicator_t **comm,
int *error_code, ...)
{
char *name;
struct ompi_communicator_t *abort_comm;
va_list arglist;
va_start(arglist, error_code);
if ( (NULL != comm) && (NULL != *comm) ) {
name = (*comm)->c_name;
abort_comm = *comm;
} else {
name = NULL;
abort_comm = NULL;
}
backend_abort(false, "communicator", abort_comm, name, error_code, arglist);
va_end(arglist);
}
void ompi_mpi_errors_abort_file_handler(struct ompi_file_t **file,
int *error_code, ...)
{
char *name;
struct ompi_communicator_t *abort_comm;
va_list arglist;
va_start(arglist, error_code);
if (NULL != file) {
name = (*file)->f_filename;
abort_comm = (*file)->f_comm;
} else {
name = NULL;
abort_comm = NULL;
}
backend_abort(false, "file", abort_comm, name, error_code, arglist);
va_end(arglist);
}
void ompi_mpi_errors_abort_win_handler(struct ompi_win_t **win,
int *error_code, ...)
{
char *name;
struct ompi_communicator_t *abort_comm = NULL;
va_list arglist;
va_start(arglist, error_code);
if (NULL != win) {
name = (*win)->w_name;
} else {
name = NULL;
}
backend_abort(false, "win", abort_comm, name, error_code, arglist);
va_end(arglist);
}
void ompi_mpi_errors_are_fatal_instance_handler (struct ompi_instance_t **instance,
int *error_code, ...)
{
char *name;
va_list arglist;
int err = MPI_ERR_UNKNOWN;
va_start(arglist, error_code);
if (NULL != instance) {
name = (*instance)->i_name;
} else {
name = NULL;
}
if (NULL != error_code) {
err = *error_code;
}
/* We only want aggregation while the rte is initialized */
if (ompi_rte_initialized) {
backend_abort_aggregate(true, "session", NULL, name, error_code, arglist);
} else {
backend_abort_no_aggregate(true, "session", NULL, name, error_code, arglist);
}
va_end(arglist);
ompi_mpi_abort(NULL, err);
}
void ompi_mpi_errors_return_comm_handler(struct ompi_communicator_t **comm,
int *error_code, ...)
{
/* Don't need anything more -- just need this function to exist */
/* Silence some compiler warnings */
va_list arglist;
va_start(arglist, error_code);
va_end(arglist);
}
void ompi_mpi_errors_return_file_handler(struct ompi_file_t **file,
int *error_code, ...)
{
/* Don't need anything more -- just need this function to exist */
/* Silence some compiler warnings */
va_list arglist;
va_start(arglist, error_code);
va_end(arglist);
}
void ompi_mpi_errors_return_win_handler(struct ompi_win_t **win,
int *error_code, ...)
{
/* Don't need anything more -- just need this function to exist */
/* Silence some compiler warnings */
va_list arglist;
va_start(arglist, error_code);
va_end(arglist);
}
void ompi_mpi_errors_return_instance_handler (struct ompi_instance_t **instance,
int *error_code, ...)
{
/* Don't need anything more -- just need this function to exist */
/* Silence some compiler warnings */
va_list arglist;
va_start(arglist, error_code);
va_end(arglist);
}
static void out(char *str, char *arg)
{
if (ompi_rte_initialized &&
ompi_mpi_state < OMPI_MPI_STATE_FINALIZE_PAST_COMM_SELF_DESTRUCT) {
if (NULL != arg) {
opal_output(0, str, arg);
} else {
opal_output(0, "%s", str);
}
} else {
if (NULL != arg) {
fprintf(stderr, str, arg);
} else {
fprintf(stderr, "%s", str);
}
}
}
/*
* Use opal_show_help() to aggregate the error messages (i.e., show it
* once rather than N times).
*
* Note that this function will only be invoked for errors during the
* MPI application (i.e., after MPI_INIT and before MPI_FINALIZE). So
* there's no need to handle the pre-MPI_INIT and post-MPI_FINALIZE
* errors here.
*/
static void backend_abort_aggregate(int fatal, char *type,
struct ompi_communicator_t *comm,
char *name, int *error_code,
va_list arglist)
{
char *arg = NULL, *prefix = NULL, *err_msg = NULL;
const char* const unknown_error_code = "Error code: %d (no associated error message)";
const char* const unknown_error = "Unknown error";
const char* const unknown_prefix = "[?:?]";
bool generated = false;
// these do not own what they point to; they're
// here to avoid repeating expressions such as
// (NULL == foo) ? unknown_foo : foo
const char* usable_prefix = unknown_prefix;
const char* usable_err_msg = unknown_error;
arg = va_arg(arglist, char*);
va_end(arglist);
if (opal_asprintf(&prefix, "[%s:%05d]",
ompi_process_info.nodename,
(int) ompi_process_info.pid) == -1) {
prefix = NULL;
// non-abort, we could still go on to give useful information here...
opal_output(0, "%s", "Could not write node and PID to prefix");
opal_output(0, "Node: %s", ompi_process_info.nodename);
opal_output(0, "PID: %d", (int) ompi_process_info.pid);
}
if (NULL != error_code) {
err_msg = ompi_mpi_errnum_get_string(*error_code);
if (NULL == err_msg) {
if (opal_asprintf(&err_msg, unknown_error_code,
*error_code) == -1) {
err_msg = NULL;
opal_output(0, "%s", "Could not write to err_msg");
opal_output(0, unknown_error_code, *error_code);
} else {
generated = true;
}
}
}
usable_prefix = (NULL == prefix) ? unknown_prefix : prefix;
usable_err_msg = (NULL == err_msg) ? unknown_error : err_msg;
if (NULL != name) {
// For the show_help topic checker script
// SHOW_HELP:"help-mpi-errors.txt","mpi_errors_are_fatal"
// SHOW_HELP:"help-mpi-errors.txt","mpi_errors_abort"
opal_show_help("help-mpi-errors.txt",
fatal? "mpi_errors_are_fatal": "mpi_errors_abort",
false,
usable_prefix,
(NULL == arg) ? "" : "in",
(NULL == arg) ? "" : arg,
usable_prefix,
OMPI_PROC_MY_NAME->jobid,
OMPI_PROC_MY_NAME->vpid,
usable_prefix,
type,
name,
usable_prefix,
usable_err_msg,
usable_prefix,
type,
usable_prefix);
} else {
opal_show_help("help-mpi-errors.txt",
"mpi_errors_are_fatal unknown handle",
false,
usable_prefix,
(NULL == arg) ? "" : "in",
(NULL == arg) ? "" : arg,
usable_prefix,
OMPI_PROC_MY_NAME->jobid,
OMPI_PROC_MY_NAME->vpid,
usable_prefix,
type,
usable_prefix,
usable_err_msg,
usable_prefix,
type,
usable_prefix);
}
free(prefix);
if (generated) {
free(err_msg);
}
}
/*
* Note that this function has to handle pre-MPI_INIT and
* post-MPI_FINALIZE errors, which backend_abort_aggregate() does not
* have to handle.
*
* This function also intentionally does not call malloc(), just in
* case we're being called due to some kind of stack/memory error --
* we *might* be able to get a message out if we're not further
* corrupting the stack by calling malloc()...
*/
static void backend_abort_no_aggregate(int fatal, char *type,
struct ompi_communicator_t *comm,
char *name, int *error_code,
va_list arglist)
{
char *arg;
int32_t state = ompi_mpi_state;
assert(state < OMPI_MPI_STATE_INIT_COMPLETED ||
state >= OMPI_MPI_STATE_FINALIZE_PAST_COMM_SELF_DESTRUCT);
fflush(stdout);
fflush(stderr);
arg = va_arg(arglist, char*);
/* Per #2152, print out in plain english if something was invoked
before MPI_INIT* or after MPI_FINALIZE */
if (state < OMPI_MPI_STATE_INIT_STARTED) {
if (NULL != arg) {
out("*** The %s() function was called before MPI_INIT was invoked.\n"
"*** This is disallowed by the MPI standard.\n", arg);
} else {
out("*** An MPI function was called before MPI_INIT was invoked.\n"
"*** This is disallowed by the MPI standard.\n"
"*** Unfortunately, no further information is available on *which* MPI\n"
"*** function was invoked, sorry. :-(\n", NULL);
}
if(fatal) out("*** Your MPI job will now abort.\n", NULL);
} else if (state >= OMPI_MPI_STATE_FINALIZE_PAST_COMM_SELF_DESTRUCT) {
if (NULL != arg) {
out("*** The %s() function was called after MPI_FINALIZE was invoked.\n"
"*** This is disallowed by the MPI standard.\n", arg);
} else {
out("*** An MPI function was called after MPI_FINALIZE was invoked.\n"
"*** This is disallowed by the MPI standard.\n"
"*** Unfortunately, no further information is available on *which* MPI\n"
"*** function was invoked, sorry. :-(\n", NULL);
}
if(fatal) out("*** Your MPI job will now abort.\n", NULL);
}
else {
int len;
char str[MPI_MAX_PROCESSOR_NAME * 2];
/* THESE MESSAGES ARE COORDINATED WITH FIXED STRINGS IN
help-mpi-errors.txt! Do not change these messages without
also changing help-mpi-errors.txt! */
/* This is after MPI_INIT* and before MPI_FINALIZE, so print
the error message normally */
if (NULL != arg) {
out("*** An error occurred in %s\n", arg);
} else {
out("*** An error occurred\n", NULL);
}
if (NULL != name) {
/* Don't use opal_asprintf() here because there may be stack /
heap corruption by the time we're invoked, so just do
it on the stack */
str[0] = '\0';
len = sizeof(str) - 1;
strncat(str, type, len);
len -= strlen(type);
if (len > 0) {
strncat(str, " ", len - 1);
--len;
if (len > 0) {
strncat(str, name, len - 1);
}
}
out("*** on %s", str);
} else if (NULL == name) {
out("*** on a NULL %s\n", type);
}
if (NULL != error_code) {
char *tmp = ompi_mpi_errnum_get_string(*error_code);
if (NULL != tmp) {
out("*** %s\n", tmp);
} else {
char intbuf[32];
snprintf(intbuf, 32, "%d", *error_code);
out("*** Error code: %d (no associated error message)\n", intbuf);
}
}
/* out("*** MPI_ERRORS_ABORT: your MPI job will now abort\n", NULL); */
if(fatal) {
out("*** MPI_ERRORS_ARE_FATAL (processes in this %s will now abort,\n", type);
out("*** and MPI will try to terminate your MPI job as well)\n", NULL);
}
else {
out("*** MPI_ERRORS_ABORT (processes in this %s will now abort,\n", type);
out("*** and potentially the rest of your MPI job)\n", NULL);
}
}
va_end(arglist);
}
static void backend_abort(int fatal, char *type, struct ompi_communicator_t *comm,
char *name, int *error_code,
va_list arglist)
{
int err = MPI_ERR_UNKNOWN;
/* We only want aggregation while the rte is initialized */
if (ompi_rte_initialized) {
backend_abort_aggregate(fatal, type, comm, name, error_code, arglist);
} else {
backend_abort_no_aggregate(fatal, type, comm, name, error_code, arglist);
}
/* In most instances the communicator will be valid. If not, we are either early in
* the initialization or we are dealing with a window. Thus, it is good enough to abort
* on MPI_COMM_SELF, the error will propagate.
*/
if (comm == NULL) {
comm = &ompi_mpi_comm_self.comm;
}
if (NULL != error_code)
err = *error_code;
/* Call abort without a specified comm to force RTE Job termination */
ompi_mpi_abort(fatal? NULL: comm, err);
}
|