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

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

dev on ADA. add flag switch _usingEP/_usingMPI

File size: 2.5 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
[1642]10//namespace ep_lib
11//{
[1134]12
[1642]13  void* EP_Comm_c2f(ep_lib::MPI_Comm comm)
[1134]14  {
15    Debug("MPI_Comm_c2f");
[1642]16    void* fint = new MPI_Fint;
[1369]17    #ifdef _intelmpi
[1642]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));
[1369]20    #elif _openmpi
[1642]21    *static_cast< MPI_Fint*>(fint) = MPI_Comm_c2f(to_mpi_comm(comm->mpi_comm));
[1369]22    #endif
[1134]23   
[1642]24    std::map<std::pair< MPI_Fint, int>, ep_lib::MPI_Comm > ::iterator it;
[1134]25   
26    #pragma omp critical (fc_comm_map)
27    {
[1642]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())
[1134]30      {
[1642]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);
[1134]33      }
34    }
35   
36   
37    return fint;
38   
39  }
40
[1642]41  ep_lib::MPI_Comm EP_Comm_f2c(void* comm)
[1134]42  {
43    Debug("MPI_Comm_f2c");
44   
45   
[1642]46    std::map<std::pair< MPI_Fint, int>, ep_lib::MPI_Comm > ::iterator it;
[1134]47   
48    #pragma omp critical (fc_comm_map)
[1642]49    it = ep_lib::fc_comm_map.find(std::make_pair(*static_cast< MPI_Fint*>(comm), omp_get_thread_num()));
[1134]50   
[1642]51    if(it != ep_lib::fc_comm_map.end())
[1134]52    {
[1642]53      ep_lib::MPI_Comm comm_ptr;
[1134]54      comm_ptr = it->second;
[1642]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);
[1134]56      return  comm_ptr;
57    }
58       
59     
[1369]60   
[1642]61    MPI_Comm *base_comm = new MPI_Comm;
[1369]62    #ifdef _intelmpi
[1642]63    *base_comm = (MPI_Comm)(*static_cast< MPI_Fint*>(comm));
[1369]64    #elif _openmpi
[1642]65    *base_comm = MPI_Comm_f2c(*static_cast< MPI_Fint*>(comm));
[1369]66    #endif
[1134]67
[1642]68    if(*base_comm != to_mpi_comm(EP_COMM_NULL->mpi_comm))
[1134]69    {
70      if(omp_get_thread_num() == 0)
71      {
72        int num_ep = omp_get_num_threads();
[1642]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;
[1134]77      }
78      #pragma omp barrier
79
[1642]80      ep_lib::MPI_Comm return_comm = ep_lib::passage[omp_get_thread_num()];
[1134]81      return return_comm;
82       
83    }
[1642]84    return EP_COMM_NULL;
[1134]85
86  }
87
[1642]88//}
[1134]89
90
Note: See TracBrowser for help on using the repository browser.