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

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

save dev

File size: 5.7 KB
Line 
1#include "ep_lib.hpp"
2#include <mpi.h>
3#include "ep_declaration.hpp"
4#include "ep_mpi.hpp"
5
6namespace ep_lib
7{
8
9  int MPI_Comm_free(MPI_Comm *comm)
10  {
11    if(! (*comm)->is_ep)
12    {
13      return MPI_Comm_free_mpi(comm);
14    }
15
16    else 
17    {
18      if((*comm)->is_intercomm)
19        return MPI_Comm_free_intercomm(comm);
20      else
21        return MPI_Comm_free_intracomm(comm);
22    }
23  }
24
25
26
27  int MPI_Comm_free_mpi(MPI_Comm *comm)
28  {
29    Debug("MPI_Comm_free with MPI\n");
30
31    return ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm));
32   
33  }
34
35  int MPI_Comm_free_intracomm(MPI_Comm *comm)
36  {
37    Debug("MPI_Comm_free with EP_intracomm\n");
38
39    int ep_rank_loc, num_ep;
40
41    ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first;
42    num_ep = (*comm)->ep_comm_ptr->size_rank_info[1].second;
43
44    MPI_Barrier(*comm);
45
46    if(ep_rank_loc == 0)
47    {
48
49#ifdef _showinfo
50      printf("delete (*comm)->my_buffer = %p\n", (*comm)->my_buffer);
51#endif
52      delete (*comm)->my_buffer;
53
54
55     
56#ifdef _showinfo       
57      printf("delete (*comm)->ep_barrier = %p\n", (*comm)->ep_barrier);
58#endif
59      delete (*comm)->ep_barrier;
60     
61
62
63      (*comm)->ep_rank_map->clear();
64#ifdef _showinfo
65      printf("delete (*comm)->ep_rank_map = %p\n", (*comm)->ep_rank_map);
66#endif
67      delete (*comm)->ep_rank_map;
68     
69
70      for(int i=0; i<num_ep; i++)
71      {
72        (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue->clear();
73#ifdef _showinfo
74        printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr->message_queue = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue);
75#endif
76        delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue;
77         
78
79#ifdef _showinfo
80        printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr);
81#endif
82        delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr;
83
84
85#ifdef _showinfo
86        printf("delete (*comm)->ep_comm_ptr->comm_list[%d] = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]);
87#endif
88        delete (*comm)->ep_comm_ptr->comm_list[i];
89      }
90
91#ifdef _showinfo
92      printf("delete (*comm)->mpi_comm = %p\n", (*comm)->mpi_comm);
93#endif
94      ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm));
95     
96#ifdef _showinfo
97      printf("delete (*comm)->ep_comm_ptr->comm_list = %p\n", (*comm)->ep_comm_ptr->comm_list);
98#endif
99      delete[] (*comm)->ep_comm_ptr->comm_list;
100    }
101  }
102
103
104
105
106
107
108
109  int MPI_Comm_free_intercomm(MPI_Comm *comm)
110  {
111    int ep_rank;
112    MPI_Comm_rank(*comm, &ep_rank);
113    int ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first;
114    int num_ep =      (*comm)->ep_comm_ptr->size_rank_info[1].second;
115   
116    int newcomm_ep_rank =(*comm)->ep_comm_ptr->intercomm->size_rank_info[0].first; 
117    int newcomm_ep_rank_loc = (*comm)->ep_comm_ptr->intercomm->size_rank_info[1].first;
118    int newcomm_num_ep = (*comm)->ep_comm_ptr->intercomm->size_rank_info[1].second;
119
120    return 0;
121    MPI_Barrier(*comm);
122
123    if(ep_rank_loc == 0)
124    {
125      (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map->clear();
126#ifdef _showinfo
127      printf("delete (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map = %p\n", (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map);
128#endif
129      delete (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map;
130
131      (*comm)->ep_comm_ptr->intercomm->local_rank_map->clear();
132#ifdef _showinfo
133      printf("delete (*comm)->ep_comm_ptr->intercomm->local_rank_map = %p\n", (*comm)->ep_comm_ptr->intercomm->local_rank_map);
134#endif
135      delete (*comm)->ep_comm_ptr->intercomm->local_rank_map;
136    }
137
138    if(newcomm_ep_rank_loc == 0)
139    {
140
141#ifdef _showinfo
142      printf("delete (*comm)->my_buffer = %p\n", (*comm)->my_buffer);
143#endif
144      delete (*comm)->my_buffer;
145
146
147     
148#ifdef _showinfo       
149      printf("delete (*comm)->ep_barrier = %p\n", (*comm)->ep_barrier);
150#endif
151      delete (*comm)->ep_barrier;
152     
153
154      (*comm)->ep_rank_map->clear();
155#ifdef _showinfo
156      printf("delete (*comm)->ep_rank_map = %p\n", (*comm)->ep_rank_map);
157#endif
158      delete (*comm)->ep_rank_map;
159     
160#ifdef _showinfo
161      printf("delete (*comm)->ep_comm_ptr->intercomm->mpi_inter_comm = %p\n", (*comm)->ep_comm_ptr->intercomm->mpi_inter_comm);
162#endif
163      ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->ep_comm_ptr->intercomm->mpi_inter_comm));
164
165      for(int i=0; i<newcomm_num_ep; i++)
166      {
167        (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue->clear();
168#ifdef _showinfo
169        printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr->message_queue = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue);
170#endif
171        delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue;
172
173#ifdef _showinfo
174        printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr->intercomm = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm);
175#endif
176        delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm;       
177         
178
179#ifdef _showinfo
180        printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr);
181#endif
182        delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr;
183
184
185#ifdef _showinfo
186        printf("delete (*comm)->ep_comm_ptr->comm_list[%d] = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]);
187#endif
188        delete (*comm)->ep_comm_ptr->comm_list[i];
189
190      }
191
192#ifdef _showinfo
193      printf("delete (*comm)->mpi_comm = %p\n", (*comm)->mpi_comm);
194#endif
195      ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm));
196     
197#ifdef _showinfo
198      printf("delete (*comm)->ep_comm_ptr->comm_list = %p\n", (*comm)->ep_comm_ptr->comm_list);
199#endif
200      delete[] (*comm)->ep_comm_ptr->comm_list;
201    }
202  }
203
204
205}
206
207
Note: See TracBrowser for help on using the repository browser.