CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How to call external function in parallel (https://www.cfd-online.com/Forums/openfoam-programming-development/173269-how-call-external-function-parallel.html)

t.oliveira June 16, 2016 09:39

How to call external function in parallel
 
Dear foamers,

I added to a solver a call to an external function after the transport problem is solved, as the code below summarizes.

Now, I would like to make the loop between stars (***) parallel.

Could you please advise me on that? After reading many docs and posts, I still couldn't do it.

Code:

int main(int argc, char *argv[])
{
  [...]
    while (simple.loop())
    {
        [...]       
        Solution of a scalar convection-diffusion problem on a given velocity field.     
        [...]
       
        // *** parallelize this loop
        forAll (mesh.cells(), cellI)    <= Lines I added (along with the
        {                              <= appropriate declarations and definitions).
            myFunc(states[cellI]);      <= states is an object of a class from
        }                              <= an external library.
        // *** end of parallel loop

        runTime.write();
    }
    Info<< "End\n" << endl;
    return 0;
}

Best wishes,
Thomas

marupio June 16, 2016 13:42

I'm not sure I understand. How is this not parallel? When running a parallel simulation, there are nProcs processes executing simultaneously. Each processor will do their own forAll(mesh.cells()) loop, and each one will execute myFunc for each cell on their own memory space.

What is not working?

t.oliveira July 16, 2019 15:10

Dear David,

Thank you for your reply. At that time, I was still new to OpenFOAM. I was running OpenFOAM in serial mode, and wanted to parallelize only the call to the function. After I understood how OpenFOAM runs in parallel, this question lost most of its significance.


All times are GMT -4. The time now is 06:00.