Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2023.
[simgrid.git] / src / smpi / mpi / smpi_errhandler.cpp
1 /* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "smpi_errhandler.hpp"
7 #include "private.hpp"
8
9 #include <cstdio>
10
11 simgrid::smpi::Errhandler smpi_MPI_ERRORS_RETURN;
12 simgrid::smpi::Errhandler smpi_MPI_ERRORS_ARE_FATAL;
13
14 namespace simgrid::smpi {
15
16 MPI_Errhandler Errhandler::f2c(int id) {
17   if (F2C::lookup() != nullptr && id >= 0) {
18     return static_cast<MPI_Errhandler>(F2C::lookup()->at(id));
19   } else {
20     return MPI_ERRHANDLER_NULL;
21   }
22 }
23
24 void Errhandler::call(MPI_Comm comm, int errorcode) const
25 {
26   comm_func_(&comm, &errorcode);
27 }
28
29 void Errhandler::call(MPI_Win win, int errorcode) const
30 {
31   win_func_(&win, &errorcode);
32 }
33
34 void Errhandler::call(MPI_File file, int errorcode) const
35 {
36   file_func_(&file, &errorcode);
37 }
38
39 void Errhandler::ref()
40 {
41   refcount_++;
42 }
43
44 void Errhandler::unref(Errhandler* errhandler){
45   if(errhandler == MPI_ERRORS_ARE_FATAL || errhandler == MPI_ERRORS_RETURN)
46     return;
47   errhandler->refcount_--;
48   if(errhandler->refcount_==0){
49     F2C::free_f(errhandler->f2c_id());
50     delete errhandler;
51   }
52 }
53
54 } // namespace simgrid::smpi