Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update RMA tests
[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 int me, nproc;
23 static const int verbose = 0;
24
25 int test_put(void);
26
27 int test_put(void)
28 {
29     MPI_Win dst_win;
30     double *dst_buf;
31     double src_buf[MAXELEMS];
32     int i, j;
33     int errs = 0;
34
35     MPI_Alloc_mem(sizeof(double) * nproc * MAXELEMS, MPI_INFO_NULL, &dst_buf);
36     MPI_Win_create(dst_buf, sizeof(double) * nproc * MAXELEMS, 1, MPI_INFO_NULL,
37                    MPI_COMM_WORLD, &dst_win);
38
39     for (i = 0; i < MAXELEMS; i++)
40         src_buf[i] = me + 1.0;
41
42     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, me, 0, dst_win);
43
44     for (i = 0; i < nproc * MAXELEMS; i++)
45         dst_buf[i] = 0.0;
46
47     MPI_Win_unlock(me, dst_win);
48
49     MPI_Barrier(MPI_COMM_WORLD);
50
51     for (i = 0; i < nproc; i++) {
52         /* int target = (me + i) % nproc; */
53         int target = i;
54         for (j = 0; j < COUNT; j++) {
55             if (verbose)
56                 printf("%2d -> %2d [%2d]\n", me, target, j);
57             MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, dst_win);
58             MPI_Put(&src_buf[j], sizeof(double), MPI_BYTE, target,
59                     (me * MAXELEMS + j) * sizeof(double), sizeof(double), MPI_BYTE, dst_win);
60             MPI_Win_unlock(target, dst_win);
61         }
62     }
63
64     MPI_Barrier(MPI_COMM_WORLD);
65
66     /* Check that the correct data was returned.  This assumes that the
67      * systems have the same data representations */
68     for (i = 0; i < nproc; i++) {
69         for (j = 0; j < COUNT; j++) {
70             if (dst_buf[i * MAXELEMS + j] != 1.0 + i) {
71                 errs++;
72                 printf("dst_buf[%d] = %e, expected %e\n",
73                        i * MAXELEMS + j, dst_buf[i * MAXELEMS + j], 1.0 + i);
74             }
75         }
76     }
77
78     MPI_Win_free(&dst_win);
79     MPI_Free_mem(dst_buf);
80
81     return errs;
82 }
83
84
85 int main(int argc, char *argv[])
86 {
87     int errs = 0;
88
89     MTest_Init(&argc, &argv);
90     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
91     MPI_Comm_rank(MPI_COMM_WORLD, &me);
92
93     assert(COUNT <= MAXELEMS);
94
95     if (me == 0 && verbose) {
96         printf("Test starting on %d processes\n", nproc);
97         fflush(stdout);
98     }
99
100     errs = test_put();
101
102     MPI_Barrier(MPI_COMM_WORLD);
103
104     MTest_Finalize(errs);
105     MPI_Finalize();
106     return MTestReturnValue(errs);
107 }