1 | #!/bin/bash |
---|
2 | |
---|
3 | function log() |
---|
4 | { |
---|
5 | echo $* |
---|
6 | $* |
---|
7 | } |
---|
8 | |
---|
9 | function full_dir() |
---|
10 | { |
---|
11 | (cd -P $1 ; pwd) |
---|
12 | } |
---|
13 | |
---|
14 | #--------------- Generate kernels, invoked by : './make_python kernels' --------------- |
---|
15 | |
---|
16 | function update() |
---|
17 | { |
---|
18 | diff $2 $1 || log cp -pr $1 $2 |
---|
19 | } |
---|
20 | |
---|
21 | function 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 | |
---|
28 | function 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 | |
---|
50 | function 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 | |
---|
68 | function 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 | |
---|
94 | cp -fpr $DYNAMICO_ROOT/Python/dynamico $DYNAMICO_ROOT/lib |
---|
95 | cp -fp *.so $DYNAMICO_ROOT/lib/dynamico/ |
---|
96 | cd $DYNAMICO_ROOT |
---|
97 | |
---|
98 | for module in cxios unstructured meshes dyn time_step DCMIP; do |
---|
99 | echo "from dynamico import $module" |
---|
100 | LD_PRELOAD=$PYTHON_PRELOAD python -c "from dynamico import $module" |
---|
101 | done |
---|
102 | } |
---|
103 | |
---|
104 | #------------------------- script starts here ------------------------ |
---|
105 | |
---|
106 | DYNAMICO_ROOT=$PWD |
---|
107 | LIBDIR=$DYNAMICO_ROOT/lib |
---|
108 | KERNELS=$DYNAMICO_ROOT/Python |
---|
109 | |
---|
110 | . arch.env |
---|
111 | . arch.path |
---|
112 | |
---|
113 | echo "Selected architecture : $CURRENT_ARCH" |
---|
114 | |
---|
115 | if [[ "$CURRENT_ARCH" == "" ]] ; then echo "Current architecture undefined or unsupported" ; exit ; fi |
---|
116 | |
---|
117 | . Python/env/${CURRENT_ARCH}.env |
---|
118 | |
---|
119 | cmd_$1 |
---|