      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      INCLUDE 'mpif.h'
C                     INITIALIZE MPI
      CALL MPI_INIT (IERR)
C                     NPES = NUMBER OF PROCESSORS                
      CALL MPI_COMM_SIZE (MPI_COMM_WORLD,NPES,IERR)
C                     ITASK = MY PROCESSOR NUMBER
      CALL MPI_COMM_RANK (MPI_COMM_WORLD,ITASK,IERR)
C                     TOTAL NUMBER OF TRIALS
      NTOTAL = 10000000
C                     TRIALS PER PROCESSOR
      NTRIALS = NTOTAL/NPES
      E = 40.0
      S0 = 39.0
      R = 0.1
      SIGMA = 0.2
      T = 0.5D0
      Rp = R - 0.5*SIGMA**2
C                     NUMBER OF COIN FLIPS PER TRIAL
      N = 1000
      DT = T/N 
      DX = SIGMA*SQRT(DT)
      RE = EXP(DX) 
      VSUM = 0.0
C                     USE DIFFERENT SEED ON EACH PROCESSOR
      CALL SRAND(ITASK)
      DO ITRIAL=1,NTRIALS
         S = S0 
         DO K=1,N
            IF (RAND() > 0.5) THEN
C                     IF HEADS, MULTIPLY S BY EXP(DX)
               S = S*RE
            ELSE 
C                     IF TAILS, DIVIDE S BY EXP(DX)
               S = S/RE
            ENDIF
         ENDDO
C                     ADJUST FINAL PRICE TO GET DESIRED MEAN
         S = S*EXP(Rp*T)
C                     VALUE OF OPTION AT FINAL TIME (T)
         VAL = MAX(S-E,0.D0)
         VSUM = VSUM + VAL 
      ENDDO
C                     AVERAGE OVER ALL TRIALS ON PROCESSOR
      Vave = VSUM/NTRIALS
C                     CURRENT VALUE OF OPTION
      Vave = Vave*EXP(-R*T)
C                     ADD AVERAGES FROM ALL PROCESSORS
      CALL MPI_REDUCE(Vave,VaveSum,1,MPI_DOUBLE_PRECISION,
     & MPI_SUM,0,MPI_COMM_WORLD,IERR)
C                     AVERAGE OVER ALL PROCESSORS AND PRINT
      Vave = VaveSum/NPES
      IF (ITASK.EQ.0) PRINT *, ' V = ',Vave
      CALL MPI_FINALIZE(IERR)
      STOP
      END 
