[1651] | 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 | #elif _openmpi |
---|
| 21 | *static_cast< MPI_Fint*>(fint) = MPI_Comm_c2f(to_mpi_comm(comm->mpi_comm)); |
---|
| 22 | #endif |
---|
| 23 | |
---|
| 24 | std::map<std::pair< MPI_Fint, int>, ep_lib::MPI_Comm > ::iterator it; |
---|
| 25 | |
---|
| 26 | #pragma omp critical (fc_comm_map) |
---|
| 27 | { |
---|
| 28 | it = ep_lib::fc_comm_map.find(std::make_pair(*static_cast< MPI_Fint*>(fint), omp_get_thread_num())); |
---|
| 29 | if(it == ep_lib::fc_comm_map.end()) |
---|
| 30 | { |
---|
| 31 | ep_lib::fc_comm_map.insert(std::make_pair( std::make_pair( *static_cast< MPI_Fint*>(fint), omp_get_thread_num()) , comm)); |
---|
| 32 | 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); |
---|
| 33 | } |
---|
| 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 | #elif _openmpi |
---|
| 65 | *base_comm = MPI_Comm_f2c(*static_cast< MPI_Fint*>(comm)); |
---|
| 66 | #endif |
---|
| 67 | |
---|
| 68 | if(*base_comm != to_mpi_comm(MPI_COMM_NULL->mpi_comm)) |
---|
| 69 | { |
---|
| 70 | if(omp_get_thread_num() == 0) |
---|
| 71 | { |
---|
| 72 | int num_ep = omp_get_num_threads(); |
---|
| 73 | ep_lib::MPI_Comm *new_comm; |
---|
| 74 | ep_lib::MPI_Info info; |
---|
| 75 | ep_lib::MPI_Comm_create_endpoints(base_comm, num_ep, info, new_comm); |
---|
| 76 | ep_lib::passage = new_comm; |
---|
| 77 | } |
---|
| 78 | #pragma omp barrier |
---|
| 79 | |
---|
| 80 | ep_lib::MPI_Comm return_comm = ep_lib::passage[omp_get_thread_num()]; |
---|
| 81 | return return_comm; |
---|
| 82 | |
---|
| 83 | } |
---|
| 84 | return MPI_COMM_NULL; |
---|
| 85 | |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | //} |
---|
| 89 | #endif |
---|
| 90 | |
---|