Prev: #define in fortran
Next: Graphics Lib Help
From: a.e.pace on 30 Oct 2006 21:49 All: I have a code that successfully compiles on my machine, but does not run properly. When I compile with the intel fortran compiler, I get the following error: forrtl: severe (180): SIGBUS, bus error occurred Stack trace terminated abnormally. When I compile with gfortran, I get the following error: "Bus error" I believe that the error lies somewhere in how I allocate the array "Y" and pass it to various subroutines. I will attach my code after this message. Any thoughts or assistance on the matter would be greatly appreciated. My warmest thanks, Alexander Pace Georgia Institute of Technology School of Aerospace Engineering. Code: program visc c use global allocatable Y(:,:) c.... enter number of subdivisions from n=0->4.8 numsubs= 100 c.... step size dn=4.8/numsubs c... define upper and lower bounds for y3(0) (xu and xl) xl=0 xu=2 c.... Start bisection method do while (xu-xl .gt. 0.000001) xm=(xu-xl)/2 c.... Perform Runge-Kutta Integrations to get values of y2(4.8) at top, c.... lower, and midpoint c allocate (Y(3,1000)) call runge(Y,xu,numsubs,dn) gu = Y(2,numsubs) - 1 call runge(Y,xl,numsubs,dn) gl = Y(2,numsubs) - 1 call runge(Y,xm,numsubs,dn) gm = Y(2,numsubs) - 1 c.... Check for location of root, change bounds if (gl*gm .lt. 0) then xu = xm else if (gl*gm .gt. 0) then xl = xm else if (gl*gm .eq. 0) then xl = xu endif end do print *, "y3(0)=", Y(3,1) end c.... This subroutine integrates the function y3 up one step, dn subroutine integratey3(y1i,y2i,y3i,y3n,dn) implicit double precision (a-h, o-z) g1= y2i**2-y1i*y3i-1 g2= (y2i+.5*g1)**2-(y1i+.5*g1)*(y3i+.5*g1)-1 g3= (y2i+.5*g2)**2-(y1i+.5*g2)*(y3i+.5*g2)-1 g4= (y2i+g3)**2-(y1i+g3)*(y3i+g3)-1 y3n= y3i+dn*(g1+2*g2+2*g3+g4)/6 return end c.... This subroutine integrates y2 up one step, dn subroutine integratey2(y2i,y3i,y2n,dn) implicit double precision (a-h, o-z) g1=y3i g2=y3i+.5*g1 g3=y3i+.5*g2 g4=y3i+g3 y2n= y2i+dn*(g1+2*g2+2*g3+g4)/6 return end c.... This subroutine integrates y1 up one step, dn subroutine integratey1(y1i,y2i,y1n,dn) implicit double precision (a-h, o-z) g1=y2i g2=y2i+.5*g1 g3=y2i+.5*g2 g4=y2i+g3 y1n= y1i+dn*(g1+2*g2+2*g3+g4)/6 return end c.... This subroutine inputs the matrix Y and an initial value for c.... y3(0) and performs the runge kutta integration from n=0->4.8 subroutine runge(Y,y3init,numsubs,dn) c use global real Y(:,:) c.... define initial conditions Y(1,1)=0 Y(2,1)=0 Y(3,1)=y3init y1n=0 y2n=0 y3n=0 c.... let 'er rip do i=2, numsubs-1 y1i=Y(1,i) y2i=Y(2,i) y3i=Y(3,i) call integratey3(y1i,y2i,y3i,y3n,dn) Y(3,i+1)=y3n call integratey2(y2i,y3i,y2n,dn) Y(2,i+1)=y2n call integratey1(y1i,y2i,y1n,dn) Y(1,i+1)=y1n end do return end
From: Gordon Sande on 31 Oct 2006 08:29 On 2006-10-30 22:49:37 -0400, a.e.pace(a)gmail.com said: > All: > I have a code that successfully compiles on my machine, but does > not run properly. When I compile with the intel fortran compiler, I > get the following error: > > forrtl: severe (180): SIGBUS, bus error occurred > > Stack trace terminated abnormally. > > When I compile with gfortran, I get the following error: > "Bus error" > > I believe that the error lies somewhere in how I allocate the array "Y" > and pass it to various subroutines. I will attach my code after this > message. Any thoughts or assistance on the matter would be greatly > appreciated. > > My warmest thanks, > > Alexander Pace > Georgia Institute of Technology > School of Aerospace Engineering. > > Code: > program visc > c use global > allocatable Y(:,:) > c.... enter number of subdivisions from n=0->4.8 > numsubs= 100 > c.... step size > dn=4.8/numsubs > > c... define upper and lower bounds for y3(0) (xu and xl) > xl=0 > xu=2 > > c.... Start bisection method > do while (xu-xl .gt. 0.000001) > xm=(xu-xl)/2 > > c.... Perform Runge-Kutta Integrations to get values of y2(4.8) at top, > c.... lower, and midpoint > > c allocate (Y(3,1000)) > call runge(Y,xu,numsubs,dn) > gu = Y(2,numsubs) - 1 > > call runge(Y,xl,numsubs,dn) > gl = Y(2,numsubs) - 1 > > call runge(Y,xm,numsubs,dn) > gm = Y(2,numsubs) - 1 > > c.... Check for location of root, change bounds > if (gl*gm .lt. 0) then > xu = xm > else if (gl*gm .gt. 0) then > xl = xm > else if (gl*gm .eq. 0) then > xl = xu > endif > end do > > print *, "y3(0)=", Y(3,1) > > end > > > > c.... This subroutine integrates the function y3 up one step, dn > > subroutine integratey3(y1i,y2i,y3i,y3n,dn) > implicit double precision (a-h, o-z) > > g1= y2i**2-y1i*y3i-1 > g2= (y2i+.5*g1)**2-(y1i+.5*g1)*(y3i+.5*g1)-1 > g3= (y2i+.5*g2)**2-(y1i+.5*g2)*(y3i+.5*g2)-1 > g4= (y2i+g3)**2-(y1i+g3)*(y3i+g3)-1 > > y3n= y3i+dn*(g1+2*g2+2*g3+g4)/6 > > return > end > > c.... This subroutine integrates y2 up one step, dn > > subroutine integratey2(y2i,y3i,y2n,dn) > implicit double precision (a-h, o-z) > > g1=y3i > g2=y3i+.5*g1 > g3=y3i+.5*g2 > g4=y3i+g3 > > y2n= y2i+dn*(g1+2*g2+2*g3+g4)/6 > > return > end > > c.... This subroutine integrates y1 up one step, dn > > subroutine integratey1(y1i,y2i,y1n,dn) > implicit double precision (a-h, o-z) > > g1=y2i > g2=y2i+.5*g1 > g3=y2i+.5*g2 > g4=y2i+g3 > > y1n= y1i+dn*(g1+2*g2+2*g3+g4)/6 > > return > end > > c.... This subroutine inputs the matrix Y and an initial value for > c.... y3(0) and performs the runge kutta integration from n=0->4.8 > > subroutine runge(Y,y3init,numsubs,dn) > c use global > > real Y(:,:) ^^^^^^ The ":"s (assumed shape) require an "explicit" interface. I quote explicit as the usual way of getting one is to have the compiler gernerate it for you by use of a contained unit or a module unit. You might also have an interface block which is explicitly "explicit" but not recommended in practice. Any interesting F90 feature, like assumed shape (the ":"s), requires an explicit interface as opposed to an assumed interface that you get with an external statement or by calling an external unit. The terminology is not quite what you would guess by consulting an English dictionary but that is often the way of precise technical thinngs. So use modules. A quick fix is to use contains and make your subroutines internal. > c.... define initial conditions > Y(1,1)=0 > Y(2,1)=0 > Y(3,1)=y3init > y1n=0 > y2n=0 > y3n=0 > > c.... let 'er rip > do i=2, numsubs-1 > y1i=Y(1,i) > y2i=Y(2,i) > y3i=Y(3,i) > call integratey3(y1i,y2i,y3i,y3n,dn) > Y(3,i+1)=y3n > call integratey2(y2i,y3i,y2n,dn) > Y(2,i+1)=y2n > call integratey1(y1i,y2i,y1n,dn) > Y(1,i+1)=y1n > end do > > return > end
From: Les on 31 Oct 2006 09:36 In addition to what others have replied. <snip> > Code: > program visc > c use global > allocatable Y(:,:) > c.... enter number of subdivisions from n=0->4.8 > numsubs= 100 > c.... step size > dn=4.8/numsubs > > c... define upper and lower bounds for y3(0) (xu and xl) > xl=0 > xu=2 > > c.... Start bisection method > do while (xu-xl .gt. 0.000001) > xm=(xu-xl)/2 > > c.... Perform Runge-Kutta Integrations to get values of y2(4.8) at top, > c.... lower, and midpoint > > c allocate (Y(3,1000)) <snip> Assuming it's not a typo, remove the "c" at the beginning of the line so that Y is allocated. Also (again assuming not a typo) since the size of the allocation is fixed then either : (a) move the allocate outside of the do-loop. Its size determined by some means. or (b) Y doesn't need to be allocatable. If Y does need to be allocated to possibly different sizes for each iteration of the loop, then you will need to deallocate Y at the end of each iteration. Les
|
Pages: 1 Prev: #define in fortran Next: Graphics Lib Help |