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