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

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

tests in XIOS OK (client, complete, remap, toy)

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