Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simple MPI_Win_lock and MPI_Win_unlock implementation.
[simgrid.git] / src / smpi / smpi_f2c.cpp
1 /* Copyright (c) 2007-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "private.h"
8 #include <vector>
9
10
11 namespace simgrid{
12 namespace smpi{
13
14 xbt_dict_t F2C::f2c_lookup_=nullptr;
15 int F2C::f2c_id_=0;
16
17 xbt_dict_t F2C::f2c_lookup(){
18   return f2c_lookup_;
19 }
20
21 void F2C::set_f2c_lookup(xbt_dict_t dict){
22   f2c_lookup_=dict;
23 }
24
25 void F2C::f2c_id_increment(){
26   f2c_id_++;
27 };
28
29 int F2C::f2c_id(){
30   return f2c_id_;
31 };
32
33 char* F2C::get_key(char* key, int id) {
34   snprintf(key, KEY_SIZE, "%x",id);
35   return key;
36 }
37
38 char* F2C::get_key_id(char* key, int id) {
39   snprintf(key, KEY_SIZE, "%x_%d",id, smpi_process()->index());
40   return key;
41 }
42
43 void F2C::delete_lookup(){
44   xbt_dict_free(&f2c_lookup_);
45 }
46
47 xbt_dict_t F2C::lookup(){
48   return f2c_lookup_;
49 }
50
51 void F2C::free_f(int id){
52   char key[KEY_SIZE];
53   xbt_dict_remove(f2c_lookup_, get_key(key, id));
54 }
55
56 int F2C::add_f(){
57   if(f2c_lookup_==nullptr){
58     f2c_lookup_=xbt_dict_new_homogeneous(nullptr);
59   }
60   char key[KEY_SIZE];
61   xbt_dict_set(f2c_lookup_, get_key(key, f2c_id_), this, nullptr);
62   f2c_id_increment();
63   return f2c_id_-1;
64 }
65
66 int F2C::c2f(){
67   if(f2c_lookup_==nullptr){
68     f2c_lookup_=xbt_dict_new_homogeneous(nullptr);
69   }
70
71   char* existing_key = xbt_dict_get_key(f2c_lookup_, this);
72   if(existing_key!=nullptr){
73     return atoi(existing_key);}
74   else{
75     return this->add_f();}
76 }
77
78 F2C* F2C::f2c(int id){
79   if(f2c_lookup_==nullptr){
80     f2c_lookup_=xbt_dict_new_homogeneous(nullptr);
81   }
82   char key[KEY_SIZE];
83   if(id >= 0){
84     return static_cast<F2C*>(xbt_dict_get_or_null(f2c_lookup_, get_key(key, id)));
85   }else
86     return NULL;
87 }
88
89 }
90 }