Thread: random num MPI help

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    79

    random num MPI help

    Hello, I would welcome some help to this problem. I am trying to have a random no generator in a way that will create random no different for each process in the MPI run. I tried to seed with something that will take the rank of the process as below so I can take different numbers but are the same every time I run the program.

    HOW CAN I TAKE DIFFERENT?

    Many thanks on behalf


    Code:
    #include <stdio.h>
    #include <mpi.h>
    #include <time.h>
    #include <limits.h>
    #include <stdlib.h>
    
    
    int main(int argc, char *argv[])
    {int i,id,p;
    
      double random_val;
      int seed;
      MPI_Init(&argc,&argv);
      MPI_Comm_rank(MPI_COMM_WORLD,&id);
      MPI_Comm_size(MPI_COMM_WORLD,&p);
       
    
    seed = 123456789 + id*100;
    srand(seed);
    
        random_val = (double)rand()/(double)RAND_MAX;
      printf("Hello, world from process number %d with rand no %f\n", id, random_val);
        
        
     
    MPI_Finalize();
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Apr 2010
    Posts
    79
    ok I found the answer. You have to comble time and id seed.

  3. #3
    Registered User jimtuv's Avatar
    Join Date
    May 2010
    Location
    Sylvania, Ohio
    Posts
    94
    Glad you found that. In the future a look a the faq or google search may get you the answer without starting three threads with the same question

    Cprogramming.com FAQ
    Last edited by jimtuv; 06-16-2010 at 06:33 AM.

  4. #4
    Registered User
    Join Date
    Apr 2010
    Posts
    79
    jimtuv get a life

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. a searching tree
    By lindaonline15 in forum C++ Programming
    Replies: 2
    Last Post: 10-15-2008, 06:06 AM
  2. Another brain block... Random Numbers
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 01-23-2005, 05:51 PM
  3. help! fifo read problem
    By judoman in forum C Programming
    Replies: 1
    Last Post: 08-16-2004, 09:19 AM
  4. Problem Using bsearch
    By Zildjian in forum C Programming
    Replies: 4
    Last Post: 11-13-2003, 08:14 PM
  5. Optimization of code
    By dpro in forum C++ Programming
    Replies: 5
    Last Post: 10-28-2002, 04:01 PM