source: XIOS/dev/branch_openmp/extern/ep_dev/ep_free.cpp @ 1527

Last change on this file since 1527 was 1527, checked in by yushan, 3 years ago

save dev

File size: 2.8 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) return MPI_Comm_free_mpi(comm);
12    else return MPI_Comm_free_endpoint(comm);
13  }
14
15
16
17  int MPI_Comm_free_mpi(MPI_Comm *comm)
18  {
19    Debug("MPI_Comm_free with MPI\n");
20
21    return ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm));
22   
23  }
24
25  int MPI_Comm_free_endpoint(MPI_Comm *comm)
26  {
27    Debug("MPI_Comm_free with EP_intracomm\n");
28
29    int ep_rank_loc, num_ep;
30
31    ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first;
32    int ep_rank = (*comm)->ep_comm_ptr->size_rank_info[0].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
40      if((*comm)->is_intercomm)
41      {
42        for(int i=0; i<num_ep; i++)
43        {
44          (*comm)->ep_comm_ptr->comm_list[i]->inter_rank_map->clear();
45#ifdef _showinfo
46          printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->inter_rank_map = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->inter_rank_map);
47#endif
48          delete (*comm)->ep_comm_ptr->comm_list[i]->inter_rank_map;
49        }
50      }
51
52
53
54#ifdef _showinfo
55      printf("delete (*comm)->my_buffer = %p\n", (*comm)->my_buffer);
56#endif
57      delete (*comm)->my_buffer;
58
59
60     
61#ifdef _showinfo       
62      printf("delete (*comm)->ep_barrier = %p\n", (*comm)->ep_barrier);
63#endif
64      delete (*comm)->ep_barrier;
65     
66
67
68      (*comm)->ep_rank_map->clear();
69#ifdef _showinfo
70      printf("delete (*comm)->ep_rank_map = %p\n", (*comm)->ep_rank_map);
71#endif
72      delete (*comm)->ep_rank_map;
73     
74
75      for(int i=0; i<num_ep; i++)
76      {
77        (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue->clear();
78#ifdef _showinfo
79        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);
80#endif
81        delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue;
82         
83
84#ifdef _showinfo
85        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);
86#endif
87        delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr;
88
89
90#ifdef _showinfo
91        printf("delete (*comm)->ep_comm_ptr->comm_list[%d] = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]);
92#endif
93        delete (*comm)->ep_comm_ptr->comm_list[i];
94      }
95
96#ifdef _showinfo
97      printf("delete (*comm)->mpi_comm = %p\n", (*comm)->mpi_comm);
98#endif
99      ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm));
100     
101#ifdef _showinfo
102      printf("delete (*comm)->ep_comm_ptr->comm_list = %p\n", (*comm)->ep_comm_ptr->comm_list);
103#endif
104      delete[] (*comm)->ep_comm_ptr->comm_list;
105    }
106  }
107
108
109
110}
111
112
Note: See TracBrowser for help on using the repository browser.