source: codes/icosagcm/devel/make_python @ 621

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

devel/unstructured : mesh partitioning

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