source: XIOS/dev/dev_trunk_omp/extern/src_ep_dev/ep_allocate.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.3 KB
Line 
1#ifdef _usingEP
2#include "ep_lib.hpp"
3#include <mpi.h>
4#include "ep_declaration.hpp"
5#include "ep_mpi.hpp"
6
7namespace ep_lib
8{
9
10
11
12  int MPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr)
13  {
14    ::MPI_Alloc_mem(to_mpi_aint(size), to_mpi_info(info), baseptr);
15    return 0;
16   }
17   
18  int MPI_Alloc_mem(unsigned long size, MPI_Info info, void *baseptr)
19  {
20    ::MPI_Alloc_mem(size, *(static_cast< ::MPI_Info*>(info->mpi_info)), baseptr);
21    return 0;
22  }
23
24  int MPI_Win_allocate (MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, void *baseptr, MPI_Win *win)
25  {
26    int rank, rank_loc, num_ep;
27    MPI_Comm_rank(comm, &rank);
28    rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
29    num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
30   
31    *win = new ep_win;
32   
33    (*win)->is_ep = comm->is_ep;
34
35    int num_ep_max;
36    MPI_Allreduce(&num_ep, &num_ep_max, 1, MPI_INT, MPI_MAX, comm);
37
38    assert(num_ep_max > 1);
39   
40    info = new ep_info;
41
42    if(num_ep == 1)  // server
43    {
44      for(int i=0; i<num_ep_max; i++)
45      {
46        (*win)->server_win[i] = new ::MPI_Win;
47      }
48
49      printf("Calling MPI_Win_allocate from server, rank = %d\n", rank);
50      for(int i=0; i<num_ep_max; i++)
51      {
52        ::MPI_Win_allocate(to_mpi_aint(size), disp_unit, to_mpi_info(info), to_mpi_comm(comm->mpi_comm), baseptr, static_cast< ::MPI_Win*>((*win)->server_win[i]));
53        (*win)->comm = comm;
54      }
55    }
56    else  // client
57    {
58      (*win)->client_win = new ::MPI_Win;
59     
60      for(int i=0; i<num_ep; i++)
61      {
62        if(rank_loc == i)
63        {
64          printf("Calling MPI_Win_allocate from client, rank = %d\n", rank);
65          ::MPI_Win_allocate(to_mpi_aint(size), disp_unit, to_mpi_info(info), to_mpi_comm(comm->mpi_comm), baseptr, static_cast< ::MPI_Win*>((*win)->client_win)); 
66          (*win)->comm = comm;
67        }
68        MPI_Barrier_local(comm);
69      }
70
71      if(num_ep_max > num_ep)
72      {
73        #pragma omp master
74        {
75          for(int i=0; i<num_ep_max-num_ep; i++)
76          {
77            (*win)->null_win[i] = new ::MPI_Win;
78            ::MPI_Win_allocate(0, disp_unit, to_mpi_info(info), to_mpi_comm(comm->mpi_comm), baseptr, static_cast< ::MPI_Win*>((*win)->null_win[i])); 
79          } 
80        } 
81      }
82
83    }
84    return 0;
85  }
86
87}
88#endif
Note: See TracBrowser for help on using the repository browser.