Logo AND Algorithmique Numérique Distribuée

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