OpenFOAM 2.1.x on Windows 64-bit with MS MPI
We have updated our free Windows source code patch for the latest OpenFOAM® release (v2.1.x). As with the previous version this patch also supports 64-bit compilation using the MinGW-w64 cross-compiler and parallel computation using the native Windows MS MPI implementation provided by the free Microsoft MPI Redistributable and also available on Microsoft Windows HPC Server 2008 for clusters.
OpenFOAM GUI
Are you looking for a GUI driven, integrated simulation environment for Windows, Linux, and Mac incorporating a selection of the RANS OpenFOAM solvers and various import/export filters? Then try our Caedium RANS Flow add-on.
Binary Version
A set of OpenFOAM binaries for Windows containing these latest patch modifications are available for purchase at "OpenFlow: OpenFOAM for Windows."
Patch Build Process
To build OpenFOAM for Windows with a cross-compiler requires expert knowledge of Windows and Linux utilities and compilers.
The following steps are required to produce a native Windows version of OpenFOAM 2.1.x 64-bit with [optional] native Windows MS MPI:
- Install MinGW-w64 cross-compiler and zlib on Linux
- Install zlib files into following locations:
<mingw-w64>/x86_64-w64-mingw32/include/zconf.h<mingw-w64>/x86_64-w64-mingw32/include/zlib.h<mingw-w64>/bin/zlib1.dll<mingw-w64>/x86_64-w64-mingw32/lib/libz.a<mingw-w64>/x86_64-w64-mingw32/lib/libzdll.a
- May need to add
#include_next <float.h>to the end of
<mingw-w64>/lib/gcc/x86_64-w64-mingw32/<gcc-version>/include/float.hand remove it from
<mingw-w64>/x86_64-w64-mingw32/include/float.hto include the right float.h - [optional] Create libmsmpi.a from Microsoft MPI Redistributable
- Install the OpenFOAM 2.1.x source distribution on Linux - git commit: eb976ba31c3644a536b658ea56c68d6c843b6976, Date: Thu Jan 5 12:21:31 2012.
- Patch (using the Linux patch command) the OpenFOAM 2.1.x source distribution with our MinGW Windows modifications [last updated Jan. 18, 2012 to v1]
- At various stages during this process you will need to set OpenFOAM MinGW-w64 environment variables and source etc/bashrc. As an example:
export FOAM_INST_DIR="$(HOME)/projects/of/2.1"; source $(FOAM_INST_DIR)/OpenFOAM-2.1.x/etc/bashrc WM_OSTYPE=MSwindows WM_COMPILER=mingw-w64 WM_ARCH_OPTION=64 WM_PRECISION_OPTION=SP WM_CC=x86_64-w64-mingw32-gcc WM_CXX=x86_64-w64-mingw32-g++ compilerInstall=system [optional] WM_MPLIB=MSMPI [optional] MPI_ARCH_PATH="$(HOME)/projects/msmpi/install" - [optional] Install the ThirdParty-2.1.0 source and build scotch according to:
ln -s ThirdParty-2.1.0 $(WM_THIRD_PARTY_DIR)ln -s $(WM_THIRD_PARTY_DIR)/scotch<version> $(WM_THIRD_PARTY_DIR)/scotchln -s $(WM_PROJECT_DIR)/extra/scotch/src/Make.inc/Makefile.inc.mingw-w64 $(WM_THIRD_PARTY_DIR)/scotch/src/Makefile.inccp $(WM_PROJECT_DIR)/extra/scotch/src/libscotch/* $(WM_THIRD_PARTY_DIR)/scotch/src/libscotch/.cd $(WM_THIRD_PARTY_DIR)/scotch/srccp $(WM_PROJECT_DIR)/extra/scotch/src/Makefile .make libscotchmkdir -p $(FOAM_LIBBIN)cd $(WM_THIRD_PARTY_DIR)/scotch/src/libscotchcp libscotch.* $(FOAM_LIBBIN)
- To build OpenFOAM:
- source the OpenFOAM native linux environment variables
cd $(WM_PROJECT_DIR)/wmake/src; makeln -s $(WM_PROJECT_DIR)/wmake/platforms/linux64Gcc $(WM_PROJECT_DIR)/wmake/platforms/linux64mingw-w64- source the OpenFOAM MinGW-w64 environment variables
cd $(WM_PROJECT_DIR);./Allwmake
- Transfer the OpenFOAM etc directory ($(WM_PROJECT_DIR)/etc), executables ($(WM_PROJECT_DIR)/platforms/linux64mingw-w64*/bin/*.exe), and libraries ($(WM_PROJECT_DIR)/platforms/linux64mingw-w64*/lib/*.dll and $(WM_PROJECT_DIR)/platforms/linux64mingw-w64*/lib/*/*.dll) to the Windows computer
- Transfer the MinGW-w64 libraries:
<mingw-w64>/bin/zlib1.dll<mingw-w64>/bin/libgcc_s_sjlj-1.dll<mingw-w64>/bin/libstdc++-6.dll
to the Windows computer
- On the Windows computer ensure the following environment variables are set:
- The WM_PROJECT_DIR and USERNAME variables are set.
- The PATH variable is set to include the OpenFOAM executable and library locations (including $(WM_PROJECT_DIR)/lib/linux64mingw-w64*/dummy or [optional] $(WM_PROJECT_DIR)/lib/linux64mingw-w64*/msmpi).
- Launch a Windows command prompt to run OpenFOAM solvers and utilities, such as simpleFoam.exe.
Windows HPC Server 2008
job submit example on Windows HPC Server 2008 for simpleFoam:
job submit /jobname:simpleFoam-jobName /name:simpleFoam-taskName /numprocessors:16 /stdout:\\CRAY01\<of-case>\stdout.txt /stderr:\\CRAY01\<of-case>\stderr.txt mpiexec -env WM_PROJECT_DIR \\CRAY01\$(WM_PROJECT_DIR) -env MPI_BUFFER_SIZE 20000000 -env USERNAME openfoam -env PATH \\CRAY01\$(WM_PROJECT_DIR)\platforms\linux64mingw-w64*\lib;\\CRAY01\$(WM_PROJECT_DIR)\platforms\linux64mingw-w64*\lib\msmpi \\CRAY01\$(WM_PROJECT_DIR)\platforms\linux64mingw-w64*\bin\simpleFoam -parallel -case \\CRAY01\<of-case>\pitzDaily
Note you need to share both the case (\\CRAY01\<of-case> - arbitrary name of your choosing) and application directories (\\CRAY01\$(WM_PROJECT_DIR)) so all nodes on the cluster can access them.
Constraints
With this method of building OpenFOAM for Windows the job control scripts in $(WM_PROJECT_DIR)/bin (such as foamSolverSweeps) are unavailable. Also the libccmio library is not built.
Notes
- OpenFOAM is a registered trademark of SGI Corp. and is unaffiliated with Symscape
- The OpenFOAM Windows patch provided here is licensed under the GNU Public License (GPL)


Comments
OSSpecific/MSWindows missing
Step 7 asks to set "WM_OSTYPE=MSwindows", thus Makefile looks for folder OSSpecific/MSWindows - But this folder is missing (I checked git repo for both 2.1.x as well as 2.0.x)
Where do I get this folder ?
Thanks.
Apply the patch
Step 6.