Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

weird storage behaviotr leading to segfault

Status
Not open for further replies.

svar

Programmer
Aug 12, 2001
349
0
0
GR
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​

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top