|
[Sponsors] |
April 21, 2014, 17:59 |
Parallelizing nested loops
|
#1 |
Member
Join Date: Feb 2012
Posts: 49
Rep Power: 14 |
I've modified a solver by writing some triple nested loops which works fine for serial case, but not for parallel case.
In my 'for loops', i get information from different meshes and modify volVectorFields and also some user-defined vectorFields(All are in different decomposed domains). Anybody knows how to parallelize these kinds of code? I bring some simplified example of my code: Code:
for (int n=0; n<10; ++n){ for (int i=0; i<2000; ++i){ forAll(U, cellI){ double xd = points[i].x() - mesh.C()[cellI].x() ; // points[] contains coordinates in different decomposed domains if (xd>1) fx= 2222; userVec[i] += fx*U[cellI]; U[cellI] = i*2; } userVec[i] = userVec[i] / 2 ; } } Last edited by ooo; May 6, 2014 at 09:00. |
|
May 6, 2014, 07:21 |
|
#2 |
Member
Join Date: Feb 2012
Posts: 49
Rep Power: 14 |
Any idea?
If it was only a c++ code, i should have split all the for loops according the number of ranks. But maybe using forAll, would be generic enough to split the loops. But still two questions remain. 1) What should i do When i need to access the value of my user-defined vectorFields(or a volVectorField), in different sub domains... 2) The dependency of a value to the previously stored value in the nested for loop i.e: userVec[i] += ... ; I would appreciate any hint. Last edited by ooo; May 6, 2014 at 11:28. |
|
June 26, 2014, 04:50 |
|
#3 |
Senior Member
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 21 |
If you haven't found out by ourself: You can share data between different processes in OpenFOAM using Pstream::scatter and its variation.
So you would probably want to first scatter your userVec then do the calculations on each partition (aka process) and then collect the results of all processes on the master (see Pstream::master()) and then sum them all up. Also have a look at OpenFOAM functions like gSum. |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Timescale vs Iteration loops for Transient Turbomachinery | aerost | CFX | 2 | October 20, 2013 19:59 |
AMI Motions: Ramped Rotation Speeds and Nested Sliding Interfaces | lordvon | OpenFOAM Programming & Development | 0 | September 24, 2013 01:30 |
how to program two independent time loops | ziemowitzima | OpenFOAM Programming & Development | 7 | January 26, 2013 09:39 |
Coefficient loops vs physical timescale | Turbomachine | CFX | 3 | February 13, 2011 19:36 |
5.7.1 solver doing max coeff loops. | Stevie Wonder | CFX | 5 | July 5, 2005 12:31 |