Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Finally use plain ints for f2c keys.
[simgrid.git] / src / smpi / mpi / smpi_f2c.cpp
1 /* Copyright (c) 2007-2020. 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::unordered_map<int, F2C*>* F2C::f2c_lookup_ = nullptr;
19 int F2C::f2c_id_ = 0;
20
21 // Keep it non trivially-constructible, or it will break MC+smpi on FreeBSD with Clang (don't ask why)
22 F2C::F2C() = default;
23
24 std::unordered_map<int, F2C*>* F2C::f2c_lookup()
25 {
26   return f2c_lookup_;
27 }
28
29 void F2C::set_f2c_lookup(std::unordered_map<int, F2C*>* map)
30 {
31   f2c_lookup_ = map;
32 }
33
34 void F2C::f2c_id_increment(){
35   f2c_id_++;
36 }
37
38 int F2C::f2c_id(){
39   return f2c_id_;
40 }
41
42 void F2C::delete_lookup(){
43   delete f2c_lookup_;
44 }
45
46 std::unordered_map<int, F2C*>* F2C::lookup()
47 {
48   return f2c_lookup_;
49 }
50
51 void F2C::free_f(int id)
52 {
53   f2c_lookup_->erase(id);
54 }
55
56 int F2C::add_f()
57 {
58   if (f2c_lookup_ == nullptr)
59     f2c_lookup_ = new std::unordered_map<int, F2C*>();
60
61   my_f2c_id_                 = f2c_id();
62   (*f2c_lookup_)[my_f2c_id_] = this;
63   f2c_id_increment();
64   return my_f2c_id_;
65 }
66
67 int F2C::c2f()
68 {
69   if (f2c_lookup_ == nullptr) {
70     f2c_lookup_ = new std::unordered_map<int, F2C*>();
71   }
72
73   if(my_f2c_id_==-1)
74     /* this function wasn't found, add it */
75     return this->add_f();
76   else
77     return my_f2c_id_;
78 }
79
80 F2C* F2C::f2c(int id)
81 {
82   if (f2c_lookup_ == nullptr)
83     f2c_lookup_ = new std::unordered_map<int, F2C*>();
84
85   if(id >= 0){
86     auto comm = f2c_lookup_->find(id);
87     return comm == f2c_lookup_->end() ? nullptr : comm->second;
88   }else
89     return nullptr;
90 }
91
92 }
93 }