while and for "loops" in parallel computing
Goodmoring this is my first thread.
I'm quite new in OpenFoam (I'm working on it since last month and I come from "Fortran" so C++ and OpenFoam at the same time in 1month are a big challenge for me so i apologize if I ask trivial things!
So I describe my problem: I'm solving a coupled solidification problem so at each step in time I have:
the resolution of NS equation (piso scheme)
the resolution of Temperature (energy) equation (Voller T-gl coupling)
and the solute transfer one
the equations are coupled so some inner loops are performed at each time step in order to be consistent.
I developed it and it work in "serial". now when I try to parallelize it I've a problem on a loop I do in order to calculate a residual "res_T"
for ( int ifield = 0 ; ifield < H.size() ; ifield++ )
// Info<< H.size() << endl;
the probem is that the "while" condition doesn't work in parallel (in serial it does).
So I tried to printout H.size that in serial gives me 3000 cause I've a 50X60 2D domain
and on 8 CPUs I've the 390 value (interal plus "shared" interface cells for each part the domain is subdivided in I guess).
If I replace this kind of while with a fake "for" where I perform 10 iterations (just to be sure the coupling is done) the code works well and the results are good (I've the serial version for comparison).
SO, please, can someone explain me if there is an error (sure there is!) in what I'm writing and how I've to redefine a "parallel" working while-for loop?
Thank you in advance (and remember I'm a newbie in C++ so be kind!)
as i know "while" is not suitable for parallel processing , because when you define "while" you have a condition which should be check in every iteration so in "while" there is no definite numbers of iteration but in parallel processing you give a definite numbers of iteration to several threads to do it simultaneously and independently.
so you should use "for" but increase ur iteration number to reach that condition!
Anyway from a logical point of view I still guess that doing a "while" is possibile in theory. You just calculate res_T on each subdomain and after that you sum them and you have the final res_T that is "global" and you perform the test.Otherwhise I guess there is the possibility to "recompose" the field afer the solution od the equation and perform the for loop on the global field directly.
I'm reading and looking at the same time to the openfoam (icofoam as an exemple) sources in order to understand the right way to do that!
Thank you again. if I find something (as long that my C++ training continues) I'll reply to you.
And otherwise you can do something like this:
By the way, a more convenient way to loop in OpenFOAM is using the forAll loop, nearly anything that you ever want to loop about as an argument. So you don't have to worry about the amount of elements in this argument.
By the way, I advise you to construct your solver in a different way. You can set the residual control in fvSolution then.
Have you solved the problem? Can you share the code ?
|All times are GMT -4. The time now is 06:09.|