source: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_free.cpp @ 1295

Last change on this file since 1295 was 1295, checked in by yushan, 6 years ago

EP update all

File size: 4.0 KB
Line 
1#include "ep_lib.hpp"
2#include <mpi.h>
3#include "ep_declaration.hpp"
4
5namespace ep_lib
6{
7
8  int MPI_Comm_free(MPI_Comm *comm)
9  {
10
11    if(! comm->is_ep)
12    {
13      if(comm->mpi_comm != static_cast< ::MPI_Comm>(MPI_COMM_NULL.mpi_comm))
14      {
15        ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm>(comm->mpi_comm);
16
17        ::MPI_Comm_free(&mpi_comm);
18        Debug("comm is MPI, freed\n");
19      }
20      return 0;
21    }
22
23    else if(comm->is_intercomm)
24    {
25      return MPI_Comm_free_intercomm(comm);
26    }
27
28    else
29    {
30      int ep_rank_loc, num_ep;
31
32      ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
33      num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
34
35      MPI_Barrier(*comm);
36
37      if(ep_rank_loc == 0)
38      {
39        Debug("comm is EP, mpi_comm_ptr != NULL\n");
40
41        delete comm->my_buffer;
42
43
44        if(comm->ep_barrier != NULL)
45        {
46          comm->ep_barrier->~OMPbarrier();
47          Debug("ep_barrier freed\n");
48        }
49
50
51        if( ! comm->rank_map->empty() )
52        {
53          comm->rank_map->clear();
54          Debug("rank_map emptied\n");
55        }
56
57        for(int i=0; i<num_ep; i++)
58        {
59          comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->message_queue->clear();
60          Debug("message queue freed\n");
61         
62
63          if(comm->ep_comm_ptr->comm_list[i].ep_comm_ptr != NULL)
64          {
65            delete comm->ep_comm_ptr->comm_list[i].ep_comm_ptr;
66            Debug("ep_comm_ptr freed\n");
67          }
68        }
69
70        if(  comm->mpi_comm != static_cast< ::MPI_Comm>(MPI_COMM_NULL.mpi_comm) 
71          && comm->mpi_comm != static_cast< ::MPI_Comm>(MPI_COMM_WORLD.mpi_comm))
72        {
73          ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm>(comm->mpi_comm);
74          ::MPI_Comm_free(&mpi_comm);
75          Debug("mpi_comm freed\n");
76        }
77
78       if(comm != NULL) {delete[] comm->ep_comm_ptr->comm_list; Debug("comm freed\n");}
79
80      }
81      return 0;
82    }
83
84
85
86  }
87
88  int MPI_Comm_free_intercomm(MPI_Comm *comm)
89  {
90    int ep_rank_loc, num_ep;
91
92    ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
93    num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
94
95    //MPI_Barrier(*comm);
96
97    if(ep_rank_loc == 0)
98    {
99      Debug("comm is EP, mpi_comm_ptr != NULL\n");
100
101
102      if(comm->ep_barrier != NULL)
103      {
104        comm->ep_barrier->~OMPbarrier();
105        Debug("ep_barrier freed\n");
106      }
107
108
109      if( ! comm->rank_map->empty() )
110      {
111        comm->rank_map->clear();
112        Debug("rank_map emptied\n");
113      }
114
115      for(int i=0; i<num_ep; i++)
116      {
117        comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->message_queue->clear();
118        Debug("message queue freed\n");
119
120        #pragma omp critical (memory_free)
121        if(comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm != NULL)
122        {
123          comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_rank_map->clear();
124          comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->remote_rank_map->clear();
125          comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_rank_map->clear();
126          Debug("intercomm local/remote/intercomm_rank_map emptied\n");
127        } 
128
129        if(comm->ep_comm_ptr->comm_list[i].ep_comm_ptr != NULL)
130        {
131          delete comm->ep_comm_ptr->comm_list[i].ep_comm_ptr;
132          Debug("ep_comm_ptr freed\n");
133        }
134      }
135
136      if(comm->mpi_comm != static_cast< ::MPI_Comm>(MPI_COMM_NULL.mpi_comm))
137      {
138        ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm>(comm->mpi_comm);
139        ::MPI_Comm_free(&mpi_comm);
140        Debug("mpi_comm freed\n");
141      }
142
143      // if(comm->ep_comm_ptr->intercomm->mpi_inter_comm != MPI_COMM_NULL_STD)
144      // {
145         // ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm>(comm->ep_comm_ptr->comm_list->ep_comm_ptr->intercomm->mpi_inter_comm);
146         // ::MPI_Comm_free(&mpi_comm);
147      //   Debug("mpi_intercomm freed\n");
148      // }
149
150     if(comm != NULL) {delete[] comm->ep_comm_ptr->comm_list; Debug("comm freed\n");}
151
152    }
153   
154    return 0;
155  }
156
157
158
159}
160
161
Note: See TracBrowser for help on using the repository browser.