Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Don't add handles to the lookup for the sake of just removing them immediately...
[simgrid.git] / src / smpi / mpi / smpi_f2c.cpp
1 /* Copyright (c) 2007-2021. 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
10 int mpi_in_place_;
11 int mpi_bottom_;
12 int mpi_status_ignore_;
13 int mpi_statuses_ignore_;
14
15 namespace simgrid{
16 namespace 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   my_f2c_id_                 = global_f2c_id();
29   (*f2c_lookup_)[my_f2c_id_] = this;
30   f2c_id_increment();
31   return my_f2c_id_;
32 }
33
34 int F2C::c2f()
35 {
36   allocate_lookup();
37
38   if(my_f2c_id_==-1)
39     /* this function wasn't found, add it */
40     return this->add_f();
41   else
42     return my_f2c_id_;
43 }
44
45 F2C* F2C::f2c(int id)
46 {
47   allocate_lookup();
48
49   if(id >= 0){
50     auto comm = f2c_lookup_->find(id);
51     return comm == f2c_lookup_->end() ? nullptr : comm->second;
52   }else
53     return nullptr;
54 }
55
56 }
57 }