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

I am doing something wrong with scatterList and boundaryFieldRef()

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 17, 2020, 08:52
Default I am doing something wrong with scatterList and boundaryFieldRef()
  #1
Member
 
David Andersson
Join Date: Oct 2019
Posts: 46
Rep Power: 7
sippanspojk is on a distinguished road
Hi Foamers,

I am writing a functionObject that is reading the pressureField, performing some calculations on those values and lastly writing the new values to a custom made field. I am currently working on adapting the code for parallel computing and I am almost there, however there is one last problem that I need help with to solve. The code is compiling and running properly but when I validate the parallel run against the EXACT same run in serial they are not the same (and I am confident that the serial run is correct), or to be precise the values that are written by the master proc (proc0) are correct but the values written by the other procs are not.

I print the values in ESWLVec just before I scatter the list and update the field and then everything looks good. However, when I compare the field from the parallel run and serial run in paraview it is not the same anymore.

This is the last section of my code.

Code:
.
.
Pstream::gatherList(facePressuresPerProc);
.
calculate meanVec and stdVec
.
calculate nomenator and denomenator
.
.
ESWLVec.resize(totNoFaces);
            for(int i = 0; i < totNoFaces; i++){
                    if(meanVec[i] >= 0){
                        ESWLVec[i] = meanVec[i] + std::abs(3.2*stdVec[i]*nomenator[i]/sqrt(denomenator));
                    }else{
                        ESWLVec[i] = meanVec[i] - std::abs(3.2*stdVec[i]*nomenator[i]/sqrt(denomenator));
                    }
            }

            //- Calculating ESWL field
            if(Pstream::parRun()){

                Foam::List<Foam::List<scalar>> ESWLforField(Pstream::nProcs(),Foam::List<scalar>(0.0));
                for(int iProc=0; iProc<Pstream::nProcs(); iProc++){
                    ESWLforField[iProc] = Foam::List<scalar>(nFacesPerProc[iProc],0.0);
                }

                int i = 0;
                for(int iProc=0; iProc<Pstream::nProcs(); iProc++){
                    for(int iFace=0; iFace<nFacesPerProc[iProc]; iFace++){
                        ESWLforField[iProc][iFace] = ESWLVec[i];
                        Info << "P=" << gatheredPatchMapping[i] << " F=" << gatheredFaceMapping[i] << " ESWL=" << ESWLVec[i] << endl;
                        i++;
                    }
                }

                Pstream::scatterList(ESWLforField);

                for(int i=0; i<ESWLforField[Pstream::myProcNo()].size(); i++){
                    label iPatch = patchMapping[Pstream::myProcNo()][i];
                    label iFace = faceMapping[Pstream::myProcNo()][i];
                    ESWL.boundaryFieldRef()[iPatch][iFace] = ESWLforField[Pstream::myProcNo()][i];
                }

            }
I would be very thankful if someone could help with this.
Cheers,
David
sippanspojk is offline   Reply With Quote

Reply

Tags
parallel computing, scatter


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



All times are GMT -4. The time now is 05:53.