Segmentation Faults (newbie)


bus_wrecker
03-28-2006, 10:04 PM
hi there,

i'm getting segmentation faults in my fortran program after succesfully compiling it.

here's the code

PROGRAM EGFR

USE nrtype; USE nrutil; USE nr
IMPLICIT NONE
REAL(SP)::x1,x2,eps,h1,hmin
REAL(SP),DIMENSION(2)::ystart

INTERFACE
SUBROUTINE derivs(x,y,dydx)
USE nrtype
IMPLICIT NONE
REAL(SP)::x
REAL(SP),DIMENSION(:)::y
REAL(SP),DIMENSION(:)::dydx
END SUBROUTINE
END INTERFACE

ystart(1)=0.1_sp
ystart(2)=1.1_sp
x1=0.0_sp
x2=1.0_sp
eps=10e-6
h1=1.0_sp
hmin=1.0_sp

CALL odeint(ystart,x1,x2,eps,h1,hmin,derivs,rkqs)

END PROGRAM

and my derivs subroutine


SUBROUTINE derivs(x,y,dydx)
USE nrtype
IMPLICIT NONE
REAL(SP)::x
REAL(SP),DIMENSION(4)::k
REAL(SP),DIMENSION(2)::y
REAL(SP),DIMENSION(2)::dydx

k(1)=0.2
k(2)=3
k(3)=2
k(4)=1

dydx(1)=k(1)*y(1)-k(2)*y(2)
dydx(2)=-k(3)*y(1)+k(4)*y(2)


END SUBROUTINE derivs


I'm currently using all the subroutines used to solve ODES listed in the book, which are odeint, rkqs, and rkck. I compiled it with the header files too, nr.f90, nrutil.f90, and nrtype.f90.

Is there a problem in the usage of the odeint function? have i declared something wrongly? I just want to get the program working to solve a small system of ODEs before i move on to a bigger problem.

regards

Julian Lee

ps- Compiler is g95 - from http://g95.sourceforge.net/

Foster Morrison
03-29-2006, 09:47 AM
I had this problem a long time ago when I first got my ancient Lahey Fortran77 for MS-DOS. The compiler would generate source code with, as I recall, only 64 segments of RAM. I set this for maybe 256. The problem was that MS-DOS coul handle programs with more than 64 segments of RAM. If you have a Windows or Linux based Fortran, the number of possible segements could be quite large. Check out the subject in your Fortran compiler documentation or contact the vendor.

bus_wrecker
03-31-2006, 04:30 AM
I had this problem a long time ago when I first got my ancient Lahey Fortran77 for MS-DOS. The compiler would generate source code with, as I recall, only 64 segments of RAM. I set this for maybe 256. The problem was that MS-DOS coul handle programs with more than 64 segments of RAM. If you have a Windows or Linux based Fortran, the number of possible segements could be quite large. Check out the subject in your Fortran compiler documentation or contact the vendor.

mr. foster morrison, thank you for your reply.

hmm. i've tried using the f90 compiler on a UNIX IBM workstation. i can compile it with the f90 compiler (no changes were made to the source code).

I had the following errors,
CALL odeint(ystart,x1,x2,eps,h1,hmin,derivs,rkqs)
^
Error 960 at (27:testing2.f) : This subroutine has the wrong number of arguments or arguments with the wrong name, type or rank

wrong number of arguments? anyone familiar with the odeint subroutine in the nr book?
am i missing out something?

regards

Foster Morrison
04-05-2006, 09:41 AM
The parameter for number of segments allowed may have to be set for the linker. I am attaching a copy of the MS-DOS batch file (with the extension as *.txt rather than *.bat, as required by this forum) that demonstrates this (... LINK %1.obj/se:256..., LINK.EXE is the MS-DOS linker). Your compiler, of course, wil do the same thing in a very different way. The compiler probably includes its own linker and so the doumentation SHOULD tell you what to do to handle more segments.

Foster Morrison
04-11-2006, 03:57 PM
Back again. This system of 2 ODEs is linear, has constant coefficients and is very small, so one can easily computer the 2 eigenvalues. I get (approximately) 3.08 and -1.88. The positive eigenvalue shows the solution is unstable (going forward in time) and will be pretty much exponential growth, since the part of the solution with a negative eigenvalue will dampen rapidly. I have a brief synopsis of the theory in "The Art of Modeling Dynamic Systems," but for a detailed treatment in matrix notation see Dave Luenberger's "Introduction to Dynamic Systems." Most introductory ODE texts give just a minimal treatment with simple characteristic polynomials rather than matrix eigenvalues. The fullblown matrix deal is good for stability analysis of nonlinear systems too - same 2 references for that. I also made another attempt to attach that batch file, and it seems to have worked.