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

how to share a scalar between processors in parallel Run

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree2Likes
  • 1 Post By kmooney
  • 1 Post By l_r_mcglashan

Reply
 
LinkBack Thread Tools Display Modes
Old   July 19, 2013, 05:27
Default how to share a scalar between processors in parallel Run
  #1
Senior Member
 
Join Date: Jun 2011
Posts: 141
Rep Power: 6
mechy is on a distinguished road
Hi all
I want to solve the single DOF forced and damped vibration equation for displacement of tip point of a plate(m*d2x/dt2+c*dx/dt+k*x=F)

and displacement of other points of plate are explicitly obtained from the first mode of the plate


the code in serial run give correct results

when I run this code in parallel for calculating displacement of other points of plate only the first processor is used correct x and others processors is used zero instead of x

how can I share the x value between all processors ?

mechy is offline   Reply With Quote

Old   July 19, 2013, 13:35
Default
  #2
Senior Member
 
kmooney's Avatar
 
Kyle Mooney
Join Date: Jul 2009
Location: Amherst, MA USA - San Diego, CA USA
Posts: 285
Rep Power: 9
kmooney is on a distinguished road
Hi Mechy,

This might not be the perfect way to do it but if you're certain that your value is correct on one processor and zero on the others, you could so a sum and reduce so that your value is identical on all processors.

Code:
//Assuming this is the x you mentioned, and it is a scalar
scalar x; 

reduce(x, sumOp<scalar>());
This code will take x from each processor, sum them all up, and set x on each processor to this sum.

In other words,
With i being the processor number,
x[i] = sum(x[i])
Again, this will work assuming that x is non-zero and correct on one processor and zero on all others. There is surely a way to handle other situations but this is all I can come up with off the top of my head.

You might have to put the Pstream name space on reduce like this: Pstream::reduce(...)

Let me know if this doesn't work!

Cheers,
Kyle

edit: change returnReduce to reduce.
hua1015 likes this.
kmooney is offline   Reply With Quote

Old   July 19, 2013, 16:25
Default
  #3
Senior Member
 
chegdan's Avatar
 
Daniel P. Combest
Join Date: Mar 2009
Location: St. Louis, USA
Posts: 546
Rep Power: 18
chegdan will become famous soon enough
Quote:
Again, this will work assuming that x is non-zero and correct on one processor and zero on all others.
If this is not the case then you could use something like MPI_Scatter to send a value everywhere. This is not currently implemented in Pstreams...so you would either implement this yourself or stick with some MPI-specific functions.
__________________
Dan

Find me on twitter @dancombest and LinkedIn
chegdan is offline   Reply With Quote

Old   July 19, 2013, 16:33
Default Hi Mooney
  #4
Senior Member
 
Join Date: Jun 2011
Posts: 141
Rep Power: 6
mechy is on a distinguished road
Hi Mooney

thanks so much for your reply
yes, in this case it works well

what shoul I do if the value of x is not equal to zero on non master procesors ?

in other words how we can use the value of objects on master processor ?


Best Regards
mechy is offline   Reply With Quote

Old   July 19, 2013, 16:36
Default
  #5
Senior Member
 
Join Date: Jun 2011
Posts: 141
Rep Power: 6
mechy is on a distinguished road
Quote:
Originally Posted by chegdan View Post
If this is not the case then you could use something like MPI_Scatter to send a value everywhere. This is not currently implemented in Pstreams...so you would either implement this yourself or stick with some MPI-specific functions.

Hi Daniel

can you give me more information

Best Regards
mechy is offline   Reply With Quote

Old   July 19, 2013, 16:48
Default
  #6
Senior Member
 
chegdan's Avatar
 
Daniel P. Combest
Join Date: Mar 2009
Location: St. Louis, USA
Posts: 546
Rep Power: 18
chegdan will become famous soon enough
Mechy,

This is where it gets a little more difficult, but you can find information here.

I used another function called MPI_Bcast and you can see my example in my GPU library cufflink. MPI_Bcast sends out the value from the master node to all other nodes and you can see some instructions here. The rest...the internet knows .

Good Luck!
__________________
Dan

Find me on twitter @dancombest and LinkedIn
chegdan is offline   Reply With Quote

