Skip to content

Commit

Permalink
updated installation scripts so it is self-contained
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Papior <[email protected]>
  • Loading branch information
zerothi committed Nov 8, 2018
1 parent 3d720e9 commit 3542d3a
Show file tree
Hide file tree
Showing 4 changed files with 382 additions and 14 deletions.
53 changes: 53 additions & 0 deletions executables/compile_upload_siesta.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

# This small script will compile and upload the executables to the
# website
base=$(pwd)
SIESTA_DIR=/home/nicpa/siesta/4.1
year=18

_obj=ObjTutorial$year

# First download and compile NetCDF
./install_netcdf4.bash

pushd $SIESTA_DIR

# Prepare directory (ensure it is clean)
rm -rf $_obj
mkdir -p $_obj
cd $_obj

# Ensure arch.make exists
rm -f arch.make
[ ! -e $base/static_gnu.make ] && echo "Failed to find static_gnu.make" && exit 1
ln -s $base/static_gnu.make arch.make

../Src/obj_setup.sh

function mmake {
local base=$1
shift
local suffix=$1
shift
make clean
make -j4 $@
[ $? -ne 0 ] && exit 1
scp $base tr:.p/sisl/workshop/$year/$base$suffix
[ $? -ne 0 ] && exit 1
}

mmake siesta ""
mmake siesta _sse USE_SSE=1
mmake siesta _avx USE_AVX=1
mmake siesta _avx2 USE_AVX2=1

cd ../Util/TS/TBtrans

mmake tbtrans "" OBJDIR=$_obj
mmake tbtrans _sse OBJDIR=$_obj USE_SSE=1
mmake tbtrans _avx OBJDIR=$_obj USE_AVX=1
mmake tbtrans _avx2 OBJDIR=$_obj USE_AVX2=1

popd

213 changes: 213 additions & 0 deletions executables/install_netcdf4.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
#!/bin/bash

# Installation script for zlib, hdf5, netcdf-c and netcdf-fortran
# with complete CDF-4 support (in serial).
# This installation script has been written by:
# Nick R. Papior, 2016-2018.
#
# The author takes no responsibility of damage done to your hardware or
# software. It is up to YOU that the script executes the correct commands.
#
# This script is released under the LGPL license.

# VERY BASIC installation script of required libraries
# for installing these packages:
# zlib-1.2.11
# hdf5-1.8.21
# netcdf-c-4.6.1
# netcdf-fortran-4.4.4
# If you want to change your compiler version you should define the
# global variables that are used for the configure scripts to grab the
# compiler, they should be CC and FC. Also if you want to compile with
# different flags you should export those variables; CFLAGS, FFLAGS.

# If you have downloaded other versions edit these version strings
z_v=1.2.11
h_v=1.8.21
nc_v=4.6.1
nf_v=4.4.4

# Install path, change accordingly
# You can change this variable to control the installation path
# If you want the installation path to be a "packages" folder in
# your home directory, change to this:
# ID=$HOME/packages
ID=$(pwd)/static-libs

echo "Installing libraries in folder: $ID"
mkdir -p $ID

# First we check that the user have downloaded the files
function file_exists {
if [ ! -e $(pwd)/$1 ]; then
echo "I could not find file $1..."
echo "Please download the file and place it in this folder:"
echo " $(pwd)"
exit 1
fi
}

# First we check that the user have downloaded the files
function dwn_file {
[ -e $2 ] && return 0
wget -O $2 $1
if [ $? -ne 0 ]; then
rm -f $2
fi
}

# Check for function $?
function retval {
local ret=$1
local info="$2"
shift 2
if [ $ret -ne 0 ]; then
echo "Error: $ret"
echo "$info"
exit 1
fi
}

dwn_file http://zlib.net/zlib-${z_v}.tar.gz .zlib-${z_v}.tar.gz
dwn_file https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8/hdf5-${h_v}/src/hdf5-${h_v}.tar.bz2 .hdf5-${h_v}.tar.bz2
dwn_file https://github.com/Unidata/netcdf-c/archive/v${nc_v}.tar.gz .netcdf-c-${nc_v}.tar.gz
dwn_file https://github.com/Unidata/netcdf-fortran/archive/v${nf_v}.tar.gz .netcdf-fortran-${nf_v}.tar.gz
unset dwn_file

file_exists .zlib-${z_v}.tar.gz
file_exists .hdf5-${h_v}.tar.bz2
file_exists .netcdf-c-${nc_v}.tar.gz
file_exists .netcdf-fortran-${nf_v}.tar.gz
unset file_exists

