Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0c0cab391272601596598da1c7618055880db87f
[simgrid.git] / src / smpi / mpi / smpi_f2c.cpp
1 /* Copyright (c) 2007-2019. 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 #include <cstdio>
11
12 int mpi_in_place_;
13 int mpi_bottom_;
14 int mpi_status_ignore_;
15 int mpi_statuses_ignore_;
16
17 namespace simgrid{
18 namespace smpi{
19
20 std::unordered_map<std::string, F2C*>* F2C::f2c_lookup_ = nullptr;
21 int F2C::f2c_id_ = 0;
22
23 std::unordered_map<std::string, F2C*>* F2C::f2c_lookup()
24 {
25   return f2c_lookup_;
26 }
27
28 void F2C::set_f2c_lookup(std::unordered_map<std::string, F2C*>* map)
29 {
30   f2c_lookup_ = map;
31 }
32
33 void F2C::f2c_id_increment(){
34   f2c_id_++;
35 }
36
37 int F2C::f2c_id(){
38   return f2c_id_;
39 }
40
41 char* F2C::get_my_key(char* key) {
42   std::snprintf(key, KEY_SIZE, "%d", my_f2c_id_);
43   return key;
44 }
45
46 char* F2C::get_key(char* key, int id) {
47   std::snprintf(key, KEY_SIZE, "%d", id);
48   return key;
49 }
50
51 void F2C::delete_lookup(){
52   delete f2c_lookup_;
53 }
54
55 std::unordered_map<std::string, F2C*>* F2C::lookup()
56 {
57   return f2c_lookup_;
58 }
59
60 void F2C::free_f(int id)
61 {
62   char key[KEY_SIZE];
63   f2c_lookup_->erase(get_key(key,id));
64 }
65
66 int F2C::add_f()
67 {
68   if (f2c_lookup_ == nullptr)
69     f2c_lookup_ = new std::unordered_map<std::string, F2C*>;
70
71   char key[KEY_SIZE];
72   my_f2c_id_=f2c_id_;
73   (*f2c_lookup_)[get_my_key(key)] = this;
74   f2c_id_increment();
75   return my_f2c_id_;
76 }
77
78 int F2C::c2f()
79 {
80   if (f2c_lookup_ == nullptr) {
81     f2c_lookup_ = new std::unordered_map<std::string, F2C*>;
82   }
83
84   if(my_f2c_id_==-1)
85     /* this function wasn't found, add it */
86     return this->add_f();
87   else
88     return my_f2c_id_;
89 }
90
91 F2C* F2C::f2c(int id)
92 {
93   if (f2c_lookup_ == nullptr)
94     f2c_lookup_ = new std::unordered_map<std::string, F2C*>;
95
96   if(id >= 0){
97     char key[KEY_SIZE];
98     auto comm = f2c_lookup_->find(get_key(key,id));
99     return comm == f2c_lookup_->end() ? nullptr : comm->second;
100   }else
101     return nullptr;
102 }
103
104 }
105 }