xref: /petsc/doc/install/windows.md (revision 763f2bca39761ced838ceb01229c1fbebe29da36)
19b92b1d3SBarry Smith(doc_windows)=
29b92b1d3SBarry Smith
39b92b1d3SBarry Smith# Installing PETSc On Microsoft Windows
49b92b1d3SBarry Smith
59b92b1d3SBarry Smith:::{admonition} Are You Sure?
69b92b1d3SBarry Smith:class: yellow
79b92b1d3SBarry Smith
89b92b1d3SBarry SmithAre you sure you want to use Microsoft Windows?
99b92b1d3SBarry Smith
109b92b1d3SBarry SmithDeveloping HPC software is more difficult on Microsoft Windows than Linux and macOS systems.
119b92b1d3SBarry SmithWe recommend using a Microsoft Windows system for PETSc only when necessary.
129b92b1d3SBarry Smith:::
139b92b1d3SBarry Smith
149b92b1d3SBarry SmithThere are many ways to install PETSc on Microsoft Windows's systems.
159b92b1d3SBarry Smith
169b92b1d3SBarry Smith- {any}`sec_linux_on_windows`
179b92b1d3SBarry Smith- {any}`sec_cygwin_gnu_on_windows`
189b92b1d3SBarry Smith- {any}`sec_native_compilers_on_windows`
199b92b1d3SBarry Smith- {any}`sec_msys2_mingw_compilers_on_windows`
209b92b1d3SBarry Smith
219b92b1d3SBarry Smith______________________________________________________________________
229b92b1d3SBarry Smith
239b92b1d3SBarry Smith(sec_linux_on_windows)=
249b92b1d3SBarry Smith
259b92b1d3SBarry Smith## Linux on Microsoft Windows
269b92b1d3SBarry Smith
27*103dcec6SCarl von Bonin- Microsoft Windows Subsystem for Linux 2 ([WSL2](https://docs.microsoft.com/en-us/windows/wsl/install-win10)). Be sure to use WSL2 for best performance.
289b92b1d3SBarry Smith- [Docker](https://docs.docker.com/docker-for-windows/) for Microsoft
299b92b1d3SBarry Smith  Windows.
309b92b1d3SBarry Smith- Linux virtual machine via [VirtualBox](https://www.virtualbox.org/) or similar. One sample
319b92b1d3SBarry Smith  tutorial is at <https://www.psychocats.net/ubuntu/virtualbox>. Google can provide more
329b92b1d3SBarry Smith  tutorials.
339b92b1d3SBarry Smith
349b92b1d3SBarry Smith______________________________________________________________________
359b92b1d3SBarry Smith
369b92b1d3SBarry Smith(sec_cygwin_gnu_on_windows)=
379b92b1d3SBarry Smith
389b92b1d3SBarry Smith## Cygwin/GNU Compilers on Microsoft Windows
399b92b1d3SBarry Smith
409b92b1d3SBarry SmithCygwin/GNU compilers allow building standalone PETSc libraries and binaries
419b92b1d3SBarry Smiththat work on Microsoft Windows, with Cygwin pre-built libraries for BLAS, LAPACK, and Open MPI.
429b92b1d3SBarry Smith
439b92b1d3SBarry Smith1. Install Cygwin:
449b92b1d3SBarry Smith
459b92b1d3SBarry Smith   Download and install Cygwin from <http://www.cygwin.com> and make sure the
469b92b1d3SBarry Smith   following Cygwin components are installed:
479b92b1d3SBarry Smith
489b92b1d3SBarry Smith   - python3
499b92b1d3SBarry Smith   - make
509b92b1d3SBarry Smith   - gcc-core gcc-g++ gcc-fortran
519b92b1d3SBarry Smith   - liblapack-devel
529b92b1d3SBarry Smith   - openmpi libopenmpi-devel libhwloc-devel libevent-devel zlib-devel
539b92b1d3SBarry Smith
549b92b1d3SBarry Smith2. To build with Cygwin installed BLAS, LAPACK, and Open MPI (from default locations), do (from `Cygwin64 Terminal`):
559b92b1d3SBarry Smith
569b92b1d3SBarry Smith   ```console
579b92b1d3SBarry Smith   $ ./configure
589b92b1d3SBarry Smith   ```
599b92b1d3SBarry Smith
609b92b1d3SBarry Smith3. Follow the Unix instructions for any additional configuration or build options.
619b92b1d3SBarry Smith
629b92b1d3SBarry Smith:::{note}
639b92b1d3SBarry Smith- Libraries built with Cygwin/GNU compilers are **not** compatible and cannot be linked with Microsoft or Intel compilers.
649b92b1d3SBarry Smith- Native libraries like MS-MPI, Intel MPI cannot be used from Cygwin/GNU compilers.
659b92b1d3SBarry Smith- Most {ref}`external packages <doc_externalsoftware>` are likely to work,
669b92b1d3SBarry Smith  however the `configure` option `--download-mpich` does not work.
679b92b1d3SBarry Smith:::
689b92b1d3SBarry Smith
699b92b1d3SBarry Smith______________________________________________________________________
709b92b1d3SBarry Smith
719b92b1d3SBarry Smith(sec_native_compilers_on_windows)=
729b92b1d3SBarry Smith
739b92b1d3SBarry Smith## Native Microsoft/Intel Windows Compilers
749b92b1d3SBarry Smith
759b92b1d3SBarry SmithMicrosoft Windows does not provide a Unix shell environment. Also
769b92b1d3SBarry Smiththe native Microsoft/Intel compilers behave differently than other (Unix) compilers. So to
779b92b1d3SBarry Smithinstall PETSc on Microsoft Windows with Microsoft or Intel compilers one has to install Cygwin (for the Unix environment)
789b92b1d3SBarry Smithand use `win32fe` [^win32] compiler wrapper, to use the Microsoft/Intel compilers.
799b92b1d3SBarry Smith
809b92b1d3SBarry Smith1. Install Cygwin:
819b92b1d3SBarry Smith
829b92b1d3SBarry Smith   Download and install Cygwin from <http://www.cygwin.com> and make sure the
839b92b1d3SBarry Smith   following Cygwin components are installed:
849b92b1d3SBarry Smith
859b92b1d3SBarry Smith   - python3
869b92b1d3SBarry Smith   - make
879b92b1d3SBarry Smith
889b92b1d3SBarry Smith   Additional Cygwin components like git and CMake can be useful for installing
899b92b1d3SBarry Smith   {ref}`external packages <doc_externalsoftware>`.
909b92b1d3SBarry Smith
919b92b1d3SBarry Smith2. Remove Cygwin link.exe:
929b92b1d3SBarry Smith
939b92b1d3SBarry Smith   Cygwin link.exe can conflict with Intel ifort compiler. If you are using ifort -
949b92b1d3SBarry Smith   do (from `Cygwin64 Terminal`):
959b92b1d3SBarry Smith
969b92b1d3SBarry Smith   ```console
979b92b1d3SBarry Smith   $ mv /usr/bin/link.exe /usr/bin/link-cygwin.exe
989b92b1d3SBarry Smith   ```
999b92b1d3SBarry Smith
1009b92b1d3SBarry Smith3. Setup `Cygwin64 Terminal` with working compilers:
1019b92b1d3SBarry Smith
1029b92b1d3SBarry Smith   We require the compilers to be setup properly in a Cygwin bash command shell, so that
1039b92b1d3SBarry Smith   `cl foo.c` or `ifort foo.F` works from this shell. For example - if using `Visual Studio 2022 C`
1049b92b1d3SBarry Smith   and `Intel oneAPI 2022 Fortran`, one can do:
1059b92b1d3SBarry Smith
1069b92b1d3SBarry Smith   1. `Start` -> `Programs` -> `Intel oneAPI 2022` -> `Intel oneAPI command prompt for Intel 64 for Visual Studio 2022`.
1079b92b1d3SBarry Smith      This should start a `DOS Command shell` with working compilers.
1089b92b1d3SBarry Smith
1099b92b1d3SBarry Smith   2. Within this `DOS Command shell` - run `Cygwin64 Terminal`, i.e., `mintty.exe` as:
1109b92b1d3SBarry Smith
1119b92b1d3SBarry Smith      ```powershell
1129b92b1d3SBarry Smith      C:\cygwin64\bin\mintty.exe -
1139b92b1d3SBarry Smith      ```
1149b92b1d3SBarry Smith
1159b92b1d3SBarry Smith   3. Verify if the compilers are usable (by running `cl` and `ifort` in this `Cygwin64 Terminal`).
1169b92b1d3SBarry Smith
1179b92b1d3SBarry Smith   4. Now run `configure` with compiler wrapper script `win32fe_cl` that uses `win32fe` [^win32] and then build the libraries with
1189b92b1d3SBarry Smith      `make` (as per the usual instructions).
1199b92b1d3SBarry Smith
1209b92b1d3SBarry Smith### Example Configure Usage With Microsoft Windows Compilers
1219b92b1d3SBarry Smith
1229b92b1d3SBarry SmithUse `configure` with `Visual Studio 2022 C` and `Intel oneAPI 2022 Fortran` (without MPI):
1239b92b1d3SBarry Smith
1249b92b1d3SBarry Smith```console
1259b92b1d3SBarry Smith$ ./configure --with-cc='win32fe_cl' --with-fc='win32fe_ifort' --with-cxx='win32fe_cl' --with-mpi=0 --download-fblaslapack
1269b92b1d3SBarry Smith```
1279b92b1d3SBarry Smith
1289b92b1d3SBarry SmithIf Fortran or C++ usage is not required, use:
1299b92b1d3SBarry Smith
1309b92b1d3SBarry Smith```console
1319b92b1d3SBarry Smith$ ./configure --with-cc='win32fe_cl' --with-fc=0 --with-cxx=0 --download-f2cblaslapack
1329b92b1d3SBarry Smith```
1339b92b1d3SBarry Smith
1349b92b1d3SBarry Smith:::{note}
1359b92b1d3SBarry Smith- One can use Intel oneAPI C/C++ compiler `icl` or `icx` instead of Microsoft `cl`, for ex: `--with-cc=win32fe_icl --with-cxx=win32fe_icl`.
1369b92b1d3SBarry Smith- A shorter form `--with-cc=cl` that translates to `--with-cc=win32fe_cl` is also supported. Similarly for `icl`, `icx`, `ifort`, `ifx`.
1379b92b1d3SBarry Smith- Intel oneAPI `ifx` currently works with `--with-shared-libraries=0` only, `ifort` is recommended for default shared library build.
1389b92b1d3SBarry Smith- The `--download-package` option may work with some {ref}`external packages <doc_externalsoftware>` and fail with most packages.
1399b92b1d3SBarry Smith:::
1409b92b1d3SBarry Smith
1419b92b1d3SBarry Smith### Using MPI, MKL
1429b92b1d3SBarry Smith
1439b92b1d3SBarry SmithWe support both MS-MPI (64-bit) and Intel MPI on Microsoft Windows. We also support using Intel MKL as BLAS and LAPACK implementations.
1449b92b1d3SBarry SmithFor example usages, check `$PETSC_DIR/config/examples/arch-mswin*.py`
1459b92b1d3SBarry Smith
1469b92b1d3SBarry Smith:::{warning}
1479b92b1d3SBarry Smith**Avoid spaces in \$PATH**
1489b92b1d3SBarry Smith
1499b92b1d3SBarry SmithIt is better to avoid spaces or similar special chars when specifying `configure` options. On
1509b92b1d3SBarry SmithMicrosoft Windows - this usually affects specifying MPI or MKL. Microsoft Windows
1519b92b1d3SBarry Smithsupports DOS short form for directory names - so it is better to use this notation. Cygwin
1529b92b1d3SBarry Smithtool `cygpath` can be used to get paths in this notation. For example:
1539b92b1d3SBarry Smith
1549b92b1d3SBarry Smith```console
1559b92b1d3SBarry Smith$ cygpath -u `cygpath -ms '/cygdrive/c/Program Files (x86)/Microsoft SDKs/MPI'`
1569b92b1d3SBarry Smith/cygdrive/c/PROGRA~2/MICROS~2/MPI
1579b92b1d3SBarry Smith$ cygpath -u `cygpath -ms '/cygdrive/c/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/mkl/lib/intel64'`
1589b92b1d3SBarry Smith/cygdrive/c/PROGRA~2/INTELS~1/COMPIL~2/windows/mkl/lib/intel64
1599b92b1d3SBarry Smith```
1609b92b1d3SBarry Smith
1619b92b1d3SBarry SmithThen use in `configure` as follows:
1629b92b1d3SBarry Smith
1639b92b1d3SBarry Smith```console
1649b92b1d3SBarry Smith$ ./configure --with-cc='win32fe_cl' --with-fc='win32fe_ifort' --with-cxx='win32fe_cl' \
1659b92b1d3SBarry Smith--with-shared-libraries=0 \
1669b92b1d3SBarry Smith--with-mpi-include='[/cygdrive/c/PROGRA~2/MICROS~2/MPI/Include,/cygdrive/c/PROGRA~2/MICROS~2/MPI/Include/x64]' \
1679b92b1d3SBarry Smith--with-mpi-lib='-L/cygdrive/c/PROGRA~2/MICROS~2/MPI/lib/x64 msmpifec.lib msmpi.lib' \
1689b92b1d3SBarry Smith--with-mpiexec=/cygdrive/c/PROGRA~1/MICROS~2/Bin/mpiexec \
1699b92b1d3SBarry Smith--with-blaslapack-lib='-L/cygdrive/c/PROGRA~2/INTELS~1/COMPIL~2/windows/mkl/lib/intel64 mkl_intel_lp64_dll.lib mkl_sequential_dll.lib mkl_core_dll.lib'
1709b92b1d3SBarry Smith```
1719b92b1d3SBarry Smith:::
1729b92b1d3SBarry Smith
1739b92b1d3SBarry Smith### Project Files
1749b92b1d3SBarry Smith
1759b92b1d3SBarry SmithWe cannot provide Microsoft Visual Studio project files for users as they are specific to
1769b92b1d3SBarry Smiththe `configure` options, location of {ref}`external packages <doc_externalsoftware>`,
1779b92b1d3SBarry Smithcompiler versions etc. used for any given build of PETSc, so they are potentially
1789b92b1d3SBarry Smithdifferent for each build of PETSc. So if you need a project file for use with PETSc -
1799b92b1d3SBarry Smithdo the following.
1809b92b1d3SBarry Smith
1819b92b1d3SBarry Smith1. Create an empty project file with one of the examples, say
1829b92b1d3SBarry Smith   `$PETSC_DIR/src/ksp/ksp/tutorials/ex2.c`
1839b92b1d3SBarry Smith
1849b92b1d3SBarry Smith2. Try compiling the example from Cygwin bash shell - using `make` - i.e.:
1859b92b1d3SBarry Smith
1869b92b1d3SBarry Smith   ```console
1879b92b1d3SBarry Smith   $ cd $PETSC_DIR/src/ksp/ksp/tutorials
1889b92b1d3SBarry Smith   $ make ex2
1899b92b1d3SBarry Smith   ```
1909b92b1d3SBarry Smith
1919b92b1d3SBarry Smith3. If the above works - then make sure all the compiler/linker options used by `make`
1929b92b1d3SBarry Smith   are also present in the project file in the correct notation.
1939b92b1d3SBarry Smith
1949b92b1d3SBarry Smith4. If errors - redo the above step. If all the options are correctly specified, the
1959b92b1d3SBarry Smith   example should compile from Microsoft Visual Studio.
1969b92b1d3SBarry Smith
1979b92b1d3SBarry Smith______________________________________________________________________
1989b92b1d3SBarry Smith
1999b92b1d3SBarry Smith(sec_msys2_mingw_compilers_on_windows)=
2009b92b1d3SBarry Smith
2019b92b1d3SBarry Smith## MSYS2/MinGW (GNU) Compilers on Microsoft Windows
2029b92b1d3SBarry Smith
2039b92b1d3SBarry SmithThese allow building standalone Microsoft Windows libraries and
2049b92b1d3SBarry Smithapplications that are compatible with the Microsoft and Intel compilers.
2059b92b1d3SBarry Smith
2069b92b1d3SBarry Smith1. Install MSYS2 and MS-MPI:
2079b92b1d3SBarry Smith
2089b92b1d3SBarry Smith   Download and install MSYS2 from <https://www.msys2.org>.
2099b92b1d3SBarry Smith   If you want to use MPI, we recommend you use MS-MPI from <https://learn.microsoft.com/en-us/message-passing-interface/microsoft-mpi>.
2109b92b1d3SBarry Smith
2119b92b1d3SBarry Smith2. Update MSYS2 and install base packages:
2129b92b1d3SBarry Smith
2139b92b1d3SBarry Smith   First, launch a MSYS2 MinGW x64 shell. Double-check this is the proper type of shell by typing
2149b92b1d3SBarry Smith
2159b92b1d3SBarry Smith   ```console
2169b92b1d3SBarry Smith   $  echo $MINGW_PREFIX
2179b92b1d3SBarry Smith   /mingw64
2189b92b1d3SBarry Smith   ```
2199b92b1d3SBarry Smith
2209b92b1d3SBarry Smith   If you see something else, e.g., `/clang64`, this is not the correct type
2219b92b1d3SBarry Smith   of shell, it may still work, but this is less tested. Then, update your
2229b92b1d3SBarry Smith   installation using `pacman` (you may be asked to quit and re-open your shell).
2239b92b1d3SBarry Smith
2249b92b1d3SBarry Smith   ```console
2259b92b1d3SBarry Smith   $  pacman -Syu
2269b92b1d3SBarry Smith   ```
2279b92b1d3SBarry Smith
2289b92b1d3SBarry Smith   Install the following packages that are needed
2299b92b1d3SBarry Smith   by some PETSc dependencies.
2309b92b1d3SBarry Smith
2319b92b1d3SBarry Smith   ```console
2329b92b1d3SBarry Smith   $  pacman -S autoconf automake-wrapper bison bsdcpio make git \
2339b92b1d3SBarry Smith   mingw-w64-x86_64-toolchain patch python flex \
2349b92b1d3SBarry Smith   pkg-config pkgfile tar unzip mingw-w64-x86_64-cmake \
2359b92b1d3SBarry Smith   mingw-w64-x86_64-msmpi mingw-w64-x86_64-openblas mingw-w64-x86_64-jq
2369b92b1d3SBarry Smith   ```
2379b92b1d3SBarry Smith
2389b92b1d3SBarry Smith3. Configuring:
2399b92b1d3SBarry Smith
2409b92b1d3SBarry Smith   The two difficulties here are: 1) make sure PETSc configure picks up the proper Python installation, as there are more than one available in a MSYS2 MinGW shell and 2) tell PETSc where MS-MPI `mpiexec` is. We recommend not using shared libraries as it is easier to create standalone binaries that way.
2419b92b1d3SBarry Smith
2429b92b1d3SBarry Smith   ```console
2439b92b1d3SBarry Smith   $  /usr/bin/python ./configure --with-mpiexec='/C/Program\ Files/Microsoft\ MPI/Bin/mpiexec' \
2449b92b1d3SBarry Smith   --with-shared-libraries=0
2459b92b1d3SBarry Smith   ```
2469b92b1d3SBarry Smith
2479b92b1d3SBarry Smith:::{note}
2489b92b1d3SBarry Smith`MinGW` (GNU) compilers can also be installed/used via `Cygwin` (not just MSYS2).
2499b92b1d3SBarry Smith:::
2509b92b1d3SBarry Smith
2519b92b1d3SBarry Smith### Debugging on Microsoft Windows
2529b92b1d3SBarry Smith
2539b92b1d3SBarry SmithRunning PETSc programs with `-start_in_debugger` is not supported on Microsoft Windows. Debuggers need to be initiated manually.
2549b92b1d3SBarry SmithMake sure your environment is properly configured to use the appropriate debugger for your compiler.
2559b92b1d3SBarry SmithThe debuggers can be initiated using Microsoft Visual Studio:
2569b92b1d3SBarry Smith
2579b92b1d3SBarry Smith```console
2589b92b1d3SBarry Smith$ devenv ex1.exe
2599b92b1d3SBarry Smith```
2609b92b1d3SBarry Smith
2619b92b1d3SBarry SmithIntel Enhanced Debugger:
2629b92b1d3SBarry Smith
2639b92b1d3SBarry Smith```console
2649b92b1d3SBarry Smith$ edb ex1.exe
2659b92b1d3SBarry Smith```
2669b92b1d3SBarry Smith
2679b92b1d3SBarry Smithor GNU Debugger
2689b92b1d3SBarry Smith
2699b92b1d3SBarry Smith```console
2709b92b1d3SBarry Smith$ gdb ex1.exe
2719b92b1d3SBarry Smith```
2729b92b1d3SBarry Smith
2739b92b1d3SBarry Smith```{rubric} Footnotes
2749b92b1d3SBarry Smith```
2759b92b1d3SBarry Smith
2769b92b1d3SBarry Smith[^win32]: [PETSc Win32 Development Tool Front End](https://bitbucket.org/petsc/win32fe) (`win32fe`): This tool is used as a wrapper to Microsoft
2779b92b1d3SBarry Smith    and Intel compilers and associated tools - to enable building PETSc libraries using
2789b92b1d3SBarry Smith    Cygwin `make` and other Unix tools. For additional info, run
2799b92b1d3SBarry Smith    `${PETSC_DIR}/lib/petsc/bin/win32fe/win32fe --help`
280