source: XIOS/dev/dev_trunk_omp/extern/src_ep_dev/ep_create.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: 4.1 KB
Line 
1#ifdef _usingEP
2/*!
3   \file ep_create.cpp
4   \since 2 may 2016
5
6   \brief Definitions of MPI endpoint function: MPI_Comm_create_endpoints
7 */
8
9#include "ep_lib.hpp"
10#include <mpi.h>
11#include "ep_declaration.hpp"
12#include "ep_mpi.hpp"
13
14using namespace std;
15
16namespace ep_lib {
17
18  /*!
19    Dynamic creation of endpoints for each MPI process.
20    The output of this function is an array of communicator handles of length num_ep, where each handle
21    corresponds to a nez local randk in the output communicator.
22    Once created, endpoints behave as MPI processes.
23    \param [in] mpi_comm Parent MPI communicator.
24    \param [in] num_ep Number of endpoints per process.
25    \param [out] info Information of the EP creation.
26    \param [out] out_comm_hdls Handles of EP communicators.
27  */
28 
29  int MPI_Comm_create_endpoints(void* base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls)
30  {
31
32    int base_rank;
33    int base_size;
34   
35    ::MPI_Comm mpi_base_comm = to_mpi_comm(base_comm_ptr);
36
37    ::MPI_Comm_size(mpi_base_comm, &base_size);  // ep_lib::mpi_comm_size
38    ::MPI_Comm_rank(mpi_base_comm, &base_rank);  // ep_lib::mpi_comm_rank
39                    // parent_comm can also be endpoints communicators
40
41    std::vector<int> recv_num_ep(base_size);
42
43    out_comm_hdls = new MPI_Comm[num_ep];
44#ifdef _showinfo
45    printf("new out_comm_hdls = %p\n", out_comm_hdls);
46#endif
47
48    ::MPI_Comm *parent_comm = new ::MPI_Comm;
49    ::MPI_Comm_dup(to_mpi_comm(base_comm_ptr), parent_comm);
50
51#ifdef _showinfo
52    printf("new out_comm_hdls->mpi_comm = %p\n", parent_comm);
53#endif
54   
55    for (int idx = 0; idx < num_ep; ++idx)
56    {
57
58      out_comm_hdls[idx] = new ep_comm;
59#ifdef _showinfo
60      printf("new out_comm_hdls[%d] = %p\n", idx, out_comm_hdls[idx]);
61#endif
62
63      out_comm_hdls[idx]->is_ep = true;
64      out_comm_hdls[idx]->is_intercomm = false;
65     
66      out_comm_hdls[idx]->ep_comm_ptr = new ep_communicator;     
67#ifdef _showinfo
68      printf("new out_comm_hdls[%d]->ep_comm_ptr = %p\n", idx, out_comm_hdls[idx]->ep_comm_ptr);
69#endif
70
71
72      out_comm_hdls[idx]->mpi_comm = parent_comm;
73      out_comm_hdls[idx]->ep_comm_ptr->comm_list = out_comm_hdls;
74    }
75
76    ::MPI_Allgather(&num_ep, 1, to_mpi_type(MPI_INT), &recv_num_ep[0], 1, to_mpi_type(MPI_INT), mpi_base_comm);
77
78
79    int sum = 0;  // representing total ep number of process with smaller rank
80    for (int i = 0; i < base_rank; ++i) {sum += recv_num_ep[i]; }
81
82    int ep_size = std::accumulate(recv_num_ep.begin(), recv_num_ep.end(), 0);
83
84    out_comm_hdls[0]->ep_barrier = new ep_barrier(num_ep);
85#ifdef _showinfo
86    printf("new out_comm_hdls[0]->ep_barrier = %p\n", out_comm_hdls[0]->ep_barrier);
87#endif
88
89    out_comm_hdls[0]->my_buffer = new BUFFER;
90#ifdef _showinfo
91    printf("new out_comm_hdls[0]->my_buffer = %p\n", out_comm_hdls[0]->my_buffer);
92#endif
93
94    out_comm_hdls[0]->ep_rank_map = new EP_RANK_MAP;
95#ifdef _showinfo
96    printf("new out_comm_hdls[0]->ep_rank_map = %p\n", out_comm_hdls[0]->ep_rank_map);
97#endif
98
99    for (int i = 1; i < num_ep; i++)
100    {
101      out_comm_hdls[i]->ep_barrier = out_comm_hdls[0]->ep_barrier;
102      out_comm_hdls[i]->my_buffer  = out_comm_hdls[0]->my_buffer;
103      out_comm_hdls[i]->ep_rank_map= out_comm_hdls[0]->ep_rank_map;
104    }
105
106
107    for (int i = 0; i < num_ep; i++)
108    {
109      out_comm_hdls[i]->ep_comm_ptr->size_rank_info[0] = std::make_pair(sum+i, ep_size);
110      out_comm_hdls[i]->ep_comm_ptr->size_rank_info[1] = std::make_pair(i, num_ep);
111      out_comm_hdls[i]->ep_comm_ptr->size_rank_info[2] = std::make_pair(base_rank, base_size);
112
113      out_comm_hdls[i]->ep_comm_ptr->message_queue = new Message_list;
114#ifdef _showinfo
115      printf("new out_comm_hdls[%d]->ep_comm_ptr->message_queue = %p\n", i, out_comm_hdls[i]->ep_comm_ptr->message_queue);
116#endif
117
118    }
119
120
121    int ind = 0;
122
123    for(int i=0; i<base_size; i++)
124    {
125      for(int j=0; j<recv_num_ep[i]; j++)
126      {
127        //out_comm_hdls[0]->ep_rank_map->insert(std::pair< int, std::pair<int,int> >(ind, j, i));
128        (*(out_comm_hdls[0]->ep_rank_map))[ind] = std::make_pair(j,i);//->insert(std::pair< int, std::pair<int,int> >(ind, j, i));
129        ind++;
130      }
131    }
132
133  } //MPI_Comm_create_endpoints
134
135 
136
137} //namespace ep_lib
138#endif
Note: See TracBrowser for help on using the repository browser.