source: XIOS/dev/dev_trunk_omp/extern/src_ep_dev/ep_fortran.cpp @ 1646

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

branch merged with trunk @1645. arch file (ep&mpi) added for ADA

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