Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add MPICH3 rma tests (15 out of 88 should be passing now)
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / attrorderwin.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 "mpi.h"
8 #include <stdio.h>
9 #include "mpitest.h"
10
11 /*
12 static char MTestDescrip[] = "Test creating and inserting attributes in \
13 different orders to ensure that the list management code handles all cases.";
14 */
15
16 int checkAttrs( MPI_Win win, int n, int key[], int attrval[] );
17 int checkNoAttrs( MPI_Win win, int n, int key[] );
18
19 int main( int argc, char *argv[] )
20 {
21     int errs = 0;
22     int key[3], attrval[3];
23     int i;
24     int buf[1];
25     MPI_Comm comm;
26     MPI_Win  win;
27
28     MTest_Init( &argc, &argv );
29
30     {
31         comm = MPI_COMM_WORLD;
32         MPI_Win_create( buf, sizeof(int), sizeof(int), MPI_INFO_NULL,
33                         comm, &win );
34
35         /* Create key values */
36         for (i=0; i<3; i++) {
37             MPI_Win_create_keyval( MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN,
38                                &key[i], (void *)0 );
39             attrval[i] = 1024 * i;
40         }
41         
42         /* Insert attribute in several orders.  Test after put with get,
43          then delete, then confirm delete with get. */
44
45         MPI_Win_set_attr( win, key[2], &attrval[2] );
46         MPI_Win_set_attr( win, key[1], &attrval[1] );
47         MPI_Win_set_attr( win, key[0], &attrval[0] );
48
49         errs += checkAttrs( win, 3, key, attrval );
50         
51         MPI_Win_delete_attr( win, key[0] );
52         MPI_Win_delete_attr( win, key[1] );
53         MPI_Win_delete_attr( win, key[2] );
54
55         errs += checkNoAttrs( win, 3, key );
56         
57         MPI_Win_set_attr( win, key[1], &attrval[1] );
58         MPI_Win_set_attr( win, key[2], &attrval[2] );
59         MPI_Win_set_attr( win, key[0], &attrval[0] );
60
61         errs += checkAttrs( win, 3, key, attrval );
62         
63         MPI_Win_delete_attr( win, key[2] );
64         MPI_Win_delete_attr( win, key[1] );
65         MPI_Win_delete_attr( win, key[0] );
66
67         errs += checkNoAttrs( win, 3, key );
68
69         MPI_Win_set_attr( win, key[0], &attrval[0] );
70         MPI_Win_set_attr( win, key[1], &attrval[1] );
71         MPI_Win_set_attr( win, key[2], &attrval[2] );
72
73         errs += checkAttrs( win, 3, key, attrval );
74         
75         MPI_Win_delete_attr( win, key[1] );
76         MPI_Win_delete_attr( win, key[2] );
77         MPI_Win_delete_attr( win, key[0] );
78
79         errs += checkNoAttrs( win, 3, key );
80         
81         for (i=0; i<3; i++) {
82             MPI_Win_free_keyval( &key[i] );
83         }
84         MPI_Win_free( &win );
85     }
86     
87     MTest_Finalize( errs );
88     MPI_Finalize();
89     return 0;
90   
91 }
92
93 int checkAttrs( MPI_Win win, int n, int key[], int attrval[] )
94 {
95     int errs = 0;
96     int i, flag, *val_p;
97
98     for (i=0; i<n; i++) {
99         MPI_Win_get_attr( win, key[i], &val_p, &flag );
100         if (!flag) {
101             errs++;
102             fprintf( stderr, "Attribute for key %d not set\n", i );
103         }
104         else if (val_p != &attrval[i]) {
105             errs++;
106             fprintf( stderr, "Atribute value for key %d not correct\n",
107                      i );
108         }
109     }
110
111     return errs;
112 }
113
114 int checkNoAttrs( MPI_Win win, int n, int key[] )
115 {
116     int errs = 0;
117     int i, flag, *val_p;
118
119     for (i=0; i<n; i++) {
120         MPI_Win_get_attr( win, key[i], &val_p, &flag );
121         if (flag) {
122             errs++;
123             fprintf( stderr, "Attribute for key %d set but should be deleted\n", i );
124         }
125     }
126
127     return errs;
128 }
129