FAQ  •  Login

MPI rand

Moderators: Dan Negrut, ME964 Spring 2012

<<

S12hatt

Newbie
Newbie

Posts: 47

Joined: Mon Jan 23, 2012 9:07 pm

Unread post Sun Apr 22, 2012 6:24 pm

MPI rand

Anyone having problems with rand in MPI? Every process is generating the same sequence for me sometimes


  Code:
 srand(mype);
  int val = rand();
  for(int i=0; i < N; i++)
  {
    val = rand();
    randvals[i]=(int)((val%11) -5);
  }
  printf("mype %d:",mype);
  PrintArray(randvals,N);


  Code:
mpiexec -np 4 ./a.out 6
mype 0:5  1  -3  -4  -1  -5 
mype 1:5  1  -3  -4  -1  -5 
mype 2:3  1  0  -4  0  1 
mype 3:-4  2  4  -2  1  -3 
<<

S12portz

Newbie
Newbie

Posts: 18

Joined: Mon Jan 23, 2012 9:07 pm

Unread post Sun Apr 22, 2012 6:32 pm

Re: MPI rand

Try doing srand(mype+1) instead. srand(0) is problematic and gets converted to srand(1).
<<

S12hatt

Newbie
Newbie

Posts: 47

Joined: Mon Jan 23, 2012 9:07 pm

Unread post Sun Apr 22, 2012 6:48 pm

Re: MPI rand

That seemed to do the trick, thanks.

Return to ME964 Spring 2012: High Performance Computing

Who is online

Users browsing this forum: No registered users and 1 guest

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software.