Page 1 of 1

About random number for particle dispersion

Posted: October 31st, 2017, 11:28 pm
by HWZealot
Hi, everyone.
I'm looking through the code of concentration program.
I notice that there are two ways to generate the random number for particle dispersion:
1. If Krand=1, will use the pre-calculated random number array.
2. If Krand=2, will use the "parvar" subroutine inside the dispersion subroutine to generate the random number.
I find that if the user not specify the krand in the Namelist file, the program will use 2 when particle smaller than 5000, otherwise the first method.

I try both, finding that the result are very similar with a little different.

I just curious if both random number method's result are acceptable. Because I'm trying to parallelize the inner loop through the particles. And the first random number method (pre-calculated) is good for parallelization while the second one cannot preserve the same result as the original sequential program. So I try to only use the first random number method for my parallel version if that is acceptable.

Thank you.

Re: About random number for particle dispersion

Posted: November 3rd, 2017, 1:01 pm
by ariel.stein
The first method is acceptable too. However, it is less accurate than the second. Having precomputed random numbers is a good approximation but it is not a truly random distribution.
The code is already parallelized through the particles. Please check the conditional compilation statements in hymodelc.F

Re: About random number for particle dispersion

Posted: November 5th, 2017, 11:20 pm
by HWZealot
Thank you!
I Checked the source code and saw how it is using MPI to parallelize the particle loop.
And I used -DMPI flag to compile the "hycm_std" to run the same example as "hycs_std".
However I found the result PostScript produced by "hycm_std" was not the same as the one produced by "hycs_std".
I guessed that it may due to the parallel random number generation is not the same as the sequential random number generation.

If there is nothing wrong with what I said above, I wonder if this small difference between MPI version and sequential version acceptable?

Thank you.

Here are two results:
The result from sequential version: hycs_std.
sequential version.PNG
The result with the same input data from MPI version: hycm_std:
MPI.PNG

Re: About random number for particle dispersion

Posted: November 6th, 2017, 11:57 am
by ariel.stein
You are right, the differences you are seeing are due to the different random numbers generated by the parallelized code. However, I can see that you are not using enough particles so your concentration fields are noisy. I would suggest increasing the number of particles you release and you will see that the differences get smaller.

Re: About random number for particle dispersion

Posted: November 6th, 2017, 8:43 pm
by HWZealot
Thank you.
I tried to increase the numpar from 7500 to 30000. And the differences are much smaller:

The sequential version:
hycs_std_30000P.png
The MPI version:
MPI_30000p.png
So, I think that this differences now acceptable right?

Thank you.

Re: About random number for particle dispersion

Posted: November 7th, 2017, 10:56 am
by ariel.stein
Yes, they are acceptable.
If you increase your particle number even more you will reach a point in which you should not see any difference. No need to do that though.