1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2003 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
14 static char MTEST_Descrip[] = "RMA to self";
17 int main(int argc, char *argv[])
24 int *sbuf, scount, vcount;
27 MTest_Init(&argc, &argv);
29 comm = MPI_COMM_WORLD;
31 MPI_Comm_rank(comm, &rank);
32 MPI_Comm_size(comm, &size);
34 /* Allocate and initialize sbuf */
37 sbuf = (int *) malloc(scount * sizeof(int));
39 fprintf(stderr, "Could not allocate send buffer f size %d\n", scount);
40 MPI_Abort(MPI_COMM_WORLD, 0);
42 for (i = 0; i < scount; i++)
45 MPI_Alloc_mem(count * sizeof(int), MPI_INFO_NULL, &winbuf);
47 /* This is a simple vector type */
49 MPI_Type_vector(vcount, 1, 2, MPI_INT, &vectype);
50 MPI_Type_commit(&vectype);
51 MPI_Win_create(winbuf, count * sizeof(int), sizeof(int), MPI_INFO_NULL, comm, &win);
53 /* Check with different combination of types, including non-contig on
57 memset(winbuf, 0, count * sizeof(int));
58 MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
59 MPI_Put(sbuf, 1, vectype, rank, 0, 1, vectype, win);
60 MPI_Win_unlock(rank, win);
63 for (i = 0; i < vcount; i++) {
64 if (winbuf[j] != sbuf[j]) {
66 fprintf(stderr, "VecPut: winbuf[%d] = %d, should = %d\n", j, winbuf[j], sbuf[j]);
71 memset(winbuf, 0, count * sizeof(int));
72 MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
73 MPI_Accumulate(sbuf, 1, vectype, rank, 0, 1, vectype, MPI_SUM, win);
74 MPI_Win_unlock(rank, win);
77 for (i = 0; i < vcount; i++) {
78 if (winbuf[j] != sbuf[j]) {
80 fprintf(stderr, "VecAcc: winbuf[%d] = %d, should = %d\n", j, winbuf[j], sbuf[j]);
85 /* Now, use get to fetch back the results that we just wrote */
86 memset(sbuf, 0, count * sizeof(int));
87 MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
88 MPI_Get(sbuf, 1, vectype, rank, 0, 1, vectype, win);
89 MPI_Win_unlock(rank, win);
92 for (i = 0; i < vcount; i++) {
93 if (winbuf[j] != sbuf[j]) {
95 fprintf(stderr, "VecAcc: winbuf[%d] = %d, should = %d\n", j, winbuf[j], sbuf[j]);
101 MPI_Free_mem(winbuf);
103 MPI_Type_free(&vectype);
105 MTest_Finalize(errs);