File: attr2type.c

package info (click to toggle)
mpich 3.3-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 131,836 kB
  • sloc: ansic: 975,868; cpp: 57,437; f90: 53,762; perl: 19,562; xml: 12,464; sh: 12,303; fortran: 7,875; makefile: 7,078; ruby: 126; java: 100; python: 98; lisp: 19; php: 8; sed: 4
file content (119 lines) | stat: -rw-r--r-- 2,859 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
/*
 *
 *  (C) 2007 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include "mpitest.h"

static int foo_keyval = MPI_KEYVAL_INVALID;

int foo_initialize(void);
void foo_finalize(void);

int foo_copy_attr_function(MPI_Datatype type, int type_keyval,
                           void *extra_state, void *attribute_val_in,
                           void *attribute_val_out, int *flag);
int foo_delete_attr_function(MPI_Datatype type, int type_keyval,
                             void *attribute_val, void *extra_state);
static const char *my_func = 0;
static int verbose = 0;
static int delete_called = 0;
static int copy_called = 0;

int main(int argc, char *argv[])
{
    int mpi_errno;
    MPI_Datatype type, duptype;
    int rank;
    int errs = 0;

    MTest_Init(&argc, &argv);

    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    foo_initialize();

    mpi_errno = MPI_Type_contiguous(2, MPI_INT, &type);

    mpi_errno = MPI_Type_set_attr(type, foo_keyval, NULL);

    mpi_errno = MPI_Type_dup(type, &duptype);

    my_func = "Free of type";
    mpi_errno = MPI_Type_free(&type);

    my_func = "free of duptype";
    mpi_errno = MPI_Type_free(&duptype);

    foo_finalize();

    if (rank == 0) {
        if (copy_called != 1) {
            printf("Copy called %d times; expected once\n", copy_called);
            errs++;
        }
        if (delete_called != 2) {
            printf("Delete called %d times; expected twice\n", delete_called);
            errs++;
        }
        fflush(stdout);
    }

    MTest_Finalize(errs);

    return MTestReturnValue(errs);
}

int foo_copy_attr_function(MPI_Datatype type,
                           int type_keyval,
                           void *extra_state,
                           void *attribute_val_in, void *attribute_val_out, int *flag)
{
    if (verbose)
        printf("copy fn. called\n");
    copy_called++;
    *(char **) attribute_val_out = NULL;
    *flag = 1;

    return MPI_SUCCESS;
}

int foo_delete_attr_function(MPI_Datatype type,
                             int type_keyval, void *attribute_val, void *extra_state)
{
    if (verbose)
        printf("delete fn. called in %s\n", my_func);
    delete_called++;

    return MPI_SUCCESS;
}

int foo_initialize(void)
{
    int mpi_errno;

    /* create keyval for use later */
    mpi_errno = MPI_Type_create_keyval(foo_copy_attr_function,
                                       foo_delete_attr_function, &foo_keyval, NULL);
    if (verbose)
        printf("created keyval\n");

    return 0;
}

void foo_finalize(void)
{
    int mpi_errno;

    /* remove keyval */
    mpi_errno = MPI_Type_free_keyval(&foo_keyval);

    if (verbose)
        printf("freed keyval\n");

    return;
}