Logo AND Algorithmique Numérique Distribuée

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