# how to share a scalar between processors in parallel Run

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

 July 19, 2013, 05:27 how to share a scalar between processors in parallel Run #1 Senior Member   Join Date: Jun 2011 Posts: 151 Rep Power: 8 Sponsored Links 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 ?

 July 19, 2013, 13:35 #2 Senior Member     Kyle Mooney Join Date: Jul 2009 Location: Amherst, MA USA - San Diego, CA USA Posts: 321 Rep Power: 11 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());``` 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.

July 19, 2013, 16:25
#3
Senior Member

Daniel P. Combest
Join Date: Mar 2009
Location: St. Louis, USA
Posts: 612
Rep Power: 22
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

 July 19, 2013, 16:33 Hi Mooney #4 Senior Member   Join Date: Jun 2011 Posts: 151 Rep Power: 8 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

July 19, 2013, 16:36
#5
Senior Member

Join Date: Jun 2011
Posts: 151
Rep Power: 8
Quote:
 Originally Posted by chegdan 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

Best Regards

 July 19, 2013, 16:48 #6 Senior Member     Daniel P. Combest Join Date: Mar 2009 Location: St. Louis, USA Posts: 612 Rep Power: 22 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

July 20, 2013, 09:57
#7
Senior Member

Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 16
Quote:
 Originally Posted by chegdan 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;```
__________________
Laurence R. McGlashan :: Website

 July 21, 2013, 22:54 #8 Senior Member     Daniel P. Combest Join Date: Mar 2009 Location: St. Louis, USA Posts: 612 Rep Power: 22 Well that's easy enough! __________________ Dan Find me on twitter @dancombest and LinkedIn

 July 22, 2013, 06:32 #9 Senior Member   Join Date: Jun 2011 Posts: 151 Rep Power: 8 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()

 July 25, 2013, 02:18 #10 Senior Member   Join Date: Jun 2011 Posts: 151 Rep Power: 8 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()

 Thread Tools Display Modes Linear Mode

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

 Similar Threads Thread Thread Starter Forum Replies Last Post vivek070176 OpenFOAM Programming & Development 10 December 24, 2014 00:48 immortality OpenFOAM Running, Solving & CFD 11 April 22, 2014 12:32 danvica OpenFOAM Running, Solving & CFD 4 April 5, 2012 11:57 JulytoNovember OpenFOAM Running, Solving & CFD 2 March 31, 2012 09:28 norman1981 OpenFOAM Bugs 5 December 7, 2011 13:48