×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

weird storage behaviotr leading to segfault

weird storage behaviotr leading to segfault

weird storage behaviotr leading to segfault

(OP)
I need to pass a set of arrays to a program that does the work (e.g. an ODe solver). Now the way this is written is it allows a parameter array RPAR which is a 1-d double precision array
However, the parameters that must be passed are a number of multidimensional arrays, and in once case a complex *16 array. As far as I know 2D arrays in Fortran are always stored by columns and a complex *16 value is two contiguous double precision reals. The minimal example showing the problem is this:
implicit double precision(a-h,o-z)
complex*16, DIMENSION (:,:), ALLOCATABLE :: evecs
double precision, dimension (:), allocatable :: evals,rpar
n=3
c allocate space
allocate (evecs(N,n ), stat=iaLLOCATEstatus)
if (IALLOCATEstatUS /= 0) then
write(6,*)'ERROR trying to allocate evecs '
stop 1
end if
allocate (evals(N ), stat=iaLLOCATEstatus)
if (IALLOCATEstatUS /= 0) then
write(6,*)'ERROR trying to allocate evals '
stop 1
end if
allocate (rpar(N*(2*N+1) ), stat=iaLLOCATEstatus)
if (IALLOCATEstatUS /= 0) then
write(6,*)'ERROR trying to allocate rpar '
stop 1
end if
c fill the data structures we will work with
do 1 i=1,n
evals(i)=1.d0*i
write(6,*)'evals(',i,')=',evals(i)
do 2 j=1,n
evecs(j,i)=dcmplx(i*1.d0,-j*1.d0)
write(6,*)'evecs(',j,i,')=',evecs(j,i)
2
continue
1
continue
c because the processing routine wants all parameters in a single double precision array rpar, do that
DO 11 I=1,N
RPAR(I)=EVALS(I)
11
CONTINUE
indx=n
DO 12 I=1,N
DO 13 J=1,N
INDX=INDX+1
RPAR(INDX)=DREAL(EVECS(J,I))
INDX=INDX+1
RPAR(INDX)=DIMAG(EVECS(J,I))
13
CONTINUE
12
CONTINUE
call bigroutine(n,rpar)
deallocate (rpar, stat=IALLOCATEstatus)
deallocate (evals, stat=IALLOCATEstatus)
deallocate (evecs, stat=IALLOCATEstatus)

end
subroutine bigroutine(n,rpar)
double precision rpar(*)
c here the main work is none. But it needs to work with evals ane evecs
call process(n,rpar)
return
end


subroutine process(n,evals,evecs)
complex*16 evecs(n,n)
double precision evals(n)
do 1 i=1,n
write(6,*)'evals(',i,')=',evals(i)
1
continue
indx=n
do 2 i=1,n*n
c row:

icol=1+(i-irow)/n
irow=mod(i,n)
if(irow.eq.0)then
irow=n
icol=i/n
endif
write(6,*)'evecs(',irow,icol,')=',evecs(irow,icol)
2
continue
return
end

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close