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