source: codes/icosagcm/devel/make_python @ 856

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

devel : towards Fortran driver for unstructured/LAM meshes

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