source: XIOS/trunk/extern/src_ep/ep_dup.cpp @ 1034

Last change on this file since 1034 was 1034, checked in by yushan, 7 years ago

adding src_ep into extern folder

File size: 2.0 KB
Line 
1#include "ep_lib.hpp"
2#include <mpi.h>
3#include "ep_declaration.hpp"
4
5namespace ep_lib
6{
7
8
9
10  int MPI_Comm_dup_dev(MPI_Comm comm, MPI_Comm *newcomm)
11  {
12    if(!comm.is_ep)
13    {
14      Debug("Comm_dup MPI\n");
15      newcomm = new MPI_Comm;
16      newcomm->is_ep = comm.is_ep;
17
18      ::MPI_Comm input = static_cast< ::MPI_Comm>(comm.mpi_comm);
19      ::MPI_Comm output;
20
21     
22      ::MPI_Comm_dup(input, &output);
23
24      newcomm->mpi_comm = output;
25
26      return 0;
27    }
28
29    if(!comm.mpi_comm) return 0;
30
31
32    int my_rank = comm.ep_comm_ptr->size_rank_info[1].first;
33    int num_ep  = comm.ep_comm_ptr->size_rank_info[1].second;
34
35
36    if(0 == my_rank)
37    {
38      MPI_Info info;
39      ::MPI_Comm mpi_dup;
40
41      ::MPI_Comm in_comm = static_cast< ::MPI_Comm>(comm.mpi_comm);
42
43      ::MPI_Comm_dup(in_comm, &mpi_dup);
44
45      MPI_Comm_create_endpoints(mpi_dup, num_ep, info, newcomm);
46      comm.ep_comm_ptr->comm_list->mem_bridge = newcomm;
47    }
48
49    MPI_Barrier_local(comm);
50
51    newcomm = &(comm.ep_comm_ptr->comm_list->mem_bridge[my_rank]);
52
53    return MPI_SUCCESS;
54  }
55
56
57
58  int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm)
59  {
60    if(!comm.is_ep)
61    {
62      Debug("Comm_dup MPI\n");
63      newcomm = new MPI_Comm;
64      newcomm->is_ep = comm.is_ep;
65
66      ::MPI_Comm input = static_cast< ::MPI_Comm>(comm.mpi_comm);
67      ::MPI_Comm output;
68
69     
70      ::MPI_Comm_dup(input, &output);
71
72      newcomm->mpi_comm = output;
73
74      return 0;
75    }
76
77    if(!comm.mpi_comm) return 0;
78
79
80    int my_rank = comm.ep_comm_ptr->size_rank_info[1].first;
81    int num_ep  = comm.ep_comm_ptr->size_rank_info[1].second;
82
83
84    if(0 == my_rank)
85    {
86      MPI_Info info;
87      MPI_Comm *out_comm;
88      ::MPI_Comm mpi_dup;
89
90      ::MPI_Comm in_comm = static_cast< ::MPI_Comm>(comm.mpi_comm);
91
92      ::MPI_Comm_dup(in_comm, &mpi_dup);
93
94      MPI_Comm_create_endpoints(mpi_dup, num_ep, info, out_comm);
95      comm.ep_comm_ptr->comm_list->mem_bridge = out_comm;
96    }
97
98    MPI_Barrier(comm);
99
100    *newcomm = (comm.ep_comm_ptr->comm_list->mem_bridge[my_rank]);
101
102    return MPI_SUCCESS;
103  }
104
105
106
107
108}
109
110
Note: See TracBrowser for help on using the repository browser.