mpid_rma.c 13.1 KB
Newer Older
1
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 3 4 5 6 7
/*
 *  (C) 2001 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */

#include "mpidimpl.h"
8
#include "mpidrma.h"
9

10 11 12 13

MPIU_THREADSAFE_INIT_DECL(initRMAoptions);

static int win_init(MPI_Aint size, int disp_unit, int create_flavor, int model,
14
                    MPID_Comm * comm_ptr, MPID_Win ** win_ptr);
15 16


17 18 19
#define MPID_WIN_FTABLE_SET_DEFAULTS(win_ptr)                   \
    do {                                                        \
        /* Get ptr to RMAFns, which is embedded in MPID_Win */  \
20
        MPID_RMAFns *ftable         = &(*(win_ptr))->RMAFns;    \
21
        ftable->Win_free            = MPIDI_Win_free;           \
22 23
        ftable->Win_attach          = MPIDI_Win_attach;         \
        ftable->Win_detach          = MPIDI_Win_detach;         \
24 25
        ftable->Win_shared_query    = MPIDI_Win_shared_query;   \
                                                                \
26 27 28
        ftable->Win_set_info        = MPIDI_Win_set_info;       \
        ftable->Win_get_info        = MPIDI_Win_get_info;       \
                                                                \
29 30 31
        ftable->Put                 = MPIDI_Put;                \
        ftable->Get                 = MPIDI_Get;                \
        ftable->Accumulate          = MPIDI_Accumulate;         \
32 33 34
        ftable->Get_accumulate      = MPIDI_Get_accumulate;     \
        ftable->Fetch_and_op        = MPIDI_Fetch_and_op;       \
        ftable->Compare_and_swap    = MPIDI_Compare_and_swap;   \
35
                                                                \
36 37 38 39
        ftable->Rput                = MPIDI_Rput;               \
        ftable->Rget                = MPIDI_Rget;               \
        ftable->Raccumulate         = MPIDI_Raccumulate;        \
        ftable->Rget_accumulate     = MPIDI_Rget_accumulate;    \
40 41 42 43 44 45 46 47 48 49 50 51 52
                                                                \
        ftable->Win_fence           = MPIDI_Win_fence;          \
        ftable->Win_post            = MPIDI_Win_post;           \
        ftable->Win_start           = MPIDI_Win_start;          \
        ftable->Win_complete        = MPIDI_Win_complete;       \
        ftable->Win_wait            = MPIDI_Win_wait;           \
        ftable->Win_test            = MPIDI_Win_test;           \
                                                                \
        ftable->Win_lock            = MPIDI_Win_lock;           \
        ftable->Win_unlock          = MPIDI_Win_unlock;         \
        ftable->Win_lock_all        = MPIDI_Win_lock_all;       \
        ftable->Win_unlock_all      = MPIDI_Win_unlock_all;     \
                                                                \
53 54 55 56
        ftable->Win_flush           = MPIDI_Win_flush;          \
        ftable->Win_flush_all       = MPIDI_Win_flush_all;      \
        ftable->Win_flush_local     = MPIDI_Win_flush_local;    \
        ftable->Win_flush_local_all = MPIDI_Win_flush_local_all;\
57 58 59 60
        ftable->Win_sync            = MPIDI_Win_sync;           \
    } while (0)


61
#undef FUNCNAME
62
#define FUNCNAME MPID_Win_create
63 64
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
65 66
int MPID_Win_create(void *base, MPI_Aint size, int disp_unit, MPID_Info * info,
                    MPID_Comm * comm_ptr, MPID_Win ** win_ptr)
67
{
68
    int mpi_errno = MPI_SUCCESS;
69

70
    MPIDI_STATE_DECL(MPID_STATE_MPID_WIN_CREATE);
71

72 73
    MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPID_WIN_CREATE);

Wesley Bland's avatar
Wesley Bland committed
74 75
    /* Check to make sure the communicator hasn't already been revoked */
    if (comm_ptr->revoked) {
76
        MPIU_ERR_SETANDJUMP(mpi_errno, MPIX_ERR_REVOKED, "**revoked");
Wesley Bland's avatar
Wesley Bland committed
77 78
    }

