[1646] | 1 | #ifdef _usingEP |
---|
[1603] | 2 | #include "ep_lib.hpp" |
---|
| 3 | #include <mpi.h> |
---|
| 4 | #include "ep_declaration.hpp" |
---|
| 5 | #include "ep_mpi.hpp" |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | namespace ep_lib |
---|
| 9 | { |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | int MPI_Win_create(void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win) |
---|
| 13 | { |
---|
| 14 | int rank, rank_loc, num_ep; |
---|
| 15 | MPI_Comm_rank(comm, &rank); |
---|
| 16 | rank_loc = comm->ep_comm_ptr->size_rank_info[1].first; |
---|
| 17 | num_ep = comm->ep_comm_ptr->size_rank_info[1].second; |
---|
| 18 | |
---|
| 19 | *win = new ep_win; |
---|
| 20 | |
---|
| 21 | (*win)->is_ep = comm->is_ep; |
---|
| 22 | |
---|
| 23 | int num_ep_max; |
---|
| 24 | MPI_Allreduce(&num_ep, &num_ep_max, 1, MPI_INT, MPI_MAX, comm); |
---|
| 25 | |
---|
| 26 | assert(num_ep_max > 1); |
---|
| 27 | |
---|
| 28 | info = new ep_info; |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | if(num_ep == 1) // server |
---|
| 33 | { |
---|
| 34 | for(int i=0; i<num_ep_max; i++) |
---|
| 35 | { |
---|
| 36 | (*win)->server_win[i] = new ::MPI_Win; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | printf("Calling MPI_Win_create from server, rank = %d\n", rank); |
---|
| 40 | for(int i=0; i<num_ep_max; i++) |
---|
| 41 | { |
---|
| 42 | ::MPI_Win_create(base, to_mpi_aint(size), disp_unit, to_mpi_info(info), to_mpi_comm(comm->mpi_comm), static_cast< ::MPI_Win*>((*win)->server_win[i])); |
---|
| 43 | (*win)->comm = comm; |
---|
| 44 | } |
---|
| 45 | } |
---|
| 46 | else // client |
---|
| 47 | { |
---|
| 48 | (*win)->client_win = new ::MPI_Win; |
---|
| 49 | |
---|
| 50 | for(int i=0; i<num_ep; i++) |
---|
| 51 | { |
---|
| 52 | if(rank_loc == i) |
---|
| 53 | { |
---|
| 54 | printf("Calling MPI_Win_create from client, rank = %d\n", rank); |
---|
| 55 | ::MPI_Win_create(base, to_mpi_aint(size), disp_unit, to_mpi_info(info), to_mpi_comm(comm->mpi_comm), static_cast< ::MPI_Win*>((*win)->client_win)); |
---|
| 56 | (*win)->comm = comm; |
---|
| 57 | } |
---|
| 58 | MPI_Barrier_local(comm); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | if(num_ep_max > num_ep) |
---|
| 62 | { |
---|
| 63 | |
---|
| 64 | #pragma omp master |
---|
| 65 | { |
---|
| 66 | for(int i=0; i<num_ep_max-num_ep; i++) |
---|
| 67 | { |
---|
| 68 | (*win)->null_win[i] = new ::MPI_Win; |
---|
| 69 | ::MPI_Win_create(NULL, 0, disp_unit, to_mpi_info(info), to_mpi_comm(comm->mpi_comm), static_cast< ::MPI_Win*>((*win)->null_win[i])); |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | } |
---|
| 75 | return 0; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | int MPI_Win_free(MPI_Win *win) |
---|
| 81 | { |
---|
| 82 | int rank, rank_loc, num_ep; |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | MPI_Comm_rank((*win)->comm, &rank); |
---|
| 86 | rank_loc = (*win)->comm->ep_comm_ptr->size_rank_info[1].first; |
---|
| 87 | num_ep = (*win)->comm->ep_comm_ptr->size_rank_info[1].second; |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | int num_ep_max; |
---|
| 91 | MPI_Allreduce(&num_ep, &num_ep_max, 1, MPI_INT, MPI_MAX, (*win)->comm); |
---|
| 92 | |
---|
| 93 | //printf("rank_loc = %d, thread_num = %d, num_ep_max = %d\n", rank_loc, omp_get_thread_num(), num_ep_max); |
---|
| 94 | |
---|
| 95 | if(num_ep == 1) |
---|
| 96 | { |
---|
| 97 | printf("Calling MPI_Win_free from server, rank = %d\n", rank); |
---|
| 98 | for(int i=0; i<num_ep_max; i++) |
---|
| 99 | { |
---|
| 100 | ::MPI_Win_free(static_cast< ::MPI_Win*>((*win)->server_win[i])); |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | else |
---|
| 104 | { |
---|
| 105 | for(int i=0; i<num_ep; i++) |
---|
| 106 | { |
---|
| 107 | if(rank_loc == i) |
---|
| 108 | { |
---|
| 109 | printf("Calling MPI_Win_free from client, rank = %d\n", rank); |
---|
| 110 | ::MPI_Win_free(static_cast< ::MPI_Win*>((*win)->client_win)); |
---|
| 111 | } |
---|
| 112 | MPI_Barrier_local((*win)->comm); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | if(num_ep_max > num_ep) |
---|
| 117 | { |
---|
| 118 | #pragma omp master |
---|
| 119 | { |
---|
| 120 | for(int i=0; i<num_ep_max-num_ep; i++) |
---|
| 121 | { |
---|
| 122 | ::MPI_Win_free(static_cast< ::MPI_Win*>((*win)->null_win[i])); |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | } |
---|
| 128 | return 0; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | int MPI_Win_fence(int assert, MPI_Win win) |
---|
| 134 | { |
---|
| 135 | int rank, rank_loc, num_ep; |
---|
| 136 | |
---|
| 137 | MPI_Comm_rank(win->comm, &rank); |
---|
| 138 | rank_loc = win->comm->ep_comm_ptr->size_rank_info[1].first; |
---|
| 139 | num_ep = win->comm->ep_comm_ptr->size_rank_info[1].second; |
---|
| 140 | |
---|
| 141 | int num_ep_max; |
---|
| 142 | MPI_Allreduce(&num_ep, &num_ep_max, 1, MPI_INT, MPI_MAX, win->comm); |
---|
| 143 | |
---|
| 144 | if(num_ep == 1) |
---|
| 145 | { |
---|
| 146 | printf("Calling MPI_Win_fence from server, rank = %d\n", rank); |
---|
| 147 | for(int i=0; i<num_ep_max; i++) |
---|
| 148 | { |
---|
| 149 | ::MPI_Win_fence(assert, *static_cast< ::MPI_Win*>(win->server_win[i])); |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | else |
---|
| 153 | { |
---|
| 154 | for(int i=0; i<num_ep; i++) |
---|
| 155 | { |
---|
| 156 | if(rank_loc == i) |
---|
| 157 | { |
---|
| 158 | printf("Calling MPI_Win_fence from client, rank = %d\n", rank); |
---|
| 159 | ::MPI_Win_fence(assert, *static_cast< ::MPI_Win*>(win->client_win)); |
---|
| 160 | } |
---|
| 161 | MPI_Barrier_local(win->comm); |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | if(num_ep_max > num_ep) |
---|
| 166 | { |
---|
| 167 | #pragma omp master |
---|
| 168 | { |
---|
| 169 | for(int i=0; i<num_ep_max-num_ep; i++) |
---|
| 170 | { |
---|
| 171 | ::MPI_Win_fence(assert, *static_cast< ::MPI_Win*>(win->null_win[i])); |
---|
| 172 | } |
---|
| 173 | } |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | return 0; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | |
---|
[1646] | 183 | #endif |
---|