source: codes/icosagcm/devel/make_python @ 861

Last change on this file since 861 was 857, checked in by dubos, 5 years ago

devel : revert accidental change to make_python

  • Property svn:executable set to *
File size: 3.5 KB
Line 
1#!/bin/bash
2
3function log()
4{
5    echo $*
6    $*
7}
8
9function full_dir()
10{
11    (cd -P $1 ; pwd)
12}
13
14function cmd_clean() # cleanup, invoked by : './make_python clean'
15{
16    rm -rf lib/*.so lib/dynamico
17    cd $KERNELS/src
18    rm -rf *.o *.so build/
19}
20
21#--------------- Generate kernels, invoked by : './make_python kernels' ---------------
22
23function update()
24{
25    diff $2 $1 || log cp -pr $1 $2
26}
27
28function cmd_extract_dysl()
29{
30    XT=$DYNAMICO_ROOT/Python/src/kernels_extracted.jin
31    rm -f $XT
32    touch $XT
33    cd $DYNAMICO_ROOT/src
34    for F90 in */*.F90 ; do
35        sed -n '/BEGIN_DYSL/,/END_DYSL/{//b;p}' $F90 >> $XT
36    done
37    cd $DYNAMICO_ROOT
38}
39
40function update_kernels()
41{
42    cd $KERNELS/src/$1
43    for x in *.k90 ; do
44        update "$x" "$DYNAMICO_ROOT/src/$2/$x"
45    done
46}
47
48function cmd_kernels() # this function is invoked by : './make_python kernels'
49{
50    cmd_clean
51    cmd_extract_dysl
52    cd $KERNELS
53    ./codegen hexagonal hex_master unstructured
54    update_kernels hexagonal kernels_hex
55    update_kernels hex_master kernels_hex_master
56    update_kernels unstructured kernels_unst
57# make sure that ./rebuild recompiles dynamics
58    cd $DYNAMICO_ROOT
59    touch src/dynamics/*.F90 src/diagnostics/*.F90 src/transport/*.F90 src/unstructured/*.F90
60}
61
62#------------------ Default action , invoked by : './make_python' --------------------
63
64function make_so()
65{
66    ARLIB=$1
67    SOLIB=$2
68
69    if [[ $ARLIB -nt $SOLIB ]]; then
70        echo $ARLIB is newer than $SOLIB
71        rm -f tmp.a
72        cp $ARLIB tmp.a
73        if [[ "$4" != "" ]] ; then ar vd tmp.a $4 ; fi
74        if [[ "$5" != "" ]] ; then ar vr tmp.a $5 ; fi
75        log $LINK $SOFLAGS $WHOLE_ARCHIVE tmp.a $NO_WHOLE_ARCHIVE $3 -o $SOLIB
76        rm -f tmp.a
77        $LDD $SOLIB
78    fi
79}
80
81
82function cmd_()
83{
84    echo "XIOS_ROOTDIR : $XIOS_ROOTDIR"
85    MISSING=""
86    for module in netCDF4 jinja2 mpi4py; do
87        echo "import $module"
88        python -c "import $module" || MISSING="$MISSING $module"
89    done
90    if [[ "$MISSING" == "" ]] ; then
91        echo "All required Python modules seem present."
92    else
93        echo "Missing/dysfunctional python modules : $MISSING"
94        echo "Please fix your Python configuration"
95        exit
96    fi
97
98    log mpicc -c -std=c99 -fPIC $PARMETIS_CFLAGS Python/src/partition.c -o obj/partition.o
99    make_so $XIOS_ROOTDIR/lib/libxios.a $LIBDIR/libxios.so "$NETCDF_LDFLAGS -lstdc++"
100    make_so $LIBDIR/libicosa.a $LIBDIR/libicosa.so "-L$LIBDIR -lxios $KERNELS_LDFLAGS" "physics_external_mod.o physics_mod.o timeloop_gcm_mod.o icosa_init_mod.o" obj/partition.o
101
102    # Cythonize Python modules
103    cd $DYNAMICO_ROOT/Python/src
104    NUMPY=$(python -c 'import numpy as np ; print np.get_include()')
105    CYTHONFLAGS="$SOFLAGS $LDFLAGS -L$LIBDIR -licosa $KERNELS_LDFLAGS"
106    LDSHARED="$LINK" CFLAGS="-fno-strict-aliasing -O2 -I$NUMPY" LDFLAGS="$CYTHONFLAGS" log python setup.py build_ext --inplace || exit
107
108    cp -fpr $DYNAMICO_ROOT/Python/dynamico $DYNAMICO_ROOT/lib
109    cp -fp *.so $DYNAMICO_ROOT/lib/dynamico/dev/
110    cd $DYNAMICO_ROOT
111
112    for module in dev.cxios dev.unstructured meshes dyn time_step DCMIP; do
113        echo "import dynamico.$module"
114        LD_PRELOAD=$PYTHON_PRELOAD python -c "import dynamico.$module"
115    done
116}
117
118#------------------------- script starts here ------------------------
119
120DYNAMICO_ROOT=$PWD
121LIBDIR=$DYNAMICO_ROOT/lib
122KERNELS=$DYNAMICO_ROOT/Python
123
124. arch.env
125. arch.path
126
127echo "Selected architecture : $CURRENT_ARCH"
128
129if [[ "$CURRENT_ARCH" == "" ]] ; then echo "Current architecture undefined or unsupported" ; exit ; fi
130
131cd Python/env ;  . ${CURRENT_ARCH}.env ; cd $DYNAMICO_ROOT
132
133time cmd_$1
Note: See TracBrowser for help on using the repository browser.