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 | |
---|
10 | namespace ep_lib |
---|
11 | { |
---|
12 | |
---|
13 | void* EP_Comm_c2f(MPI_Comm comm) |
---|
14 | { |
---|
15 | Debug("MPI_Comm_c2f"); |
---|
16 | void* fint = new ::MPI_Fint; |
---|
17 | #ifdef _intelmpi |
---|
18 | *static_cast< ::MPI_Fint*>(fint) = (::MPI_Fint)(to_mpi_comm(comm->mpi_comm)); |
---|
19 | #elif _openmpi |
---|
20 | *static_cast< ::MPI_Fint*>(fint) = MPI_Comm_c2f(to_mpi_comm(comm->mpi_comm)); |
---|
21 | #endif |
---|
22 | |
---|
23 | std::map<std::pair< ::MPI_Fint, int>, MPI_Comm > ::iterator it; |
---|
24 | |
---|
25 | #pragma omp critical (fc_comm_map) |
---|
26 | { |
---|
27 | it = fc_comm_map.find(std::make_pair(*static_cast< ::MPI_Fint*>(fint), omp_get_thread_num())); |
---|
28 | if(it == fc_comm_map.end()) |
---|
29 | { |
---|
30 | fc_comm_map.insert(std::make_pair( std::make_pair( *static_cast< ::MPI_Fint*>(fint), omp_get_thread_num()) , comm)); |
---|
31 | printf("EP_Comm_c2f : MAP %p insert: %d, %d, %p\n", &fc_comm_map, *static_cast< ::MPI_Fint*>(fint), omp_get_thread_num(), comm->ep_comm_ptr); |
---|
32 | } |
---|
33 | } |
---|
34 | |
---|
35 | |
---|
36 | return fint; |
---|
37 | |
---|
38 | } |
---|
39 | |
---|
40 | MPI_Comm EP_Comm_f2c(void* comm) |
---|
41 | { |
---|
42 | Debug("MPI_Comm_f2c"); |
---|
43 | |
---|
44 | |
---|
45 | std::map<std::pair< ::MPI_Fint, int>, MPI_Comm > ::iterator it; |
---|
46 | |
---|
47 | #pragma omp critical (fc_comm_map) |
---|
48 | it = fc_comm_map.find(std::make_pair(*static_cast< ::MPI_Fint*>(comm), omp_get_thread_num())); |
---|
49 | |
---|
50 | if(it != fc_comm_map.end()) |
---|
51 | { |
---|
52 | MPI_Comm comm_ptr; |
---|
53 | comm_ptr = it->second; |
---|
54 | 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); |
---|
55 | return comm_ptr; |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | |
---|
60 | #ifdef _intelmpi |
---|
61 | ::MPI_Comm *base_comm = new ::MPI_Comm; |
---|
62 | *base_comm = (::MPI_Comm)(*static_cast< ::MPI_Fint*>(comm)); |
---|
63 | #elif _openmpi |
---|
64 | ::MPI_Comm *base_comm = ::MPI_Comm_f2c(*static_cast< ::MPI_Fint*>(comm)); |
---|
65 | #endif |
---|
66 | |
---|
67 | if(*base_comm != to_mpi_comm(MPI_COMM_NULL->mpi_comm)) |
---|
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 | |
---|