source: XIOS/dev/dev_trunk_omp/extern/ep_dev/ep_merge.cpp @ 1604

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

branch_openmp merged with trunk r1597

File size: 2.9 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   
34    ///////////////////////////////////
35    int int_high = high? 1 : 0;
36    int sum_high;
37   
38    MPI_Allreduce(&int_high, &sum_high, 1, MPI_INT, MPI_SUM, *newintracomm);
39
40    if(sum_high==0 || sum_high==ep_size+remote_ep_size)
41    {
42      printf("MPI_Intercomm_merge error: please define high with different value...\n");
43      MPI_Abort(inter_comm, 0);
44    }
45   
46   
47   
48    ///////////////////////////////////
49   
50    (*newintracomm)->ep_comm_ptr->size_rank_info[0].first = new_ep_rank;
51
52    // modif ep_rank_map
53    int my_triple[3] = {new_ep_rank, ep_rank_loc, mpi_rank};
54    int *my_triple_list = new int[3*(ep_size+remote_ep_size)];
55
56   
57    MPI_Allgather(my_triple, 3, MPI_INT, my_triple_list, 3, MPI_INT, *newintracomm); 
58
59
60#ifdef _showinfo
61    for(int i=0; i<ep_size+remote_ep_size; i++)
62    {
63      if(new_ep_rank == i)
64      {
65        for(int j=0; j<ep_size+remote_ep_size; j++)
66        {
67          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]);
68        }
69        printf("\n");
70      }
71      MPI_Barrier(*newintracomm);
72    }
73#endif
74
75    if((*newintracomm)->ep_comm_ptr->size_rank_info[1].first==0)
76    {
77      for(int i=0; i<ep_size+remote_ep_size; i++)
78      {
79        (*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]);
80      }
81    }
82
83    MPI_Barrier_local(*newintracomm);
84
85#ifdef _showinfo
86
87    for(int i=0; i<ep_size+remote_ep_size; i++)
88    {
89      if(new_ep_rank == i)
90      {
91        for(EP_RANK_MAP::iterator it = (*newintracomm)->ep_rank_map->begin(); it != (*newintracomm)->ep_rank_map->end(); it++)
92        {
93          printf("rank %d : ep_rank_map[%d] = %d %d\n", i, it->first, it->second.first, it->second.second);
94        }
95        printf("\n");
96      }
97      MPI_Barrier(*newintracomm);
98    }
99#endif
100
101    delete[] my_triple_list;
102
103  }
104 
105}
Note: See TracBrowser for help on using the repository browser.