amagrammer
Technical User
HI, Volks,
I am a beginner in Fortran programming. I use Compaq Fortran Compiler 6.6 on Windows Vista. I wrote a program to calculate a PDE with NAG Fortran Library. But it goes awry as it debugging. Command window shows:
forrtl:severe <157>: program exception - access violation
routine line source
unknown unknown unknown
Then I read another thread dealing with similar problem. Following the advice by mikrom, I tried to use GDB-debugger to locate the error. I run the executable under GDB. As it segmentation fault( 0x004a70bc in ??<>) occurred, I typed 'info stack' to trace the stack back. Command windows showed frames of lines like
#1 0x004a70bc in ??<>
#2 0x004027a2 in ??<>
.
.
#433 0x7595fd89 in SetFilePointer <> from c:\windows\system32\kernel32.dll
.
#436 0x75938425 in SetEndOfFile <> from c:\windows\system32\kernel32.dll
.
.
After a while of striking return key, it came to " cannot access memory at address 0x134000"
I don't know what all this means. I am not sure that I use GDB-debugger correctly either. I attach my code below so that someone can replicate my situation. Thanks a lot.
regards,
amagrammer
CODE:
I am a beginner in Fortran programming. I use Compaq Fortran Compiler 6.6 on Windows Vista. I wrote a program to calculate a PDE with NAG Fortran Library. But it goes awry as it debugging. Command window shows:
forrtl:severe <157>: program exception - access violation
routine line source
unknown unknown unknown
Then I read another thread dealing with similar problem. Following the advice by mikrom, I tried to use GDB-debugger to locate the error. I run the executable under GDB. As it segmentation fault( 0x004a70bc in ??<>) occurred, I typed 'info stack' to trace the stack back. Command windows showed frames of lines like
#1 0x004a70bc in ??<>
#2 0x004027a2 in ??<>
.
.
#433 0x7595fd89 in SetFilePointer <> from c:\windows\system32\kernel32.dll
.
#436 0x75938425 in SetEndOfFile <> from c:\windows\system32\kernel32.dll
.
.
After a while of striking return key, it came to " cannot access memory at address 0x134000"
I don't know what all this means. I am not sure that I use GDB-debugger correctly either. I attach my code below so that someone can replicate my situation. Thanks a lot.
regards,
amagrammer
CODE:
Code:
program carbonprice_sp
implicit none
! Variables
! .. Parameters ..
INTEGER NOUT
PARAMETER (NOUT=6)
!Character(LEN=200), parameter:: inputfile ="C:\\Carbon\\data\\.txt"
Character(LEN=200), parameter:: outputfile ="C:\\Carbon\\results\\carbonprice.txt"
! .. External Subroutines ..
EXTERNAL EX1
! .. Executable Statements ..
open (unit=99, file = outputfile)
WRITE (99,*) 'Carbon Price Results:'
CALL EX1
STOP
write (NOUT,*) 'Program has been successfully excuted!'
read (NOUT,*)
end program carbonprice_sp
SUBROUTINE EX1
! .. Parameters ..
INTEGER NOUT
PARAMETER (NOUT=6)
INTEGER MXLEV, NPDE, NPTS
PARAMETER (MXLEV=3,NPDE=1,NPTS=5.0D4)
INTEGER LENIWK, LENRWK, LENLWK
PARAMETER (LENIWK=NPTS*(5*MXLEV+14)+2+7*MXLEV,&
LENRWK=NPTS*NPDE*(5*MXLEV+9+18*NPDE)+NPTS*2,&
LENLWK=NPTS+1)
! .. Scalars in Common ..
DOUBLE PRECISION PENALTY, ENDOWMENT, MACOST, INTEREST, MU, SIGMA
INTEGER IOUT
! .. Arrays in Common ..
DOUBLE PRECISION TWANT(2)
! .. Local Scalars ..
DOUBLE PRECISION TOLS, TOLT, TOUT, TS, XMAX, XMIN, YMAX, YMIN
INTEGER I, IFAIL, IND, ITRACE, J, MAXLEV, NX, NY
! .. Local Arrays ..
DOUBLE PRECISION DT(3), OPTR(3,NPDE), RWK(LENRWK)
INTEGER IWK(LENIWK), OPTI(4)
LOGICAL LWK(LENLWK)
! .. External Subroutines ..
EXTERNAL D03RAF, MONIT1, PDEF1, PDEIV1 ! BNDRY1 ! NO Boundary conditions
! .. Intrinsic Functions ..
INTRINSIC EXP
! .. Common blocks ..
COMMON /OTIME1/TWANT, IOUT
COMMON /PARAM1/PENALTY, ENDOWMENT, MACOST, INTEREST, MU, SIGMA
! .. Executable Statements ..
WRITE (99,*)
WRITE (99,*)
WRITE (99,*) 'Carbon Emission Allowance Prices w.r.t. time, emission amount(X) and rate(Y)'
WRITE (99,*)
!
! Problem Parameters
!
PENALTY = 100.0D0
ENDOWMENT = 66935.0D0
MACOST = 0.24D0
INTEREST = 0.05D0
MU = 0.01D0
SIGMA = 0.15D0
IND = 0
ITRACE = 1
TS = 0.0D0
DT(1) = 1.0D-2
DT(2) = 0.0D0
DT(3) = 0.0D0
TOUT = 8.0D0
TWANT(1) = 2.0D-2
TWANT(2) = 8.0D0
XMIN = 65754.0D0
XMAX = 67135.0D0
YMIN = 1500.0D0
YMAX = 2500.0D0
NX = 151
NY = 101
TOLS = 10.0D0
TOLT = 0.01D0
OPTI(1) = 3
DO 20 I = 2, 4
OPTI(I) = 10
20 CONTINUE
DO 60 J = 1, NPDE
DO 40 I = 1, 3
OPTR(I,J) = 1.0D0
40 CONTINUE
60 CONTINUE
DO 120 IOUT = 1, 2
IFAIL = -1
TOUT = TWANT(IOUT)
CALL D03RAF(NPDE,TS,TOUT,DT,XMIN,XMAX,YMIN,YMAX,NX,NY,TOLS,&
TOLT,PDEF1,BNDRY1,PDEIV1,MONIT1,OPTI,OPTR,RWK,&
LENRWK,IWK,LENIWK,LWK,LENLWK,ITRACE,IND,IFAIL)
!
! Print statistics
WRITE (99,'('' Statistics:'')')
WRITE (99,'('' Time = '',F8.4)') TS
WRITE (99,'('' Total number of accepted timesteps ='', I5)') IWK(1)
WRITE (99,'('' Total number of rejected timesteps ='', I5)') IWK(2)
WRITE (99,*)
WRITE (99, '('' T o t a l n u m b e r o f '')')
WRITE (99, '('' Residual Jacobian Newton '' , '' Lin sys'')' )
WRITE (99, '('' evals evals iters '' , '' iters'')')
WRITE (99,'('' At level '')')
MAXLEV = 3
DO 80 J = 1, MAXLEV
IF (IWK(J+2).NE.0) THEN
WRITE (99,'(I8,4I10)') J, IWK(J+2), IWK(J+2+MAXLEV), IWK(J+2+2*MAXLEV),IWK(J+2+3*MAXLEV)
END IF
80 CONTINUE
WRITE (99,*)
WRITE (99, '('' M a x i m u m n u m b e r '', '' o f'')')
WRITE (99, '('' Newton iters Lin sys iters '')')
WRITE (99,'('' At level '')')
DO 100 J = 1, MAXLEV
IF (IWK(J+2).NE.0) THEN
WRITE (99,'(I8,2I14)') J, &
IWK(J+2+4*MAXLEV), IWK(J+2+5*MAXLEV) !max number of newton, linear solvers of any time step at J
END IF
100 CONTINUE
WRITE (99,*) '------+++++++++++++++++-------------+++++++++++++-------------------'
120 CONTINUE
RETURN
END
! The initial valuess
SUBROUTINE PDEIV1(NPTS,NPDE,T,X,Y,U)
! .. Scalar Arguments ..
DOUBLE PRECISION T, ENDOWMENT, PENALTY
INTEGER NPDE, NPTS
! .. Array Arguments ..
DOUBLE PRECISION U(NPTS,NPDE), X(NPTS), Y(NPTS)
! ...common blocks... I added, not all variables used. MU, SIGMA, INTEREST may be removed
COMMON /PARAM1/PENALTY, ENDOWMENT, MACOST, INTEREST, MU, SIGMA
! .. Local Scalars ..
DOUBLE PRECISION TOL !
INTEGER I
! .. Executable Statements ..
TOL = 10.D0*X02AJF()
DO 20 I = 1, NPTS
IF( (X(I)-ENDOWMENT) .GE. TOL) THEN
!write(*,*) 'emission amount=', X(I), 'endowment=', ENDOWMENT, 'penalty= ', PENALTY
!read(*,*)
U(I,1) = (X(I)-ENDOWMENT)*PENALTY
!write(*,*) 'penalty payment= ', U(I,1)
!read(*,*)
ELSE
U(I,1) = 0.0D0
END IF
20 CONTINUE
RETURN
END
!Definition of the PDE, equation (1) in the Document
SUBROUTINE PDEF1(NPTS,NPDE,T,X,Y,U,UT,UX,UY,UXX,UXY,UYY,RES)
! .. Scalar Arguments ..
DOUBLE PRECISION T
INTEGER NPDE, NPTS
! .. Array Arguments ..
DOUBLE PRECISION RES(NPTS,NPDE), U(NPTS,NPDE), UT(NPTS,NPDE),&
UX(NPTS,NPDE), UXX(NPTS,NPDE), UXY(NPTS,NPDE),&
UY(NPTS,NPDE), UYY(NPTS,NPDE), X(NPTS), Y(NPTS)
! .. Scalars in Common ..
DOUBLE PRECISION PENALTY, ENDOWMENT, MACOST, INTEREST, MU, SIGMA
! .. Local Scalars ..
INTEGER I
! .. Intrinsic Functions ..
INTRINSIC EXP
! .. Common blocks ..
COMMON /PARAM1/PENALTY, ENDOWMENT, MACOST, INTEREST, MU, SIGMA
! .. Executable Statements ..
DO 20 I = 1, NPTS
RES(I,1) = UT(I,1) - INTEREST*U(I,1) - 0.5D0*UX(I,1)*UX(I,1)/MACOST + Y(I)*UX(I,1) + MU*Y(I)*UY(I,1) + 0.5D0*UYY(I,1)*SIGMA*SIGMA*Y(I)*Y(I)
20 CONTINUE
RETURN
END
! SUBROUTINE BNDRY1(NPTS,NPDE,T,X,Y,U,UT,UX,UY,NBPTS,LBND,RES)
! .. Scalar Arguments ..
! DOUBLE PRECISION T
! INTEGER NBPTS, NPDE, NPTS
!.. Array Arguments ..
! DOUBLE PRECISION RES(NPTS,NPDE), U(NPTS,NPDE), UT(NPTS,NPDE),&
! UX(NPTS,NPDE), UY(NPTS,NPDE), X(NPTS), Y(NPTS)
! INTEGER LBND(NBPTS)
! .. Local Scalars ..
! DOUBLE PRECISION TOL
! INTEGER I, J
!
! .. External Functions ..
! DOUBLE PRECISION X02AJF
! EXTERNAL X02AJF ! The machine precision
! .. Intrinsic Functions ..
! INTRINSIC ABS
! .. Executable Statements ..
! TOL = 10.D0*X02AJF()
! DO 20 I = 1, NBPTS
! J = LBND(I)
! IF (ABS(X(J)).LE.TOL) THEN
! RES(J,1) = UX(J,1)
! ELSE IF (ABS(X(J)-1.0D0).LE.TOL) THEN
! RES(J,1) = U(J,1) - 1.0D0
! ELSE IF (ABS(Y(J)).LE.TOL) THEN
! RES(J,1) = UY(J,1)
! ELSE IF (ABS(Y(J)-1.0D0).LE.TOL) THEN
! RES(J,1) = U(J,1) - 1.0D0
! END IF
! 20 CONTINUE
!
! RETURN
! END
SUBROUTINE MONIT1(NPDE,T,DT,DTNEW,TLAST,NLEV,NGPTS,XPTS,YPTS,LSOL,SOL,IERR)
! .. Parameters ..
INTEGER NOUT
PARAMETER (NOUT=6)
! .. Scalar Arguments ..
DOUBLE PRECISION DT, DTNEW, T
INTEGER IERR, NLEV, NPDE
LOGICAL TLAST
! .. Array Arguments ..
DOUBLE PRECISION SOL(*), XPTS(*), YPTS(*)
INTEGER LSOL(NLEV), NGPTS(NLEV)
! .. Scalars in Common ..
INTEGER IOUT
! .. Arrays in Common ..
DOUBLE PRECISION TWANT(2)
! .. Local Scalars ..
INTEGER I, IPSOL, IPT, LEVEL, NPTS
! .. Common blocks ..
COMMON /OTIME1/TWANT, IOUT
! .. Executable Statements ..
IF (TLAST) THEN
! Print solution at the time T controlled by IOUT
IF (IOUT.EQ.1) THEN
WRITE (99,'('' Solution at every 4th grid point '', ''in level 1 at time '', F8.4,'':'')') T
WRITE (99,*)
WRITE (99,'(7X,''x'',10X,''y'',8X,''approx u'')')
WRITE (99,*)
LEVEL = 1
NPTS = NGPTS(LEVEL) ! total points on the first level. grid levels are in the y direction
IPSOL = LSOL(LEVEL)
IPT = 1
DO 20 I = 1, NPTS, 4
WRITE (99,'(3(1X,E11.4))') XPTS(NGPTS(1)+IPT+I-1),YPTS(NGPTS(1)+IPT+I-1), SOL(IPSOL+I)
20 CONTINUE
WRITE (99,*)
END IF
END IF
RETURN
END