| 1 | /* -*- Mode: C; c-basic-offset:4 ; -*- */ |
|---|
| 2 | /* |
|---|
| 3 | * (C) 2001 by Argonne National Laboratory. |
|---|
| 4 | * See COPYRIGHT in top-level directory. |
|---|
| 5 | */ |
|---|
| 6 | |
|---|
| 7 | #include "mpidi_ch3_impl.h" |
|---|
| 8 | #include "mpidrma.h" |
|---|
| 9 | |
|---|
| 10 | #define MPIDI_PASSIVE_TARGET_DONE_TAG 348297 |
|---|
| 11 | #define MPIDI_PASSIVE_TARGET_RMA_TAG 563924 |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #undef FUNCNAME |
|---|
| 15 | #define FUNCNAME MPIDI_Win_create |
|---|
| 16 | #undef FCNAME |
|---|
| 17 | #define FCNAME MPIDI_QUOTE(FUNCNAME) |
|---|
| 18 | int MPIDI_Win_create(void *base, MPI_Aint size, int disp_unit, MPID_Info *info, |
|---|
| 19 | MPID_Comm *comm_ptr, MPID_Win **win_ptr ) |
|---|
| 20 | { |
|---|
| 21 | int mpi_errno=MPI_SUCCESS, i, comm_size, rank; |
|---|
| 22 | MPI_Aint *tmp_buf; |
|---|
| 23 | MPIU_CHKPMEM_DECL(4); |
|---|
| 24 | MPIU_CHKLMEM_DECL(1); |
|---|
| 25 | MPIU_THREADPRIV_DECL; |
|---|
| 26 | MPIDI_STATE_DECL(MPID_STATE_MPIDI_WIN_CREATE); |
|---|
| 27 | |
|---|
| 28 | MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPIDI_WIN_CREATE); |
|---|
| 29 | |
|---|
| 30 | /* FIXME: There should be no unreferenced args */ |
|---|
| 31 | MPIU_UNREFERENCED_ARG(info); |
|---|
| 32 | |
|---|
| 33 | MPIU_THREADPRIV_GET; |
|---|
| 34 | |
|---|
| 35 | MPIR_Nest_incr(); |
|---|
| 36 | |
|---|
| 37 | comm_size = comm_ptr->local_size; |
|---|
| 38 | rank = comm_ptr->rank; |
|---|
| 39 | |
|---|
| 40 | *win_ptr = (MPID_Win *)MPIU_Handle_obj_alloc( &MPID_Win_mem ); |
|---|
| 41 | MPIU_ERR_CHKANDJUMP(!(*win_ptr),mpi_errno,MPI_ERR_OTHER,"**nomem"); |
|---|
| 42 | |
|---|
| 43 | (*win_ptr)->fence_cnt = 0; |
|---|
| 44 | (*win_ptr)->base = base; |
|---|
| 45 | (*win_ptr)->size = size; |
|---|
| 46 | (*win_ptr)->disp_unit = disp_unit; |
|---|
| 47 | (*win_ptr)->start_group_ptr = NULL; |
|---|
| 48 | (*win_ptr)->start_assert = 0; |
|---|
| 49 | (*win_ptr)->attributes = NULL; |
|---|
| 50 | (*win_ptr)->rma_ops_list = NULL; |
|---|
| 51 | (*win_ptr)->lock_granted = 0; |
|---|
| 52 | (*win_ptr)->current_lock_type = MPID_LOCK_NONE; |
|---|
| 53 | (*win_ptr)->shared_lock_ref_cnt = 0; |
|---|
| 54 | (*win_ptr)->lock_queue = NULL; |
|---|
| 55 | (*win_ptr)->my_counter = 0; |
|---|
| 56 | (*win_ptr)->my_pt_rma_puts_accs = 0; |
|---|
| 57 | |
|---|
| 58 | mpi_errno = NMPI_Comm_dup(comm_ptr->handle, &((*win_ptr)->comm)); |
|---|
| 59 | if (mpi_errno) { MPIU_ERR_POP(mpi_errno); } |
|---|
| 60 | |
|---|
| 61 | /* allocate memory for the base addresses, disp_units, and |
|---|
| 62 | completion counters of all processes */ |
|---|
| 63 | MPIU_CHKPMEM_MALLOC((*win_ptr)->base_addrs, void **, |
|---|
| 64 | comm_size*sizeof(void *), |
|---|
| 65 | mpi_errno, "(*win_ptr)->base_addrs"); |
|---|
| 66 | |
|---|
| 67 | MPIU_CHKPMEM_MALLOC((*win_ptr)->disp_units, int *, comm_size*sizeof(int), |
|---|
| 68 | mpi_errno, "(*win_ptr)->disp_units"); |
|---|
| 69 | |
|---|
| 70 | MPIU_CHKPMEM_MALLOC((*win_ptr)->all_win_handles, MPI_Win *, |
|---|
| 71 | comm_size*sizeof(MPI_Win), |
|---|
| 72 | mpi_errno, "(*win_ptr)->all_win_handles"); |
|---|
| 73 | |
|---|
| 74 | MPIU_CHKPMEM_MALLOC((*win_ptr)->pt_rma_puts_accs, int *, |
|---|
| 75 | comm_size*sizeof(int), |
|---|
| 76 | mpi_errno, "(*win_ptr)->pt_rma_puts_accs"); |
|---|
| 77 | for (i=0; i<comm_size; i++) (*win_ptr)->pt_rma_puts_accs[i] = 0; |
|---|
| 78 | |
|---|
| 79 | /* get the addresses of the windows, window objects, and completion |
|---|
| 80 | counters of all processes. allocate temp. buffer for communication */ |
|---|
| 81 | MPIU_CHKLMEM_MALLOC(tmp_buf, MPI_Aint *, 3*comm_size*sizeof(MPI_Aint), |
|---|
| 82 | mpi_errno, "tmp_buf"); |
|---|
| 83 | |
|---|
| 84 | /* FIXME: This needs to be fixed for heterogeneous systems */ |
|---|
| 85 | tmp_buf[3*rank] = MPIU_PtrToAint(base); |
|---|
| 86 | tmp_buf[3*rank+1] = (MPI_Aint) disp_unit; |
|---|
| 87 | tmp_buf[3*rank+2] = (MPI_Aint) (*win_ptr)->handle; |
|---|
| 88 | |
|---|
| 89 | mpi_errno = NMPI_Allgather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, |
|---|
| 90 | tmp_buf, 3 * sizeof(MPI_Aint), MPI_BYTE, |
|---|
| 91 | comm_ptr->handle); |
|---|
| 92 | if (mpi_errno) { MPIU_ERR_POP(mpi_errno); } |
|---|
| 93 | |
|---|
| 94 | for (i=0; i<comm_size; i++) |
|---|
| 95 | { |
|---|
| 96 | (*win_ptr)->base_addrs[i] = MPIU_AintToPtr(tmp_buf[3*i]); |
|---|
| 97 | (*win_ptr)->disp_units[i] = (int) tmp_buf[3*i+1]; |
|---|
| 98 | (*win_ptr)->all_win_handles[i] = (MPI_Win) tmp_buf[3*i+2]; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | fn_exit: |
|---|
| 102 | MPIR_Nest_decr(); |
|---|
| 103 | MPIU_CHKLMEM_FREEALL(); |
|---|
| 104 | MPIDI_RMA_FUNC_EXIT(MPID_STATE_MPIDI_WIN_CREATE); |
|---|
| 105 | return mpi_errno; |
|---|
| 106 | /* --BEGIN ERROR HANDLING-- */ |
|---|
| 107 | fn_fail: |
|---|
| 108 | MPIU_CHKPMEM_REAP(); |
|---|
| 109 | goto fn_exit; |
|---|
| 110 | /* --END ERROR HANDLING-- */ |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | #undef FUNCNAME |
|---|
| 117 | #define FUNCNAME MPIDI_Win_free |
|---|
| 118 | #undef FCNAME |
|---|
| 119 | #define FCNAME MPIDI_QUOTE(FUNCNAME) |
|---|
| 120 | int MPIDI_Win_free(MPID_Win **win_ptr) |
|---|
| 121 | { |
|---|
| 122 | int mpi_errno=MPI_SUCCESS, total_pt_rma_puts_accs, i, *recvcnts, comm_size; |
|---|
| 123 | MPID_Comm *comm_ptr; |
|---|
| 124 | MPIU_CHKLMEM_DECL(1); |
|---|
| 125 | MPIU_THREADPRIV_DECL; |
|---|
| 126 | |
|---|
| 127 | MPIDI_STATE_DECL(MPID_STATE_MPIDI_WIN_FREE); |
|---|
| 128 | |
|---|
| 129 | MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPIDI_WIN_FREE); |
|---|
| 130 | |
|---|
| 131 | MPIU_THREADPRIV_GET; |
|---|
| 132 | MPIR_Nest_incr(); |
|---|
| 133 | |
|---|
| 134 | /* set up the recvcnts array for the reduce scatter to check if all |
|---|
| 135 | passive target rma operations are done */ |
|---|
| 136 | MPID_Comm_get_ptr( (*win_ptr)->comm, comm_ptr ); |
|---|
| 137 | comm_size = comm_ptr->local_size; |
|---|
| 138 | |
|---|
| 139 | MPIU_CHKLMEM_MALLOC(recvcnts, int *, comm_size*sizeof(int), mpi_errno, |
|---|
| 140 | "recvcnts"); |
|---|
| 141 | for (i=0; i<comm_size; i++) recvcnts[i] = 1; |
|---|
| 142 | |
|---|
| 143 | mpi_errno = NMPI_Reduce_scatter((*win_ptr)->pt_rma_puts_accs, |
|---|
| 144 | &total_pt_rma_puts_accs, recvcnts, |
|---|
| 145 | MPI_INT, MPI_SUM, (*win_ptr)->comm); |
|---|
| 146 | if (mpi_errno) { MPIU_ERR_POP(mpi_errno); } |
|---|
| 147 | |
|---|
| 148 | if (total_pt_rma_puts_accs != (*win_ptr)->my_pt_rma_puts_accs) |
|---|
| 149 | { |
|---|
| 150 | MPID_Progress_state progress_state; |
|---|
| 151 | |
|---|
| 152 | /* poke the progress engine until the two are equal */ |
|---|
| 153 | MPID_Progress_start(&progress_state); |
|---|
| 154 | while (total_pt_rma_puts_accs != (*win_ptr)->my_pt_rma_puts_accs) |
|---|
| 155 | { |
|---|
| 156 | mpi_errno = MPID_Progress_wait(&progress_state); |
|---|
| 157 | /* --BEGIN ERROR HANDLING-- */ |
|---|
| 158 | if (mpi_errno != MPI_SUCCESS) |
|---|
| 159 | { |
|---|
| 160 | MPID_Progress_end(&progress_state); |
|---|
| 161 | MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**winnoprogress"); |
|---|
| 162 | } |
|---|
| 163 | /* --END ERROR HANDLING-- */ |
|---|
| 164 | } |
|---|
| 165 | MPID_Progress_end(&progress_state); |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | NMPI_Comm_free(&((*win_ptr)->comm)); |
|---|
| 169 | |
|---|
| 170 | MPIU_Free((*win_ptr)->base_addrs); |
|---|
| 171 | MPIU_Free((*win_ptr)->disp_units); |
|---|
| 172 | MPIU_Free((*win_ptr)->all_win_handles); |
|---|
| 173 | MPIU_Free((*win_ptr)->pt_rma_puts_accs); |
|---|
| 174 | |
|---|
| 175 | /* check whether refcount needs to be decremented here as in group_free */ |
|---|
| 176 | MPIU_Handle_obj_free( &MPID_Win_mem, *win_ptr ); |
|---|
| 177 | |
|---|
| 178 | fn_exit: |
|---|
| 179 | MPIR_Nest_decr(); |
|---|
| 180 | MPIU_CHKLMEM_FREEALL(); |
|---|
| 181 | MPIDI_RMA_FUNC_EXIT(MPID_STATE_MPIDI_WIN_FREE); |
|---|
| 182 | return mpi_errno; |
|---|
| 183 | |
|---|
| 184 | fn_fail: |
|---|
| 185 | goto fn_exit; |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | #undef FUNCNAME |
|---|
| 191 | #define FUNCNAME MPIDI_Put |
|---|
| 192 | #undef FCNAME |
|---|
| 193 | #define FCNAME MPIDI_QUOTE(FUNCNAME) |
|---|
| 194 | int MPIDI_Put(void *origin_addr, int origin_count, MPI_Datatype |
|---|
| 195 | origin_datatype, int target_rank, MPI_Aint target_disp, |
|---|
| 196 | int target_count, MPI_Datatype target_datatype, MPID_Win *win_ptr) |
|---|
| 197 | { |
|---|
| 198 | int mpi_errno = MPI_SUCCESS; |
|---|
| 199 | int dt_contig, rank, predefined; |
|---|
| 200 | MPIDI_RMA_ops *curr_ptr, *prev_ptr, *new_ptr; |
|---|
| 201 | MPID_Datatype *dtp; |
|---|
| 202 | MPI_Aint dt_true_lb; |
|---|
| 203 | MPIDI_msg_sz_t data_sz; |
|---|
| 204 | MPIU_CHKPMEM_DECL(1); |
|---|
| 205 | MPIU_THREADPRIV_DECL; |
|---|
| 206 | MPIDI_STATE_DECL(MPID_STATE_MPIDI_PUT); |
|---|
| 207 | |
|---|
| 208 | MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPIDI_PUT); |
|---|
| 209 | |
|---|
| 210 | MPIU_THREADPRIV_GET; |
|---|
| 211 | MPIDI_Datatype_get_info(origin_count, origin_datatype, |
|---|
| 212 | dt_contig, data_sz, dtp,dt_true_lb); |
|---|
| 213 | |
|---|
| 214 | if ((data_sz == 0) || (target_rank == MPI_PROC_NULL)) |
|---|
| 215 | { |
|---|
| 216 | goto fn_exit; |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | /* FIXME: It makes sense to save the rank (and size) of the |
|---|
| 220 | communicator in the window structure to speed up these operations, |
|---|
| 221 | or to save a pointer to the communicator structure, rather than |
|---|
| 222 | just the handle |
|---|
| 223 | */ |
|---|
| 224 | MPIR_Nest_incr(); |
|---|
| 225 | NMPI_Comm_rank(win_ptr->comm, &rank); |
|---|
| 226 | MPIR_Nest_decr(); |
|---|
| 227 | |
|---|
| 228 | /* If the put is a local operation, do it here */ |
|---|
| 229 | if (target_rank == rank) |
|---|
| 230 | { |
|---|
| 231 | mpi_errno = MPIR_Localcopy(origin_addr, origin_count, origin_datatype, |
|---|
| 232 | (char *) win_ptr->base + win_ptr->disp_unit * |
|---|
| 233 | target_disp, target_count, target_datatype); |
|---|
| 234 | } |
|---|
| 235 | else |
|---|
| 236 | { |
|---|
| 237 | /* queue it up */ |
|---|
| 238 | curr_ptr = win_ptr->rma_ops_list; |
|---|
| 239 | prev_ptr = curr_ptr; |
|---|
| 240 | while (curr_ptr != NULL) |
|---|
| 241 | { |
|---|
| 242 | prev_ptr = curr_ptr; |
|---|
| 243 | curr_ptr = curr_ptr->next; |
|---|
| 244 | } |
|---|
| 245 | |
|---|
| 246 | /* FIXME: Where does this memory get freed? */ |
|---|
| 247 | MPIU_CHKPMEM_MALLOC(new_ptr, MPIDI_RMA_ops *, sizeof(MPIDI_RMA_ops), |
|---|
| 248 | mpi_errno, "RMA operation entry"); |
|---|
| 249 | if (prev_ptr != NULL) |
|---|
| 250 | prev_ptr->next = new_ptr; |
|---|
| 251 | else |
|---|
| 252 | win_ptr->rma_ops_list = new_ptr; |
|---|
| 253 | |
|---|
| 254 | new_ptr->next = NULL; |
|---|
| 255 | new_ptr->type = MPIDI_RMA_PUT; |
|---|
| 256 | new_ptr->origin_addr = origin_addr; |
|---|
| 257 | new_ptr->origin_count = origin_count; |
|---|
| 258 | new_ptr->origin_datatype = origin_datatype; |
|---|
| 259 | new_ptr->target_rank = target_rank; |
|---|
| 260 | new_ptr->target_disp = target_disp; |
|---|
| 261 | new_ptr->target_count = target_count; |
|---|
| 262 | new_ptr->target_datatype = target_datatype; |
|---|
| 263 | |
|---|
| 264 | /* if source or target datatypes are derived, increment their |
|---|
| 265 | reference counts */ |
|---|
| 266 | MPIDI_CH3I_DATATYPE_IS_PREDEFINED(origin_datatype, predefined); |
|---|
| 267 | if (!predefined) |
|---|
| 268 | { |
|---|
| 269 | MPID_Datatype_get_ptr(origin_datatype, dtp); |
|---|
| 270 | MPID_Datatype_add_ref(dtp); |
|---|
| 271 | } |
|---|
| 272 | MPIDI_CH3I_DATATYPE_IS_PREDEFINED(target_datatype, predefined); |
|---|
| 273 | if (!predefined) |
|---|
| 274 | { |
|---|
| 275 | MPID_Datatype_get_ptr(target_datatype, dtp); |
|---|
| 276 | MPID_Datatype_add_ref(dtp); |
|---|
| 277 | } |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | fn_exit: |
|---|
| 281 | MPIDI_RMA_FUNC_EXIT(MPID_STATE_MPIDI_PUT); |
|---|
| 282 | return mpi_errno; |
|---|
| 283 | |
|---|
| 284 | /* --BEGIN ERROR HANDLING-- */ |
|---|
| 285 | fn_fail: |
|---|
| 286 | MPIU_CHKPMEM_REAP(); |
|---|
| 287 | goto fn_exit; |
|---|
| 288 | /* --END ERROR HANDLING-- */ |
|---|
| 289 | } |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | #undef FUNCNAME |
|---|
| 294 | #define FUNCNAME MPIDI_Get |
|---|
| 295 | #undef FCNAME |
|---|
| 296 | #define FCNAME MPIDI_QUOTE(FUNCNAME) |
|---|
| 297 | int MPIDI_Get(void *origin_addr, int origin_count, MPI_Datatype |
|---|
| 298 | origin_datatype, int target_rank, MPI_Aint target_disp, |
|---|
| 299 | int target_count, MPI_Datatype target_datatype, MPID_Win *win_ptr) |
|---|
| 300 | { |
|---|
| 301 | int mpi_errno = MPI_SUCCESS; |
|---|
| 302 | MPIDI_msg_sz_t data_sz; |
|---|
| 303 | int dt_contig, rank, predefined; |
|---|
| 304 | MPI_Aint dt_true_lb; |
|---|
| 305 | MPIDI_RMA_ops *curr_ptr, *prev_ptr, *new_ptr; |
|---|
| 306 | MPID_Datatype *dtp; |
|---|
| 307 | MPIU_CHKPMEM_DECL(1); |
|---|
| 308 | MPIU_THREADPRIV_DECL; |
|---|
| 309 | MPIDI_STATE_DECL(MPID_STATE_MPIDI_GET); |
|---|
| 310 | |
|---|
| 311 | MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPIDI_GET); |
|---|
| 312 | |
|---|
| 313 | MPIU_THREADPRIV_GET; |
|---|
| 314 | MPIDI_Datatype_get_info(origin_count, origin_datatype, |
|---|
| 315 | dt_contig, data_sz, dtp, dt_true_lb); |
|---|
| 316 | |
|---|
| 317 | if ((data_sz == 0) || (target_rank == MPI_PROC_NULL)) |
|---|
| 318 | { |
|---|
| 319 | goto fn_exit; |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | /* FIXME: It makes sense to save the rank (and size) of the |
|---|
| 323 | communicator in the window structure to speed up these operations */ |
|---|
| 324 | MPIR_Nest_incr(); |
|---|
| 325 | NMPI_Comm_rank(win_ptr->comm, &rank); |
|---|
| 326 | MPIR_Nest_decr(); |
|---|
| 327 | |
|---|
| 328 | /* If the get is a local operation, do it here */ |
|---|
| 329 | if (target_rank == rank) |
|---|
| 330 | { |
|---|
| 331 | mpi_errno = MPIR_Localcopy((char *) win_ptr->base + |
|---|
| 332 | win_ptr->disp_unit * target_disp, |
|---|
| 333 | target_count, target_datatype, |
|---|
| 334 | origin_addr, origin_count, |
|---|
| 335 | origin_datatype); |
|---|
| 336 | } |
|---|
| 337 | else |
|---|
| 338 | { |
|---|
| 339 | /* queue it up */ |
|---|
| 340 | curr_ptr = win_ptr->rma_ops_list; |
|---|
| 341 | prev_ptr = curr_ptr; |
|---|
| 342 | while (curr_ptr != NULL) |
|---|
| 343 | { |
|---|
| 344 | prev_ptr = curr_ptr; |
|---|
| 345 | curr_ptr = curr_ptr->next; |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | MPIU_CHKPMEM_MALLOC(new_ptr, MPIDI_RMA_ops *, sizeof(MPIDI_RMA_ops), |
|---|
| 349 | mpi_errno, "RMA operation entry"); |
|---|
| 350 | if (prev_ptr != NULL) |
|---|
| 351 | { |
|---|
| 352 | prev_ptr->next = new_ptr; |
|---|
| 353 | } |
|---|
| 354 | else |
|---|
| 355 | { |
|---|
| 356 | win_ptr->rma_ops_list = new_ptr; |
|---|
| 357 | } |
|---|
| 358 | |
|---|
| 359 | new_ptr->next = NULL; |
|---|
| 360 | new_ptr->type = MPIDI_RMA_GET; |
|---|
| 361 | new_ptr->origin_addr = origin_addr; |
|---|
| 362 | new_ptr->origin_count = origin_count; |
|---|
| 363 | new_ptr->origin_datatype = origin_datatype; |
|---|
| 364 | new_ptr->target_rank = target_rank; |
|---|
| 365 | new_ptr->target_disp = target_disp; |
|---|
| 366 | new_ptr->target_count = target_count; |
|---|
| 367 | new_ptr->target_datatype = target_datatype; |
|---|
| 368 | |
|---|
| 369 | /* if source or target datatypes are derived, increment their |
|---|
| 370 | reference counts */ |
|---|
| 371 | MPIDI_CH3I_DATATYPE_IS_PREDEFINED(origin_datatype, predefined); |
|---|
| 372 | if (!predefined) |
|---|
| 373 | { |
|---|
| 374 | MPID_Datatype_get_ptr(origin_datatype, dtp); |
|---|
| 375 | MPID_Datatype_add_ref(dtp); |
|---|
| 376 | } |
|---|
| 377 | MPIDI_CH3I_DATATYPE_IS_PREDEFINED(target_datatype, predefined); |
|---|
| 378 | if (!predefined) |
|---|
| 379 | { |
|---|
| 380 | MPID_Datatype_get_ptr(target_datatype, dtp); |
|---|
| 381 | MPID_Datatype_add_ref(dtp); |
|---|
| 382 | } |
|---|
| 383 | } |
|---|
| 384 | |
|---|
| 385 | fn_exit: |
|---|
| 386 | MPIDI_RMA_FUNC_EXIT(MPID_STATE_MPIDI_GET); |
|---|
| 387 | return mpi_errno; |
|---|
| 388 | |
|---|
| 389 | /* --BEGIN ERROR HANDLING-- */ |
|---|
| 390 | fn_fail: |
|---|
| 391 | MPIU_CHKPMEM_REAP(); |
|---|
| 392 | goto fn_exit; |
|---|
| 393 | /* --END ERROR HANDLING-- */ |
|---|
| 394 | } |
|---|
| 395 | |
|---|
| 396 | |
|---|
| 397 | |
|---|
| 398 | #undef FUNCNAME |
|---|
| 399 | #define FUNCNAME MPIDI_Accumulate |
|---|
| 400 | #undef FCNAME |
|---|
| 401 | #define FCNAME MPIDI_QUOTE(FUNCNAME) |
|---|
| 402 | int MPIDI_Accumulate(void *origin_addr, int origin_count, MPI_Datatype |
|---|
| 403 | origin_datatype, int target_rank, MPI_Aint target_disp, |
|---|
| 404 | int target_count, MPI_Datatype target_datatype, MPI_Op op, |
|---|
| 405 | MPID_Win *win_ptr) |
|---|
| 406 | { |
|---|
| 407 | int nest_level_inc = FALSE; |
|---|
| 408 | int mpi_errno=MPI_SUCCESS; |
|---|
| 409 | MPIDI_msg_sz_t data_sz; |
|---|
| 410 | int dt_contig, rank, origin_predefined, target_predefined; |
|---|
| 411 | MPI_Aint dt_true_lb; |
|---|
| 412 | MPIDI_RMA_ops *curr_ptr, *prev_ptr, *new_ptr; |
|---|
| 413 | MPID_Datatype *dtp; |
|---|
| 414 | MPIU_CHKLMEM_DECL(2); |
|---|
| 415 | MPIU_CHKPMEM_DECL(1); |
|---|
| 416 | MPIU_THREADPRIV_DECL; |
|---|
| 417 | MPIDI_STATE_DECL(MPID_STATE_MPIDI_ACCUMULATE); |
|---|
| 418 | |
|---|
| 419 | MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPIDI_ACCUMULATE); |
|---|
| 420 | |
|---|
| 421 | MPIU_THREADPRIV_GET; |
|---|
| 422 | MPIDI_Datatype_get_info(origin_count, origin_datatype, |
|---|
| 423 | dt_contig, data_sz, dtp, dt_true_lb); |
|---|
| 424 | |
|---|
| 425 | if ((data_sz == 0) || (target_rank == MPI_PROC_NULL)) |
|---|
| 426 | { |
|---|
| 427 | goto fn_exit; |
|---|
| 428 | } |
|---|
| 429 | |
|---|
| 430 | MPIR_Nest_incr(); |
|---|
| 431 | nest_level_inc = TRUE; |
|---|
| 432 | |
|---|
| 433 | /* FIXME: It makes sense to save the rank (and size) of the |
|---|
| 434 | communicator in the window structure to speed up these operations, |
|---|
| 435 | or to save a pointer to the communicator structure, rather than |
|---|
| 436 | just the handle |
|---|
| 437 | */ |
|---|
| 438 | NMPI_Comm_rank(win_ptr->comm, &rank); |
|---|
| 439 | |
|---|
| 440 | MPIDI_CH3I_DATATYPE_IS_PREDEFINED(origin_datatype, origin_predefined); |
|---|
| 441 | MPIDI_CH3I_DATATYPE_IS_PREDEFINED(target_datatype, target_predefined); |
|---|
| 442 | |
|---|
| 443 | if (target_rank == rank) |
|---|
| 444 | { |
|---|
| 445 | MPI_User_function *uop; |
|---|
| 446 | |
|---|
| 447 | if (op == MPI_REPLACE) |
|---|
| 448 | { |
|---|
| 449 | mpi_errno = MPIR_Localcopy(origin_addr, origin_count, |
|---|
| 450 | origin_datatype, |
|---|
| 451 | (char *) win_ptr->base + win_ptr->disp_unit * |
|---|
| 452 | target_disp, target_count, target_datatype); |
|---|
| 453 | goto fn_exit; |
|---|
| 454 | } |
|---|
| 455 | |
|---|
| 456 | MPIU_ERR_CHKANDJUMP1((HANDLE_GET_KIND(op) != HANDLE_KIND_BUILTIN), |
|---|
| 457 | mpi_errno, MPI_ERR_OP, "**opnotpredefined", |
|---|
| 458 | "**opnotpredefined %d", op ); |
|---|
| 459 | |
|---|
| 460 | /* get the function by indexing into the op table */ |
|---|
| 461 | uop = MPIR_Op_table[(op)%16 - 1]; |
|---|
| 462 | |
|---|
| 463 | if (origin_predefined && target_predefined) |
|---|
| 464 | { |
|---|
| 465 | (*uop)(origin_addr, (char *) win_ptr->base + win_ptr->disp_unit * |
|---|
| 466 | target_disp, &target_count, &target_datatype); |
|---|
| 467 | } |
|---|
| 468 | else |
|---|
| 469 | { |
|---|
| 470 | /* derived datatype */ |
|---|
| 471 | |
|---|
| 472 | MPID_Segment *segp; |
|---|
| 473 | DLOOP_VECTOR *dloop_vec; |
|---|
| 474 | MPI_Aint first, last; |
|---|
| 475 | int vec_len, i, type_size, count; |
|---|
| 476 | MPI_Datatype type; |
|---|
| 477 | MPI_Aint true_lb, true_extent, extent; |
|---|
| 478 | void *tmp_buf=NULL, *source_buf, *target_buf; |
|---|
| 479 | |
|---|
| 480 | if (origin_datatype != target_datatype) |
|---|
| 481 | { |
|---|
| 482 | /* first copy the data into a temporary buffer with |
|---|
| 483 | the same datatype as the target. Then do the |
|---|
| 484 | accumulate operation. */ |
|---|
| 485 | |
|---|
| 486 | mpi_errno = NMPI_Type_get_true_extent(target_datatype, |
|---|
| 487 | &true_lb, &true_extent); |
|---|
| 488 | if (mpi_errno) { MPIU_ERR_POP(mpi_errno); } |
|---|
| 489 | |
|---|
| 490 | MPID_Datatype_get_extent_macro(target_datatype, extent); |
|---|
| 491 | |
|---|
| 492 | MPIU_CHKLMEM_MALLOC(tmp_buf, void *, |
|---|
| 493 | target_count * (MPIR_MAX(extent,true_extent)), |
|---|
| 494 | mpi_errno, "temporary buffer"); |
|---|
| 495 | /* adjust for potential negative lower bound in datatype */ |
|---|
| 496 | tmp_buf = (void *)((char*)tmp_buf - true_lb); |
|---|
| 497 | |
|---|
| 498 | mpi_errno = MPIR_Localcopy(origin_addr, origin_count, |
|---|
| 499 | origin_datatype, tmp_buf, |
|---|
| 500 | target_count, target_datatype); |
|---|
| 501 | if (mpi_errno) { MPIU_ERR_POP(mpi_errno); } |
|---|
| 502 | } |
|---|
| 503 | |
|---|
| 504 | if (target_predefined) { |
|---|
| 505 | /* target predefined type, origin derived datatype */ |
|---|
| 506 | |
|---|
| 507 | (*uop)(tmp_buf, (char *) win_ptr->base + win_ptr->disp_unit * |
|---|
| 508 | target_disp, &target_count, &target_datatype); |
|---|
| 509 | } |
|---|
| 510 | else { |
|---|
| 511 | |
|---|
| 512 | segp = MPID_Segment_alloc(); |
|---|
| 513 | MPIU_ERR_CHKANDJUMP((!segp), mpi_errno, MPI_ERR_OTHER, "**nomem"); |
|---|
| 514 | MPID_Segment_init(NULL, target_count, target_datatype, segp, 0); |
|---|
| 515 | first = 0; |
|---|
| 516 | last = SEGMENT_IGNORE_LAST; |
|---|
| 517 | |
|---|
| 518 | MPID_Datatype_get_ptr(target_datatype, dtp); |
|---|
| 519 | vec_len = dtp->max_contig_blocks * target_count + 1; |
|---|
| 520 | /* +1 needed because Rob says so */ |
|---|
| 521 | MPIU_CHKLMEM_MALLOC(dloop_vec, DLOOP_VECTOR *, |
|---|
| 522 | vec_len * sizeof(DLOOP_VECTOR), |
|---|
| 523 | mpi_errno, "dloop vector"); |
|---|
| 524 | |
|---|
| 525 | MPID_Segment_pack_vector(segp, first, &last, dloop_vec, &vec_len); |
|---|
| 526 | |
|---|
| 527 | source_buf = (tmp_buf != NULL) ? tmp_buf : origin_addr; |
|---|
| 528 | target_buf = (char *) win_ptr->base + |
|---|
| 529 | win_ptr->disp_unit * target_disp; |
|---|
| 530 | type = dtp->eltype; |
|---|
| 531 | type_size = MPID_Datatype_get_basic_size(type); |
|---|
| 532 | for (i=0; i<vec_len; i++) |
|---|
| 533 | { |
|---|
| 534 | count = (dloop_vec[i].DLOOP_VECTOR_LEN)/type_size; |
|---|
| 535 | (*uop)((char *)source_buf + MPIU_PtrToAint(dloop_vec[i].DLOOP_VECTOR_BUF), |
|---|
| 536 | (char *)target_buf + MPIU_PtrToAint(dloop_vec[i].DLOOP_VECTOR_BUF), |
|---|
| 537 | &count, &type); |
|---|
| 538 | } |
|---|
| 539 | |
|---|
| 540 | MPID_Segment_free(segp); |
|---|
| 541 | } |
|---|
| 542 | } |
|---|
| 543 | } |
|---|
| 544 | else |
|---|
| 545 | { |
|---|
| 546 | /* queue it up */ |
|---|
| 547 | curr_ptr = win_ptr->rma_ops_list; |
|---|
| 548 | prev_ptr = curr_ptr; |
|---|
| 549 | while (curr_ptr != NULL) |
|---|
| 550 | { |
|---|
| 551 | prev_ptr = curr_ptr; |
|---|
| 552 | curr_ptr = curr_ptr->next; |
|---|
| 553 | } |
|---|
| 554 | |
|---|
| 555 | MPIU_CHKPMEM_MALLOC(new_ptr, MPIDI_RMA_ops *, sizeof(MPIDI_RMA_ops), |
|---|
| 556 | mpi_errno, "RMA operation entry"); |
|---|
| 557 | if (prev_ptr != NULL) |
|---|
| 558 | { |
|---|
| 559 | prev_ptr->next = new_ptr; |
|---|
| 560 | } |
|---|
| 561 | else |
|---|
| 562 | { |
|---|
| 563 | win_ptr->rma_ops_list = new_ptr; |
|---|
| 564 | } |
|---|
| 565 | |
|---|
| 566 | new_ptr->next = NULL; |
|---|
| 567 | new_ptr->type = MPIDI_RMA_ACCUMULATE; |
|---|
| 568 | new_ptr->origin_addr = origin_addr; |
|---|
| 569 | new_ptr->origin_count = origin_count; |
|---|
| 570 | new_ptr->origin_datatype = origin_datatype; |
|---|
| 571 | new_ptr->target_rank = target_rank; |
|---|
| 572 | new_ptr->target_disp = target_disp; |
|---|
| 573 | new_ptr->target_count = target_count; |
|---|
| 574 | new_ptr->target_datatype = target_datatype; |
|---|
| 575 | new_ptr->op = op; |
|---|
| 576 | |
|---|
| 577 | /* if source or target datatypes are derived, increment their |
|---|
| 578 | reference counts */ |
|---|
| 579 | if (!origin_predefined) |
|---|
| 580 | { |
|---|
| 581 | MPID_Datatype_get_ptr(origin_datatype, dtp); |
|---|
| 582 | MPID_Datatype_add_ref(dtp); |
|---|
| 583 | } |
|---|
| 584 | if (!target_predefined) |
|---|
| 585 | { |
|---|
| 586 | MPID_Datatype_get_ptr(target_datatype, dtp); |
|---|
| 587 | MPID_Datatype_add_ref(dtp); |
|---|
| 588 | } |
|---|
| 589 | } |
|---|
| 590 | |
|---|
| 591 | fn_exit: |
|---|
| 592 | MPIU_CHKLMEM_FREEALL(); |
|---|
| 593 | if (nest_level_inc) |
|---|
| 594 | { |
|---|
| 595 | MPIR_Nest_decr(); |
|---|
| 596 | } |
|---|
| 597 | MPIDI_RMA_FUNC_EXIT(MPID_STATE_MPIDI_ACCUMULATE); |
|---|
| 598 | return mpi_errno; |
|---|
| 599 | |
|---|
| 600 | /* --BEGIN ERROR HANDLING-- */ |
|---|
| 601 | fn_fail: |
|---|
| 602 | MPIU_CHKPMEM_REAP(); |
|---|
| 603 | goto fn_exit; |
|---|
| 604 | /* --END ERROR HANDLING-- */ |
|---|
| 605 | } |
|---|
| 606 | |
|---|
| 607 | |
|---|
| 608 | #undef FUNCNAME |
|---|
| 609 | #define FUNCNAME MPIDI_Alloc_mem |
|---|
| 610 | #undef FCNAME |
|---|
| 611 | #define FCNAME MPIDI_QUOTE(FUNCNAME) |
|---|
| 612 | void *MPIDI_Alloc_mem( size_t size, MPID_Info *info_ptr ) |
|---|
| 613 | { |
|---|
| 614 | void *ap; |
|---|
| 615 | MPIDI_STATE_DECL(MPID_STATE_MPIDI_ALLOC_MEM); |
|---|
| 616 | |
|---|
| 617 | MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_ALLOC_MEM); |
|---|
| 618 | |
|---|
| 619 | ap = MPIU_Malloc(size); |
|---|
| 620 | |
|---|
| 621 | MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_ALLOC_MEM); |
|---|
| 622 | return ap; |
|---|
| 623 | } |
|---|
| 624 | |
|---|
| 625 | |
|---|
| 626 | #undef FUNCNAME |
|---|
| 627 | #define FUNCNAME MPIDI_Free_mem |
|---|
| 628 | #undef FCNAME |
|---|
| 629 | #define FCNAME MPIDI_QUOTE(FUNCNAME) |
|---|
| 630 | int MPIDI_Free_mem( void *ptr ) |
|---|
| 631 | { |
|---|
| 632 | int mpi_errno = MPI_SUCCESS; |
|---|
| 633 | MPIDI_STATE_DECL(MPID_STATE_MPIDI_FREE_MEM); |
|---|
| 634 | |
|---|
| 635 | MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_FREE_MEM); |
|---|
| 636 | |
|---|
| 637 | MPIU_Free(ptr); |
|---|
| 638 | |
|---|
| 639 | MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_FREE_MEM); |
|---|
| 640 | return mpi_errno; |
|---|
| 641 | } |
|---|