source: XIOS/dev/branch_openmp/extern/ep_dev/ep_merge.cpp @ 1532

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

save dev

File size: 2.4 KB
Line 
1#include "ep_lib.hpp"
2#include <mpi.h>
3#include "ep_declaration.hpp"
4#include "ep_mpi.hpp"
5
6using namespace std;
7
8
9namespace ep_lib
10{
11
12  int MPI_Intercomm_merge(MPI_Comm inter_comm, bool high, MPI_Comm *newintracomm)
13  {
14   
15    int ep_rank = inter_comm->ep_comm_ptr->size_rank_info[0].first;
16    int ep_size = inter_comm->ep_comm_ptr->size_rank_info[0].second;
17    int ep_rank_loc = inter_comm->ep_comm_ptr->size_rank_info[1].first;
18    int num_ep = inter_comm->ep_comm_ptr->size_rank_info[1].second;
19    int mpi_rank = inter_comm->ep_comm_ptr->size_rank_info[2].first;
20
21    int remote_ep_size = inter_comm->inter_rank_map->size();
22
23    int new_ep_rank = high? remote_ep_size + ep_rank : ep_rank;
24
25
26    MPI_Comm_dup(inter_comm, newintracomm);
27
28    (*newintracomm)->is_intercomm = false;
29    (*newintracomm)->inter_rank_map->clear();
30    delete (*newintracomm)->inter_rank_map;
31
32    (*newintracomm)->ep_comm_ptr->size_rank_info[0].second = ep_size + remote_ep_size;
33    (*newintracomm)->ep_comm_ptr->size_rank_info[0].first = new_ep_rank;
34
35    // modif ep_rank_map
36    int my_triple[3] = {new_ep_rank, ep_rank_loc, mpi_rank};
37    int *my_triple_list = new int[3*(ep_size+remote_ep_size)];
38
39   
40    MPI_Allgather(my_triple, 3, MPI_INT, my_triple_list, 3, MPI_INT, *newintracomm); 
41
42
43#ifdef _showinfo
44    for(int i=0; i<ep_size+remote_ep_size; i++)
45    {
46      if(new_ep_rank == i)
47      {
48        for(int j=0; j<ep_size+remote_ep_size; j++)
49        {
50          printf("rank %d : my_triple_list[%d] = %d %d %d\n", i, j, my_triple_list[3*j], my_triple_list[3*j+1], my_triple_list[3*j+2]);
51        }
52        printf("\n");
53      }
54      MPI_Barrier(*newintracomm);
55    }
56#endif
57
58    if((*newintracomm)->ep_comm_ptr->size_rank_info[1].first==0)
59    {
60      for(int i=0; i<ep_size+remote_ep_size; i++)
61      {
62        (*newintracomm)->ep_comm_ptr->comm_list[0]->ep_rank_map->at(my_triple_list[3*i]) = std::make_pair(my_triple_list[3*i+1], my_triple_list[3*i+2]);
63      }
64    }
65
66    MPI_Barrier_local(*newintracomm);
67
68#ifdef _showinfo
69
70    for(int i=0; i<ep_size+remote_ep_size; i++)
71    {
72      if(new_ep_rank == i)
73      {
74        for(EP_RANK_MAP::iterator it = (*newintracomm)->ep_rank_map->begin(); it != (*newintracomm)->ep_rank_map->end(); it++)
75        {
76          printf("rank %d : ep_rank_map[%d] = %d %d\n", i, it->first, it->second.first, it->second.second);
77        }
78        printf("\n");
79      }
80      MPI_Barrier(*newintracomm);
81    }
82#endif
83
84    delete[] my_triple_list;
85  }
86 
87}
Note: See TracBrowser for help on using the repository browser.