79 80 81 82
    mpi_errno =
        win_init(size, disp_unit, MPI_WIN_FLAVOR_CREATE, MPI_WIN_UNIFIED, comm_ptr, win_ptr);
    if (mpi_errno)
        MPIU_ERR_POP(mpi_errno);
83

84 85
    (*win_ptr)->base = base;

86 87 88
    mpi_errno = MPIDI_CH3U_Win_fns.create(base, size, disp_unit, info, comm_ptr, win_ptr);
    if (mpi_errno)
        MPIU_ERR_POP(mpi_errno);
89

90
  fn_fail:
91 92 93 94 95 96 97 98 99
    MPIDI_FUNC_EXIT(MPID_STATE_MPID_WIN_CREATE);
    return mpi_errno;
}


#undef FUNCNAME
#define FUNCNAME MPID_Win_allocate
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
100 101
int MPID_Win_allocate(MPI_Aint size, int disp_unit, MPID_Info * info,
                      MPID_Comm * comm_ptr, void *baseptr, MPID_Win ** win_ptr)
102
{
103
    int mpi_errno = MPI_SUCCESS;
104
    MPIDI_STATE_DECL(MPID_STATE_MPID_WIN_ALLOCATE);
105

106 107
    MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPID_WIN_ALLOCATE);

108 109 110 111 112
    mpi_errno =
        win_init(size, disp_unit, MPI_WIN_FLAVOR_ALLOCATE, MPI_WIN_UNIFIED, comm_ptr, win_ptr);
    if (mpi_errno != MPI_SUCCESS) {
        MPIU_ERR_POP(mpi_errno);
    }
113

114 115 116
    /* FOR ALLOCATE, alloc_shm info is default to set to TRUE */
    (*win_ptr)->info_args.alloc_shm = TRUE;

117 118
    if (info != NULL) {
        int alloc_shm_flag = 0;
119
        char shm_alloc_value[MPI_MAX_INFO_VAL + 1];
120
        MPIR_Info_get_impl(info, "alloc_shm", MPI_MAX_INFO_VAL, shm_alloc_value, &alloc_shm_flag);
121 122
        if ((alloc_shm_flag == 1) && (!strncmp(shm_alloc_value, "false", sizeof("false"))))
            (*win_ptr)->info_args.alloc_shm = FALSE;
123 124
    }

125
    mpi_errno = MPIDI_CH3U_Win_fns.allocate(size, disp_unit, info, comm_ptr, baseptr, win_ptr);
126 127 128
    if (mpi_errno != MPI_SUCCESS) {
        MPIU_ERR_POP(mpi_errno);
    }
129

130
  fn_fail:
131 132 133 134 135 136 137 138 139
    MPIDI_FUNC_EXIT(MPID_STATE_MPID_WIN_ALLOCATE);
    return mpi_errno;
}


#undef FUNCNAME
#define FUNCNAME MPID_Win_create_dynamic
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
140
int MPID_Win_create_dynamic(MPID_Info * info, MPID_Comm * comm_ptr, MPID_Win ** win_ptr)
141
{
142
    int mpi_errno = MPI_SUCCESS;
143

144
    MPIDI_STATE_DECL(MPID_STATE_MPID_WIN_CREATE_DYNAMIC);
145

146
    MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPID_WIN_CREATE_DYNAMIC);
147

148 149 150
    mpi_errno = win_init(0 /* spec defines size to be 0 */ ,
                         1 /* spec defines disp_unit to be 1 */ ,
                         MPI_WIN_FLAVOR_DYNAMIC, MPI_WIN_UNIFIED, comm_ptr, win_ptr);
151

152 153
    if (mpi_errno)
        MPIU_ERR_POP(mpi_errno);
154

155 156
    (*win_ptr)->base = MPI_BOTTOM;

157
    mpi_errno = MPIDI_CH3U_Win_fns.create_dynamic(info, comm_ptr, win_ptr);
