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

Combining Lists distributed amongst processors

Register Blogs Community New Posts Updated Threads Search

Like Tree7Likes
  • 7 Post By l_r_mcglashan

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 23, 2010, 14:06
Default Combining Lists distributed amongst processors
  #1
Member
 
Matthew J. Churchfield
Join Date: Nov 2009
Location: Boulder, Colorado, USA
Posts: 49
Rep Power: 19
mchurchf is on a distinguished road
Hello,

I have set up a piece of code which searches my mesh for all the different distinct heights of cell centers. It is a simple block shaped mesh in which each layer is at a different height, so if there are 20 cells in the vertical direction then the list of heights is 20 elements long.

This works fine in serial. What I would like to do is extend this to parallel such that at the end of the search, each processor has a global list of distinct heights.

Is there a way to take each list of heights that each processor creates, collect them on the master processor, combine them into one global list, and give the global list back to each processor?

Thank you,

Matt
mchurchf is offline   Reply With Quote

Old   June 24, 2010, 06:35
Default
  #2
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23
l_r_mcglashan will become famous soon enough
Yes, I've done something really similar with lagrangian flamelets. The code is a mess but I can tidy it up and post it up if you like. Otherwise the outline of the approach I took is below:

Create a vector of stuff on each processor:

Code:
for(int i=0;i<mesh_.nCells();++i)
{
        stuff.push_back(mesh_.C().internalField()[i].component(heightDirection));
}
Then gather each list onto the master processor:

Code:
// Create lists of the variables on each processor so that they can be
// gathered onto the master processor later.
List<scalar> stuffList(stuff.size());

// Populate the above lists.
for(unsigned int I=0; I<someSize.size(); ++I)
{
    stuffList[I] = stuff[I];
}

// Create lists of the lists of the above variables, with size equal to the
// number of processors.
List< List<scalar> > gatheredStuff(Pstream::nProcs());

//  Populate and gather the stuff onto the master processor.
gatheredStuff[Pstream::myProcNo()] = stuffList;
Pstream::gatherList(gatheredStuff);
You can then go through vectors in a manner such as given below to get unique heights:

Code:
for(unsigned int i=0;i<stuff.size();++i)
{
        std::sort(stuff.begin(), stuff.end());
        stuff.erase(std::unique(stuff.begin(), stuff.end(), equalToTolerance), stuff.end());
}
You can then scatter a list onto each processor using either Pstream::scatterList or Pstream::listCombineScatter, depending on what you want to do.
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   June 25, 2010, 10:48
Default
  #3
Member
 
Matthew J. Churchfield
Join Date: Nov 2009
Location: Boulder, Colorado, USA
Posts: 49
Rep Power: 19
mchurchf is on a distinguished road
Laurence,

Thanks for the reply. It worked well!

Matt Churchfield
mchurchf is offline   Reply With Quote

Old   February 4, 2020, 12:07
Default
  #4
Member
 
David Andersson
Join Date: Oct 2019
Posts: 46
Rep Power: 7
sippanspojk is on a distinguished road
Quote:
Originally Posted by l_r_mcglashan View Post
Yes, I've done something really similar with lagrangian flamelets. The code is a mess but I can tidy it up and post it up if you like. Otherwise the outline of the approach I took is below:

Create a vector of stuff on each processor:

Code:
for(int i=0;i<mesh_.nCells();++i)
{
        stuff.push_back(mesh_.C().internalField()[i].component(heightDirection));
}
Then gather each list onto the master processor:

Code:
// Create lists of the variables on each processor so that they can be
// gathered onto the master processor later.
List<scalar> stuffList(stuff.size());

// Populate the above lists.
for(unsigned int I=0; I<someSize.size(); ++I)
{
    stuffList[I] = stuff[I];
}

// Create lists of the lists of the above variables, with size equal to the
// number of processors.
List< List<scalar> > gatheredStuff(Pstream::nProcs());

//  Populate and gather the stuff onto the master processor.
gatheredStuff[Pstream::myProcNo()] = stuffList;
Pstream::gatherList(gatheredStuff);
You can then go through vectors in a manner such as given below to get unique heights:

Code:
for(unsigned int i=0;i<stuff.size();++i)
{
        std::sort(stuff.begin(), stuff.end());
        stuff.erase(std::unique(stuff.begin(), stuff.end(), equalToTolerance), stuff.end());
}
You can then scatter a list onto each processor using either Pstream::scatterList or Pstream::listCombineScatter, depending on what you want to do.
Hi Laurence,

I am having a similar problem as Matthew had - I have written a function object that works perfectly in series and now I want to expand it to also work in parallel, but I have a hard time understanding how I should do it.

I've based my function on the "forces" function object and there they use:
Code:
    Pstream::listCombineGather(force_, plusEqOp<vectorField>());
    Pstream::listCombineScatter(force_);
I thought I should do something similar but I don't get how...

I would really appreciate your help on this.

Thanks,
David
sippanspojk is offline   Reply With Quote

Reply


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
HP MPI warning...Distributed parallel processing Peter CFX 10 May 14, 2011 07:17
polyhedral mesh with multiple processors user1 Siemens 7 August 22, 2008 11:59
Firewall settings bproc distributed file syntax mike_jaworski OpenFOAM 2 January 14, 2008 11:46
Parallel Computing on Multi-Core Processors Upgrading Hardware CFX 6 June 7, 2007 16:54
64-bit processors for home computing Ananda Himansu Main CFD Forum 2 March 16, 2004 13:48


All times are GMT -4. The time now is 19:02.