source: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allocate.cpp @ 1539

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

update intercomm_merge and remove redundant files

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