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

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

add modif for workflow_cmip6

File size: 2.9 KB
RevLine 
[1381]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
[1522]9namespace ep_lib
10{
[1381]11
[1527]12  int MPI_Intercomm_merge(MPI_Comm inter_comm, bool high, MPI_Comm *newintracomm)
[1381]13  {
[1527]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;
[1381]20
[1527]21    int remote_ep_size = inter_comm->inter_rank_map->size();
[1381]22
[1527]23    int new_ep_rank = high? remote_ep_size + ep_rank : ep_rank;
[1381]24
25
26    MPI_Comm_dup(inter_comm, newintracomm);
27
[1527]28    (*newintracomm)->is_intercomm = false;
29    (*newintracomm)->inter_rank_map->clear();
30    delete (*newintracomm)->inter_rank_map;
[1381]31
[1527]32    (*newintracomm)->ep_comm_ptr->size_rank_info[0].second = ep_size + remote_ep_size;
[1540]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   
[1527]50    (*newintracomm)->ep_comm_ptr->size_rank_info[0].first = new_ep_rank;
[1381]51
[1527]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)];
[1381]55
[1527]56   
57    MPI_Allgather(my_triple, 3, MPI_INT, my_triple_list, 3, MPI_INT, *newintracomm); 
[1381]58
59
[1527]60#ifdef _showinfo
61    for(int i=0; i<ep_size+remote_ep_size; i++)
[1381]62    {
[1527]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);
[1381]72    }
[1527]73#endif
[1381]74
[1527]75    if((*newintracomm)->ep_comm_ptr->size_rank_info[1].first==0)
[1381]76    {
[1527]77      for(int i=0; i<ep_size+remote_ep_size; i++)
[1381]78      {
[1527]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]);
[1381]80      }
81    }
82
83    MPI_Barrier_local(*newintracomm);
84
[1527]85#ifdef _showinfo
[1381]86
[1527]87    for(int i=0; i<ep_size+remote_ep_size; i++)
[1381]88    {
[1527]89      if(new_ep_rank == i)
[1518]90      {
[1527]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");
[1518]96      }
[1527]97      MPI_Barrier(*newintracomm);
[1518]98    }
[1527]99#endif
[1518]100
[1527]101    delete[] my_triple_list;
[1540]102
[1381]103  }
[1522]104 
[1381]105}
Note: See TracBrowser for help on using the repository browser.