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

Sending a large bufffer between processes (with Pstream?)

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 11, 2016, 13:50
Default Sending a large bufffer between processes (with Pstream?)
  #1
Member
 
Join Date: Aug 2015
Posts: 37
Rep Power: 11
knuckles is on a distinguished road
I'm implementing an algorithm which requires that I trade large amounts of data between neighbouring processes at each time step - something on the order of thousands of doubles. My understanding is that the ideal way of doing this is with one large transfer, as this should be much faster than many small ones. In MPI, I would build up a buffer on the sending process and then transfer the data all at once. In OpenFOAM, most things seem to be done using Pstream, but I haven't found documentation explaining the extent to which Pstream is buffered.

For my interest, I'm wondering:
  1. Is a blocking Pstream buffered? Would "myBlockingPstream << 1 << 2;" result in two separate transfers of one int, rather than one transfer of two ints?
  2. In normal operation, will a non-blocking Pstream send as soon as it can, or wait until it has to (full buffer/"wait for all transfers" command encountered)?
More importantly: for the task at hand, I'm wondering:
  • Is there a way of loading a large amount of data into a Pstream's buffer and guaranteeing that none of it will be transferred until I say so?
  • Is there a different or better way of transferring large chunks of data in a single operation within OpenFOAM?
knuckles is offline   Reply With Quote

Old   January 11, 2016, 14:34
Default
  #2
Senior Member
 
mkraposhin's Avatar
 
Matvey Kraposhin
Join Date: Mar 2009
Location: Moscow, Russian Federation
Posts: 355
Rep Power: 21
mkraposhin is on a distinguished road
Quote:
Originally Posted by knuckles View Post
  • Is there a different or better way of transferring large chunks of data in a single operation within OpenFOAM?
Hi, i'm not sure that this way is best, but it guarantee simultaneous transfer of data as one transaction.
You must use functions IPstream::read and IPstream::write.
For example, to read data on master from slave
Code:
scalarList arrayToRead (10);
label nPoints = arrayToRead.size();
IPstream::read(Pstream::scheduled, jSlave, reinterpret_cast<char*>(&arrayToRead[0]), nPoints*sizeof(scalar),
			    UPstream::msgType(), UPstream::worldComm)
And to write data from slave to master
Code:
scalarList arrayToWrite (10);
label nPoints = arrayToWrite.size();
OPstream::write(Pstream::scheduled, Pstream::masterNo(), reinterpret_cast<char*>(&(arrayToWrite[0])), nPoints*sizeof(scalar),
			UPstream::msgType(), UPstream::worldComm);

Last edited by mkraposhin; January 11, 2016 at 16:35.
mkraposhin is offline   Reply With Quote

Old   January 11, 2016, 15:52
Default
  #3
Member
 
Join Date: Aug 2015
Posts: 37
Rep Power: 11
knuckles is on a distinguished road
Thanks for the prompt reply, mkraposhin!

This approach looks good to me. It seems to me that it's actually better than what I was originally suggesting, because you've eliminated the unnecessary step of copying the data from my external buffer into the buffer of a Pstream object for transferring.

Two questions about your solution:
  • Am I correct in thinking that there's a typo in the first part - the buffer name changed from arrayToRead (at declaration) to arrayToSend (at use)?
  • I notice that you asked for "scheduled" communication rather than "blocking." What is the difference, and why did you choose scheduled?
knuckles is offline   Reply With Quote

Old   January 11, 2016, 16:35
Default
  #4
Senior Member
 
mkraposhin's Avatar
 
Matvey Kraposhin
Join Date: Mar 2009
Location: Moscow, Russian Federation
Posts: 355
Rep Power: 21
mkraposhin is on a distinguished road
Quote:
Originally Posted by knuckles View Post
  • Am I correct in thinking that there's a typo in the first part - the buffer name changed from arrayToRead (at declaration) to arrayToSend (at use)?
Yes, you are right. I'll try to correct my mistake

Quote:
Originally Posted by knuckles View Post
  • I notice that you asked for "scheduled" communication rather than "blocking." What is the difference, and why did you choose scheduled?
Actually, i'm not a professional in MPI, and this communication settings were suggested by my colleague from IT department.
I'll ask him for explanation tomorrow.

If you will find answer before me, can you be so kind to enlighten me?
mkraposhin is offline   Reply With Quote

Old   January 11, 2016, 20:55
Default
  #5
Member
 
Join Date: Aug 2015
Posts: 37
Rep Power: 11
knuckles is on a distinguished road
Thanks!

Do you happen to know whether there is a readWrite() function, for if I wanted to fully trade the data (master sends to slave and slave sends to master in one call)?
knuckles is offline   Reply With Quote

Reply

Tags
pstream


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
big difference between clockTime and executionTime LM4112 OpenFOAM Running, Solving & CFD 21 February 15, 2019 04:05
foam-extend-3.2 Pstream: "MPI_ABORT was invoked" craven.brent OpenFOAM Running, Solving & CFD 5 November 18, 2015 08:55
MPI problmes sharonyue OpenFOAM 11 December 28, 2012 05:40
Large Epsilon 3D lepsilon Main CFD Forum 0 July 10, 2012 11:43


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