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

Using IPstream and OPstream

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 7, 2017, 03:29
Default Using IPstream and OPstream
  #1
New Member
 
Roman G.
Join Date: Apr 2017
Posts: 16
Rep Power: 9
Novel is on a distinguished road
Hello cfd-online community,
my name is Roman I'm new to this forum; right now I'm working on my Master thesis which involves some parallel programming in OpenFoam. I'm used to program with MPI but struggling a little bit with the Pstream lib. My problem is the following I just try to exchange some fields between the processes but when running the code bellow a deadlock occurs. So the idea is, if we have 4 processes, process 0 receives from process 3 and sends to process 1, process 1 recieves from process 0 and sends to process 2 and so on... With MPI I could just use MPI_Sendrecv_replace. Would be nice if someone could give me a hint or maybe a samplecode where OPstream and IPstream is used.

Thanks in advance.

Roman

const int nProcs = UPstream::nProcs();

const int sendToProc = (Pstream::UPstream::myProcNo() + 1) % nProcs;
const int recFromProc = (Pstream::UPstream::myProcNo() + nProcs - 1) % nProcs;
vectorField cellNeighCenters = cellCenters;
vectorField jV = J*cellVolumes;

Field<vector> recvBuffer(J.size());

for( int i = 0; i < nProcs;i++ )
{

//////////
....
.... Some computations
....
/////////

if ( Pstream::UPstream::myProcNo() % 2 == 0 )
{

OPstream sendStream
(
Pstream::blocking,
sendToProc,
sizeof(jV)
);

sendStream << jV << endl;
sendStream << cellNeighCenters << endl;

IPstream recieveStream
(
Pstream::blocking,
recFromProc,
sizeof(jV)
);

recieveStream >> recvBuffer;
jV = recvBuffer;

recieveStream >> recvBuffer;
cellNeighCenters = recvBuffer;
}
else
{
IPstream recieveStream
(
Pstream::blocking,
recFromProc,
sizeof(jV)
);

recieveStream >> recvBuffer;
jV = recvBuffer;

recieveStream >> recvBuffer;
cellNeighCenters = recvBuffer;

OPstream sendStream
(
Pstream::blocking,
sendToProc,
sizeof(jV)
);

sendStream << jV << endl;
sendStream << cellNeighCenters << endl;
}
}
Novel 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
OpenFOAM updates vaina74 OpenFOAM Installation 22 January 20, 2011 23:16
openfoam 1.6 on debian etch romant OpenFOAM Installation 9 May 6, 2010 02:26


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