CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Parallelizing nested loops

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By jherb

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 21, 2014, 17:59
Default Parallelizing nested loops
  #1
ooo
Member
 
Join Date: Feb 2012
Posts: 49
Rep Power: 14
ooo is on a distinguished road
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 ;
}
}
I would appreciate any hint.

Last edited by ooo; May 6, 2014 at 09:00.
ooo is offline   Reply With Quote

Old   May 6, 2014, 07:21
Default
  #2
ooo
Member
 
Join Date: Feb 2012
Posts: 49
Rep Power: 14
ooo is on a distinguished road
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.
ooo is offline   Reply With Quote

Old   June 26, 2014, 04:50
Default
  #3
Senior Member
 
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 21
jherb is on a distinguished road
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.
ooo likes this.
jherb is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


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