CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   including third party GPU library in OpenFOAM (

spelai March 13, 2012 10:39

including third party GPU library in OpenFOAM

this is a slightly convoluted question, but please bear with me.

We have incorporated the OpenMM GPU library ( inside OpenFOAM and are using it to perform Molecular Dynamics force calculations on the GPU. The OpenMM is compiled as a shared library and included in the OpenFOAM MD solver.

OpenMM supports two GPU platforms: CUDA and OpenCL. CUDA is precompiled with a make compiler but OpenCL code gets compiled at runtime. As a consequence, CUDA code runs fine within OpenFOAM, but the OpenCL code crashes.

Unfortunately, we need the OpenCL and we suspect that the problem is due to the difference in compilers. The OpenMM example simulation code uses make and the OpenCL compiled this way works fine. However, when integrated in OpenFOAM, the solver is compiled with wmake and this seems to disagree with the OpenCL code. We have checked all the compiler options but to no avail.

Does anyone have a similar experience with integrating third-party libraries inside OpenFOAM? Would you be able to offer any insight?


chegdan March 13, 2012 13:21


Does anyone have a similar experience with integrating third-party libraries inside OpenFOAM? Would you be able to offer any insight?
A few months ago I had integrated some CUDA into OF and had to achieve this as an extern function while compiling the CUDA separately and then including it in OF compilation. The project is at

the compile script you are interested is in

and the example of the extern function in OF is

extern "C" void CFL_AinvPBiCGStab(cusp_equation_system *CES, OFSolverPerformance *OFSP);//extern function in CUDA that solves the equation system

in the file (

lastly, the definition of the extern function in CUDA is in

Hope that helps.

spelai March 13, 2012 15:35

Hi Dan,

thank you for your reply. I have found the same thing with CUDA - because it can be fully compiled externally, there seems to be no problem with including it in OF - the OF compiler does not need to recompile it while compiling the solver.

With the OpenCL, things seem to be different as you do not compile it externally, it gets compiled at runtime and it is here that I run into problems.

I'll have a look at your CUDA solution and see if I can get any ideas for how to tackle this.


klausb November 2, 2012 06:06

Have a look at clFoam

there has been an OpenCl plugin for OpenFOAM - maybe that helps:

The OpenCL solver plugin : clFoam v0.1 come out for test.

Until now, clFoam single precision has been tested on ATI 5650M GPU and NVidia Tesla C2050. The speed is slightly slower than CPU on Tesla C2050 for 160000 cells of case: cavity 4 times steps (clPCG). (see profilingDatasheet.xls in profiling data/ for details)

The openCL solver is still promising, as it is a new tech and has great space to improve.

download link:

Quite a lot of work to do, any advice on improving the efficiency is appreciated. further, there must be some errors in the manual, DO leave me a email to correct them.

Thanks very much


Qingfeng Xia


Let me know how it works - I'm planning something similar.


All times are GMT -4. The time now is 23:27.