Jaehoon Seol wrote:
>
> 1. Can anyone tell me why the ouput of the array content a in testGSolver
> is different from that of the array content a in dgeco.
You have a type in the call statement
>
> 2. I also appreciate if you can tell me what difference there is between
> double precision a(lda,1)
> and
> double precision a(lda,n)
Both declare a two dimension array. The first is essentially a column
vector. The second declares a two dimensional array and the second
bound is "n" rather than "1". It is possible and legal for n to be
1, but the compiler will generate code to handle any value. In the
first case it can (and usually will) ignore the second dimension for
code generation purposes.
The first was a common practice in the good old days and declared the
array as a two dimensional array and implied that the compiler didn't
need to worry about what the second dimension was; the programmer
promised
to always do the right thing. Programs that did this were usually
non-standard because they exceeded the array bounds in the second
dimension. A standard conforming way to do this is to use (lda,*)
for the dimensions.
For people who write explicit DO loops to do their array work, and who
do not turn on bounds checking, they are about the same. If you use
array processing statements, like a=10, then the compiler needs to know
both subscript bounds and you will get different results.
Dick Hendrickson
>
> Thanks.
>
> ========= calling program testSolver.f90 in fortran 90 =========
> !! In this program, we are solving the following system
> !! Ax = b
> !! using Gaussian Elimination
>
> program testGSolver
> implicit none
>
> integer, parameter :: dp = kind(1.0d0), &!
> d = 2
> real(kind=dp),dimension(d,d) :: a
> real(kind=dp),dimension(d) :: extras
> real(kind=dp) :: cond_num
> integer,dimension(d) :: pivot_info
> integer :: nrow
>
>
>
>
> a = reshape((/1,2,3,5/),(/2,2/)) ! initialization of the array
> nrow = d
> call dgeco(at,nrow,nrow,pivot_info,cond_num,extras)
here you use ^^ at as the argument, but you dimensioned the array
as "a"
In effect youy are passing a scalar variable to a subroutine which
treats
it as an array and most likely overwrites some other variables.
> print *, a(1,:)
> print *, a(2,:)
> print *, "pivot information: ", pivot_info
> print *, "condition number : ", cond_num
>
> end program testGSolver
>
> =========== called program dgeco.f in fortran 77 ===============
> subroutine dgeco(a,lda,n,ipvt,rcond,z)
> integer lda,n,ipvt(1)
>
> ! double precision a(lda,1),z(1)
>
> double precision a(lda,n),z(1)
> double precision rcond
>
> print *,"dgeco : lda = ", lda
> print *,"dgeco : n = ", n
> print *,"dgeco : shape of a =: ",shape(a)
>
> a = 10
> a(1,1) = 11
>
> print *,"dgeco : ",a(1,:)
> print *,"dgeco : ",a(2,:)
>
> return
> end
>
> =========== output result ====================
> dgeco : lda = 2
> dgeco : n = 2
> dgeco : shape of a = 2 2
> dgeco : 11.0 10.0
> dgeco : 10.0 10.0
> 1.0 3.0
> 2.0 5.0
> pivot information: 0 0
> condition number : 0.0
>
> -----------------------------------------------------------
> Jaehoon,Seol e-mail : [log in to unmask]
> www : http://www.math.uiowa.edu/~seol
> Only the person born without mother can be free.
> -----------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|