#################
# Install z-lib #
#################
[ -e $ID/lib64/libz.a ] && zlib_lib=lib64 || zlib_lib=lib
if [ ! -e $ID/$zlib_lib/libz.a ]; then
tar xfz .zlib-${z_v}.tar.gz
cd zlib-${z_v}
./configure --prefix $ID
retval $? "zlib config"
make
retval $? "zlib make"
make test 2>&1 | tee zlib.test
retval $? "zlib make test"
make install
retval $? "zlib make install"
mv zlib.test $ID/
cd ../
rm -rf zlib-${z_v}
echo "Completed installing zlib"
[ -e $ID/lib64/libz.a ] && zlib_lib=lib64 || zlib_lib=lib
else
echo "zlib directory already found."
fi

################
# Install hdf5 #
################
[ -e $ID/lib64/libhdf5.a ] && hdf5_lib=lib64 || hdf5_lib=lib
if [ ! -e $ID/$hdf5_lib/libhdf5.a ]; then
tar xfj .hdf5-${h_v}.tar.bz2
cd hdf5-${h_v}
mkdir build ; cd build
../configure --prefix=$ID --enable-static \
--enable-fortran --with-zlib=$ID
LDFLAGS="-L$ID/$zlib_lib -Wl,-rpath=$ID/$zlib_lib"
retval $? "hdf5 configure"
make
retval $? "hdf5 make"
make check-s 2>&1 | tee hdf5.test
retval $? "hdf5 make check-s"
make install
retval $? "hdf5 make install"
mv hdf5.test $ID/
cd ../../
rm -rf hdf5-${h_v}
echo "Completed installing hdf5"
[ -e $ID/lib64/libhdf5.a ] && hdf5_lib=lib64 || hdf5_lib=lib
else
echo "hdf5 directory already found."
fi

####################
# Install NetCDF-C #
####################
[ -e $ID/lib64/libnetcdf.a ] && cdf_lib=lib64 || cdf_lib=lib
if [ ! -e $ID/$cdf_lib/libnetcdf.a ]; then
tar xfz .netcdf-c-${nc_v}.tar.gz
cd netcdf-c-${nc_v}
mkdir build ; cd build
../configure --prefix=$ID --enable-static \
--enable-netcdf-4 --disable-dap \
CPPFLAGS="-I$ID/include" \
LDFLAGS="-L$ID/$hdf5_lib -Wl,-rpath=$ID/$hdf5_lib -L$ID/$zlib_lib -Wl,-rpath=$ID/$zlib_lib"
retval $? "netcdf configure"
make
retval $? "netcdf make"
make install
retval $? "netcdf make install"
cd ../../
rm -rf netcdf-c-${nc_v}
echo "Completed installing C NetCDF library"
[ -e $ID/lib64/libnetcdf.a ] && cdf_lib=lib64 || cdf_lib=lib
else
echo "netcdf directory already found."
fi

##########################
# Install NetCDF-Fortran #
##########################
if [ ! -e $ID/$cdf_lib/libnetcdff.a ]; then
tar xfz .netcdf-fortran-${nf_v}.tar.gz
cd netcdf-fortran-${nf_v}
mkdir build ; cd build
../configure CPPFLAGS="-DgFortran -I$ID/include" \
LIBS="-L$ID/$zlib_lib -Wl,-rpath=$ID/$zlib_lib \
-L$ID/$hdf5_lib -Wl,-rpath=$ID/$hdf5_lib \
-L$ID/$cdf_lib -Wl,-rpath=$ID/$cdf_lib \
-lnetcdf -lhdf5hl_fortran -lhdf5_fortran -lhdf5_hl -lhdf5 -lz" \
--prefix=$ID --enable-static
retval $? "netcdf-fortran configure"
make
retval $? "netcdf-fortran make"
make check 2>&1 | tee check.fortran.serial
retval $? "netcdf-fortran make check"
make install
retval $? "netcdf-fortran make install"
mv check.fortran.serial $ID/
cd ../../
rm -rf netcdf-fortran-${nf_v}
echo "Completed installing Fortran NetCDF library"
else
echo "netcdf-fortran library already found."
fi

##########################
# Completed installation #
##########################

echo ""
echo "##########################"
echo "# Completed installation #"
echo "# of NetCDF package #"
echo "# and its dependencies #"
echo "##########################"
echo ""
echo ""

