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

Code parallelization using Pstream: simultaneous send/receive deadlocking

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By wyldckat

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 9, 2012, 06:14
Question Code parallelization using Pstream: simultaneous send/receive deadlocking
  #1
Senior Member
 
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21
tomislav_maric is on a distinguished road
Hi everyone,

I am trying to write the simplest parallel code that involves simultaneous communication accross processes:

Proc1: Send(0),Receive(0)

Proc2: Send(1),Receive(1)

Of course, such code will experience a deadlock. There are multiple solutions for this beginner problem: exchanging the order of Send/Receive based on the process rank, using non-blocking communication, using buffered communication (bSend, bRecv), etc.

Both the problem and possible solutions are explained here (Note: if the links don't work by clicking, copy/paste them):

http://www.ncsa.illinois.edu/UserInf...IDeadlock.html

and here:

http://www.cs.ucsb.edu/~hnielsen/cs140/mpi-deadlocks.html

So. I have tried to use these solutions in OpenFOAM, sending/receiving a scalarField around, and I keep getting errors. I linked the application source below, where you can uncomment parts of the code to get specific solutions (described in the links above). What I find strange is:

  • the code deadlocks when I properly combine blocking send/receive and receive/send
  • the code experiences FoamFatalError when I use nonBlocking communication: UPstream::waitRequests() is an empty function, Pstream::nRequests() returns 0 regardless of the number of outstanding nonBlocking requests in the program


I am not sure if I am missing something obvious, but it seems strange that every option I try, fails.


Also: I've switched on the Pstream debugSwitch in etc/controlDict, but I still don't see the debug info comming from the UPstream.C in the Pstream/mpi folder. This looks like my application is using the dummy implementation of UPstream and its children, instead of linking with stuff from Pstream/mpi.



Download link (OpenFOAM 2.0.x):


http://dl.dropbox.com/u/3316983/pStr...leExchange.tgz


Tomislav

Last edited by tomislav_maric; July 9, 2012 at 06:31.
tomislav_maric is offline   Reply With Quote

Old   July 13, 2012, 04:47
Default
  #2
Senior Member
 
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21
tomislav_maric is on a distinguished road
(bump)

O.K. , let me rephrase the question: there are two processes available.

How do I use Pstream to exchange the number Pstream::myProcNo() between the processes without deadlocking?
tomislav_maric is offline   Reply With Quote

Old   July 13, 2012, 05:14
Default
  #3
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Greetings Tomislav,

Have you looked at the source code for the OpenFOAM application Test-parallel? It's located at "applications/test/parallel".
It's a very decent example of what you seem to be trying to do!

Browse the other applications in the test folder as well, because I remember there are other very sweet examples of parallel manipulations!

Good luck!
Bruno
tomislav_maric and scleakey like this.
__________________
wyldckat is offline   Reply With Quote

Old   July 13, 2012, 05:16
Default
  #4
Senior Member
 
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21
tomislav_maric is on a distinguished road
Thanks, I'm on it!
tomislav_maric is offline   Reply With Quote

Old   July 13, 2012, 05:20
Default
  #5
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 29
akidess will become famous soon enough
What went wrong with the ucsb solution? It seems brilliantly simple...

Code:
if (rank % 2) {
    MPI_Send(data, (rank + 1) % size);
    MPI_Recv(newdata, (rank - 1) % size);
} else {
    MPI_Recv(newdata, (rank - 1) % size);
    MPI_Send(data, (rank + 1) % size);
}
__________________
*On twitter @akidTwit
*Spend as much time formulating your questions as you expect people to spend on their answer.
akidess is offline   Reply With Quote

Old   July 13, 2012, 05:22
Default
  #6
Senior Member
 
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21
tomislav_maric is on a distinguished road
Quote:
Originally Posted by akidess View Post
What went wrong with the ucsb solution? It seems brilliantly simple...

Code:
if (rank % 2) {
    MPI_Send(data, (rank + 1) % size);
    MPI_Recv(newdata, (rank - 1) % size);
} else {
    MPI_Recv(newdata, (rank - 1) % size);
    MPI_Send(data, (rank + 1) % size);
}
Well, when you try this with Pstream, the thing just hangs in the air... If you don't believe me, uncomment SOLUTION 0 in the source I linked below... it's just weird.

Added: I wrote it for just 2 processes: 0 is sending/receiving to/from 1, and 1 is sending/receiving to/from 0.
tomislav_maric is offline   Reply With Quote

Old   April 8, 2023, 09:06
Default
  #7
New Member
 
Karl Sturm
Join Date: Apr 2023
Posts: 2
Rep Power: 0
sturmk is on a distinguished road
Quote:
Originally Posted by tomislav_maric View Post
Well, when you try this with Pstream, the thing just hangs in the air... If you don't believe me, uncomment SOLUTION 0 in the source I linked below... it's just weird.

Added: I wrote it for just 2 processes: 0 is sending/receiving to/from 1, and 1 is sending/receiving to/from 0.

Sorry to dig this post up one decade later, but the problem still persists today (OpenFoam v9).

I hope this reaches some of the OF devs by bringing it up again...
sturmk is offline   Reply With Quote

Old   April 8, 2023, 10:26
Default
  #8
New Member
 
Karl Sturm
Join Date: Apr 2023
Posts: 2
Rep Power: 0
sturmk is on a distinguished road
Since the abovementioned might be a roadblocker, here's a workaround:
Code:
if(isPrimaryNode()) {
     IPstream *recv = new IPstream(Pstream::commsTypes::blocking,
                                                   secondaryNodeNo());
     *recv >> remote_data;
     delete recv;
     OPstream *send = new OPstream(Pstream::commsTypes::blocking,
                                                   secondaryNodeNo());
     *send << local_data;
     delete send;
}
if(isSecondaryNode()) {
     OPstream *send = new OPstream(Pstream::commsTypes::blocking,
                                                   primaryNodeNo());
     *send << local_data;
     delete send;
     IPstream *recv = new IPstream(Pstream::commsTypes::blocking,
                                                   primaryNodeNo());
     *recv >> remote_data;
     delete recv;
  }
FYI: I also tried to implement a "proper" solution by allocating a separate communicator and using Pstream::exchange(). Unfortunately, UPstream::allocateCommunicator() is the bad call and blocks indefinitely.
sturmk is offline   Reply With Quote

Old   April 14, 2023, 04:31
Default
  #9
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,684
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
If it is contiguous data, and you know the dimensions, a combination of non-blocking UIPstream::read and UOPstream::write, followed by a UPstream::waitRequests should work.


If you have non-contiguous data and want a whatever to whatever type of exchange. consider using PstreamBuffers. Setup all of your sends on primary/secondary node, mark the sends as finished and then followup with the receives. It is slight overkill since it will use the personalised exchange (involving an all-to-all for distributing sizes) but if not called within a tight loop and with fewer than say 8k ranks, should be OK.
olesen 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
What is the Better Way to Do CFD? John C. Chien Main CFD Forum 54 April 23, 2001 08:10
Open source CFD code development, possible? Dr. Yazid Bindar Main CFD Forum 27 July 18, 2000 00:18
State of the art in CFD technology Juan Carlos GARCIA SALAS Main CFD Forum 39 November 1, 1999 14:34
public CFD Code development Heinz Wilkening Main CFD Forum 38 March 5, 1999 11:44
What kind of Cmmercial CFD code you feel well? Lans Main CFD Forum 13 October 27, 1998 10:20


All times are GMT -4. The time now is 00:01.