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

Looping in parallel in template class chemistryModel

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 5, 2024, 18:39
Default Looping in parallel in template class chemistryModel
  #1
Senior Member
 
mturcios777's Avatar
 
Marco A. Turcios
Join Date: Mar 2009
Location: Vancouver, BC, Canada
Posts: 740
Rep Power: 28
mturcios777 will become famous soon enough
Hello all,

I have been updating some old OpenFOAM code (originally in v2, now in v10/11) based on the chemistryModel library where I do a calculation over all cells. I have added the virtual function to basicChemistryModel and the implementation in chemistryModel/chemistryModel.C. I am trying to just do a loop over all cells with a forAll loop, but I only get the first processor to work.

I can't post the full code so I need to create a stub case, but basically (assuming a private member A_ that is a volScalarField that is registered and read in):
Code:
template<class ThermoType>
void Foam::chemistryModel<ThermoType>::someFunction()
{
    tmp<volScalarField> trho(this->thermo().rho();
    const volScalarField rho = trho();
    scalar AVolAve = 0;
    scalar totalVol = 0;

   forAll(rho,celli)
   {
        A_[celli] = rho[celli];
        //AVolAve = A_[celli]*this->mesh().V()[celli];
        //totalVol = this->mesh().V()[celli];
   }

    //reduce(AVolAve, sumOp<scalar>());
    //reduce(totalVol, sumOp<scalar>());

    //AVolAve /= totalVol;
    //Info << "Volume averaged A is: " << AVolAve << endl;
}
The code compiles and runs perfectly in serial. When running in parallel, the reduce operations are necessary to ensure code executes on all processors. If I comment out he code as above, only the first processor is updated.

Any assistance would be welcome.

Last edited by mturcios777; March 6, 2024 at 17:36. Reason: Further context on parallel issues
mturcios777 is offline   Reply With Quote

Old   March 16, 2024, 06:52
Default
  #2
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 mturcios777 View Post
The code compiles and runs perfectly in serial. When running in parallel, the reduce operations are necessary to ensure code executes on all processors. If I comment out he code as above, only the first processor is updated.
I think that you are much too quick jumping to the wrong conclusion - what makes you think that the code is only being executed on one rank?

If you replace the "Info" statement with "Pout" you will print the values on each rank, which will presumably contradict your conclusion.
olesen is offline   Reply With Quote

Old   March 16, 2024, 06:59
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
Quote:
Originally Posted by mturcios777 View Post
Code:
    tmp<volScalarField> trho(this->thermo().rho();
    const volScalarField rho = trho();
This is wasteful to make a full copy of the tmp field, please use a reference:
Code:
tmp<volScalarField> trho(this->thermo().rho();
const auto& rho = trho();
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
fvc::div for surfaceVectorField ARTem OpenFOAM Programming & Development 4 November 2, 2018 12:41
[snappyHexMesh] OpenFoam in parallel with sHM and sFE pradyumnsingh OpenFOAM Meshing & Mesh Conversion 4 October 26, 2018 16:25
Error running openfoam in parallel fede32 OpenFOAM Programming & Development 5 October 4, 2018 16:38
The udf.h headers are unable to open- in VISUAL STUDIO 13 sanjeetlimbu Fluent UDF and Scheme Programming 4 May 2, 2016 05:38
Parallel Computing Classes at San Diego Supercomputer Center Jan. 20-22 Amitava Majumdar Main CFD Forum 0 January 5, 1999 12:00


All times are GMT -4. The time now is 20:21.