Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix a bunch of typos thanks to the new spell script. I only made the words starting...
[simgrid.git] / teshsuite / smpi / mpich3-test / attr / attrordertype.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_Datatype type, int n, int key[], int attrval[] );
17 int checkNoAttrs( MPI_Datatype type, 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     MPI_Datatype type;
25
26     MTest_Init( &argc, &argv );
27
28     {
29         type = MPI_INT;
30         /* Create key values */
31         for (i=0; i<3; i++) {
32             MPI_Type_create_keyval( MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN,
33                                &key[i], (void *)0 );
34             attrval[i] = 1024 * i;
35         }
36         
37         /* Insert attribute in several orders.  Test after put with get,
38          then delete, then confirm delete with get. */
39
40         MPI_Type_set_attr( type, key[2], &attrval[2] );
41         MPI_Type_set_attr( type, key[1], &attrval[1] );
42         MPI_Type_set_attr( type, key[0], &attrval[0] );
43
44         errs += checkAttrs( type, 3, key, attrval );
45         
46         MPI_Type_delete_attr( type, key[0] );
47         MPI_Type_delete_attr( type, key[1] );
48         MPI_Type_delete_attr( type, key[2] );
49
50         errs += checkNoAttrs( type, 3, key );
51         
52         MPI_Type_set_attr( type, key[1], &attrval[1] );
53         MPI_Type_set_attr( type, key[2], &attrval[2] );
54         MPI_Type_set_attr( type, key[0], &attrval[0] );
55
56         errs += checkAttrs( type, 3, key, attrval );
57         
58         MPI_Type_delete_attr( type, key[2] );
59         MPI_Type_delete_attr( type, key[1] );
60         MPI_Type_delete_attr( type, key[0] );
61
62         errs += checkNoAttrs( type, 3, key );
63
64         MPI_Type_set_attr( type, key[0], &attrval[0] );
65         MPI_Type_set_attr( type, key[1], &attrval[1] );
66         MPI_Type_set_attr( type, key[2], &attrval[2] );
67
68         errs += checkAttrs( type, 3, key, attrval );
69         
70         MPI_Type_delete_attr( type, key[1] );
71         MPI_Type_delete_attr( type, key[2] );
72         MPI_Type_delete_attr( type, key[0] );
73
74         errs += checkNoAttrs( type, 3, key );
75         
76         for (i=0; i<3; i++) {
77             MPI_Type_free_keyval( &key[i] );
78         }
79     }
80     
81     MTest_Finalize( errs );
82     MPI_Finalize();
83     return 0;
84   
85 }
86
87 int checkAttrs( MPI_Datatype type, int n, int key[], int attrval[] )
88 {
89     int errs = 0;
90     int i, flag, *val_p;
91
92     for (i=0; i<n; i++) {
93         MPI_Type_get_attr( type, key[i], &val_p, &flag );
94         if (!flag) {
95             errs++;
96             fprintf( stderr, "Attribute for key %d not set\n", i );
97         }
98         else if (val_p != &attrval[i]) {
99             errs++;
100             fprintf( stderr, "Attribute value for key %d not correct\n",
101                      i );
102         }
103     }
104
105     return errs;
106 }
107
108 int checkNoAttrs( MPI_Datatype type, int n, int key[] )
109 {
110     int errs = 0;
111     int i, flag, *val_p;
112
113     for (i=0; i<n; i++) {
114         MPI_Type_get_attr( type, key[i], &val_p, &flag );
115         if (flag) {
116             errs++;
117             fprintf( stderr, "Attribute for key %d set but should be deleted\n", i );
118         }
119     }
120
121     return errs;
122 }
123