1 /* Handle Fortran - C conversion for MPI Types*/
3 /* Copyright (c) 2010-2023. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #ifndef SMPI_F2C_HPP_INCLUDED
10 #define SMPI_F2C_HPP_INCLUDED
13 #include <unordered_map>
16 namespace simgrid::smpi {
20 using f2c_lookup_type = std::unordered_map<unsigned int, F2C*>;
22 // We use a single lookup table for every type.
23 // Beware of collisions if id in mpif.h is not unique
24 static std::unique_ptr<f2c_lookup_type> f2c_lookup_;
26 static f2c_lookup_type::size_type num_default_handles_;
28 bool deleted_ = false;
29 std::string call_location_;
32 static void allocate_lookup()
35 f2c_lookup_ = std::make_unique<f2c_lookup_type>();
37 int f2c_id() const { return my_f2c_id_; }
38 static int global_f2c_id() { return f2c_id_; }
39 static void f2c_id_increment() { f2c_id_++; }
42 void mark_as_deleted() { deleted_ = true; };
43 bool deleted() const { return deleted_; }
44 static f2c_lookup_type* lookup() { return f2c_lookup_.get(); }
46 virtual ~F2C() = default;
47 virtual std::string name() const = 0;
50 static void free_f(int id) { if(id!=-1) f2c_lookup_->erase(id); }
53 // This method should be overridden in all subclasses to avoid casting the result when calling it.
54 // For the default one, the MPI_*_NULL returned is assumed to be NULL.
55 static F2C* f2c(int id);
56 static void finish_initialization() { num_default_handles_ = f2c_lookup_->size(); }
57 static f2c_lookup_type::size_type get_num_default_handles() { return num_default_handles_; }
58 const std::string& call_location() const { return call_location_; }
61 } // namespace simgrid::smpi