Logo AND Algorithmique Numérique Distribuée

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