Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
this tests actually does not conform to the standard and crashed now, but it's OK...
[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, &key[i], (void *) 0);
33             attrval[i] = 1024 * i;
34         }
35
36         /* Insert attribute in several orders.  Test after put with get,
37          * then delete, then confirm delete with get. */
38
39         MPI_Type_set_attr(type, key[2], &attrval[2]);
40         MPI_Type_set_attr(type, key[1], &attrval[1]);
41         MPI_Type_set_attr(type, key[0], &attrval[0]);
42
43         errs += checkAttrs(type, 3, key, attrval);
44
45         MPI_Type_delete_attr(type, key[0]);
46         MPI_Type_delete_attr(type, key[1]);
47         MPI_Type_delete_attr(type, key[2]);
48
49         errs += checkNoAttrs(type, 3, key);
50
51         MPI_Type_set_attr(type, key[1], &attrval[1]);
52         MPI_Type_set_attr(type, key[2], &attrval[2]);
53         MPI_Type_set_attr(type, key[0], &attrval[0]);
54
55         errs += checkAttrs(type, 3, key, attrval);
56
57         MPI_Type_delete_attr(type, key[2]);
58         MPI_Type_delete_attr(type, key[1]);
59         MPI_Type_delete_attr(type, key[0]);
60
61         errs += checkNoAttrs(type, 3, key);
62
63         MPI_Type_set_attr(type, key[0], &attrval[0]);
64         MPI_Type_set_attr(type, key[1], &attrval[1]);
65         MPI_Type_set_attr(type, key[2], &attrval[2]);
66
67         errs += checkAttrs(type, 3, key, attrval);
68
69         MPI_Type_delete_attr(type, key[1]);
70         MPI_Type_delete_attr(type, key[2]);
71         MPI_Type_delete_attr(type, key[0]);
72
73         errs += checkNoAttrs(type, 3, key);
74
75         for (i = 0; i < 3; i++) {
76             MPI_Type_free_keyval(&key[i]);
77         }
78     }
79
80     MTest_Finalize(errs);
81     MPI_Finalize();
82     return 0;
83
84 }
85
86 int checkAttrs(MPI_Datatype type, int n, int key[], int attrval[])
87 {
88     int errs = 0;
89     int i, flag, *val_p;
90
91     for (i = 0; i < n; i++) {
92         MPI_Type_get_attr(type, key[i], &val_p, &flag);
93         if (!flag) {
94             errs++;
95             fprintf(stderr, "Attribute for key %d not set\n", i);
96         }
97         else if (val_p != &attrval[i]) {
98             errs++;
99             fprintf(stderr, "Attribute value for key %d not correct\n", i);
100         }
101     }
102
103     return errs;
104 }
105
106 int checkNoAttrs(MPI_Datatype type, int n, int key[])
107 {
108     int errs = 0;
109     int i, flag, *val_p;
110
111     for (i = 0; i < n; i++) {
112         MPI_Type_get_attr(type, key[i], &val_p, &flag);
113         if (flag) {
114             errs++;
115             fprintf(stderr, "Attribute for key %d set but should be deleted\n", i);
116         }
117     }
118
119     return errs;
120 }