GridPACK on Windows - wperkins/GridPACK GitHub Wiki
This describes building GridPACK on a specific system. Perhaps, it will be a useful guide for building on another system.
- Key Things
- System Preparation
- Build System Description
- Build Prerequisite Libraries
- Build GridPACK
- Notes
Building GridPACK on Windows is not for the faint of heart. GridPACK was developed on and for high performance Linux or UNIX-like systems. GridPACK depends on several libraries that were also developed on and for UNIX-like systems. The Windows programming model is very different from Linux or UNIX. If you are familiar with one, the other is usually confusing.
On the other hand, a sucessful build will allow GridPACK to take full advantage of multi-core Windows systems, or perhaps a Windows cluster.
There are a number key things to keep in mind while attempting to build GridPACK on Windows:
-
Make sure all code is compiled with the same compiler. Even if you think only one version of MS Visual C++ is installed, there may be different compiler (
CL.EXE
) versions. Make certain that that the compilerCL.EXE
is the same one that CMake uses. Make sure all the libraries are built with the same compiler. -
Make sure all libraries are built with the same run time library option. For some good reason, surely, code referring to different run time libraries cannot be linked together. Here, all code is linked to the shared (non-debug) run time library, which means code is compiled with the
/MD
option. -
The build description here is that recorded when GridPACK was built on a single system. Your system is different. Adjustments will be required.
-
A Windows user account building and/or debugging programs may need to have special permissions ("Developer"?). Administrator privileges may also be necessary for some tasks.
-
In this build, everything is done from a Command Prompt or shell. Use a 64-bit Visual Studio command prompt, which should be available from the Start Menu. If your version of Visual Studio has more than one type of Command Prompt, use the "Developer" prompt. You may need to open Command Prompts as administrator, depending on your installation and user account. To do this, mouse over the Command Prompt field and right-click. A menu should show up with "Run as Administrator" as one of the options. Type, or copy and paste, the commands below into that command prompt window.
-
Disclaimer: Some of the actions listed here may require Administrator privileges. Mistakes made with Administrator privileges can do serious damage to your system. If you are uncomfortable using Administrator privileges, don't. Just walk away. If you proceed and damage your system, it is your fault.
-
Disclaimer: The writer is not a Windows developer, and not particularly knowledgeable about Windows programming.
There are several requirements that need be installed. These can be installed in the normal Windows way:
-
Visual C++ in some form.
-
A C++ compiler is necessary. Instructions for this are elsewhere. The "free" ones, Visual Studio Express and Community, should work, but were not tested. Visual Studio 2015 was used here.
-
Use 64-bit compilers on a 64-bit system. To get the 64-bit compilers for Visual Studio 2015, you need to use the "x64 Native Tools Command Prompt" (you may need to go into the Visual Studios folder and then into the Visual Studio Tools subfolder and then into the Windows Desktop Command Prompts folder under that to find it).
-
-
Windows SDK, which is usually installed with Visual Studio
-
CMake is required.
During the installation process, the dialog will ask if you want CMake added to
PATH
variable. For some reason, the default is not to include CMake. You should change the selection to add CMake to thePATH
for all users. -
A minimal Cygwin installation is necessary.
Cygwin is required to build, and test for, PETSc. If the system has a Cygwin installation that is being used, it would probably be best to make another installation for GridPACK installation exclusively. If gcc and cmake are already installed in Cygwin, you can rerun the installer and deselect these packages (they can be found under the developer category).
-
Minimum required packages:
- Base
- Python
- Make
-
Rename
/usr/bin/link.exe so
it does not interfere with WindowsLINK.EXE
-
If you want to use a Cygwin shell to build and/or debug GridPACK applications:
- Do not install a compiler set.
- Do not install CMake.
-
-
This appears to be the only modern MPI implementation available for Windows. Download and install both the .msi and .exe files.
-
Some software to unpack .zip, .gz, and tar archives. Commands to unpack all of these archives are available with Cygwin or the GIT shell. Windows can handle .zip archives natively. 7-Zip also handles these archive types.
-
Git is used to obtaining the GridPACK and other code from the Github repository. It also supplies a Linux-like command prompt, that is easier to use than Cygwin's, with some necessary Linux commands, like
patch
andtar
. -
(optional) MS-MPI Debugger Extension is useful for debugging problems with parallel programs.
This build was done on a specific system.
Batch files and shells scripts used to build GridPACK and its dependencies on this system are in the source repository.
The writer had Administrator privileges on this system, which may be necessary.
The first compiler found by the Command Prompt is the one used by the Boost and PETSc build systems. To verify its location and version,
C:\>where cl
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\cl.exe
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\cl.exe
C:\>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24210 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
usage: cl [ option... ] filename... [ /link linkoption... ]
This shows that the first compiler found is from MSVC 14 and its
version is 19.00.24210
.
C:\>cmake --help
Usage
cmake [options] <path-to-source>
cmake [options] <path-to-existing-build>
cmake [options] -S <path-to-source> -B <path-to-build>
Specify a source directory to (re-)generate a build system for it in the
current working directory. Specify an existing build directory to
re-generate its build system.
Options
[...]
Generators
The following generators are available on this platform (* marks default):
Visual Studio 16 2019 = Generates Visual Studio 2019 project files.
Use -A option to specify architecture.
Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files.
Optional [arch] can be "Win64" or "ARM".
* Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files.
Optional [arch] can be "Win64" or "ARM".
[...]
-
Choose a single place to install GridPACK and related libraries,
C:\GridPACK
orC:\Users\TheUser\gridpack
. Avoid a path with spaces or special characters in it. It's convenient to set an (user) environment variable to hold this path.GridPACKDir
is used here. -
Make a folder in a convenient location in which source archives can be unpacked and the builds can be performed.
%GridPACKDir%\src
is used here[^1]. Again, avoid a path with spaces or special characters in it. -
Open an appropriate "Developer" Command Prompt as described above. It may be necessary to adjust the
PATH
environment variable to remove anything that might interfere with the build process. These steps are suggested- In the Command Prompt, type
echo %PATH%
- Mark and copy the result and paste it into a text editor like NotePAD. Make it into a single line, being careful to preserve any spaces.
- Examine each path entry, separated by
;
, and remove those that are unneeded or might interfere. Some examples: - Save the editted
PATH
in a text file for future reference. - Mark and copy the editted
PATH
and in the Command Prompt, typeand paste the new path.set PATH=
- In the Command Prompt, type
-
Make sure that MPI variables are set correctly by typing,
set msmpi
The response should be something like
MSMPI_BIN=C:\Program Files\Microsoft MPI\Bin\ MSMPI_INC=C:\Program Files (x86)\Microsoft SDKs\MPI\Include\ MSMPI_LIB32=C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x86\ MSMPI_LIB64=C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64\
-
Make sure the
MPIEXEC
command is available. -
The caret ^ character is the line continuation character for Command Prompt window.
-
Download source from here and unpack in the source directory. Version 1.68.0 was used here and seemed to work out of the box.
-
Bootstrap
boost.build
, with.\bootstrap.bat
-
Add
using mpi ;
toproject-config.jam
-
Configure, build, and install:
.\b2 ^ --prefix="%GridPACKDir%" ^ --with-mpi ^ --with-serialization ^ --with-random ^ --with-filesystem ^ --with-system ^ --build-type=complete ^ threading=single ^ address-model=64 ^ link=static runtime-link=shared ^ install
Notes:
-
Using
runtime-link=shared
causes Boost code to be built with/MD
. -
Boost decorates the library names with the compiler version, so explicitly specify the compiler and make sure that's the compiler you use for GridPACK. If multiple compilers are available, it is possible to force the boost configuration to pick a specific one by adding an option like
-toolchain=msvc-11.0
to the.\b2
arguments. -
This version of Boost built out of the box without difficulty.
-
Some references:
-
Global Arrays is built using CMake. The CMake configuration in the current GA repository does not work without a Fortran compiler (at the time of writing).
The fixed GA source can be obtained from an alternate repository
git clone https://github.com/wperkins/ga.git
This will probably have to be executed in the GIT shell.
-
Make a build directory, configure, build, and install:
mkdir ga\build cd ga\build cmake -Wdev --debug-trycompile ^ -D BUILD_SHARED_LIBS:BOOL=OFF ^ -G "Visual Studio 14 2015 Win64" ^ -D ENABLE_I8:BOOL=No ^ -D ENABLE_BLAS:BOOL=No ^ -D ENABLE_FORTRAN:BOOL=No ^ -D ENABLE_CXX:BOOL=Yes ^ -D GA_RUNTIME:STRING=MPI_TS ^ -D CMAKE_INSTALL_PREFIX:PATH="C:\Users\D3G096\gridpack" ^ .. cmake --build . --config Release cmake --build . --config Release --target install
- Get the official distribution from
here. Unpack
the archive in the source directory. The
source distribution needs to modified to
- have CMake look for MPI in the correct way
- set the real type size
- make sure metis.h is installed
- deal with the lack of
rint()
on with later versions of MSVC. There is a patch in the GridPACK source repository. This patch can be applied by using thepatch
command within the GIT shell:
cd parmetis-4.0.3/
patch -p1 < .../parmetis-patch.txt
- Configure, build, and install
cmake ^ -G "Visual Studio 14 2015 Win64" ^ -D BUILD_SHARED_LIBS:BOOL=NO ^ -D METIS_INSTALL:BOOL=YES ^ -D CMAKE_INSTALL_PREFIX:PATH=%GridPACKDir% ^ .. cmake --build . --config Release cmake --build . --target install --config Release
Ordinarily, several packages used by GridPACK can be built by having PETSc download and build them as part of the PETSc build. Unfortunately, while this works quite well on the Linux OS, it does not work in many cases for Windows. Consequently, these packages must be downloaded and built separately. Note that the builds below all assume that you are calling the CMake command in a separate directory, below the main library directory.
Some implementation of BLAS/LAPACK is required for PETSc and some other libraries. The implementation described here was chosen because it does not require a Fortran compiler. It is apparently ''really'' slow. It will probably be necessary to install Intel compilers and MKL in order to get improvement in speed. The Windows port of CLAPACK is described here.
-
Get the source here.
-
Configure, build, and install
cd clapack-3.2.1-CMAKE mkdir build cd build set CFLAGS="/MD" set CXXFLAGS="/MD" cmake -Wdev --debug-trycompile ^ -D BUILD_SHARED_LIBS:BOOL=OFF ^ -G "Visual Studio 14 2015 Win64" ^ -D CMAKE_INSTALL_PREFIX:PATH="%GridPACKDir%" ^ .. cmake --build . --config Release cmake --build . --config Release --target install
The Suitesparse provides the KLU serial direct sparse linear solver, which is a good choice for some GridPACK applications.
-
Obtain the source for a variant suitable for Windows from here.
-
Configure, build, and install
set GridPACKDir="C:/Users/D3G096/gridpack" set CFLAGS="/MD" set CXXFLAGS="/MD" cmake -Wdev ^ -G "Visual Studio 14 2015 Win64" ^ -D BUILD_METIS:BOOL=NO ^ -D LAPACK_DIR:PATH="%GridPACKDir%" ^ -D BLAS_DIR:PATH="%GridPACKDir%" ^ -D LAPACK_LIBRARIES:STRING="%GridPACKDir%/lib/lapack.lib" ^ -D BLAS_LIBRARIES:STRING="%GridPACKDir%/lib/blas.lib;%GridPACKDir%/lib/libf2c.lib" ^ -D CMAKE_INSTALL_PREFIX:PATH="%GridPACKDir%" ^ .. cmake --build . --config Release cmake --build . --target install --config Release
Note that forward slashes (
/
) are required in%GridPACKDir%
instead of back slashes (\
) for the Suitesparse CMake configuration. This seems to be the only package bothered by that.
Notes:
- Some building hints are available here
SuperLU_DIST is needed so a parallel direct linear solver is available in GridPACK via PETSc. A specific SuperLU_DIST revision is required by PETSc depending on the PETSc version. Here, PETSc version 3.10.5 is being used, so SuperLU_DIST revision c0f64b8. This requires a specific Do not simply download the latest version of SuperLU_DIST. This will not work with most versions of PETSc.
- Obtain the
SuperLU_DIST by
cloning the tagged revision:
git clone -b v6.1.1 https://github.com/xiaoyeli/superlu_dist
- Edit
SRC\util.c
and comment out the include ofunistd.h
. It should look like this#include <math.h> /* #include <unistd.h> */ #include "superlu_ddefs.h"
- Configure, build, and install:
set CFLAGS=/DWIN32 /D_WINDOWS /W3 /D_CRT_SECURE_NO_WARNINGS set CXXFLAGS=/DWIN32 /D_WINDOWS /W3 /D_CRT_SECURE_NO_WARNINGS cmake -Wdev ^ -G "Visual Studio 14 2015 Win64" ^ -D CMAKE_INSTALL_PREFIX:PATH="%GridPACKDir%" ^ -D CMAKE_BUILD_TYPE:STRING=Release ^ -D enable_double:BOOL=ON ^ -D enable_openmp:BOOL=OFF ^ -D enable_tests:BOOL=OFF ^ -D enable_examples:BOOL=OFF ^ -D USE_XSDK_DEFAULTS:BOOL=TRUE ^ -D XSDK_ENABLE_Fortran:BOOL=FALSE ^ -D BUILD_SHARED_LIBS:BOOL=FALSE ^ -D TPL_ENABLE_BLASLIB:BOOL=OFF ^ -D TPL_ENABLE_COMBBLASLIB:BOOL=OFF ^ -D BLAS_LIBRARIES:STRING="%GridPACKDir%/lib/blas.lib;%GridPACKDir%/lib/libf2c.lib" ^ -D LAPACK_LIBRARIES:STRING="%GridPACKDir%/lib/lapack.lib" ^ -D TPL_PARMETIS_INCLUDE_DIRS:STRING="%GridPACKDir%/include" ^ -D TPL_PARMETIS_LIBRARIES:STRING="%GridPACKDir%/lib/parmetis.lib;%GridPACKDir%/lib/metis.lib" ^ .. cmake --build . --config Release cmake --build . --config Release --target install
PETSc version 3.10.5 was used here. PETSc needs to be built within a Cygwin with the appropriate environment. Note that Cygwin file paths are different from Windows paths. This requires some attention.
- Download the code from here and unpack.
- Open
...\src\mat\order\amd\amd.c
in an editor and change this linetotval = (PetscBool)Control[AMD_AGGRESSIVE];
if (Control[AMD_AGGRESSIVE]) tval = PETSC_TRUE; else tval = PETSC_FALSE;
- Start a developer Command Prompt and set the
PATH
environment variable as above. - Start a minimal Cygwin shell
This will start a new window running the Cygwin shell.
C:\cygwin64\bin\mintty.exe
- In the Cygwin shell,
will make the needed Cygwin commands available.
/usr/bin/bash -l
- Configure:
Some notes on this configuration
prefix="/cygdrive/c/Users/D3G096/gridpack" export PETSC_DIR="${prefix}/src/petsc-3.10.5" python ./configure \ PETSC_ARCH=mswin-c++-real \ --with-cc="win32fe cl" --with-fc=0 --with-cxx="win32fe cl" \ --with-clanguage=c++ \ --with-cxx-dialect=C++11 \ --with-c++-support=1 \ --with-precision=double \ --with-scalar-type=real \ --with-shared-libraries=0 \ --with-debugging=0 \ --with-mpi-include='[/cygdrive/c/PROGRA~2/MIA713~1/MPI/Include,/cygdrive/c/PROGRA~2/MIA713~1/MPI/Include/x64]' \ --with-mpi-include=/cygdrive/c/Program\ Files\ \(x86\)/Microsoft\ SDKs/MPI/Include \ --with-mpi-lib=['/cygdrive/c/Program\ Files\ \(x86\)/Microsoft\ SDKs/MPI/Lib/x64/msmpi.lib'] \ --with-mpiexec='/cygdrive/c/Program\ Files/Microsoft\ MPI/Bin/mpiexec.exe' \ --with-blaslapack-lib=[$prefix/lib/lapack.lib,$prefix/lib/blas.lib,$prefix/lib/libf2c.lib] \ --with-metis=1 \ --with-metis-include=${prefix}/include \ --with-metis-lib=[${prefix}/lib/metis.lib] \ --with-parmetis=1 \ --with-parmetis-include=${prefix}/include \ --with-parmetis-lib=[${prefix}/lib/parmetis.lib] \ --with-suitesparse=1 \ --with-suitesparse-include="${prefix}/include/suitesparse" \ --with-suitesparse-lib=[${prefix}/lib/libumfpack.lib,${prefix}/lib/libamd.lib,${prefix}/lib/libbtf.lib,${prefix}/lib/libcamd.lib,${prefix}/lib/libccolamd.lib,${prefix}/lib/libcolamd.lib,${prefix}/lib/libcholmod.lib,${prefix}/lib/libcxsparse.lib,${prefix}/lib/libklu.lib,${prefix}/lib/libspqr.lib,${prefix}/lib/libldl.lib,${prefix}/lib/suitesparseconfig.lib] \ --with-superlu_dist=1 \ --with-superlu_dist-include="${prefix}/include" \ --with-superlu_dist-lib="${prefix}/lib/superlu_dist.lib" \ CFLAGS="-O2 -MD -wd4996" \ CXXFLAGS="-O2 -MD -wd4996 -EHsc"
- Set
PETSC_DIR
to the directory where the PETSc source archive was unpacked. - The
-EHsc
flag is to enable C++ exceptions. - The
--with-clanguage=c++
option is necessary because PETSc C code requires C99 and MSVC does not support that. - Change '--with-scalar-type=real' to '--with-scalar-type=complex' to build PETSc using complex numbers (change the PETSC_ARCH variable accordingly ).
- Note format of file paths and how some are mangled. Spaces or
special (to Cygwin) characters in paths can cause trouble. If
problems are encountered, paths can be converted to Linux-type
directory names by using the
cygpath
command inside the Cygwin shell. Typeto getcygpath -d "C:\Program Files (x86)\Microsoft SDKs\MPI\Include"
and use this name for any configure options that have a path listing.C:\PROGRA~2\MIA713~1\MPI\Include
- Set
- Build
make PETSC_DIR=$PETSC_DIR PETSC_ARCH=mswin-c++-real all
- Check
make PETSC_DIR=$PETSC_DIR PETSC_ARCH=mswin-c++-real check
Notes:
- This mostly follows these instructions.
- The official instructions for building PETSc on Windows are here.
-
Clone Windows port branch of GridPACK from Githup
git clone -b windoze2 https://github.com/wperkins/GridPACK.git
-
Configure
cmake -Wdev --debug-trycompile ^ -G "Visual Studio 14 2015 Win64" ^ -D USE_PROGRESS_RANKS:BOOL=OFF ^ -D BOOST_ROOT:PATH=%prefix% ^ -D Boost_USE_STATIC_LIBS:BOOL=ON ^ -D BOOST_INCLUDEDIR=%prefix%\include\boost-1_68 ^ -D PETSC_DIR="%prefix%\src\petsc-3.10.5" ^ -D PETSC_ARCH="mswin-c++-real" ^ -D GA_DIR:PATH="%prefix%" ^ -D PARMETIS_DIR:PATH="%prefix%" ^ -D PARMETIS_INCLUDE_DIR:PATH="%prefix%\include" ^ -D PARMETIS_LIB_DIR:PATH="%prefix%\lib" ^ -D MPIEXEC_MAX_NUMPROCS:STRING="2" ^ -D GRIDPACK_TEST_TIMEOUT:STRING=20 ^ ..
-
Build
cmake --build . --config Release -j
-
Run unit tests
ctest -C Release
- CMake refuses to use
/MD
withtry_compile()
and instead uses/MDd
. This requires the use ofCMAKE_USER_MAKE_RULES_OVERRIDE
to change theCMAKE_<lang>_DEBUG
flag initialization. This will enableFindPETSC
andFindGA
to work. - This build was for static libraries. A shared library build was not attempted.
[^1]: The value of an environment or batch script variable is obtained
by placing the name between %
.