Old   July 20, 2013, 09:57
Default
  #7
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 14
l_r_mcglashan will become famous soon enough
Quote:
Originally Posted by chegdan View Post
If this is not the case then you could use something like MPI_Scatter to send a value everywhere. This is not currently implemented in Pstreams...so you would either implement this yourself or stick with some MPI-specific functions.
This works for me;

Code:
   
label x = 0;

if (Pstream::master())
{
    x = 1;
}

Pout<< x << endl;

Pstream::scatter(x);

Pout<< x << endl;
hua1015 likes this.
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   July 21, 2013, 22:54
Default
  #8
Senior Member
 
chegdan's Avatar
 
Daniel P. Combest
Join Date: Mar 2009
Location: St. Louis, USA
Posts: 546
Rep Power: 18
chegdan will become famous soon enough
Well that's easy enough!
__________________
Dan

Find me on twitter @dancombest and LinkedIn
chegdan is offline   Reply With Quote

Old   July 22, 2013, 06:32
Default
  #9
Senior Member
 
Join Date: Jun 2011
Posts: 141
Rep Power: 6
mechy is on a distinguished road
Is it possible to reconstruct pressure or velocity on a boundary in a parallel run and obtain the
pressure on that boundary
for example: if during a run the pressure at processor N is shown by PN and they are as follow
how we can reconstruct them


P0=
20
(
-55.8428
-57.6691
-61.1336
-65.5385
-70.2184
-74.7188
-78.6798
-81.829
-83.9898
-85.0677
123.47
125.28
128.745
133.15
137.831
142.333
146.297
149.452
151.617
152.696
)





P1=
25
(
-85.0475
-83.8217
-81.4402
-77.9027
-73.199
-67.2925
-60.0901
-51.3958
-40.7595
-28.5443
13.0599
23.4403
33.5093
43.5004
53.6818
152.681
151.464
149.081
145.536
140.815
134.877
127.62
118.849
108.006
95.2818
)



P2=0()


P3=0()
mechy is offline   Reply With Quote

Old   July 25, 2013, 02:18
Default
  #10
Senior Member
 
Join Date: Jun 2011
Posts: 141
Rep Power: 6
mechy is on a distinguished road
Is it possible to reconstruct pressure or velocity on a boundary in a parallel run and obtain the
pressure on that boundary
for example: if during a run the pressure at processor N is shown by PN and they are as follow
how we can reconstruct them


P0=
20
(
-55.8428
-57.6691
-61.1336
-65.5385
-70.2184
-74.7188
-78.6798
-81.829
-83.9898
-85.0677
123.47
125.28
128.745
133.15
137.831
142.333
146.297
149.452
151.617
152.696
)





P1=
25
(
-85.0475
-83.8217
-81.4402
-77.9027
-73.199
-67.2925
-60.0901
-51.3958
-40.7595
-28.5443
13.0599
23.4403
33.5093
43.5004
53.6818
152.681
151.464
149.081
145.536
140.815
134.877
127.62
118.849
108.006
95.2818
)



P2=0()


P3=0()
mechy is offline   Reply With Quote

Old   July 25, 2013, 08:52
Default
  #11
Senior Member
 
chegdan's Avatar
 
Daniel P. Combest
Join Date: Mar 2009
Location: St. Louis, USA
Posts: 546
Rep Power: 18
chegdan will become famous soon enough
Mechy,

You posted this question on another thread already

How reconstruct pressure on a boundary in parallel run ?

This will probably not get answered any faster doing this, in fact it might have the opposite effect. You might want to refer to the Forum rules, particularly number 6. And for some general guidelines for posts, see How to give enough info to get help. I would focus this discussion on your other thread. You can then reply to yourself with more information on what you are trying to achieve or what you have tried already and I'm sure people will answer .
Good Luck!
__________________
Dan

Find me on twitter @dancombest and LinkedIn
chegdan is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
dieselFoam problem!! trying to introduce a new heat transfer model vivek070176 OpenFOAM Programming & Development 10 December 24, 2014 00:48
whats the cause of error? immortality OpenFOAM Running, Solving & CFD 11 April 22, 2014 12:32
Parallel run - number of processors danvica OpenFOAM Running, Solving & CFD 4 April 5, 2012 11:57
Can't run in parallel JulytoNovember OpenFOAM Running, Solving & CFD 2 March 31, 2012 09:28
SnappyHexMesh OF-1.6-ext crashes on a parallel run norman1981 OpenFOAM Bugs 5 December 7, 2011 13:48


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