[1646] | 1 | #ifdef _usingEP |
---|
[1603] | 2 | #include "ep_lib.hpp" |
---|
| 3 | #include <mpi.h> |
---|
| 4 | #include "ep_declaration.hpp" |
---|
| 5 | #include "ep_mpi.hpp" |
---|
| 6 | |
---|
| 7 | using namespace std; |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | namespace ep_lib |
---|
| 11 | { |
---|
| 12 | |
---|
| 13 | int MPI_Intercomm_merge(MPI_Comm inter_comm, bool high, MPI_Comm *newintracomm) |
---|
| 14 | { |
---|
| 15 | |
---|
| 16 | int ep_rank = inter_comm->ep_comm_ptr->size_rank_info[0].first; |
---|
| 17 | int ep_size = inter_comm->ep_comm_ptr->size_rank_info[0].second; |
---|
| 18 | int ep_rank_loc = inter_comm->ep_comm_ptr->size_rank_info[1].first; |
---|
| 19 | int num_ep = inter_comm->ep_comm_ptr->size_rank_info[1].second; |
---|
| 20 | int mpi_rank = inter_comm->ep_comm_ptr->size_rank_info[2].first; |
---|
| 21 | |
---|
| 22 | int remote_ep_size = inter_comm->inter_rank_map->size(); |
---|
| 23 | |
---|
| 24 | int new_ep_rank = high? remote_ep_size + ep_rank : ep_rank; |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | MPI_Comm_dup(inter_comm, newintracomm); |
---|
| 28 | |
---|
| 29 | (*newintracomm)->is_intercomm = false; |
---|
| 30 | (*newintracomm)->inter_rank_map->clear(); |
---|
| 31 | delete (*newintracomm)->inter_rank_map; |
---|
| 32 | |
---|
| 33 | (*newintracomm)->ep_comm_ptr->size_rank_info[0].second = ep_size + remote_ep_size; |
---|
| 34 | |
---|
| 35 | /////////////////////////////////// |
---|
| 36 | int int_high = high? 1 : 0; |
---|
| 37 | int sum_high; |
---|
| 38 | |
---|
| 39 | MPI_Allreduce(&int_high, &sum_high, 1, MPI_INT, MPI_SUM, *newintracomm); |
---|
| 40 | |
---|
| 41 | if(sum_high==0 || sum_high==ep_size+remote_ep_size) |
---|
| 42 | { |
---|
| 43 | printf("MPI_Intercomm_merge error: please define high with different value...\n"); |
---|
| 44 | MPI_Abort(inter_comm, 0); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | /////////////////////////////////// |
---|
| 50 | |
---|
| 51 | (*newintracomm)->ep_comm_ptr->size_rank_info[0].first = new_ep_rank; |
---|
| 52 | |
---|
| 53 | // modif ep_rank_map |
---|
| 54 | int my_triple[3] = {new_ep_rank, ep_rank_loc, mpi_rank}; |
---|
| 55 | int *my_triple_list = new int[3*(ep_size+remote_ep_size)]; |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | MPI_Allgather(my_triple, 3, MPI_INT, my_triple_list, 3, MPI_INT, *newintracomm); |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | #ifdef _showinfo |
---|
| 62 | for(int i=0; i<ep_size+remote_ep_size; i++) |
---|
| 63 | { |
---|
| 64 | if(new_ep_rank == i) |
---|
| 65 | { |
---|
| 66 | for(int j=0; j<ep_size+remote_ep_size; j++) |
---|
| 67 | { |
---|
| 68 | 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]); |
---|
| 69 | } |
---|
| 70 | printf("\n"); |
---|
| 71 | } |
---|
| 72 | MPI_Barrier(*newintracomm); |
---|
| 73 | } |
---|
| 74 | #endif |
---|
| 75 | |
---|
| 76 | if((*newintracomm)->ep_comm_ptr->size_rank_info[1].first==0) |
---|
| 77 | { |
---|
| 78 | for(int i=0; i<ep_size+remote_ep_size; i++) |
---|
| 79 | { |
---|
| 80 | (*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]); |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | MPI_Barrier_local(*newintracomm); |
---|
| 85 | |
---|
| 86 | #ifdef _showinfo |
---|
| 87 | |
---|
| 88 | for(int i=0; i<ep_size+remote_ep_size; i++) |
---|
| 89 | { |
---|
| 90 | if(new_ep_rank == i) |
---|
| 91 | { |
---|
| 92 | for(EP_RANK_MAP::iterator it = (*newintracomm)->ep_rank_map->begin(); it != (*newintracomm)->ep_rank_map->end(); it++) |
---|
| 93 | { |
---|
| 94 | printf("rank %d : ep_rank_map[%d] = %d %d\n", i, it->first, it->second.first, it->second.second); |
---|
| 95 | } |
---|
| 96 | printf("\n"); |
---|
| 97 | } |
---|
| 98 | MPI_Barrier(*newintracomm); |
---|
| 99 | } |
---|
| 100 | #endif |
---|
| 101 | |
---|
| 102 | delete[] my_triple_list; |
---|
| 103 | |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | } |
---|
[1646] | 107 | #endif |
---|