
      program option_pricing
      implicit none
      
      integer info, nodes, msgtype
      integer mytid, tids(0:32)
      character*8 arch
      COMMON /APIENV/ nodes, mytid, tids
      
      real sz,k,r,t,tdiv,div,v(4),rate
      real psi,xmu,rho,cbscall,camc,ceur,cams
      integer repb,reps,reps1,i, j, times
      
c     ------------ Starting up all the tasks ---------------------------

c     Enroll this program in API 
c      call pvmfmytid( mytid )
      call MP_ENVIRON(nodes,mytid)

c     Initiate nodes instances of node program 
c      print *,'How many slave programs (1-32)?'
c      read *, nodes

c     --- for trace back data used by VT
c      call VT_trc_start(15)

c      print *,'API start ...'
      
c     --- only suitable node number can be used
      if (nodes.ge.32) then
         nodes = 32
         reps1 = 5
      else if (nodes.ge.16) then
         nodes = 16
         reps1 = 4
      else if (nodes.ge.8) then
         nodes = 8
         reps1 = 3
      else if (nodes.ge.4) then
         nodes = 4
         reps1 = 2
      else if (nodes.ge.2) then
         nodes = 2
         reps1 = 1
      else
         nodes = 1
         reps1 = 0
      ENDIF           

c     --- initial primitive model parameters
         sz = 110
         repb = 100
         reps = 17
         psi = 1.0
         xmu = 0.0 
         rho = 0.234
         k = 100.00       
         t = .25          
         v(2) = 0.15                                                 
         v(3) = 0.15 
         v(4) = 0.15           
         div = 1.0
         tdiv = 0.125

c      goto 1234
      
c     --- stochastic volatility European Model
      if (mytid .eq. 0) then
         print *,'stochastic volatility European Model'
         print *,'reps         Value      Time(usec.)'
         print *,'----------------------------------'
      endif

      call svcorp2(sz,k,rate,t,v(3),psi,xmu,rho,reps,reps1,ceur)

      if (mytid .eq. 0) then
         write(*,'(I3,9X,f9.4)') reps,ceur
      endif

c      goto 999
       
 1234 continue

      j = 1
      tdiv = t*j/float(reps)

c     --- stochastic volatility American Model
      if (mytid .eq. 0) then
         print *,'stochastic volatility American Model'
         print *,'reps   reps1      Value  Time(usec.)'
         print *,'-----------------------------------'
      endif

      call asvcorp2(sz,k,rate,t,v(4),tdiv,div,psi,
     &     xmu,rho,reps,reps1,cams) 
      
      if (mytid .eq. 0) then
         write(*,'(I3,5X,I3,5X,f9.4)') reps,
     &        (INT(reps*tdiv/t)+1),cams
      endif
      
 999  continue
      
c     program finished leave API before exiting 
      
c      call MP_STOPALL(1)
c      call VT_trc_stop(15)
c       if (mytid .eq. 0) stop
c     call exit_profs('Done!\0')

      end
