	PROGRAM Eurpoean_node

        COMMON /XPRESS/ NOCARE, NORDER, NONODE, IHOST, IALNOD, IALPRC
        parameter (MAXSIZE = 524288)
c        parameter (MAXSIZE = 1048576)
c        implicit none
      
        real sl(MAXSIZE),vl(MAXSIZE)
        real u,d,xval,ux,dx,sig,dt,tmp1,tmp2
        real cval, sk, r
        integer i,j,j1,reps
      
	INTEGER ENV(5)
	INTEGER STATUS
        real*4 data(6)
	INTEGER TYPE, dummy
	INTEGER FADD
	EXTERNAL FADD
	DATA TYPE/123/

C-- Start up EXPRESS. This MUST be the first EXPRESS system call used.

	CALL KXINIT

C-- Set up the communication profiler.
        CALL KCPON

C-- Read system parameters, number of nodes etc......

	STATUS = KXPARA(ENV)

 999    continue

c     --- read parameters from host
	STATUS = KXBROD(data, IHOST, 24, IALNOD, DUMMY, TYPE)
        u = data(1)
        d = data(2)
        r = data(3)
        dt = data(4)
        reps = INT(data(5))
        sk = data(6)

c     --- read initial stock and valatility values from host
        status = KXREAD(sl(1), 4, IHOST, type)
        status = KXREAD(vl(1), 4, IHOST, type)        

c     --- calculate binomial lattice
        do 3000 i = 1, reps                 
           do 2000 j = 2**i,1,-2                  
              j1 = j/2                             
              sig = vl(j1)  
              tmp1 = (r-0.5*sig)*dt
              tmp2 = SQRT(sig*dt)
              ux = EXP(tmp1 + tmp2)
              dx = EXP(tmp1 - tmp2)
              
              sl(j)   = sl(j1)*dx             
              sl(j-1) = sl(j1)*ux            
              vl(j)   = vl(j1)*d                       
              vl(j-1) = vl(j1)*u                      
 2000      continue
 3000   continue                                

c     --- sum final values in the binomial lattice
        cval = 0.0
        do 4000 i = 1, 2**reps
           xval = sl(i) - sk
           if (xval .gt. 0.0) cval = cval + xval
 4000   continue

        call KXSYNC
c     --- sum values across the network
        status = KXCOMB(cval, FADD, 4, 1, IALNOD, dummy, type)

c     --- send the sum to host
        if (env(1) .eq. 0) then
           status = KXWRIT(cval, 4, IHOST, type)
        endif

c     --- for communication profiler (ctool) 
        CALL KCPELT('exprof.prc')

        goto 999
      
        end

	INTEGER FUNCTION FADD(I, J, SIZE)
	INTEGER SIZE
        real i, j

	I = I + J
	FADD = 0

	return
	END




