1 | #include "ep_lib.hpp" |
---|
2 | #include "ep_lib_fortran.hpp" |
---|
3 | #include <mpi.h> |
---|
4 | #include <map> |
---|
5 | #include <utility> |
---|
6 | #include "ep_declaration.hpp" |
---|
7 | |
---|
8 | |
---|
9 | namespace ep_lib |
---|
10 | { |
---|
11 | |
---|
12 | int EP_Comm_c2f(MPI_Comm comm) |
---|
13 | { |
---|
14 | Debug("MPI_Comm_c2f"); |
---|
15 | int fint; |
---|
16 | #ifdef _intelmpi |
---|
17 | fint = (::MPI_Fint)(comm.mpi_comm); |
---|
18 | #elif _openmpi |
---|
19 | fint = ::MPI_Comm_c2f(static_cast< ::MPI_Comm>(comm.mpi_comm)); |
---|
20 | #endif |
---|
21 | |
---|
22 | std::map<std::pair<int, int>, MPI_Comm > ::iterator it; |
---|
23 | |
---|
24 | it = fc_comm_map.find(std::make_pair(fint, omp_get_thread_num())); |
---|
25 | if(it == fc_comm_map.end()) |
---|
26 | { |
---|
27 | fc_comm_map.insert(std::make_pair( std::make_pair( fint, omp_get_thread_num()) , comm)); |
---|
28 | printf("EP_Comm_c2f : MAP insert: %d, %d, %p\n", fint, omp_get_thread_num(), comm.ep_comm_ptr); |
---|
29 | } |
---|
30 | |
---|
31 | |
---|
32 | return fint; |
---|
33 | |
---|
34 | } |
---|
35 | |
---|
36 | MPI_Comm EP_Comm_f2c(int comm) |
---|
37 | { |
---|
38 | Debug("MPI_Comm_f2c"); |
---|
39 | |
---|
40 | |
---|
41 | std::map<std::pair<int, int>, MPI_Comm > ::iterator it; |
---|
42 | |
---|
43 | it = fc_comm_map.find(std::make_pair(comm, omp_get_thread_num())); |
---|
44 | if(it != fc_comm_map.end()) |
---|
45 | { |
---|
46 | MPI_Comm comm_ptr; |
---|
47 | comm_ptr = it->second; |
---|
48 | printf("EP_Comm_f2c : MAP find: %d, %d, %p\n", it->first.first, it->first.second, comm_ptr.ep_comm_ptr); |
---|
49 | return comm_ptr; |
---|
50 | } |
---|
51 | else |
---|
52 | { |
---|
53 | |
---|
54 | #ifdef _openmpi |
---|
55 | ::MPI_Comm base_comm = ::MPI_Comm_f2c(comm); |
---|
56 | #elif _intelmpi |
---|
57 | ::MPI_Comm base_comm = (::MPI_Comm)(comm); |
---|
58 | #endif |
---|
59 | |
---|
60 | if(base_comm != MPI_COMM_NULL_STD) |
---|
61 | { |
---|
62 | if(omp_get_thread_num() == 0) |
---|
63 | { |
---|
64 | int num_ep = omp_get_num_threads(); |
---|
65 | MPI_Comm *new_comm; |
---|
66 | MPI_Info info; |
---|
67 | MPI_Comm_create_endpoints(base_comm, num_ep, info, new_comm); |
---|
68 | passage = new_comm; |
---|
69 | } |
---|
70 | #pragma omp barrier |
---|
71 | |
---|
72 | MPI_Comm return_comm = passage[omp_get_thread_num()]; |
---|
73 | return return_comm; |
---|
74 | |
---|
75 | } |
---|
76 | return MPI_COMM_NULL; |
---|
77 | |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | // #ifdef _intelmpi |
---|
82 | |
---|
83 | // MPI_Fint MPI_Comm_c2f(MPI_Comm comm) |
---|
84 | // { |
---|
85 | // Debug("MPI_Comm_c2f"); |
---|
86 | // int fint; |
---|
87 | // fint = (::MPI_Fint)(comm.mpi_comm); |
---|
88 | |
---|
89 | // std::map<std::pair<int, int>, MPI_Comm > ::iterator it; |
---|
90 | |
---|
91 | // it = fc_comm_map.find(std::make_pair(fint, omp_get_thread_num())); |
---|
92 | // if(it == fc_comm_map.end()) |
---|
93 | // { |
---|
94 | // fc_comm_map.insert(std::make_pair( std::make_pair( fint, omp_get_thread_num()) , comm)); |
---|
95 | // printf("MAP insert: %d, %d, %p\n", fint, omp_get_thread_num(), &comm); |
---|
96 | // } |
---|
97 | |
---|
98 | // MPI_Fint Fint; |
---|
99 | // Fint.mpi_fint = fint; |
---|
100 | // return Fint; |
---|
101 | |
---|
102 | // } |
---|
103 | |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | // MPI_Comm MPI_Comm_f2c(MPI_Fint comm) |
---|
108 | // { |
---|
109 | // Debug("MPI_Comm_f2c"); |
---|
110 | |
---|
111 | |
---|
112 | // std::map<std::pair<int, int>, MPI_Comm > ::iterator it; |
---|
113 | |
---|
114 | // it = fc_comm_map.find(std::make_pair(comm.mpi_fint, omp_get_thread_num())); |
---|
115 | // if(it != fc_comm_map.end()) |
---|
116 | // { |
---|
117 | // MPI_Comm comm_ptr; |
---|
118 | // comm_ptr = it->second; |
---|
119 | // printf("MAP find: %d, %d, %p\n", it->first.first, it->first.second, &comm_ptr); |
---|
120 | // return comm_ptr; |
---|
121 | // } |
---|
122 | // else |
---|
123 | // { |
---|
124 | // MPI_Comm return_comm; |
---|
125 | // return_comm.mpi_comm = (::MPI_Comm)(comm.mpi_fint); |
---|
126 | // return return_comm; |
---|
127 | // } |
---|
128 | // } |
---|
129 | |
---|
130 | |
---|
131 | |
---|
132 | // #elif _openmpi |
---|
133 | |
---|
134 | // int MPI_Comm_c2f(MPI_Comm comm) |
---|
135 | // { |
---|
136 | // Debug("MPI_Comm_c2f"); |
---|
137 | // int fint; |
---|
138 | // fint = ::MPI_Comm_c2f(static_cast< ::MPI_Comm>(comm.mpi_comm)); |
---|
139 | |
---|
140 | // std::map<std::pair<int, int>, MPI_Comm > ::iterator it; |
---|
141 | |
---|
142 | // it = fc_comm_map.find(std::make_pair(fint, omp_get_thread_num())); |
---|
143 | // if(it == fc_comm_map.end()) |
---|
144 | // { |
---|
145 | // fc_comm_map.insert(std::make_pair( std::make_pair( fint, omp_get_thread_num()) , comm)); |
---|
146 | // printf("MAP insert: %d, %d, %p\n", fint, omp_get_thread_num(), &comm); |
---|
147 | // } |
---|
148 | |
---|
149 | // return fint; |
---|
150 | |
---|
151 | // } |
---|
152 | |
---|
153 | // ep_lib::MPI_Comm MPI_Comm_f2c(MPI_Fint comm) |
---|
154 | // { |
---|
155 | // Debug("MPI_Comm_f2c"); |
---|
156 | |
---|
157 | |
---|
158 | // std::map<std::pair<int, int>, MPI_Comm > ::iterator it; |
---|
159 | |
---|
160 | // it = fc_comm_map.find(std::make_pair(comm, omp_get_thread_num())); |
---|
161 | // if(it != fc_comm_map.end()) |
---|
162 | // { |
---|
163 | // MPI_Comm comm_ptr; |
---|
164 | // comm_ptr = it->second; |
---|
165 | // printf("MAP find: %d, %d, %p\n", it->first.first, it->first.second, &comm_ptr); |
---|
166 | // return comm_ptr; |
---|
167 | // } |
---|
168 | // else |
---|
169 | // { |
---|
170 | // MPI_Comm return_comm; |
---|
171 | // return_comm.mpi_comm = (::MPI_Comm)(comm); |
---|
172 | // return return_comm; |
---|
173 | // } |
---|
174 | // } |
---|
175 | // #endif |
---|
176 | |
---|
177 | } |
---|
178 | |
---|
179 | |
---|