Changeset 1520
- Timestamp:
- 06/04/18 19:25:08 (7 years ago)
- Location:
- XIOS/dev/branch_openmp
- Files:
-
- 58 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/branch_openmp/arch/arch-CURIE_Intel.fcm
r1134 r1520 3 3 ################################################################################ 4 4 5 %CCOMPILER mpicc -openmp -D_intelmpi -D_usingEP 5 %CCOMPILER mpicc -openmp -D_intelmpi -D_usingEP -std=c++11 6 6 %FCOMPILER mpif90 -openmp 7 7 %LINKER mpif90 -openmp -Wl,-rpath -Wl,$HOME/lib/netcdf_f_intel/lib -
XIOS/dev/branch_openmp/bld.cfg
r1482 r1520 30 30 src::remap $PWD/extern/remap/src 31 31 src::src_ep_dev $PWD/extern/src_ep_dev 32 #src::src_ep_dev $PWD/extern/ep_dev 32 33 bld::lib xios 33 34 bld::target libxios.a -
XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.cpp
r1517 r1520 27 27 int get_ep_rank(MPI_Comm comm, int ep_rank_loc, int mpi_rank) 28 28 { 29 if(comm->is_intercomm) 30 { 31 for(std::map<int, std::pair< int, std::pair<int, int> > >::iterator it = comm->ep_comm_ptr->intercomm->intercomm_rank_map->begin(); it != comm->ep_comm_ptr->intercomm->intercomm_rank_map->end(); it++) 32 { 33 if( ( it->second.first == ep_rank_loc ) 34 && ( it->second.second.first == mpi_rank ) ) 35 { 36 return it->first; 37 } 38 } 39 printf("rank not find for EP_intercomm\n"); 40 int err; 41 return MPI_Abort(comm, err); 42 } 43 29 44 for(std::map<int, std::pair<int, int> >::iterator it = comm->ep_rank_map->begin(); it != comm->ep_rank_map->end(); it++) 30 45 { … … 35 50 } 36 51 } 37 printf("rank not find\n"); 52 printf("rank not find for EP_intracomm\n"); 53 int err; 54 return MPI_Abort(comm, err); 38 55 } 39 56 -
XIOS/dev/branch_openmp/extern/ep_dev/ep_test.cpp
r1500 r1520 33 33 status->ep_tag = (*request)->ep_tag; 34 34 status->ep_datatype = (*request)->ep_datatype; 35 //delete request->mpi_request; 35 delete (*request)->mpi_request; 36 delete request; 36 37 } 37 38 … … 60 61 status->ep_tag = (*request)->ep_tag; 61 62 status->ep_datatype = (*request)->ep_datatype; 62 //delete request->mpi_request; 63 delete (*request)->mpi_request; 64 delete request; 63 65 //int count; 64 66 //MPI_Get_count(status, request->ep_datatype, &count); … … 75 77 { 76 78 Debug("MPI_Testall with EP"); 77 *flag = true; 78 int i=0; 79 while(*flag && i<count ) 79 80 ::MPI_Request* mpi_request = new ::MPI_Request[count]; 81 ::MPI_Status* mpi_status = new ::MPI_Status[count]; 82 83 84 for(int i=0; i<count; i++) 80 85 { 81 MPI_Test(&array_of_requests[i], flag, &array_of_statuses[i]); 82 i++; 86 mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i]->mpi_request); 87 } 88 89 ::MPI_Testall(count, mpi_request, flag, mpi_status); 90 91 if(flag) 92 { 93 for(int i=0; i<count; i++) 94 { 95 array_of_statuses[i].mpi_status = &mpi_status[i]; 96 array_of_statuses[i].ep_src = array_of_requests[i]->ep_src; 97 array_of_statuses[i].ep_tag = array_of_requests[i]->ep_tag; 98 array_of_statuses[i].ep_datatype = array_of_requests[i]->ep_datatype; 99 100 memcheck("delete "<< array_of_requests[i]->mpi_request <<" : in ep_lib::MPI_Waitall, array_of_requests["<<i<<"]->mpi_request"); 101 delete array_of_requests[i]->mpi_request; 102 delete array_of_requests[i]; 103 } 104 83 105 } 84 106 … … 87 109 88 110 } 111 -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgather.cpp
r1354 r1520 17 17 { 18 18 19 int MPI_Allgather_local(const void *sendbuf, int count, MPI_Datatype datatype, void *recvbuf, MPI_Comm comm) 20 { 21 assert(valid_type(datatype)); 22 23 ::MPI_Aint datasize, lb; 24 ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize); 25 26 int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 27 int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 28 29 #pragma omp critical (write_buffer) 30 comm->my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf); 31 32 MPI_Barrier_local(comm); 33 34 #pragma omp critical (read_buffer) 35 { 36 for(int i=0; i<num_ep; i++) 37 memcpy(recvbuf + datasize * i * count, comm->my_buffer->void_buffer[i], datasize * count); 38 } 39 MPI_Barrier_local(comm); 40 } 41 19 42 int MPI_Allgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) 20 43 { 21 44 22 if(!comm .is_ep && comm.mpi_comm)45 if(!comm->is_ep && comm->mpi_comm) 23 46 { 24 return ::MPI_Allgather(const_cast<void*>(sendbuf), sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), to_mpi_comm(comm .mpi_comm));47 return ::MPI_Allgather(const_cast<void*>(sendbuf), sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), to_mpi_comm(comm->mpi_comm)); 25 48 } 26 49 … … 37 60 38 61 39 int ep_rank = comm .ep_comm_ptr->size_rank_info[0].first;40 int ep_rank_loc = comm .ep_comm_ptr->size_rank_info[1].first;41 int mpi_rank = comm .ep_comm_ptr->size_rank_info[2].first;42 int ep_size = comm .ep_comm_ptr->size_rank_info[0].second;43 int num_ep = comm .ep_comm_ptr->size_rank_info[1].second;44 int mpi_size = comm .ep_comm_ptr->size_rank_info[2].second;62 int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 63 int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 64 int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 65 int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 66 int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 67 int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 45 68 46 69 bool is_master = ep_rank_loc==0; … … 70 93 int local_sendcount = num_ep * count; 71 94 72 ::MPI_Allgather(&local_sendcount, 1, to_mpi_type(MPI_INT), mpi_recvcounts, 1, to_mpi_type(MPI_INT), to_mpi_comm(comm .mpi_comm));95 ::MPI_Allgather(&local_sendcount, 1, to_mpi_type(MPI_INT), mpi_recvcounts, 1, to_mpi_type(MPI_INT), to_mpi_comm(comm->mpi_comm)); 73 96 74 97 mpi_displs[0] = 0; … … 79 102 80 103 81 ::MPI_Allgatherv(local_recvbuf, num_ep * count, to_mpi_type(datatype), tmp_recvbuf, mpi_recvcounts, mpi_displs, to_mpi_type(datatype), to_mpi_comm(comm .mpi_comm));104 ::MPI_Allgatherv(local_recvbuf, num_ep * count, to_mpi_type(datatype), tmp_recvbuf, mpi_recvcounts, mpi_displs, to_mpi_type(datatype), to_mpi_comm(comm->mpi_comm)); 82 105 83 106 … … 86 109 for(int i=0; i<ep_size; i++) 87 110 { 88 offset = mpi_displs[comm .rank_map->at(i).second] + comm.rank_map->at(i).first * sendcount;111 offset = mpi_displs[comm->ep_rank_map->at(i).second] + comm->ep_rank_map->at(i).first * sendcount; 89 112 memcpy(recvbuf + i*sendcount*datasize, tmp_recvbuf+offset*datasize, sendcount*datasize); 90 113 } -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgatherv.cpp
r1354 r1520 20 20 { 21 21 22 if(!comm .is_ep && comm.mpi_comm)22 if(!comm->is_ep && comm->mpi_comm) 23 23 { 24 return ::MPI_Allgatherv(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcounts, displs, to_mpi_type(recvtype), to_mpi_comm(comm .mpi_comm));24 return ::MPI_Allgatherv(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcounts, displs, to_mpi_type(recvtype), to_mpi_comm(comm->mpi_comm)); 25 25 } 26 26 27 if(!comm .mpi_comm) return 0;27 if(!comm->mpi_comm) return 0; 28 28 29 29 … … 38 38 39 39 40 int ep_rank = comm .ep_comm_ptr->size_rank_info[0].first;41 int ep_rank_loc = comm .ep_comm_ptr->size_rank_info[1].first;42 int mpi_rank = comm .ep_comm_ptr->size_rank_info[2].first;43 int ep_size = comm .ep_comm_ptr->size_rank_info[0].second;44 int num_ep = comm .ep_comm_ptr->size_rank_info[1].second;45 int mpi_size = comm .ep_comm_ptr->size_rank_info[2].second;40 int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 41 int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 42 int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 43 int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 44 int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 45 int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 46 46 47 47 assert(sendcount == recvcounts[ep_rank]); … … 79 79 80 80 int local_sendcount = std::accumulate(local_recvcounts.begin(), local_recvcounts.end(), 0); 81 ::MPI_Allgather(&local_sendcount, 1, to_mpi_type(MPI_INT), mpi_recvcounts.data(), 1, to_mpi_type(MPI_INT), to_mpi_comm(comm .mpi_comm));81 ::MPI_Allgather(&local_sendcount, 1, to_mpi_type(MPI_INT), mpi_recvcounts.data(), 1, to_mpi_type(MPI_INT), to_mpi_comm(comm->mpi_comm)); 82 82 83 83 for(int i=1; i<mpi_size; i++) … … 85 85 86 86 87 ::MPI_Allgatherv(local_recvbuf, local_sendcount, to_mpi_type(datatype), tmp_recvbuf, mpi_recvcounts.data(), mpi_displs.data(), to_mpi_type(datatype), to_mpi_comm(comm .mpi_comm));87 ::MPI_Allgatherv(local_recvbuf, local_sendcount, to_mpi_type(datatype), tmp_recvbuf, mpi_recvcounts.data(), mpi_displs.data(), to_mpi_type(datatype), to_mpi_comm(comm->mpi_comm)); 88 88 89 89 // reorder … … 92 92 { 93 93 int extra = 0; 94 for(int j=0, k=0; j<ep_size, k<comm .rank_map->at(i).first; j++)95 if(comm .rank_map->at(i).second == comm.rank_map->at(j).second)94 for(int j=0, k=0; j<ep_size, k<comm->ep_rank_map->at(i).first; j++) 95 if(comm->ep_rank_map->at(i).second == comm->ep_rank_map->at(j).second) 96 96 { 97 97 extra += recvcounts[j]; … … 99 99 } 100 100 101 offset = mpi_displs[comm .rank_map->at(i).second] + extra;101 offset = mpi_displs[comm->ep_rank_map->at(i).second] + extra; 102 102 103 103 memcpy(recvbuf+displs[i]*datasize, tmp_recvbuf+offset*datasize, recvcounts[i]*datasize); -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allreduce.cpp
r1354 r1520 21 21 int MPI_Allreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) 22 22 { 23 if(!comm .is_ep && comm.mpi_comm)23 if(!comm->is_ep && comm->mpi_comm) 24 24 { 25 return ::MPI_Allreduce(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm .mpi_comm));25 return ::MPI_Allreduce(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm)); 26 26 } 27 27 28 28 29 29 30 int ep_rank = comm .ep_comm_ptr->size_rank_info[0].first;31 int ep_rank_loc = comm .ep_comm_ptr->size_rank_info[1].first;32 int mpi_rank = comm .ep_comm_ptr->size_rank_info[2].first;33 int ep_size = comm .ep_comm_ptr->size_rank_info[0].second;34 int num_ep = comm .ep_comm_ptr->size_rank_info[1].second;35 int mpi_size = comm .ep_comm_ptr->size_rank_info[2].second;30 int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 31 int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 32 int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 33 int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 34 int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 35 int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 36 36 37 37 … … 55 55 if(is_master) 56 56 { 57 ::MPI_Allreduce(local_recvbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm .mpi_comm));57 ::MPI_Allreduce(local_recvbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm)); 58 58 } 59 59 -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_alltoall.cpp
r1354 r1520 9 9 int MPI_Alltoall(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) 10 10 { 11 if(!comm .is_ep)11 if(!comm->is_ep) 12 12 { 13 return ::MPI_Alltoall(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), to_mpi_comm(comm .mpi_comm));13 return ::MPI_Alltoall(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), to_mpi_comm(comm->mpi_comm)); 14 14 } 15 15 … … 23 23 int count = sendcount; 24 24 25 int ep_rank = comm .ep_comm_ptr->size_rank_info[0].first;26 int ep_rank_loc = comm .ep_comm_ptr->size_rank_info[1].first;27 int mpi_rank = comm .ep_comm_ptr->size_rank_info[2].first;28 int ep_size = comm .ep_comm_ptr->size_rank_info[0].second;29 int num_ep = comm .ep_comm_ptr->size_rank_info[1].second;30 int mpi_size = comm .ep_comm_ptr->size_rank_info[2].second;25 int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 26 int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 27 int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 28 int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 29 int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 30 int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 31 31 32 32 void* tmp_recvbuf; -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_barrier.cpp
r1354 r1520 9 9 int MPI_Barrier(MPI_Comm comm) 10 10 { 11 if(comm .is_intercomm) return MPI_Barrier_intercomm(comm);11 if(comm->is_intercomm) return MPI_Barrier_intercomm(comm); 12 12 13 if(comm .is_ep)13 if(comm->is_ep) 14 14 { 15 int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 16 17 MPI_Barrier_local(comm); 18 19 if(ep_rank_loc == 0) 20 { 21 ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm); 22 23 ::MPI_Barrier(mpi_comm); 24 } 25 26 MPI_Barrier_local(comm); 27 28 return 0; 29 } 30 else if(comm.mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm)) 31 { 32 ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm); 33 ::MPI_Barrier(mpi_comm); 34 return 0; 15 return MPI_Barrier_intracomm(comm); 35 16 } 36 17 37 else return 0; 18 19 return MPI_Barrier_mpi(comm); 20 38 21 } 39 22 40 41 int MPI_Barrier_intercomm(MPI_Comm comm) 23 int MPI_Barrier_intracomm(MPI_Comm comm) 42 24 { 43 44 int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first; 25 int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 45 26 46 27 MPI_Barrier_local(comm); … … 48 29 if(ep_rank_loc == 0) 49 30 { 50 ::MPI_Comm mpi_comm = to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm); 31 ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm); 32 51 33 ::MPI_Barrier(mpi_comm); 52 34 } … … 55 37 56 38 return 0; 39 } 57 40 41 int MPI_Barrier_intercomm(MPI_Comm comm) 42 { 43 MPI_Barrier_local(comm); 44 45 if(comm->ep_comm_ptr->intercomm->size_rank_info[1].first == 0) 46 ::MPI_Barrier(to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm)); 47 48 MPI_Barrier_local(comm); 49 } 50 51 int MPI_Barrier_mpi(MPI_Comm comm) 52 { 53 return ::MPI_Barrier(to_mpi_comm(comm->mpi_comm)); 58 54 } 59 55 … … 61 57 int MPI_Barrier_local(MPI_Comm comm) 62 58 { 63 //Message_Check(comm); 64 comm.ep_barrier->wait(); 59 comm->ep_barrier->wait(); 65 60 } 66 61 -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_bcast.cpp
r1354 r1520 20 20 assert(valid_type(datatype)); 21 21 22 int ep_rank_loc = comm .ep_comm_ptr->size_rank_info[1].first;22 int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 23 23 24 24 ::MPI_Aint datasize, lb; … … 28 28 if(ep_rank_loc == local_root) 29 29 { 30 comm .my_buffer->void_buffer[local_root] = buffer;30 comm->my_buffer->void_buffer[local_root] = buffer; 31 31 } 32 32 … … 36 36 { 37 37 #pragma omp critical (_bcast) 38 memcpy(buffer, comm .my_buffer->void_buffer[local_root], datasize * count);38 memcpy(buffer, comm->my_buffer->void_buffer[local_root], datasize * count); 39 39 } 40 40 … … 45 45 { 46 46 47 if(!comm .is_ep)47 if(!comm->is_ep) 48 48 { 49 49 #pragma omp single nowait 50 ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root, to_mpi_comm(comm .mpi_comm));50 ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root, to_mpi_comm(comm->mpi_comm)); 51 51 return 0; 52 52 } 53 53 54 54 55 int ep_rank = comm .ep_comm_ptr->size_rank_info[0].first;56 int ep_rank_loc = comm .ep_comm_ptr->size_rank_info[1].first;57 int mpi_rank = comm .ep_comm_ptr->size_rank_info[2].first;55 int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 56 int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 57 int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 58 58 59 int root_mpi_rank = comm .rank_map->at(root).second;60 int root_ep_rank_loc = comm .rank_map->at(root).first;59 int root_mpi_rank = comm->ep_rank_map->at(root).second; 60 int root_ep_rank_loc = comm->ep_rank_map->at(root).first; 61 61 62 62 63 63 if((ep_rank_loc==0 && mpi_rank != root_mpi_rank ) || ep_rank == root) 64 64 { 65 ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root_mpi_rank, to_mpi_comm(comm .mpi_comm));65 ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 66 66 } 67 67 -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_create.cpp
r1356 r1520 25 25 \param [out] out_comm_hdls Handles of EP communicators. 26 26 */ 27 // #ifdef _intelmpi28 // int MPI_Comm_create_endpoints(int base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls)29 // {30 // int base_rank;31 // int base_size;32 33 // ::MPI_Comm mpi_base_comm = static_cast< ::MPI_Comm> (base_comm_ptr);34 35 // ::MPI_Comm_size(mpi_base_comm, &base_size); // ep_lib::mpi_comm_size36 // ::MPI_Comm_rank(mpi_base_comm, &base_rank); // ep_lib::mpi_comm_rank37 // // parent_comm can also be endpoints communicators38 39 // std::vector<int> recv_num_ep(base_size);40 41 // out_comm_hdls = new MPI_Comm[num_ep];42 43 // for (int idx = 0; idx < num_ep; ++idx)44 // {45 // out_comm_hdls[idx].is_ep = true;46 // out_comm_hdls[idx].is_intercomm = false;47 // out_comm_hdls[idx].ep_comm_ptr = new ep_communicator;48 // out_comm_hdls[idx].mpi_comm = base_comm_ptr;49 // out_comm_hdls[idx].ep_comm_ptr->comm_list = out_comm_hdls;50 // out_comm_hdls[idx].ep_comm_ptr->comm_label = 0;51 // }52 53 // ::MPI_Allgather(&num_ep, 1, static_cast< ::MPI_Datatype>(MPI_INT), &recv_num_ep[0], 1, static_cast< ::MPI_Datatype>(MPI_INT), mpi_base_comm);54 55 56 // int sum = 0; // representing total ep number of process with smaller rank57 // for (int i = 0; i < base_rank; ++i) {sum += recv_num_ep[i]; }58 59 // int ep_size = std::accumulate(recv_num_ep.begin(), recv_num_ep.end(), 0);60 61 // out_comm_hdls[0].ep_barrier = new OMPbarrier(num_ep);62 63 // out_comm_hdls[0].my_buffer = new BUFFER;64 65 // out_comm_hdls[0].rank_map = new RANK_MAP;66 // out_comm_hdls[0].rank_map->resize(ep_size);67 68 69 // for (int i = 1; i < num_ep; i++)70 // {71 // out_comm_hdls[i].ep_barrier = out_comm_hdls[0].ep_barrier;72 // out_comm_hdls[i].my_buffer = out_comm_hdls[0].my_buffer;73 // out_comm_hdls[i].rank_map = out_comm_hdls[0].rank_map;74 // }75 76 77 // for (int i = 0; i < num_ep; i++)78 // {79 // out_comm_hdls[i].ep_comm_ptr->size_rank_info[0] = std::make_pair(sum+i, ep_size);80 // out_comm_hdls[i].ep_comm_ptr->size_rank_info[1] = std::make_pair(i, num_ep);81 // out_comm_hdls[i].ep_comm_ptr->size_rank_info[2] = std::make_pair(base_rank, base_size);82 83 // out_comm_hdls[i].ep_comm_ptr->message_queue = new Message_list;84 // }85 86 87 // int ind = 0;88 89 // for(int i=0; i<base_size; i++)90 // {91 // for(int j=0; j<recv_num_ep[i]; j++)92 // {93 // out_comm_hdls[0].rank_map->at(ind) = make_pair(j, i);94 // ind++;95 // }96 // }97 98 99 100 // return 0;101 102 // } //MPI_Comm_create_endpoints103 104 // #elif _openmpi105 // int MPI_Comm_create_endpoints(void* base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls)106 // {107 108 // int base_rank;109 // int base_size;110 111 // ::MPI_Comm mpi_base_comm = static_cast< ::MPI_Comm> (base_comm_ptr);112 113 // ::MPI_Comm_size(mpi_base_comm, &base_size); // ep_lib::mpi_comm_size114 // ::MPI_Comm_rank(mpi_base_comm, &base_rank); // ep_lib::mpi_comm_rank115 // // parent_comm can also be endpoints communicators ?116 // std::vector<int> recv_num_ep(base_size);117 118 // out_comm_hdls = new MPI_Comm[num_ep];119 120 // for (int idx = 0; idx < num_ep; ++idx)121 // {122 // out_comm_hdls[idx].is_ep = true;123 // out_comm_hdls[idx].is_intercomm = false;124 // out_comm_hdls[idx].ep_comm_ptr = new ep_communicator;125 // out_comm_hdls[idx].mpi_comm = base_comm_ptr;126 // out_comm_hdls[idx].ep_comm_ptr->comm_list = out_comm_hdls;127 // out_comm_hdls[idx].ep_comm_ptr->comm_label = 0;128 // }129 130 // ::MPI_Allgather(&num_ep, 1, static_cast< ::MPI_Datatype> (MPI_INT),131 // &recv_num_ep[0], 1, static_cast< ::MPI_Datatype> (MPI_INT), mpi_base_comm);132 133 // int sum = 0; // representing total ep number of process with smaller rank134 // for (int i = 0; i < base_rank; ++i) {sum += recv_num_ep[i]; }135 136 // int ep_size = std::accumulate(recv_num_ep.begin(), recv_num_ep.end(), 0);137 138 // out_comm_hdls[0].ep_barrier = new OMPbarrier(num_ep);139 // out_comm_hdls[0].my_buffer = new BUFFER;140 141 // out_comm_hdls[0].rank_map = new RANK_MAP;142 // out_comm_hdls[0].rank_map->resize(ep_size);143 144 145 // for (int i = 1; i < num_ep; i++)146 // {147 // out_comm_hdls[i].ep_barrier = out_comm_hdls[0].ep_barrier;148 // out_comm_hdls[i].my_buffer = out_comm_hdls[0].my_buffer;149 // out_comm_hdls[i].rank_map = out_comm_hdls[0].rank_map;150 // }151 152 153 // for (int i = 0; i < num_ep; i++)154 // {155 // out_comm_hdls[i].ep_comm_ptr->size_rank_info[0] = std::make_pair(sum+i, ep_size);156 // out_comm_hdls[i].ep_comm_ptr->size_rank_info[1] = std::make_pair(i, num_ep);157 // out_comm_hdls[i].ep_comm_ptr->size_rank_info[2] = std::make_pair(base_rank, base_size);158 159 // out_comm_hdls[i].ep_comm_ptr->message_queue = new Message_list;160 // }161 162 163 // int ind = 0;164 165 // for(int i=0; i<base_size; i++)166 // {167 // for(int j=0; j<recv_num_ep[i]; j++)168 // {169 // out_comm_hdls[0].rank_map->at(ind) = make_pair(j, i);170 // ind++;171 // }172 // }173 174 // return 0;175 176 // } //MPI_Comm_create_endpoints177 178 // #endif179 180 27 181 28 int MPI_Comm_create_endpoints(void* base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls) … … 194 41 195 42 out_comm_hdls = new MPI_Comm[num_ep]; 43 #ifdef _showinfo 44 printf("new out_comm_hdls = %p\n", out_comm_hdls); 45 #endif 196 46 47 ::MPI_Comm *parent_comm = new ::MPI_Comm; 48 ::MPI_Comm_dup(to_mpi_comm(base_comm_ptr), parent_comm); 49 50 #ifdef _showinfo 51 printf("new out_comm_hdls->mpi_comm = %p\n", parent_comm); 52 #endif 53 197 54 for (int idx = 0; idx < num_ep; ++idx) 198 55 { 199 out_comm_hdls[idx].is_ep = true; 200 out_comm_hdls[idx].is_intercomm = false; 201 out_comm_hdls[idx].ep_comm_ptr = new ep_communicator; 202 *(static_cast< ::MPI_Comm*>(out_comm_hdls[idx].mpi_comm)) = *(static_cast< ::MPI_Comm*>(base_comm_ptr)); 203 out_comm_hdls[idx].ep_comm_ptr->comm_list = out_comm_hdls; 204 out_comm_hdls[idx].ep_comm_ptr->comm_label = 0; 56 57 out_comm_hdls[idx] = new ep_comm; 58 #ifdef _showinfo 59 printf("new out_comm_hdls[%d] = %p\n", idx, out_comm_hdls[idx]); 60 #endif 61 62 out_comm_hdls[idx]->is_ep = true; 63 out_comm_hdls[idx]->is_intercomm = false; 64 65 out_comm_hdls[idx]->ep_comm_ptr = new ep_communicator; 66 #ifdef _showinfo 67 printf("new out_comm_hdls[%d]->ep_comm_ptr = %p\n", idx, out_comm_hdls[idx]->ep_comm_ptr); 68 #endif 69 70 71 out_comm_hdls[idx]->mpi_comm = parent_comm; 72 out_comm_hdls[idx]->ep_comm_ptr->comm_list = out_comm_hdls; 73 out_comm_hdls[idx]->ep_comm_ptr->comm_label = 0; 205 74 } 206 75 … … 213 82 int ep_size = std::accumulate(recv_num_ep.begin(), recv_num_ep.end(), 0); 214 83 215 out_comm_hdls[0].ep_barrier = new OMPbarrier(num_ep); 216 out_comm_hdls[0].my_buffer = new BUFFER; 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 217 88 218 out_comm_hdls[0].rank_map = new RANK_MAP; 219 out_comm_hdls[0].rank_map->resize(ep_size); 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 220 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 221 98 222 99 for (int i = 1; i < num_ep; i++) 223 100 { 224 out_comm_hdls[i] .ep_barrier = out_comm_hdls[0].ep_barrier;225 out_comm_hdls[i] .my_buffer = out_comm_hdls[0].my_buffer;226 out_comm_hdls[i] .rank_map = out_comm_hdls[0].rank_map;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; 227 104 } 228 105 … … 230 107 for (int i = 0; i < num_ep; i++) 231 108 { 232 out_comm_hdls[i] .ep_comm_ptr->size_rank_info[0] = std::make_pair(sum+i, ep_size);233 out_comm_hdls[i] .ep_comm_ptr->size_rank_info[1] = std::make_pair(i, num_ep);234 out_comm_hdls[i] .ep_comm_ptr->size_rank_info[2] = std::make_pair(base_rank, base_size);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); 235 112 236 out_comm_hdls[i].ep_comm_ptr->message_queue = new Message_list; 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 237 118 } 238 119 … … 244 125 for(int j=0; j<recv_num_ep[i]; j++) 245 126 { 246 out_comm_hdls[0] .rank_map->at(ind) = make_pair(j, i);127 out_comm_hdls[0]->ep_rank_map->insert(std::pair< int, std::pair<int,int> >(ind, j, i)); 247 128 ind++; 248 129 } … … 253 134 } //MPI_Comm_create_endpoints 254 135 136 255 137 256 138 } //namespace ep_lib -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_declaration.cpp
r1482 r1520 42 42 ::MPI_Op MPI_MIN_STD = MPI_MIN; 43 43 ::MPI_Op MPI_LOR_STD = MPI_LOR; 44 ::MPI_Op MPI_REPLACE_STD = MPI_REPLACE; 44 45 45 46 #undef MPI_SUM … … 47 48 #undef MPI_MIN 48 49 #undef MPI_LOR 50 #undef MPI_REPLACE 49 51 50 52 … … 66 68 extern ::MPI_Op MPI_MIN_STD; 67 69 extern ::MPI_Op MPI_LOR_STD; 70 extern ::MPI_Op MPI_REPLACE_STD; 68 71 69 72 extern ::MPI_Comm MPI_COMM_WORLD_STD; … … 89 92 ep_lib::MPI_Op MPI_MIN = &MPI_MIN_STD; 90 93 ep_lib::MPI_Op MPI_LOR = &MPI_LOR_STD; 94 ep_lib::MPI_Op MPI_REPLACE = &MPI_REPLACE_STD; 91 95 92 ep_lib:: MPI_Comm MPI_COMM_WORLD(&MPI_COMM_WORLD_STD);93 ep_lib:: MPI_Comm MPI_COMM_NULL(&MPI_COMM_NULL_STD);96 ep_lib::ep_comm EP_COMM_WORLD(&MPI_COMM_WORLD_STD); 97 ep_lib::ep_comm EP_COMM_NULL(&MPI_COMM_NULL_STD); 94 98 95 ep_lib::MPI_Request MPI_REQUEST_NULL(&MPI_REQUEST_NULL_STD); 96 ep_lib::MPI_Info MPI_INFO_NULL(&MPI_INFO_NULL_STD); 99 ep_lib::MPI_Comm MPI_COMM_WORLD = &EP_COMM_WORLD; 100 ep_lib::MPI_Comm MPI_COMM_NULL = &EP_COMM_NULL; 101 102 //ep_lib::ep_status EP_STATUS_IGNORE(&MPI_STATUS_IGNORE_STD); 103 ep_lib::ep_request EP_REQUEST_NULL(&MPI_REQUEST_NULL_STD); 104 ep_lib::ep_info EP_INFO_NULL(&MPI_INFO_NULL_STD); 105 106 //ep_lib::MPI_Status MPI_STATUS_IGNORE = &EP_STATUS_IGNORE; 107 ep_lib::MPI_Request MPI_REQUEST_NULL = &EP_REQUEST_NULL; 108 ep_lib::MPI_Info MPI_INFO_NULL = &EP_INFO_NULL; 97 109 98 110 99 111 100 -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_declaration.hpp
r1482 r1520 16 16 #undef MPI_MIN 17 17 #undef MPI_LOR 18 #undef MPI_REPLACE 18 19 19 20 #undef MPI_COMM_WORLD … … 38 39 extern ep_lib::MPI_Op MPI_MIN; 39 40 extern ep_lib::MPI_Op MPI_LOR; 41 extern ep_lib::MPI_Op MPI_REPLACE; 40 42 41 43 extern ep_lib::MPI_Comm MPI_COMM_WORLD; -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_dup.cpp
r1468 r1520 7 7 { 8 8 9 int MPI_Comm_dup (MPI_Comm comm, MPI_Comm *newcomm)9 int MPI_Comm_dup_mpi(MPI_Comm comm, MPI_Comm *newcomm) 10 10 { 11 if(!comm.is_ep) 12 { 13 Debug("Comm_dup MPI\n"); 14 newcomm = new MPI_Comm; 15 newcomm->is_ep = comm.is_ep; 11 newcomm = new MPI_Comm; 12 (*newcomm)->is_ep = false; 16 13 17 ::MPI_Comm input = to_mpi_comm(comm.mpi_comm); 18 ::MPI_Comm *output = new ::MPI_Comm; 14 ::MPI_Comm *output = new ::MPI_Comm; 15 16 ::MPI_Comm_dup(to_mpi_comm(comm->mpi_comm), output); 19 17 20 21 ::MPI_Comm_dup(input, output);18 (*newcomm)->mpi_comm = output; 19 } 22 20 23 newcomm->mpi_comm = output; 24 25 return 0; 26 } 27 28 if(comm.is_intercomm) return MPI_Comm_dup_intercomm(comm, newcomm); 29 30 // for intracomm 31 if(comm.mpi_comm == static_cast< ::MPI_Comm* >(MPI_COMM_NULL.mpi_comm)) return 0; 21 int MPI_Comm_dup_intracomm(MPI_Comm comm, MPI_Comm *newcomm) 22 { 23 int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 24 int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 32 25 33 26 34 int my_rank = comm.ep_comm_ptr->size_rank_info[1].first; 35 int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 36 37 38 if(0 == my_rank) 27 if(0 == ep_rank_loc) 39 28 { 40 29 MPI_Info info; 41 30 MPI_Comm *out_comm; 42 ::MPI_Comm *mpi_dup = new ::MPI_Comm;43 31 44 ::MPI_Comm in_comm = to_mpi_comm(comm.mpi_comm); 45 46 ::MPI_Comm_dup(in_comm, mpi_dup); 47 48 MPI_Comm_create_endpoints(mpi_dup, num_ep, info, out_comm); 49 comm.ep_comm_ptr->comm_list->mem_bridge = out_comm; 32 MPI_Comm_create_endpoints(comm->mpi_comm, num_ep, info, out_comm); 33 comm->ep_comm_ptr->comm_list[0]->mem_bridge = out_comm; 50 34 } 51 35 52 MPI_Barrier (comm);36 MPI_Barrier_local(comm); 53 37 54 *newcomm = (comm.ep_comm_ptr->comm_list->mem_bridge[my_rank]); 38 *newcomm = (comm->ep_comm_ptr->comm_list[0]->mem_bridge[ep_rank_loc]); 39 40 } 55 41 56 return MPI_SUCCESS; 42 int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm) 43 { 44 45 if(!comm->is_ep) 46 { 47 Debug("MPI_Comm_dup with MPI\n"); 48 return MPI_Comm_dup_mpi(comm, newcomm); 49 } 50 51 if(comm->is_intercomm) return MPI_Comm_dup_intercomm(comm, newcomm); 52 53 54 return MPI_Comm_dup_intracomm(comm, newcomm); 55 56 57 57 } 58 58 … … 60 60 { 61 61 62 if(comm.mpi_comm == static_cast< ::MPI_Comm* >(MPI_COMM_NULL.mpi_comm)) return 0; 63 64 int my_rank = comm.ep_comm_ptr->size_rank_info[1].first; 65 int num_ep = comm.ep_comm_ptr->size_rank_info[1].second; 62 int newcomm_ep_rank =comm->ep_comm_ptr->intercomm->size_rank_info[0].first; 63 int newcomm_ep_rank_loc = comm->ep_comm_ptr->intercomm->size_rank_info[1].first; 64 int newcomm_num_ep = comm->ep_comm_ptr->intercomm->size_rank_info[1].second; 66 65 67 66 68 if(0 == my_rank)67 if(0 == newcomm_ep_rank_loc) 69 68 { 69 //printf("in dup , newcomm_ep_rank_loc = 0 : ep %d\n", comm->ep_comm_ptr->intercomm->size_rank_info[0].first); 70 70 71 MPI_Info info; 71 72 MPI_Comm *out_comm; 72 ::MPI_Comm *mpi_dup = new ::MPI_Comm;73 73 74 ::MPI_Comm in_comm = to_mpi_comm(comm.mpi_comm);74 MPI_Comm_create_endpoints(comm->mpi_comm, newcomm_num_ep, info, out_comm); 75 75 76 ::MPI_Comm_dup(in_comm, mpi_dup); 76 ::MPI_Comm *mpi_inter_comm = new ::MPI_Comm; 77 ::MPI_Comm_dup(to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), mpi_inter_comm); 77 78 78 MPI_Comm_create_endpoints(mpi_dup, num_ep, info, out_comm); 79 80 ::MPI_Comm *mpi_inter = new ::MPI_Comm; 81 82 ::MPI_Comm_dup(to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm), mpi_inter); 83 84 for(int i=0; i<num_ep; i++) 79 for(int i=0; i<newcomm_num_ep; i++) 85 80 { 86 out_comm[i].ep_comm_ptr->comm_label = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->comm_label; 87 out_comm[i].ep_comm_ptr->intercomm = new ep_intercomm; 88 89 out_comm[i].ep_comm_ptr->intercomm->mpi_inter_comm = mpi_inter; 90 out_comm[i].is_intercomm = true; 91 92 out_comm[i].ep_comm_ptr->intercomm->intercomm_rank_map = new RANK_MAP; 93 out_comm[i].ep_comm_ptr->intercomm->local_rank_map = new RANK_MAP; 94 out_comm[i].ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP; 95 96 int map_size = 0; 97 map_size = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_rank_map->size(); 98 out_comm[i].ep_comm_ptr->intercomm->intercomm_rank_map->resize(map_size); 99 for(int ii=0; ii<map_size; ii++) 100 out_comm[i].ep_comm_ptr->intercomm->intercomm_rank_map->at(ii) = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_rank_map->at(ii); 101 102 map_size = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_rank_map->size(); 103 out_comm[i].ep_comm_ptr->intercomm->local_rank_map->resize(map_size); 104 for(int ii=0; ii<map_size; ii++) 105 out_comm[i].ep_comm_ptr->intercomm->local_rank_map->at(ii) = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_rank_map->at(ii); 106 107 map_size = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->remote_rank_map->size(); 108 out_comm[i].ep_comm_ptr->intercomm->remote_rank_map->resize(map_size); 109 for(int ii=0; ii<map_size; ii++) 110 out_comm[i].ep_comm_ptr->intercomm->remote_rank_map->at(ii) = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->remote_rank_map->at(ii); 81 out_comm[i]->is_intercomm = true; 82 out_comm[i]->ep_comm_ptr->comm_label = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->comm_label; 83 out_comm[i]->ep_comm_ptr->intercomm = new ep_lib::ep_intercomm; 84 #ifdef _showinfo 85 printf("new out_comm[%d]->ep_comm_ptr->intercomm = %p\n", i, out_comm[i]->ep_comm_ptr->intercomm); 86 #endif 87 out_comm[i]->ep_comm_ptr->intercomm->mpi_inter_comm = mpi_inter_comm; 88 } 111 89 112 90 113 //out_comm[i].ep_comm_ptr->intercomm->intercomm_rank_map = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_rank_map; 114 //out_comm[i].ep_comm_ptr->intercomm->local_rank_map = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_rank_map; 115 //out_comm[i].ep_comm_ptr->intercomm->remote_rank_map = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->remote_rank_map; 116 117 out_comm[i].ep_comm_ptr->intercomm->local_comm = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_comm; 118 out_comm[i].ep_comm_ptr->intercomm->intercomm_tag = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_tag; 119 120 for(int j =0; j<3; j++) 121 { 122 out_comm[i].ep_comm_ptr->intercomm->size_rank_info[j] = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->size_rank_info[j]; 123 } 124 125 } 126 127 comm.ep_comm_ptr->comm_list->mem_bridge = out_comm; 91 comm->ep_comm_ptr->comm_list[0]->mem_bridge = out_comm; 128 92 } 129 93 130 MPI_Barrier (comm);94 MPI_Barrier_local(comm); 131 95 132 *newcomm = comm.ep_comm_ptr->comm_list->mem_bridge[my_rank]; 96 *newcomm = (comm->ep_comm_ptr->comm_list[0]->mem_bridge[newcomm_ep_rank_loc]); 97 98 (*newcomm)->ep_comm_ptr->size_rank_info[0] = comm->ep_comm_ptr->size_rank_info[0]; 99 (*newcomm)->ep_comm_ptr->size_rank_info[1] = comm->ep_comm_ptr->size_rank_info[1]; 100 (*newcomm)->ep_comm_ptr->size_rank_info[2] = comm->ep_comm_ptr->size_rank_info[2]; 101 102 (*newcomm)->ep_comm_ptr->intercomm->size_rank_info[0] = comm->ep_comm_ptr->intercomm->size_rank_info[0]; 103 (*newcomm)->ep_comm_ptr->intercomm->size_rank_info[1] = comm->ep_comm_ptr->intercomm->size_rank_info[1]; 104 (*newcomm)->ep_comm_ptr->intercomm->size_rank_info[2] = comm->ep_comm_ptr->intercomm->size_rank_info[2]; 105 106 (*newcomm)->ep_comm_ptr->intercomm->intercomm_tag = comm->ep_comm_ptr->intercomm->intercomm_tag; 107 108 109 int ep_rank_loc = (*newcomm)->ep_comm_ptr->size_rank_info[1].first; 110 111 if(ep_rank_loc == 0) 112 { 113 int world_rank; 114 MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); 115 116 (*newcomm)->ep_comm_ptr->intercomm->intercomm_rank_map = new INTERCOMM_RANK_MAP; 117 (*newcomm)->ep_comm_ptr->intercomm->local_rank_map = new EP_RANK_MAP; 118 119 *(*newcomm)->ep_comm_ptr->intercomm->intercomm_rank_map = *comm->ep_comm_ptr->intercomm->intercomm_rank_map; 120 *(*newcomm)->ep_comm_ptr->intercomm->local_rank_map = *comm->ep_comm_ptr->intercomm->local_rank_map; 121 } 122 123 MPI_Barrier_local(comm); 124 125 if(ep_rank_loc !=0 ) 126 { 127 int target = (*newcomm)->ep_comm_ptr->intercomm->intercomm_tag; 128 (*newcomm)->ep_comm_ptr->intercomm->intercomm_rank_map = (*newcomm)->ep_comm_ptr->comm_list[target]->ep_comm_ptr->intercomm->intercomm_rank_map; 129 (*newcomm)->ep_comm_ptr->intercomm->local_rank_map = (*newcomm)->ep_comm_ptr->comm_list[target]->ep_comm_ptr->intercomm->local_rank_map; 130 } 131 133 132 134 133 135 return MPI_SUCCESS; 134 135 136 136 137 } 137 138 -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_exscan.cpp
r1295 r1520 50 50 valid_op(op); 51 51 52 int ep_rank_loc = comm .ep_comm_ptr->size_rank_info[1].first;53 int num_ep = comm .ep_comm_ptr->size_rank_info[1].second;54 int mpi_rank = comm .ep_comm_ptr->size_rank_info[2].first;52 int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 53 int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 54 int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 55 55 56 56 … … 60 60 if(ep_rank_loc == 0 && mpi_rank != 0) 61 61 { 62 comm .my_buffer->void_buffer[0] = recvbuf;62 comm->my_buffer->void_buffer[0] = recvbuf; 63 63 } 64 64 if(ep_rank_loc == 0 && mpi_rank == 0) 65 65 { 66 comm .my_buffer->void_buffer[0] = const_cast<void*>(sendbuf);66 comm->my_buffer->void_buffer[0] = const_cast<void*>(sendbuf); 67 67 } 68 68 … … 70 70 MPI_Barrier_local(comm); 71 71 72 memcpy(recvbuf, comm .my_buffer->void_buffer[0], datasize*count);72 memcpy(recvbuf, comm->my_buffer->void_buffer[0], datasize*count); 73 73 74 74 MPI_Barrier_local(comm); 75 75 76 comm .my_buffer->void_buffer[ep_rank_loc] = const_cast<void*>(sendbuf);76 comm->my_buffer->void_buffer[ep_rank_loc] = const_cast<void*>(sendbuf); 77 77 78 78 MPI_Barrier_local(comm); … … 84 84 assert(datasize == sizeof(int)); 85 85 for(int i=0; i<ep_rank_loc; i++) 86 reduce_sum<int>(static_cast<int*>(comm .my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);86 reduce_sum<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count); 87 87 } 88 88 … … 91 91 assert(datasize == sizeof(float)); 92 92 for(int i=0; i<ep_rank_loc; i++) 93 reduce_sum<float>(static_cast<float*>(comm .my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);93 reduce_sum<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count); 94 94 } 95 95 … … 99 99 assert(datasize == sizeof(double)); 100 100 for(int i=0; i<ep_rank_loc; i++) 101 reduce_sum<double>(static_cast<double*>(comm .my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);101 reduce_sum<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 102 102 } 103 103 … … 106 106 assert(datasize == sizeof(char)); 107 107 for(int i=0; i<ep_rank_loc; i++) 108 reduce_sum<char>(static_cast<char*>(comm .my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);108 reduce_sum<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 109 109 } 110 110 … … 113 113 assert(datasize == sizeof(long)); 114 114 for(int i=0; i<ep_rank_loc; i++) 115 reduce_sum<long>(static_cast<long*>(comm .my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);115 reduce_sum<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 116 116 } 117 117 … … 120 120 assert(datasize == sizeof(unsigned long)); 121 121 for(int i=0; i<ep_rank_loc; i++) 122 reduce_sum<unsigned long>(static_cast<unsigned long*>(comm .my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);122 reduce_sum<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count); 123 123 } 124 124 … … 134 134 assert(datasize == sizeof(int)); 135 135 for(int i=0; i<ep_rank_loc; i++) 136 reduce_max<int>(static_cast<int*>(comm .my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);136 reduce_max<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count); 137 137 } 138 138 … … 141 141 assert(datasize == sizeof(float)); 142 142 for(int i=0; i<ep_rank_loc; i++) 143 reduce_max<float>(static_cast<float*>(comm .my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);143 reduce_max<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count); 144 144 } 145 145 … … 148 148 assert(datasize == sizeof(double)); 149 149 for(int i=0; i<ep_rank_loc; i++) 150 reduce_max<double>(static_cast<double*>(comm .my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);150 reduce_max<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 151 151 } 152 152 … … 155 155 assert(datasize == sizeof(char)); 156 156 for(int i=0; i<ep_rank_loc; i++) 157 reduce_max<char>(static_cast<char*>(comm .my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);157 reduce_max<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 158 158 } 159 159 … … 162 162 assert(datasize == sizeof(long)); 163 163 for(int i=0; i<ep_rank_loc; i++) 164 reduce_max<long>(static_cast<long*>(comm .my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);164 reduce_max<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 165 165 } 166 166 … … 169 169 assert(datasize == sizeof(unsigned long)); 170 170 for(int i=0; i<ep_rank_loc; i++) 171 reduce_max<unsigned long>(static_cast<unsigned long*>(comm .my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);171 reduce_max<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count); 172 172 } 173 173 … … 181 181 assert(datasize == sizeof(int)); 182 182 for(int i=0; i<ep_rank_loc; i++) 183 reduce_min<int>(static_cast<int*>(comm .my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);183 reduce_min<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count); 184 184 } 185 185 … … 188 188 assert(datasize == sizeof(float)); 189 189 for(int i=0; i<ep_rank_loc; i++) 190 reduce_min<float>(static_cast<float*>(comm .my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);190 reduce_min<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count); 191 191 } 192 192 … … 195 195 assert(datasize == sizeof(double)); 196 196 for(int i=0; i<ep_rank_loc; i++) 197 reduce_min<double>(static_cast<double*>(comm .my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);197 reduce_min<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count); 198 198 } 199 199 … … 202 202 assert(datasize == sizeof(char)); 203 203 for(int i=0; i<ep_rank_loc; i++) 204 reduce_min<char>(static_cast<char*>(comm .my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);204 reduce_min<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count); 205 205 } 206 206 … … 209 209 assert(datasize == sizeof(long)); 210 210 for(int i=0; i<ep_rank_loc; i++) 211 reduce_min<long>(static_cast<long*>(comm .my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);211 reduce_min<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count); 212 212 } 213 213 … … 216 216 assert(datasize == sizeof(unsigned long)); 217 217 for(int i=0; i<ep_rank_loc; i++) 218 reduce_min<unsigned long>(static_cast<unsigned long*>(comm .my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);218 reduce_min<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count); 219 219 } 220 220 … … 228 228 int MPI_Exscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) 229 229 { 230 if(!comm .is_ep)231 { 232 return ::MPI_Scan(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm .mpi_comm));230 if(!comm->is_ep) 231 { 232 return ::MPI_Scan(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm)); 233 233 } 234 234 235 235 valid_type(datatype); 236 236 237 int ep_rank = comm .ep_comm_ptr->size_rank_info[0].first;238 int ep_rank_loc = comm .ep_comm_ptr->size_rank_info[1].first;239 int mpi_rank = comm .ep_comm_ptr->size_rank_info[2].first;240 int ep_size = comm .ep_comm_ptr->size_rank_info[0].second;241 int num_ep = comm .ep_comm_ptr->size_rank_info[1].second;242 int mpi_size = comm .ep_comm_ptr->size_rank_info[2].second;237 int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 238 int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 239 int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 240 int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 241 int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 242 int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 243 243 244 244 ::MPI_Aint datasize, lb; … … 253 253 std::vector<int> my_map(mpi_size, 0); 254 254 255 for(int i=0; i<comm .rank_map->size(); i++) my_map[comm.rank_map->at(i).second]++;255 for(int i=0; i<comm->ep_rank_map->size(); i++) my_map[comm->ep_rank_map->at(i).second]++; 256 256 257 257 for(int i=0; i<mpi_rank; i++) my_src += my_map[i]; … … 291 291 292 292 if(ep_rank_loc == 0) 293 ::MPI_Exscan(MPI_IN_PLACE, tmp_recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm .mpi_comm));293 ::MPI_Exscan(MPI_IN_PLACE, tmp_recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm)); 294 294 295 295 // printf(" ID=%d : %d %d \n", ep_rank, static_cast<int*>(tmp_recvbuf)[0], static_cast<int*>(tmp_recvbuf)[1]); -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_finalize.cpp
r1354 r1520 22 22 int MPI_Abort(MPI_Comm comm, int errorcode) 23 23 { 24 int id = omp_get_thread_num(); 24 if(!comm->is_ep) 25 return MPI_Abort_mpi(comm, errorcode); 25 26 26 if(id == 0)27 else 27 28 { 28 ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm); 29 ::MPI_Abort(mpi_comm, errorcode); 29 if(comm->ep_comm_ptr->size_rank_info[1].first == 0) 30 { 31 ::MPI_Abort(to_mpi_comm(comm->mpi_comm), errorcode); 32 } 30 33 } 31 return 0; 34 } 35 36 int MPI_Abort_mpi(MPI_Comm comm, int errorcode) 37 { 38 return ::MPI_Abort(to_mpi_comm(comm->mpi_comm), errorcode); 32 39 } 33 40 -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_fortran.cpp
r1369 r1520 16 16 void* fint = new ::MPI_Fint; 17 17 #ifdef _intelmpi 18 *static_cast< ::MPI_Fint*>(fint) = (::MPI_Fint)(to_mpi_comm(comm .mpi_comm));18 *static_cast< ::MPI_Fint*>(fint) = (::MPI_Fint)(to_mpi_comm(comm->mpi_comm)); 19 19 #elif _openmpi 20 *static_cast< ::MPI_Fint*>(fint) = MPI_Comm_c2f(to_mpi_comm(comm .mpi_comm));20 *static_cast< ::MPI_Fint*>(fint) = MPI_Comm_c2f(to_mpi_comm(comm->mpi_comm)); 21 21 #endif 22 22 … … 29 29 { 30 30 fc_comm_map.insert(std::make_pair( std::make_pair( *static_cast< ::MPI_Fint*>(fint), omp_get_thread_num()) , comm)); 31 printf("EP_Comm_c2f : MAP %p insert: %d, %d, %p\n", &fc_comm_map, *static_cast< ::MPI_Fint*>(fint), omp_get_thread_num(), comm .ep_comm_ptr);31 printf("EP_Comm_c2f : MAP %p insert: %d, %d, %p\n", &fc_comm_map, *static_cast< ::MPI_Fint*>(fint), omp_get_thread_num(), comm->ep_comm_ptr); 32 32 } 33 33 } … … 52 52 MPI_Comm comm_ptr; 53 53 comm_ptr = it->second; 54 printf("EP_Comm_f2c : MAP %p find: %d, %d, %p\n", &fc_comm_map, it->first.first, it->first.second, comm_ptr .ep_comm_ptr);54 printf("EP_Comm_f2c : MAP %p find: %d, %d, %p\n", &fc_comm_map, it->first.first, it->first.second, comm_ptr->ep_comm_ptr); 55 55 return comm_ptr; 56 56 } … … 65 65 #endif 66 66 67 if(*base_comm != to_mpi_comm(MPI_COMM_NULL .mpi_comm))67 if(*base_comm != to_mpi_comm(MPI_COMM_NULL->mpi_comm)) 68 68 { 69 69 if(omp_get_thread_num() == 0) -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_free.cpp
r1468 r1520 9 9 int MPI_Comm_free(MPI_Comm *comm) 10 10 { 11 if(! comm->is_ep) 12 { 13 if(comm->mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm)) 14 { 15 ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm); 16 17 ::MPI_Comm_free(&mpi_comm); 18 Debug("comm is MPI, freed\n"); 19 } 20 return 0; 21 } 22 23 else if(comm->is_intercomm) 24 { 25 return MPI_Comm_free_intercomm(comm); 26 } 27 28 else 29 { 30 int ep_rank_loc, num_ep; 31 32 ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 33 num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 34 35 MPI_Barrier(*comm); 36 37 if(ep_rank_loc == 0) 38 { 39 Debug("comm is EP, mpi_comm_ptr != NULL\n"); 40 41 delete comm->my_buffer; 42 43 44 if(comm->ep_barrier != NULL) 45 { 46 comm->ep_barrier->~OMPbarrier(); 47 Debug("ep_barrier freed\n"); 48 } 49 50 51 if( ! comm->rank_map->empty() ) 52 { 53 comm->rank_map->clear(); 54 Debug("rank_map emptied\n"); 55 } 56 57 for(int i=0; i<num_ep; i++) 58 { 59 comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->message_queue->clear(); 60 Debug("message queue freed\n"); 61 62 63 if(comm->ep_comm_ptr->comm_list[i].ep_comm_ptr != NULL) 64 { 65 delete comm->ep_comm_ptr->comm_list[i].ep_comm_ptr; 66 Debug("ep_comm_ptr freed\n"); 67 } 68 } 69 70 if( to_mpi_comm(comm->mpi_comm) != *static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm) 71 && to_mpi_comm(comm->mpi_comm) != *static_cast< ::MPI_Comm*>(MPI_COMM_WORLD.mpi_comm)) 72 { 73 ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm); 74 ::MPI_Comm_free(&mpi_comm); 75 Debug("mpi_comm freed\n"); 76 } 77 78 if(comm != NULL) {delete[] comm->ep_comm_ptr->comm_list; Debug("comm freed\n");} 79 80 } 81 82 return 0; 83 } 84 85 86 87 } 88 89 int MPI_Comm_free_intercomm(MPI_Comm *comm) 90 { 11 if(! (*comm)->is_ep) 12 { 13 return MPI_Comm_free_mpi(comm); 14 } 15 16 else 17 { 18 if((*comm)->is_intercomm) 19 return MPI_Comm_free_intercomm(comm); 20 else 21 return MPI_Comm_free_intracomm(comm); 22 } 23 } 24 25 26 27 int MPI_Comm_free_mpi(MPI_Comm *comm) 28 { 29 Debug("MPI_Comm_free with MPI\n"); 30 31 return ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm)); 32 33 } 34 35 int MPI_Comm_free_intracomm(MPI_Comm *comm) 36 { 37 Debug("MPI_Comm_free with EP_intracomm\n"); 38 91 39 int ep_rank_loc, num_ep; 92 40 93 ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;94 num_ep = comm->ep_comm_ptr->size_rank_info[1].second;95 96 //MPI_Barrier(*comm);41 ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first; 42 num_ep = (*comm)->ep_comm_ptr->size_rank_info[1].second; 43 44 MPI_Barrier(*comm); 97 45 98 46 if(ep_rank_loc == 0) 99 47 { 100 Debug("comm is EP, mpi_comm_ptr != NULL\n"); 101 102 103 if(comm->ep_barrier != NULL) 104 { 105 comm->ep_barrier->~OMPbarrier(); 106 Debug("ep_barrier freed\n"); 107 } 108 109 110 if( ! comm->rank_map->empty() ) 111 { 112 comm->rank_map->clear(); 113 Debug("rank_map emptied\n"); 114 } 48 49 #ifdef _showinfo 50 printf("delete (*comm)->my_buffer = %p\n", (*comm)->my_buffer); 51 #endif 52 delete (*comm)->my_buffer; 53 54 55 56 #ifdef _showinfo 57 printf("delete (*comm)->ep_barrier = %p\n", (*comm)->ep_barrier); 58 #endif 59 delete (*comm)->ep_barrier; 60 61 62 63 (*comm)->ep_rank_map->clear(); 64 #ifdef _showinfo 65 printf("delete (*comm)->ep_rank_map = %p\n", (*comm)->ep_rank_map); 66 #endif 67 delete (*comm)->ep_rank_map; 68 115 69 116 70 for(int i=0; i<num_ep; i++) 117 71 { 118 comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->message_queue->clear();119 Debug("message queue freed\n"); 120 121 #pragma omp critical (memory_free) 122 if(comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm != NULL)123 {124 comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_rank_map->clear(); 125 comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->remote_rank_map->clear(); 126 comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_rank_map->clear();127 Debug("intercomm local/remote/intercomm_rank_map emptied\n"); 128 }129 130 if(comm->ep_comm_ptr->comm_list[i].ep_comm_ptr != NULL) 131 { 132 delete comm->ep_comm_ptr->comm_list[i].ep_comm_ptr;133 Debug("ep_comm_ptr freed\n"); 134 }72 (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue->clear(); 73 #ifdef _showinfo 74 printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr->message_queue = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue); 75 #endif 76 delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue; 77 78 79 #ifdef _showinfo 80 printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr); 81 #endif 82 delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr; 83 84 85 #ifdef _showinfo 86 printf("delete (*comm)->ep_comm_ptr->comm_list[%d] = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]); 87 #endif 88 delete (*comm)->ep_comm_ptr->comm_list[i]; 135 89 } 136 90 137 if(comm->mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm)) 91 #ifdef _showinfo 92 printf("delete (*comm)->mpi_comm = %p\n", (*comm)->mpi_comm); 93 #endif 94 ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm)); 95 96 #ifdef _showinfo 97 printf("delete (*comm)->ep_comm_ptr->comm_list = %p\n", (*comm)->ep_comm_ptr->comm_list); 98 #endif 99 delete[] (*comm)->ep_comm_ptr->comm_list; 100 } 101 } 102 103 104 105 106 107 108 109 int MPI_Comm_free_intercomm(MPI_Comm *comm) 110 { 111 int ep_rank; 112 MPI_Comm_rank(*comm, &ep_rank); 113 int ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first; 114 int num_ep = (*comm)->ep_comm_ptr->size_rank_info[1].second; 115 116 int newcomm_ep_rank =(*comm)->ep_comm_ptr->intercomm->size_rank_info[0].first; 117 int newcomm_ep_rank_loc = (*comm)->ep_comm_ptr->intercomm->size_rank_info[1].first; 118 int newcomm_num_ep = (*comm)->ep_comm_ptr->intercomm->size_rank_info[1].second; 119 120 MPI_Barrier(*comm); 121 122 if(ep_rank_loc == 0) 123 { 124 (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map->clear(); 125 #ifdef _showinfo 126 printf("delete (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map = %p\n", (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map); 127 #endif 128 delete (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map; 129 130 (*comm)->ep_comm_ptr->intercomm->local_rank_map->clear(); 131 #ifdef _showinfo 132 printf("delete (*comm)->ep_comm_ptr->intercomm->local_rank_map = %p\n", (*comm)->ep_comm_ptr->intercomm->local_rank_map); 133 #endif 134 delete (*comm)->ep_comm_ptr->intercomm->local_rank_map; 135 } 136 137 if(newcomm_ep_rank_loc == 0) 138 { 139 140 #ifdef _showinfo 141 printf("delete (*comm)->my_buffer = %p\n", (*comm)->my_buffer); 142 #endif 143 delete (*comm)->my_buffer; 144 145 146 147 #ifdef _showinfo 148 printf("delete (*comm)->ep_barrier = %p\n", (*comm)->ep_barrier); 149 #endif 150 delete (*comm)->ep_barrier; 151 152 153 (*comm)->ep_rank_map->clear(); 154 #ifdef _showinfo 155 printf("delete (*comm)->ep_rank_map = %p\n", (*comm)->ep_rank_map); 156 #endif 157 delete (*comm)->ep_rank_map; 158 159 #ifdef _showinfo 160 printf("delete (*comm)->ep_comm_ptr->intercomm->mpi_inter_comm = %p\n", (*comm)->ep_comm_ptr->intercomm->mpi_inter_comm); 161 #endif 162 ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->ep_comm_ptr->intercomm->mpi_inter_comm)); 163 164 for(int i=0; i<newcomm_num_ep; i++) 138 165 { 139 ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm); 140 ::MPI_Comm_free(&mpi_comm); 141 Debug("mpi_comm freed\n"); 166 (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue->clear(); 167 #ifdef _showinfo 168 printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr->message_queue = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue); 169 #endif 170 delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue; 171 172 #ifdef _showinfo 173 printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr->intercomm = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm); 174 #endif 175 delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm; 176 177 178 #ifdef _showinfo 179 printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr); 180 #endif 181 delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr; 182 183 184 #ifdef _showinfo 185 printf("delete (*comm)->ep_comm_ptr->comm_list[%d] = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]); 186 #endif 187 delete (*comm)->ep_comm_ptr->comm_list[i]; 188 142 189 } 143 190 144 if(comm->ep_comm_ptr->intercomm->mpi_inter_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm)) 145 { 146 ::MPI_Comm mpi_comm = to_mpi_comm(comm->ep_comm_ptr->comm_list->ep_comm_ptr->intercomm->mpi_inter_comm); 147 ::MPI_Comm_free(&mpi_comm); 148 Debug("mpi_intercomm freed\n"); 149 } 150 151 if(comm != NULL) {delete[] comm->ep_comm_ptr->comm_list; Debug("comm freed\n");} 152 153 } 154 155 156 157 return 0; 158 } 159 191 #ifdef _showinfo 192 printf("delete (*comm)->mpi_comm = %p\n", (*comm)->mpi_comm); 193 #endif 194 ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm)); 195 196 #ifdef _showinfo 197 printf("delete (*comm)->ep_comm_ptr->comm_list = %p\n", (*comm)->ep_comm_ptr->comm_list); 198 #endif 199 delete[] (*comm)->ep_comm_ptr->comm_list; 200 } 201 } 160 202 161 203 -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_gather.cpp
r1365 r1520 23 23 ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize); 24 24 25 int ep_rank_loc = comm .ep_comm_ptr->size_rank_info[1].first;26 int num_ep = comm .ep_comm_ptr->size_rank_info[1].second;25 int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 26 int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 27 27 28 28 #pragma omp critical (_gather) 29 comm .my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf);29 comm->my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf); 30 30 31 31 MPI_Barrier_local(comm); … … 34 34 { 35 35 for(int i=0; i<num_ep; i++) 36 memcpy(recvbuf + datasize * i * count, comm .my_buffer->void_buffer[i], datasize * count);36 memcpy(recvbuf + datasize * i * count, comm->my_buffer->void_buffer[i], datasize * count); 37 37 38 38 //printf("local_recvbuf = %d %d \n", static_cast<int*>(recvbuf)[0], static_cast<int*>(recvbuf)[1] ); … … 44 44 int MPI_Gather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) 45 45 { 46 if(!comm .is_ep)46 if(!comm->is_ep) 47 47 { 48 48 return ::MPI_Gather(const_cast<void*>(sendbuf), sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), 49 root, to_mpi_comm(comm .mpi_comm));49 root, to_mpi_comm(comm->mpi_comm)); 50 50 } 51 51 52 52 assert(sendcount == recvcount && sendtype == recvtype); 53 53 54 int ep_rank = comm .ep_comm_ptr->size_rank_info[0].first;55 int ep_rank_loc = comm .ep_comm_ptr->size_rank_info[1].first;56 int mpi_rank = comm .ep_comm_ptr->size_rank_info[2].first;57 int ep_size = comm .ep_comm_ptr->size_rank_info[0].second;58 int num_ep = comm .ep_comm_ptr->size_rank_info[1].second;59 int mpi_size = comm .ep_comm_ptr->size_rank_info[2].second;54 int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 55 int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 56 int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 57 int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 58 int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 59 int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 60 60 61 int root_mpi_rank = comm .rank_map->at(root).second;62 int root_ep_loc = comm .rank_map->at(root).first;61 int root_mpi_rank = comm->ep_rank_map->at(root).second; 62 int root_ep_loc = comm->ep_rank_map->at(root).first; 63 63 64 64 ::MPI_Aint datasize, lb; … … 90 90 for(int i=0; i<ep_size; i++) 91 91 { 92 recvcounts[comm .rank_map->at(i).second]+=sendcount;92 recvcounts[comm->ep_rank_map->at(i).second]+=sendcount; 93 93 } 94 94 … … 96 96 displs[i] = displs[i-1] + recvcounts[i-1]; 97 97 98 ::MPI_Gatherv(local_recvbuf, sendcount*num_ep, to_mpi_type(sendtype), tmp_recvbuf, recvcounts.data(), displs.data(), to_mpi_type(recvtype), root_mpi_rank, to_mpi_comm(comm .mpi_comm));98 ::MPI_Gatherv(local_recvbuf, sendcount*num_ep, to_mpi_type(sendtype), tmp_recvbuf, recvcounts.data(), displs.data(), to_mpi_type(recvtype), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 99 99 } 100 100 … … 111 111 for(int i=0; i<ep_size; i++) 112 112 { 113 offset = displs[comm .rank_map->at(i).second] + comm.rank_map->at(i).first * sendcount;113 offset = displs[comm->ep_rank_map->at(i).second] + comm->ep_rank_map->at(i).first * sendcount; 114 114 memcpy(recvbuf + i*sendcount*datasize, tmp_recvbuf+offset*datasize, sendcount*datasize); 115 115 -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_gatherv.cpp
r1365 r1520 23 23 ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize); 24 24 25 int ep_rank_loc = comm .ep_comm_ptr->size_rank_info[1].first;26 int num_ep = comm .ep_comm_ptr->size_rank_info[1].second;25 int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 26 int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 27 27 28 28 29 29 #pragma omp critical (_gatherv) 30 comm .my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf);30 comm->my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf); 31 31 32 32 MPI_Barrier_local(comm); … … 35 35 { 36 36 for(int i=0; i<num_ep; i++) 37 memcpy(recvbuf + datasize*displs[i], comm .my_buffer->void_buffer[i], datasize*recvcounts[i]);37 memcpy(recvbuf + datasize*displs[i], comm->my_buffer->void_buffer[i], datasize*recvcounts[i]); 38 38 39 39 } … … 46 46 { 47 47 48 if(!comm .is_ep)48 if(!comm->is_ep) 49 49 { 50 50 return ::MPI_Gatherv(const_cast<void*>(sendbuf), sendcount, to_mpi_type(sendtype), recvbuf, const_cast<int*>(input_recvcounts), const_cast<int*>(input_displs), 51 to_mpi_type(recvtype), root, to_mpi_comm(comm .mpi_comm));51 to_mpi_type(recvtype), root, to_mpi_comm(comm->mpi_comm)); 52 52 } 53 53 … … 56 56 57 57 58 int ep_rank = comm .ep_comm_ptr->size_rank_info[0].first;59 int ep_rank_loc = comm .ep_comm_ptr->size_rank_info[1].first;60 int mpi_rank = comm .ep_comm_ptr->size_rank_info[2].first;61 int ep_size = comm .ep_comm_ptr->size_rank_info[0].second;62 int num_ep = comm .ep_comm_ptr->size_rank_info[1].second;63 int mpi_size = comm .ep_comm_ptr->size_rank_info[2].second;58 int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first; 59 int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 60 int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 61 int ep_size = comm->ep_comm_ptr->size_rank_info[0].second; 62 int num_ep = comm->ep_comm_ptr->size_rank_info[1].second; 63 int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second; 64 64 65 int root_mpi_rank = comm .rank_map->at(root).second;66 int root_ep_loc = comm .rank_map->at(root).first;65 int root_mpi_rank = comm->ep_rank_map->at(root).second; 66 int root_ep_loc = comm->ep_rank_map->at(root).first; 67 67 68 68 ::MPI_Aint datasize, lb; … … 126 126 for(int i=0; i<ep_size; i++) 127 127 { 128 mpi_recvcounts[comm .rank_map->at(i).second]+=recvcounts[i];128 mpi_recvcounts[comm->ep_rank_map->at(i).second]+=recvcounts[i]; 129 129 } 130 130 … … 133 133 134 134 135 ::MPI_Gatherv(local_recvbuf, sendcount*num_ep, to_mpi_type(sendtype), tmp_recvbuf, mpi_recvcounts.data(), mpi_displs.data(), to_mpi_type(recvtype), root_mpi_rank, to_mpi_comm(comm .mpi_comm));135 ::MPI_Gatherv(local_recvbuf, sendcount*num_ep, to_mpi_type(sendtype), tmp_recvbuf, mpi_recvcounts.data(), mpi_displs.data(), to_mpi_type(recvtype), root_mpi_rank, to_mpi_comm(comm->mpi_comm)); 136 136 } 137 137 … … 144 144 { 145 145 int extra = 0; 146 for(int j=0, k=0; j<ep_size, k<comm .rank_map->at(i).first; j++)147 if(comm .rank_map->at(i).second == comm.rank_map->at(j).second)146 for(int j=0, k=0; j<ep_size, k<comm->ep_rank_map->at(i).first; j++) 147 if(comm->ep_rank_map->at(i).second == comm->ep_rank_map->at(j).second) 148 148 { 149 149 extra += recvcounts[j]; … … 151 151 } 152 152 153 offset = mpi_displs[comm .rank_map->at(i).second] + extra;153 offset = mpi_displs[comm->ep_rank_map->at(i).second] + extra; 154 154 155 155 memcpy(recvbuf+displs[i]*datasize, tmp_recvbuf+offset*datasize, recvcounts[i]*datasize); -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_init.cpp
r1134 r1520 11 11 int MPI_Init_thread(int *argc, char*** argv, int required, int*provided) 12 12 { 13 //printf("MPI_Init_thread\n");13 Debug("MPI_Init_thread with EP/MPI\n"); 14 14 15 int id = omp_get_thread_num(); 16 17 if(id == 0) 15 if(omp_get_thread_num() == 0) 18 16 { 19 17 ::MPI_Init_thread(argc, argv, required, provided); 20 18 } 21 return 0;22 19 } 23 20 24 21 int MPI_Init(int *argc, char ***argv) 25 22 { 26 //printf("MPI_init called\n"); 27 int id = omp_get_thread_num(); 23 Debug("MPI_Init with EP/MPI\n"); 28 24 29 if( id== 0)25 if(omp_get_thread_num() == 0) 30 26 { 31 27 ::MPI_Init(argc, argv); 32 28 } 33 return 0;34 29 } 35 30 36 31 int MPI_Initialized(int *flag) 37 32 { 38 //printf("MPI_initialized called\n");33 Debug("MPI_Initialized with EP/MPI\n"); 39 34 40 ::MPI_Initialized(flag); 41 42 return 0; 35 return ::MPI_Initialized(flag); 43 36 } 44 37 -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm.cpp
r1354 r1520 10 10 int MPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm) 11 11 { 12 assert(local_comm .is_ep);12 assert(local_comm->is_ep); 13 13 14 14 int ep_rank, ep_rank_loc, mpi_rank; 15 15 int ep_size, num_ep, mpi_size; 16 16 17 ep_rank = local_comm .ep_comm_ptr->size_rank_info[0].first;18 ep_rank_loc = local_comm .ep_comm_ptr->size_rank_info[1].first;19 mpi_rank = local_comm .ep_comm_ptr->size_rank_info[2].first;20 ep_size = local_comm .ep_comm_ptr->size_rank_info[0].second;21 num_ep = local_comm .ep_comm_ptr->size_rank_info[1].second;22 mpi_size = local_comm .ep_comm_ptr->size_rank_info[2].second;17 ep_rank = local_comm->ep_comm_ptr->size_rank_info[0].first; 18 ep_rank_loc = local_comm->ep_comm_ptr->size_rank_info[1].first; 19 mpi_rank = local_comm->ep_comm_ptr->size_rank_info[2].first; 20 ep_size = local_comm->ep_comm_ptr->size_rank_info[0].second; 21 num_ep = local_comm->ep_comm_ptr->size_rank_info[1].second; 22 mpi_size = local_comm->ep_comm_ptr->size_rank_info[2].second; 23 23 24 24 25 25 MPI_Barrier(local_comm); 26 27 int leader_ranks_in_peer[3]; // local_leader_rank_in_peer 28 // remote_leader_rank_in_peer 29 // size of peer 30 31 if(ep_rank == local_leader) 32 { 33 MPI_Comm_rank(peer_comm, &leader_ranks_in_peer[0]); 34 leader_ranks_in_peer[1] = remote_leader; 35 MPI_Comm_size(peer_comm, &leader_ranks_in_peer[2]); 36 } 37 38 MPI_Bcast(leader_ranks_in_peer, 3, MPI_INT, local_leader, local_comm); 39 40 if(leader_ranks_in_peer[0] != leader_ranks_in_peer[2]) 41 { 42 Debug("calling MPI_Intercomm_create_kernel\n"); 43 return MPI_Intercomm_create_kernel(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm); 44 } 45 46 else 47 { 48 if(leader_ranks_in_peer[2] == 1) 49 { 50 Debug("calling MPI_Intercomm_create_unique\n"); 51 return MPI_Intercomm_create_unique_leader(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm); 52 53 } 54 else 55 { 56 Debug("calling MPI_Intercomm_create_world\n"); 57 return MPI_Intercomm_create_from_world(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm); 58 } 59 60 } 61 62 26 63 27 64 … … 61 98 if( leader_ranks[1] * leader_ranks[4] == 1) 62 99 { 63 if(ep_rank == local_leader) Debug("calling MPI_Intercomm_create_unique_leader\n");64 local_comm .ep_comm_ptr->comm_label = -99;100 if(ep_rank == local_leader) printf("calling MPI_Intercomm_create_unique_leader\n"); 101 local_comm->ep_comm_ptr->comm_label = -99; 65 102 66 103 return MPI_Intercomm_create_unique_leader(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm); … … 77 114 // change leader 78 115 is_decider = true; 79 int target = local_comm .rank_map->at(local_leader).second;116 int target = local_comm->ep_rank_map->at(local_leader).second; 80 117 { 81 118 for(int i=0; i<ep_size; i++) 82 119 { 83 if(local_comm .rank_map->at(i).second != target && local_comm.rank_map->at(i).first == 0)120 if(local_comm->ep_rank_map->at(i).second != target && local_comm->ep_rank_map->at(i).first == 0) 84 121 { 85 122 new_local_leader = i; … … 100 137 // change leader 101 138 is_decider = true; 102 int target = local_comm .rank_map->at(local_leader).second;139 int target = local_comm->ep_rank_map->at(local_leader).second; 103 140 { 104 141 for(int i=0; i<ep_size; i++) 105 142 { 106 if(local_comm .rank_map->at(i).second != target && local_comm.rank_map->at(i).first == 0)143 if(local_comm->ep_rank_map->at(i).second != target && local_comm->ep_rank_map->at(i).first == 0) 107 144 { 108 145 new_local_leader = i; … … 146 183 if(ep_rank == new_local_leader) 147 184 { 148 ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD .mpi_comm), &leader_in_world[0]);185 ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &leader_in_world[0]); 149 186 } 150 187 … … 165 202 MPI_Bcast(&leader_in_world[1], 1, MPI_INT, local_leader, local_comm); 166 203 167 local_comm .ep_comm_ptr->comm_label = tag;168 169 if(ep_rank == local_leader) Debug("calling MPI_Intercomm_create_from_world\n");170 171 return MPI_Intercomm_create_from_world(local_comm, new_local_leader, MPI_COMM_WORLD .mpi_comm, leader_in_world[1], new_tag_in_world, newintercomm);204 local_comm->ep_comm_ptr->comm_label = tag; 205 206 if(ep_rank == local_leader) printf("calling MPI_Intercomm_create_from_world\n"); 207 208 return MPI_Intercomm_create_from_world(local_comm, new_local_leader, MPI_COMM_WORLD->mpi_comm, leader_in_world[1], new_tag_in_world, newintercomm); 172 209 173 210 } 174 211 } 175 212 176 if(ep_rank == local_leader) Debug("calling MPI_Intercomm_create_kernel\n"); 177 178 return MPI_Intercomm_create_kernel(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm); 213 179 214 180 215 } … … 183 218 { 184 219 *flag = false; 185 if(comm .is_ep)186 { 187 *flag = comm .is_intercomm;220 if(comm->is_ep) 221 { 222 *flag = comm->is_intercomm; 188 223 return 0; 189 224 } 190 else if(comm .mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm))191 { 192 ::MPI_Comm mpi_comm = to_mpi_comm(comm .mpi_comm);225 else if(comm->mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL->mpi_comm)) 226 { 227 ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm); 193 228 194 229 ::MPI_Comm_test_inter(mpi_comm, flag); -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm_kernel.cpp
r1368 r1520 14 14 int ep_size, num_ep, mpi_size; 15 15 16 ep_rank = local_comm.ep_comm_ptr->size_rank_info[0].first; 17 ep_rank_loc = local_comm.ep_comm_ptr->size_rank_info[1].first; 18 mpi_rank = local_comm.ep_comm_ptr->size_rank_info[2].first; 19 ep_size = local_comm.ep_comm_ptr->size_rank_info[0].second; 20 num_ep = local_comm.ep_comm_ptr->size_rank_info[1].second; 21 mpi_size = local_comm.ep_comm_ptr->size_rank_info[2].second; 22 23 std::vector<int> rank_info[4]; //! 0->rank_in_world of local_comm, 1->rank_in_local_parent of local_comm 24 //! 2->rank_in_world of remote_comm, 3->rank_in_local_parent of remote_comm 16 ep_rank = local_comm->ep_comm_ptr->size_rank_info[0].first; 17 ep_rank_loc = local_comm->ep_comm_ptr->size_rank_info[1].first; 18 mpi_rank = local_comm->ep_comm_ptr->size_rank_info[2].first; 19 ep_size = local_comm->ep_comm_ptr->size_rank_info[0].second; 20 num_ep = local_comm->ep_comm_ptr->size_rank_info[1].second; 21 mpi_size = local_comm->ep_comm_ptr->size_rank_info[2].second; 22 23 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 24 // step 1 : local leaders exchange ep_size, leader_rank_in_peer, leader_rank_in_peer_mpi, leader_rank_in_world. // 25 // local leaders bcast results to all ep in local_comm // 26 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 27 28 bool is_local_leader = ep_rank==local_leader? true: false; 29 30 31 32 int local_leader_rank_in_peer; 33 int local_leader_rank_in_peer_mpi; 34 int local_leader_rank_in_world; 35 36 int remote_ep_size; 37 int remote_leader_rank_in_peer; 38 int remote_leader_rank_in_peer_mpi; 39 int remote_leader_rank_in_world; 40 41 int send_quadruple[4]; 42 int recv_quadruple[4]; 43 44 45 if(is_local_leader) 46 { 47 MPI_Comm_rank(peer_comm, &local_leader_rank_in_peer); 48 ::MPI_Comm_rank(to_mpi_comm(peer_comm->mpi_comm), &local_leader_rank_in_peer_mpi); 49 ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &local_leader_rank_in_world); 50 51 send_quadruple[0] = ep_size; 52 send_quadruple[1] = local_leader_rank_in_peer; 53 send_quadruple[2] = local_leader_rank_in_peer_mpi; 54 send_quadruple[3] = local_leader_rank_in_world; 55 56 MPI_Request request; 57 MPI_Status status; 58 59 60 if(remote_leader > local_leader_rank_in_peer) 61 { 62 MPI_Isend(send_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request); 63 MPI_Wait(&request, &status); 64 65 MPI_Irecv(recv_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request); 66 MPI_Wait(&request, &status); 67 } 68 else 69 { 70 MPI_Irecv(recv_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request); 71 MPI_Wait(&request, &status); 72 73 MPI_Isend(send_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request); 74 MPI_Wait(&request, &status); 75 } 76 77 remote_ep_size = recv_quadruple[0]; 78 remote_leader_rank_in_peer = recv_quadruple[1]; 79 remote_leader_rank_in_peer_mpi = recv_quadruple[2]; 80 remote_leader_rank_in_world = recv_quadruple[3]; 81 #ifdef _showinfo 82 printf("peer_rank = %d, packed exchange OK\n", local_leader_rank_in_peer); 83 #endif 84 } 85 86 MPI_Bcast(send_quadruple, 4, MPI_INT, local_leader, local_comm); 87 MPI_Bcast(recv_quadruple, 4, MPI_INT, local_leader, local_comm); 88 89 if(!is_local_leader) 90 { 91 local_leader_rank_in_peer = send_quadruple[1]; 92 local_leader_rank_in_peer_mpi = send_quadruple[2]; 93 local_leader_rank_in_world = send_quadruple[3]; 94 95 remote_ep_size = recv_quadruple[0]; 96 remote_leader_rank_in_peer = recv_quadruple[1]; 97 remote_leader_rank_in_peer_mpi = recv_quadruple[2]; 98 remote_leader_rank_in_world = recv_quadruple[3]; 99 } 100 101 102 #ifdef _showinfo 103 MPI_Barrier(peer_comm); 104 MPI_Barrier(peer_comm); 105 printf("peer_rank = %d, ep_size = %d, remote_ep_size = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, ep_size, remote_ep_size); 106 MPI_Barrier(peer_comm); 107 MPI_Barrier(peer_comm); 108 #endif 109 110 /////////////////////////////////////////////////////////////////// 111 // step 2 : gather ranks in world for both local and remote comm // 112 /////////////////////////////////////////////////////////////////// 25 113 26 114 int rank_in_world; 27 int rank_in_local_parent; 28 29 int rank_in_peer_mpi[2]; 30 31 int local_ep_size = ep_size; 32 int remote_ep_size; 33 34 35 ::MPI_Comm local_mpi_comm = to_mpi_comm(local_comm.mpi_comm); 36 37 38 ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD.mpi_comm), &rank_in_world); 39 ::MPI_Comm_rank(local_mpi_comm, &rank_in_local_parent); 40 41 42 bool is_proc_master = false; 43 bool is_local_leader = false; 44 bool is_final_master = false; 45 46 47 if(ep_rank == local_leader) { is_proc_master = true; is_local_leader = true; is_final_master = true;} 48 if(ep_rank_loc == 0 && mpi_rank != local_comm.rank_map->at(local_leader).second) is_proc_master = true; 49 50 51 int size_info[4]; //! used for choose size of rank_info 0-> mpi_size of local_comm, 1-> mpi_size of remote_comm 52 53 int leader_info[4]; //! 0->world rank of local_leader, 1->world rank of remote leader 54 55 56 std::vector<int> ep_info[2]; //! 0-> num_ep in local_comm, 1->num_ep in remote_comm 57 58 std::vector<int> new_rank_info[4]; 59 std::vector<int> new_ep_info[2]; 60 61 std::vector<int> offset; 62 63 if(is_proc_master) 64 { 65 66 size_info[0] = mpi_size; 67 68 rank_info[0].resize(size_info[0]); 69 rank_info[1].resize(size_info[0]); 70 71 72 73 ep_info[0].resize(size_info[0]); 74 75 vector<int> send_buf(6); 76 vector<int> recv_buf(3*size_info[0]); 77 78 send_buf[0] = rank_in_world; 79 send_buf[1] = rank_in_local_parent; 80 send_buf[2] = num_ep; 81 82 ::MPI_Allgather(send_buf.data(), 3, to_mpi_type(MPI_INT), recv_buf.data(), 3, to_mpi_type(MPI_INT), local_mpi_comm); 83 84 for(int i=0; i<size_info[0]; i++) 85 { 86 rank_info[0][i] = recv_buf[3*i]; 87 rank_info[1][i] = recv_buf[3*i+1]; 88 ep_info[0][i] = recv_buf[3*i+2]; 89 } 115 ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &rank_in_world); 116 117 int *ranks_in_world_local = new int[ep_size]; 118 int *ranks_in_world_remote = new int[remote_ep_size]; 119 120 MPI_Allgather(&rank_in_world, 1, MPI_INT, ranks_in_world_local, 1, MPI_INT, local_comm); 121 122 if(is_local_leader) 123 { 124 MPI_Request request; 125 MPI_Status status; 126 127 if(remote_leader > local_leader_rank_in_peer) 128 { 129 MPI_Isend(ranks_in_world_local, ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 130 MPI_Wait(&request, &status); 131 132 MPI_Irecv(ranks_in_world_remote, remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 133 MPI_Wait(&request, &status); 134 } 135 else 136 { 137 MPI_Irecv(ranks_in_world_remote, remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 138 MPI_Wait(&request, &status); 139 140 MPI_Isend(ranks_in_world_local, ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 141 MPI_Wait(&request, &status); 142 } 143 #ifdef _showinfo 144 printf("peer_rank = %d, ranks_in_world exchange OK\n", local_leader_rank_in_peer); 145 #endif 146 } 147 148 MPI_Bcast(ranks_in_world_remote, remote_ep_size, MPI_INT, local_leader, local_comm); 149 150 #ifdef _showinfo 151 152 MPI_Barrier(peer_comm); 153 MPI_Barrier(peer_comm); 154 155 if(remote_leader == 4) 156 { 157 for(int i=0; i<ep_size; i++) 158 { 159 if(ep_rank == i) 160 { 161 printf("peer_rank = %d, ranks_in_world_local = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first); 162 for(int i=0; i<ep_size; i++) 163 { 164 printf("%d\t", ranks_in_world_local[i]); 165 } 166 167 printf("\npeer_rank = %d, ranks_in_world_remote = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first); 168 for(int i=0; i<remote_ep_size; i++) 169 { 170 printf("%d\t", ranks_in_world_remote[i]); 171 } 172 printf("\n"); 173 174 } 175 176 MPI_Barrier(local_comm); 177 MPI_Barrier(local_comm); 178 MPI_Barrier(local_comm); 179 } 180 } 181 182 MPI_Barrier(peer_comm); 183 MPI_Barrier(peer_comm); 184 MPI_Barrier(peer_comm); 185 186 if(remote_leader == 13) 187 { 188 for(int i=0; i<ep_size; i++) 189 { 190 if(ep_rank == i) 191 { 192 printf("peer_rank = %d, ranks_in_world_local = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first); 193 for(int i=0; i<ep_size; i++) 194 { 195 printf("%d\t", ranks_in_world_local[i]); 196 } 197 198 printf("\npeer_rank = %d, ranks_in_world_remote = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first); 199 for(int i=0; i<remote_ep_size; i++) 200 { 201 printf("%d\t", ranks_in_world_remote[i]); 202 } 203 printf("\n"); 204 205 } 206 207 MPI_Barrier(local_comm); 208 MPI_Barrier(local_comm); 209 MPI_Barrier(local_comm); 210 } 211 } 212 213 MPI_Barrier(peer_comm); 214 MPI_Barrier(peer_comm); 215 216 #endif 217 218 ////////////////////////////////////////////////////////////// 219 // step 3 : determine the priority and ownership of each ep // 220 ////////////////////////////////////////////////////////////// 221 222 bool priority = local_leader_rank_in_peer > remote_leader_rank_in_peer? true : false; 223 224 225 int ownership; 226 227 if(rank_in_world == ranks_in_world_local[local_leader]) ownership = 1; 228 else if(rank_in_world == remote_leader_rank_in_world) ownership = 0; 229 else 230 { 231 ownership = 1; 232 for(int i=0; i<remote_ep_size; i++) 233 { 234 if(rank_in_world == ranks_in_world_remote[i]) 235 { 236 ownership = priority? 1 : 0; 237 break; 238 } 239 } 240 } 241 242 #ifdef _showinfo 243 MPI_Barrier(peer_comm); 244 MPI_Barrier(peer_comm); 245 printf("peer_rank = %d, priority = %d, local_leader_rank_in_peer = %d, remote_leader_rank_in_peer = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, priority, local_leader_rank_in_peer, remote_leader_rank_in_peer); 246 MPI_Barrier(peer_comm); 247 MPI_Barrier(peer_comm); 248 #endif 249 250 251 #ifdef _showinfo 252 MPI_Barrier(peer_comm); 253 MPI_Barrier(peer_comm); 254 printf("peer_rank = %d, priority = %d, ownership = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, priority, ownership); 255 MPI_Barrier(peer_comm); 256 MPI_Barrier(peer_comm); 257 #endif 258 259 ////////////////////////////////////////////////////// 260 // step 4 : extract local_comm and create intercomm // 261 ////////////////////////////////////////////////////// 262 263 bool is_involved = is_local_leader || (!is_local_leader && ep_rank_loc == 0 && rank_in_world != local_leader_rank_in_world); 264 265 #ifdef _showinfo 266 267 MPI_Barrier(peer_comm); 268 MPI_Barrier(peer_comm); 269 printf("peer_rank = %d, is_involved = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, is_involved); 270 MPI_Barrier(peer_comm); 271 MPI_Barrier(peer_comm); 272 273 #endif 274 275 if(is_involved) 276 { 277 ::MPI_Group local_group; 278 ::MPI_Group extracted_group; 279 ::MPI_Comm *extracted_comm = new ::MPI_Comm; 280 281 282 ::MPI_Comm_group(to_mpi_comm(local_comm->mpi_comm), &local_group); 283 284 int *ownership_list = new int[mpi_size]; 285 int *mpi_rank_list = new int[mpi_size]; 286 287 ::MPI_Allgather(&ownership, 1, to_mpi_type(MPI_INT), ownership_list, 1, to_mpi_type(MPI_INT), to_mpi_comm(local_comm->mpi_comm)); 288 ::MPI_Allgather(&mpi_rank, 1, to_mpi_type(MPI_INT), mpi_rank_list, 1, to_mpi_type(MPI_INT), to_mpi_comm(local_comm->mpi_comm)); 289 290 291 int n=0; 292 for(int i=0; i<mpi_size; i++) 293 { 294 n+=ownership_list[i]; 295 } 296 297 int *new_mpi_rank_list = new int[n]; 298 int j=0; 299 for(int i=0; i<mpi_size; i++) 300 { 301 if(ownership_list[i] !=0) 302 { 303 new_mpi_rank_list[j++] = mpi_rank_list[i]; 304 } 305 } 306 307 308 ::MPI_Group_incl(local_group, n, new_mpi_rank_list, &extracted_group); 309 310 ::MPI_Comm_create(to_mpi_comm(local_comm->mpi_comm), extracted_group, extracted_comm); 311 312 ::MPI_Comm *mpi_inter_comm = new ::MPI_Comm; 313 314 int local_leader_rank_in_extracted_comm; 90 315 91 316 if(is_local_leader) 92 317 { 93 leader_info[0] = rank_in_world; 94 leader_info[1] = remote_leader; 95 96 ::MPI_Comm_rank(to_mpi_comm(peer_comm.mpi_comm), &rank_in_peer_mpi[0]); 97 98 send_buf[0] = size_info[0]; 99 send_buf[1] = local_ep_size; 100 send_buf[2] = rank_in_peer_mpi[0]; 101 102 103 104 MPI_Request requests[2]; 105 MPI_Status statuses[2]; 106 107 MPI_Isend(send_buf.data(), 3, MPI_INT, remote_leader, tag, peer_comm, &requests[0]); 108 MPI_Irecv(recv_buf.data(), 3, MPI_INT, remote_leader, tag, peer_comm, &requests[1]); 109 110 111 MPI_Waitall(2, requests, statuses); 112 113 size_info[1] = recv_buf[0]; 114 remote_ep_size = recv_buf[1]; 115 rank_in_peer_mpi[1] = recv_buf[2]; 116 117 } 118 119 120 121 send_buf[0] = size_info[1]; 122 send_buf[1] = leader_info[0]; 123 send_buf[2] = leader_info[1]; 124 send_buf[3] = rank_in_peer_mpi[0]; 125 send_buf[4] = rank_in_peer_mpi[1]; 126 127 ::MPI_Bcast(send_buf.data(), 5, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 128 129 size_info[1] = send_buf[0]; 130 leader_info[0] = send_buf[1]; 131 leader_info[1] = send_buf[2]; 132 rank_in_peer_mpi[0] = send_buf[3]; 133 rank_in_peer_mpi[1] = send_buf[4]; 134 135 136 rank_info[2].resize(size_info[1]); 137 rank_info[3].resize(size_info[1]); 138 139 ep_info[1].resize(size_info[1]); 140 141 send_buf.resize(3*size_info[0]); 142 recv_buf.resize(3*size_info[1]); 143 144 if(is_local_leader) 145 { 146 MPI_Request requests[2]; 147 MPI_Status statuses[2]; 148 149 std::copy ( rank_info[0].data(), rank_info[0].data() + size_info[0], send_buf.begin() ); 150 std::copy ( rank_info[1].data(), rank_info[1].data() + size_info[0], send_buf.begin() + size_info[0] ); 151 std::copy ( ep_info[0].data(), ep_info[0].data() + size_info[0], send_buf.begin() + 2*size_info[0] ); 152 153 MPI_Isend(send_buf.data(), 3*size_info[0], MPI_INT, remote_leader, tag+1, peer_comm, &requests[0]); 154 MPI_Irecv(recv_buf.data(), 3*size_info[1], MPI_INT, remote_leader, tag+1, peer_comm, &requests[1]); 155 156 MPI_Waitall(2, requests, statuses); 157 } 158 159 ::MPI_Bcast(recv_buf.data(), 3*size_info[1], to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 160 161 std::copy ( recv_buf.data(), recv_buf.data() + size_info[1], rank_info[2].begin() ); 162 std::copy ( recv_buf.data() + size_info[1], recv_buf.data() + 2*size_info[1], rank_info[3].begin() ); 163 std::copy ( recv_buf.data() + 2*size_info[1], recv_buf.data() + 3*size_info[1], ep_info[1].begin() ); 164 165 166 offset.resize(size_info[0]); 167 168 if(leader_info[0]<leader_info[1]) // erase all ranks doubled with remote_comm, except the local leader 169 { 170 171 bool found = false; 172 int ep_local; 173 int ep_remote; 174 for(int i=0; i<size_info[0]; i++) 318 ::MPI_Comm_rank(*extracted_comm, &local_leader_rank_in_extracted_comm); 319 } 320 321 ::MPI_Bcast(&local_leader_rank_in_extracted_comm, 1, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, to_mpi_comm(local_comm->mpi_comm)); 322 323 324 if(ownership) 325 ::MPI_Intercomm_create(*extracted_comm, local_leader_rank_in_extracted_comm, to_mpi_comm(peer_comm->mpi_comm), remote_leader_rank_in_peer_mpi, tag, mpi_inter_comm); 326 327 //////////////////////////////////// 328 // step 5 :: determine new num_ep // 329 //////////////////////////////////// 330 331 int num_ep_count=0; 332 333 for(int i=0; i<ep_size; i++) 334 { 335 if(rank_in_world == ranks_in_world_local[i]) 336 num_ep_count++; 337 } 338 339 for(int i=0; i<remote_ep_size; i++) 340 { 341 if(rank_in_world == ranks_in_world_remote[i]) 342 num_ep_count++; 343 } 344 345 346 /////////////////////////////////////////////////// 347 // step 6 : create endpoints from extracted_comm // 348 /////////////////////////////////////////////////// 349 350 if(ownership) 351 { 352 MPI_Comm *ep_comm; 353 MPI_Info info; 354 MPI_Comm_create_endpoints(extracted_comm, num_ep_count, info, ep_comm); 355 356 #ifdef _showinfo 357 printf("new ep_comm->ep_comm_ptr->intercomm->mpi_inter_comm = %p\n", mpi_inter_comm); 358 #endif 359 360 for(int i=0; i<num_ep_count; i++) 175 361 { 176 int target = rank_info[0][i]; 177 found = false; 178 for(int j=0; j<size_info[1]; j++) 362 ep_comm[i]->is_intercomm = true; 363 ep_comm[i]->ep_comm_ptr->comm_label = ranks_in_world_local[local_leader]; 364 ep_comm[i]->ep_comm_ptr->intercomm = new ep_lib::ep_intercomm; 365 #ifdef _showinfo 366 printf("new ep_comm[%d]->ep_comm_ptr->intercomm = %p\n", i, ep_comm[i]->ep_comm_ptr->intercomm); 367 #endif 368 ep_comm[i]->ep_comm_ptr->intercomm->mpi_inter_comm = mpi_inter_comm; 369 370 } 371 372 373 #pragma omp critical (write_to_tag_list) 374 intercomm_list.push_back(make_pair( make_pair(tag, min(local_leader_rank_in_world, remote_leader_rank_in_world)) , make_pair(ep_comm , make_pair(num_ep_count, 0)))); 375 #pragma omp flush 376 #ifdef _showinfo 377 for(int i=0; i<num_ep_count; i++) 378 printf("peer_rank = %d, ep_comm = %p, ep_comm[%d] -> new_ep_rank = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, ep_comm, i, ep_comm[i]->ep_comm_ptr->size_rank_info[0].first); 379 #endif 380 } 381 382 383 delete ownership_list; 384 delete mpi_rank_list; 385 delete new_mpi_rank_list; 386 387 } 388 389 int repeated=0; 390 for(int i=0; i<remote_ep_size; i++) 391 { 392 if(rank_in_world == ranks_in_world_remote[i]) 393 repeated++; 394 } 395 396 int my_turn = ownership? ep_rank_loc : ep_rank_loc+repeated; 397 398 #ifdef _showinfo 399 400 MPI_Barrier(peer_comm); 401 MPI_Barrier(peer_comm); 402 printf("peer_rank = %d, ep_rank_loc = %d, ownership = %d, repeated = %d, my_turn = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, ep_rank_loc, ownership, repeated, my_turn); 403 MPI_Barrier(peer_comm); 404 MPI_Barrier(peer_comm); 405 406 #endif 407 408 409 #pragma omp flush 410 #pragma omp critical (read_from_intercomm_list) 411 { 412 bool flag=true; 413 while(flag) 414 { 415 for(std::list<std::pair<std::pair<int, int> , std::pair<MPI_Comm * , std::pair<int, int> > > >::iterator iter = intercomm_list.begin(); iter!=intercomm_list.end(); iter++) 416 { 417 if(iter->first == make_pair(tag, min(local_leader_rank_in_world, remote_leader_rank_in_world))) 179 418 { 180 if(target == rank_info[2][j]) 181 { 182 found = true; 183 ep_local = ep_info[0][j]; 184 ep_remote = ep_info[1][j]; 185 break; 186 } 187 } 188 if(found) 189 { 190 191 if(target == leader_info[0]) // the leader is doubled in remote 192 { 193 new_rank_info[0].push_back(target); 194 new_rank_info[1].push_back(rank_info[1][i]); 195 196 new_ep_info[0].push_back(ep_local + ep_remote); 197 offset[i] = 0; 198 } 199 else 200 { 201 offset[i] = ep_local; 202 } 203 } 204 else 205 { 206 new_rank_info[0].push_back(target); 207 new_rank_info[1].push_back(rank_info[1][i]); 208 209 new_ep_info[0].push_back(ep_info[0][i]); 210 211 offset[i] = 0; 212 } 213 214 } 215 } 216 217 else // erase rank doubled with remote leader 218 { 219 220 bool found = false; 221 int ep_local; 222 int ep_remote; 223 for(int i=0; i<size_info[0]; i++) 224 { 225 int target = rank_info[0][i]; 226 found = false; 227 for(int j=0; j<size_info[1]; j++) 228 { 229 230 if(target == rank_info[2][j]) 231 { 232 found = true; 233 ep_local = ep_info[0][j]; 234 ep_remote = ep_info[1][j]; 235 break; 236 } 237 } 238 if(found) 239 { 240 if(target != leader_info[1]) 241 { 242 new_rank_info[0].push_back(target); 243 new_rank_info[1].push_back(rank_info[1][i]); 244 245 new_ep_info[0].push_back(ep_local + ep_remote); 246 offset[i] = 0; 247 } 248 else // found remote leader 249 { 250 offset[i] = ep_remote; 251 } 252 } 253 else 254 { 255 new_rank_info[0].push_back(target); 256 new_rank_info[1].push_back(rank_info[1][i]); 257 258 new_ep_info[0].push_back(ep_info[0][i]); 259 offset[i] = 0; 419 *newintercomm = iter->second.first[my_turn]; 420 421 iter->second.second.second++; 422 423 if(iter->second.second.first == iter->second.second.second) 424 intercomm_list.erase(iter); 425 426 flag = false; 427 break; 260 428 } 261 429 } 262 430 } 263 264 if(offset[mpi_rank] == 0) 265 { 266 is_final_master = true; 267 } 268 269 270 //! size_info[4]: 2->size of new_ep_info for local, 3->size of new_ep_info for remote 271 272 if(is_local_leader) 273 { 274 size_info[2] = new_ep_info[0].size(); 275 MPI_Request requests[2]; 276 MPI_Status statuses[2]; 277 MPI_Isend(&size_info[2], 1, MPI_INT, remote_leader, tag+2, peer_comm, &requests[0]); 278 MPI_Irecv(&size_info[3], 1, MPI_INT, remote_leader, tag+2, peer_comm, &requests[1]); 279 280 MPI_Waitall(2, requests, statuses); 281 } 282 283 ::MPI_Bcast(&size_info[2], 2, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 284 285 new_rank_info[2].resize(size_info[3]); 286 new_rank_info[3].resize(size_info[3]); 287 new_ep_info[1].resize(size_info[3]); 288 289 send_buf.resize(size_info[2]); 290 recv_buf.resize(size_info[3]); 291 292 if(is_local_leader) 293 { 294 MPI_Request requests[2]; 295 MPI_Status statuses[2]; 296 297 std::copy ( new_rank_info[0].data(), new_rank_info[0].data() + size_info[2], send_buf.begin() ); 298 std::copy ( new_rank_info[1].data(), new_rank_info[1].data() + size_info[2], send_buf.begin() + size_info[2] ); 299 std::copy ( new_ep_info[0].data(), new_ep_info[0].data() + size_info[0], send_buf.begin() + 2*size_info[2] ); 300 301 MPI_Isend(send_buf.data(), 3*size_info[2], MPI_INT, remote_leader, tag+3, peer_comm, &requests[0]); 302 MPI_Irecv(recv_buf.data(), 3*size_info[3], MPI_INT, remote_leader, tag+3, peer_comm, &requests[1]); 303 304 MPI_Waitall(2, requests, statuses); 305 } 306 307 ::MPI_Bcast(recv_buf.data(), 3*size_info[3], to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 308 309 std::copy ( recv_buf.data(), recv_buf.data() + size_info[3], new_rank_info[2].begin() ); 310 std::copy ( recv_buf.data() + size_info[3], recv_buf.data() + 2*size_info[3], new_rank_info[3].begin() ); 311 std::copy ( recv_buf.data() + 2*size_info[3], recv_buf.data() + 3*size_info[3], new_ep_info[1].begin() ); 312 313 } 314 315 316 317 if(is_proc_master) 318 { 319 //! leader_info[4]: 2-> rank of local leader in new_group generated comm; 320 // 3-> rank of remote leader in new_group generated comm; 321 ::MPI_Group local_group; 322 ::MPI_Group new_group; 323 ::MPI_Comm *new_comm = new ::MPI_Comm; 324 ::MPI_Comm *intercomm = new ::MPI_Comm; 325 326 ::MPI_Comm_group(local_mpi_comm, &local_group); 327 328 ::MPI_Group_incl(local_group, size_info[2], new_rank_info[1].data(), &new_group); 329 330 ::MPI_Comm_create(local_mpi_comm, new_group, new_comm); 331 332 333 334 if(is_local_leader) 335 { 336 ::MPI_Comm_rank(*new_comm, &leader_info[2]); 337 } 338 339 ::MPI_Bcast(&leader_info[2], 1, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 340 341 if(new_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm)) 342 { 343 344 ::MPI_Barrier(*new_comm); 345 346 ::MPI_Intercomm_create(*new_comm, leader_info[2], to_mpi_comm(peer_comm.mpi_comm), rank_in_peer_mpi[1], tag, intercomm); 347 348 int id; 349 350 ::MPI_Comm_rank(*new_comm, &id); 351 int my_num_ep = new_ep_info[0][id]; 352 353 MPI_Comm *ep_intercomm; 354 MPI_Info info; 355 MPI_Comm_create_endpoints(new_comm, my_num_ep, info, ep_intercomm); 356 357 358 for(int i= 0; i<my_num_ep; i++) 431 } 432 433 #ifdef _showinfo 434 435 MPI_Barrier(peer_comm); 436 MPI_Barrier(peer_comm); 437 printf("peer_rank = %d, test_rank = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, (*newintercomm)->ep_comm_ptr->size_rank_info[0].first); 438 MPI_Barrier(peer_comm); 439 MPI_Barrier(peer_comm); 440 441 #endif 442 443 ////////////////////////////////////////////////////////// 444 // step 7 : create intercomm_rank_map for local leaders // 445 ////////////////////////////////////////////////////////// 446 447 int my_quadruple[4]; 448 449 my_quadruple[0] = ep_rank; 450 my_quadruple[1] = (*newintercomm)->ep_comm_ptr->size_rank_info[1].first; 451 my_quadruple[2] = (*newintercomm)->ep_comm_ptr->size_rank_info[2].first; 452 my_quadruple[3] = (*newintercomm)->ep_comm_ptr->comm_label; 453 454 455 #ifdef _showinfo 456 457 MPI_Barrier(peer_comm); 458 MPI_Barrier(peer_comm); 459 printf("peer_rank = %d, my_quadruple = %d %d %d %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, my_quadruple[0], my_quadruple[1], my_quadruple[2], my_quadruple[3]); 460 MPI_Barrier(peer_comm); 461 MPI_Barrier(peer_comm); 462 #endif 463 464 int *local_quadruple_list; 465 int *remote_quadruple_list; 466 if(is_involved) 467 { 468 local_quadruple_list = new int[4*ep_size]; 469 remote_quadruple_list = new int[4*remote_ep_size]; 470 471 } 472 473 MPI_Gather(my_quadruple, 4, MPI_INT, local_quadruple_list, 4, MPI_INT, local_leader, local_comm); 474 475 476 if(is_local_leader) 477 { 478 MPI_Request request; 479 MPI_Status status; 480 481 if(remote_leader > local_leader_rank_in_peer) 482 { 483 MPI_Isend(local_quadruple_list, 4*ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 484 MPI_Wait(&request, &status); 485 486 MPI_Irecv(remote_quadruple_list, 4*remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 487 MPI_Wait(&request, &status); 488 } 489 else 490 { 491 MPI_Irecv(remote_quadruple_list, 4*remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 492 MPI_Wait(&request, &status); 493 494 MPI_Isend(local_quadruple_list, 4*ep_size, MPI_INT, remote_leader, tag, peer_comm, &request); 495 MPI_Wait(&request, &status); 496 } 497 #ifdef _showinfo 498 printf("peer_rank = %d, quadruple_list exchange OK\n", local_leader_rank_in_peer); 499 #endif 500 } 501 502 if(is_involved) 503 { 504 ::MPI_Bcast(remote_quadruple_list, 4*remote_ep_size, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, to_mpi_comm(local_comm->mpi_comm)); 505 (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map = new INTERCOMM_RANK_MAP; 506 #ifdef _showinfo 507 printf("new intercomm_rank_map = %p\n", (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map); 508 #endif 509 for(int i=0; i<remote_ep_size; i++) 510 { 511 (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->insert(std::pair<int, std::pair< int, std::pair<int, int> > >(remote_quadruple_list[4*i], remote_quadruple_list[4*i+1], remote_quadruple_list[4*i+2], remote_quadruple_list[4*i+3])); 512 } 513 } 514 515 //////////////////////////////////////////////////////// 516 // step 8 : associate intercomm_rank_map to endpoints // 517 //////////////////////////////////////////////////////// 518 519 int *leader_rank_in_world_local_gathered = new int[(*newintercomm)->ep_comm_ptr->size_rank_info[1].second]; 520 521 MPI_Allgather_local(&local_leader_rank_in_world, 1, MPI_INT, leader_rank_in_world_local_gathered, *newintercomm); 522 523 524 int new_rank_loc = (*newintercomm)->ep_comm_ptr->size_rank_info[1].first; 525 int *new_rank_loc_local_gathered = new int[(*newintercomm)->ep_comm_ptr->size_rank_info[1].second]; 526 527 MPI_Allgather_local(&new_rank_loc, 1, MPI_INT, new_rank_loc_local_gathered, *newintercomm); 528 529 //printf("peer_rank = %d, leader_rank_in_world_local_gathered = %d %d %d %d, new_rank_loc_local_gathered = %d %d %d %d\n", 530 // peer_comm->ep_comm_ptr->size_rank_info[0].first, leader_rank_in_world_local_gathered[0], leader_rank_in_world_local_gathered[1], leader_rank_in_world_local_gathered[2], leader_rank_in_world_local_gathered[3], 531 // new_rank_loc_local_gathered[0], new_rank_loc_local_gathered[1], new_rank_loc_local_gathered[2], new_rank_loc_local_gathered[3]); 532 533 if(is_involved) 534 { 535 536 (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map = new EP_RANK_MAP; 537 #ifdef _showinfo 538 printf("new local_rank_map = %p\n", (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map); 539 #endif 540 541 for(std::map<int, std::pair<int, int> >::iterator it = local_comm->ep_rank_map->begin(); it != local_comm->ep_rank_map->end(); it++) 542 { 543 (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->insert(std::pair<int, std::pair< int, int > >(it->first, it->second.first, it->second.second)); 544 } 545 } 546 547 MPI_Barrier_local(*newintercomm); 548 549 550 if(!is_involved) 551 { 552 int target; 553 for(int i=0; i<(*newintercomm)->ep_comm_ptr->size_rank_info[1].second; i++) 554 { 555 if(local_leader_rank_in_world == leader_rank_in_world_local_gathered[i]) 359 556 { 360 ep_intercomm[i].is_intercomm = true; 361 362 ep_intercomm[i].ep_comm_ptr->intercomm = new ep_lib::ep_intercomm; 363 ep_intercomm[i].ep_comm_ptr->intercomm->mpi_inter_comm = intercomm; 364 ep_intercomm[i].ep_comm_ptr->comm_label = leader_info[0]; 365 } 366 367 368 #pragma omp critical (write_to_tag_list) 369 tag_list.push_back(make_pair( make_pair(tag, min(leader_info[0], leader_info[1])) , ep_intercomm)); 370 //printf("tag_list size = %lu\n", tag_list.size()); 371 } 372 } 373 374 vector<int> bcast_buf(8); 375 if(is_local_leader) 376 { 377 std::copy(size_info, size_info+4, bcast_buf.begin()); 378 std::copy(leader_info, leader_info+4, bcast_buf.begin()+4); 379 } 380 381 MPI_Bcast(bcast_buf.data(), 8, MPI_INT, local_leader, local_comm); 382 383 if(!is_local_leader) 384 { 385 std::copy(bcast_buf.begin(), bcast_buf.begin()+4, size_info); 386 std::copy(bcast_buf.begin()+4, bcast_buf.begin()+8, leader_info); 387 } 388 389 if(!is_local_leader) 390 { 391 new_rank_info[1].resize(size_info[2]); 392 ep_info[1].resize(size_info[1]); 393 offset.resize(size_info[0]); 394 } 395 396 bcast_buf.resize(size_info[2]+size_info[1]+size_info[0]+1); 397 398 if(is_local_leader) 399 { 400 bcast_buf[0] = remote_ep_size; 401 std::copy(new_rank_info[1].data(), new_rank_info[1].data()+size_info[2], bcast_buf.begin()+1); 402 std::copy(ep_info[1].data(), ep_info[1].data()+size_info[1], bcast_buf.begin()+size_info[2]+1); 403 std::copy(offset.data(), offset.data()+size_info[0], bcast_buf.begin()+size_info[2]+size_info[1]+1); 404 } 405 406 MPI_Bcast(bcast_buf.data(), size_info[2]+size_info[1]+size_info[0]+1, MPI_INT, local_leader, local_comm); 407 408 if(!is_local_leader) 409 { 410 remote_ep_size = bcast_buf[0]; 411 std::copy(bcast_buf.data()+1, bcast_buf.data()+1+size_info[2], new_rank_info[1].begin()); 412 std::copy(bcast_buf.data()+1+size_info[2], bcast_buf.data()+1+size_info[2]+size_info[1], ep_info[1].begin()); 413 std::copy(bcast_buf.data()+1+size_info[2]+size_info[1], bcast_buf.data()+1+size_info[2]+size_info[1]+size_info[0], offset.begin()); 414 } 415 416 int my_position = offset[rank_in_local_parent]+ep_rank_loc; 417 418 MPI_Barrier_local(local_comm); 419 #pragma omp flush 420 421 422 #pragma omp critical (read_from_tag_list) 423 { 424 bool found = false; 425 while(!found) 426 { 427 for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++) 428 { 429 if((*iter).first == make_pair(tag, min(leader_info[0], leader_info[1]))) 430 { 431 *newintercomm = iter->second[my_position]; 432 found = true; 433 break; 434 } 435 } 436 } 437 } 438 439 MPI_Barrier(local_comm); 440 441 if(is_local_leader) 442 { 443 int local_flag = true; 444 int remote_flag = false; 445 MPI_Request mpi_requests[2]; 446 MPI_Status mpi_statuses[2]; 447 448 MPI_Isend(&local_flag, 1, MPI_INT, remote_leader, tag, peer_comm, &mpi_requests[0]); 449 MPI_Irecv(&remote_flag, 1, MPI_INT, remote_leader, tag, peer_comm, &mpi_requests[1]); 450 451 MPI_Waitall(2, mpi_requests, mpi_statuses); 452 } 453 454 455 MPI_Barrier(local_comm); 456 457 if(is_proc_master) 458 { 459 for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++) 460 { 461 if((*iter).first == make_pair(tag, min(leader_info[0], leader_info[1]))) 462 { 463 tag_list.erase(iter); 557 target = i; 558 (*newintercomm)->ep_comm_ptr->intercomm->intercomm_tag = target; 464 559 break; 465 560 } 466 561 } 467 } 468 469 int intercomm_ep_rank, intercomm_ep_rank_loc, intercomm_mpi_rank; 470 int intercomm_ep_size, intercomm_num_ep, intercomm_mpi_size; 471 472 intercomm_ep_rank = newintercomm->ep_comm_ptr->size_rank_info[0].first; 473 intercomm_ep_rank_loc = newintercomm->ep_comm_ptr->size_rank_info[1].first; 474 intercomm_mpi_rank = newintercomm->ep_comm_ptr->size_rank_info[2].first; 475 intercomm_ep_size = newintercomm->ep_comm_ptr->size_rank_info[0].second; 476 intercomm_num_ep = newintercomm->ep_comm_ptr->size_rank_info[1].second; 477 intercomm_mpi_size = newintercomm->ep_comm_ptr->size_rank_info[2].second; 478 479 MPI_Bcast(&remote_ep_size, 1, MPI_INT, local_leader, local_comm); 480 481 int my_rank_map_elem[2]; 482 483 my_rank_map_elem[0] = intercomm_ep_rank; 484 my_rank_map_elem[1] = (*newintercomm).ep_comm_ptr->comm_label; 485 486 vector<pair<int, int> > local_rank_map_array; 487 vector<pair<int, int> > remote_rank_map_array; 488 489 490 (*newintercomm).ep_comm_ptr->intercomm->local_rank_map = new RANK_MAP; 491 (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->resize(local_ep_size); 492 493 MPI_Allgather(my_rank_map_elem, 2, MPI_INT, 494 (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2, MPI_INT, local_comm); 495 496 (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP; 497 (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->resize(remote_ep_size); 498 499 (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[0] = local_comm.ep_comm_ptr->size_rank_info[0]; 500 (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[1] = local_comm.ep_comm_ptr->size_rank_info[1]; 501 (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[2] = local_comm.ep_comm_ptr->size_rank_info[2]; 502 503 int local_intercomm_size = intercomm_ep_size; 504 int remote_intercomm_size; 505 506 int new_bcast_root_0 = 0; 507 int new_bcast_root = 0; 508 509 510 if(is_local_leader) 511 { 512 MPI_Request requests[4]; 513 MPI_Status statuses[4]; 514 515 MPI_Isend((*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_ep_size, MPI_INT, remote_leader, tag+4, peer_comm, &requests[0]); 516 MPI_Irecv((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, MPI_INT, remote_leader, tag+4, peer_comm, &requests[1]); 517 518 MPI_Isend(&local_intercomm_size, 1, MPI_INT, remote_leader, tag+5, peer_comm, &requests[2]); 519 MPI_Irecv(&remote_intercomm_size, 1, MPI_INT, remote_leader, tag+5, peer_comm, &requests[3]); 520 521 MPI_Waitall(4, requests, statuses); 522 523 new_bcast_root_0 = intercomm_ep_rank; 524 } 525 526 MPI_Allreduce(&new_bcast_root_0, &new_bcast_root, 1, MPI_INT, MPI_SUM, *newintercomm); 527 528 529 MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, MPI_INT, local_leader, local_comm); 530 MPI_Bcast(&remote_intercomm_size, 1, MPI_INT, new_bcast_root, *newintercomm); 531 532 533 (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map = new RANK_MAP; 534 (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->resize(remote_intercomm_size); 535 536 537 538 539 if(is_local_leader) 540 { 541 MPI_Request requests[2]; 542 MPI_Status statuses[2]; 543 544 MPI_Isend((*newintercomm).rank_map->data(), 2*local_intercomm_size, MPI_INT, remote_leader, tag+6, peer_comm, &requests[0]); 545 MPI_Irecv((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, MPI_INT, remote_leader, tag+6, peer_comm, &requests[1]); 546 547 MPI_Waitall(2, requests, statuses); 548 } 549 550 MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, MPI_INT, new_bcast_root, *newintercomm); 551 552 (*newintercomm).ep_comm_ptr->intercomm->local_comm = &(local_comm.ep_comm_ptr->comm_list[ep_rank_loc]); 553 (*newintercomm).ep_comm_ptr->intercomm->intercomm_tag = tag; 562 (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map = (*newintercomm)->ep_comm_ptr->comm_list[target]->ep_comm_ptr->intercomm->intercomm_rank_map; 563 (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map = (*newintercomm)->ep_comm_ptr->comm_list[target]->ep_comm_ptr->intercomm->local_rank_map; 564 } 565 else 566 { 567 (*newintercomm)->ep_comm_ptr->intercomm->intercomm_tag = -1; 568 } 569 570 (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[0] = (*newintercomm)->ep_comm_ptr->size_rank_info[0]; 571 (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[1] = (*newintercomm)->ep_comm_ptr->size_rank_info[1]; 572 (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[2] = (*newintercomm)->ep_comm_ptr->size_rank_info[2]; 573 574 575 (*newintercomm)->ep_comm_ptr->size_rank_info[0] = local_comm->ep_comm_ptr->size_rank_info[0]; 576 (*newintercomm)->ep_comm_ptr->size_rank_info[1] = local_comm->ep_comm_ptr->size_rank_info[1]; 577 (*newintercomm)->ep_comm_ptr->size_rank_info[2] = local_comm->ep_comm_ptr->size_rank_info[2]; 578 579 580 #ifdef _showinfo 581 MPI_Barrier(peer_comm); 582 MPI_Barrier(peer_comm); 583 584 printf("peer_rank = %d, size_rank_info = %d %d %d %d %d %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, 585 (*newintercomm)->ep_comm_ptr->size_rank_info[0].first, (*newintercomm)->ep_comm_ptr->size_rank_info[0].second, 586 (*newintercomm)->ep_comm_ptr->size_rank_info[1].first, (*newintercomm)->ep_comm_ptr->size_rank_info[1].second, 587 (*newintercomm)->ep_comm_ptr->size_rank_info[2].first, (*newintercomm)->ep_comm_ptr->size_rank_info[2].second); 588 589 MPI_Barrier(peer_comm); 590 MPI_Barrier(peer_comm); 591 592 #endif 554 593 555 594 /* 556 for(int i=0; i<local_ep_size; i++) 557 if(local_comm.ep_comm_ptr->comm_label == 0) printf("ep_rank (from EP) = %d, local_rank_map[%d] = (%d,%d)\n", intercomm_ep_rank, i, 558 (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->at(i).first, (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->at(i).second); 559 560 for(int i=0; i<remote_ep_size; i++) 561 if(local_comm.ep_comm_ptr->comm_label == 0) printf("ep_rank (from EP) = %d, remote_rank_map[%d] = (%d,%d)\n", intercomm_ep_rank, i, 562 (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->at(i).first, (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->at(i).second); 563 564 for(int i=0; i<remote_intercomm_size; i++) 565 if(local_comm.ep_comm_ptr->comm_label == 0) printf("ep_rank (from EP) = %d, intercomm_rank_map[%d] = (%d,%d)\n", intercomm_ep_rank, i, 566 (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->at(i).first, (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->at(i).second); 595 if(peer_comm->ep_comm_ptr->size_rank_info[0].first == 5) 596 { 597 int receiver = rand()%10; 598 printf("receiver = %d, intercomm_local_rank = %d, intercomm_mpi_rank = %d, comm_label = %d\n", receiver, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).first, 599 (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.first, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.second); 600 } 601 602 if(peer_comm->ep_comm_ptr->size_rank_info[0].first == 9) 603 { 604 int receiver = rand()%6; 605 printf("receiver = %d, intercomm_local_rank = %d, intercomm_mpi_rank = %d, comm_label = %d\n", receiver, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).first, 606 (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.first, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.second); 607 } 608 609 610 if(peer_comm->ep_comm_ptr->size_rank_info[0].first == 5) 611 { 612 for(int i=0; i<ep_size; i++) 613 { 614 printf("rank_map->at(%d) = %d, %d\n", i, (*newintercomm)->ep_rank_map->at(i).first, (*newintercomm)->ep_rank_map->at(i).second); 615 } 616 } 567 617 */ 568 569 // for(int i=0; i<(*newintercomm).rank_map->size(); i++) 570 // if(local_comm.ep_comm_ptr->comm_label != 99) printf("ep_rank = %d, rank_map[%d] = (%d,%d)\n", intercomm_ep_rank, i, 571 // (*newintercomm).rank_map->at(i).first, (*newintercomm).rank_map->at(i).second); 572 573 // MPI_Comm *test_comm = newintercomm->ep_comm_ptr->intercomm->local_comm; 574 // int test_rank; 575 // MPI_Comm_rank(*test_comm, &test_rank); 576 // printf("=================test_rank = %d\n", test_rank); 577 578 579 580 return MPI_SUCCESS; 618 ////////////// 619 // clean up // 620 ////////////// 621 622 delete ranks_in_world_local; 623 delete ranks_in_world_remote; 624 625 if(is_involved) 626 { 627 delete local_quadruple_list; 628 delete remote_quadruple_list; 629 } 630 631 delete leader_rank_in_world_local_gathered; 632 delete new_rank_loc_local_gathered; 633 581 634 582 635 } … … 584 637 585 638 586 587 int MPI_Intercomm_create_unique_leader(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm) 588 { 589 //! mpi_size of local comm = 1 590 //! same world rank of leaders 591 592 int ep_rank, ep_rank_loc, mpi_rank; 593 int ep_size, num_ep, mpi_size; 594 595 ep_rank = local_comm.ep_comm_ptr->size_rank_info[0].first; 596 ep_rank_loc = local_comm.ep_comm_ptr->size_rank_info[1].first; 597 mpi_rank = local_comm.ep_comm_ptr->size_rank_info[2].first; 598 ep_size = local_comm.ep_comm_ptr->size_rank_info[0].second; 599 num_ep = local_comm.ep_comm_ptr->size_rank_info[1].second; 600 mpi_size = local_comm.ep_comm_ptr->size_rank_info[2].second; 601 602 603 604 std::vector<int> rank_info[4]; //! 0->rank_in_world of local_comm, 1->rank_in_local_parent of local_comm 605 //! 2->rank_in_world of remote_comm, 3->rank_in_local_parent of remote_comm 606 607 int rank_in_world; 608 609 int rank_in_peer_mpi[2]; 610 611 ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD.mpi_comm), &rank_in_world); 612 613 614 int local_num_ep = num_ep; 615 int remote_num_ep; 616 int total_num_ep; 617 618 int leader_rank_in_peer[2]; 619 620 int my_position; 621 int tag_label[2]; 622 623 vector<int> send_buf(4); 624 vector<int> recv_buf(4); 625 626 627 if(ep_rank == local_leader) 628 { 629 MPI_Status status; 630 631 632 633 MPI_Comm_rank(peer_comm, &leader_rank_in_peer[0]); 634 635 send_buf[0] = local_num_ep; 636 send_buf[1] = leader_rank_in_peer[0]; 637 638 MPI_Request req_s, req_r; 639 640 MPI_Isend(send_buf.data(), 2, MPI_INT, remote_leader, tag, peer_comm, &req_s); 641 MPI_Irecv(recv_buf.data(), 2, MPI_INT, remote_leader, tag, peer_comm, &req_r); 642 643 644 MPI_Wait(&req_s, &status); 645 MPI_Wait(&req_r, &status); 646 647 recv_buf[2] = leader_rank_in_peer[0]; 648 649 } 650 651 MPI_Bcast(recv_buf.data(), 3, MPI_INT, local_leader, local_comm); 652 653 remote_num_ep = recv_buf[0]; 654 leader_rank_in_peer[1] = recv_buf[1]; 655 leader_rank_in_peer[0] = recv_buf[2]; 656 657 total_num_ep = local_num_ep + remote_num_ep; 658 659 660 if(leader_rank_in_peer[0] < leader_rank_in_peer[1]) 661 { 662 my_position = ep_rank_loc; 663 //! LEADER create EP 664 if(ep_rank == local_leader) 665 { 666 ::MPI_Comm *mpi_dup = new ::MPI_Comm; 667 668 ::MPI_Comm_dup(to_mpi_comm(local_comm.mpi_comm), mpi_dup); 669 670 MPI_Comm *ep_intercomm; 671 MPI_Info info; 672 MPI_Comm_create_endpoints(mpi_dup, total_num_ep, info, ep_intercomm); 673 674 675 for(int i=0; i<total_num_ep; i++) 676 { 677 ep_intercomm[i].is_intercomm = true; 678 ep_intercomm[i].ep_comm_ptr->intercomm = new ep_lib::ep_intercomm; 679 ep_intercomm[i].ep_comm_ptr->intercomm->mpi_inter_comm = 0; 680 681 ep_intercomm[i].ep_comm_ptr->comm_label = leader_rank_in_peer[0]; 682 } 683 684 tag_label[0] = TAG++; 685 tag_label[1] = rank_in_world; 686 687 #pragma omp critical (write_to_tag_list) 688 tag_list.push_back(make_pair( make_pair(tag_label[0], tag_label[1]) , ep_intercomm)); 689 690 MPI_Request req_s; 691 MPI_Status sta_s; 692 MPI_Isend(tag_label, 2, MPI_INT, remote_leader, tag, peer_comm, &req_s); 693 694 MPI_Wait(&req_s, &sta_s); 695 696 } 697 } 698 else 699 { 700 //! Wait for EP creation 701 my_position = remote_num_ep + ep_rank_loc; 702 if(ep_rank == local_leader) 703 { 704 MPI_Status status; 705 MPI_Request req_r; 706 MPI_Irecv(tag_label, 2, MPI_INT, remote_leader, tag, peer_comm, &req_r); 707 MPI_Wait(&req_r, &status); 708 } 709 } 710 711 MPI_Bcast(tag_label, 2, MPI_INT, local_leader, local_comm); 712 713 714 715 716 #pragma omp critical (read_from_tag_list) 717 { 718 bool found = false; 719 while(!found) 720 { 721 for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++) 722 { 723 if((*iter).first == make_pair(tag_label[0], tag_label[1])) 724 { 725 *newintercomm = iter->second[my_position]; 726 found = true; 727 // tag_list.erase(iter); 728 break; 729 } 730 } 731 } 732 } 733 734 MPI_Barrier_local(local_comm); 735 736 if(leader_rank_in_peer[0] < leader_rank_in_peer[1]) 737 { 738 for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++) 739 { 740 if((*iter).first == make_pair(tag_label[0], tag_label[1])) 741 { 742 tag_list.erase(iter); 743 break; 744 } 745 } 746 } 747 748 749 750 int intercomm_ep_rank, intercomm_ep_rank_loc, intercomm_mpi_rank; 751 int intercomm_ep_size, intercomm_num_ep, intercomm_mpi_size; 752 753 intercomm_ep_rank = newintercomm->ep_comm_ptr->size_rank_info[0].first; 754 intercomm_ep_rank_loc = newintercomm->ep_comm_ptr->size_rank_info[1].first; 755 intercomm_mpi_rank = newintercomm->ep_comm_ptr->size_rank_info[2].first; 756 intercomm_ep_size = newintercomm->ep_comm_ptr->size_rank_info[0].second; 757 intercomm_num_ep = newintercomm->ep_comm_ptr->size_rank_info[1].second; 758 intercomm_mpi_size = newintercomm->ep_comm_ptr->size_rank_info[2].second; 759 760 761 762 (*newintercomm).ep_comm_ptr->intercomm->local_rank_map = new RANK_MAP; 763 (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP; 764 (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->resize(local_num_ep); 765 (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->resize(remote_num_ep); 766 767 (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[0] = local_comm.ep_comm_ptr->size_rank_info[0]; 768 (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[1] = local_comm.ep_comm_ptr->size_rank_info[1]; 769 (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[2] = local_comm.ep_comm_ptr->size_rank_info[2]; 770 771 772 773 int local_rank_map_ele[2]; 774 local_rank_map_ele[0] = intercomm_ep_rank; 775 local_rank_map_ele[1] = (*newintercomm).ep_comm_ptr->comm_label; 776 777 MPI_Allgather(local_rank_map_ele, 2, MPI_INT, 778 (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2, MPI_INT, local_comm); 779 780 if(ep_rank == local_leader) 781 { 782 MPI_Status status; 783 MPI_Request req_s, req_r; 784 785 MPI_Isend((*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_num_ep, MPI_INT, remote_leader, tag, peer_comm, &req_s); 786 MPI_Irecv((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_num_ep, MPI_INT, remote_leader, tag, peer_comm, &req_r); 787 788 789 MPI_Wait(&req_s, &status); 790 MPI_Wait(&req_r, &status); 791 792 } 793 794 MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_num_ep, MPI_INT, local_leader, local_comm); 795 (*newintercomm).ep_comm_ptr->intercomm->local_comm = &(local_comm.ep_comm_ptr->comm_list[ep_rank_loc]); 796 (*newintercomm).ep_comm_ptr->intercomm->intercomm_tag = tag; 797 798 799 return MPI_SUCCESS; 800 } 801 802 639 803 640 } -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm_world.cpp
r1356 r1520 9 9 { 10 10 11 // #ifdef _openmpi 12 13 // int MPI_Intercomm_create_from_world(MPI_Comm local_comm, int local_leader, void* peer_comm_ptr, int mpi_remote_leader, int tag, MPI_Comm *newintercomm) 14 // { 15 16 // int ep_rank, ep_rank_loc, mpi_rank; 17 // int ep_size, num_ep, mpi_size; 18 19 // ep_rank = local_comm.ep_comm_ptr->size_rank_info[0].first; 20 // ep_rank_loc = local_comm.ep_comm_ptr->size_rank_info[1].first; 21 // mpi_rank = local_comm.ep_comm_ptr->size_rank_info[2].first; 22 // ep_size = local_comm.ep_comm_ptr->size_rank_info[0].second; 23 // num_ep = local_comm.ep_comm_ptr->size_rank_info[1].second; 24 // mpi_size = local_comm.ep_comm_ptr->size_rank_info[2].second; 25 26 27 // std::vector<int> rank_info[4]; //! 0->rank_in_world of local_comm, 1->rank_in_local_parent of local_comm 28 // //! 2->rank_in_world of remote_comm, 3->rank_in_local_parent of remote_comm 29 30 // int rank_in_world; 31 // int rank_in_local_parent; 32 33 // int local_ep_size = ep_size; 34 // int remote_ep_size; 35 36 // ::MPI_Comm peer_comm = to_mpi_comm(peer_comm_ptr); 37 // ::MPI_Comm local_mpi_comm = to_mpi_comm(local_comm.mpi_comm); 38 39 // ::MPI_Comm_rank(peer_comm, &rank_in_world); 40 41 // ::MPI_Comm_rank(local_mpi_comm, &rank_in_local_parent); 42 43 // bool is_proc_master = false; 44 // bool is_local_leader = false; 45 // bool is_final_master = false; 46 47 48 // if(ep_rank == local_leader) { is_proc_master = true; is_local_leader = true; is_final_master = true;} 49 // if(ep_rank_loc == 0 && mpi_rank != local_comm.rank_map->at(local_leader).second) is_proc_master = true; 50 51 52 // int size_info[4]; //! used for choose size of rank_info 0-> mpi_size of local_comm, 1-> mpi_size of remote_comm 53 54 // int leader_info[4]; //! 0->world rank of local_leader, 1->world rank of remote leader 55 56 57 // std::vector<int> ep_info[2]; //! 0-> num_ep in local_comm, 1->num_ep in remote_comm 58 59 // std::vector<int> new_rank_info[4]; 60 // std::vector<int> new_ep_info[2]; 61 62 // std::vector<int> offset; 63 64 // if(is_proc_master) 65 // { 66 67 // size_info[0] = mpi_size; 68 69 // rank_info[0].resize(size_info[0]); 70 // rank_info[1].resize(size_info[0]); 71 72 73 74 // ep_info[0].resize(size_info[0]); 75 76 // vector<int> send_buf(6); 77 // vector<int> recv_buf(3*size_info[0]); 78 79 // send_buf[0] = rank_in_world; 80 // send_buf[1] = rank_in_local_parent; 81 // send_buf[2] = num_ep; 82 83 // ::MPI_Allgather(send_buf.data(), 3, to_mpi_type(MPI_INT), recv_buf.data(), 3, to_mpi_type(MPI_INT), local_mpi_comm); 84 85 // for(int i=0; i<size_info[0]; i++) 86 // { 87 // rank_info[0][i] = recv_buf[3*i]; 88 // rank_info[1][i] = recv_buf[3*i+1]; 89 // ep_info[0][i] = recv_buf[3*i+2]; 90 // } 91 92 // if(is_local_leader) 93 // { 94 // leader_info[0] = rank_in_world; 95 // leader_info[1] = mpi_remote_leader; 96 97 // ::MPI_Status mpi_status; 98 99 // send_buf[0] = size_info[0]; 100 // send_buf[1] = local_ep_size; 101 102 // ::MPI_Send(send_buf.data(), 2, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 103 104 // ::MPI_Recv(recv_buf.data(), 2, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 105 106 // recv_buf[2] = rank_in_world; 107 // recv_buf[3] = mpi_remote_leader; 108 109 // } 110 111 // ::MPI_Bcast(recv_buf.data(), 4, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 112 113 // size_info[1] = recv_buf[0]; 114 // remote_ep_size = recv_buf[1]; 115 // leader_info[0] = recv_buf[2]; 116 // leader_info[1] = recv_buf[3]; 117 118 // rank_info[2].resize(size_info[1]); 119 // rank_info[3].resize(size_info[1]); 120 121 // ep_info[1].resize(size_info[1]); 122 123 // send_buf.resize(3*size_info[0]); 124 // recv_buf.resize(3*size_info[1]); 125 126 // if(is_local_leader) 127 // { 128 // ::MPI_Status mpi_status; 129 130 131 // std::copy ( rank_info[0].data(), rank_info[0].data() + size_info[0], send_buf.begin() ); 132 // std::copy ( rank_info[1].data(), rank_info[1].data() + size_info[0], send_buf.begin() + size_info[0] ); 133 // std::copy ( ep_info[0].data(), ep_info[0].data() + size_info[0], send_buf.begin() + 2*size_info[0] ); 134 135 // ::MPI_Send(send_buf.data(), 3*size_info[0], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 136 137 // ::MPI_Recv(recv_buf.data(), 3*size_info[1], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 138 139 // } 140 141 // ::MPI_Bcast(recv_buf.data(), 3*size_info[1], to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 142 143 // std::copy ( recv_buf.data(), recv_buf.data() + size_info[1], rank_info[2].begin() ); 144 // std::copy ( recv_buf.data() + size_info[1], recv_buf.data() + 2*size_info[1], rank_info[3].begin() ); 145 // std::copy ( recv_buf.data() + 2*size_info[1], recv_buf.data() + 3*size_info[1], ep_info[1].begin() ); 146 147 // offset.resize(size_info[0]); 148 149 // if(leader_info[0]<leader_info[1]) // erase all ranks doubled with remote_comm, except the local leader 150 // { 151 152 // bool found = false; 153 // int ep_tmp; 154 // int ep_local; 155 // int ep_remote; 156 // for(int i=0; i<size_info[0]; i++) 157 // { 158 // int target = rank_info[0][i]; 159 // found = false; 160 // for(int j=0; j<size_info[1]; j++) 161 // { 162 // if(target == rank_info[2][j]) 163 // { 164 // found = true; 165 // ep_tmp = ep_info[1][j]; 166 // ep_local = ep_info[0][j]; 167 // ep_remote = ep_info[1][j]; 168 // break; 169 // } 170 // } 171 // if(found) 172 // { 173 174 // if(target == leader_info[0]) // the leader is doubled in remote 175 // { 176 // new_rank_info[0].push_back(target); 177 // new_rank_info[1].push_back(rank_info[1][i]); 178 179 // new_ep_info[0].push_back(ep_local + ep_remote); 180 // offset[i] = 0; 181 // } 182 // else 183 // { 184 // offset[i] = ep_local; 185 // } 186 // } 187 // else 188 // { 189 // new_rank_info[0].push_back(target); 190 // new_rank_info[1].push_back(rank_info[1][i]); 191 192 // new_ep_info[0].push_back(ep_info[0][i]); 193 194 // offset[i] = 0; 195 // } 196 197 // } 198 // } 199 200 // else // erase rank doubled with remote leader 201 // { 202 203 // bool found = false; 204 // int ep_tmp; 205 // int ep_local; 206 // int ep_remote; 207 // for(int i=0; i<size_info[0]; i++) 208 // { 209 // int target = rank_info[0][i]; 210 // found = false; 211 // for(int j=0; j<size_info[1]; j++) 212 // { 213 214 // if(target == rank_info[2][j]) 215 // { 216 // found = true; 217 // ep_tmp = ep_info[1][j]; 218 // ep_local = ep_info[0][j]; 219 // ep_remote = ep_info[1][j]; 220 // break; 221 // } 222 // } 223 // if(found) 224 // { 225 // if(target != leader_info[1]) 226 // { 227 // new_rank_info[0].push_back(target); 228 // new_rank_info[1].push_back(rank_info[1][i]); 229 230 // new_ep_info[0].push_back(ep_local + ep_remote); 231 // offset[i] = 0; 232 // } 233 // else // found remote leader 234 // { 235 // offset[i] = ep_remote; 236 // } 237 // } 238 // else 239 // { 240 // new_rank_info[0].push_back(target); 241 // new_rank_info[1].push_back(rank_info[1][i]); 242 243 // new_ep_info[0].push_back(ep_info[0][i]); 244 // offset[i] = 0; 245 // } 246 // } 247 // } 248 249 // if(offset[mpi_rank] == 0) 250 // { 251 // is_final_master = true; 252 // } 253 254 255 // // size_info[4]: 2->size of new_ep_info for local, 3->size of new_ep_info for remote 256 257 // if(is_local_leader) 258 // { 259 // size_info[2] = new_ep_info[0].size(); 260 // ::MPI_Status mpi_status; 261 262 // ::MPI_Send(&size_info[2], 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 263 264 // ::MPI_Recv(&size_info[3], 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 265 // } 266 267 // ::MPI_Bcast(&size_info[2], 2, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 268 269 // new_rank_info[2].resize(size_info[3]); 270 // new_rank_info[3].resize(size_info[3]); 271 // new_ep_info[1].resize(size_info[3]); 272 273 // send_buf.resize(size_info[2]); 274 // recv_buf.resize(size_info[3]); 275 276 // if(is_local_leader) 277 // { 278 // ::MPI_Status mpi_status; 279 280 // std::copy ( new_rank_info[0].data(), new_rank_info[0].data() + size_info[2], send_buf.begin() ); 281 // std::copy ( new_rank_info[1].data(), new_rank_info[1].data() + size_info[2], send_buf.begin() + size_info[2] ); 282 // std::copy ( new_ep_info[0].data(), new_ep_info[0].data() + size_info[0], send_buf.begin() + 2*size_info[2] ); 283 284 // ::MPI_Send(send_buf.data(), 3*size_info[2], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 285 // ::MPI_Recv(recv_buf.data(), 3*size_info[3], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 286 287 // } 288 289 // ::MPI_Bcast(recv_buf.data(), 3*size_info[3], to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 290 291 // std::copy ( recv_buf.data(), recv_buf.data() + size_info[3], new_rank_info[2].begin() ); 292 // std::copy ( recv_buf.data() + size_info[3], recv_buf.data() + 2*size_info[3], new_rank_info[3].begin() ); 293 // std::copy ( recv_buf.data() + 2*size_info[3], recv_buf.data() + 3*size_info[3], new_ep_info[1].begin() ); 294 295 // } 296 297 298 299 // if(is_proc_master) 300 // { 301 // // leader_info[4]: 2-> rank of local leader in new_group generated comm; 302 // // 3-> rank of remote leader in new_group generated comm; 303 // ::MPI_Group local_group; 304 // ::MPI_Group new_group; 305 // ::MPI_Comm *new_comm = new ::MPI_Comm; 306 // ::MPI_Comm *intercomm = new ::MPI_Comm; 307 308 // ::MPI_Comm_group(local_mpi_comm, &local_group); 309 310 // ::MPI_Group_incl(local_group, size_info[2], new_rank_info[1].data(), &new_group); 311 312 // ::MPI_Comm_create(local_mpi_comm, new_group, new_comm); 313 314 315 316 // if(is_local_leader) 317 // { 318 // ::MPI_Comm_rank(*new_comm, &leader_info[2]); 319 // } 320 321 // ::MPI_Bcast(&leader_info[2], 1, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm); 322 323 // if(new_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm)) 324 // { 325 // ::MPI_Barrier(*new_comm); 326 327 // ::MPI_Intercomm_create(*new_comm, leader_info[2], peer_comm, leader_info[1], tag, intercomm); 328 329 // int id; 330 // ::MPI_Comm_rank(*new_comm, &id); 331 // int my_num_ep = new_ep_info[0][id]; 332 333 // MPI_Comm *ep_intercomm; 334 // MPI_Info info; 335 // MPI_Comm_create_endpoints(new_comm, my_num_ep, info, ep_intercomm); 336 337 338 339 // for(int i= 0; i<my_num_ep; i++) 340 // { 341 // ep_intercomm[i].is_intercomm = true; 342 343 // ep_intercomm[i].ep_comm_ptr->intercomm = new ep_lib::ep_intercomm; 344 // ep_intercomm[i].ep_comm_ptr->intercomm->mpi_inter_comm = intercomm; 345 // ep_intercomm[i].ep_comm_ptr->comm_label = leader_info[0]; 346 // } 347 348 // #pragma omp critical (write_to_tag_list) 349 // tag_list.push_back(make_pair( make_pair(tag, min(leader_info[0], leader_info[1])) , ep_intercomm)); 350 // } 351 352 353 // } 354 355 356 // MPI_Barrier_local(local_comm); 357 358 // vector<int> bcast_buf(8); 359 // if(is_local_leader) 360 // { 361 // std::copy(size_info, size_info+4, bcast_buf.begin()); 362 // std::copy(leader_info, leader_info+4, bcast_buf.begin()+4); 363 // } 364 365 // MPI_Bcast(bcast_buf.data(), 8, MPI_INT, local_leader, local_comm); 366 367 // if(!is_local_leader) 368 // { 369 // std::copy(bcast_buf.begin(), bcast_buf.begin()+4, size_info); 370 // std::copy(bcast_buf.begin()+4, bcast_buf.begin()+8, leader_info); 371 // } 372 373 // if(!is_local_leader) 374 // { 375 // new_rank_info[1].resize(size_info[2]); 376 // ep_info[1].resize(size_info[1]); 377 // offset.resize(size_info[0]); 378 // } 379 380 // bcast_buf.resize(size_info[2]+size_info[1]+size_info[0]+1); 381 382 // if(is_local_leader) 383 // { 384 // bcast_buf[0] = remote_ep_size; 385 // std::copy(new_rank_info[1].data(), new_rank_info[1].data()+size_info[2], bcast_buf.begin()+1); 386 // std::copy(ep_info[1].data(), ep_info[1].data()+size_info[1], bcast_buf.begin()+size_info[2]+1); 387 // std::copy(offset.data(), offset.data()+size_info[0], bcast_buf.begin()+size_info[2]+size_info[1]+1); 388 // } 389 390 // MPI_Bcast(bcast_buf.data(), size_info[2]+size_info[1]+size_info[0]+1, MPI_INT, local_leader, local_comm); 391 392 // if(!is_local_leader) 393 // { 394 // remote_ep_size = bcast_buf[0]; 395 // std::copy(bcast_buf.data()+1, bcast_buf.data()+1+size_info[2], new_rank_info[1].begin()); 396 // std::copy(bcast_buf.data()+1+size_info[2], bcast_buf.data()+1+size_info[2]+size_info[1], ep_info[1].begin()); 397 // std::copy(bcast_buf.data()+1+size_info[2]+size_info[1], bcast_buf.data()+1+size_info[2]+size_info[1]+size_info[0], offset.begin()); 398 // } 399 400 401 // int my_position = offset[rank_in_local_parent]+ep_rank_loc; 402 403 404 // MPI_Barrier_local(local_comm); 405 // #pragma omp flush 406 407 408 // #pragma omp critical (read_from_tag_list) 409 // { 410 // bool found = false; 411 // while(!found) 412 // { 413 // for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++) 414 // { 415 // if((*iter).first == make_pair(tag, min(leader_info[0], leader_info[1]))) 416 // { 417 // *newintercomm = iter->second[my_position]; 418 419 // found = true; 420 // //tag_list.erase(iter); 421 // break; 422 // } 423 // } 424 // } 425 // } 426 427 // MPI_Barrier(local_comm); 428 429 // if(is_local_leader) 430 // { 431 // int local_flag = true; 432 // int remote_flag = false; 433 // ::MPI_Status mpi_status; 434 435 // ::MPI_Send(&local_flag, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 436 437 // ::MPI_Recv(&remote_flag, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status); 438 // } 439 440 // MPI_Barrier(local_comm); 441 442 // if(is_proc_master) 443 // { 444 // for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++) 445 // { 446 // if((*iter).first == make_pair(tag, min(leader_info[0], leader_info[1]))) 447 // { 448 // tag_list.erase(iter); 449 // break; 450 // } 451 // } 452 // } 453 454 455 456 // int intercomm_ep_rank, intercomm_ep_rank_loc, intercomm_mpi_rank; 457 // int intercomm_ep_size, intercomm_num_ep, intercomm_mpi_size; 458 459 // intercomm_ep_rank = newintercomm->ep_comm_ptr->size_rank_info[0].first; 460 // intercomm_ep_rank_loc = newintercomm->ep_comm_ptr->size_rank_info[1].first; 461 // intercomm_mpi_rank = newintercomm->ep_comm_ptr->size_rank_info[2].first; 462 // intercomm_ep_size = newintercomm->ep_comm_ptr->size_rank_info[0].second; 463 // intercomm_num_ep = newintercomm->ep_comm_ptr->size_rank_info[1].second; 464 // intercomm_mpi_size = newintercomm->ep_comm_ptr->size_rank_info[2].second; 465 466 // MPI_Bcast(&remote_ep_size, 1, MPI_INT, local_leader, local_comm); 467 468 // int my_rank_map_elem[2]; 469 470 471 // my_rank_map_elem[0] = intercomm_ep_rank; 472 473 // my_rank_map_elem[1] = (*newintercomm).ep_comm_ptr->comm_label; 474 475 // vector<pair<int, int> > local_rank_map_array; 476 // vector<pair<int, int> > remote_rank_map_array; 477 478 479 // (*newintercomm).ep_comm_ptr->intercomm->local_rank_map = new RANK_MAP; 480 // (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->resize(local_ep_size); 481 482 // MPI_Allgather2(my_rank_map_elem, 2, MPI_INT, (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2, MPI_INT, local_comm); 483 484 // (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP; 485 // (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->resize(remote_ep_size); 486 487 // int local_intercomm_size = intercomm_ep_size; 488 // int remote_intercomm_size; 489 490 491 492 493 // if(is_local_leader) 494 // { 495 // ::MPI_Status status; 496 497 // ::MPI_Send((*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_ep_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 498 499 // ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status); 500 501 // ::MPI_Send(&local_intercomm_size, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 502 503 // ::MPI_Recv(&remote_intercomm_size, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status); 504 // } 505 506 // MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, MPI_INT, local_leader, local_comm); 507 // MPI_Bcast(&remote_intercomm_size, 1, MPI_INT, 0, *newintercomm); 508 509 510 // (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map = new RANK_MAP; 511 // (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->resize(remote_intercomm_size); 512 513 // (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[0] = local_comm.ep_comm_ptr->size_rank_info[0]; 514 // (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[1] = local_comm.ep_comm_ptr->size_rank_info[1]; 515 // (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[2] = local_comm.ep_comm_ptr->size_rank_info[2]; 516 517 518 // if(is_local_leader) 519 // { 520 // ::MPI_Status status; 521 522 // ::MPI_Send((*newintercomm).rank_map->data(), 2*local_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 523 524 // ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status); 525 // } 526 527 // MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, to_mpi_type(MPI_INT), 0, *newintercomm); 528 529 // (*newintercomm).ep_comm_ptr->intercomm->local_comm = &(local_comm.ep_comm_ptr->comm_list[ep_rank_loc]); 530 // (*newintercomm).ep_comm_ptr->intercomm->intercomm_tag = local_comm.ep_comm_ptr->comm_label; 531 532 533 // return MPI_SUCCESS; 534 535 // } 536 537 538 539 // #elif _intelmpi 11 540 12 int MPI_Intercomm_create_from_world(MPI_Comm local_comm, int local_leader, void* peer_comm_ptr, int mpi_remote_leader, int tag, MPI_Comm *newintercomm) 541 13 { … … 543 15 int ep_size, num_ep, mpi_size; 544 16 545 ep_rank = local_comm .ep_comm_ptr->size_rank_info[0].first;546 ep_rank_loc = local_comm .ep_comm_ptr->size_rank_info[1].first;547 mpi_rank = local_comm .ep_comm_ptr->size_rank_info[2].first;548 ep_size = local_comm .ep_comm_ptr->size_rank_info[0].second;549 num_ep = local_comm .ep_comm_ptr->size_rank_info[1].second;550 mpi_size = local_comm .ep_comm_ptr->size_rank_info[2].second;17 ep_rank = local_comm->ep_comm_ptr->size_rank_info[0].first; 18 ep_rank_loc = local_comm->ep_comm_ptr->size_rank_info[1].first; 19 mpi_rank = local_comm->ep_comm_ptr->size_rank_info[2].first; 20 ep_size = local_comm->ep_comm_ptr->size_rank_info[0].second; 21 num_ep = local_comm->ep_comm_ptr->size_rank_info[1].second; 22 mpi_size = local_comm->ep_comm_ptr->size_rank_info[2].second; 551 23 552 24 std::vector<int> rank_info[4]; //! 0->rank_in_world of local_comm, 1->rank_in_local_parent of local_comm … … 560 32 561 33 ::MPI_Comm peer_comm = to_mpi_comm(peer_comm_ptr); 562 ::MPI_Comm local_mpi_comm = to_mpi_comm(local_comm .mpi_comm);34 ::MPI_Comm local_mpi_comm = to_mpi_comm(local_comm->mpi_comm); 563 35 564 36 ::MPI_Comm_rank(peer_comm, &rank_in_world); … … 572 44 573 45 if(ep_rank == local_leader) { is_proc_master = true; is_local_leader = true; is_final_master = true;} 574 if(ep_rank_loc == 0 && mpi_rank != local_comm .rank_map->at(local_leader).second) is_proc_master = true;46 if(ep_rank_loc == 0 && mpi_rank != local_comm->ep_rank_map->at(local_leader).second) is_proc_master = true; 575 47 576 48 … … 633 105 } 634 106 635 ::MPI_Bcast(recv_buf.data(), 4, to_mpi_type(MPI_INT), local_comm .rank_map->at(local_leader).second, local_mpi_comm);107 ::MPI_Bcast(recv_buf.data(), 4, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, local_mpi_comm); 636 108 637 109 size_info[1] = recv_buf[0]; … … 663 135 } 664 136 665 ::MPI_Bcast(recv_buf.data(), 3*size_info[1], to_mpi_type(MPI_INT), local_comm .rank_map->at(local_leader).second, local_mpi_comm);137 ::MPI_Bcast(recv_buf.data(), 3*size_info[1], to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, local_mpi_comm); 666 138 667 139 std::copy ( recv_buf.data(), recv_buf.data() + size_info[1], rank_info[2].begin() ); … … 789 261 } 790 262 791 ::MPI_Bcast(&size_info[2], 2, to_mpi_type(MPI_INT), local_comm .rank_map->at(local_leader).second, local_mpi_comm);263 ::MPI_Bcast(&size_info[2], 2, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, local_mpi_comm); 792 264 793 265 new_rank_info[2].resize(size_info[3]); … … 811 283 } 812 284 813 ::MPI_Bcast(recv_buf.data(), 3*size_info[3], to_mpi_type(MPI_INT), local_comm .rank_map->at(local_leader).second, local_mpi_comm);285 ::MPI_Bcast(recv_buf.data(), 3*size_info[3], to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, local_mpi_comm); 814 286 815 287 std::copy ( recv_buf.data(), recv_buf.data() + size_info[3], new_rank_info[2].begin() ); … … 843 315 } 844 316 845 ::MPI_Bcast(&leader_info[2], 1, to_mpi_type(MPI_INT), local_comm .rank_map->at(local_leader).second, local_mpi_comm);846 847 if(new_comm != static_cast< ::MPI_Comm* >(MPI_COMM_NULL .mpi_comm))317 ::MPI_Bcast(&leader_info[2], 1, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, local_mpi_comm); 318 319 if(new_comm != static_cast< ::MPI_Comm* >(MPI_COMM_NULL->mpi_comm)) 848 320 { 849 321 ::MPI_Barrier(*new_comm); … … 861 333 for(int i= 0; i<my_num_ep; i++) 862 334 { 863 ep_intercomm[i] .is_intercomm = true;864 865 ep_intercomm[i] .ep_comm_ptr->intercomm = new ep_lib::ep_intercomm;866 ep_intercomm[i] .ep_comm_ptr->intercomm->mpi_inter_comm = intercomm;867 ep_intercomm[i] .ep_comm_ptr->comm_label = leader_info[0];335 ep_intercomm[i]->is_intercomm = true; 336 337 ep_intercomm[i]->ep_comm_ptr->intercomm = new ep_lib::ep_intercomm; 338 ep_intercomm[i]->ep_comm_ptr->intercomm->mpi_inter_comm = intercomm; 339 ep_intercomm[i]->ep_comm_ptr->comm_label = leader_info[0]; 868 340 } 869 341 … … 979 451 int intercomm_ep_size, intercomm_num_ep, intercomm_mpi_size; 980 452 981 intercomm_ep_rank = newintercomm->ep_comm_ptr->size_rank_info[0].first;982 intercomm_ep_rank_loc = newintercomm->ep_comm_ptr->size_rank_info[1].first;983 intercomm_mpi_rank = newintercomm->ep_comm_ptr->size_rank_info[2].first;984 intercomm_ep_size = newintercomm->ep_comm_ptr->size_rank_info[0].second;985 intercomm_num_ep = newintercomm->ep_comm_ptr->size_rank_info[1].second;986 intercomm_mpi_size = newintercomm->ep_comm_ptr->size_rank_info[2].second;453 intercomm_ep_rank = (*newintercomm)->ep_comm_ptr->size_rank_info[0].first; 454 intercomm_ep_rank_loc = (*newintercomm)->ep_comm_ptr->size_rank_info[1].first; 455 intercomm_mpi_rank = (*newintercomm)->ep_comm_ptr->size_rank_info[2].first; 456 intercomm_ep_size = (*newintercomm)->ep_comm_ptr->size_rank_info[0].second; 457 intercomm_num_ep = (*newintercomm)->ep_comm_ptr->size_rank_info[1].second; 458 intercomm_mpi_size = (*newintercomm)->ep_comm_ptr->size_rank_info[2].second; 987 459 988 460 … … 994 466 my_rank_map_elem[0] = intercomm_ep_rank; 995 467 996 my_rank_map_elem[1] = (*newintercomm) .ep_comm_ptr->comm_label;468 my_rank_map_elem[1] = (*newintercomm)->ep_comm_ptr->comm_label; 997 469 998 470 vector<pair<int, int> > local_rank_map_array; … … 1000 472 1001 473 1002 (*newintercomm).ep_comm_ptr->intercomm->local_rank_map = new RANK_MAP;1003 (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->resize(local_ep_size);1004 1005 MPI_Allgather(my_rank_map_elem, 2, MPI_INT, (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2, MPI_INT, local_comm);474 //(*newintercomm)->ep_comm_ptr->intercomm->local_rank_map = new RANK_MAP; 475 //(*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->resize(local_ep_size); 476 477 //MPI_Allgather(my_rank_map_elem, 2, MPI_INT, (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->data(), 2, MPI_INT, local_comm); 1006 478 1007 (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP;1008 (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->resize(remote_ep_size);479 //(*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP; 480 //(*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->resize(remote_ep_size); 1009 481 1010 482 int local_intercomm_size = intercomm_ep_size; … … 1016 488 ::MPI_Status status; 1017 489 1018 ::MPI_Send((*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_ep_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);1019 1020 ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status);490 //::MPI_Send((*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_ep_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 491 492 //::MPI_Recv((*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status); 1021 493 1022 494 ::MPI_Send(&local_intercomm_size, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); … … 1025 497 } 1026 498 1027 MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, MPI_INT, local_leader, local_comm);499 //MPI_Bcast((*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, MPI_INT, local_leader, local_comm); 1028 500 MPI_Bcast(&remote_intercomm_size, 1, MPI_INT, 0, *newintercomm); 1029 501 1030 502 1031 (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map = new RANK_MAP;1032 (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->resize(remote_intercomm_size);1033 1034 (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[0] = local_comm.ep_comm_ptr->size_rank_info[0];1035 (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[1] = local_comm.ep_comm_ptr->size_rank_info[1];1036 (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[2] = local_comm.ep_comm_ptr->size_rank_info[2];503 //(*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map = new RANK_MAP; 504 //(*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->resize(remote_intercomm_size); 505 506 //(*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[0] = local_comm->ep_comm_ptr->size_rank_info[0]; 507 //(*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[1] = local_comm->ep_comm_ptr->size_rank_info[1]; 508 //(*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[2] = local_comm->ep_comm_ptr->size_rank_info[2]; 1037 509 1038 510 … … 1040 512 { 1041 513 ::MPI_Status status; 1042 1043 ::MPI_Send((*newintercomm).rank_map->data(), 2*local_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 1044 1045 ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status); 1046 } 1047 1048 MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, MPI_INT, 0, *newintercomm); 1049 1050 (*newintercomm).ep_comm_ptr->intercomm->local_comm = &(local_comm.ep_comm_ptr->comm_list[ep_rank_loc]); 1051 (*newintercomm).ep_comm_ptr->intercomm->intercomm_tag = local_comm.ep_comm_ptr->comm_label; 514 515 std::vector<std::pair<int, std::pair<int, int> > > map2vec((*newintercomm)->ep_rank_map->size()); 516 std::vector<std::pair<int, std::pair<int, int> > > vec2map((*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->size()); 517 518 int ii=0; 519 for(std::map<int, std::pair<int, int> >::iterator it = (*newintercomm)->ep_rank_map->begin(); it != (*newintercomm)->ep_rank_map->end(); it++) 520 { 521 map2vec[ii++] = make_pair(it->first, make_pair(it->second.first, it->second.second)); 522 } 523 524 525 ::MPI_Send(map2vec.data(), 3*local_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm); 526 ::MPI_Recv(vec2map.data(), 3*remote_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status); 527 528 529 for(ii=0; ii<vec2map.size(); ii++) 530 { 531 //(*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(vec2map[ii].first) = make_pair(vec2map[ii].second.first, vec2map[ii].second.second); 532 } 533 } 534 535 //MPI_Bcast((*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, MPI_INT, 0, *newintercomm); 536 537 //(*newintercomm)->ep_comm_ptr->intercomm->local_comm = (local_comm->ep_comm_ptr->comm_list[ep_rank_loc]); 538 (*newintercomm)->ep_comm_ptr->intercomm->intercomm_tag = local_comm->ep_comm_ptr->comm_label; 1052 539 1053 540 return MPI_SUCCESS; -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.cpp
r1495 r1520 4 4 #include <iostream> 5 5 #include <fstream> 6 #include "ep_mpi.hpp" 6 7 7 8 using namespace std; … … 14 15 namespace ep_lib 15 16 { 16 bool MPI_Comm::is_null()17 {18 if(!this->is_intercomm)19 return this->mpi_comm == MPI_COMM_NULL.mpi_comm;20 else21 return this->ep_comm_ptr->intercomm->mpi_inter_comm == MPI_COMM_NULL.mpi_comm;22 }23 17 24 18 int tag_combine(int real_tag, int src, int dest) … … 33 27 int get_ep_rank(MPI_Comm comm, int ep_rank_loc, int mpi_rank) 34 28 { 35 for(int i=0; i<comm.rank_map->size(); i++) 36 { 37 if( ( comm.rank_map->at(i).first == ep_rank_loc ) 38 && ( comm.rank_map->at(i).second == mpi_rank ) ) 39 { 40 return i; 41 } 42 } 43 printf("rank not find\n"); 29 if(comm->is_intercomm) 30 { 31 for(std::map<int, std::pair< int, std::pair<int, int> > >::iterator it = comm->ep_comm_ptr->intercomm->intercomm_rank_map->begin(); it != comm->ep_comm_ptr->intercomm->intercomm_rank_map->end(); it++) 32 { 33 if( ( it->second.first == ep_rank_loc ) 34 && ( it->second.second.first == mpi_rank ) ) 35 { 36 return it->first; 37 } 38 } 39 printf("rank not find for EP_intercomm\n"); 40 int err; 41 return MPI_Abort(comm, err); 42 } 43 44 for(std::map<int, std::pair<int, int> >::iterator it = comm->ep_rank_map->begin(); it != comm->ep_rank_map->end(); it++) 45 { 46 if( ( it->second.first == ep_rank_loc ) 47 && ( it->second.second == mpi_rank ) ) 48 { 49 return it->first; 50 } 51 } 52 printf("rank not find for EP_intracomm\n"); 53 int err; 54 return MPI_Abort(comm, err); 44 55 } 45 56 46 int get_ep_rank_intercomm(MPI_Comm comm, int ep_rank_loc, int mpi_rank)47 {48 // intercomm49 int inter_rank;50 for(int i=0; i<comm.ep_comm_ptr->intercomm->intercomm_rank_map->size(); i++)51 {52 if( ( comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(i).first == ep_rank_loc )53 && ( comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(i).second == mpi_rank ) )54 {55 inter_rank = i;56 break;57 }58 }59 60 for(int i=0; i<comm.ep_comm_ptr->intercomm->remote_rank_map->size(); i++)61 {62 if( comm.ep_comm_ptr->intercomm->remote_rank_map->at(i).first == inter_rank )63 {64 //printf("get_ep_rank for intercomm, ep_rank_loc = %d, mpi_rank = %d => ep_src = %d\n", ep_rank_loc, mpi_rank, i);65 return i;66 }67 }68 69 printf("rank not find\n");70 71 }72 73 57 74 58 int MPI_Get_count(const MPI_Status *status, MPI_Datatype datatype, int *count) 75 59 { 76 77 ::MPI_Status *mpi_status = static_cast< ::MPI_Status* >(status->mpi_status); 78 ::MPI_Datatype *mpi_datatype = static_cast< ::MPI_Datatype*>(datatype); 79 80 ::MPI_Get_count(mpi_status, *mpi_datatype, count); 60 return ::MPI_Get_count(to_mpi_status_ptr(*status), to_mpi_type(datatype), count); 81 61 } 82 62 … … 89 69 void check_sum_send(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, int type) 90 70 { 71 91 72 int src_rank; 92 73 int int_count; … … 121 102 void check_sum_recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, int type) 122 103 { 104 123 105 int dest_rank; 124 106 int int_count; … … 147 129 } 148 130 else printf("Unable to open file\n"); 131 149 132 150 133 } … … 251 234 { 252 235 return *(static_cast< MPI_Comm* >(comm)); 236 } 237 238 MPI_Comm* to_mpi_comm_ptr(void* comm) 239 { 240 return static_cast< MPI_Comm* >(comm); 253 241 } 254 242 … … 258 246 } 259 247 260 MPI_Info to_mpi_info(void* info) 261 { 262 return *(static_cast< MPI_Info* >(info)); 263 } 264 265 266 267 268 248 MPI_Message* to_mpi_message_ptr(ep_lib::MPI_Message message) 249 { 250 return static_cast< MPI_Message* >(message->mpi_message); 251 } 252 253 MPI_Info to_mpi_info(ep_lib::MPI_Info info) 254 { 255 return *(static_cast< MPI_Info* >(info->mpi_info)); 256 } 257 258 MPI_Win to_mpi_win(void* win) 259 { 260 return *(static_cast< MPI_Win* >(win)); 261 } 262 263 MPI_Aint to_mpi_aint(ep_lib::MPI_Aint aint) 264 { 265 return *(static_cast< MPI_Aint* >(aint.mpi_aint)); 266 } 267 268 MPI_Status* to_mpi_status_ptr(ep_lib::MPI_Status status) 269 { 270 return static_cast< MPI_Status* >(status.mpi_status); 271 } 272 273 MPI_Request* to_mpi_request_ptr(ep_lib::MPI_Request request) 274 { 275 return static_cast< MPI_Request* >(request->mpi_request); 276 } 277 278 279 -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.hpp
r1368 r1520 4 4 #include "ep_type.hpp" 5 5 #include "ep_lib_intercomm.hpp" 6 #include "ep_lib_intracomm.hpp" 6 7 #include "ep_lib_local.hpp" 7 8 #include "ep_lib_collective.hpp" 8 9 #include "ep_tag.hpp" 9 10 #include "ep_lib_fortran.hpp" 11 #include "ep_lib_win.hpp" 12 #include "ep_lib_mpi.hpp" 13 //#include "ep_mpi.hpp" 14 10 15 11 16 namespace ep_lib … … 33 38 34 39 int MPI_Get_count(const MPI_Status *status, MPI_Datatype datatype, int *count); 35 36 // #ifdef _openmpi37 // int MPI_Comm_create_endpoints(void* mpi_comm, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls); // from MPI to create endpoints38 // #elif _intelmpi39 // int MPI_Comm_create_endpoints(int mpi_comm, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls); // from MPI to create endpoints40 // #endif41 40 42 int MPI_Comm_ create_endpoints(void* base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls); // from EP to create endpoints41 int MPI_Comm_remote_size(MPI_Comm comm, int *size); 43 42 44 43 int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm); … … 47 46 int MPI_Issend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request); 48 47 49 int tag_combine(int real_tag, int src, int dest);50 int get_ep_rank(MPI_Comm comm, int ep_rank_loc, int mpi_rank);51 int get_ep_rank_intercomm(MPI_Comm comm, int ep_rank_loc, int mpi_rank);52 53 int Message_Check(MPI_Comm comm);54 int Request_Check();55 48 56 49 int MPI_Recv (void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status); … … 74 67 int MPI_Alloc_mem(unsigned long size, MPI_Info info, void *baseptr); 75 68 69 int MPI_Comm_test_inter(MPI_Comm comm, int *flag); 70 76 71 77 72 void check_sum_send(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, int type); … … 81 76 bool valid_op(MPI_Op op); 82 77 78 int tag_combine(int real_tag, int src, int dest); 79 int get_ep_rank(MPI_Comm comm, int ep_rank_loc, int mpi_rank); 80 81 int Message_Check(MPI_Comm comm); 82 83 int Request_Check(); 84 85 int test_sendrecv(MPI_Comm comm); 86 87 83 88 } 84 89 -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_collective.hpp
r1368 r1520 10 10 11 11 int MPI_Barrier(MPI_Comm comm); 12 12 13 13 14 int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm); … … 26 27 27 28 int MPI_Gather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm); 29 28 30 int MPI_Allgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm); 29 31 … … 41 43 int MPI_Alltoall(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm); 42 44 45 int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm); 46 47 int MPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm); 48 49 int MPI_Intercomm_create_kernel(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm); 50 51 52 int MPI_Intercomm_create_from_world(MPI_Comm local_comm, int local_leader, void* peer_comm_ptr, int mpi_remote_leader, int tag, MPI_Comm *newintercomm); 53 54 int MPI_Intercomm_create_unique_leader(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm); 55 56 int MPI_Comm_create_endpoints(void* base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls); // from EP to create endpoints 57 58 59 60 int MPI_Intercomm_merge(MPI_Comm intercomm, bool high, MPI_Comm *newintracomm); 61 62 int MPI_Intercomm_merge_unique_leader(MPI_Comm intercomm, bool high, MPI_Comm *newintracomm); 63 43 64 } 44 65 -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_intercomm.hpp
r1368 r1520 8 8 typedef void* MPI_Op; 9 9 10 10 int MPI_Send_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm); 11 int MPI_Ssend_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm); 12 int MPI_Isend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request); 13 14 int MPI_Issend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request); 15 16 11 17 int MPI_Comm_dup_intercomm(MPI_Comm comm, MPI_Comm *newcomm); 12 18 … … 22 28 23 29 int MPI_Iprobe_intercomm(int source, int tag, MPI_Comm comm, int *flag, MPI_Status *status); 24 int MPI_Iprobe_any_source(int tag, MPI_Comm comm, int *flag, MPI_Status *status);25 30 int MPI_Improbe_intercomm(int source, int tag, MPI_Comm comm, int *flag, MPI_Message *message, MPI_Status *status); 26 int MPI_Improbe_any_source(int tag, MPI_Comm comm, int *flag, MPI_Message *message, MPI_Status *status);27 31 28 int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm);29 32 30 int MPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm);31 33 32 int MPI_Intercomm_create_kernel(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm);33 34 // #ifdef _intelmpi35 // int MPI_Intercomm_create_from_world(MPI_Comm local_comm, int local_leader, int peer_comm_ptr, int mpi_remote_leader, int tag, MPI_Comm *newintercomm);36 // #elif _openmpi37 // int MPI_Intercomm_create_from_world(MPI_Comm local_comm, int local_leader, void* peer_comm_ptr, int mpi_remote_leader, int tag, MPI_Comm *newintercomm);38 // #endif39 40 int MPI_Intercomm_create_from_world(MPI_Comm local_comm, int local_leader, void* peer_comm_ptr, int mpi_remote_leader, int tag, MPI_Comm *newintercomm);41 42 int MPI_Intercomm_create_unique_leader(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm);43 44 int MPI_Intercomm_merge(MPI_Comm intercomm, bool high, MPI_Comm *newintracomm);45 46 int MPI_Intercomm_merge_unique_leader(MPI_Comm intercomm, bool high, MPI_Comm *newintracomm);47 48 int MPI_Comm_remote_size(MPI_Comm comm, int *size);49 50 int MPI_Comm_test_inter(MPI_Comm comm, int *flag);51 52 int test_sendrecv(MPI_Comm comm);53 34 54 35 } -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_local.hpp
r1368 r1520 18 18 19 19 int MPI_Gather_local (const void *sendbuf, int count, MPI_Datatype datatype, void *recvbuf, int local_root, MPI_Comm comm); 20 21 int MPI_Allgather_local (const void *sendbuf, int count, MPI_Datatype datatype, void *recvbuf, MPI_Comm comm); 20 22 21 23 int MPI_Gatherv_local (const void *sendbuf, int count, MPI_Datatype datatype, void *recvbuf, -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_merge.cpp
r1354 r1520 7 7 8 8 9 namespace ep_lib { 9 namespace ep_lib 10 { 10 11 11 12 int MPI_Intercomm_merge_unique_leader(MPI_Comm inter_comm, bool high, MPI_Comm *newintracomm) … … 18 19 int ep_size, num_ep, mpi_size; 19 20 20 ep_rank = inter_comm .ep_comm_ptr->size_rank_info[0].first;21 ep_rank_loc = inter_comm .ep_comm_ptr->size_rank_info[1].first;22 mpi_rank = inter_comm .ep_comm_ptr->size_rank_info[2].first;23 ep_size = inter_comm .ep_comm_ptr->size_rank_info[0].second;24 num_ep = inter_comm .ep_comm_ptr->size_rank_info[1].second;25 mpi_size = inter_comm .ep_comm_ptr->size_rank_info[2].second;21 ep_rank = inter_comm->ep_comm_ptr->size_rank_info[0].first; 22 ep_rank_loc = inter_comm->ep_comm_ptr->size_rank_info[1].first; 23 mpi_rank = inter_comm->ep_comm_ptr->size_rank_info[2].first; 24 ep_size = inter_comm->ep_comm_ptr->size_rank_info[0].second; 25 num_ep = inter_comm->ep_comm_ptr->size_rank_info[1].second; 26 mpi_size = inter_comm->ep_comm_ptr->size_rank_info[2].second; 26 27 27 28 int local_high = high; 28 29 int remote_high; 29 30 30 int remote_ep_size = inter_comm .ep_comm_ptr->intercomm->remote_rank_map->size();31 int remote_ep_size = inter_comm->ep_comm_ptr->intercomm->remote_rank_map->size(); 31 32 32 33 int local_ep_rank, local_ep_rank_loc, local_mpi_rank; 33 34 int local_ep_size, local_num_ep, local_mpi_size; 34 35 35 local_ep_rank = inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[0].first;36 local_ep_rank_loc = inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[1].first;37 local_mpi_rank = inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[2].first;38 local_ep_size = inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[0].second;39 local_num_ep = inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[1].second;40 local_mpi_size = inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[2].second;36 //local_ep_rank = inter_comm->ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[0].first; 37 //local_ep_rank_loc = inter_comm->ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[1].first; 38 //local_mpi_rank = inter_comm->ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[2].first; 39 //local_ep_size = inter_comm->ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[0].second; 40 //local_num_ep = inter_comm->ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[1].second; 41 //local_mpi_size = inter_comm->ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[2].second; 41 42 42 43 … … 45 46 MPI_Status status[2]; 46 47 MPI_Request request[2]; 47 MPI_Isend(&local_high, 1, MPI_INT, 0, inter_comm .ep_comm_ptr->intercomm->intercomm_tag, inter_comm, &request[0]);48 MPI_Irecv(&remote_high, 1, MPI_INT, 0, inter_comm .ep_comm_ptr->intercomm->intercomm_tag, inter_comm, &request[1]);48 MPI_Isend(&local_high, 1, MPI_INT, 0, inter_comm->ep_comm_ptr->intercomm->intercomm_tag, inter_comm, &request[0]); 49 MPI_Irecv(&remote_high, 1, MPI_INT, 0, inter_comm->ep_comm_ptr->intercomm->intercomm_tag, inter_comm, &request[1]); 49 50 50 51 MPI_Waitall(2, request, status); … … 52 53 53 54 54 MPI_Bcast(&remote_high, 1, MPI_INT, 0, *(inter_comm.ep_comm_ptr->intercomm->local_comm));55 //MPI_Bcast(&remote_high, 1, MPI_INT, 0, inter_comm->ep_comm_ptr->intercomm->local_comm); 55 56 56 57 … … 64 65 int intra_ep_size, intra_num_ep, intra_mpi_size; 65 66 66 intra_ep_rank = newintracomm->ep_comm_ptr->size_rank_info[0].first;67 intra_ep_rank_loc = newintracomm->ep_comm_ptr->size_rank_info[1].first;68 intra_mpi_rank = newintracomm->ep_comm_ptr->size_rank_info[2].first;69 intra_ep_size = newintracomm->ep_comm_ptr->size_rank_info[0].second;70 intra_num_ep = newintracomm->ep_comm_ptr->size_rank_info[1].second;71 intra_mpi_size = newintracomm->ep_comm_ptr->size_rank_info[2].second;67 intra_ep_rank = (*newintracomm)->ep_comm_ptr->size_rank_info[0].first; 68 intra_ep_rank_loc = (*newintracomm)->ep_comm_ptr->size_rank_info[1].first; 69 intra_mpi_rank = (*newintracomm)->ep_comm_ptr->size_rank_info[2].first; 70 intra_ep_size = (*newintracomm)->ep_comm_ptr->size_rank_info[0].second; 71 intra_num_ep = (*newintracomm)->ep_comm_ptr->size_rank_info[1].second; 72 intra_mpi_size = (*newintracomm)->ep_comm_ptr->size_rank_info[2].second; 72 73 73 74 … … 85 86 if(intra_ep_rank_loc == 0) 86 87 { 87 ::MPI_Bcast(reorder, intra_ep_size, to_mpi_type(MPI_INT), 0, to_mpi_comm( newintracomm->mpi_comm));88 ::MPI_Bcast(reorder, intra_ep_size, to_mpi_type(MPI_INT), 0, to_mpi_comm((*newintracomm)->mpi_comm)); 88 89 89 90 vector< pair<int, int> > tmp_rank_map(intra_ep_size); … … 92 93 for(int i=0; i<intra_ep_size; i++) 93 94 { 94 tmp_rank_map[reorder[i]] = newintracomm->rank_map->at(i) ; 95 } 96 97 newintracomm->rank_map->swap(tmp_rank_map); 95 tmp_rank_map[reorder[i]] = (*newintracomm)->ep_rank_map->at(i) ; 96 } 97 98 //(*newintracomm)->rank_map->swap(tmp_rank_map); 99 (*newintracomm)->ep_rank_map->clear(); 100 for(int i=0; i<tmp_rank_map.size(); i++) 101 { 102 (*newintracomm)->ep_rank_map->insert(std::pair< int, std::pair<int,int> >(i, tmp_rank_map[i].first, tmp_rank_map[i].second)); 103 } 104 98 105 99 106 tmp_rank_map.clear(); … … 102 109 MPI_Barrier_local(*newintracomm); 103 110 104 (*newintracomm) .ep_comm_ptr->size_rank_info[0].first = my_ep_rank;111 (*newintracomm)->ep_comm_ptr->size_rank_info[0].first = my_ep_rank; 105 112 106 113 if(intra_ep_rank_loc == 0) … … 118 125 int MPI_Intercomm_merge(MPI_Comm inter_comm, bool high, MPI_Comm *newintracomm) 119 126 { 120 121 assert(inter_comm.is_intercomm); 122 123 if(inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->comm_label == -99) 124 { 125 return MPI_Intercomm_merge_unique_leader(inter_comm, high, newintracomm); 126 } 127 128 129 Debug("intercomm_merge kernel\n"); 130 131 int ep_rank_loc; 132 int num_ep; 133 134 ep_rank_loc = inter_comm.ep_comm_ptr->size_rank_info[1].first; 135 num_ep = inter_comm.ep_comm_ptr->size_rank_info[1].second; 136 137 138 139 int remote_ep_size = inter_comm.ep_comm_ptr->intercomm->remote_rank_map->size(); 140 141 142 MPI_Barrier(inter_comm); 143 144 145 ::MPI_Comm *mpi_intracomm = new ::MPI_Comm; 146 MPI_Comm *ep_intracomm; 147 148 if(ep_rank_loc == 0) 149 { 150 151 ::MPI_Comm mpi_comm = to_mpi_comm(inter_comm.ep_comm_ptr->intercomm->mpi_inter_comm); 152 153 ::MPI_Intercomm_merge(mpi_comm, high, mpi_intracomm); 127 128 129 assert(inter_comm->is_intercomm); 130 131 // determine if only one MPI proc 132 133 // to be completed ...... 134 135 // multiple MPI proc and high differs 136 137 int newcomm_ep_rank = inter_comm->ep_comm_ptr->intercomm->size_rank_info[0].first; 138 int newcomm_ep_rank_loc = inter_comm->ep_comm_ptr->intercomm->size_rank_info[1].first; 139 int newcomm_num_ep = inter_comm->ep_comm_ptr->intercomm->size_rank_info[1].second; 140 141 int ep_rank = inter_comm->ep_comm_ptr->size_rank_info[0].first; 142 int ep_rank_loc = inter_comm->ep_comm_ptr->size_rank_info[1].first; 143 int num_ep = inter_comm->ep_comm_ptr->size_rank_info[1].second; 144 145 if(newcomm_ep_rank_loc == 0) 146 { 147 ::MPI_Comm *mpi_intracomm = new ::MPI_Comm; 148 ::MPI_Intercomm_merge(to_mpi_comm(inter_comm->ep_comm_ptr->intercomm->mpi_inter_comm), high, mpi_intracomm); 149 154 150 MPI_Info info; 155 MPI_Comm _create_endpoints(mpi_intracomm, num_ep, info, ep_intracomm);156 157 inter_comm.ep_comm_ptr->comm_list->mem_bridge = ep_intracomm; 158 151 MPI_Comm *ep_comm; 152 MPI_Comm_create_endpoints(mpi_intracomm, newcomm_num_ep, info, ep_comm); 153 154 inter_comm->ep_comm_ptr->comm_list[0]->mem_bridge = ep_comm; 159 155 } 160 156 161 157 MPI_Barrier_local(inter_comm); 162 158 163 int inter_rank; 164 MPI_Comm_rank(inter_comm, &inter_rank); 159 int remote_num_ep = newcomm_num_ep - num_ep; 160 161 *newintracomm = inter_comm->ep_comm_ptr->comm_list[0]->mem_bridge[high? remote_num_ep+ep_rank_loc : ep_rank_loc]; 162 163 int ep_size = inter_comm->ep_comm_ptr->size_rank_info[0].second; 164 int remote_ep_size = inter_comm->ep_comm_ptr->intercomm->intercomm_rank_map->size(); 165 166 //printf("ep_size = %d, remote_ep_size = %d\n", ep_size, remote_ep_size); 167 168 (*newintracomm)->ep_comm_ptr->size_rank_info[0].first = high? remote_ep_size+ep_rank : ep_rank; 169 170 int my_triple[3]; 171 my_triple[0] = (*newintracomm)->ep_comm_ptr->size_rank_info[0].first; 172 my_triple[1] = (*newintracomm)->ep_comm_ptr->size_rank_info[1].first; 173 my_triple[2] = (*newintracomm)->ep_comm_ptr->size_rank_info[2].first; 174 175 int *my_triple_list = new int[3 * (*newintracomm)->ep_comm_ptr->size_rank_info[0].second]; 176 177 178 MPI_Allgather(my_triple, 3, MPI_INT, my_triple_list, 3, MPI_INT, *newintracomm); 179 180 if((*newintracomm)->ep_comm_ptr->size_rank_info[1].first == 0) 181 { 182 (*newintracomm)->ep_rank_map->clear(); 183 for(int i=0; i<(*newintracomm)->ep_comm_ptr->size_rank_info[0].second; i++) 184 { 185 (*newintracomm)->ep_rank_map->insert(std::pair< int, std::pair<int,int> >(my_triple_list[3*i], my_triple_list[3*i+1], my_triple_list[3*i+2])); 186 } 187 } 188 189 #ifdef _showinfo 190 MPI_Barrier_local(inter_comm); 191 if((*newintracomm)->ep_comm_ptr->size_rank_info[0].first == 15) 192 { 193 for(std::map<int, std::pair<int, int> >::iterator it = (*newintracomm)->ep_rank_map->begin(); it != (*newintracomm)->ep_rank_map->end(); it++) 194 { 195 printf("(%d %d %d)\n", it->first, it->second.first, it->second.second); 196 } 197 } 198 #endif 165 199 166 int my_ep_rank = high? inter_rank+remote_ep_size : inter_rank; 167 int my_ep_rank_loc = inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[1].first; 168 int my_num_ep_loc = inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[1].second; 169 int my_num_ep_total = inter_comm.ep_comm_ptr->comm_list->mem_bridge[0].ep_comm_ptr->size_rank_info[1].second; 170 int my_ep_size = inter_comm.ep_comm_ptr->comm_list->mem_bridge[0].ep_comm_ptr->size_rank_info[0].second; 171 172 int tmp_intra_ep_rank_loc = high?my_ep_rank_loc+my_num_ep_total-my_num_ep_loc: my_ep_rank_loc; 173 174 175 *newintracomm = inter_comm.ep_comm_ptr->comm_list->mem_bridge[tmp_intra_ep_rank_loc]; 176 177 int newintracomm_ep_rank = (*newintracomm).ep_comm_ptr->size_rank_info[0].first; 178 int newintracomm_ep_rank_loc = (*newintracomm).ep_comm_ptr->size_rank_info[1].first; 179 int newintracomm_mpi_rank = (*newintracomm).ep_comm_ptr->size_rank_info[2].first; 180 int newintracomm_ep_size = (*newintracomm).ep_comm_ptr->size_rank_info[0].second; 181 int newintracomm_num_ep = (*newintracomm).ep_comm_ptr->size_rank_info[1].second; 182 int newintracomm_mpi_size = (*newintracomm).ep_comm_ptr->size_rank_info[2].second; 183 184 185 int buf[3]; 186 buf[0] = my_ep_rank; 187 buf[1] = tmp_intra_ep_rank_loc; 188 buf[2] = newintracomm->ep_comm_ptr->size_rank_info[2].first; 189 190 // printf("my_ep_rank = %d, tmp_intra_ep_rank_loc = %d, mpi_rank = %d\n", my_ep_rank, tmp_intra_ep_rank_loc, newintracomm->ep_comm_ptr->size_rank_info[2].first); 191 192 int *rankmap_buf; 193 rankmap_buf = new int [3*my_ep_size]; 194 195 MPI_Allgather(buf, 3, MPI_INT, rankmap_buf, 3, MPI_INT, *newintracomm); 196 197 198 // printf(" ID = %d : rankmap_buf = (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d)\n", newintracomm_ep_rank, 199 // rankmap_buf[0], rankmap_buf[1], rankmap_buf[2], rankmap_buf[3], rankmap_buf[4], rankmap_buf[5], rankmap_buf[6], rankmap_buf[7], rankmap_buf[8], rankmap_buf[9], 200 // rankmap_buf[10], rankmap_buf[11], rankmap_buf[12], rankmap_buf[13], rankmap_buf[14], rankmap_buf[15], rankmap_buf[16], rankmap_buf[17], rankmap_buf[18], rankmap_buf[19], 201 // rankmap_buf[20], rankmap_buf[21], rankmap_buf[22], rankmap_buf[23], rankmap_buf[24], rankmap_buf[25], rankmap_buf[26], rankmap_buf[27], rankmap_buf[28], rankmap_buf[29], 202 // rankmap_buf[30], rankmap_buf[31], rankmap_buf[32], rankmap_buf[33], rankmap_buf[34], rankmap_buf[35], rankmap_buf[36], rankmap_buf[37], rankmap_buf[38], rankmap_buf[39], 203 // rankmap_buf[40], rankmap_buf[41], rankmap_buf[42], rankmap_buf[43], rankmap_buf[44], rankmap_buf[45], rankmap_buf[46], rankmap_buf[47]); 204 205 206 for(int i=0; i<newintracomm_ep_size; i++) 207 { 208 (*newintracomm).rank_map->at(rankmap_buf[3*i]).first = rankmap_buf[3*i+1]; 209 (*newintracomm).rank_map->at(rankmap_buf[3*i]).second = rankmap_buf[3*i+2]; 210 } 211 212 213 (*newintracomm).ep_comm_ptr->size_rank_info[0].first = my_ep_rank; 214 (*newintracomm).ep_comm_ptr->size_rank_info[1].first = tmp_intra_ep_rank_loc; 215 216 217 delete[] rankmap_buf; 218 219 220 return MPI_SUCCESS; 221 200 delete my_triple_list; 222 201 } 223 224 202 225 203 } -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_message.cpp
r1374 r1520 18 18 namespace ep_lib 19 19 { 20 20 int Request_Check() 21 { 22 if(EP_PendingRequests == 0 ) EP_PendingRequests = new std::list< MPI_Request* >; 23 24 if(EP_PendingRequests->size() == 0) return 0; 25 26 MPI_Status status; 27 MPI_Message *message; 28 int probed = false; 29 int recv_count = 0; 30 std::list<MPI_Request* >::iterator it; 31 32 33 for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); it++) 34 { 35 Message_Check(((*(*it))->comm)); 36 } 37 38 39 for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); ) 40 { 41 if((*(*it))->state == 0) 42 { 43 #pragma omp critical (_query0) 44 { 45 MPI_Iprobe((*(*it))->ep_src, (*(*it))->ep_tag, ((*(*it))->comm), &probed, &status); 46 if(probed) 47 { 48 message = new MPI_Message; 49 *message = new ep_message; 50 51 memcheck("new "<< message <<" : in ep_lib::Request_Check, message = new MPI_Message"); 52 memcheck("new "<< *message <<" : in ep_lib::Request_Check, *message = new ep_message"); 53 54 55 MPI_Improbe((*(*it))->ep_src, (*(*it))->ep_tag, (*(*it))->comm, &probed, message, &status); 56 57 } 58 } 59 60 61 if(probed) 62 { 63 MPI_Get_count(&status, (*(*it))->ep_datatype, &recv_count); 64 65 MPI_Imrecv((*(*it))->buf, recv_count, (*(*it))->ep_datatype, message, *it); 66 (*(*it))->type = 3; 67 (*(*it))->state = 1; 68 69 memcheck("delete "<< status.mpi_status <<" : in ep_lib::Request_Check, delete status.mpi_status"); 70 delete status.mpi_status; 71 72 memcheck("delete "<< *message <<" : in ep_lib::Request_Check, delete *message"); 73 memcheck("delete "<< message <<" : in ep_lib::Request_Check, delete message"); 74 75 delete *message; 76 delete message; 77 78 it++; 79 continue; 80 } 81 } 82 83 if((*(*it))->state == 2) 84 { 85 int ep_rank = ((*(*it))->comm)->ep_comm_ptr->size_rank_info[0].first; 86 memcheck("delete "<< (*(*it)) <<" : in ep_lib::Request_Check, delete (*(*it))"); 87 88 89 int world_rank; 90 MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); 91 if(world_rank==2) 92 { 93 printf("ep %d erased one pending request %p\n", world_rank,*(*it)); 94 } 95 96 EP_PendingRequests->erase(it); 97 98 memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size()); 99 it = EP_PendingRequests->begin(); 100 continue; 101 } 102 else it++; 103 } 104 } 105 106 107 21 108 int Message_Check(MPI_Comm comm) 22 109 { 23 if(!comm.is_ep) return 0; 24 25 if(comm.is_intercomm) 26 { 27 return Message_Check_intercomm(comm); 28 } 110 if(!comm->is_ep) return MPI_SUCCESS; 111 112 if(comm->is_intercomm) 113 { 114 Message_Check_intercomm(comm); 115 } 116 117 return Message_Check_intracomm(comm); 118 119 } 120 121 122 int Message_Check_intracomm(MPI_Comm comm) 123 { 124 125 int flag = true; 126 ::MPI_Status status; 127 ::MPI_Message message; 128 129 while(flag) // loop until the end of global queue 130 { 131 Debug("Message probing for intracomm\n"); 132 133 #pragma omp critical (_mpi_call) 134 { 135 ::MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, to_mpi_comm(comm->mpi_comm), &flag, &status); 136 if(flag) 137 { 138 Debug("find message in mpi comm \n"); 139 ::MPI_Mprobe(status.MPI_SOURCE, status.MPI_TAG, to_mpi_comm(comm->mpi_comm), &message, &status); 140 } 141 } 142 143 144 if(flag) 145 { 146 MPI_Message msg = new ep_message; 147 msg->mpi_message = new ::MPI_Message(message); 148 149 memcheck("new "<< msg <<" : in ep_lib::Message_Check, msg = new ep_message"); 150 memcheck("new "<< msg->mpi_message <<" : in ep_lib::Message_Check, msg->mpi_message = new ::MPI_Message"); 151 152 153 msg->ep_tag = bitset<15>(status.MPI_TAG >> 16).to_ulong(); 154 int src_loc = bitset<8> (status.MPI_TAG >> 8) .to_ulong(); 155 int dest_loc = bitset<8> (status.MPI_TAG) .to_ulong(); 156 int src_mpi = status.MPI_SOURCE; 157 158 msg->ep_src = get_ep_rank(comm, src_loc, src_mpi); 159 160 #ifdef _showinfo 161 printf("status.MPI_TAG = %d, src_loc = %d, dest_loc = %d, ep_tag = %d\n", status.MPI_TAG, src_loc, dest_loc, msg->ep_tag); 162 #endif 163 164 msg->mpi_status = new ::MPI_Status(status); 165 memcheck("new "<< msg->mpi_status <<" : in ep_lib::Message_Check, msg->mpi_status = new ::MPI_Status"); 166 167 #pragma omp critical (_query) 168 { 169 #pragma omp flush 170 comm->ep_comm_ptr->comm_list[dest_loc]->ep_comm_ptr->message_queue->push_back(msg); 171 int dest_mpi = comm->ep_comm_ptr->size_rank_info[2].first; 172 memcheck("message_queue["<<dest_mpi<<","<<dest_loc<<"]->size = "<<comm->ep_comm_ptr->comm_list[dest_loc]->ep_comm_ptr->message_queue->size()); 173 #pragma omp flush 174 } 175 } 176 } 177 178 return MPI_SUCCESS; 179 } 180 181 182 183 184 185 186 187 int Message_Check_intercomm(MPI_Comm comm) 188 { 189 if(!comm->ep_comm_ptr->intercomm->mpi_inter_comm) return 0; 190 191 Debug("Message probing for intercomm\n"); 29 192 30 193 int flag = true; 31 194 ::MPI_Message message; 32 195 ::MPI_Status status; 33 int mpi_source;34 35 while(flag) // loop until the end of global queue36 {37 Debug("Message probing for intracomm\n");38 39 #pragma omp critical (_mpi_call)40 {41 ::MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, to_mpi_comm(comm.mpi_comm), &flag, &status);42 if(flag)43 {44 Debug("find message in mpi comm \n");45 mpi_source = status.MPI_SOURCE;46 int tag = status.MPI_TAG;47 ::MPI_Mprobe(mpi_source, tag, to_mpi_comm(comm.mpi_comm), &message, &status);48 49 }50 }51 52 53 if(flag)54 {55 56 MPI_Message *msg_block = new MPI_Message;57 msg_block->mpi_message = new ::MPI_Message;58 *(static_cast< ::MPI_Message*>(msg_block->mpi_message)) = message;59 msg_block->ep_tag = bitset<15>(status.MPI_TAG >> 16).to_ulong();60 int src_loc = bitset<8> (status.MPI_TAG >> 8) .to_ulong();61 int dest_loc = bitset<8> (status.MPI_TAG) .to_ulong();62 int src_mpi = status.MPI_SOURCE;63 64 msg_block->ep_src = get_ep_rank(comm, src_loc, src_mpi);65 msg_block->mpi_status = new ::MPI_Status(status);66 67 MPI_Comm* ptr_comm_list = comm.ep_comm_ptr->comm_list;68 MPI_Comm* ptr_comm_target = &ptr_comm_list[dest_loc];69 70 71 #pragma omp critical (_query)72 {73 #pragma omp flush74 comm.ep_comm_ptr->comm_list[dest_loc].ep_comm_ptr->message_queue->push_back(*msg_block);75 #pragma omp flush76 }77 78 delete msg_block;79 }80 81 }82 83 return MPI_SUCCESS;84 }85 86 87 88 int Message_Check_intercomm(MPI_Comm comm)89 {90 if(!comm.ep_comm_ptr->intercomm->mpi_inter_comm) return 0;91 92 Debug("Message probing for intercomm\n");93 94 int flag = true;95 ::MPI_Message message;96 ::MPI_Status status;97 int mpi_source;98 196 int current_ep_rank; 99 197 MPI_Comm_rank(comm, ¤t_ep_rank); 100 198 101 while(flag) // loop until the end of global queue "comm .ep_comm_ptr->intercomm->mpi_inter_comm"199 while(flag) // loop until the end of global queue "comm->ep_comm_ptr->intercomm->mpi_inter_comm" 102 200 { 103 201 Debug("Message probing for intracomm\n"); … … 105 203 #pragma omp critical (_mpi_call) 106 204 { 107 ::MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, to_mpi_comm(comm .ep_comm_ptr->intercomm->mpi_inter_comm), &flag, &status);205 ::MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), &flag, &status); 108 206 if(flag) 109 207 { 110 208 Debug("find message in mpi comm \n"); 111 mpi_source = status.MPI_SOURCE; 112 int tag = status.MPI_TAG; 113 ::MPI_Mprobe(mpi_source, tag, to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm), &message, &status); 114 209 ::MPI_Mprobe(status.MPI_SOURCE, status.MPI_TAG, to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), &message, &status); 115 210 } 116 211 } … … 120 215 { 121 216 122 MPI_Message *msg_block = new MPI_Message; 123 msg_block->mpi_message = new ::MPI_Message; 124 *(static_cast< ::MPI_Message*>(msg_block->mpi_message)) = message; 125 msg_block->ep_tag = bitset<15>(status.MPI_TAG >> 16).to_ulong(); 126 int src_loc = bitset<8> (status.MPI_TAG >> 8) .to_ulong(); 127 int dest_loc = bitset<8> (status.MPI_TAG) .to_ulong(); 128 int src_mpi = status.MPI_SOURCE; 129 int current_inter = comm.ep_comm_ptr->intercomm->local_rank_map->at(current_ep_rank).first; 217 MPI_Message msg = new ep_message; 218 msg->mpi_message = new ::MPI_Message(message); 219 220 memcheck("new "<< msg <<" : in ep_lib::Message_Check, msg = new ep_message"); 221 memcheck("new "<< msg->mpi_message <<" : in ep_lib::Message_Check, msg->mpi_message = new ::MPI_Message"); 222 223 224 msg->ep_tag = bitset<15>(status.MPI_TAG >> 16).to_ulong(); 225 int src_loc = bitset<8> (status.MPI_TAG >> 8) .to_ulong(); 226 int dest_loc = bitset<8> (status.MPI_TAG) .to_ulong(); 227 int src_mpi = status.MPI_SOURCE; 130 228 131 msg _block->ep_src = get_ep_rank_intercomm(comm, src_loc, src_mpi);132 msg_block->mpi_status = new ::MPI_Status(status); 133 134 135 MPI_Comm* ptr_comm_list = comm.ep_comm_ptr->comm_list; 136 MPI_Comm* ptr_comm_target = &ptr_comm_list[dest_loc];137 229 msg->ep_src = get_ep_rank(comm, src_loc, src_mpi); 230 #ifdef _showinfo 231 printf("status.MPI_TAG = %d, src_loc = %d, dest_loc = %d, ep_tag = %d\n", status.MPI_TAG, src_loc, dest_loc, msg->ep_tag); 232 #endif 233 234 msg->mpi_status = new ::MPI_Status(status); 235 memcheck("new "<< msg->mpi_status <<" : in ep_lib::Message_Check, msg->mpi_status = new ::MPI_Status"); 138 236 139 237 #pragma omp critical (_query) 140 238 { 141 239 #pragma omp flush 142 comm.ep_comm_ptr->comm_list[dest_loc].ep_comm_ptr->message_queue->push_back(*msg_block); 143 #pragma omp flush 144 } 145 146 delete msg_block; 147 148 } 149 150 } 151 152 flag = true; 153 while(flag) // loop until the end of global queue "comm.mpi_comm" 154 { 155 Debug("Message probing for intracomm\n"); 156 157 #pragma omp critical (_mpi_call) 158 { 159 ::MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, to_mpi_comm(comm.mpi_comm), &flag, &status); 160 if(flag) 161 { 162 Debug("find message in mpi comm \n"); 163 mpi_source = status.MPI_SOURCE; 164 int tag = status.MPI_TAG; 165 ::MPI_Mprobe(mpi_source, tag, to_mpi_comm(comm.mpi_comm), &message, &status); 166 167 } 168 } 169 170 171 if(flag) 172 { 173 174 MPI_Message *msg_block = new MPI_Message; 175 msg_block->mpi_message = new ::MPI_Message; 176 *(static_cast< ::MPI_Message*>(msg_block->mpi_message)) = message; 177 msg_block->ep_tag = bitset<15>(status.MPI_TAG >> 16).to_ulong(); 178 int src_loc = bitset<8> (status.MPI_TAG >> 8) .to_ulong(); 179 int dest_loc = bitset<8> (status.MPI_TAG) .to_ulong(); 180 int src_mpi = status.MPI_SOURCE; 181 182 msg_block->ep_src = get_ep_rank_intercomm(comm, src_loc, src_mpi); 183 msg_block->mpi_status = new ::MPI_Status(status); 184 185 186 MPI_Comm* ptr_comm_list = comm.ep_comm_ptr->comm_list; 187 MPI_Comm* ptr_comm_target = &ptr_comm_list[dest_loc]; 188 189 190 #pragma omp critical (_query) 191 { 192 #pragma omp flush 193 comm.ep_comm_ptr->comm_list[dest_loc].ep_comm_ptr->message_queue->push_back(*msg_block); 194 #pragma omp flush 195 } 196 197 delete msg_block; 198 199 } 200 201 } 240 comm->ep_comm_ptr->comm_list[dest_loc]->ep_comm_ptr->message_queue->push_back(msg); 241 memcheck("comm->ep_comm_ptr->comm_list["<<dest_loc<<"]->ep_comm_ptr->message_queue->size = "<<comm->ep_comm_ptr->comm_list[dest_loc]->ep_comm_ptr->message_queue->size()); 242 #pragma omp flush 243 } 244 } 245 } 246 247 Message_Check_intracomm(comm); 202 248 203 249 return MPI_SUCCESS; 204 250 } 205 251 206 int Request_Check() 207 { 208 MPI_Status status; 209 MPI_Message message; 210 int probed = false; 211 int recv_count = 0; 212 std::list<MPI_Request* >::iterator it; 213 214 for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); it++) 215 { 216 Message_Check((*it)->comm); 217 } 218 219 220 for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); ) 221 { 222 MPI_Improbe((*it)->ep_src, (*it)->ep_tag, (*it)->comm, &probed, &message, &status); 223 if(probed) 224 { 225 MPI_Get_count(&status, (*it)->ep_datatype, &recv_count); 226 MPI_Imrecv((*it)->buf, recv_count, (*it)->ep_datatype, &message, *it); 227 (*it)->type = 3; 228 EP_PendingRequests->erase(it); 229 it = EP_PendingRequests->begin(); 230 continue; 231 } 232 it++; 233 } 234 } 252 235 253 236 254 } -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_mpi.hpp
r1362 r1520 7 7 MPI_Op to_mpi_op(ep_lib::MPI_Op op); 8 8 MPI_Comm to_mpi_comm(void* comm); 9 MPI_Comm* to_mpi_comm_ptr(void* comm); 9 10 MPI_Message to_mpi_message(void* message); 10 MPI_Info to_mpi_info(void* info); 11 MPI_Info to_mpi_info(ep_lib::MPI_Info info); 12 MPI_Win to_mpi_win(void* win); 13 MPI_Aint to_mpi_aint(ep_lib::MPI_Aint aint); 14 MPI_Status* to_mpi_status_ptr (ep_lib::MPI_Status status); 15 MPI_Request* to_mpi_request_ptr(ep_lib::MPI_Request request); 16 MPI_Message* to_mpi_message_ptr(ep_lib::MPI_Message message); 11 17 12 18 #endif // EP_MPI_HPP_INCLUDED -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_probe.cpp
r1362 r1520 6 6 namespace ep_lib 7 7 { 8 int MPI_Iprobe_mpi(int src, int tag, MPI_Comm comm, int *flag, MPI_Status *status) 9 { 10 status->ep_src = src; 11 status->ep_tag = tag; 12 return ::MPI_Iprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), flag, to_mpi_status_ptr(*status)); 13 } 8 14 9 15 int MPI_Iprobe(int src, int tag, MPI_Comm comm, int *flag, MPI_Status *status) 10 16 { 11 *flag = false; 17 if(!comm->is_ep) 18 { 19 Debug("MPI_Iprobe with MPI\n"); 20 return MPI_Iprobe_mpi(src, tag, comm, flag, status); 21 } 22 23 else 24 { 25 Debug("MPI_Iprobe with EP\n"); 26 27 *flag = false; 28 29 Message_Check(comm); 12 30 13 if(!comm.is_ep) 14 { 15 ::MPI_Status *mpi_status = static_cast< ::MPI_Status* >(status->mpi_status); 16 ::MPI_Iprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm.mpi_comm), flag, mpi_status); 31 #pragma omp flush 17 32 18 status->mpi_status = mpi_status; 19 status->ep_src = src; 20 status->ep_tag = tag; 21 return 0; 22 } 23 24 Debug("calling MPI_Iprobe EP\n"); 25 26 Message_Check(comm); 27 28 #pragma omp flush 29 30 #pragma omp critical (_query) 31 if(!comm.ep_comm_ptr->message_queue->empty()) 32 { 33 for(Message_list::iterator it = comm.ep_comm_ptr->message_queue->begin(); it!= comm.ep_comm_ptr->message_queue->end(); ++it) 33 #pragma omp critical (_query) 34 for(Message_list::iterator it = comm->ep_comm_ptr->message_queue->begin(); it!= comm->ep_comm_ptr->message_queue->end(); ++it) 34 35 { 35 bool src_matched = src<0? true: it->ep_src == src;36 bool tag_matched = tag<0? true: it->ep_tag == tag;36 bool src_matched = src<0? true: (*it)->ep_src == src; 37 bool tag_matched = tag<0? true: (*it)->ep_tag == tag; 37 38 38 39 if(src_matched && tag_matched) 39 40 { 40 41 Debug("find message\n"); 42 43 44 status->mpi_status = new ::MPI_Status(*static_cast< ::MPI_Status*>((*it)->mpi_status)); 45 status->ep_src = (*it)->ep_src; 46 status->ep_tag = (*it)->ep_tag; 47 41 48 *flag = true; 42 43 ::MPI_Status mpi_status = *(static_cast< ::MPI_Status *>(it->mpi_status));44 45 status->mpi_status = new ::MPI_Status(mpi_status);46 status->ep_src = it->ep_src;47 status->ep_tag = it->ep_tag;48 49 49 break; 50 50 } 51 52 51 } 53 52 } 54 55 return 0;56 53 } 57 54 … … 60 57 int MPI_Improbe(int src, int tag, MPI_Comm comm, int *flag, MPI_Message *message, MPI_Status *status) 61 58 { 59 int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; 60 int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first; 62 61 *flag = false; 63 if(!comm .is_ep)62 if(!comm->is_ep) 64 63 { 65 64 Debug("calling MPI_Improbe MPI\n"); … … 71 70 #pragma omp critical (_mpi_call) 72 71 { 73 ::MPI_Iprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm .mpi_comm), flag, &mpi_status);72 ::MPI_Iprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), flag, &mpi_status); 74 73 if(*flag) 75 74 { 76 ::MPI_Mprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm .mpi_comm), &mpi_message, &mpi_status);75 ::MPI_Mprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), &mpi_message, &mpi_status); 77 76 } 78 77 } 79 78 #elif _intelmpi 80 ::MPI_Improbe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm .mpi_comm), flag, &mpi_message, &mpi_status);79 ::MPI_Improbe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), flag, &mpi_message, &mpi_status); 81 80 #endif 82 81 83 status->mpi_status = new ::MPI_Status(mpi_status);82 status->mpi_status = &mpi_status; 84 83 status->ep_src = src; 85 84 status->ep_tag = tag; 86 85 87 message->mpi_message = new ::MPI_Message; 88 *(static_cast< ::MPI_Message*>(message->mpi_message)) = mpi_message; 89 message->ep_src = src; 90 message->ep_tag = tag; 86 (*message)->mpi_message = &message; 87 (*message)->ep_src = src; 88 (*message)->ep_tag = tag; 89 90 91 91 return 0; 92 92 } 93 93 94 95 //Message_Check(comm); 94 96 95 97 96 #pragma omp flush 98 97 99 98 #pragma omp critical (_query) 100 if(! comm .ep_comm_ptr->message_queue->empty())99 if(! comm->ep_comm_ptr->message_queue->empty()) 101 100 { 102 for(Message_list::iterator it = comm .ep_comm_ptr->message_queue->begin(); it!= comm.ep_comm_ptr->message_queue->end(); ++it)101 for(Message_list::iterator it = comm->ep_comm_ptr->message_queue->begin(); it!= comm->ep_comm_ptr->message_queue->end(); ++it) 103 102 { 104 bool src_matched = src<0? true: it->ep_src == src; 105 bool tag_matched = tag<0? true: it->ep_tag == tag; 103 104 bool src_matched = src<0? true: (*it)->ep_src == src; 105 bool tag_matched = tag<0? true: (*it)->ep_tag == tag; 106 106 107 107 if(src_matched && tag_matched) … … 109 109 *flag = true; 110 110 111 ::MPI_Status mpi_status; 112 mpi_status = *(static_cast< ::MPI_Status *>(it->mpi_status)); 111 status->mpi_status = new ::MPI_Status(*static_cast< ::MPI_Status*>((*it)->mpi_status)); 112 memcheck("new "<< status->mpi_status << " : in ep_lib::MPI_Improbe, status->mpi_status = new ::MPI_Status"); 113 status->ep_src = (*it)->ep_src; 114 status->ep_tag = (*it)->ep_tag; 113 115 114 status->mpi_status = new ::MPI_Status(mpi_status); 115 status->ep_src = it->ep_src; 116 status->ep_tag = it->ep_tag; 117 118 message->mpi_message = it->mpi_message; 119 message->ep_tag = it->ep_tag; 120 message->ep_src = it->ep_src; 116 (*message)->mpi_message = new ::MPI_Message(*static_cast< ::MPI_Message*>((*it)->mpi_message)); 117 memcheck("new "<< (*message)->mpi_message <<" : in ep_lib::MPI_Improbe, (*message)->mpi_message = new ::MPI_Message"); 118 (*message)->ep_src = (*it)->ep_src; 119 (*message)->ep_tag = (*it)->ep_tag; 120 121 121 122 122 #pragma omp critical (_query2) 123 123 { 124 delete it->mpi_status; 125 comm.ep_comm_ptr->message_queue->erase(it); 124 memcheck("delete "<< (*it)->mpi_message <<" : in ep_lib::Message_Check, delete (*it)->mpi_message"); 125 memcheck("delete "<< (*it)->mpi_status <<" : in ep_lib::Message_Check, delete (*it)->mpi_status"); 126 memcheck("delete "<< (*it) <<" : in ep_lib::Message_Check, delete (*it)"); 127 128 129 delete (*it)->mpi_message; 130 delete (*it)->mpi_status; 131 delete *it; 132 133 134 comm->ep_comm_ptr->message_queue->erase(it); 135 memcheck("message_queue["<<mpi_rank<<","<<ep_rank_loc<<"]->size = "<<comm->ep_comm_ptr->message_queue->size()); 126 136 #pragma omp flush 127 137 } 128 138 129 139 break; 130 140 } -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_rank.cpp
r1354 r1520 7 7 { 8 8 9 int MPI_Comm_rank(MPI_Comm comm, int* rank) 10 { 11 if(comm->is_ep) 12 { 13 Debug("MPI_Comm_rank with EP"); 14 return *rank = comm->ep_comm_ptr->size_rank_info[0].first; 15 } 16 17 return MPI_Comm_rank_mpi(comm, rank); 18 } 9 19 10 20 11 int MPI_Comm_rank (MPI_Comm comm, int* rank)21 int MPI_Comm_rank_mpi(MPI_Comm comm, int* rank) 12 22 { 13 14 if(comm.is_ep) 15 { 16 Debug("Calling EP_Comm_rank\n"); 17 18 if(comm.is_intercomm) 19 { 20 *rank = comm.ep_comm_ptr->intercomm->size_rank_info[0].first; 21 return 0; 22 } 23 else 24 { 25 *rank = comm.ep_comm_ptr->size_rank_info[0].first; 26 return 0; 27 } 28 } 29 30 31 if(comm != MPI_COMM_NULL) 32 { 33 ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm); 34 ::MPI_Comm_rank(mpi_comm, rank); 35 return 0; 36 } 37 else 38 { 39 printf("rank is undefined\n"); 40 41 *rank = MPI_UNDEFINED; 42 return 0; 43 } 44 23 Debug("MPI_Comm_rank with MPI"); 24 return ::MPI_Comm_rank(to_mpi_comm(comm->mpi_comm), rank); 45 25 } 46 47 26 48 27 -
XIOS/dev/branch_openmp/extern/src_ep_dev/ep_recv.cpp
r1374 r1520 19 19 namespace ep_lib 20 20 { 21 22 21 23 22 int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status) 24 23 { 25 24 26 if(!comm.is_ep) 27 { 28 ::MPI_Status mpi_status; 29 ::MPI_Recv(buf, count, to_mpi_type(datatype), src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm.mpi_comm), &mpi_status); 30 31 status->ep_src = src; 32 status->ep_tag = tag; 33 status->ep_datatype = datatype; 34 35 return 0; 36 } 37 38 Message_Check(comm); 25 if(!comm->is_ep) return MPI_Recv_mpi(buf, count, datatype, src, tag, comm, status); 26 27 Debug("MPI_Recv with EP"); 39 28 40 29 MPI_Request request; … … 45 34 } 46 35 47 36 48 37 49 38 50 39 int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request) 51 40 { 52 41 if(!comm->is_ep) return MPI_Irecv_mpi(buf, count, datatype, src, tag, comm, request); 42 53 43 Debug("MPI_Irecv with EP"); 54 44 int dest_rank; 55 45 MPI_Comm_rank(comm, &dest_rank); 56 46 47 *request = new ep_request; 48 memcheck("new " << *request <<" : in ep_lib::MPI_Irecv, *request = new ep_request"); 57 49 58 if(!comm.is_ep) 50 (*request)->mpi_request = new ::MPI_Request; 51 memcheck("new " << (*request)->mpi_request << " : in ep_lib::MPI_Irecv, (*request)->mpi_request = new ::MPI_Request"); 52 53 (*request)->buf = buf; 54 (*request)->comm = comm; 55 (*request)->type = 2; 56 (*request)->state = 0; 57 58 59 (*request)->ep_src = src; 60 (*request)->ep_tag = tag; 61 (*request)->ep_datatype = datatype; 62 63 if(EP_PendingRequests == 0 ) EP_PendingRequests = new std::list< MPI_Request* >; 64 65 EP_PendingRequests->push_back(request); 66 67 int world_rank; 68 MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); 69 if(world_rank==2) 59 70 { 60 ::MPI_Request mpi_request; 61 ::MPI_Irecv(buf, count, to_mpi_type(datatype), src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm.mpi_comm), &mpi_request); 71 printf("ep %d inserted one pending request %p\n", world_rank, *request); 72 } 73 74 memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size()); 62 75 63 request->mpi_request = new ::MPI_Request(mpi_request); 64 request->ep_src = src; 65 request->ep_datatype = datatype; 66 request->ep_tag = tag; 67 } 76 #ifdef _showinfo 77 if(comm->is_intercomm) 78 { 79 int ep_dest_loc = comm->ep_rank_map->at(dest_rank).first; 80 int ep_src_loc = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(src).first; 81 int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc); 82 int mpi_dest = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(src).second.first; 68 83 69 request->buf = buf;70 request->comm = comm;71 request->type = 2; 84 printf("Irecv : ep_src_loc = %d, ep_dest_loc = %d, mpi_src = %d, mpi_dest = %d, mpi_tag = %d\n", ep_src_loc, ep_dest_loc, comm->ep_comm_ptr->size_rank_info[2].first, mpi_dest, mpi_tag); 85 } 86 #endif 72 87 73 request->ep_src = src; 74 request->ep_tag = tag; 75 request->ep_datatype = datatype; 88 return Request_Check(); 89 } 90 91 int MPI_Mrecv(void *buf, int count, MPI_Datatype datatype, MPI_Message *message, MPI_Status *status) 92 { 93 Debug("MPI_Mrecv with MPI/EP"); 76 94 95 status->mpi_status = new ::MPI_Status; 96 memcheck("new " << status->mpi_status << " : in ep_lib::MPI_Mrecv, status->mpi_status = new ::MPI_Status"); 97 98 ::MPI_Mrecv(buf, count, to_mpi_type(datatype), static_cast< ::MPI_Message* >((*message)->mpi_message), to_mpi_status_ptr(*status)); 77 99 100 101 status->ep_src = (*message)->ep_src; 102 status->ep_datatype = datatype; 103 status->ep_tag = (*message)->ep_tag; 78 104 79 /* With Improbe*/80 Message_Check(comm);105 memcheck("delete " << (*message)->mpi_message << " : in ep_lib::MPI_Mrecv, delete (*message)->mpi_message"); 106 delete (*message)->mpi_message; 81 107 82 if(EP_PendingRequests == 0 ) 83 { 84 EP_PendingRequests = new std::list< MPI_Request* >; 85 } 108 #ifdef _check_sum 109 check_sum_recv(buf, count, datatype, message->ep_src, message->ep_tag); 110 #endif 86 111 112 return Request_Check(); 113 } 87 114 88 EP_PendingRequests->push_back(request);89 90 91 Request_Check();92