echo "Please add the following to the BOTTOM of your arch.make file"
echo ""
echo "INCFLAGS += -I$ID/include"
echo "LDFLAGS += -L$ID/$zlib_lib -Wl,-rpath=$ID/$zlib_lib"
if [ $hdf5_lib != $zlib_lib ]; then
echo "LDFLAGS += -L$ID/$hdf5_lib -Wl,-rpath=$ID/$hdf5_lib"
fi
if [ $cdf_lib != $zlib_lib ]; then
echo "LDFLAGS += -L$ID/$cdf_lib -Wl,-rpath=$ID/$cdf_lib"
fi
echo "LIBS += -lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lz"
echo "COMP_LIBS += libncdf.a libfdict.a"
echo "FPPFLAGS += -DCDF -DNCDF -DNCDF_4"
echo ""
87 changes: 87 additions & 0 deletions executables/static_gnu.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
### Notes
# Compilation of static OpenBLAS with dynamic architecture may be
# done like this:
# make clean
# make DYNAMIC_ARCH=1 USE_THREAD=1 NUM_THREADS=4 USE_OPENMP=1 BINARY=64 SANITY_CHECK=1 MAX_STACK_ALLOC=2048 NO_LAPACK=0 CC=gcc FC=gfortran libs
# To install the NetCDF suite, simply do:
# ./install_netcdf4.bash

# Define whether the program should be compiled with SSE/AVX/AVX2
USE_SSE ?= 0
USE_AVX ?= 0
USE_AVX2 ?= 0

.SUFFIXES:
.SUFFIXES: .f .F .c .o .a .f90 .F90

SIESTA_ARCH=x86_64-gfortran-serial-static
FPP = gfortran
FPP_OUTPUT=
FC = gfortran
FC_SERIAL = gfortran
AR = gcc-ar
RANLIB = gcc-ranlib
SYS = nag
SP_KIND = 4
DP_KIND = 8
KINDS = $(SP_KIND) $(DP_KIND)

# Generic paths
#INC_PATH = -I/usr/local/include/ -I/usr/include/
#LIB_PATH = -L/usr/local/lib -L/usr/lib

# Add local paths for NetCDF4 installation and OpenBLAS
INSTALL_NCDF4_PATH = /home/nicpa/siesta/ts-tbt-sisl-tutorial/executables/static-libs
INC_PATH = -I$(INSTALL_NCDF4_PATH)/include
LIB_PATH = -L$(INSTALL_NCDF4_PATH)/lib -L$(INSTALL_NCDF4_PATH)/lib64

FFLAGS = -m64 -fPIC -O2 -ftree-vectorize -fexpensive-optimizations -fno-second-underscore $(INC_PATH)

ifeq ($(USE_AVX2),1)
FFLAGS += -mavx2
USE_AVX := 1
endif
ifeq ($(USE_AVX),1)
FFLAGS += -mavx
USE_SSE := 1
endif
ifeq ($(USE_SSE),1)
FFLAGS += -msse2
endif

INCFLAGS += $(INC_PATH)

FPPFLAGS = -DFC_HAVE_FLUSH -DFC_HAVE_ABORT -DCDF -DNCDF -DNCDF_4
COMP_LIBS = libncdf.a libfdict.a
COMP_LIBS += libsiestaLAPACK.a libsiestaBLAS.a

LDFLAGS = $(LIB_PATH)

# These two flags should work:
NETCDF_LIBS = -lnetcdff -lnetcdf

# The hdf5 libraries may have different names
#NETCDF_LIBS += -lhdf5 -lhdf5_serial
# Or
#NETCDF_LIBS += -lhdf5
NETCDF_LIBS += -lhdf5_hl -lhdf5

# Finally add zlib (and dl which is needed for HDF5, but ain't used)
NETCDF_LIBS += -lz -ldl

LIBS += $(NETCDF_LIBS)

# Ensure the executable is static
FFLAGS += -static
LDFLAGS += -static

#Dependency rules are created by autoconf according to whether
#discrete preprocessing is necessary or not.
.F.o:
$(FC) -c $(FFLAGS) $(INCFLAGS) $(FPPFLAGS) $(FPPFLAGS_fixed_F) $<
.F90.o:
$(FC) -c $(FFLAGS) $(INCFLAGS) $(FPPFLAGS) $(FPPFLAGS_free_F90) $<
.f.o:
$(FC) -c $(FFLAGS) $(INCFLAGS) $(FCFLAGS_fixed_f) $<
.f90.o:
$(FC) -c $(FFLAGS) $(INCFLAGS) $(FCFLAGS_free_f90) $<
Loading

0 comments on commit 3542d3a

Please sign in to comment.