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

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

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

File size: 2.7 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");
20    return ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm));
21  }
[1381]22
[1527]23  int MPI_Comm_free_endpoint(MPI_Comm *comm)
[1517]24  {
25    Debug("MPI_Comm_free with EP_intracomm\n");
[1381]26
[1517]27    int ep_rank_loc, num_ep;
[1381]28
[1517]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;
[1381]31
[1538]32    MPI_Barrier_local(*comm);
[1381]33
[1517]34    if(ep_rank_loc == 0)
35    {
[1381]36
[1527]37      if((*comm)->is_intercomm)
[1517]38      {
[1527]39        for(int i=0; i<num_ep; i++)
[1525]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
[1517]51#ifdef _showinfo
52      printf("delete (*comm)->my_buffer = %p\n", (*comm)->my_buffer);
53#endif
54      delete (*comm)->my_buffer;
[1381]55
56
[1517]57     
58#ifdef _showinfo       
59      printf("delete (*comm)->ep_barrier = %p\n", (*comm)->ep_barrier);
60#endif
61      delete (*comm)->ep_barrier;
62     
63
[1527]64
[1517]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
[1527]72      for(int i=0; i<num_ep; i++)
[1381]73      {
[1500]74        (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue->clear();
[1517]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         
[1381]80
[1517]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;
[1381]85
86
[1517]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];
[1381]91      }
92
[1517]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;
[1381]102    }
103  }
104
105
[1527]106
[1381]107}
108
109
Note: See TracBrowser for help on using the repository browser.