158 159 160
    if (mpi_errno != MPI_SUCCESS) {
        MPIU_ERR_POP(mpi_errno);
    }
161

162
  fn_fail:
163
    MPIDI_FUNC_EXIT(MPID_STATE_MPID_WIN_CREATE_DYNAMIC);
164 165 166 167
    return mpi_errno;
}


168
/* The memory allocation functions */
169 170 171 172
#undef FUNCNAME
#define FUNCNAME MPID_Alloc_mem
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
173
void *MPID_Alloc_mem(size_t size, MPID_Info * info_ptr)
174
{
175
    void *ap = NULL;
176 177 178 179
    MPIDI_STATE_DECL(MPID_STATE_MPID_ALLOC_MEM);

    MPIDI_FUNC_ENTER(MPID_STATE_MPID_ALLOC_MEM);

180
    ap = MPIDI_Alloc_mem(size, info_ptr);
181

182 183 184 185 186 187 188 189 190
    MPIDI_FUNC_EXIT(MPID_STATE_MPID_ALLOC_MEM);
    return ap;
}


#undef FUNCNAME
#define FUNCNAME MPID_Free_mem
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
191
int MPID_Free_mem(void *ptr)
192 193 194 195 196 197
{
    int mpi_errno = MPI_SUCCESS;
    MPIDI_STATE_DECL(MPID_STATE_MPID_FREE_MEM);

    MPIDI_FUNC_ENTER(MPID_STATE_MPID_FREE_MEM);

198
    mpi_errno = MPIDI_Free_mem(ptr);
199
    if (mpi_errno != MPI_SUCCESS) {
200
        MPIU_ERR_POP(mpi_errno);
201
    }
202 203

  fn_fail:
204
    MPIDI_FUNC_EXIT(MPID_STATE_MPID_FREE_MEM);
205 206 207
    return mpi_errno;
}

208

209 210 211 212
#undef FUNCNAME
#define FUNCNAME MPID_Win_allocate_shared
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
213 214
int MPID_Win_allocate_shared(MPI_Aint size, int disp_unit, MPID_Info * info, MPID_Comm * comm_ptr,
                             void *base_ptr, MPID_Win ** win_ptr)
215
{
216
    int mpi_errno = MPI_SUCCESS;
217 218

    MPIDI_STATE_DECL(MPID_STATE_MPID_WIN_ALLOCATE_SHARED);
219

220 221
    MPIDI_RMA_FUNC_ENTER(MPID_STATE_MPID_WIN_ALLOCATE_SHARED);

222 223 224 225
    mpi_errno =
        win_init(size, disp_unit, MPI_WIN_FLAVOR_SHARED, MPI_WIN_UNIFIED, comm_ptr, win_ptr);
    if (mpi_errno)
        MPIU_ERR_POP(mpi_errno);
226

227 228 229 230 231
    /* FOR ALLOCATE_SHARED, alloc_shm info is default to set to TRUE */
    (*win_ptr)->info_args.alloc_shm = TRUE;

    if (info != NULL) {
        int alloc_shm_flag = 0;
232
        char shm_alloc_value[MPI_MAX_INFO_VAL + 1];
233 234 235 236 237 238
        MPIR_Info_get_impl(info, "alloc_shm", MPI_MAX_INFO_VAL, shm_alloc_value, &alloc_shm_flag);
        /* if value of 'alloc_shm' info is not set to true, throw an error */
        if (alloc_shm_flag == 1 && strncmp(shm_alloc_value, "true", sizeof("true")))
            MPIU_ERR_SETANDJUMP(mpi_errno, MPI_ERR_OTHER, "**infoval");
    }

239 240 241 242
    mpi_errno =
        MPIDI_CH3U_Win_fns.allocate_shared(size, disp_unit, info, comm_ptr, base_ptr, win_ptr);
    if (mpi_errno != MPI_SUCCESS)
        MPIU_ERR_POP(mpi_errno);
243

244
  fn_fail:
245 246 247
    MPIDI_FUNC_EXIT(MPID_STATE_MPID_WIN_ALLOCATE_SHARED);
    return mpi_errno;
}
248 249 250 251 252 253 254


