Project

General

Profile

build_gromacs.sh

Koushik Choudhury, 10/11/2019 05:01 PM

 
1
#!/bin/bash
2
set -e
3

    
4
# Installation directory is $BASEDIR/$VERSION/$SIMD.
5
BASEDIR='/nethome/koushikc'
6
# List of SIMD variants to build. If you change this also change the ln commands
7
# at the end of this script accordingly.
8
BUILD_SIMD_LIST='SSE2 SSE4.1 AVX_128_FMA AVX_256 AVX2_128 AVX2_256 AVX_512'
9
# The versions to build. Can be plain version numbers or something like 5.1-debug.
10
# The latter will require editing this script below (look for CUSTOM FLAVORS HERE).
11
BUILD_VERSIONS='2020-beta1'
12

    
13
# Number of parallel jobs for make
14
JOBS=16
15

    
16
fftw_version=3.3.8-sse2-avx-avx2-avx128fma-avx512
17
fftw_noavx=3.3.8-sse2
18

    
19
# start with clean environment variables
20
export PATH=/usr/sbin:/usr/bin:/sbin:/bin LD_LIBRARY_PATH=''
21
. /usr/share/modules/init/bash
22
module load cmake/3.9 gcc/7.3 cuda/10.0 openmpi/4.0 hwloc/2.0.2 fftw/$fftw_version
23
#export CC=gcc-4.8 CXX=g++-4.8
24

    
25
for VERSION in $BUILD_VERSIONS; do
26
	if ! [ -w "$BASEDIR/$VERSION/." ]; then
27
		echo "No write access to $BASEDIR/$VERSION. Ask an admin to create the directory with correct permissions." >&2
28
		exit 1
29
	fi
30
done
31

    
32
# Build a list of SIMD variants we can test on this machine.
33
NATIVE_SIMD_LIST="SSE2"
34
grep -qw sse4_1 /proc/cpuinfo && NATIVE_SIMD_LIST+=" SSE4.1"
35
grep -qw avx /proc/cpuinfo && grep -qw fma4 /proc/cpuinfo && NATIVE_SIMD_LIST+=" AVX_128_FMA"
36
grep -qw avx /proc/cpuinfo && NATIVE_SIMD_LIST+=" AVX_256"
37
grep -qw avx2 /proc/cpuinfo && NATIVE_SIMD_LIST+=" AVX2_128 AVX2_256"
38
[ -c /dev/nvidia0 ] && GPU_AVAIL=true
39

    
40
cmake_install(){
41
	cmake "$@"
42
	make -j $JOBS
43
	if [[ "$NATIVE_SIMD_LIST" == *$SIMD* && ( "$GPU_AVAIL" == 'true' || "$GPU_BUILD" == 'OFF' ) ]]; then
44
		make -j $JOBS tests
45
		make check
46
	fi
47
	make install
48
}
49

    
50
CWDIR=$PWD
51
for VERSION in $BUILD_VERSIONS; do
52
	GMX_VERSION=${VERSION%%}
