source: XIOS3/trunk/src/mpi_garbage_collector.hpp @ 2569

Last change on this file since 2569 was 2569, checked in by jderouillat, 10 months ago

Clean memory associated to EventScheduler? hierarchy and MpiGarbageCollector?

  • Property svn:executable set to *
File size: 889 bytes
Line 
1#ifndef __MPI_GARBAGE_COLLECTOR_HPP__
2#define __MPI_GARBAGE_COLLECTOR_HPP__
3#include "mpi.hpp"
4namespace xios
5{
6  class CMpiGarbageCollector
7  {
8   
9    private:
10
11      struct SType
12      {
13        enum {COMM, WIN} type ;
14        MPI_Comm comm ;
15        MPI_Win win ;
16        std::string str;
17      } ;
18      std::list<SType> stack_ ;
19   
20    public:
21
22      void registerCommunicator(MPI_Comm& comm, std::string str="") { stack_.push_back(SType{SType::COMM, comm, MPI_WIN_NULL, str}) ;}
23      void registerWindow(MPI_Win& win, std::string str="") { stack_.push_back(SType{SType::WIN, MPI_COMM_NULL, win, str}) ;}
24      void release(void)
25      {
26        for( auto& it : stack_) 
27          if (it.type==SType::COMM) MPI_Comm_free(&it.comm);
28          else if (it.type==SType::WIN) MPI_Win_free(&it.win);
29        stack_.clear();
30      }
31  } ;
32
33}
34
35#endif
Note: See TracBrowser for help on using the repository browser.