Allwmake 4.53 KB
Newer Older
1
#!/bin/sh
2
3
4
5
cd ${0%/*} || exit 1    # Run from this directory

# Parse arguments for library compilation
. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Test for metis.
# - return 0 and export METIS_ARCH_PATH on success
hasMetis()
{
    echo
    echo "Metis decomposition"

    unset METIS_ARCH_PATH METIS_VERSION
    settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/metis) || {
        echo
        echo "Error: no config.sh/metis settings"
        echo
        return 1
    }

22
    . $settings
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
    if [ -z "$METIS_ARCH_PATH" -o "${METIS_ARCH_PATH##*-}" = none ]
    then
        echo "   skipping - no metis"
        echo
        return 1
    fi

    # Header
    local header=$METIS_ARCH_PATH/include/metis.h
    if [ "${METIS_ARCH_PATH##*-}" = system ]
    then
        [ -f "$header" ] || header=/usr/include/metis.h
    fi
    [ -f "$header" ] || {
        echo "    skipping - no metis header"
        echo
        return 2  # file not found
    }

    # Library
    [ -r $FOAM_EXT_LIBBIN/libmetis.so ] || \
    [ -r $METIS_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/libmetis.so ] || \
    [ "${METIS_ARCH_PATH##*-}" = system ] || {
        echo "   skipping - missing library"
        echo
        return 2
    }

    # Ensure consistent sizes between OpenFOAM and metis header
52
53
    # Extract IDXTYPEWIDTH from metis.h: regex as per ThirdParty Allwmake
    local label=$(sed -ne 's/^.*#define  *IDXTYPEWIDTH  *\([1-9][0-9]\).*/\1/p' $header)
54
55
56
57
58
59
    [ "$WM_LABEL_SIZE" = "$label" ] || {
        echo "   skipping - label=$WM_LABEL_SIZE, metis.h has '$label'"
        echo
        return 1
    }

60
    echo "using METIS_ARCH_PATH=$METIS_ARCH_PATH"
61
    echo "    label=$label"
62
    echo
63
64
65
66
67
68
69
70
71
    export METIS_ARCH_PATH
    return 0 # success
}


# Test for scotch.
# - return 0 and export SCOTCH_ARCH_PATH, SCOTCH_VERSION on success
hasScotch()
{
72
    echo
73
74
75
76
77
78
79
80
81
    echo "Scotch decomposition"

    unset SCOTCH_ARCH_PATH SCOTCH_VERSION
    settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/scotch) || {
        echo
        echo "Error: no config.sh/scotch settings"
        echo
        return 1
    }
82

83
    . $settings
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
120
121
122
123
124
125
    if [ -z "$SCOTCH_ARCH_PATH" -o "${SCOTCH_ARCH_PATH##*-}" = none ]
    then
        echo "    skipping - no scotch"
        echo
        return 1
    fi

    # Header
    local header=$SCOTCH_ARCH_PATH/include/scotch.h
    if [ "${SCOTCH_ARCH_PATH##*-}" = system ]
    then
        [ -f "$header" ] || header=/usr/include/scotch.h
    fi
    [ -f "$header" ] || {
        echo "    skipping - no scotch header"
        echo
        return 2  # file not found
    }

    # Library
    [ -r $FOAM_EXT_LIBBIN/libscotch.so ] || \
    [ -r $SCOTCH_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/libscotch.so ] || \
    [ "${SCOTCH_ARCH_PATH##*-}" = system ] || {
        echo "    skipping - missing library"
        echo
        return 2
    }

    # Ensure consistent sizes between OpenFOAM and scotch header
    # extract 'typedef int64_t SCOTCH_Num' or equivalent
    local label=$(sed -ne \
        's/^.*typedef *\([^ ]*\) *SCOTCH_Num.*/\1/ip' \
        "$header")

    : ${label:=unknown}
    [ "$WM_LABEL_SIZE" = 32 -a \( "$label" = int32_t -o "$label" = int  \) ] || \
    [ "$WM_LABEL_SIZE" = 64 -a \( "$label" = int64_t -o "$label" = long \) ] || {
        echo "   skipping - label='$WM_LABEL_SIZE', scotch.h has '$label'"
        echo
        return 1
    }

126
    echo "using SCOTCH_ARCH_PATH=$SCOTCH_ARCH_PATH"
127
    echo "    label=$label ($WM_LABEL_SIZE)"
128
    echo
129
130
131
    export SCOTCH_ARCH_PATH SCOTCH_VERSION
    return 0 # success
}
132
133
134


#
135
# Define how to create an mpi-versioned library of $targetType
136
# compile into qualified directory
137
# use sentinel file(s) to handle version changes
138
139
140
#
wmakeMpiLib()
{
141
142
    local decompName="$1"
    shift
143
144
145
146
    for libName
    do
    (
        WM_OPTIONS="$WM_OPTIONS$WM_MPLIB"
147
148
        libDir="$WM_PROJECT_DIR/platforms/$WM_OPTIONS/src/parallel/decompose/$libName"
        whichmpi="$libDir/using:$FOAM_MPI"
149
150
        whichdecomp="$libDir/using:$decompName"
        [ -e "$whichmpi" -a -e "$whichdecomp" ] || wclean $libName
151
152
        echo "wmake $targetType $libName"
        wmake $targetType $libName
153
        mkdir -p "$libDir"
154
        touch "$whichdecomp" "$whichmpi"
155
156
157
158
    )
    done
}

159
160
wmakeLnInclude decompositionMethods

161
if hasScotch
162
then
163
    wmake $targetType scotchDecomp
164
165
    if [ -d "$FOAM_LIBBIN/$FOAM_MPI" ]
    then
166
        wmakeMpiLib "$SCOTCH_VERSION" ptscotchDecomp
167
    fi
168
169
fi

170
if hasMetis
171
172
173
then
    wmake $targetType metisDecomp
fi
174

175
176
wmake $targetType decompositionMethods
wmake $targetType decompose
177

178
#------------------------------------------------------------------------------