53
	FLAVOR=${VERSION#${GMX_VERSION}}
54
	FLAVOR=${FLAVOR#-}
55
	SRC_DIR="$CWDIR/gromacs-$GMX_VERSION"
56
	SRC_TARBALL="gromacs-${GMX_VERSION}.tar.gz"
57
	[ -f "$SRC_TARBALL" ] || wget -q "http://ftp.gromacs.org/gromacs/$SRC_TARBALL"
58
	[ -d "$SRC_DIR" ] && rm -rf "$SRC_DIR"
59
	tar xf "$SRC_TARBALL"
60
	BUILD_DIR="$SRC_DIR/build"
61
	#CMAKE_OPTS1="-DGMX_OPENMP=ON -DNVML_INC_DIR=$CUDA_HOME/gdk/usr/include/nvidia/gdk -DNVML_LIBRARY=$CUDA_HOME/gdk/usr/src/gdk/nvml/lib/libnvidia-ml.so -DGMX_EXTERNAL_BLAS=OFF -DGMX_EXTERNAL_BOOST=OFF -DGMX_EXTERNAL_LAPACK=OFF -DGMX_SYMLINK_OLD_BINARY_NAMES=OFF -DGMX_BUILD_UNITTESTS=ON -DREGRESSIONTEST_DOWNLOAD=ON"
62
	CMAKE_OPTS1="-DGMX_OPENMP=ON -DGMX_EXTERNAL_BLAS=OFF -DGMX_EXTERNAL_BOOST=OFF -DGMX_EXTERNAL_LAPACK=OFF -DGMX_SYMLINK_OLD_BINARY_NAMES=OFF -DGMX_BUILD_UNITTESTS=ON -DREGRESSIONTEST_DOWNLOAD=ON"
63
	for SIMD in $BUILD_SIMD_LIST; do
64
		[ -d "$BUILD_DIR" ] && rm -rf "$BUILD_DIR"
65
		mkdir "$BUILD_DIR"
66
		cd "$BUILD_DIR"
67
		if [[ "$SIMD" != AVX* ]]; then
68
			module switch fftw/$FFTW_VERSION fftw/$fftw_noavx
69
		else
70
			module switch fftw/$FFTW_VERSION fftw/$fftw_version
71
		fi
72
		INSTALL_DIR="$BASEDIR/$VERSION/$SIMD"
73
		CMAKE_OPTS2="-DGMX_SIMD=$SIMD -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DCMAKE_PREFIX_PATH=$FFTW_HOME"
74
		if [ -z "$FLAVOR" ]; then
75
			# Here we build and install gmx, gmx_mpi and gmx_d all in the same directory.
76
			GPU_BUILD=ON
77
			cmake_install "$SRC_DIR" $CMAKE_OPTS1 $CMAKE_OPTS2 -DGMX_GPU=$GPU_BUILD -DGMX_MPI=OFF -DGMX_THREAD_MPI=ON  -DGMX_DOUBLE=OFF
78
			cmake_install "$SRC_DIR" $CMAKE_OPTS1 $CMAKE_OPTS2 -DGMX_GPU=$GPU_BUILD -DGMX_MPI=ON  -DGMX_THREAD_MPI=OFF -DGMX_DOUBLE=OFF
79
			# GMX_DOUBLE=ON build fails with AVX_512 (v2016.2)
80
			[ "$SIMD" = 'AVX_512' ] && continue
81
			GPU_BUILD=OFF
82
		#	cmake_install "$SRC_DIR" $CMAKE_OPTS1 $CMAKE_OPTS2 -DGMX_GPU=$GPU_BUILD -DGMX_MPI=OFF -DGMX_THREAD_MPI=ON  -DGMX_DOUBLE=ON
83
		# CUSTOM FLAVORS HERE
84
		#elif [ "$FLAVOR" = 'strawberry' ]; then
85
		#	cmake_install "$SRC_DIR" $CMAKE_OPTS1 $CMAKE_OPTS2 -DSTRAWBERRIES=ON -DVANILLA=OFF
86
		else
87
			echo "No idea how to build $VERSION. Edit this script and add cmake options for \"$FLAVOR\" flavor." >&2
88
			exit 1
89
		fi
90
	done
91
	cd "$CWDIR"
92
	ln -s SSE2 "${INSTALL_DIR%/*}/legacy"
93
	ln -s SSE2 "${INSTALL_DIR%/*}/istanbul"
94
	ln -s SSE2 "${INSTALL_DIR%/*}/shanghai"
95
	ln -s SSE4.1 "${INSTALL_DIR%/*}/generic"
96
	ln -s SSE4.1 "${INSTALL_DIR%/*}/nehalem"
97
	ln -s AVX_128_FMA "${INSTALL_DIR%/*}/bulldozer"
98
	ln -s AVX_128_FMA "${INSTALL_DIR%/*}/piledriver"
99
	ln -s AVX_256 "${INSTALL_DIR%/*}/sandybridge"
100
	ln -s AVX2_256 "${INSTALL_DIR%/*}/haswell"
101
	ln -s AVX2_256 "${INSTALL_DIR%/*}/broadwell"
102
	ln -s AVX2_256 "${INSTALL_DIR%/*}/skylake"
103
	tar czvf "tcbsys_gromacs_${VERSION}.tar.gz" --owner=root --group=root -C "$BASEDIR" "$VERSION"
104
	echo "Created tarball $CWDIR/tcbsys_gromacs_${VERSION}.tar.gz from installed files."
105
done
106