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

Print information in processor sequentially

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By HPE

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 25, 2022, 05:09
Default Print information in processor sequentially
  #1
New Member
 
Join Date: Dec 2021
Posts: 23
Rep Power: 4
MamboJambo is on a distinguished road
Hello to all,


How can one print the information in a processor sequentially?

Let us assume:


Code:
const volVectorField& C = mesh.C();
I would like to have all information in processor 1, 2, 3 ...,N, sequentially.


If I do:
Code:
Pout << C << endl;
It will get mixed up.
MamboJambo is offline   Reply With Quote

Old   March 25, 2022, 06:47
Default
  #2
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 723
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
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
	  }
}
dlahaye is offline   Reply With Quote

Old   March 26, 2022, 11:43
Default
  #3
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,686
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
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
olesen is offline   Reply With Quote

Old   March 26, 2022, 11:45
Default
  #4
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,686
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by dlahaye View Post
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
	  }
}
This will not work.
olesen is offline   Reply With Quote

Old   March 26, 2022, 14:14
Default
  #5
HPE
Senior Member
 
HPE's Avatar
 
Herpes Free Engineer
Join Date: Sep 2019
Location: The Home Under The Ground with the Lost Boys
Posts: 932
Rep Power: 12
HPE is on a distinguished road
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;
}
MamboJambo likes this.
HPE is offline   Reply With Quote

Old   March 28, 2022, 04:51
Default
  #6
New Member
 
Join Date: Dec 2021
Posts: 23
Rep Power: 4
MamboJambo is on a distinguished road
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;
 }
}
MamboJambo is offline   Reply With Quote

Old   March 30, 2022, 13:35
Default
  #7
New Member
 
Join Date: Dec 2021
Posts: 23
Rep Power: 4
MamboJambo is on a distinguished road
Quote:
Originally Posted by olesen View Post
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

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;
    }
}
So it would stay, something like this?

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;
    }
}
Is it possible to get the patch name from the above code?
So that the output is "Data from patch: somePatchName"
MamboJambo is offline   Reply With Quote

Old   April 1, 2022, 04:52
Default
  #8
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,686
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
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.
olesen 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
[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


All times are GMT -4. The time now is 14:52.