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

Last change on this file since 1642 was 1642, checked in by yushan, 5 years ago

dev on ADA. add flag switch _usingEP/_usingMPI

File size: 2.5 KB
Line 
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(ep_lib::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    *static_cast< MPI_Fint*>(fint) = MPI_Comm_c2f(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(EP_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 EP_COMM_NULL;
85
86  }
87
88//}
89
90
Note: See TracBrowser for help on using the repository browser.