Statistics
| Branch: | Revision:

root / synthbench / euroben-dm / mod1j / mod1j.f @ 0:839f52ef7657

History | View | Annotate | Download (4.8 kB)

1
      Program mod1j
2
! ----------------------------------------------------------------------
3
      Use                     numerics
4
      Use                     dist_module
5
      Implicit                None
6
      Include                 'mpif.h'
7

    
8
      Integer              :: comm, status, istat(MPI_Status_Size) 
9
      Integer              :: i, ireps, length, nreps
10
      Real(l_)             :: incpt, perc, slope, time
11
      Real(l_)             :: bw, bwmax, latency, lperc
12
      Real(l_)             :: start_time, end_time
13
      Logical              :: ok
14

    
15
      Integer, Allocatable :: message(:)
16
! ----------------------------------------------------------------------
17
! --- Initialise MPI.
18

    
19
      Call csetup
20
      comm = MPI_Comm_World
21
      start_time = MPI_Wtime()
22
! --- Call identification routine.
23

    
24
      If ( me == 0 ) Then
25
          Call state('mod1j   ')
26
          Print 1000
27
      End If
28
! ----------------------------------------------------------------------
29
! --- If I am the first node, get data , send data, and wait for data
30
!     from the second node.
31
!     Also initialise the least-squares routine and max. bandwidth.
32
! ----------------------------------------------------------------------
33
      If ( me == 0 ) Then
34
         Call lsq( 0, 0.0_l_, 0.0_l_, slope, incpt, perc )
35
         bwmax = 0.0_l_
36
      End If
37
      Open( 1, File = 'mod1j.in' )
38
   10 Read( 1, *, End = 20 ) length, nreps
39
      Allocate( message(length) )
40
      If ( me == 0 ) Then
41
         Do i = 1, length
42
            message(i) = i
43
         End Do
44
      Else If ( me == 1 ) Then
45
         message = 0
46
      End If
47
! -----------------------------------------------------------------------
48
! --- Functional part: Perform transfer functions and time them.
49
! -----------------------------------------------------------------------
50
 
51
      If ( me == 0 ) Then
52
         time = MPI_Wtime()
53
         Do ireps = 1, nreps
54

    
55
! --- Send data to other processsor.
56
 
57
            Call MPI_Send( message, length, MPI_Integer, 1, 1, comm,
58
     &                     status )
59

    
60
! --- Now, get message back from the destination processor.
61
 
62
            Call MPI_Recv( message, length, MPI_Integer, 1, 2, comm,
63
     &                     istat, status )
64
         End Do
65

    
66
! --- Time again and divide by 2 to get communication time.
67
 
68
         time = ( MPI_Wtime() - time )/( 2.0_l_*nreps )
69
         If ( Abs( time ) <= 1.0e-14_l_ ) Then
70
             Print *, 'Time interval too short to measure', time
71
         Else
72
             Call lsq( 1, Real( length, l_ ), time, slope, incpt,
73
     &                 perc )
74
             If ( length == 30 ) Then
75
                latency = incpt*1.0e6_l_
76
                lperc   = perc
77
             End If
78
             bw = 1.0e-6_l_*Real( 4*length, l_ )/time
79
             bwmax = Max( bwmax, bw )
80
             ok = .TRUE.
81
             Call check( message, length, ok )
82
             Print 1010, 4*length, time, bw, ok
83
         End If
84
! ----------------------------------------------------------------------
85
      Else
86
! ----------------------------------------------------------------------
87
! --- This is the receiving processor that sends back the messages 
88
!     from processor 0 as soon as they are received.
89
! ----------------------------------------------------------------------
90
         Do ireps = 1, nreps
91
   
92
! --- Receive message from the sending processor and send it back
93
!     immediately.
94
 
95
            Call MPI_Recv( message, length, MPI_Integer, 0, 1, comm,
96
     &                     istat, status )
97
            Call MPI_Send( message, length, MPI_Integer, 0, 2, comm,
98
     &                     status )
99
         End Do
100
      End If
101
! ----------------------------------------------------------------------
102
      Deallocate( message )
103
      Go To 10
104
   20 If ( me == 0 ) Then
105
         Print 1020
106
         Print 1030, bwmax, latency, lperc
107
      End If
108

    
109
      end_time =  MPI_Wtime() - start_time
110
      If ( me == 0 ) Then
111
         Write(6,22) 'Walltime: ', end_time, " s"
112
 22      Format(A,F9.3,A)
113
      End If
114
      Call MPI_Finalize( istat )
115
! ----------------------------------------------------------------------
116
 1000 Format('Program mod1j: measure distributed memory communication'/
117
     &       '-------------------------------------------------------'/
118
     &       '| Mess. length | Transfer time |   Bandwidth   |   |'/
119
     &       '|    (Bytes)   |    (seconds)  |   (Mbyte/s)   |OK?|'/
120
     &       '----------------------------------------------------' )
121
 1010 Format('|', 3x, i8, 3x, '|', 1x, g13.5, 1x, '|', 1x, g13.5, 1x,
122
     &       '|', l2,' |' )
123
 1020 Format('----------------------------------------------------' )
124
 1030 Format( 'Maximum bandwidth = ' g12.5, ' MB/s'/
125
     &        'Latency   = ', g11.4, ' microsec., Error = ', f6.2, '%'/
126
     &        '-------------------------------------------------------')
127
! ----------------------------------------------------------------------
128
      End Program mod1j