1 /* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */
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. */
6 #include "src/smpi/private.h"
7 #include "src/smpi/smpi_f2c.hpp"
8 #include "src/smpi/smpi_process.hpp"
15 xbt_dict_t F2C::f2c_lookup_=nullptr;
18 xbt_dict_t F2C::f2c_lookup(){
22 void F2C::set_f2c_lookup(xbt_dict_t dict){
26 void F2C::f2c_id_increment(){
34 char* F2C::get_key(char* key, int id) {
35 std::snprintf(key, KEY_SIZE, "%x",id);
39 char* F2C::get_key_id(char* key, int id) {
40 std::snprintf(key, KEY_SIZE, "%x_%d",id, smpi_process()->index());
44 void F2C::delete_lookup(){
45 xbt_dict_free(&f2c_lookup_);
48 xbt_dict_t F2C::lookup(){
52 void F2C::free_f(int id){
54 xbt_dict_remove(f2c_lookup_, get_key(key, id));
58 if(f2c_lookup_==nullptr){
59 f2c_lookup_=xbt_dict_new_homogeneous(nullptr);
62 xbt_dict_set(f2c_lookup_, get_key(key, f2c_id_), this, nullptr);
68 if(f2c_lookup_==nullptr){
69 f2c_lookup_=xbt_dict_new_homogeneous(nullptr);
72 char* existing_key = xbt_dict_get_key(f2c_lookup_, this);
73 if(existing_key!=nullptr){
74 return atoi(existing_key);}
76 return this->add_f();}
79 F2C* F2C::f2c(int id){
80 if(f2c_lookup_==nullptr){
81 f2c_lookup_=xbt_dict_new_homogeneous(nullptr);
85 return static_cast<F2C*>(xbt_dict_get_or_null(f2c_lookup_, get_key(key, id)));