CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   how to share a scalar between processors in parallel Run (http://www.cfd-online.com/Forums/openfoam-programming-development/121012-how-share-scalar-between-processors-parallel-run.html)

mechy July 19, 2013 05:27

how to share a scalar between processors in parallel Run
 
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 ?


kmooney July 19, 2013 13:35

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.

chegdan July 19, 2013 16:25

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.

mechy July 19, 2013 16:33

Hi Mooney
 
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 July 19, 2013 16:36

Quote:

Originally Posted by chegdan (Post 440894)
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

chegdan July 19, 2013 16:48

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 :D .

Good Luck!

l_r_mcglashan July 20, 2013 09:57

Quote:

Originally Posted by chegdan (Post 440894)
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;


chegdan July 21, 2013 22:54

Well that's easy enough!

mechy July 22, 2013 06:32

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 July 25, 2013 02:18

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()

chegdan July 25, 2013 08:52

Mechy,

You posted this question on another thread already

http://www.cfd-online.com/Forums/ope...allel-run.html

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 http://www.cfd-online.com/Forums/ope...-get-help.html. 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 :D .
Good Luck!


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