Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://github.com/mpoquet/simgrid
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / baseattrwin.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2001 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include <stdio.h>
8 #include "mpi.h"
9 #include "mpitest.h"
10
11 int main( int argc, char **argv)
12 {
13     int    errs = 0;
14     void *v;
15     int  flag;
16     int  rank, size;
17     int base[1024];
18     MPI_Aint n;
19     int     disp;
20     MPI_Win win;
21
22     MTest_Init( &argc, &argv );
23     MPI_Comm_size( MPI_COMM_WORLD, &size );
24     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
25
26     /* Create a window; then extract the values */
27     n    = 1024;
28     disp = 4;
29     MPI_Win_create( base, n, disp, MPI_INFO_NULL, MPI_COMM_WORLD, &win );
30
31     MPI_Win_get_attr( win, MPI_WIN_BASE, &v, &flag );
32     if (!flag) {
33         errs++;
34         fprintf( stderr, "Could not get WIN_BASE\n" );
35     }
36     else {
37         /* MPI 2.1, section 11.2.2.  v must be a pointer to the start of the 
38          window.  It is not a pointer to a pointer to the start of the window. 
39         */
40         if ((int*)v != base) {
41             errs++;
42             fprintf( stderr, "Got incorrect value for WIN_BASE (%p, should be %p)", 
43                      v, base );
44         }
45     }
46
47     MPI_Win_get_attr( win, MPI_WIN_SIZE, &v, &flag );
48     if (!flag) {
49         errs++;
50         fprintf( stderr, "Could not get WIN_SIZE\n" );
51     }
52     else {
53         MPI_Aint vval = *(MPI_Aint*)v;
54         if (vval != n) {
55             errs++;
56             fprintf( stderr, "Got wrong value for WIN_SIZE (%ld, should be %ld)\n", 
57                      (long) vval, (long) n );
58         }
59     }
60
61     MPI_Win_get_attr( win, MPI_WIN_DISP_UNIT, &v, &flag );
62     if (!flag) {
63         errs++;
64         fprintf( stderr, "Could not get WIN_DISP_UNIT\n" );
65     }
66     else {
67         int vval = *(int*)v;
68         if (vval != disp) {
69             errs++;
70             fprintf( stderr, "Got wrong value for WIN_DISP_UNIT (%d, should be %d)\n",
71                      vval, disp );
72         }
73     }
74
75     MPI_Win_free(&win);
76     MTest_Finalize( errs );
77     MPI_Finalize( );
78     
79     return 0;
80 }