This is a short guide to set a bitpit compliant 64bit Windows environment using MSYS2/MinGW64.
-
Windows 8/10 (8.1 pro/10 tested)
-
MSYS2 (64bit) https://www.msys2.org/ (tested version msys2-x86_64-20210725.exe)
-
MSYS2 packages:
- base-devel
- binutils
- python
- git (optional)
-
MinGW64 packages:
- mingw-w64-x86_64-toolchain
- mingw-w64-x86_64-lapack
- mingw-w64-x86_64-msmpi
- mingw-w64-x86_64-cmake
- mingw-w64-x86_64-qt5 (optional, but needed to run cmake-gui. Consider 1.22 GB to install it.)
- mingw-w64-x86_64-doxygen (to generate Doxygen documentation)
- mingw-w64-x86_64-graphviz (to generate Doxygen documentation)
-
Microsoft MPI: MSMpiSetup.exe or msmpisdk.msi (downloadable for free from https://www.microsoft.com/ searching for "MicrosoftMPI v x.x.x". Here the exact version x.x.x must be compliant with the version of MinGW64 package mingw-w64-x86_64-msmpi. See MSMPI section in procedure chapter for details)
-
PETSc library The newest PETSc version tested with bitpit is 3.15.4. You can get it alternatively:
- building from sources: https://www.mcs.anl.gov/petsc/download/index.html.
- from MinGW64 packages:
- mingw-w64-x86_64-petsc
- mingw-w64-x86_64-petsc-build
-
Download MSYS2 from https://www.msys2.org/ and install it following the instructions on the site to update and get the environment ready to be used. A more detailed install guide can be found also here: https://www.msys2.org/wiki/MSYS2-installation/. This will install a bunch of subsystems, two in particular are of interest in this context:
- msys2: general POSIX compliant emulating environment
- mingw64: environment, based on msys2 and specifically tuned to provide better interoperability with native 64bit Windows software, using MingGW.
-
If you did not run MSYS2 just after installation, look for msys2 or mingw64 shells among your installed programs or launch them from cmd (Windows Prompt):
>C:\msys64\msys2_shell.cmd -msys2 (for msys2 shell) >C:\msys64\msys2_shell.cmd -mingw64 (for mingw64 shell)
-
Open a msys2 shell and install base msys2 packages base-devel, binutils, python, git. On usage of pacman please refer to https://www.msys2.org/docs/package-management/ :
user@machine MSYS2 ~ > pacman -S base-devel binutils python git
As in a Linux system, libraries and binaries installed can be found navigating C:/msys64/usr/lib or C:/msys64/usr/bin
-
Open a mingw64 shell and install the base development toolchain for mingw64. This will include C,C++, Fortran compilers and libraries :
user@machine MINGW64 ~ > pacman -S mingw-w64-x86_64-toolchain
As in a Linux system, libs and binaries installed can be found navigating C:/msys64/mingw64/lib or C:/msys64/mingw64/bin. Verify the installation with:
user@machine MINGW64 ~ > gcc -v
It should print something like this: (the gcc version will depend on the update status of your MSYS2 package repository. Please refer to MSYS2 documentation for instruction on how update it)
Using built-in specs. COLLECT_GCC=C:\msys64\mingw64\bin\gcc.exe COLLECT_LTO_WRAPPER=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/lto-wrapper.exe Target: x86_64-w64-mingw32 Configured with: ../gcc-10.3.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --enable-checking=release --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++,jit --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-lto --enable-libgomp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev2, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --with-boot-ldflags='-pipe -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high -Wl,--disable-dynamicbase -static-libstdc++ -static-libgcc' 'LDFLAGS_FOR_TARGET=-pipe -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high' --enable-linker-plugin-flags='LDFLAGS=-static-libstdc++\ -static-libgcc\ -pipe\ -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high\ -Wl,--stack,12582912' Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 10.3.0 (Rev2, Built by MSYS2 project)
-
In order to make your Windows OS see the mingw64 shell binaries, modify the Windows PATH environment variable by adding
C:\msys64\mingw64\bin
. The same output of 4) should appear launching from a Windows PowerShell or a Windows prompt the command:> gcc.exe -v
If not, check if
C:\msys64\mingw64\bin
is present in windows PATH typing:(prompt) > echo %PATH% (PowerShell) > $Env:Path
This section will install MPI on your machine, both libraries and compiler wrappers (mpic, mpicxx) through mingw-w64-x86_64-msmpi package and mpiexec command through native Windows package MicrosoftMPI
-
Open a mingw64 shell and type:
user@machine MINGW64 ~ > pacman -Ss mingw-w64-x86_64-msmpi
It should return something like:
mingw64/mingw-w64-x86_64-msmpi 10.1.1-4 Microsoft MPI SDK (mingw-w64)
Please take note of the MSMPIVersion number, in the specific case 10.1.1, but it can vary according to the update status of your MSYS2 package repository. Install the msmpi from mingw64:
user@machine MINGW64 ~ > pacman -S mingw-w64-x86_64-msmpi
Close the mingw64 shell.
-
Download Microsoft MPI from https://docs.microsoft.com/en-us/message-passing-interface/microsoft-mpi. If on site version does not match the MSMPIVersion noted earlier, a simple browser search of "MSMPI" and target version number will redirect you to the correct version download page on the official Microsoft site. Then install both MSMpiSetup.exe and msmpisdk.msi.
-
Reopen the mingw64 shell (to load the new enviroment variables introduced in 2.) and locate the environment variable MSMPI_BIN typing:
user@machine MINGW64 ~ > printenv | grep "WIN\|MSMPI"
You should see something like this:
USERDOMAIN=VIRTUALWIN8 MSMPI_INC=C:\Program Files (x86)\Microsoft SDKs\MPI\Include\ COMPUTERNAME=VIRTUALWIN8 USERDOMAIN_ROAMINGPROFILE=VIRTUALWIN8 MSMPI_BIN=C:\Program Files\Microsoft MPI\Bin\ MSMPI_LIB32=C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x86\ MSMPI_LIB64=C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64\ WINDIR=C:\Windows
If not, please verify you MSMPI installation on 2. Take note of MSMPI_BIN content path (here it is
C:\Program Files\Microsoft MPI\Bin\
). -
In order to use mpiexec.exe inside the mingw64 shell, the content path of MSMPI_BIN needs to be added to the local PATH of the shell. Sometimes problems of compatibility can arise in a direct export, because of blank spaces inside native Windows path. In such cases is strongly recommended to use cygpath (already available in the shell) to convert this path in a more compact and unix compliant format. To do so, it is sufficient to transform the original Windows path in dos short format:
user@machine MINGW64 ~ > cygpath -ms 'C:\Program Files\Microsoft MPI\Bin\' result will be: C:/PROGRA~1/MICROS~2/Bin/
then transform the last result in a unix compliant path:
user@machine MINGW64 ~ > cygpath -u 'C:/PROGRA~1/MICROS~2/Bin/' result will be: /c/PROGRA~1/MICROS~2/Bin/
The last result can be safely exported in the local mingw64 shell PATH environment variable with:
export PATH=$PATH:/c/PROGRA~1/MICROS~2/Bin/
and make mpiexec.exe available in the shell. It is recommended to add it permanently to the ~/.bashrc configuration file of the shell.
-
Before moving on, test MSMPI with a simple MPI Hello World code. Here an example in c++:
#include <mpi.h> #include <iostream> int main(int argc,char** argv){ MPI_Init(&argc,&argv); int rank; int nprocs; MPI_Comm_rank(MPI_COMM_WORLD,&rank); MPI_Comm_size(MPI_COMM_WORLD,&nprocs); std::cout << "I'm " << rank << " of " << nprocs << std::endl; MPI_Finalize(); }
compile it using MSMPI language relative wrapper
user@machine MINGW64 ~ > mpicxx -o mpi_hello mpi_hello.cpp
and launch your test sample:
user@machine MINGW64 ~ > mpiexec -n 2 ./mpi_hello
You should get
I'm 0 of 2 I'm 1 of 2
For the following subsections, open a mingw64 shell.
Beware: some of these dependencies can be available also as native Windows applications/libraries. Anyway we choose to use those provided by msys2/mingw64 repositories to ensure the maximum coherence during the installation flow. If you choose to use different versions/distributions, let us know your experience. We will be glad to use your tips to enrich the current guide.
CMAKE
Install cmake and its GUI cmake-gui with:
user@machine MINGW64 ~
> pacman -S mingw-w64-x86_64-cmake mingw-w64-x86_64-qt5
If you are short in disk space, you can avoid installing mingw-w64-x86_64-qt5 (~1.22 GB), but you cannot use cmake-gui for setting cmake variables in building configuration. Without gui, you have to consider a large use of cmake "-D" flag or to manually modify CMakeCache.txt file, in order to set the values of the cmake variables.
LAPACK
Install lapack with:
user@machine MINGW64 ~
> pacman -S mingw-w64-x86_64-lapack
PETSc
PETSc can be installed on the MSYS2/MinGW64 environment in two ways:
- MinGW64 packages:
user@machine MINGW64 ~
> pacman -S mingw-w64-x86_64-petsc
> pacman -S mingw-w64-x86_64-petsc-build
This will automatically install one of the most recent release version of PETSc (e.g., v.3.15.4). Within its periodical updates, the MSYS2-MINGW64 environment will update also the version of its own supported petsc package. Use the MSYS2 update command to check for updates. Once installed, the installation directory PETSC_DIR will be found at:
> <msys64 path>/mingw64/src/petsc-<version>
The package comes with different petsc libraries (in both static and shared form) for different architectures. The most important ones for bitpit are:
- dso : for double precision, sequential threading, optimized petsc.
- dto : for double precision, multi-threaded, optimized petsc.
- dmo : for double precision, MPI-compliant, optimized petsc.
You can choose between them using the PETSC_ARCH variable (e.g., PETSC_ARCH=dmo).
Finally, dlls for every petsc architectures shared libraries will be found in
> <msys64 path>/mingw64/bin
- Building from sources
First, PETSc sources are needed. Download PETSc v3.15.4 from https://www.mcs.anl.gov/petsc/download/index.html. This is the most recent version of PETSc tested with bitpit. If you want to have a try with different versions, please let us know your experience.
-
Untar the downloaded PETSc archive and enter the PETSc sources folder from the mingw64 shell.
-
Get track of msys2 python.exe and ar.exe binaries, both available in '/usr/bin/' inside the mingw64 shell (if not check subsection 3 of Install MSYS2(64bit) and MINGW64 chapter of the guide). These ones are the only that work properly with PETSc configure scripts. mingw64 python and ar versions create problems.
-
Check if mpiexec.exe is available in the shell (type "mpiex" and complete with tab). If not please check again the section 4 of MS-MPI chapter.
-
We configure PETSc using a Python script (3.x version namely). Edit a new Python file, e.g. myConf.py, and add these lines:
configure_options = [
'--with-ar=/usr/bin/ar' ,
'--with-shared-libraries=0',
'--with-debugging=0',
'--with-visibility=0',
'--prefix=/c/msys64/mingw64/petsc',
'FOPTFLAGS=-O3 -fno-range-check',
'COPTFLAGS=-O3',
'CXXOPTFLAGS=-O3'
]
if __name__ == '__main__':
import sys,os
sys.path.insert(0,os.path.abspath('config'))
import configure
configure.petsc_configure(configure_options)
The prefix can be any path on your Windows machine, provided that it is specified as unix compliant - blank space free path (use cygpath, an example is reported in MS-MPI chapter, section 4). You can customize your PETSc configuration following the instructions at https://www.mcs.anl.gov/petsc/documentation/installation.html. The Python script above gives you a double precision, static(.a), optimized installation of PETSc library that works with bitpit.
- Therefore, launch:
user@machine MINGW64 ~
> /usr/bin/python2 myConf.py
and follow the PETSc instructions to complete the installation ( copy and paste exactly the command lines PETSc suggests, up to the 'make...test' part).
- Installation directory PETSC_DIR will be at chosen
#prefix#
(that provided in the python configuration script) and PETSC_ARCH will be empty.
For both methods, PETSC_DIR and PETSC_ARCH can be exported into the mingw64 shell as temporary or permanent environment variables, to ease the retrieval of the correct petsc library.
-
Download bitpit master archive at https://github.com/optimad/bitpit/archive/master.zip or git clone it using SSH or HTTPS.
-
Once the MinGW64 development environment is ready, you can install bitpit following the installation instructions you can find at https://github.com/optimad/bitpit/blob/master/INSTALL.md or locally in the INSTALL.md file in bitpit root folder.
-
In order to compile a Windows native version of bitpit you have to:
- specify the MinGW Makefiles Generator to cmake, e.g. in your bitpit build folder
user@machine MINGW64 ~ > cmake -G "MinGW Makefiles" ..
or if cmake-gui is used, enable a MinGW Makefiles project.
- use mingw32-make in place of standard make command to build bitpit.
-
Warning 1: if bitpit cmake configuration exits with PETSc error, verify the values of PETSC_DIR and PETSC_ARCH cmake variables and possibly set them to the correct values. If you used the Building From Sources method with exactly myConf.py script above to configure PETSc, their values are
PETSC_DIR=/c/msys64/mingw64/petsc PETSC_ARCH=
If you are using the MINGW64 binaries package, your msys64 is installed in /c/msys64, the petsc version is 3.15.4, and you want to use dmo (MPI compliant) architecture, their values will be:
PETSC_DIR=/c/msys64/mingw64/src/petsc-3.15.4 PETSC_ARCH=dmo