Ejemplo n.º 1
0
main()
{
  int streamnum, nstreams, seed, *stream, i;
  double rn;



  /************************** Initialization *******************************/

  streamnum = 0;
  nstreams = 1;

  seed = make_sprng_seed();	/* make new seed each time program is run  */

  stream = init_sprng(streamnum,nstreams,seed,SPRNG_DEFAULT); /*initialize stream*/
  printf(" Printing information about new stream\n");
  print_sprng(stream);

  /************************ print random numbers ***************************/

  printf(" Printing 3 random numbers in [0,1):\n");
  for (i=0;i<3;i++)
  {
    rn = sprng(stream);		/* generate double precision random number */
    printf("%f\n", rn);
  }

  free_sprng(stream);		/* free memory used to store stream state  */
}
Ejemplo n.º 2
0
main(int argc, char *argv[])
{
  int streamnum, nstreams, seed, *stream, i, myid, nprocs;
  double rn;
  int gtype;  /*---    */


  /*************************** MPI calls ***********************************/

  MPI_Init(&argc, &argv);	/* Initialize MPI                          */
  MPI_Comm_rank(MPI_COMM_WORLD, &myid);	/* find process id                 */
  MPI_Comm_size(MPI_COMM_WORLD, &nprocs); /* find number of processes      */

  /************************** Initialization *******************************/

  streamnum = myid;
  nstreams = nprocs;		/* one stream per processor                */
  seed = make_sprng_seed();	/* make new seed each time program is run  */
  
  /*--- node 0 is reading in a generator type */
  if(myid == 0)
  {
#include "gen_types_menu.h"
    printf("Type in a generator type (integers: 0,1,2,3,4,5):  ");
    scanf("%d", &gtype);
  }
  MPI_Bcast(&gtype,1,MPI_INT,0,MPI_COMM_WORLD );

  /* Seed should be the same on all processes                              */
  printf("Process %d: seed = %16d\n", myid, seed);
  
  stream = init_sprng(gtype,streamnum,nstreams,seed,SPRNG_DEFAULT);	/*initialize stream*/
  printf("\n\nProcess %d: Print information about stream:\n",myid);
  print_sprng(stream);

  /************************ print random numbers ***************************/

  for (i=0;i<3;i++)
  {
    rn = sprng(stream);		/* generate double precision random number */
    printf("process %d, random number %d: %f\n", myid, i+1, rn);
  }

  free_sprng(stream);           /* free memory used to store stream state  */

  MPI_Finalize();		/* Terminate MPI                           */
}
Ejemplo n.º 3
0
void main (int argc, char *argv[])
{

  int i, seed, param, nruns, nstreams, n, *stream, myid=0, nprocs=1;


#ifdef SPRNG_MPI
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &myid);
  MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
  if(myid != 0)			/* This is a sequential program currently  */
  {
    MPI_Finalize();
    exit(0);
  }
#endif

  /**************************** Initialization *****************************/

  if(argc != 8 || atoi(argv[2]) != 1 || atoi(argv[6]) != 0)
  {
    fprintf(stderr,"USAGE: %s nstreams 1 seed param nruns 0 n\n",
	    argv[0]);
    exit(-1);
  }
  else if(atoi(argv[1]) < 1 || atoi(argv[5]) < 1 || atoi(argv[7]) < 1 )
  {
    fprintf(stderr,"ERROR: nstreams, nruns, and n must be > 0\n");
    exit(-1);
  }
  
  nstreams = atoi(argv[1]);	/* number of streams                       */
  param = atoi(argv[4]);	/* parameter to the generator              */
  nruns = atoi(argv[5]);	/* number of runs to repeat                */
  n = atoi(argv[7]);		/* number of random numbers per stream     */

  if(n&1)			/* number of rows for Fourier coefficients */
    lda = n+1;
  else
    lda = n+2;
  
  FFTcoeffs = (double *) malloc(lda*nstreams*sizeof(double)); /* FFT coeffs */
  means = (double *) malloc(lda*nstreams*sizeof(double)); /* average coeffs */
  streams = (int **) malloc(nstreams*sizeof(int *)); /*random number streams*/
  
  for(i=0; i<lda*nstreams; i++)
    FFTcoeffs[i] = means[i] = 0.0;
  
  seed = make_sprng_seed();
  
  for (i=0; i<nstreams; i++)	/* initialize random number streams         */
    streams[i] = init_sprng(i,nstreams,seed,param);
  

  /***************************** Calculate FFTs *****************************/

  FFTCalc(nstreams,nruns,n);


  /************************* Analyze coefficients ***************************/

  Analyze(nstreams,nruns,n); 

  free(FFTcoeffs);
  free(means);
  free(streams);

#if defined(SPRNG_MPI)
     MPI_Finalize();
#endif

  
}