This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Is there any difference between a C++ application in FEniCS and a Python application in FEniCS?

0 votes

I am looking to use FEniCS for some of my flow and transport research - and I have explored many of FEniCS' capabilities and find them to my liking.

I had one question about the C++ and the Python interfaces though. I am wondering whether there is any difference in performance when I write a FEniCS application for a problem using the C++ interface as compared to the Python interface. I am looking to run applications that involve large numbers of degrees of freedom, and that involve running these applications in parallel.

For example, the Navier-Stokes demo - when implemented using the C++ interface (using .ufl and .cc files) and the Python interface (using one .py file) - do these implementations have any difference in performance or capabilities ?

Any pointers or suggestions will be very valuable.

asked Sep 5, 2014 by debmukh FEniCS Novice (880 points)

1 Answer

0 votes

In practice, the c++ interface can produce faster code, but it is very much dependent on what you are doing. In parallel, thr mesh partitioning and linear algebra, for example, will take the same time in python and c++ as they are both external library functions.
Some operations, e.g. setting BCs, can be slow in python. Python itself can be slow to load.

On the other hand python is very useful for quick prototyping.

answered Sep 6, 2014 by chris_richardson FEniCS Expert (31,740 points)

Thanks for the response !

Being a newcomer to FEniCS - I was just wondering then whether all of C++ library functions/capabilities are accessible through Python ?

Furthermore, for time-varying problems, does Python load the compiler for compiling code every time-step ? or does it invoke it only once ?

Pardon if the questions sound too basic.
I think I am gradually getting up to speed with the capabilities - but, I still have these few questions about the general operation of the FEniCS tool.

Thanks a lot again for the help.

Almost everything is available via python. Python caches the JIT compiled modules, so your time-dependent problems don't have to keep recompiling (unless you change your equations).
Minor changes, such as coefficients, can be accommodated without recompilng.

Your best way forward is to try out some of the demos in the demo folder. There are C++ and python examples, so you can try it out for yourself.

...