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

Last change on this file since 1287 was 1287, checked in by yushan, 7 years ago

EP updated

File size: 3.9 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
42        if(comm->ep_barrier != NULL)
43        {
44          comm->ep_barrier->~OMPbarrier();
45          Debug("ep_barrier freed\n");
46        }
47
48
49        if( ! comm->rank_map->empty() )
50        {
51          comm->rank_map->clear();
52          Debug("rank_map emptied\n");
53        }
54
55        for(int i=0; i<num_ep; i++)
56        {
57          comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->message_queue->clear();
58          Debug("message queue freed\n");
59         
60
61          if(comm->ep_comm_ptr->comm_list[i].ep_comm_ptr != NULL)
62          {
63            delete comm->ep_comm_ptr->comm_list[i].ep_comm_ptr;
64            Debug("ep_comm_ptr freed\n");
65          }
66        }
67
68        if(  comm->mpi_comm != static_cast< ::MPI_Comm>(MPI_COMM_NULL.mpi_comm) 
69          && comm->mpi_comm != static_cast< ::MPI_Comm>(MPI_COMM_WORLD.mpi_comm))
70        {
71          ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm>(comm->mpi_comm);
72          ::MPI_Comm_free(&mpi_comm);
73          Debug("mpi_comm freed\n");
74        }
75
76       if(comm != NULL) {delete[] comm->ep_comm_ptr->comm_list; Debug("comm freed\n");}
77
78      }
79      return 0;
80    }
81
82
83
84  }
85
86  int MPI_Comm_free_intercomm(MPI_Comm *comm)
87  {
88    int ep_rank_loc, num_ep;
89
90    ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
91    num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
92
93    //MPI_Barrier(*comm);
94
95    if(ep_rank_loc == 0)
96    {
97      Debug("comm is EP, mpi_comm_ptr != NULL\n");
98
99
100      if(comm->ep_barrier != NULL)
101      {
102        comm->ep_barrier->~OMPbarrier();
103        Debug("ep_barrier freed\n");
104      }
105
106
107      if( ! comm->rank_map->empty() )
108      {
109        comm->rank_map->clear();
110        Debug("rank_map emptied\n");
111      }
112
113      for(int i=0; i<num_ep; i++)
114      {
115        comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->message_queue->clear();
116        Debug("message queue freed\n");
117
118        #pragma omp critical (memory_free)
119        if(comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm != NULL)
120        {
121          comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_rank_map->clear();
122          comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->remote_rank_map->clear();
123          comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_rank_map->clear();
124          Debug("intercomm local/remote/intercomm_rank_map emptied\n");
125        } 
126
127        if(comm->ep_comm_ptr->comm_list[i].ep_comm_ptr != NULL)
128        {
129          delete comm->ep_comm_ptr->comm_list[i].ep_comm_ptr;
130          Debug("ep_comm_ptr freed\n");
131        }
132      }
133
134      if(comm->mpi_comm != static_cast< ::MPI_Comm>(MPI_COMM_NULL.mpi_comm))
135      {
136        ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm>(comm->mpi_comm);
137        ::MPI_Comm_free(&mpi_comm);
138        Debug("mpi_comm freed\n");
139      }
140
141      // if(comm->ep_comm_ptr->intercomm->mpi_inter_comm != MPI_COMM_NULL_STD)
142      // {
143         // ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm>(comm->ep_comm_ptr->comm_list->ep_comm_ptr->intercomm->mpi_inter_comm);
144         // ::MPI_Comm_free(&mpi_comm);
145      //   Debug("mpi_intercomm freed\n");
146      // }
147
148     if(comm != NULL) {delete[] comm->ep_comm_ptr->comm_list; Debug("comm freed\n");}
149
150    }
151   
152    return 0;
153  }
154
155
156
157}
158
159
Note: See TracBrowser for help on using the repository browser.