Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'mc'
[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) printf("%2d -> %2d [%2d]\n", me, target, j); 
56       MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, dst_win);
57       MPI_Put(&src_buf[j], sizeof(double), MPI_BYTE, target, 
58               (me*MAXELEMS+j)*sizeof(double), sizeof(double), MPI_BYTE, dst_win);
59       MPI_Win_unlock(target, dst_win);
60     }
61   }
62
63   MPI_Barrier(MPI_COMM_WORLD);
64
65   /* Check that the correct data was returned.  This assumes that the 
66      systems have the same data representations */
67   for (i=0; i<nproc; i++) {
68       for (j=0; j<COUNT; j++) {
69           if (dst_buf[i*MAXELEMS+j] != 1.0 + i) {
70               errs++;
71               printf( "dst_buf[%d] = %e, expected %e\n",
72                       i*MAXELEMS+j, dst_buf[i*MAXELEMS+j], 1.0 + i );
73           }
74       }
75   }
76
77   MPI_Win_free(&dst_win);
78   MPI_Free_mem(dst_buf);
79
80   return errs;
81 }
82
83
84 int main(int argc, char* argv[]) {
85     int errs = 0;
86
87     MTest_Init(&argc, &argv);
88     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
89     MPI_Comm_rank(MPI_COMM_WORLD, &me);
90     
91     assert(COUNT <= MAXELEMS);
92     
93     if (me == 0 && verbose) {
94         printf("Test starting on %d processes\n", nproc); 
95         fflush(stdout);
96     }
97     
98     errs = test_put();
99     
100     MPI_Barrier(MPI_COMM_WORLD);
101     
102     MTest_Finalize( errs );
103     MPI_Finalize();
104     return MTestReturnValue( errs );
105 }