source: codes/icosagcm/devel/make_python @ 846

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