Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Revert "[TESTS] SMPI/MPICH3: Fix failing rma test"
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / selfrma.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include "mpitest.h"
12
13 /*
14 static char MTEST_Descrip[] = "RMA to self";
15 */
16
17 int main(int argc, char *argv[])
18 {
19     int errs = 0;
20     int rank, size, i, j;
21     MPI_Comm comm;
22     MPI_Win win;
23     int *winbuf, count;
24     int *sbuf, scount, vcount;
25     MPI_Datatype vectype;
26
27     MTest_Init(&argc, &argv);
28
29     comm = MPI_COMM_WORLD;
30
31     MPI_Comm_rank(comm, &rank);
32     MPI_Comm_size(comm, &size);
33
34     /* Allocate and initialize sbuf */
35     scount = 1000;
36     count = 1000;
37     sbuf = (int *) malloc(scount * sizeof(int));
38     if (!sbuf) {
39         fprintf(stderr, "Could not allocate send buffer f size %d\n", scount);
40         MPI_Abort(MPI_COMM_WORLD, 0);
41     }
42     for (i = 0; i < scount; i++)
43         sbuf[i] = i;
44
45     MPI_Alloc_mem(count * sizeof(int), MPI_INFO_NULL, &winbuf);
46
47     /* This is a simple vector type */
48     vcount = count / 4;
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);
52
53     /* Check with different combination of types, including non-contig on
54      * both sides */
55
56     /* Clear winbuf */
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);
61     /* Check results */
62     j = 0;
63     for (i = 0; i < vcount; i++) {
64         if (winbuf[j] != sbuf[j]) {
65             errs++;
66             fprintf(stderr, "VecPut: winbuf[%d] = %d, should = %d\n", j, winbuf[j], sbuf[j]);
67         }
68         j += 2;
69     }
70
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);
75     /* Check results */
76     j = 0;
77     for (i = 0; i < vcount; i++) {
78         if (winbuf[j] != sbuf[j]) {
79             errs++;
80             fprintf(stderr, "VecAcc: winbuf[%d] = %d, should = %d\n", j, winbuf[j], sbuf[j]);
81         }
82         j += 2;
83     }
84
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);
90     /* Check results */
91     j = 0;
92     for (i = 0; i < vcount; i++) {
93         if (winbuf[j] != sbuf[j]) {
94             errs++;
95             fprintf(stderr, "VecAcc: winbuf[%d] = %d, should = %d\n", j, winbuf[j], sbuf[j]);
96         }
97         j += 2;
98     }
99
100     MPI_Win_free(&win);
101     MPI_Free_mem(winbuf);
102     free(sbuf);
103     MPI_Type_free(&vectype);
104
105     MTest_Finalize(errs);
106
107     MPI_Finalize();
108     return 0;
109 }