xref: /petsc/doc/install/windows.md (revision 9b92b1d3a7bbc5a081edc9021bfd15a36804dd1c)
1*9b92b1d3SBarry Smith(doc_windows)=
2*9b92b1d3SBarry Smith
3*9b92b1d3SBarry Smith# Installing PETSc On Microsoft Windows
4*9b92b1d3SBarry Smith
5*9b92b1d3SBarry Smith:::{admonition} Are You Sure?
6*9b92b1d3SBarry Smith:class: yellow
7*9b92b1d3SBarry Smith
8*9b92b1d3SBarry SmithAre you sure you want to use Microsoft Windows?
9*9b92b1d3SBarry Smith
10*9b92b1d3SBarry SmithDeveloping HPC software is more difficult on Microsoft Windows than Linux and macOS systems.
11*9b92b1d3SBarry SmithWe recommend using a Microsoft Windows system for PETSc only when necessary.
12*9b92b1d3SBarry Smith:::
13*9b92b1d3SBarry Smith
14*9b92b1d3SBarry SmithThere are many ways to install PETSc on Microsoft Windows's systems.
15*9b92b1d3SBarry Smith
16*9b92b1d3SBarry Smith- {any}`sec_linux_on_windows`
17*9b92b1d3SBarry Smith- {any}`sec_cygwin_gnu_on_windows`
18*9b92b1d3SBarry Smith- {any}`sec_native_compilers_on_windows`
19*9b92b1d3SBarry Smith- {any}`sec_msys2_mingw_compilers_on_windows`
20*9b92b1d3SBarry Smith
21*9b92b1d3SBarry Smith______________________________________________________________________
22*9b92b1d3SBarry Smith
23*9b92b1d3SBarry Smith(sec_linux_on_windows)=
24*9b92b1d3SBarry Smith
25*9b92b1d3SBarry Smith## Linux on Microsoft Windows
26*9b92b1d3SBarry Smith
27*9b92b1d3SBarry Smith- Microsoft Windows Subsystem for Linux 2 ([WLS2](https://docs.microsoft.com/en-us/windows/wsl/install-win10)). Be sure to use WSL2 for best performance.
28*9b92b1d3SBarry Smith- [Docker](https://docs.docker.com/docker-for-windows/) for Microsoft
29*9b92b1d3SBarry Smith  Windows.
30*9b92b1d3SBarry Smith- Linux virtual machine via [VirtualBox](https://www.virtualbox.org/) or similar. One sample
31*9b92b1d3SBarry Smith  tutorial is at <https://www.psychocats.net/ubuntu/virtualbox>. Google can provide more
32*9b92b1d3SBarry Smith  tutorials.
33*9b92b1d3SBarry Smith
34*9b92b1d3SBarry Smith______________________________________________________________________
35*9b92b1d3SBarry Smith
36*9b92b1d3SBarry Smith(sec_cygwin_gnu_on_windows)=
37*9b92b1d3SBarry Smith
38*9b92b1d3SBarry Smith## Cygwin/GNU Compilers on Microsoft Windows
39*9b92b1d3SBarry Smith
40*9b92b1d3SBarry SmithCygwin/GNU compilers allow building standalone PETSc libraries and binaries
41*9b92b1d3SBarry Smiththat work on Microsoft Windows, with Cygwin pre-built libraries for BLAS, LAPACK, and Open MPI.
42*9b92b1d3SBarry Smith
43*9b92b1d3SBarry Smith1. Install Cygwin:
44*9b92b1d3SBarry Smith
45*9b92b1d3SBarry Smith   Download and install Cygwin from <http://www.cygwin.com> and make sure the
46*9b92b1d3SBarry Smith   following Cygwin components are installed:
47*9b92b1d3SBarry Smith
48*9b92b1d3SBarry Smith   - python3
49*9b92b1d3SBarry Smith   - make
50*9b92b1d3SBarry Smith   - gcc-core gcc-g++ gcc-fortran
51*9b92b1d3SBarry Smith   - liblapack-devel
52*9b92b1d3SBarry Smith   - openmpi libopenmpi-devel libhwloc-devel libevent-devel zlib-devel
53*9b92b1d3SBarry Smith
54*9b92b1d3SBarry Smith2. To build with Cygwin installed BLAS, LAPACK, and Open MPI (from default locations), do (from `Cygwin64 Terminal`):
55*9b92b1d3SBarry Smith
56*9b92b1d3SBarry Smith   ```console
57*9b92b1d3SBarry Smith   $ ./configure
58*9b92b1d3SBarry Smith   ```
59*9b92b1d3SBarry Smith
60*9b92b1d3SBarry Smith3. Follow the Unix instructions for any additional configuration or build options.
61*9b92b1d3SBarry Smith
62*9b92b1d3SBarry Smith:::{note}
63*9b92b1d3SBarry Smith- Libraries built with Cygwin/GNU compilers are **not** compatible and cannot be linked with Microsoft or Intel compilers.
64*9b92b1d3SBarry Smith- Native libraries like MS-MPI, Intel MPI cannot be used from Cygwin/GNU compilers.
65*9b92b1d3SBarry Smith- Most {ref}`external packages <doc_externalsoftware>` are likely to work,
66*9b92b1d3SBarry Smith  however the `configure` option `--download-mpich` does not work.
67*9b92b1d3SBarry Smith:::
68*9b92b1d3SBarry Smith
69*9b92b1d3SBarry Smith______________________________________________________________________
70*9b92b1d3SBarry Smith
71*9b92b1d3SBarry Smith(sec_native_compilers_on_windows)=
72*9b92b1d3SBarry Smith
73*9b92b1d3SBarry Smith## Native Microsoft/Intel Windows Compilers
74*9b92b1d3SBarry Smith
75*9b92b1d3SBarry SmithMicrosoft Windows does not provide a Unix shell environment. Also
76*9b92b1d3SBarry Smiththe native Microsoft/Intel compilers behave differently than other (Unix) compilers. So to
77*9b92b1d3SBarry Smithinstall PETSc on Microsoft Windows with Microsoft or Intel compilers one has to install Cygwin (for the Unix environment)
78*9b92b1d3SBarry Smithand use `win32fe` [^win32] compiler wrapper, to use the Microsoft/Intel compilers.
79*9b92b1d3SBarry Smith
80*9b92b1d3SBarry Smith1. Install Cygwin:
81*9b92b1d3SBarry Smith
82*9b92b1d3SBarry Smith   Download and install Cygwin from <http://www.cygwin.com> and make sure the
83*9b92b1d3SBarry Smith   following Cygwin components are installed:
84*9b92b1d3SBarry Smith
85*9b92b1d3SBarry Smith   - python3
86*9b92b1d3SBarry Smith   - make
87*9b92b1d3SBarry Smith
88*9b92b1d3SBarry Smith   Additional Cygwin components like git and CMake can be useful for installing
89*9b92b1d3SBarry Smith   {ref}`external packages <doc_externalsoftware>`.
90*9b92b1d3SBarry Smith
91*9b92b1d3SBarry Smith2. Remove Cygwin link.exe:
92*9b92b1d3SBarry Smith
93*9b92b1d3SBarry Smith   Cygwin link.exe can conflict with Intel ifort compiler. If you are using ifort -
94*9b92b1d3SBarry Smith   do (from `Cygwin64 Terminal`):
95*9b92b1d3SBarry Smith
96*9b92b1d3SBarry Smith   ```console
97*9b92b1d3SBarry Smith   $ mv /usr/bin/link.exe /usr/bin/link-cygwin.exe
98*9b92b1d3SBarry Smith   ```
99*9b92b1d3SBarry Smith
100*9b92b1d3SBarry Smith3. Setup `Cygwin64 Terminal` with working compilers:
101*9b92b1d3SBarry Smith
102*9b92b1d3SBarry Smith   We require the compilers to be setup properly in a Cygwin bash command shell, so that
103*9b92b1d3SBarry Smith   `cl foo.c` or `ifort foo.F` works from this shell. For example - if using `Visual Studio 2022 C`
104*9b92b1d3SBarry Smith   and `Intel oneAPI 2022 Fortran`, one can do:
105*9b92b1d3SBarry Smith
106*9b92b1d3SBarry Smith   1. `Start` -> `Programs` -> `Intel oneAPI 2022` -> `Intel oneAPI command prompt for Intel 64 for Visual Studio 2022`.
107*9b92b1d3SBarry Smith      This should start a `DOS Command shell` with working compilers.
108*9b92b1d3SBarry Smith
109*9b92b1d3SBarry Smith   2. Within this `DOS Command shell` - run `Cygwin64 Terminal`, i.e., `mintty.exe` as:
110*9b92b1d3SBarry Smith
111*9b92b1d3SBarry Smith      ```powershell
112*9b92b1d3SBarry Smith      C:\cygwin64\bin\mintty.exe -
113*9b92b1d3SBarry Smith      ```
114*9b92b1d3SBarry Smith
115*9b92b1d3SBarry Smith   3. Verify if the compilers are usable (by running `cl` and `ifort` in this `Cygwin64 Terminal`).
116*9b92b1d3SBarry Smith
117*9b92b1d3SBarry Smith   4. Now run `configure` with compiler wrapper script `win32fe_cl` that uses `win32fe` [^win32] and then build the libraries with
118*9b92b1d3SBarry Smith      `make` (as per the usual instructions).
119*9b92b1d3SBarry Smith
120*9b92b1d3SBarry Smith### Example Configure Usage With Microsoft Windows Compilers
121*9b92b1d3SBarry Smith
122*9b92b1d3SBarry SmithUse `configure` with `Visual Studio 2022 C` and `Intel oneAPI 2022 Fortran` (without MPI):
123*9b92b1d3SBarry Smith
124*9b92b1d3SBarry Smith```console
125*9b92b1d3SBarry Smith$ ./configure --with-cc='win32fe_cl' --with-fc='win32fe_ifort' --with-cxx='win32fe_cl' --with-mpi=0 --download-fblaslapack
126*9b92b1d3SBarry Smith```
127*9b92b1d3SBarry Smith
128*9b92b1d3SBarry SmithIf Fortran or C++ usage is not required, use:
129*9b92b1d3SBarry Smith
130*9b92b1d3SBarry Smith```console
131*9b92b1d3SBarry Smith$ ./configure --with-cc='win32fe_cl' --with-fc=0 --with-cxx=0 --download-f2cblaslapack
132*9b92b1d3SBarry Smith```
133*9b92b1d3SBarry Smith
134*9b92b1d3SBarry Smith:::{note}
135*9b92b1d3SBarry 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`.
136*9b92b1d3SBarry Smith- A shorter form `--with-cc=cl` that translates to `--with-cc=win32fe_cl` is also supported. Similarly for `icl`, `icx`, `ifort`, `ifx`.
137*9b92b1d3SBarry Smith- Intel oneAPI `ifx` currently works with `--with-shared-libraries=0` only, `ifort` is recommended for default shared library build.
138*9b92b1d3SBarry Smith- The `--download-package` option may work with some {ref}`external packages <doc_externalsoftware>` and fail with most packages.
139*9b92b1d3SBarry Smith:::
140*9b92b1d3SBarry Smith
141*9b92b1d3SBarry Smith### Using MPI, MKL
142*9b92b1d3SBarry Smith
143*9b92b1d3SBarry SmithWe support both MS-MPI (64-bit) and Intel MPI on Microsoft Windows. We also support using Intel MKL as BLAS and LAPACK implementations.
144*9b92b1d3SBarry SmithFor example usages, check `$PETSC_DIR/config/examples/arch-mswin*.py`
145*9b92b1d3SBarry Smith
146*9b92b1d3SBarry Smith:::{warning}
147*9b92b1d3SBarry Smith**Avoid spaces in \$PATH**
148*9b92b1d3SBarry Smith
149*9b92b1d3SBarry SmithIt is better to avoid spaces or similar special chars when specifying `configure` options. On
150*9b92b1d3SBarry SmithMicrosoft Windows - this usually affects specifying MPI or MKL. Microsoft Windows
151*9b92b1d3SBarry Smithsupports DOS short form for directory names - so it is better to use this notation. Cygwin
152*9b92b1d3SBarry Smithtool `cygpath` can be used to get paths in this notation. For example:
153*9b92b1d3SBarry Smith
154*9b92b1d3SBarry Smith```console
155*9b92b1d3SBarry Smith$ cygpath -u `cygpath -ms '/cygdrive/c/Program Files (x86)/Microsoft SDKs/MPI'`
156*9b92b1d3SBarry Smith/cygdrive/c/PROGRA~2/MICROS~2/MPI
157*9b92b1d3SBarry Smith$ cygpath -u `cygpath -ms '/cygdrive/c/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/mkl/lib/intel64'`
158*9b92b1d3SBarry Smith/cygdrive/c/PROGRA~2/INTELS~1/COMPIL~2/windows/mkl/lib/intel64
159*9b92b1d3SBarry Smith```
160*9b92b1d3SBarry Smith
161*9b92b1d3SBarry SmithThen use in `configure` as follows:
162*9b92b1d3SBarry Smith
163*9b92b1d3SBarry Smith```console
164*9b92b1d3SBarry Smith$ ./configure --with-cc='win32fe_cl' --with-fc='win32fe_ifort' --with-cxx='win32fe_cl' \
165*9b92b1d3SBarry Smith--with-shared-libraries=0 \
166*9b92b1d3SBarry Smith--with-mpi-include='[/cygdrive/c/PROGRA~2/MICROS~2/MPI/Include,/cygdrive/c/PROGRA~2/MICROS~2/MPI/Include/x64]' \
167*9b92b1d3SBarry Smith--with-mpi-lib='-L/cygdrive/c/PROGRA~2/MICROS~2/MPI/lib/x64 msmpifec.lib msmpi.lib' \
168*9b92b1d3SBarry Smith--with-mpiexec=/cygdrive/c/PROGRA~1/MICROS~2/Bin/mpiexec \
169*9b92b1d3SBarry 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'
170*9b92b1d3SBarry Smith```
171*9b92b1d3SBarry Smith:::
172*9b92b1d3SBarry Smith
173*9b92b1d3SBarry Smith### Project Files
174*9b92b1d3SBarry Smith
175*9b92b1d3SBarry SmithWe cannot provide Microsoft Visual Studio project files for users as they are specific to
176*9b92b1d3SBarry Smiththe `configure` options, location of {ref}`external packages <doc_externalsoftware>`,
177*9b92b1d3SBarry Smithcompiler versions etc. used for any given build of PETSc, so they are potentially
178*9b92b1d3SBarry Smithdifferent for each build of PETSc. So if you need a project file for use with PETSc -
179*9b92b1d3SBarry Smithdo the following.
180*9b92b1d3SBarry Smith
181*9b92b1d3SBarry Smith1. Create an empty project file with one of the examples, say
182*9b92b1d3SBarry Smith   `$PETSC_DIR/src/ksp/ksp/tutorials/ex2.c`
183*9b92b1d3SBarry Smith
184*9b92b1d3SBarry Smith2. Try compiling the example from Cygwin bash shell - using `make` - i.e.:
185*9b92b1d3SBarry Smith
186*9b92b1d3SBarry Smith   ```console
187*9b92b1d3SBarry Smith   $ cd $PETSC_DIR/src/ksp/ksp/tutorials
188*9b92b1d3SBarry Smith   $ make ex2
189*9b92b1d3SBarry Smith   ```
190*9b92b1d3SBarry Smith
191*9b92b1d3SBarry Smith3. If the above works - then make sure all the compiler/linker options used by `make`
192*9b92b1d3SBarry Smith   are also present in the project file in the correct notation.
193*9b92b1d3SBarry Smith
194*9b92b1d3SBarry Smith4. If errors - redo the above step. If all the options are correctly specified, the
195*9b92b1d3SBarry Smith   example should compile from Microsoft Visual Studio.
196*9b92b1d3SBarry Smith
197*9b92b1d3SBarry Smith______________________________________________________________________
198*9b92b1d3SBarry Smith
199*9b92b1d3SBarry Smith(sec_msys2_mingw_compilers_on_windows)=
200*9b92b1d3SBarry Smith
201*9b92b1d3SBarry Smith## MSYS2/MinGW (GNU) Compilers on Microsoft Windows
202*9b92b1d3SBarry Smith
203*9b92b1d3SBarry SmithThese allow building standalone Microsoft Windows libraries and
204*9b92b1d3SBarry Smithapplications that are compatible with the Microsoft and Intel compilers.
205*9b92b1d3SBarry Smith
206*9b92b1d3SBarry Smith1. Install MSYS2 and MS-MPI:
207*9b92b1d3SBarry Smith
208*9b92b1d3SBarry Smith   Download and install MSYS2 from <https://www.msys2.org>.
209*9b92b1d3SBarry 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>.
210*9b92b1d3SBarry Smith
211*9b92b1d3SBarry Smith2. Update MSYS2 and install base packages:
212*9b92b1d3SBarry Smith
213*9b92b1d3SBarry Smith   First, launch a MSYS2 MinGW x64 shell. Double-check this is the proper type of shell by typing
214*9b92b1d3SBarry Smith
215*9b92b1d3SBarry Smith   ```console
216*9b92b1d3SBarry Smith   $  echo $MINGW_PREFIX
217*9b92b1d3SBarry Smith   /mingw64
218*9b92b1d3SBarry Smith   ```
219*9b92b1d3SBarry Smith
220*9b92b1d3SBarry Smith   If you see something else, e.g., `/clang64`, this is not the correct type
221*9b92b1d3SBarry Smith   of shell, it may still work, but this is less tested. Then, update your
222*9b92b1d3SBarry Smith   installation using `pacman` (you may be asked to quit and re-open your shell).
223*9b92b1d3SBarry Smith
224*9b92b1d3SBarry Smith   ```console
225*9b92b1d3SBarry Smith   $  pacman -Syu
226*9b92b1d3SBarry Smith   ```
227*9b92b1d3SBarry Smith
228*9b92b1d3SBarry Smith   Install the following packages that are needed
229*9b92b1d3SBarry Smith   by some PETSc dependencies.
230*9b92b1d3SBarry Smith
231*9b92b1d3SBarry Smith   ```console
232*9b92b1d3SBarry Smith   $  pacman -S autoconf automake-wrapper bison bsdcpio make git \
233*9b92b1d3SBarry Smith   mingw-w64-x86_64-toolchain patch python flex \
234*9b92b1d3SBarry Smith   pkg-config pkgfile tar unzip mingw-w64-x86_64-cmake \
235*9b92b1d3SBarry Smith   mingw-w64-x86_64-msmpi mingw-w64-x86_64-openblas mingw-w64-x86_64-jq
236*9b92b1d3SBarry Smith   ```
237*9b92b1d3SBarry Smith
238*9b92b1d3SBarry Smith3. Configuring:
239*9b92b1d3SBarry Smith
240*9b92b1d3SBarry 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.
241*9b92b1d3SBarry Smith
242*9b92b1d3SBarry Smith   ```console
243*9b92b1d3SBarry Smith   $  /usr/bin/python ./configure --with-mpiexec='/C/Program\ Files/Microsoft\ MPI/Bin/mpiexec' \
244*9b92b1d3SBarry Smith   --with-shared-libraries=0
245*9b92b1d3SBarry Smith   ```
246*9b92b1d3SBarry Smith
247*9b92b1d3SBarry Smith:::{note}
248*9b92b1d3SBarry Smith`MinGW` (GNU) compilers can also be installed/used via `Cygwin` (not just MSYS2).
249*9b92b1d3SBarry Smith:::
250*9b92b1d3SBarry Smith
251*9b92b1d3SBarry Smith### Debugging on Microsoft Windows
252*9b92b1d3SBarry Smith
253*9b92b1d3SBarry SmithRunning PETSc programs with `-start_in_debugger` is not supported on Microsoft Windows. Debuggers need to be initiated manually.
254*9b92b1d3SBarry SmithMake sure your environment is properly configured to use the appropriate debugger for your compiler.
255*9b92b1d3SBarry SmithThe debuggers can be initiated using Microsoft Visual Studio:
256*9b92b1d3SBarry Smith
257*9b92b1d3SBarry Smith```console
258*9b92b1d3SBarry Smith$ devenv ex1.exe
259*9b92b1d3SBarry Smith```
260*9b92b1d3SBarry Smith
261*9b92b1d3SBarry SmithIntel Enhanced Debugger:
262*9b92b1d3SBarry Smith
263*9b92b1d3SBarry Smith```console
264*9b92b1d3SBarry Smith$ edb ex1.exe
265*9b92b1d3SBarry Smith```
266*9b92b1d3SBarry Smith
267*9b92b1d3SBarry Smithor GNU Debugger
268*9b92b1d3SBarry Smith
269*9b92b1d3SBarry Smith```console
270*9b92b1d3SBarry Smith$ gdb ex1.exe
271*9b92b1d3SBarry Smith```
272*9b92b1d3SBarry Smith
273*9b92b1d3SBarry Smith```{rubric} Footnotes
274*9b92b1d3SBarry Smith```
275*9b92b1d3SBarry Smith
276*9b92b1d3SBarry Smith[^win32]: [PETSc Win32 Development Tool Front End](https://bitbucket.org/petsc/win32fe) (`win32fe`): This tool is used as a wrapper to Microsoft
277*9b92b1d3SBarry Smith    and Intel compilers and associated tools - to enable building PETSc libraries using
278*9b92b1d3SBarry Smith    Cygwin `make` and other Unix tools. For additional info, run
279*9b92b1d3SBarry Smith    `${PETSC_DIR}/lib/petsc/bin/win32fe/win32fe --help`
280