Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
SMPI : add leak detection.
[simgrid.git] / src / smpi / include / smpi_f2c.hpp
1 /* Handle Fortran - C conversion for MPI Types*/
2
3 /* Copyright (c) 2010-2021. The SimGrid Team.
4  * All rights reserved.                                                     */
5
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. */
8
9 #ifndef SMPI_F2C_HPP_INCLUDED
10 #define SMPI_F2C_HPP_INCLUDED
11
12 #include <unordered_map>
13
14 namespace simgrid{
15 namespace smpi{
16
17 class F2C {
18 private:
19   // We use a single lookup table for every type.
20   // Beware of collisions if id in mpif.h is not unique
21   static std::unordered_map<unsigned int, F2C*>* f2c_lookup_;
22   static int f2c_id_;
23   static std::unordered_map<unsigned int, F2C*>::size_type num_default_handles_;
24   int my_f2c_id_ = -1;
25
26 protected:
27   static void set_f2c_lookup(std::unordered_map<unsigned int, F2C*>* map) { f2c_lookup_ = map; }
28   static int f2c_id() { return f2c_id_; }
29   static void f2c_id_increment() { f2c_id_++; }
30
31 public:
32   static void delete_lookup() { delete f2c_lookup_; f2c_lookup_ = nullptr ;}
33   static std::unordered_map<unsigned int, F2C*>* lookup() { return f2c_lookup_; }
34   F2C();
35   virtual ~F2C() = default;
36
37   // Override these to handle specific values.
38   virtual int add_f();
39   static void free_f(int id) { f2c_lookup_->erase(id); }
40   virtual int c2f();
41   static void print_f2c_lookup();
42   // This method should be overridden in all subclasses to avoid casting the result when calling it.
43   // For the default one, the MPI_*_NULL returned is assumed to be NULL.
44   static F2C* f2c(int id);
45   static void finish_initialization() { num_default_handles_ = f2c_lookup_->size(); }
46   static std::unordered_map<unsigned int, F2C*>::size_type get_num_default_handles() { return num_default_handles_;}
47 };
48
49 }
50 }
51
52 #endif