source: codes/icosagcm/devel/make_python @ 654

Last change on this file since 654 was 654, checked in by dubos, 6 years ago

devel : minor bigfix make_python

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