source: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_fortran.cpp @ 1520

Last change on this file since 1520 was 1520, checked in by yushan, 6 years ago

save dev. TO DO : test with xios

File size: 2.3 KB
RevLine 
[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
9
10namespace ep_lib
11{
12
[1369]13  void* EP_Comm_c2f(MPI_Comm comm)
[1134]14  {
15    Debug("MPI_Comm_c2f");
[1369]16    void* fint = new ::MPI_Fint;
17    #ifdef _intelmpi
[1520]18    *static_cast< ::MPI_Fint*>(fint) = (::MPI_Fint)(to_mpi_comm(comm->mpi_comm));
[1369]19    #elif _openmpi
[1520]20    *static_cast< ::MPI_Fint*>(fint) = MPI_Comm_c2f(to_mpi_comm(comm->mpi_comm));
[1369]21    #endif
[1134]22   
[1369]23    std::map<std::pair< ::MPI_Fint, int>, MPI_Comm > ::iterator it;
[1134]24   
25    #pragma omp critical (fc_comm_map)
26    {
[1369]27      it = fc_comm_map.find(std::make_pair(*static_cast< ::MPI_Fint*>(fint), omp_get_thread_num()));
[1134]28      if(it == fc_comm_map.end())
29      {
[1369]30        fc_comm_map.insert(std::make_pair( std::make_pair( *static_cast< ::MPI_Fint*>(fint), omp_get_thread_num()) , comm));
[1520]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);
[1134]32      }
33    }
34   
35   
36    return fint;
37   
38  }
39
[1369]40  MPI_Comm EP_Comm_f2c(void* comm)
[1134]41  {
42    Debug("MPI_Comm_f2c");
43   
44   
[1369]45    std::map<std::pair< ::MPI_Fint, int>, MPI_Comm > ::iterator it;
[1134]46   
47    #pragma omp critical (fc_comm_map)
[1369]48    it = fc_comm_map.find(std::make_pair(*static_cast< ::MPI_Fint*>(comm), omp_get_thread_num()));
[1134]49   
50    if(it != fc_comm_map.end())
51    {
52      MPI_Comm comm_ptr;
53      comm_ptr = it->second;
[1520]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);
[1134]55      return  comm_ptr;
56    }
57       
58     
[1369]59   
60    #ifdef _intelmpi
[1354]61    ::MPI_Comm *base_comm = new ::MPI_Comm;
[1369]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
[1134]66
[1520]67    if(*base_comm != to_mpi_comm(MPI_COMM_NULL->mpi_comm))
[1134]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
Note: See TracBrowser for help on using the repository browser.