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 | #ifdef _openmpi |
---|
9 | //#undef MPI_Fint |
---|
10 | #endif |
---|
11 | |
---|
12 | namespace ep_lib |
---|
13 | { |
---|
14 | |
---|
15 | int EP_Comm_c2f(MPI_Comm comm) |
---|
16 | { |
---|
17 | Debug("MPI_Comm_c2f"); |
---|
18 | int fint; |
---|
19 | #ifdef _intelmpi |
---|
20 | fint = (::MPI_Fint)(comm.mpi_comm); |
---|
21 | #elif _openmpi |
---|
22 | fint = ::MPI_Comm_c2f(static_cast< ::MPI_Comm>(comm.mpi_comm)); |
---|
23 | #endif |
---|
24 | |
---|
25 | std::map<std::pair<int, int>, MPI_Comm > ::iterator it; |
---|
26 | |
---|
27 | #pragma omp critical (fc_comm_map) |
---|
28 | { |
---|
29 | it = fc_comm_map.find(std::make_pair(fint, omp_get_thread_num())); |
---|
30 | if(it == fc_comm_map.end()) |
---|
31 | { |
---|
32 | fc_comm_map.insert(std::make_pair( std::make_pair( fint, omp_get_thread_num()) , comm)); |
---|
33 | //printf("EP_Comm_c2f : MAP insert: %d, %d, %p\n", fint, omp_get_thread_num(), comm.ep_comm_ptr); |
---|
34 | } |
---|
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 | #pragma omp critical (fc_comm_map) |
---|
50 | it = fc_comm_map.find(std::make_pair(comm, omp_get_thread_num())); |
---|
51 | |
---|
52 | if(it != fc_comm_map.end()) |
---|
53 | { |
---|
54 | MPI_Comm comm_ptr; |
---|
55 | comm_ptr = it->second; |
---|
56 | //printf("EP_Comm_f2c : MAP find: %d, %d, %p\n", it->first.first, it->first.second, comm_ptr.ep_comm_ptr); |
---|
57 | return comm_ptr; |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | #ifdef _openmpi |
---|
62 | ::MPI_Comm base_comm = ::MPI_Comm_f2c(comm); |
---|
63 | #elif _intelmpi |
---|
64 | ::MPI_Comm base_comm = (::MPI_Comm)(comm); |
---|
65 | #endif |
---|
66 | |
---|
67 | if(base_comm != MPI_COMM_NULL_STD) |
---|
68 | { |
---|
69 | if(omp_get_thread_num() == 0) |
---|
70 | { |
---|
71 | int num_ep = omp_get_num_threads(); |
---|
72 | MPI_Comm *new_comm; |
---|
73 | MPI_Info info; |
---|
74 | MPI_Comm_create_endpoints(base_comm, num_ep, info, new_comm); |
---|
75 | passage = new_comm; |
---|
76 | } |
---|
77 | #pragma omp barrier |
---|
78 | |
---|
79 | MPI_Comm return_comm = passage[omp_get_thread_num()]; |
---|
80 | return return_comm; |
---|
81 | |
---|
82 | } |
---|
83 | return MPI_COMM_NULL; |
---|
84 | |
---|
85 | } |
---|
86 | |
---|
87 | } |
---|
88 | |
---|
89 | |
---|