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