|
[Sponsors] |
January 23, 2015, 09:39 |
parallel programming issues
|
#1 |
New Member
Theodore S. Richfield
Join Date: Jan 2015
Location: germany
Posts: 3
Rep Power: 11 |
Dear All,
in the course of a university project we are trying to adapt the basic simpleFoam solver to our needs by adding some lines of code. Everything works fine performing single core, but as soon as we go parallel, we encountered problems. Right before the simple algorithm we perform a loop over all cells, where the elements of vector A are initialized with the average of vector B, using something like... Code:
forAll(mesh.cells(), i) { A[i] = B.average().value(); ... } Code:
temp=B.average().value(); forAll(mesh.cells(), i) { A[i] = tmp; ... } Furthermore, we thought, that as with 'conventional' MPI parallelization we know from pure C programming, we used mpi_reduce statements to sum up and count, and calculate an average of a quantity over all workers. Please, could someone point us in the right direction in the context of C++ & OpenFOAM programming, since we are "just beginners" We are already struggling with getting some debug information from each worker, i.e. how can we put something like Code:
Info << "worker no. " << i << " | value = " << v << endl; We've checked the manuals and tutorials available throughout the internet, but ... Is there any good programming tutorial focusing on parallel? We would be grateful for your feedback, Kind Regards, George |
|
January 24, 2015, 09:38 |
|
#2 |
Senior Member
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 21 |
A very incomplete answer, but this is what I know:
The following statement I use for parallel debugging (that way, each processor shows its own message with the processor ID appended): Code:
Sout << "[" << Pstream::myProcNo() << "] " << "Debug message" << nl; Last edited by floquation; January 24, 2015 at 14:05. |
|
January 25, 2015, 09:48 |
|
#3 |
New Member
Theodore S. Richfield
Join Date: Jan 2015
Location: germany
Posts: 3
Rep Power: 11 |
Thanks a lot floquation!
In the meantime I also found that Code:
Sout Code:
.average() Code:
gaverage Code:
mpi_reduce However, I still don't understand, what is the difference between using the average method inside the 'forall' scope or outside? Well, my code does it's job right now, but I'm really interested in what is going on behind the scenes!? Please, if anyone can put a light on this, I would be grateful! Cheers, George BTW: Could anyone provide me a link on a more comprehensive programming guideline (sorry, even though I do programming for a while, I'm an engineer and not an IT specialist) that goes a bit further than the official OF programming guide, and which provides a clarifying picture of the underlying structure and hierarchy of OF? |
|
January 29, 2015, 05:39 |
|
#4 |
Senior Member
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 22 |
Why do you call B.average() inside the loop? It looks like it is not depending on i (or the cell), so you are calculating the same value again and again. Can't you put it into a temporary variable defined before the loop? (Ok, the compiler might be optimizing it this way, but who knows?)
|
|
January 29, 2015, 05:58 |
|
#5 |
New Member
Theodore S. Richfield
Join Date: Jan 2015
Location: germany
Posts: 3
Rep Power: 11 |
Hi jherb,
indeed, you#re right, and that's what I already did (cf. my first post). But, even though it will be optimized by either the compiler (if...) or by developer (if she is aware of it...), it is not clear for me, why we receive an mpi_error in the first case (average in loop)... So finally, it is clear, that one should keep the calculation of a non-changing value outside of the loop with respect to performance (regardless of compiler optimization), but with regards to efficiently do parallel programming in openFoam, we'd like to know more about the source of the problem. Kind Regards, George |
|
January 29, 2015, 19:08 |
|
#6 |
Senior Member
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 22 |
The gaverage function (see also e.g. the gSum function) automatically reduce the results from all CPUs, i.e. collect the results from all CPUs and does the averaging. Then the result is sent to all CPUs.
Just speculating, but I think the call to such a reducing function has to be called on all CPUs at the same point in the code. But the loop of the mesh cells is for different cells on the different CPUs. So if there are different number of cells on different CPUs this sounds like trouble |
|
Tags |
mpi, parallel |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
simpleFoam parallel | AndrewMortimer | OpenFOAM Running, Solving & CFD | 12 | August 7, 2015 19:45 |
FE-3.1 Parallel issues with BCs (gMax, reduce...) | Phicau | OpenFOAM Bugs | 2 | August 1, 2014 07:22 |
How can i make a parallel programming in OpenFOAM? | jignesh_thaker2007 | OpenFOAM Running, Solving & CFD | 3 | July 2, 2014 10:37 |
Installation issues for parallel computation | Akash C | SU2 Installation | 1 | June 21, 2013 06:26 |
PROBLEM IN PARALLEL PROGRAMMING WITH MPI | Niavarani | Main CFD Forum | 1 | April 20, 2004 07:51 |