#undef FUNCNAME
#define FUNCNAME win_init
#undef FCNAME
#define FCNAME MPIU_QUOTE(FUNCNAME)
static int win_init(MPI_Aint size, int disp_unit, int create_flavor, int model,
255
                    MPID_Comm * comm_ptr, MPID_Win ** win_ptr)
256 257
{
    int mpi_errno = MPI_SUCCESS;
258
    int i;
259
    MPID_Comm *win_comm_ptr;
260
    MPIU_CHKPMEM_DECL(2);
261 262 263 264
    MPIDI_STATE_DECL(MPID_STATE_WIN_INIT);

    MPIDI_FUNC_ENTER(MPID_STATE_WIN_INIT);

265
    if (initRMAoptions) {
266
        MPIU_THREADSAFE_INIT_BLOCK_BEGIN(initRMAoptions);
267 268

        MPIDI_CH3_RMA_Init_Pvars();
269 270 271 272 273

        MPIU_THREADSAFE_INIT_CLEAR(initRMAoptions);
        MPIU_THREADSAFE_INIT_BLOCK_END(initRMAoptions);
    }

274 275 276
    *win_ptr = (MPID_Win *) MPIU_Handle_obj_alloc(&MPID_Win_mem);
    MPIU_ERR_CHKANDJUMP1(!(*win_ptr), mpi_errno, MPI_ERR_OTHER, "**nomem",
                         "**nomem %s", "MPID_Win_mem");
277 278

    mpi_errno = MPIR_Comm_dup_impl(comm_ptr, &win_comm_ptr);
279 280
    if (mpi_errno)
        MPIU_ERR_POP(mpi_errno);
281 282 283

    MPIU_Object_set_ref(*win_ptr, 1);

284
    (*win_ptr)->fence_issued = 0;
285 286
    /* (*win_ptr)->errhandler is set by upper level; */
    /* (*win_ptr)->base is set by caller; */
287 288 289 290 291 292 293 294
    (*win_ptr)->size = size;
    (*win_ptr)->disp_unit = disp_unit;
    (*win_ptr)->create_flavor = create_flavor;
    (*win_ptr)->model = model;
    (*win_ptr)->attributes = NULL;
    (*win_ptr)->start_group_ptr = NULL;
    (*win_ptr)->start_assert = 0;
    (*win_ptr)->comm_ptr = win_comm_ptr;
295

296
    (*win_ptr)->at_completion_counter = 0;
297 298 299 300
    /* (*win_ptr)->base_addrs[] is set by caller; */
    /* (*win_ptr)->sizes[] is set by caller; */
    /* (*win_ptr)->disp_units[] is set by caller; */
    /* (*win_ptr)->all_win_handles[] is set by caller; */
301
    (*win_ptr)->current_lock_type = MPID_LOCK_NONE;
302
    (*win_ptr)->shared_lock_ref_cnt = 0;
303 304 305 306
    (*win_ptr)->lock_queue = NULL;
    (*win_ptr)->epoch_state = MPIDI_EPOCH_NONE;
    (*win_ptr)->epoch_count = 0;
    (*win_ptr)->at_rma_ops_list = NULL;
307
    (*win_ptr)->at_rma_ops_list_tail = NULL;
308
    (*win_ptr)->shm_allocated = FALSE;
309

310
    /* Initialize the passive target lock state */
311
    MPIU_CHKPMEM_MALLOC((*win_ptr)->targets, struct MPIDI_Win_target_state *,
312
                        sizeof(struct MPIDI_Win_target_state) * MPIR_Comm_size(win_comm_ptr),
313 314 315 316
                        mpi_errno, "RMA target states array");

    for (i = 0; i < MPIR_Comm_size(win_comm_ptr); i++) {
        (*win_ptr)->targets[i].rma_ops_list = NULL;
317
        (*win_ptr)->targets[i].rma_ops_list_tail = NULL;
318
        (*win_ptr)->targets[i].remote_lock_state = MPIDI_CH3_WIN_LOCK_NONE;
319 320
    }

321
    /* Initialize the info flags */
322
    (*win_ptr)->info_args.no_locks = 0;
323
    (*win_ptr)->info_args.accumulate_ordering = MPIDI_ACC_ORDER_RAR | MPIDI_ACC_ORDER_RAW |
324 325 326
        MPIDI_ACC_ORDER_WAR | MPIDI_ACC_ORDER_WAW;
    (*win_ptr)->info_args.accumulate_ops = MPIDI_ACC_OPS_SAME_OP_NO_OP;
    (*win_ptr)->info_args.same_size = 0;
327
    (*win_ptr)->info_args.alloc_shared_noncontig = 0;
328
    (*win_ptr)->info_args.alloc_shm = FALSE;
329

330 331 332 333 334 335 336 337 338 339
    MPIU_CHKPMEM_MALLOC((*win_ptr)->op_pool_start, struct MPIDI_RMA_Op *,
                        sizeof(MPIDI_RMA_Op_t) * MPIR_CVAR_CH3_RMA_OP_WIN_POOL_SIZE, mpi_errno,
                        "RMA op pool");
    (*win_ptr)->op_pool = NULL;
    (*win_ptr)->op_pool_tail = NULL;
    for (i = 0; i < MPIR_CVAR_CH3_RMA_OP_WIN_POOL_SIZE; i++) {
        (*win_ptr)->op_pool_start[i].pool_type = MPIDI_RMA_POOL_WIN;
        MPL_LL_APPEND((*win_ptr)->op_pool, (*win_ptr)->op_pool_tail, &((*win_ptr)->op_pool_start[i]));
    }

340 341
    MPID_WIN_FTABLE_SET_DEFAULTS(win_ptr);

342
  fn_exit:
343 344
    MPIDI_FUNC_EXIT(MPID_STATE_WIN_INIT);
    return mpi_errno;
345
  fn_fail:
346
    MPIU_CHKPMEM_REAP();
347 348
    goto fn_exit;
}
349 350 351 352 353 354


