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