Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
This particular RMA test is filled with stupid calls... We send errors for most of...
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / contention_putget.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/get test -- James Dinan <dinan@mcs.anl.gov>
8   *
9   * Each process issues COUNT put and get operations to non-overlapping
10   * locations on every other processs.
11   */
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <assert.h>
16 #include "mpi.h"
17
18 #define MAXELEMS      6400
19 #define COUNT         1000
20
21
22 static const int verbose = 0;
23
24 void test_put(void);
25 void test_put(void)
26 {
27     int me, nproc;
28     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
29     MPI_Comm_rank(MPI_COMM_WORLD, &me);
30     MPI_Win dst_win;
31     double *dst_buf;
32     double src_buf[MAXELEMS];
33     int i, j;
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, MPI_COMM_WORLD,
37                    &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 = i;
53
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         for (j = 0; j < COUNT; j++) {
64             if (verbose)
65                 printf("%2d <- %2d [%2d]\n", me, target, j);
66             MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, dst_win);
67             MPI_Get(&src_buf[j], sizeof(double), MPI_BYTE, target,
68                     (me * MAXELEMS + j) * sizeof(double), sizeof(double), MPI_BYTE, dst_win);
69             MPI_Win_unlock(target, dst_win);
70         }
71     }
72
73     MPI_Barrier(MPI_COMM_WORLD);
74
75     MPI_Win_free(&dst_win);
76     MPI_Free_mem(dst_buf);
77 }
78
79
80 int main(int argc, char *argv[])
81 {
82     MPI_Init(&argc, &argv);
83     int me, nproc;
84     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
85     MPI_Comm_rank(MPI_COMM_WORLD, &me);
86
87     assert(COUNT <= MAXELEMS);
88
89     if (me == 0 && verbose) {
90         printf("Test starting on %d processes\n", nproc);
91         fflush(stdout);
92     }
93
94     test_put();
95
96     MPI_Barrier(MPI_COMM_WORLD);
97
98     MPI_Finalize();
99
100     if (me == 0 && verbose) {
101         printf("Test completed.\n");
102         fflush(stdout);
103     }
104
105     if (me == 0)
106         printf(" No Errors\n");
107
108     return 0;
109 }