Greetings everyone,
I have two questions:
The first question is: Is it possible for a plug-in to specifically evaluate the solver’s source term?
My second question: by default, plug-ins are executed as Python code; is it possible to execute them as standard C++ code? This way it can be faster.
Appreciate any advice!
You would probably have to do a bit of leg work to read in the source terms from the config file and evaluate the expressions. But this sort of thing is done pretty commonly in the plugins, for example in the time averager or ascent plugin.
To the best of my knowledge you can’t call C++ functions from python, but you can call c functions. This is exactly what I did in the Ascent plugin so that might be a good place to start. (Actually Ascent is written in C++ but they provide a C API which is what I called).
However, I would ask why you are worried about the performance of a plugin? Typically they aren’t run very often, at least that is the ethos they are designed with, and so performance isn’t normally that big of an issue.
Actually, my plug-in evaluates a body force that I use as the source term in a solver.
I initially started with MAKO based code however, later on, I found that that my body force algorithm may not be suitable to get executed on gpu as pointwise kernel.
Nevertheless I would like for the remainder of the code to be executed on the GPU.
So I created the body force term as a plug-in because it is fairly easy to code and debug and it worked but since it runs on python there is a lot to be desired regarding the performance ( as you mentioned plugins are not built for performance)
I understand that it might not have been the best idea, but surprisingly enough it worked.
So right now I would like for my plug-in to interact with the solver to supply it with the source term that it needs, and next, I am hoping to port that code as C or C++, so that it runs efficiently.
I would first look and see how much of the time is being spent copying the data from the GPU back to the host. If this is significant then there may not be a lot gained from rewriting in C.
Well I have not measured the transfer time but technically I only need to copy selected cells of one of the variables from gpu to cpu and then after calculating the body force term copy it back to gpu.
also this body force term has non zero values at certain region of domain ( 10-20% of the domain cells) while the rest is zero for the entire unsteady simulation.
So setting forces this way may not be appropriate since plugins run at most once every time step, whereas for forces you really want something which runs at every RK stage.