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, 6 years ago

save dev

File size: 2.8 KB
RevLine 
[1381]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  {
[1527]11    if(! (*comm)->is_ep) return MPI_Comm_free_mpi(comm);
12    else return MPI_Comm_free_endpoint(comm);
[1517]13  }
[1381]14
15
16
[1517]17  int MPI_Comm_free_mpi(MPI_Comm *comm)
18  {
19    Debug("MPI_Comm_free with MPI\n");
[1381]20
[1517]21    return ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm));
22   
23  }
[1381]24
[1527]25  int MPI_Comm_free_endpoint(MPI_Comm *comm)
[1517]26  {
27    Debug("MPI_Comm_free with EP_intracomm\n");
[1381]28
[1517]29    int ep_rank_loc, num_ep;
[1381]30
[1517]31    ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first;
[1527]32    int ep_rank = (*comm)->ep_comm_ptr->size_rank_info[0].first;
[1517]33    num_ep = (*comm)->ep_comm_ptr->size_rank_info[1].second;
[1381]34
[1517]35    MPI_Barrier(*comm);
[1381]36
[1517]37    if(ep_rank_loc == 0)
38    {
[1381]39
[1527]40      if((*comm)->is_intercomm)
[1517]41      {
[1527]42        for(int i=0; i<num_ep; i++)
[1525]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
[1517]54#ifdef _showinfo
55      printf("delete (*comm)->my_buffer = %p\n", (*comm)->my_buffer);
56#endif
57      delete (*comm)->my_buffer;
[1381]58
59
[1517]60     
61#ifdef _showinfo       
62      printf("delete (*comm)->ep_barrier = %p\n", (*comm)->ep_barrier);
63#endif
64      delete (*comm)->ep_barrier;
65     
66
[1527]67
[1517]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
[1527]75      for(int i=0; i<num_ep; i++)
[1381]76      {
[1500]77        (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue->clear();
[1517]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         
[1381]83
[1517]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;
[1381]88
89
[1517]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];
[1381]94      }
95
[1517]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;
[1381]105    }
106  }
107
108
[1527]109
[1381]110}
111
112
Note: See TracBrowser for help on using the repository browser.