random initialization in parallel computation

[size=medium]Hi all,
I have problem with truly! random initialization of a sample code when I run it in parallel mode.
Please check the code in the folder ~/examples/codesByTopics/shanChenMultiPhase.
When I run it on a single core, everything is OK. But in parallel mode (like with 4 cores), the initial field is not truly random. Actually, the 4 blocks of the domain have the same random initial condition.
It seems the command line:
T rho = rho0 + ((T)random()/(T)RAND_MAX)*maxRho;
does not work properly in parallel mode.
Any solution?

Cheers[/size]

Hello,

a quick fix could be to include the header:

#include

then replace the line:

T rho = rho0 + ((T)random()/(T)RAND_MAX)*maxRho;

with:

T rho = rho0 + ((T)rand()/(T)RAND_MAX)*maxRho;

and at the beginning of the main function, after:

plbInit(&argc, &argv);
global::directories().setOutputDir("./tmp/");

add:

srand((unsigned int) global::mpi().getRank() * (unsigned int) time(0));

I hope this solves your problem.

Best,
Dimitris

[size=medium]Hi Dimitris,
It works…
Thank you for your quick reply.
[/size]

[size=medium]
empty!!
[/size]