Skip to content

Instantly share code, notes, and snippets.

@rdbuf
Last active July 8, 2019 22:30
Show Gist options
  • Select an option

  • Save rdbuf/d43f47ef97d9ffec004bd61d344291f6 to your computer and use it in GitHub Desktop.

Select an option

Save rdbuf/d43f47ef97d9ffec004bd61d344291f6 to your computer and use it in GitHub Desktop.
Build script for SU2 with AD enabled under MSYS2 using MS-MPI

SU2+AD under MSYS2 with MS-MPI

The script attached below allows one to build SU2 with AD enabled under MSYS2 using MS-MPI. In order to do so, perform the following:

  1. Install the prerequisites:
  2. Run pacman -Syu from inside the fresh installed MSYS2
  3. Run SU2_install.sh under MSYS2 MinGW 64-bit
#!/bin/bash
step() {
CYAN='\e[0;36m'; NORM='\e[0;0m'
echo -e "${CYAN}$1${NORM}"
}
trap "step 'Exit requested'; exit 1" INT
trap "step 'SIGTERM caught'; exit 2" TERM
done_path="$(pwd)/done"
done="$(cat done 2>/dev/null || echo 0)"
echo "Done = $done. To change the number of steps assumed to be done, modify ./done"
step 'Installing the neccessary instrumentation [1/6]'
if [[ "$done" -lt 1 ]]; then
pacman -Syu --noconfirm
pacman -S --noconfirm git python2 base-devel mingw-w64-x86_64-toolchain unzip
pacman -S --noconfirm mingw-w64-x86_64-python2-numpy mingw-w64-x86_64-python2-scipy
echo 1 > "$done_path"
else step ' - was done before'
fi
step 'Retrieving sources [2/6]'
if [[ "$done" -lt 2 ]]; then
git clone --depth=1 --recurse-submodules -j4 https://github.com/su2code/SU2.git
echo 2 > "$done_path"
else step ' - was done before'
fi
cd SU2
step "Fixing ./preconfigure.py to work under our environment [3/6]"
if [[ "$done" -lt 3 ]]; then
# othewise subprocess.check_call would incorrectly resolve the path to the executable
# and subprocess.Popen would always throw an error
cat <<EOF | patch -p1
diff --git a/preconfigure.py b/preconfigure.py
index f74f7b3..c1dc462 100755
--- a/preconfigure.py
+++ b/preconfigure.py
@@ -346,7 +346,7 @@ def submodule_check(name, alt_name, github_rep, sha_tag, log, err, update = Fals
def submodule_status(path, update):
try:
- status = check_output('git submodule status ' + path).decode()
+ status = check_output('git submodule status'.split(' ') + [path]).decode()
except RuntimeError:
raise RuntimeError
@@ -407,7 +407,7 @@ def configure(argument_dict,
made_codi):
# Set the base command for running configure
- configure_base = '../configure'
+ configure_base = 'sh ../configure'
# Add the arguments to the configure command
for arg in argument_dict:
@@ -507,7 +507,7 @@ def run_command(command, log, err, env):
def check_output(cmd):
- std, err = subprocess.Popen([cmd], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell = True).communicate()
+ std, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell = True).communicate()
if err:
raise RuntimeError(err)
return std
EOF
echo 3 > "$done_path"
else step ' - was done before'
fi
step 'Invoking ./preconfigure.py with the correct flags [4/6]'
if [[ "$done" -lt 4 ]]; then
cp "$MSMPI_INC/mpi.h" /mingw64/include
export CXXFLAGS="-O3 -DMEDI_MPI_TARGET=103 -DMSMPI_NO_DEPRECATE_20 -std=c++17" && export LDFLAGS="-LC:/Windows/SYSTEM32 -static -static-libgcc -static-libstdc++" && export LIBS="-lmsmpi" && ./preconfigure.py --enable-autodiff --enable-mpi --with-metis-cppflags="'-D_FILE_OFFSET_BITS=64 -DNDEBUG -DNDEBUG2 -DHAVE_GETLINE'"
echo 4 > "$done_path"
else step ' - was done before'
fi
step 'Setting up the environment [5/6]'
if [[ "$done" -lt 5 ]]; then
cat <<'EOF' | tee -a ~/.bashrc
export SU2_RUN="$HOME/SU2/bin"
export SU2_HOME="$HOME/SU2"
export PATH=$PATH:$SU2_RUN:$MSMPI_BIN
export PYTHONPATH=$PYTHONPATH:$SU2_RUN
EOF
echo 5 > "$done_path"
else step ' - was done before'
fi
step 'Actually compiling & linking [6/6]'
if [[ "$done" -lt 6 ]]; then
make -j5 install
echo 6 > "$done_path"
else step ' - was done before'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment