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