Blame test/mpi/rma/locknull.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *
Packit 0848f5
 *  (C) 2008 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
#include "mpi.h"
Packit 0848f5
#include <stdio.h>
Packit 0848f5
#include <stdlib.h>
Packit 0848f5
#include "mpitest.h"
Packit 0848f5
#include <string.h>
Packit 0848f5
Packit 0848f5
/*
Packit 0848f5
static char MTEST_Descrip[] = "Locks with no RMA operations";
Packit 0848f5
*/
Packit 0848f5
Packit 0848f5
int main(int argc, char *argv[])
Packit 0848f5
{
Packit 0848f5
    int errs = 0;
Packit 0848f5
    int rank, size, i;
Packit 0848f5
    MPI_Comm comm;
Packit 0848f5
    MPI_Win win;
Packit 0848f5
    int *winbuf, count;
Packit 0848f5
Packit 0848f5
    MTest_Init(&argc, &argv);
Packit 0848f5
Packit 0848f5
    comm = MPI_COMM_WORLD;
Packit 0848f5
Packit 0848f5
    MPI_Comm_rank(comm, &rank;;
Packit 0848f5
    MPI_Comm_size(comm, &size);
Packit 0848f5
Packit 0848f5
    /* Allocate and initialize buf */
Packit 0848f5
    count = 1000;
Packit 0848f5
Packit 0848f5
    MPI_Alloc_mem(count * sizeof(int), MPI_INFO_NULL, &winbuf);
Packit 0848f5
Packit 0848f5
    MPI_Win_create(winbuf, count * sizeof(int), sizeof(int), MPI_INFO_NULL, comm, &win);
Packit 0848f5
Packit 0848f5
    /* Clear winbuf */
Packit 0848f5
    memset(winbuf, 0, count * sizeof(int));
Packit 0848f5
Packit 0848f5
    /* Note that for i == rank, this is a useful operation - it allows
Packit 0848f5
     * the programmer to use direct loads and stores, rather than
Packit 0848f5
     * put/get/accumulate, to access the local memory window. */
Packit 0848f5
    for (i = 0; i < size; i++) {
Packit 0848f5
        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, i, 0, win);
Packit 0848f5
        MPI_Win_unlock(i, win);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    for (i = 0; i < size; i++) {
Packit 0848f5
        MPI_Win_lock(MPI_LOCK_SHARED, i, 0, win);
Packit 0848f5
        MPI_Win_unlock(i, win);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MPI_Win_free(&win);
Packit 0848f5
    MPI_Free_mem(winbuf);
Packit 0848f5
Packit 0848f5
    /* If this test completes, no error has been found */
Packit 0848f5
    /* A more complete test may ensure that local locks in fact block
Packit 0848f5
     * remote, exclusive locks */
Packit 0848f5
    MTest_Finalize(errs);
Packit 0848f5
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return 0;
Packit 0848f5
}