-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·164 lines (136 loc) · 6.48 KB
/
setup.sh
File metadata and controls
executable file
·164 lines (136 loc) · 6.48 KB
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
#!/bin/bash
set -e # Exit with non-zero exit code if anything fails
# ============================================================================ #
# Print the help message
function help() {
echo -e "Usage: $0 [options]"
echo -e "Options:"
echo -e "\t-h, --help Show this help message and exit"
echo -e "\t-t, --tests Run the tests after the installation"
echo -e "\t-c, --clean Clean the build directory before compiling"
echo -e "\t-q, --quiet Suppress output"
echo -e "\t-d, --device Device type to compile for (off, CUDA, HIP)"
echo -e "\t-e, --examples Build the examples"
echo -e "\t --docs Build the documentation"
echo -e ""
echo -e "Compilation and setup of Neko-TOP, this script will install all"
echo -e "the dependencies and compile the Neko-TOP code."
echo -e ""
echo -e "Environment Variables:"
echo -e "\tNEKO_DIR The directory where Neko is installed"
echo -e "\tJSON_FORTRAN_DIR The directory where JSON-Fortran is installed"
echo -e "\tNEK5000_DIR The directory where Nek5000 is installed"
echo -e "\tPFUNIT_DIR The directory where PFUnit is installed"
echo -e "\tGSLIB_DIR The directory where GSLIB is installed"
echo -e "\tCUDA_DIR The directory where CUDA is installed"
echo -e "\tHIP_DIR The directory where HIP is installed"
echo -e "\tBLAS_DIR The directory where BLAS is installed"
echo -e "\tCMAKE_VARIABLES Additional variables to pass to CMake"
echo -e "\tNEKO_CONFIG_FLAGS Additional features to pass to neko configure"
}
# ============================================================================ #
# Set main directories
export CURRENT_DIR=$(pwd)
export MAIN_DIR=$(dirname $(realpath $0))
export EXTERNAL_DIR="$MAIN_DIR/external"
# ============================================================================ #
# Parse the options
# Assign default values to the options
DEVICE_TYPE="CPU"
CLEAN=false
CLEAN_NEKO=false
QUIET=false
TEST=OFF
DOCS=OFF
EXAMPLES=OFF
# List possible options
OPTIONS=help,tests,clean,clean-neko,quiet,device:,docs,examples
OPT=h,t,c,q,d:,e
# Parse the inputs for options
PARSED=$(getopt --options=$OPT --longoptions=$OPTIONS --name "$0" -- "$@")
eval set -- "$PARSED"
# Loop through the options and set the variables
while true; do
case "$1" in
"-h" | "--help") help && exit ;; # Print help
"-t" | "--tests") TEST="ON" && shift ;; # Build the tests
"-c" | "--clean") CLEAN=true && shift ;; # Clean compilation
"-q" | "--quiet") QUIET=true && shift ;; # Suppress output
"-d" | "--device") DEVICE_TYPE="$2" && shift 2 ;; # Device type
"-e" | "--examples") EXAMPLES="ON" && shift ;; # Build the examples
# Purely long settings
"--docs") DOCS="ON" && shift ;; # Build the documentation
"--clean-neko") CLEAN_NEKO=true && shift ;; # Clean Neko
# End of options
"--") shift && break ;;
esac
done
[ "$CLEAN_NEKO" == true ] && CLEAN=true
export TEST CLEAN CLEAN_NEKO QUIET DEVICE_TYPE
# ============================================================================ #
# Execute the preparation script if it exists and prepare the environment
printf "=%.0s" {1..80} && printf "\n"
printf "Preparing environment.\n"
# Execute the preparation script if it exists
if [ -f "$MAIN_DIR/prepare.env" ]; then
source $MAIN_DIR/prepare.env
fi
source $MAIN_DIR/scripts/dependencies.sh
# Define standard compilers if they are not defined as environment variables
if [ -z "$CC" ]; then export CC=$(which mpicc); else export CC; fi
if [ -z "$CXX" ]; then export CXX=$(which mpicxx); else export CXX; fi
if [ -z "$FC" ]; then export FC=$(which mpifort); else export FC; fi
if [ -z "$MPIFC" ]; then export MPIFC=$(which mpif90); else export MPIFC; fi
if [ -z "$MPICC" ]; then export MPICC=$(which mpicc); else export MPICC; fi
if [ -z "$MPICXX" ]; then export MPICXX=$(which mpicxx); else export MPICXX; fi
# Device specific compilers
if [ "$DEVICE_TYPE" == "CUDA" ]; then
if [ -z "$NVCC" ]; then export NVCC=$(which nvcc); else export NVCC; fi
elif [ "$DEVICE_TYPE" == "HIP" ]; then
if [ -z "$HIPCC" ]; then export HIPCC=$(which hipcc); else export HIPCC; fi
fi
# Everything past this point should be general across all setups.
# ============================================================================ #
# Install dependencies (See scripts/dependencies.sh for details)
printf "=%.0s" {1..80} && printf "\n"
printf "Setting up external dependencies\n"
check_system_dependencies # Check for system dependencies.
find_json_fortran $JSON_FORTRAN_DIR # Re-defines the JSON_FORTRAN_DIR variable.
find_neko $NEKO_DIR # Re-defines the NEKO_DIR variable.
[ "$TEST" == "ON" ] && find_pfunit $PFUNIT_DIR # Re-defines the PFUNIT_DIR variable.
# Done setting up external dependencies
# ============================================================================ #
# Compile the Neko-TOP and example codes.
printf "=%.0s" {1..80} && printf "\n"
printf "Compiling the example codes and Neko-TOP\n"
# Clean the build directory if the clean flag is set
[ "$CLEAN" == true ] && rm -fr $MAIN_DIR/build
# If CMAKE_VARIABLES is a string, convert it to an array
if [ -n "$CMAKE_VARIABLES" ]; then
CMAKE_VARIABLES=($CMAKE_VARIABLES)
else
CMAKE_VARIABLES=()
fi
# Enable desired features
CMAKE_VARIABLES+=("-DBUILD_DOCS=$DOCS")
CMAKE_VARIABLES+=("-DBUILD_TESTING=$TEST")
CMAKE_VARIABLES+=("-DBUILD_EXAMPLES=$EXAMPLES")
# Run the cmake command to configure the build
cmake -B $MAIN_DIR/build -S $MAIN_DIR "${CMAKE_VARIABLES[@]}"
# Clean the build directory if the clean flag is set
cmake --build $MAIN_DIR/build --parallel
# ============================================================================ #
# Print the status of the build
printf "=%.0s" {1..80} && printf "\n"
printf "Neko-TOP Installation Complete\n"
printf "=%.0s" {1..80} && printf "\n"
printf "Neko installed to:\n"
printf "\t$NEKO_DIR\n"
printf "Supported features:\n"
printf "\tMPI: YES\n"
printf "\tDevice: $DEVICE_TYPE\n"
printf "\tTests: " && [[ "$TEST" == "ON" ]] && printf "YES\n" || printf "NO\n"
printf "\tExamples: " && [[ "$EXAMPLES" == "ON" ]] && printf "YES\n" || printf "NO\n"
printf "\tDocumentation: " && [[ "$DOCS" == "ON" ]] && printf "YES\n" || printf "NO\n"
printf "\tHDF5: " && [[ -d "$HDF5_DIR" ]] && printf "YES\n" || printf "NO\n"
printf "=%.0s" {1..80} && printf "\n"