Skip to content

Building SWAT from this repository

mlt edited this page Apr 19, 2013 · 3 revisions

Building SWAT from this repository

Prerequisites

By default gfortran from GCC is used. Other Fortran compiler can be used by supplying a corresponding name to -DCMAKE_Fortran_COMPILER=<name> like ifort provided it is properly installed. You may consider using cmake-gui in place of cmake if you don’t feel comfortable with a command line.

Windows

Ubuntu GNU/Linux

sudo apt-get install git gfortran cmake

GCC

The following is for MS Windows. Instructions for Ubuntu GNU/Linux are similar just skip generator part (-G "MSYS Makefiles”).

git clone https://github.com/mlt/swat.git
cd swat
mkdir -p build/Debug build/Release
cd build/Debug
cmake -DCMAKE_Fortran_FLAGS=-Og -DCMAKE_BUILD_TYPE=Debug -G "MSYS Makefiles" ../..
make -j 4
cd ../Release
cmake "-DCMAKE_Fortran_FLAGS_RELEASE=-march=native -Ofast" -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS=-s -G "MSYS Makefiles" ../..
make -j 4
make package

Hint: You may want to enable /Quick Edit/ for the ease of copy-pasting in a command window if on Windows. Also this link

Useful flags with GCC

Debugging

-ggdb -fimplicit-none -Wall -Wextra -Wtabs -ffpe-trap=invalid -finit-real=snan -Wuninitialized -Wno-unused -freal-4-real-8

Release

-Ofast -fimplicit-none -Wall -Wextra -Wtabs -Wuninitialized -Wno-unused -freal-4-real-8

Profile guided optimization

2-pass compilation may help to gain some performance by optimizing CPU instructions for most likely conditional branching in the code.

Note that gfortran generated code is slower than that of Intel. Even with PGO resulting speed won’t be stunning though you’ll notice some difference.

For PGO build to work, copy an existing TxtInOut folder into a cloned repository swat and do the following starting from repository root

mkdir -p build/PGO
cd build/PGO
cmake "-DCMAKE_Fortran_FLAGS=-march=native -Ofast" -DCMAKE_BUILD_TYPE=PGO -DCMAKE_EXE_LINKER_FLAGS=-s -G "MSYS Makefiles" ../..
make -j 4

After first pass, SWAT will run your model and run statistics will be collected to adjust conditional branching code for the second pass. Final executable is in src sub-folder.

LLVM via DragonEgg

It is possible to use LLVM optimizers and code generator by means of DragonEgg project, a GCC plugin.

mkdir -p build/LLVM
cd build/LLVM
cmake "-DCMAKE_Fortran_FLAGS=-fplugin=dragonegg -fplugin-arg-dragonegg-enable-gcc-optzns -O4" -DCMAKE_EXE_LINKER_FLAGS=-s -G "MSYS Makefiles" ../..
make -j 4

Intel Fortran

Something like the following should do the job for Intel Fortran compiler once you change directory to cloned git repository.

mkdir -p build/ifort
cd build/ifort
cmake -DCMAKE_Fortran_COMPILER=ifort -DCMAKE_Fortran_FLAGS_RELEASE=-fast -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS=-s ../..
make -j 4

Useful flags with ifort

Debugging

-gdwarf-3 -check all,nopointers -fp-stack-check -fstack-protector-all -ftrapuv -opt-multi-version-aggressive -warn all -warn notruncated_source -warn nounused -diag-disable 8291 -diag-disable 8290 -diag-disable 5415

Release

-fast -fp-model fast=2 -opt-multi-version-aggressive -warn all -warn notruncated_source -warn nounused -diag-disable 8291 -diag-disable 8290 -diag-disable 5415

PGO

mkdir -p build/IPGO
cd build/IPGO
cmake -DCMAKE_Fortran_COMPILER=ifort -DCMAKE_Fortran_FLAGS=-fast -DCMAKE_BUILD_TYPE=IPGO -DCMAKE_EXE_LINKER_FLAGS=-s ../..
make -j 4