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 / keyval_double_free_win.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2015 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include <mpi.h>
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include "mpitest.h"
11
12 #define NUM_WIN 2
13 #define DATA_SZ sizeof(int)
14
15 /* tests multiple invocations of MPI_Win_free_keyval on the same keyval */
16
17 int delete_fn(MPI_Comm comm, int keyval, void *attr, void *extra);
18 int delete_fn(MPI_Comm comm, int keyval, void *attr, void *extra)
19 {
20     MPI_Win_free_keyval(&keyval);
21     return MPI_SUCCESS;
22 }
23
24 int main(int argc, char **argv)
25 {
26     void *base_ptr[NUM_WIN];
27     MPI_Win windows[NUM_WIN];
28     int keyval = MPI_KEYVAL_INVALID;
29     int keyval_copy = MPI_KEYVAL_INVALID;
30     int errs = 0;
31
32     MTest_Init(&argc, &argv);
33     MPI_Alloc_mem(DATA_SZ, MPI_INFO_NULL, &base_ptr[0]);
34     MPI_Win_create(base_ptr[0], DATA_SZ, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &windows[0]);
35     MPI_Alloc_mem(DATA_SZ, MPI_INFO_NULL, &base_ptr[1]);
36     MPI_Win_create(base_ptr[1], DATA_SZ, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &windows[1]);
37
38     MPI_Win_create_keyval(MPI_NULL_COPY_FN, delete_fn, &keyval, NULL);
39     keyval_copy = keyval;
40
41     MPI_Win_set_attr(windows[0], keyval, NULL);
42     MPI_Win_set_attr(windows[1], keyval, NULL);
43
44     MPI_Win_free(&windows[0]);      /* first MPI_Win_free_keyval */
45     MPI_Free_mem(base_ptr[0]);
46     MPI_Win_free_keyval(&keyval);   /* second MPI_Win_free_keyval */
47     MPI_Win_free_keyval(&keyval_copy);      /* third MPI_Win_free_keyval */
48     MPI_Win_free(&windows[1]);      /* fourth MPI_Win_free_keyval */
49     MPI_Free_mem(base_ptr[1]);
50     MTest_Finalize(errs);
51     MPI_Finalize();
52     return 0;
53 }
54