Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
MpiErrorHandler.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* MpiErrorHandler.cc (C) 2000-2020 */
9/* */
10/* Gestionnaire d'erreur pour MPI. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/parallel/mpi/MpiErrorHandler.h"
15
16#include "arcane/utils/FatalErrorException.h"
17
18/*---------------------------------------------------------------------------*/
19/*---------------------------------------------------------------------------*/
20
21namespace Arcane
22{
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27MpiErrorHandler::
28MpiErrorHandler()
29: m_err_handler(MPI_Errhandler())
30, m_has_err_handler(false)
31{
32}
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
37MpiErrorHandler::
38~MpiErrorHandler()
39{
40 removeHandler();
41}
42
43/*---------------------------------------------------------------------------*/
44/*---------------------------------------------------------------------------*/
45
46void MpiErrorHandler::
47removeHandler()
48{
49 if (m_has_err_handler){
50 MPI_Errhandler_free(&m_err_handler);
51 m_has_err_handler = false;
52 }
53}
54
55/*---------------------------------------------------------------------------*/
56/*---------------------------------------------------------------------------*/
57
58void MpiErrorHandler::
59registerHandler(MPI_Comm comm)
60{
61 if (m_has_err_handler)
62 ARCANE_FATAL("Handler already registered");
63
64 // Regarder s'il faut le rendre optionnel.
65 MPI_Comm_create_errhandler(&MpiErrorHandler::_ErrorHandler,&m_err_handler);
66 MPI_Comm_set_errhandler(comm,m_err_handler);
67 m_has_err_handler = true;
68}
69
70/*---------------------------------------------------------------------------*/
71/*---------------------------------------------------------------------------*/
72
73void MpiErrorHandler::
74_ErrorHandler(MPI_Comm* comm, int* error_code, ...)
75{
76 ARCANE_UNUSED(comm);
77
78 char error_buf[MPI_MAX_ERROR_STRING+1];
79 int error_len = 0;
80 int e = *error_code;
81 // int MPI_Error_string(int errorcode, char *string, int *resultlen);
82 MPI_Error_string(e,error_buf,&error_len);
83 error_buf[error_len] = '\0';
84 error_buf[MPI_MAX_ERROR_STRING] = '\0';
85
86 // int MPI_Error_class(int errorcode, int *errorclass);
87
88 ARCANE_FATAL("Error in MPI call code={0} msg={1}",*error_code,error_buf);
89}
90
91/*---------------------------------------------------------------------------*/
92/*---------------------------------------------------------------------------*/
93
94} // End namespace Arcane
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-