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

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

save dev

File size: 1.6 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 
10  int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm)
11  {
12   
13    if(!comm->is_ep)
14    {
15      Debug("MPI_Comm_dup with MPI\n");
16      return MPI_Comm_dup_mpi(comm, newcomm); 
17    }
18
19    return MPI_Comm_dup_endpoint(comm, newcomm); 
20   
21  }
22
23
24 
25  int MPI_Comm_dup_endpoint(MPI_Comm comm, MPI_Comm *newcomm)
26  {
27    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
28    int num_ep      = comm->ep_comm_ptr->size_rank_info[1].second;
29
30
31    if(0 == ep_rank_loc)
32    {
33      MPI_Info info;
34      MPI_Comm *out_comm;
35
36      MPI_Comm_create_endpoints(comm->mpi_comm, num_ep, info, out_comm);
37      comm->ep_comm_ptr->comm_list[0]->mem_bridge = out_comm;
38    }
39
40    MPI_Barrier_local(comm);
41
42    *newcomm = (comm->ep_comm_ptr->comm_list[0]->mem_bridge[ep_rank_loc]);
43
44    if(comm->is_intercomm)
45    {
46      (*newcomm)->is_intercomm = true;
47      (*newcomm)->ep_comm_ptr->size_rank_info[0] = comm->ep_comm_ptr->size_rank_info[0];
48      (*newcomm)->inter_rank_map = new INTER_RANK_MAP;
49
50      for(INTER_RANK_MAP::iterator it = comm->inter_rank_map->begin(); it !=comm->inter_rank_map->end(); it++)
51      {
52        (*newcomm)->inter_rank_map->insert(std::make_pair(it->first, it->second));
53      }
54
55    }
56   
57  }
58
59  int MPI_Comm_dup_mpi(MPI_Comm comm, MPI_Comm *newcomm)
60  {
61    newcomm = new MPI_Comm;
62    (*newcomm)->is_ep = false;
63
64    ::MPI_Comm *output = new ::MPI_Comm;
65     
66    ::MPI_Comm_dup(to_mpi_comm(comm->mpi_comm), output);
67
68    (*newcomm)->mpi_comm = output;
69  }
70
71
72
73}
74
75
Note: See TracBrowser for help on using the repository browser.