Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / src / smpi / mpi / smpi_f2c.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_f2c.hpp"
7 #include "private.hpp"
8 #include "src/smpi/include/smpi_actor.hpp"
9 #include "src/instr/instr_smpi.hpp"
10
11 const int mpi_in_place_        = -222;
12 const int mpi_bottom_          = -111;
13 const int mpi_status_ignore_   = 0;
14 const int mpi_statuses_ignore_ = 0;
15
16 namespace simgrid::smpi {
17
18 std::unique_ptr<F2C::f2c_lookup_type> F2C::f2c_lookup_    = nullptr;
19 int F2C::f2c_id_ = 0;
20 F2C::f2c_lookup_type::size_type F2C::num_default_handles_ = 0;
21
22 // Keep it non trivially-constructible, or it will break MC+smpi on FreeBSD with Clang (don't ask why)
23 F2C::F2C() = default;
24
25 int F2C::add_f()
26 {
27   allocate_lookup();
28   if (auto const* loc = smpi_process()->call_location(); loc && loc->linenumber != 0)
29     call_location_= std::string (loc->filename + ":" + std::to_string(loc->linenumber));
30   my_f2c_id_                 = global_f2c_id();
31   (*f2c_lookup_)[my_f2c_id_] = this;
32   f2c_id_increment();
33   return my_f2c_id_;
34 }
35
36 int F2C::c2f()
37 {
38   allocate_lookup();
39
40   if(my_f2c_id_==-1)
41     /* this function wasn't found, add it */
42     return this->add_f();
43   else
44     return my_f2c_id_;
45 }
46
47 F2C* F2C::f2c(int id)
48 {
49   allocate_lookup();
50
51   if(id >= 0){
52     auto comm = f2c_lookup_->find(id);
53     return comm == f2c_lookup_->end() ? nullptr : comm->second;
54   }else
55     return nullptr;
56 }
57
58 } // namespace simgrid::smpi