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

Last change on this file since 2628 was 2593, checked in by jderouillat, 8 months ago

Rename the MemTrack? namespace associated to CppTrace? (conflict with the --memtrack option), waiting for its full integration

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