[1134] | 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" |
---|
[1354] | 7 | #include "ep_mpi.hpp" |
---|
[1134] | 8 | |
---|
[1354] | 9 | // #ifdef _openmpi |
---|
| 10 | // //#undef MPI_Fint |
---|
| 11 | // #endif |
---|
[1134] | 12 | |
---|
| 13 | namespace ep_lib |
---|
| 14 | { |
---|
| 15 | |
---|
| 16 | int EP_Comm_c2f(MPI_Comm comm) |
---|
| 17 | { |
---|
| 18 | Debug("MPI_Comm_c2f"); |
---|
| 19 | int fint; |
---|
[1355] | 20 | //#ifdef _intelmpi |
---|
[1354] | 21 | fint = (::MPI_Fint)(to_mpi_comm(comm.mpi_comm)); |
---|
[1355] | 22 | //#elif _openmpi |
---|
| 23 | //fint = ::MPI_Comm_c2f(to_mpi_comm(comm.mpi_comm)); |
---|
| 24 | //#endif |
---|
[1134] | 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)); |
---|
[1328] | 34 | printf("EP_Comm_c2f : MAP %p insert: %d, %d, %p\n", &fc_comm_map, fint, omp_get_thread_num(), comm.ep_comm_ptr); |
---|
[1134] | 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; |
---|
[1328] | 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); |
---|
[1134] | 58 | return comm_ptr; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | |
---|
[1355] | 62 | //#ifdef _openmpi |
---|
| 63 | //::MPI_Comm base_comm = ::MPI_Comm_f2c(comm); |
---|
| 64 | //#elif _intelmpi |
---|
[1354] | 65 | ::MPI_Comm *base_comm = new ::MPI_Comm; |
---|
| 66 | *base_comm = (::MPI_Comm)(comm); |
---|
[1355] | 67 | //#endif |
---|
[1134] | 68 | |
---|
[1355] | 69 | if(*base_comm != to_mpi_comm(MPI_COMM_NULL.mpi_comm)) |
---|
[1134] | 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 | |
---|