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

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

save dev. TO DO : test with xios

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    MPI_Barrier(*comm);
121
122    if(ep_rank_loc == 0)
123    {
124      (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map->clear();
125#ifdef _showinfo
126      printf("delete (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map = %p\n", (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map);
127#endif
128      delete (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map;
129
130      (*comm)->ep_comm_ptr->intercomm->local_rank_map->clear();
131#ifdef _showinfo
132      printf("delete (*comm)->ep_comm_ptr->intercomm->local_rank_map = %p\n", (*comm)->ep_comm_ptr->intercomm->local_rank_map);
133#endif
134      delete (*comm)->ep_comm_ptr->intercomm->local_rank_map;
135    }
136
137    if(newcomm_ep_rank_loc == 0)
138    {
139
140#ifdef _showinfo
141      printf("delete (*comm)->my_buffer = %p\n", (*comm)->my_buffer);
142#endif
143      delete (*comm)->my_buffer;
144
145
146     
147#ifdef _showinfo       
148      printf("delete (*comm)->ep_barrier = %p\n", (*comm)->ep_barrier);
149#endif
150      delete (*comm)->ep_barrier;
151     
152
153      (*comm)->ep_rank_map->clear();
154#ifdef _showinfo
155      printf("delete (*comm)->ep_rank_map = %p\n", (*comm)->ep_rank_map);
156#endif
157      delete (*comm)->ep_rank_map;
158     
159#ifdef _showinfo
160      printf("delete (*comm)->ep_comm_ptr->intercomm->mpi_inter_comm = %p\n", (*comm)->ep_comm_ptr->intercomm->mpi_inter_comm);
161#endif
162      ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->ep_comm_ptr->intercomm->mpi_inter_comm));
163
164      for(int i=0; i<newcomm_num_ep; i++)
165      {
166        (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue->clear();
167#ifdef _showinfo
168        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);
169#endif
170        delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue;
171
172#ifdef _showinfo
173        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);
174#endif
175        delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm;       
176         
177
178#ifdef _showinfo
179        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);
180#endif
181        delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr;
182
183
184#ifdef _showinfo
185        printf("delete (*comm)->ep_comm_ptr->comm_list[%d] = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]);
186#endif
187        delete (*comm)->ep_comm_ptr->comm_list[i];
188
189      }
190
191#ifdef _showinfo
192      printf("delete (*comm)->mpi_comm = %p\n", (*comm)->mpi_comm);
193#endif
194      ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm));
195     
196#ifdef _showinfo
197      printf("delete (*comm)->ep_comm_ptr->comm_list = %p\n", (*comm)->ep_comm_ptr->comm_list);
198#endif
199      delete[] (*comm)->ep_comm_ptr->comm_list;
200    }
201  }
202
203
204}
205
206
Note: See TracBrowser for help on using the repository browser.