|
[Sponsors] |
April 7, 2017, 03:29 |
Using IPstream and OPstream
|
#1 |
New Member
Roman G.
Join Date: Apr 2017
Posts: 16
Rep Power: 9 |
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; } } |
|
|
|
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 |