Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
one more test for attr
[simgrid.git] / teshsuite / smpi / mpich3-test / attr / attrdelete.c
1 /*
2  * Copyright (C) by Argonne National Laboratory
3  *     See COPYRIGHT in top-level directory
4  */
5
6 /*
7   Having attr delete function to delete another attribute.
8  */
9 #include "mpi.h"
10 #include "mpitest.h"
11 #include <stdio.h>
12
13 int key1, key2, key3;
14
15 int test_communicator(MPI_Comm comm);
16
17 int main(int argc, char **argv)
18 {
19     int errs;
20     MTest_Init(&argc, &argv);
21     errs = test_communicator(MPI_COMM_WORLD);
22     MTest_Finalize(errs);
23     return MTestReturnValue(errs);
24 }
25
26 static int key2_delete_fn(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state)
27 {
28     MPI_Comm_delete_attr(comm, key1);
29     MPI_Comm_delete_attr(comm, key3);
30     return MPI_SUCCESS;
31 }
32
33 int test_communicator(MPI_Comm comm)
34 {
35     int errs = 0;
36     int rank, size;
37
38     MPI_Comm_rank(comm, &rank);
39     MPI_Comm_size(comm, &size);
40
41     MPI_Comm_create_keyval(MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN, &key1, NULL);
42     MPI_Comm_create_keyval(MPI_NULL_COPY_FN, key2_delete_fn, &key2, NULL);
43     MPI_Comm_create_keyval(MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN, &key3, NULL);
44
45     MPI_Comm_set_attr(comm, key1, (void *) (MPI_Aint) rank);
46     MPI_Comm_set_attr(comm, key2, (void *) (MPI_Aint) (rank + 100));
47     MPI_Comm_set_attr(comm, key3, (void *) (MPI_Aint) (rank + 200));
48
49     MPI_Comm_delete_attr(comm, key2);
50
51     MPI_Comm_free_keyval(&key1);
52     MPI_Comm_free_keyval(&key2);
53     MPI_Comm_free_keyval(&key3);
54
55     return errs;
56 }