-
Notifications
You must be signed in to change notification settings - Fork 2
/
mpi_netcdf.sh
executable file
·460 lines (423 loc) · 12.5 KB
/
mpi_netcdf.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
#!/bin/bash
# Install NetCDF4 (along with zlib and HDF5 it needs) from the source code
# Originally written by Seb Eastham
curl_version="7.67.0"
zlib_version="1.2.11"
#zlib_version="1.2.12"
szip_version="2.1.1"
hdf_version="1.10.6"
#ncc_version="4.7.3"
ncc_version="4.7.4"
#ncf_version="4.5.2"
ncf_version="4.5.4"
ncpp_version="4.3.1"
openmpi_version="4.0.4"
cmake_version="3.16.5"
mvapich2_version="2.3.4"
# Initialize our own variables:
install_curl=true
install_zlib=true
install_szip=true
install_hdf5=true
install_ncc=true
install_ncf=true
install_nc_cpp=false
install_cmake=false
dry_run=false
force_install=false
clobberDir=0
while getopts "cdops:f" opt; do
case "$opt" in
d)
dry_run=true
;;
c)
install_cmake=true
;;
f)
force_install=true
;;
o)
clobberDir=1
;;
p)
install_nc_cpp=true
;;
s) skip_list=$OPTARG
for skip_lib in $(echo $skip_list | sed "s/,/ /g")
do
if [[ "$skip_lib" == "curl" ]]; then
install_curl=false
elif [[ "$skip_lib" == "zlib" ]]; then
install_zlib=false
elif [[ "$skip_lib" == "szip" ]]; then
install_szip=false
elif [[ "$skip_lib" == "hdf5" ]]; then
install_hdf5=false
elif [[ "$skip_lib" == "netcdf-c" ]]; then
install_ncc=false
elif [[ "$skip_lib" == "netcdf-fortran" ]]; then
install_ncf=false
elif [[ "$skip_lib" == "cmake" ]]; then
install_cmake=false
else
echo "Invalid argument given: $skip_lib"
exit 94
fi
done
;;
esac
done
if [[ "$force_install" == "false" ]]; then
ldc=ldconfig
which $ldc &> /dev/null
if [[ $? -ne 0 ]]; then
ls /usr/sbin/ldconfig &> /dev/null
if [[ $? -ne 0 ]]; then
echo "Cannot find ldconfig; cannot check for existence of libraries"
echo "Reverting to user selections"
else
ldc=/usr/sbin/ldconfig
fi
fi
# curl
wc_check=$( $ldc -p | grep "libcurl.so " | wc -l )
if [[ $wc_check -eq 0 ]]; then
so4_check=$( ldc -p | grep "libcurl.so.4" )
if [[ $? -eq 0 ]]; then
# libcurl exists, but need a softlink to the specific library
lc_loc=$( echo $so4_check | rev | cut -d" " -f 1 | rev )
if [[ ! -d $installDir/lib ]]; then
mkdir $installDir/lib
fi
ln -s $lc_loc $installDir/lib
echo "Found and linked existing curl distribution"
install_curl=false
else
install_curl=true
fi
else
echo "Found existing curl distribution; no link required"
install_curl=false
fi
fi
echo "Install curl : $install_curl"
echo "Install zlib : $install_zlib"
echo "Install szip : $install_szip"
echo "Install HDF-5 : $install_hdf5"
echo "Install NetCDF-C : $install_ncc"
echo "Install NetCDF-Fortran : $install_ncf"
echo "Install NetCDF-C++ : $install_nc_cpp"
echo "Install CMake : $install_cmake"
if [[ "$dry_run" == "true" || ! -d src_all ]]; then
echo "Setting up source code directory (one-time operation)"
./dl_files.sh $curl_version $zlib_version $szip_version $hdf_version $ncc_version $ncf_version $ncpp_version $openmpi_version $cmake_version $mvapich2_version
if [[ $? -ne 0 ]]; then
echo "Failed to download source files"
exit 90
fi
fi
if [[ "$dry_run" == "true" ]]; then
echo "Source files checked and acquired."
exit 0
fi
# Check environment variables
if [[ "z$NETCDF_HOME" == "z" ]]; then
echo "Variable NETCDF_HOME must be defined"
exit 80
elif [[ "z$NETCDF_FORTRAN_HOME" == "z" ]]; then
echo "Variable NETCDF_FORTRAN_HOME must be defined"
exit 80
elif [[ "$NETCDF_HOME" != "$NETCDF_FORTRAN_HOME" ]]; then
echo "NETCDF_HOME must match NETCDF_FORTRAN_HOME"
exit 81
fi
if [[ "z$TMPDIR" == "z" ]]; then
change_dir=y
else
read -p "Temporary directory will be created in $TMPDIR; would you like to change this? [y/n] " change_dir
fi
if [[ "$change_dir" == "y" ]]; then
read -p "Please enter target directory for temporary files: " new_tmpdir
export TMPDIR=$new_tmpdir
if [[ ! -d $TMPDIR ]]; then
mkdir $TMPDIR
if [[ $? -ne 0 ]]; then
echo "Creation of temporary directory $TMPDIR failed. Aborting"
exit 95
fi
fi
fi
read -p "Force compilers to be MPI wrappers? [y/n] " force_mpi
if [[ "$force_mpi" == "y" ]]; then
echo "Changing compilers to match standard choices"
if [[ "$ESMF_COMM" == "intelmpi" ]]; then
export CC=mpiicc
export CXX=mpiicpc
export FC=mpiifort
else
export CC=mpicc
export CXX=mpicxx
export FC=mpif90
fi
export F90=$FC
export F77=$FC
elif [[ "$force_mpi" == "n" ]]; then
echo "Compilers will be left as given"
else
echo "Must give y/n answer"
exit 70
fi
echo "CC => " $CC
echo "CXX => " $CXX
echo "FC => " $FC
echo "F77 => " $F77
echo "F90 => " $F90
if [[ "$CC" != "mpi"* ]]; then
echo "Need MPI wrappers to compile"
exit 80
fi
# Set up the compilers
if [[ "x$F90" == "x" ]]; then
echo "Fortran compilers not fully set up"
exit 90
fi
if [[ "$MPI_ROOT/bin/mpicc" != $( which mpicc ) ]]; then
echo "WARNING: which mpicc gives $( which mpicc ) and your MPI root is $MPI_ROOT"
read -p "Are you sure you wish to proceed? [y/n] " keep_going
if [[ "$keep_going" != "y" ]]; then
echo "Aborting"
exit 95
fi
fi
# Set up an installation directory
installDir=$NETCDF_HOME
srcDir=$(mktemp -d -t ci-XXXXXXXXXX )
if [[ $? -ne 0 ]]; then
echo "Failed to generate temporary directory"
exit 99
fi
echo "Using temporary directory $srcDir"
if [[ -d $installDir ]]; then
echo "WARNING: Installation directory $installDir already exists"
if [[ $clobberDir -eq 0 ]]; then
echo "Clobbering disabled. To proceed with the installation, either delete the current installation directory or (UNSAFE) set clobberDir in the installation script to a non-zero value"
exit 91
fi
else
mkdir $installDir
if [[ $? -ne 0 ]]; then
echo "Could not make installation directory. Aborting"
exit 92
fi
fi
cp -a src_all/* $srcDir/.
if [[ ! -d $srcDir ]]; then
mkdir $srcDir
fi
# Easiest to install all tools to one directory
export CURLDIR=$installDir
export ZDIR=$installDir
export SZDIR=$installDir
export H5DIR=$installDir
export NCDIR=$installDir
export NFDIR=$installDir
export NCPPDIR=$installDir
# NOTE: The installation instructions for HDF5 and NetCDF will show only "make check" and "make install", but this can
# sometimes result in failure due to a bad build order. Running "make -> make check -> make install" is slower but safer.
echo " The following packages will be downloaded and installed:"
if [[ "$install_curl" == "true" ]]; then
echo " curl =============> $CURLDIR"
fi
if [[ "$install_zlib" == "true" ]]; then
echo " ZLib =============> $ZDIR"
fi
if [[ "$install_szip" == "true" ]]; then
echo " SZip =============> $SZDIR"
fi
if [[ "$install_hdf5" == "true" ]]; then
echo " HDF5 =============> $H5DIR"
fi
if [[ "$install_ncc" == "true" ]]; then
echo " NetCDF-C =========> $NCDIR"
fi
if [[ "$install_ncf" == "true" ]]; then
echo " NetCDF-Fortran ===> $NFDIR"
fi
if [[ "$install_nc_cpp" == "true" ]]; then
echo " NetCDF-C++ ===> $NFDIR"
fi
# 0. Install curl
if [[ "$install_curl" == "true" ]]; then
echo "Installing curl to $CURLDIR"
cd $srcDir
mkdir -p curl
cd curl
dir_name=curl-7.67.0
cp ../${dir_name}.tar.gz .
tar -xzf ${dir_name}.tar.gz
cd ${dir_name}
./configure --prefix=${CURLDIR} --without-librtmp
make
make test
make install
if [[ $? -eq 0 ]]; then
echo "curl successfully installed"
else
echo "Installation failed: curl. Aborting"
exit 92
fi
fi
# 1. Install ZLib
if [[ "$install_zlib" == "true" ]]; then
echo "Installing ZLib to $ZDIR"
cd $srcDir
mkdir -p zlib
cd zlib
cp ../zlib-${zlib_version}.tar.gz .
tar -xzf zlib-${zlib_version}.tar.gz
cd zlib-${zlib_version}
./configure --prefix=${ZDIR}
make
make check
make install
if [[ -e $ZDIR/lib/libz.a ]]; then
echo "ZLib successfully installed"
else
echo "Installation failed: ZLib. Aborting"
exit 92
fi
fi
# 1b. Install SZip
if [[ "$install_szip" == "true" ]]; then
echo "Installing SZip to $SZDIR"
cd $srcDir
mkdir szip
cd szip
cp ../szip-${szip_version}.tar.gz .
tar -xzf szip-${szip_version}.tar.gz
cd szip-${szip_version}
./configure --prefix=$SZDIR
make
make install
make check
if [[ $? -eq 0 ]]; then
echo "SZip successfully installed"
else
echo "Installation failed: SZip. Aborting"
exit 92
fi
fi
# 2. Install HDF5
if [[ "$install_hdf5" == "true" ]]; then
echo "Installing HDF-5 to $H5DIR"
cd $srcDir
mkdir -p hdf5
cd hdf5
cp ../hdf5-${hdf_version}.tar.gz .
tar -xzf hdf5-${hdf_version}.tar.gz
cd hdf5-${hdf_version}
./configure --enable-parallel --with-zlib=${ZDIR} --with-szlib=${SZDIR} --prefix=${H5DIR} --enable-fortran
make
# WARNING: This can sometimes take a VERY long time!
make check
make install
if [[ -e $H5DIR/bin/h5copy ]]; then
echo "HDF-5 successfully installed"
else
echo "Installation failed: HDF-5. Aborting"
exit 92
fi
fi
# Add HDF5 libraries to LD_LIBRARY_PATH
export LD_LIBRARY_PATH=${H5DIR}/lib:${LD_LIBRARY_PATH}
# 3. Install NetCDF-C
if [[ "$install_ncc" == "true" ]]; then
echo "Installing NetCDF-C to $NCDIR"
cd $srcDir
mkdir -p netcdf-c
cd netcdf-c
if [[ -d netcdf-c-${ncc_version} ]]; then
rm -rf netcdf-c-${ncc_version}
fi
cp ../netcdf-c-${ncc_version}.tar.gz .
tar -xzf netcdf-c-${ncc_version}.tar.gz
cd netcdf-c-${ncc_version}
NC_EXTRA="--enable-cxx-4"
CPPFLAGS=-I${H5DIR}/include LDFLAGS=-L${H5DIR}/lib ./configure --prefix=${NCDIR} ${NC_EXTRA}
make
make check
make install
if [[ -e $NCDIR/bin/nc-config ]]; then
echo "NetCDF-C ${ncc_version} successfully installed"
else
echo "Installation failed: NetCDF-C {ncc_version}. Aborting"
exit 92
fi
fi
# 4. Install NetCDF-Fortran
if [[ "$install_ncf" == "true" ]]; then
echo "Installing NetCDF-Fortran to $NFDIR"
cd $srcDir
mkdir -p netcdf-fortran
cd netcdf-fortran
#cp ../netcdf-fortran-${ncf_version}.tar.gz .
cp ../netcdf-fortran-${ncf_version}.zip .
if [[ -d netcdf-fortran-${ncf_version} ]]; then
rm -rf netcdf-fortran-${ncf_version}
fi
#tar -xzf netcdf-fortran-${ncf_version}.tar.gz
unzip netcdf-fortran-${ncf_version}.zip
cd netcdf-fortran-${ncf_version}
CPPFLAGS=-I${NCDIR}/include LDFLAGS=-L${NCDIR}/lib ./configure --prefix=${NFDIR} --disable-dap
make
make check
make install
if [[ -e $NFDIR/bin/nf-config ]]; then
echo "NetCDF-Fortran successfully installed"
else
echo "Installation failed: NetCDF-Fortran. Aborting"
exit 92
fi
fi
# 5. Install NetCDF-C++
if [[ "$install_nc_cpp" == "true" ]]; then
echo "Installing NetCDF-C++ to $NCPPDIR"
cd $srcDir
mkdir -p netcdf-cxx4
cd netcdf-cxx4
f_short=netcdf-cxx4-${ncpp_version}
#cp ../netcdf-fortran-${ncf_version}.tar.gz .
cp ../${f_short}.tar.gz .
if [[ -d ${f_short} ]]; then
rm -rf ${f_short}
fi
tar -xzf ${f_short}.tar.gz
#unzip netcdf-fortran-${ncf_version}.zip
cd ${f_short}
CPPFLAGS=-I${NCDIR}/include LDFLAGS=-L${NCDIR}/lib ./configure --prefix=${NCPPDIR}
make
make check
make install
if [[ $? == 0 ]]; then
echo "NetCDF-C++ successfully installed"
else
echo "Installation failed: NetCDF-Fortran. Aborting"
exit 92
fi
fi
# This is a bit too dangerous
#echo "Success. Removing temporary directory"
#rm -rf $srcDir
echo "Success. Left-over files are in $srcDir; suggest user removes them with the command"
echo "rm -rf $srcDir"
echo ""
echo "You have successfully installed NetCDF and all the supporting packages!"
echo "It is STRONGLY RECOMMENDED that you now modify the .bashrc file which "
echo "you use to run your chosen application to include the following lines: "
echo ""
echo "export NETCDF_HOME=$NETCDF_HOME"
echo "export NETCDF_FORTRAN_HOME=$NETCDF_FORTRAN_HOME"
echo "export PATH=\${NETCDF_HOME}/bin:\$PATH"
echo "export LD_LIBRARY_PATH=\${NETCDF_HOME}/lib:\$LD_LIBRARY_PATH"
exit 0