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

for loop, not working in parallel

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 2, 2012, 10:19
Default for loop, not working in parallel
  #1
Member
 
Carlos Xisto
Join Date: Nov 2009
Location: Covilhã, Portugal
Posts: 53
Rep Power: 16
xisto is on a distinguished road
Send a message via MSN to xisto
Hello everyone,

Maybe this is not a new question, but for some reason this piece of code does not work in parallel, just in serial.

Any advice?

Code:
for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)  //internalFACES

{ 


 if(mag(M_R[faceI]) >= scalar(1.0)) //rigth face values 
     {
         M_4_neg[faceI] = M_1_neg[faceI]; //rigth side face function
         P_5_neg[faceI] = M_1_neg[faceI]/M_R[faceI]; 
     }    

   if(mag(M_L[faceI]) >= scalar(1.0)) //left face values 
      {
         M_4_pos[faceI] = M_1_pos[faceI]; //left side face functions 
         P_5_pos[faceI] = M_1_pos[faceI]/M_L[faceI];   
      }  
      
 
}
xisto is offline   Reply With Quote

Old   April 3, 2012, 05:20
Default
  #2
Member
 
Carlos Xisto
Join Date: Nov 2009
Location: Covilhã, Portugal
Posts: 53
Rep Power: 16
xisto is on a distinguished road
Send a message via MSN to xisto
This is the Bernhard answer to my email:

>Anyway: one of your problems might be that faces that were internal in
>the serial case are now boundary faces (on a processor patch). From
>what I see in your code you don't treat them at all. You'll have to do
>that treatment separately for these patches.

Thanks Bernhard
xisto is offline   Reply With Quote

Old   April 3, 2012, 08:32
Default
  #3
Member
 
Carlos Xisto
Join Date: Nov 2009
Location: Covilhã, Portugal
Posts: 53
Rep Power: 16
xisto is on a distinguished road
Send a message via MSN to xisto
So I have added the boundaryField. But is still not working.

Any ideas?

Code:
for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)  //internalFACES
  {
 if(mag(M_R[faceI]) >= scalar(1.0)) //rigth face values (for ox)
     {
         M_4_neg[faceI] = M_1_neg[faceI]; //rigth side face function
         P_5_neg[faceI] = M_1_neg[faceI]/M_R[faceI]; 
     }    
        
   if(mag(M_L[faceI]) >= scalar(1.0)) //left face values (for ox)
      {
         M_4_pos[faceI] = M_1_pos[faceI]; //left side face functions 
         P_5_pos[faceI] = M_1_pos[faceI]/M_L[faceI];   
      }  
  }


  forAll(mesh.boundaryMesh(), patchi)
    {
 if(mag(M_R[patchi]) >= scalar(1.0)) //rigth face values (for ox)
     {
         M_4_neg[patchi] = M_1_neg[patchi]; //rigth side face function
         P_5_neg[patchi] = M_1_neg[patchi]/M_R[patchi]; 
     }    
        
   if(mag(M_L[patchi]) >= scalar(1.0)) //left face values (for ox)
      {
         M_4_pos[patchi] = M_1_pos[patchi]; //left side face functions 
         P_5_pos[patchi] = M_1_pos[patchi]/M_L[patchi];   
      }  
    }
xisto is offline   Reply With Quote

Old   April 3, 2012, 14:42
Default
  #4
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by xisto View Post
So I have added the boundaryField. But is still not working.

Any ideas?

Code:
for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)  //internalFACES
  {
 if(mag(M_R[faceI]) >= scalar(1.0)) //rigth face values (for ox)
     {
         M_4_neg[faceI] = M_1_neg[faceI]; //rigth side face function
         P_5_neg[faceI] = M_1_neg[faceI]/M_R[faceI]; 
     }    
        
   if(mag(M_L[faceI]) >= scalar(1.0)) //left face values (for ox)
      {
         M_4_pos[faceI] = M_1_pos[faceI]; //left side face functions 
         P_5_pos[faceI] = M_1_pos[faceI]/M_L[faceI];   
      }  
  }


  forAll(mesh.boundaryMesh(), patchi)
    {
 if(mag(M_R[patchi]) >= scalar(1.0)) //rigth face values (for ox)
     {
         M_4_neg[patchi] = M_1_neg[patchi]; //rigth side face function
         P_5_neg[patchi] = M_1_neg[patchi]/M_R[patchi]; 
     }    
        
   if(mag(M_L[patchi]) >= scalar(1.0)) //left face values (for ox)
      {
         M_4_pos[patchi] = M_1_pos[patchi]; //left side face functions 
         P_5_pos[patchi] = M_1_pos[patchi]/M_L[patchi];   
      }  
    }
Your on the right track. But

a) you'll have to loop over the individual faces in each patch (just like you did for the internal field)
b) you'll want to be sure that you do this only on processor patches. Use "isA" to find out

Have a look at $FOAM_SRC/finiteVolume/lnInclude/adjustPhi.C for inspiration
gschaider is offline   Reply With Quote

Old   April 3, 2012, 17:45
Default
  #5
Member
 
Carlos Xisto
Join Date: Nov 2009
Location: Covilhã, Portugal
Posts: 53
Rep Power: 16
xisto is on a distinguished road
Send a message via MSN to xisto
I was doing this in the wrong way, now I see that. But I can use a different and ingenious approach (without loops) for this particular case (see bellow).

Once more, thanks Bernhard you were very helpful and I think that I need to use your suggestion for another loop problem.



Following the solution of Alberto Passalacqua.

The best way in this case is to forget about the loops and treat everything as a surface scalar.

Quote:
the for loop is not required anymore because the operation is done using the surface field, and not accessing to each face. The "pos" and "neg" methods return a surfaceScalarField with values of 1 on the faces where the argument is positive (pos) or negative (neg), and zero elsewhere. So, say you have your field magMR = mag(M_R), if you do M_4_neg = pos(magMR - 1.0)*(operations...) + neg(magMR - 1.0)*(operations...); you should end up with the final result you want without looping.
and I did just that..

It was necessary to use Foam:os(magMR -1.0), dont know why.

Many thanks Alberto and Bernhard

You guys are the best.

Carlos
xisto 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
OF 2.0.1 parallel running problems moser_r OpenFOAM Running, Solving & CFD 9 July 27, 2022 03:15
Running mapFields with Parallel Source and Parallel Target RDanks OpenFOAM Pre-Processing 4 August 2, 2016 05:24
CFX parallel multi-node jobs fail w/ SLURM on Ubuntu 10.04 danieru CFX 0 February 17, 2012 06:20
parallel fluent under pbs not working kharnabnew FLUENT 0 January 6, 2011 03:28
MPICH Parallel Run Error on the Windows Server2003 Saturn CFX 3 August 29, 2006 08:42


All times are GMT -4. The time now is 17:57.