File: decode_handle

package info (click to toggle)
mpich 3.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • 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 (114 lines) | stat: -rwxr-xr-x 3,479 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
#!/usr/bin/env perl
#
# (C) 2011 by Argonne National Laboratory.
#     See COPYRIGHT in top-level directory.
#

# A simple perl script that takes handle values as arguments and decodes them.
# It can help minimize distraction in your brain during a marathon debugging
# session that comes from manually decoding these values.

use strict;
use warnings;

# the order here matters
my @kind_table = qw(
    INVALID
    COMM
    GROUP
    DATATYPE
    FILE
    ERRHANDLER
    OP
    INFO
    WIN
    KEYVAL
    ATTR
    REQUEST
    PROCGROUP
    VCONN
    WORKQ_ELEM
    GREQ_CLASS
);

my @type_table = qw(
    INVALID
    BUILTIN
    DIRECT
    INDIRECT
);

while (scalar @ARGV) {
    my $arg = shift @ARGV;

    # handle the (common) case of a hex value instead of a decimal integer
    if ($arg =~ m/^0x[0-9a-fA-F]+$/) {
        $arg = hex $arg;
    }

    my $kind = ($arg & 0x3c000000) >> 26;
    my $type = ($arg & 0xc0000000) >> 30;

    if ($kind_table[$kind] eq "DATATYPE" and $type_table[$type] eq "BUILTIN") {
        my $datatype_size = ($arg & 0x0000ff00) >> 8;
        printf("value=0x%08x kind=0x%x (%10s) type=0x%x (%8s) size=%d (0x%x)\n", $arg, $kind, $kind_table[$kind], $type, $type_table[$type], $datatype_size, $datatype_size);
    }
    else {
        printf("value=0x%08x kind=0x%x (%10s) type=0x%x (%8s)\n", $arg, $kind, $kind_table[$kind], $type, $type_table[$type]);
    }
}

## code from src/include/mpir_objects.h from which this script was derived
## ----8<----
##
## typedef enum MPII_Object_kind {
##   MPIR_COMM       = 0x1,
##   MPIR_GROUP      = 0x2,
##   MPIR_DATATYPE   = 0x3,
##   MPIR_FILE       = 0x4,               /* This is not used */
##   MPIR_ERRHANDLER = 0x5,
##   MPIR_OP         = 0x6,
##   MPIR_INFO       = 0x7,
##   MPIR_WIN        = 0x8,
##   MPID_KEYVAL     = 0x9,
##   MPIR_ATTR       = 0xa,
##   MPIR_REQUEST    = 0xb,
##   MPIR_PROCGROUP  = 0xc,               /* These are internal device objects */
##   MPIR_VCONN      = 0xd,
##   MPIR_WORKQ_ELEM = 0xe,
##   MPIR_GREQ_CLASS = 0xf
##   } MPII_Object_kind;
##
## #define HANDLE_MPI_KIND_SHIFT 26
## #define HANDLE_GET_MPI_KIND(a) ( ((a)&0x3c000000) >> HANDLE_MPI_KIND_SHIFT )
## #define HANDLE_SET_MPI_KIND(a,kind) ((a) | ((kind) << HANDLE_MPI_KIND_SHIFT))
## 
## /* returns the name of the handle kind for debugging/logging purposes */
## const char *MPIR_Handle_get_kind_str(int kind);
## 
## /* Handle types.  These are really 2 bits */
## #define HANDLE_KIND_INVALID  0x0
## #define HANDLE_KIND_BUILTIN  0x1
## #define HANDLE_KIND_DIRECT   0x2
## #define HANDLE_KIND_INDIRECT 0x3
## /* Mask assumes that ints are at least 4 bytes */
## #define HANDLE_KIND_MASK 0xc0000000
## #define HANDLE_KIND_SHIFT 30
## #define HANDLE_GET_KIND(a) (((unsigned)(a)&HANDLE_KIND_MASK)>>HANDLE_KIND_SHIFT)
## #define HANDLE_SET_KIND(a,kind) ((a)|((kind)<<HANDLE_KIND_SHIFT))
## 
## /* For indirect, the remainder of the handle has a block and index */
## #define HANDLE_INDIRECT_SHIFT 16
## #define HANDLE_BLOCK(a) (((a)& 0x03FF0000) >> HANDLE_INDIRECT_SHIFT)
## #define HANDLE_BLOCK_INDEX(a) ((a) & 0x0000FFFF)
## 
## /* Handle block is between 1 and 1024 *elements* */
## #define HANDLE_BLOCK_SIZE 256
## /* Index size is bewtween 1 and 65536 *elements* */
## #define HANDLE_BLOCK_INDEX_SIZE 1024
## 
## /* For direct, the remainder of the handle is the index into a predefined 
##    block */
## #define HANDLE_MASK 0x03FFFFFF
## #define HANDLE_INDEX(a) ((a)& HANDLE_MASK)
## ----8<----