source: codes/icosagcm/devel/make_python @ 792

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

devel/unstructured : more fixes to mixed precision

  • 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 -f 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}
36
37function cmd_kernels() # this function is invoked by : './make_python kernels'
38{
39    cmd_clean
40    cd $KERNELS
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
46    cd $DYNAMICO_ROOT
47    touch src/dynamics/*.F90 src/diagnostics/*.F90 src/transport/*.F90 src/unstructured/*.F90
48}
49
50#------------------ Default action , invoked by : './make_python' --------------------
51
52function make_so()
53{
54    ARLIB=$1
55    SOLIB=$2
56
57    if [[ $ARLIB -nt $SOLIB ]]; then
58        echo $ARLIB is newer than $SOLIB
59        rm -f tmp.a
60        cp $ARLIB tmp.a
61        if [[ "$4" != "" ]] ; then ar vd tmp.a $4 ; fi
62        if [[ "$5" != "" ]] ; then ar vr tmp.a $5 ; fi
63        log $LINK $SOFLAGS $WHOLE_ARCHIVE tmp.a $NO_WHOLE_ARCHIVE $3 -o $SOLIB
64        rm -f tmp.a
65        $LDD $SOLIB
66    fi
67}
68
69
70function cmd_()
71{
72    echo "XIOS_ROOTDIR : $XIOS_ROOTDIR"
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
87    make_so $XIOS_ROOTDIR/lib/libxios.a $LIBDIR/libxios.so "$NETCDF_LDFLAGS -lstdc++"
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
89
90    # Cythonize Python modules
91    cd $DYNAMICO_ROOT/Python/src
92    NUMPY=$(python -c 'import numpy as np ; print np.get_include()')
93    CYTHONFLAGS="$SOFLAGS $LDFLAGS -L$LIBDIR -licosa $KERNELS_LDFLAGS"
94    LDSHARED="$LINK" CFLAGS="-fno-strict-aliasing -O2 -I$NUMPY" LDFLAGS="$CYTHONFLAGS" log python setup.py build_ext --inplace || exit
95
96    cp -fpr $DYNAMICO_ROOT/Python/dynamico $DYNAMICO_ROOT/lib
97    cp -fp *.so $DYNAMICO_ROOT/lib/dynamico/
98    cd $DYNAMICO_ROOT
99
100    for module in cxios unstructured meshes dyn time_step DCMIP; do
101        echo "from dynamico import $module"
102        LD_PRELOAD=$PYTHON_PRELOAD python -c "from dynamico import $module"
103    done
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
119cd Python/env ;  . ${CURRENT_ARCH}.env ; cd $DYNAMICO_ROOT
120
121time cmd_$1
Note: See TracBrowser for help on using the repository browser.