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
RevLine 
[1134]1#include "ep_lib.hpp"
2#include <mpi.h>
3#include "ep_declaration.hpp"
[1354]4#include "ep_mpi.hpp"
[1134]5
6namespace ep_lib
7{
8
9  int MPI_Comm_free(MPI_Comm *comm)
10  {
[1520]11    if(! (*comm)->is_ep)
[1134]12    {
[1520]13      return MPI_Comm_free_mpi(comm);
[1134]14    }
15
[1520]16    else 
[1134]17    {
[1520]18      if((*comm)->is_intercomm)
19        return MPI_Comm_free_intercomm(comm);
20      else
21        return MPI_Comm_free_intracomm(comm);
[1134]22    }
[1520]23  }
[1134]24
25
26
[1520]27  int MPI_Comm_free_mpi(MPI_Comm *comm)
28  {
29    Debug("MPI_Comm_free with MPI\n");
[1134]30
[1520]31    return ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm));
32   
33  }
[1134]34
[1520]35  int MPI_Comm_free_intracomm(MPI_Comm *comm)
36  {
37    Debug("MPI_Comm_free with EP_intracomm\n");
[1134]38
[1520]39    int ep_rank_loc, num_ep;
[1295]40
[1520]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;
[1134]43
[1520]44    MPI_Barrier(*comm);
[1134]45
[1520]46    if(ep_rank_loc == 0)
47    {
[1134]48
[1520]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;
[1134]77         
78
[1520]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;
[1134]83
84
[1520]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];
[1134]89      }
[1356]90
[1520]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;
[1134]100    }
[1520]101  }
[1134]102
103
104
105
[1520]106
107
108
[1134]109  int MPI_Comm_free_intercomm(MPI_Comm *comm)
110  {
[1520]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;
[1134]119
[1533]120    return 0;
[1520]121    MPI_Barrier(*comm);
[1134]122
123    if(ep_rank_loc == 0)
124    {
[1520]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;
[1134]130
[1520]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    }
[1134]137
[1520]138    if(newcomm_ep_rank_loc == 0)
139    {
[1134]140
[1520]141#ifdef _showinfo
142      printf("delete (*comm)->my_buffer = %p\n", (*comm)->my_buffer);
143#endif
144      delete (*comm)->my_buffer;
[1134]145
146
[1520]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++)
[1134]166      {
[1520]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;
[1134]172
[1520]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         
[1134]178
[1520]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;
[1134]183
184
[1520]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
[1356]190      }
[1134]191
[1520]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;
[1134]201    }
202  }
203
204
205}
206
207
Note: See TracBrowser for help on using the repository browser.