Professional Documents
Culture Documents
Codigo
Codigo
2 ! Input: None.
5 ! Algorithm:
14 ! processors changed.
16 PROGRAM Parallel_Trapezoid
17 IMPLICIT NONE
18 include 'mpif.h'
32 integer tag
33 integer status(MPI_STATUS_SIZE)
36 integer num_local
37 real Trap
49 IF(my_rank == 0) THEN
50 interval = n/p
52 allocate(iend(p))
79
53
54 DO iproc = 1, p
55 ibegin(iproc) = (iproc-1)*interval + 1
57 END DO
58 write(*,'(a,i8)') ' ==> Elements= ', n
60
61 DO iproc=1, p
63 Range= ',ibegin(iproc),iend(iproc)
64 END DO
66 ! starts at:
67 local_a = a + my_rank*local_n*h
72 total = integral
73 DO source = 1, p-1
77 END DO
79 ENDIF
82 write(6,200) n
84 write(6,300) a, b, total
86 ENDIF
87 ! Shut down MPI.
88 CALL MPI_FINALIZE(ierr)
90 !Function Trap
92 IMPLICIT NONE
94 integer local_n
96 real x, i, f, h
98 x = local_a
99 DO i = 1, local_n – 1
100 x = x + h
102 ENDDO
105 Return
106 End
109 real x
110 f = x*x