#undef FUNCNAME
#define FUNCNAME MPID_Win_set_info
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
355
int MPID_Win_set_info(MPID_Win * win, MPID_Info * info)
356 357 358 359 360 361 362
{
    int mpi_errno = MPI_SUCCESS;
    MPIDI_STATE_DECL(MPID_STATE_MPID_WIN_SET_INFO);

    MPIDI_FUNC_ENTER(MPID_STATE_MPID_WIN_SET_INFO);

    mpi_errno = win->RMAFns.Win_set_info(win, info);
363 364 365
    if (mpi_errno != MPI_SUCCESS) {
        MPIU_ERR_POP(mpi_errno);
    }
366

367
  fn_exit:
368 369
    MPIDI_FUNC_EXIT(MPID_STATE_MPID_WIN_SET_INFO);
    return mpi_errno;
370
  fn_fail:
371 372 373 374 375 376 377 378
    goto fn_exit;
}


#undef FUNCNAME
#define FUNCNAME MPID_Win_get_info
#undef FCNAME
#define FCNAME MPIDI_QUOTE(FUNCNAME)
379
int MPID_Win_get_info(MPID_Win * win, MPID_Info ** info_used)
380 381 382 383 384 385 386
{
    int mpi_errno = MPI_SUCCESS;
    MPIDI_STATE_DECL(MPID_STATE_MPID_WIN_GET_INFO);

    MPIDI_FUNC_ENTER(MPID_STATE_MPID_WIN_GET_INFO);

    mpi_errno = win->RMAFns.Win_get_info(win, info_used);
387 388 389
    if (mpi_errno != MPI_SUCCESS) {
        MPIU_ERR_POP(mpi_errno);
    }
390

391
  fn_exit:
392 393
    MPIDI_FUNC_EXIT(MPID_STATE_MPID_WIN_GET_INFO);
    return mpi_errno;
394
  fn_fail:
395 396
    goto fn_exit;
}