File: 2streamsf_mpi.F

package info (click to toggle)
sprng 2.0a-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,076 kB
  • ctags: 2,031
  • sloc: ansic: 30,361; fortran: 1,618; makefile: 566; cpp: 58; sh: 5
file content (77 lines) | stat: -rw-r--r-- 2,325 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
C
C              Demonstrates use of shared and non-shared streams    
C Each process has two streams.  One stream is common to all the    
C processes. The other stream is different on each processor. 
C
C Uncomment the following line to get the interface with pointer checking
C #define CHECK_POINTERS

       program twostreamsf_mpi
       implicit none
      
#include <mpif.h>
#include "sprng_f.h"

       integer streamnum,commNum, nstreams, seed
       SPRNG_POINTER stream, commonStream
       real*8 rn
       integer i
       integer myid, nprocs, ierror
       integer junk
C---
       integer gtype       
C---
      call MPI_INIT(ierror)

      call MPI_COMM_SIZE(MPI_COMM_WORLD, nprocs, ierror)

      call MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierror)

       
       streamnum = myid     !This stream is different on each proces
       commNum = nprocs     !This stream is common to all processes
       nstreams = nprocs +1 !extra stream is common to all processes
       seed = 985456376

C--- node 0 is reading in a generator type
       if (myid .eq. 0) then	
#include "genf_types_menu.h"
	 print *,'Type in a generator type (integers: 0,1,2,3,4,5):  '
         read *, gtype
       endif
       call MPI_BCAST(gtype,1, MPI_INTEGER,0,MPI_COMM_WORLD,ierror)
C---

C  This stream is different on each process
       stream = init_sprng(gtype,streamnum,nstreams,seed,SPRNG_DEFAULT)
       write(6, 44) myid
 44    format("Process", i2, ": Print information about new stream")
       junk = print_sprng(stream)

C  This stream is identical on each process
       commonStream = init_sprng(gtype,commNum,nstreams,
     &      seed,SPRNG_DEFAULT)
       write (6, 55) myid
 55    format ("Process", i2, 
     &      ": This stream is identical on all processes")
       junk = print_sprng(commonStream)

       do 100 i = 1, 2
          rn = sprng(stream)
          write(6, 66) myid, i, rn
 100   continue

       do 200 i = 1, 2
          rn = sprng(commonStream)
          write(6, 77) myid, i, rn
 200   continue
 66    format("Process", i2, 
     &   ", random number (distinct stream)",i2,": ", f8.6)
 77    format("Process", i2, ", random number (shared stream)",
     &   i2,": ", f8.6)
       junk = free_sprng(stream)
       junk = free_sprng(commonStream)

       call MPI_FINALIZE(ierror)

       end