Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[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::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 int F2C::add_f()
25 {
26   if (f2c_lookup_ == nullptr)
27     f2c_lookup_ = new std::unordered_map<int, F2C*>();
28
29   my_f2c_id_                 = f2c_id();
30   (*f2c_lookup_)[my_f2c_id_] = this;
31   f2c_id_increment();
32   return my_f2c_id_;
33 }
34
35 int F2C::c2f()
36 {
37   if (f2c_lookup_ == nullptr) {
38     f2c_lookup_ = new std::unordered_map<int, F2C*>();
39   }
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   if (f2c_lookup_ == nullptr)
51     f2c_lookup_ = new std::unordered_map<int, F2C*>();
52
53   if(id >= 0){
54     auto comm = f2c_lookup_->find(id);
55     return comm == f2c_lookup_->end() ? nullptr : comm->second;
56   }else
57     return nullptr;
58 }
59
60 }
61 }