|
[Sponsors] |
March 25, 2022, 05:09 |
Print information in processor sequentially
|
#1 |
New Member
Join Date: Dec 2021
Posts: 23
Rep Power: 4 |
Hello to all,
How can one print the information in a processor sequentially? Let us assume: Code:
const volVectorField& C = mesh.C(); If I do: Code:
Pout << C << endl; |
|
March 25, 2022, 06:47 |
|
#2 |
Senior Member
|
Wrap below in loop over processor id?
Code:
// retrieve processor ID label n=Pstream::nProcs(); printf(' my processor id = %d\n', n); // print data on a given processor ID only as a first test if (n==1) { // print statement goes here } } |
|
March 26, 2022, 11:43 |
|
#3 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,686
Rep Power: 40 |
If you want it completely sorted, you will need to serialize this yourself. That means that on the master process first print its values, then loop over the remaining number of processes, receiving and writing their values. On the non-master processes, they send their contents to the master.
For example, https://develop.openfoam.com/Develop...mplates.C#L186 |
|
March 26, 2022, 11:45 |
|
#4 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,686
Rep Power: 40 |
||
March 26, 2022, 14:14 |
|
#5 |
Senior Member
Herpes Free Engineer
Join Date: Sep 2019
Location: The Home Under The Ground with the Lost Boys
Posts: 932
Rep Power: 12 |
Unless I misunderstood your question, I sometimes do the following to group few things (not tested, and it should not resolve the sequential issue - see Mark's comment - yet still might be useful to print a specific processor field):
Code:
// a geometric field from upstream, say U (velocity field) // or some other parallelised object if (Pstream::parRun()) { for (label i = 0; i < Pstream::nProcs(); ++i) { if (i == Pstream::myProcNo()) // if ( i == 2) { for (const auto& u : U) { Sout<< u << nl; // or Pout << ... } Sout<< endl; // or Sout << U << endl; } } } else { for (const auto& u : U) { Info<< u << nl; } Info<< endl; }
__________________
The OpenFOAM community is the biggest contributor to OpenFOAM: User guide/Wiki-1/Wiki-2/Code guide/Code Wiki/Journal Nilsson/Guerrero/Holzinger/Holzmann/Nagy/Santos/Nozaki/Jasak/Primer Governance Bugs/Features: OpenFOAM (ESI-OpenCFD-Trademark) Bugs/Features: FOAM-Extend (Wikki-FSB) Bugs: OpenFOAM.org How to create a MWE New: Forkable OpenFOAM mirror |
|
March 28, 2022, 04:51 |
|
#6 |
New Member
Join Date: Dec 2021
Posts: 23
Rep Power: 4 |
Hello to all and thank you for your input.
For my application this sufficed: Code:
for (label i = 0; i < Pstream::nProcs(); ++i) if (i == Pstream::myProcNo()) { // Loop through field/boundar, etc.. for (const auto& u : U) { Pout<< u << nl; } Pout<< “Finish reading data in processor ” << i << endl; } |
|
March 30, 2022, 13:35 |
|
#7 | |
New Member
Join Date: Dec 2021
Posts: 23
Rep Power: 4 |
Quote:
This also seems interesting: I am using OF2106 and the same function reads: Code:
template<class Type> void Foam::vtk::writeListParallel ( vtk::formatter& fmt, const UList<Type>& values ) { if (Pstream::master()) { vtk::writeList(fmt, values); List<Type> recv; // Receive and write for (const int slave : Pstream::subProcs()) { IPstream fromSlave(Pstream::commsTypes::blocking, slave); fromSlave >> recv; vtk::writeList(fmt, recv); } } else { // Send to master OPstream toMaster ( Pstream::commsTypes::blocking, Pstream::masterNo() ); toMaster << values; } } Code:
if (Pstream::master()) { Info << myField << endl; List<Type> recv; // Receive and write for (const int slave : Pstream::subProcs()) { IPstream fromSlave(Pstream::commsTypes::blocking, slave); fromSlave >> recv; Info << "Data in processor " << slave << endl; Info << recv << endl; } } else { // Send to master OPstream toMaster ( Pstream::commsTypes::blocking, Pstream::masterNo() ); toMaster << myField; } } So that the output is "Data from patch: somePatchName" |
||
April 1, 2022, 04:52 |
|
#8 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,686
Rep Power: 40 |
The code in VTK writing is optimized for contiguous data, but shows the general idea of collecting in values into the master process. If you want a more general gathering (non-contiguous) then globalIndexTemplates.C would also provide some reasonable snippets.
BTW: you may also want non-blocking modes, but then you will have to wait for the requests yourself. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[General] Extracting ParaView Data into Python Arrays | Jeffzda | ParaView | 30 | November 6, 2023 21:00 |
[General] Acces to information tab data | badoumba | ParaView | 0 | August 8, 2017 10:20 |
script for export particle information | archetype | CFX | 2 | August 8, 2017 09:57 |
OpenFOAM 2D simulation - Freelancer Job- Information will be provided | sanjar | CFD Freelancers | 0 | March 7, 2017 09:45 |
information from saved data files:Unsteady flow | Atul | FLUENT | 5 | July 27, 2008 20:05 |