OpenFOAM 2.1.x on Windows 64-bit with MS MPI

For the latest version of our Windows patch for OpenFOAM visit "OpenFOAM 2.2.x on Windows".

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 2012 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?

Get Started With Caedium Now

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:

  1. Install MinGW-w64 cross-compiler and zlib on Linux
  2. 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
  3. If you see an error while compiling like:
    signals/sigFpe.C:45:15: error: '_clearfp' was not declared in this scope
    You need to add #include_next <float.h> to the end of
    <mingw-w64>/lib/gcc/x86_64-w64-mingw32/<gcc-version>/include/float.h and remove it from
    <mingw-w64>/x86_64-w64-mingw32/include/float.h to include the right float.h
  4. [optional] Create libmsmpi.a from Microsoft MPI Redistributable
  5. Install the OpenFOAM 2.1.x source distribution on Linux - git commit: 68d39c199c99cda16108ddcf019743d4e6f18854, Date: Wed Jan 9 16:16:53 2013 +0000.
  6. Patch (using the Linux patch command) the OpenFOAM 2.1.x source distribution with our MinGW Windows modifications [last updated May 13, 2013 to v9]
  7. 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"
  8. [optional] Install the ThirdParty-2.1.0 source and build scotch according to:
    1. ln -s ThirdParty-2.1.0 $(WM_THIRD_PARTY_DIR)
    2. ln -s $(WM_THIRD_PARTY_DIR)/scotch<version> $(WM_THIRD_PARTY_DIR)/scotch
    3. ln -s $(WM_PROJECT_DIR)/extra/scotch/src/Make.inc/Makefile.inc.mingw-w64 $(WM_THIRD_PARTY_DIR)/scotch/src/Makefile.inc
    4. cp $(WM_PROJECT_DIR)/extra/scotch/src/libscotch/* $(WM_THIRD_PARTY_DIR)/scotch/src/libscotch/.
    5. cd $(WM_THIRD_PARTY_DIR)/scotch/src
    6. cp $(WM_PROJECT_DIR)/extra/scotch/src/Makefile .
    7. make libscotch
    8. mkdir -p $(FOAM_LIBBIN)
    9. cd $(WM_THIRD_PARTY_DIR)/scotch/src/libscotch
    10. cp libscotch.* $(FOAM_LIBBIN)
  9. To build OpenFOAM:
    1. source the OpenFOAM native linux environment variables
    2. cd $(WM_PROJECT_DIR)/wmake/src; make
    3. ln -s $(WM_PROJECT_DIR)/wmake/platforms/linux64Gcc $(WM_PROJECT_DIR)/wmake/platforms/linux64mingw-w64
    4. source the OpenFOAM MinGW-w64 environment variables
    5. cd $(WM_PROJECT_DIR);./Allwmake
  10. 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
  11. 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

  12. 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).
  13. Launch a Windows command prompt to run OpenFOAM solvers and utilities, such as simpleFoam.exe.

Windows HPC Server 2012

job submit example on Windows HPC Server 2012 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 OpenCFD 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.

Thanks

Yes, That helped.

All the "Allwmake" files need execute permission.Manually executed the following command :
find . -name Allwmake | xargs chmod a+x

Building libscotch

I'm building libscotch on linux platform using the cross-compiler. I run into the following problem :

./dummysizes library.h scotch.h
run-detectors: unable to find an interpreter for ./dummysizes

This is because dummysizes binary is windows binary, and can't be executed on linux platform.
So first I executed the build without mingw to create native dummysizes binary, then all the .o files were bad for mingw, so I executed "make clean" which also removed my native dummysizes binary

What am I doing wrong ?

Delete Scotch Linux object files

After building Scotch for Linux just delete all the object files (rm *.o, i.e., don't use "make clean") and then build for MinGW.

Errors while compiling

Hi everyone,

I did everything from the guide except I'm not building third party sources.

I have some errors I can't resolve. The first error appears at the beginning and the error about missing .H file comes on almost every other file. Does anyone has a clue what could be wrong?

I hope I'm not cluttering the comments, here is the part of the output:

SOURCE=db/IOobject/IOobject.C ; x86_64-w64-mingw32-g++ -m64 -Dlinux64 -DWM_SP -DMSWIN -DLITTLE_ENDIAN -Wall -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -O3 -DNDEBUG -DNoRepository -ftemplate-depth-40 -IMake/linux64mingw-w64SPOpt -IlnInclude -I. -I/home/user1/OpenFOAM/compile/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude -I/home/user1/OpenFOAM/compile/OpenFOAM-2.1.x/src/OSspecific/MSwindows/lnInclude -c $SOURCE -o Make/linux64mingw-w64SPOpt/IOobject.o
db/IOobject/IOobject.C:439:1: error: caller edge frequency 492 does not match BB frequency 1000
}
^
_ZN4Foam6stringC2ERKS0_/2189 (Foam::string::string(const Foam::string&)) @0x2ab4880809c0
Type: function
Visibility: public comdat comdat_group:_ZN4Foam6stringC2ERKS0_ one_only artificial
References:
Referring:
Function Foam::string::string(const Foam::string&)/2189 is inline copy in Foam::word::word(const Foam::word&)/263
Clone of _ZN4Foam6stringC2ERKS0_/255
Availability: local
Function flags: analyzed body local finalized
Called by: _ZN4Foam4wordC1ERKS0_/263 (0.49 per call) (inlined) (can throw external)
Calls: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]/1901 (0.49 per call) (can throw external)
db/IOobject/IOobject.C:439:1: internal compiler error: verify_cgraph_node failed
}
^
Please submit a full bug report,
with preprocessed source if appropriate.
See for instructions.
make: *** [Make/linux64mingw-w64SPOpt/IOobject.o] Error 1
+ wmake all utilities
make[1]: Entering directory `/home/user1/OpenFOAM/compile/OpenFOAM-2.1.x/applications/utilities/mesh'
make[2]: Entering directory `/home/user1/OpenFOAM/compile/OpenFOAM-2.1.x/applications/utilities/mesh/advanced'
make[3]: Entering directory `/home/user1/OpenFOAM/compile/OpenFOAM-2.1.x/applications/utilities/mesh/advanced/PDRMesh'
SOURCE=PDRMesh.C ; x86_64-w64-mingw32-g++ -m64 -Dlinux64 -DWM_SP -DMSWIN -DLITTLE_ENDIAN -Wall -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -O3 -DNDEBUG -DNoRepository -ftemplate-depth-40 -I/home/user1/OpenFOAM/compile/OpenFOAM-2.1.x/src/meshTools/lnInclude -I/home/user1/OpenFOAM/compile/OpenFOAM-2.1.x/src/dynamicMesh/lnInclude -I/home/user1/OpenFOAM/compile/OpenFOAM-2.1.x/src/finiteVolume/lnInclude -IlnInclude -I. -I/home/user1/OpenFOAM/compile/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude -I/home/user1/OpenFOAM/compile/OpenFOAM-2.1.x/src/OSspecific/MSwindows/lnInclude -c $SOURCE -o Make/linux64mingw-w64SPOpt/PDRMesh.o
PDRMesh.C:45:26: fatal error: fvMeshSubset.H: No such file or directory
#include "fvMeshSubset.H"

Only first error is relevant

"db/IOobject/IOobject.C:439:1: error: caller edge frequency 492 does not match BB frequency 1000" - looks like some strange internal compiler error - never seen it before.

I tought so. The first error

I tought so. The first error is something I never saw before.
It is probably related to incompatible latest compiler.

Can you suggest exactly which package version to use?
I used the latest Automated build package. I guess that created errors. It comes with GCC 4.8.0.

Using gcc 4.5.4

x86_64-w64-mingw32-gcc --version
x86_64-w64-mingw32-gcc (GCC) 4.5.4 20110822 (prerelease)

Thanks for your help so

Thanks for your help so far.

I've changed the compiler but for some reason now I'm getting this error. This is the part of the log where the first error occurred:

Making dependency list for source file graph/graph.C
Making dependency list for source file graph/writers/rawGraph/rawGraph.C
Making dependency list for source file graph/writers/gnuplotGraph/gnuplotGraph.C
Making dependency list for source file graph/writers/xmgrGraph/xmgrGraph.C
Making dependency list for source file graph/writers/jplotGraph/jplotGraph.C
Making dependency list for source file meshes/data/data.C

make: *** No rule to make target `meshes/primitiveMesh/primitivePatch/PrimitivePatch.H', needed by `meshes/primitiveMesh/primitivePatch/walkPatch.dep'. Stop.

Then I get other errors ofcourse.

There is no PrimitivePatch.H in primitivePatch folder, but there is one in PrimitivePatch. Notice the change of case.
Anybody has any idea what could be the problem?

Can not run on Windows7 64vit

I have followed the processes described on the page "OpenFOAM 2.1.x on Windows 64-bit with MS MPI" and successfully built *.dll and *.exe files. Then I sent these files to the Windows7 64bit PC to try to execute blockMesh.

But I encountered the problem. The message from Windows7 means "The execution of blockMesh.exe stopped because problem occuured. The program is closed. Windows may tell you how to solve it if there is some solution." But no message come, and there is not any info output. I am not using MS-MPI as I turned off the MPI flag.

How can I solve this problem?
I wonder the binaries built by Mingw + Windows pathces are not configured for Windows7 ?

Thank you for all of your helps.
regards.

Windows 7 64-bit works fine

The binary OpenFOAM executables I have compiled and distribute work fine with Windows 7 64-bit.

Are you sure you've set your Windows environment variables correctly?

I am setting environment variables on Windows7

Thanks a lot, but I am sorry not to reply you soon.

I am setting environment variables on Windows7.
WM_PROJECT_DIR and USERNAME, and PATH for executable and library locations.

I am working on the following Linux cross-compile tools and environments:

- Linux : CentOS 5.3
- mingw :
mingw-w64-1.0-src-_20100208,
mingw-w64-v1.0-snapshot-20100212,
mingw-libgnurx-2.5.1-src.tar.gz,
pexports-0.44-1-mingw32-src.tar.lzma
- gcc version : gcc-4.4.2
- OpenFOAM-2.1.1 (source)
- ThirdParty-2.1.1 (source)
- environment variables
WM_OSTYPE=MSwindows
WM_COMPILER=mingw-w64
WM_ARCH_OPTION=64
WM_PRECISION_OPTION=DP
WM_CC=mingw
WM_CXX=mingw
WM_MPLIB=NONE
foamCompiler=ThirdParty (because installed mingw under ThirdParty)

Please let me know your suggestions.
Thank you.

Review Steps 11 - 12

Your Linux environment variables look reasonable, but what about the environment variables you used on the Windows side (step 12)?

Did the compilation complete without any errors?

Did you transfer the compiler runtime etc. (step 11) over to Windows?

Re : Review Steps 11 - 12

About step12, WM_PROJECT_DIR, USERNAME, and PATH for libs including :
$WM_PROJECT_DIR\\platforms\linux64mingw-w64DPOpt\bin
$WM_PROJECT_DIR\\platforms\linux64mingw-w64DPOpt\lib
$WM_PROJECT_DIR\\platforms\linux64mingw-w64DPOpt\\lib/dummy
$WM_PROJECT_DIR\\platforms\linux64mingw-w64DPOpt\lib/gpuless
are properly set (not using MSMPI).

About compiler error, I found the patch failed in one case in building mingw, so I corrected the problem.
But the problem has not been solved.

About step 11, I do not have
/bin/libgcc_s_sjlj-1.dll
/bin/libstdc++-6.dll
but I have zlib1.dll and libgnurx-0.dll, so I locate then on Windows 7 and set PATH.

I found that ansysToFoam.exe and checkMesh.exe works with no problem on Windows 7.!

The other exes crash with all the same problem such as:
fault module name StackHash_e3f8
fault module version: 6.1.7601.17725
:exception code c0000374

I did same using OpenFOAM-2.1.0, but the same problem occurred.
I guess mingw version I am using is old, so I will try update mingw.
Could you please tell me other suggestions?

Thank you.

Update Compiler

Just to be clear you have to match the exact git commit version for the patch. Assuming you have patched correctly then definitely try updating your compiler.

problem is solved

Thanks your advise.

I updated the MinGW compiler as mingw-w64-v2.0.6 and gcc-4.5.4.
Still the same problem occurred in this case. Execution crashed in Stack Hash, exception code c0000374.

Next I changed the configure option for gcc and rebuild mingw.
I removed the following options which I was using so far:
--enable-fully-dynamic-strings --disable-werror
--disable-win32-registry --disable-shared --enable-sjlj-exceptions \
--enable-threads=win32

Then I recompiled OpenFOAM-2.1.0. At this time, exe files runs fine.
I don't know which option was wrong, but anyway, I can run exe on Windows now.
I will try MSMPI from now.

Thank you.

Hi , I had the same problem

Hi ,
I had the same problem before, and this is how i fix it.
I think the problem is in your file "wmake/rules/linux64mingw-w64/general" ,
add the following :
CPP = x86_64-w64-mingw32-cpp -E -traditional-cpp $(GFLAGS)

and comment :
PROJECT_LIBS = -l$(WM_PROJECT) # -L$(FOAM_LIBBIN)/dummy -lPstream

and add this line :

MKDEP = x86_64-w64-mingw32-g++ -M -I$(*D) $(LIB_HEADER_DIRS)

hope this help.
best regards,

Cherif