Using IPstream and OPstream
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; } } |
All times are GMT -4. The time now is 11:24. |