File: dt_arch.c

package info (click to toggle)
openmpi 1.2.7~rc2-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 41,300 kB
  • ctags: 24,303
  • sloc: ansic: 224,835; sh: 22,627; makefile: 7,037; cpp: 6,353; asm: 3,547; lex: 528; objc: 383; perl: 348; csh: 89; f90: 49; fortran: 47; tcl: 12
file content (113 lines) | stat: -rw-r--r-- 4,034 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
/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
 * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2006 The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2006 The Regents of the University of California.
 *                         All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */
#include "ompi_config.h"
#include "dt_arch.h"

int32_t ompi_arch_compute_local_id( uint32_t *me )
{
    ompi_arch_create_empty_id( me );

    /* Handle the size of long (can hold a pointer) */
    if( 8 == sizeof(long) )
        ompi_arch_setmask( me, OMPI_ARCH_LONGIS64 );

    /* sizeof bool */
    if (1 == sizeof(bool) ) {
        ompi_arch_setmask( me, OMPI_ARCH_BOOLIS8);
    } else if (2 == sizeof(bool)) {
        ompi_arch_setmask( me, OMPI_ARCH_BOOLIS16);
    } else if (4 == sizeof(bool)) {
        ompi_arch_setmask( me, OMPI_ARCH_BOOLIS32);
    }

    /* sizeof fortran logical */
    if (1 == sizeof(ompi_fortran_logical_t) ) {
        ompi_arch_setmask( me, OMPI_ARCH_LOGICALIS8);
    } else if (2 == sizeof(ompi_fortran_logical_t)) {
        ompi_arch_setmask( me, OMPI_ARCH_LOGICALIS16);
    } else if (4 == sizeof(ompi_fortran_logical_t)) {
        ompi_arch_setmask( me, OMPI_ARCH_LOGICALIS32);
    }

    /* Initialize the information regarding the long double */
    if( 12 == sizeof(long double) )
        ompi_arch_setmask( me, OMPI_ARCH_LONGDOUBLEIS96 );
    else if( 16 == sizeof(long double) )
        ompi_arch_setmask( me, OMPI_ARCH_LONGDOUBLEIS128 );

    /* Big endian or little endian ? That's the question */
    if( ompi_arch_isbigendian() )
        ompi_arch_setmask( me, OMPI_ARCH_ISBIGENDIAN );

    /* What's the maximum exponent ? */
    if ( LDBL_MAX_EXP == 16384 )
        ompi_arch_setmask( me, OMPI_ARCH_LDEXPSIZEIS15 );

    /* How about the length in bits of the mantissa */
    if ( LDBL_MANT_DIG == 64 )
        ompi_arch_setmask( me, OMPI_ARCH_LDMANTDIGIS64 );
    else if ( LDBL_MANT_DIG == 105 )
        ompi_arch_setmask( me, OMPI_ARCH_LDMANTDIGIS105 );
    else if ( LDBL_MANT_DIG == 106 )
        ompi_arch_setmask( me, OMPI_ARCH_LDMANTDIGIS106 );
    else if ( LDBL_MANT_DIG == 107 )
        ompi_arch_setmask( me, OMPI_ARCH_LDMANTDIGIS107 );
    else if ( LDBL_MANT_DIG == 113 )
        ompi_arch_setmask( me, OMPI_ARCH_LDMANTDIGIS113 );

    /* Intel data representation or Sparc ? */
    if( ompi_arch_ldisintel() )
        ompi_arch_setmask( me, OMPI_ARCH_LDISINTEL );

    return OMPI_SUCCESS;
}

int32_t ompi_arch_checkmask ( uint32_t *var, uint32_t mask )
{
    unsigned int tmpvar = *var;

    /* Check whether the headers are set correctly,
       or whether this is an erroneous integer */
    if( !((*var) & OMPI_ARCH_HEADERMASK) ) {
        if( (*var) & OMPI_ARCH_HEADERMASK2 ) {
            char* pcDest, *pcSrc;
            /* Both ends of this integer have the wrong settings,
               maybe its just the wrong endian-representation. Try
               to swap it and check again. If it looks now correct,
               keep this version of the variable
            */

            pcDest = (char *) &tmpvar;
            pcSrc  = (char *) var + 3;
            *pcDest++ = *pcSrc--;
            *pcDest++ = *pcSrc--;
            *pcDest++ = *pcSrc--;
            *pcDest++ = *pcSrc--;

            if( (tmpvar & OMPI_ARCH_HEADERMASK) && (!(tmpvar & OMPI_ARCH_HEADERMASK2)) ) {
                *var = tmpvar;
            } else
                return -1;
        } else
            return -1;
    }

    /* Here is the real evaluation of the bitmask */
    return ( ((*var) & mask) == mask );
}