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 / contention_put.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6
7 /** Contended RMA put test -- James Dinan <dinan@mcs.anl.gov>
8   *
9   * Each process issues COUNT put operations to non-overlapping locations on
10   * every other processs.
11   */
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <assert.h>
16 #include "mpi.h"
17 #include "mpitest.h"
18
19 #define MAXELEMS      6400
20 #define COUNT         1000
21
22 static const int verbose = 0;
23
24 int test_put(void);
25
26 int test_put(void)
27 {
28     int me, nproc;
29     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
30     MPI_Comm_rank(MPI_COMM_WORLD, &me);
31
32     assert(COUNT <= MAXELEMS);
33
34     if (me == 0 && verbose) {
35         printf("Test starting on %d processes\n", nproc);
36         fflush(stdout);
37     }
38
39     MPI_Win dst_win;
40     double *dst_buf;
41     double src_buf[MAXELEMS];
42     int i, j;
43     int errs = 0;
44
45     MPI_Alloc_mem(sizeof(double) * nproc * MAXELEMS, MPI_INFO_NULL, &dst_buf);
46     MPI_Win_create(dst_buf, sizeof(double) * nproc * MAXELEMS, 1, MPI_INFO_NULL,
47                    MPI_COMM_WORLD, &dst_win);
48
49     for (i = 0; i < MAXELEMS; i++)
50         src_buf[i] = me + 1.0;
51
52     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, me, 0, dst_win);
53
54     for (i = 0; i < nproc * MAXELEMS; i++)
55         dst_buf[i] = 0.0;
56
57     MPI_Win_unlock(me, dst_win);
58
59     MPI_Barrier(MPI_COMM_WORLD);
60
61     for (i = 0; i < nproc; i++) {
62         /* int target = (me + i) % nproc; */
63         int target = i;
64         for (j = 0; j < COUNT; j++) {
65             if (verbose)
66                 printf("%2d -> %2d [%2d]\n", me, target, j);
67             MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, dst_win);
68             MPI_Put(&src_buf[j], sizeof(double), MPI_BYTE, target,
69                     (me * MAXELEMS + j) * sizeof(double), sizeof(double), MPI_BYTE, dst_win);
70             MPI_Win_unlock(target, dst_win);
71         }
72     }
73
74     MPI_Barrier(MPI_COMM_WORLD);
75
76     /* Check that the correct data was returned.  This assumes that the
77      * systems have the same data representations */
78     for (i = 0; i < nproc; i++) {
79         for (j = 0; j < COUNT; j++) {
80             if (dst_buf[i * MAXELEMS + j] != 1.0 + i) {
81                 errs++;
82                 printf("dst_buf[%d] = %e, expected %e\n",
83                        i * MAXELEMS + j, dst_buf[i * MAXELEMS + j], 1.0 + i);
84             }
85         }
86     }
87
88     MPI_Win_free(&dst_win);
89     MPI_Free_mem(dst_buf);
90
91     return errs;
92 }
93
94
95 int main(int argc, char *argv[])
96 {
97     int errs = 0;
98
99     MTest_Init(&argc, &argv);
100
101     errs = test_put();
102
103     MPI_Barrier(MPI_COMM_WORLD);
104
105     MTest_Finalize(errs);
106     MPI_Finalize();
107     return MTestReturnValue(errs);
108 }