From: rudra on
Dear friends, few days back , i asked your help on a "gfortran
problem"

subroutine
coefficient(istart,lorbit,nrec,nsite,nmax,nn,cmat,dmat)
implicit none
integer:: i,j,k,q,orb,rcs,site,itr,sorbit,strstat,torbit
integer::nn,lorbit,nrec,istart,cnt,nsite,nmax
real(8):: pp,d11,d12,d22
! real(8),dimension(nmax,9)::h1,h2,h3
! integer,dimension(nsite,nn)::npos
real(8),dimension(:,:),allocatable::h1,h2,h3
integer,dimension(:,:),allocatable::npos
real(8),dimension(0:nn,9,9)::str
real(8),dimension(9):: cmat,dmat
real(8),dimension(9,9)::str1
real(8),dimension(nrec+1)::alpha
real(8),dimension(0:nrec+1)::beta
character(8)cdum1
character(40)cdum2
allocate(h1(nmax,lorbit),h2(nmax,lorbit),h3(nmax,lorbit))
allocate(npos(nsite,nn))
.
.
.
so on

when i am directly assigneing the value of h1,h2, h3 and npos,
the code is working fine with ifort but fails on other compiler. but
if I am trying to use dynamic allocation, its coming out with error:
*** glibc detected *** ./run.out: munmap_chunk(): invalid pointer:
0x400bc008 ***
======= Backtrace: =========
/lib/libc.so.6(cfree+0x1bb)[0x5f321b]
../run.out[0x806b93b]
../run.out[0x804bda6]
../run.out[0x804c8d3]
../run.out[0x8049bc1]
/lib/libc.so.6(__libc_start_main+0xe0)[0x59c390]
../run.out[0x8049ad1]
======= Memory map: ========
00567000-00582000 r-xp 00000000 08:07 4859005 /lib/ld-2.7.so
00582000-00583000 r-xp 0001a000 08:07 4859005 /lib/ld-2.7.so
00583000-00584000 rwxp 0001b000 08:07 4859005 /lib/ld-2.7.so
00586000-006d9000 r-xp 00000000 08:07 2457626 /lib/libc-2.7.so
006d9000-006db000 r-xp 00153000 08:07 2457626 /lib/libc-2.7.so
006db000-006dc000 rwxp 00155000 08:07 2457626 /lib/libc-2.7.so
006dc000-006df000 rwxp 006dc000 00:00 0
006e1000-00708000 r-xp 00000000 08:07 2457630 /lib/libm-2.7.so
00708000-00709000 r-xp 00026000 08:07 2457630 /lib/libm-2.7.so
00709000-0070a000 rwxp 00027000 08:07 2457630 /lib/libm-2.7.so
0070c000-0070f000 r-xp 00000000 08:07 2457627 /lib/libdl-2.7.so
0070f000-00710000 r-xp 00002000 08:07 2457627 /lib/libdl-2.7.so
00710000-00711000 rwxp 00003000 08:07 2457627 /lib/libdl-2.7.so
08048000-080c5000 r-xp 00000000 00:1c 11714571 /matsc/students/Rudra/
Recursion/Real/run.out
080c5000-080ca000 rwxp 0007c000 00:1c 11714571 /matsc/students/Rudra/
Recursion/Real/run.out
080ca000-080ce000 rwxp 080ca000 00:00 0
08e1b000-08e63000 rwxp 08e1b000 00:00 0
40000000-40001000 r-xp 40000000 00:00 0 [vdso]
40001000-40002000 rwxp 40001000 00:00 0
40021000-4002d000 r-xp 00000000 00:1c 23593507 /matsc/students/Rudra/
gfortran/lib/libgcc_s.so.1
4002d000-4002e000 r-xp 0000b000 00:1c 23593507 /matsc/students/Rudra/
gfortran/lib/libgcc_s.so.1
4002e000-4002f000 rwxp 0000c000 00:1c 23593507 /matsc/students/Rudra/
gfortran/lib/libgcc_s.so.1
4002f000-40102000 rwxp 4002f000 00:00 0
bf95f000-bf974000 rwxp bffea000 00:00 0 [stack]
forrtl: error (76): Abort trap signal
Image PC Routine Line
Source
.. 40000402 Unknown Unknown Unknown
libc.so.6 005B0F91 Unknown Unknown Unknown
libc.so.6 005E79EB Unknown Unknown Unknown
libc.so.6 005F321B Unknown Unknown Unknown
run.out 0806B93B Unknown Unknown Unknown
run.out 0804BDA6 Unknown Unknown Unknown
run.out 0804C8D3 Unknown Unknown Unknown
run.out 08049BC1 Unknown Unknown Unknown
libc.so.6 0059C390 Unknown Unknown Unknown
run.out 08049AD1 Unknown Unknown Unknown
../run.sh: line 58: 25230 Aborted ( ./run.out )
Calculation aborted....rerun!!

this is giving problem for all the compiler
again if i dont modularize the program, it is working fine...so i
first suspect some problem in transfering nmax,nsite...but later
verified that it is not so. i have also checked ulimit -s unlimited
and
ifort -heap-arrays but didnt help either. any suggestion?
From: Richard Maine on
rudra <bnrj.rudra(a)gmail.com> wrote:

> subroutine
> coefficient(istart,lorbit,nrec,nsite,nmax,nn,cmat,dmat)
....
> real(8),dimension(:,:),allocatable::h1,h2,h3
> integer,dimension(:,:),allocatable::npos
.....
> when i am directly assigneing the value of h1,h2, h3 and npos,
> the code is working fine with ifort but fails on other compiler. but
> if I am trying to use dynamic allocation, its coming out with error:

At least we have some actual code to look at this time. We don't have
enough of the code to show the problem... but fortunately, we have
enough to make a good guess from.

In general, you really need to show more of the relevant code, In this
case, the code that calls this subroutine is very relevant... in fact,
that's where the whole problem probably is... but you haven't shown it.
We have enough information to make a pretty good guess from, but it
would make things much simpler to diagnose if we didn't have to guess.
That's an incredibly important and fundamental party of getting
debugging help (and it comes up all the time - you aren't alone in it.)

I'm almost certain that your problem is that the subroutine doesn't have
an explicit interface in the place where it is called from. Many
features relating to procedures require explicit interfaces. I recommend
that you just make it a habit to have explicit interfaces for all
procedures. That way you don't have to memorize the longish list of
exact conditions under which you need one. Besides which, explicit
interfaces substantially improve the odds of the compiler catching some
kinds of errors that can otherwise be subtle to debug.

Allocatable dummy arguments are one of the many things that require an
explicit interface. If you don't provide one, the argument passing is
likely to get "all messed up", which can cause any number of symptoms.
The explicit interface tells the compiler to pass what is needed for
allocatable dummy arguments to work.

There are severall ways to provide an explicit interface.

For most purposes, I recommend putting all subroutines in modules and
then USEing those modules. The USE statement then provides the explicit
interface.

For small programs, you can put the subroutines as internal subroutines
of the main program. That also provides an explicit interface without
much manual "fuss", but it doesn't grow well to larger applications.

Another way is to write an interface block for the subroutine. I don't
usually recommend that one for most uses. I consider it laborious and
error prone. Some transitioning f77 programers latch on to it as
requiring less of a change from practices they are used to. I think that
unfortunate, because it leaves them with the impression that things are
much harder.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
From: Greg Lindahl on
In article <47fea16c-b9d1-4b29-85d4-789ef42f6e74(a)i36g2000prf.googlegroups.com>,
rudra <bnrj.rudra(a)gmail.com> wrote:

>Dear friends, few days back , i asked your help on a "gfortran
>problem"

Right. The answer this time is the same as last time. Try turning on
bounds checking, and if that doesn't reveal your error, run it under
valgrind.

-- greg

From: Les on

"rudra" <bnrj.rudra(a)gmail.com> wrote in message
news:47fea16c-b9d1-4b29-85d4-789ef42f6e74(a)i36g2000prf.googlegroups.com...
> Dear friends, few days back , i asked your help on a "gfortran
> problem"
<snip>

> allocate(h1(nmax,lorbit),h2(nmax,lorbit),h3(nmax,lorbit))

In addition to what others have written. I recommend allocate one array at a
time and use the error status to verify success, especially if the problem
domain is large. Then if an allocate fails you may gracefully terminate the
program and can even inform the user why. Or choose an alternative option.
( I saw code some time ago which used a file to store data if it was unable
to allocate sufficient memory. It may have made that part of the code run
slower but at least it didn't just die.)

<snip> .

> 08048000-080c5000 r-xp 00000000 00:1c 11714571 /matsc/students/Rudra/
> Recursion/Real/run.out
> 080c5000-080ca000 rwxp 0007c000 00:1c 11714571 /matsc/students/Rudra/
> Recursion/Real/run.out

This may be irrelevant but I notice the word "Recursion" in there.
Are you using recursion in your code? If so it could indicate a possible
problem area.

Les


From: rudra on
This is my full code; however, it reads a very large file nn-
bcc.dat(102719 ) and some other file like pot and struct which is not
writable here as u can understand. if someone(as Richard Maine asked)
to send me those file , i am ready to send that to them ...but in that
case i need their email so that i can attach the file. looking fwd
for your support



!FILE CMAT
-0.254762493737499
-1.29898640827846
-1.29898640827846
-1.29898640827846
0.563874755720254
0.563874755720254
0.563874755720254
0.563874755720254
0.563874755720254

!FILE DMAT
0.108095140482755
-0.184404840578172
-0.184404840578172
-0.184404840578172
9.942824921491064E-002
9.942824921491064E-002
9.942824921491064E-002
9.942824921491064E-002
9.942824921491064E-002

!INPUT
&INPUT
!---------------------------
!INPUT FILE FOR RECURSION -
!---------------------------
istart= 0,
nsite= 3721,
nmax= 3969,
lorbit= 9,
nn= 8,
nrec= 10,
alps= 0.35d0,
alpp= 0.057167d0,
alpd= 0.016807d0
$end


!the program
!-------------------------------------------
! This is the main driver routine
! for the recursion calculation.
! It reads the the input value from
! the file parameter.f90 and transfers
! those values to the subroutines
! g2a, potential and coefficient
! that it calls
!-------------------------------------------

program main
implicit none
integer:: i,j,k,l
real(8)::es,cs,ds,xx,gs,ep,cp,dp,gp,ed,cd,dd,gd
real(8)::dels,delp,deld,rs,rp,rd
real(8):: dsqs,dsqp,dsqd,ccs,ccp,ccd,os,op,od
real(8),dimension(9)::dmat,cmat
integer::istart
integer::nsite,nmax
integer::lorbit
integer::nn
integer::nrec
real(4)::enmin
real(4)::enmax
real(8)::alps,alpp,alpd
character::x0
NAMELIST /input/ istart,nsite,nmax,lorbit,nn,nrec, &
& enmin,enmax,alps,alpp,alpd
read(5,nml= input )

open(10,file='DATA/pot',status='old')
read(10,*)es,cs,ds,xx,gs,xx
read(10,*)ep,cp,dp,xx,gp,xx
read(10,*)ed,cd,dd,xx,gd,xx
close(10)

31 format( "Doing recursion for ",i7, " atom; upto 2nd nearest &
& neighbour i.e. ",i2," atom")
write(*,31) nsite,nn


call coefficient(istart,lorbit,nrec,nsite,nmax,nn,cmat,dmat)

end program main


!-------------------------------------------
! Creating the coefficients
! alpha and beta
!-------------------------------------------
subroutine coefficient(istart,lorbit,nrec,nsite,nmax,nn)
implicit none
integer:: i,j,k,q,orb,rcs,site,itr,sorbit,strstat,torbit
integer::nn,lorbit,nrec,istart,cnt,nsite,nmax
real(8):: pp,d11,d12,d22
! real(8),dimension(nmax,9)::h1,h2,h3
! integer,dimension(nsite,nn)::npos
real(8),dimension(:,:),allocatable::h1,h2,h3
integer,dimension(:,:),allocatable::npos
real(8),dimension(0:nn,9,9)::str
real(8),dimension(9):: cmat,dmat
real(8),dimension(9,9)::str1
real(8),dimension(nrec+1)::alpha
real(8),dimension(0:nrec+1)::beta
character(8)cdum1
character(40)cdum2
allocate(h1(nmax,lorbit),h2(nmax,lorbit),h3(nmax,lorbit))
allocate(npos(nsite,nn))
open(3,file='cmat',status='old')
read(3,*)cmat
open(4,file='dmat',status='old')
read(4,*)dmat

sorbit=1
if (istart==1)then
open(20,file='rerun',status='old')
read(20,'(a8,i1)')cdum1,strstat
read(20,'(a40,i1)')cdum2,torbit
close(20)
if ((torbit >=1).and.(torbit<9)) then
sorbit=torbit+1
write(*,'(a46,1x,i1)') "rerun.....restarting calculation from
orbital",sorbit
end if
if (torbit==9)write(*,*) "Job is over...you idiot!!!check the
result!"
end if

open(20,file='DATA/nn-bcc.dat',status='old')
do i=1,nsite
read(20,*) nsite,(npos(i,j),j=1,nn)
end do
close(20)

open(21,file='DATA/structure',status='old')
do i=0,nn
read(21,*)
read(21,*)
read(21,*)
do j=1,lorbit
read(21,*) (str(i,j,k),k=1,lorbit)
end do
end do
close(21)
! INITIALIZE THE BASIS
h3(:,:)=0.0d0
h1(:,:)=0.0d0
h2(:,:)=0.0d0

if (istart==0)then
open(22,file='RESULT/ab.dat',status='replace')
else
open(22,file='RESULT/ab.dat',status='old',position='append')
end if

open(14,file='startmode',status='replace')
write(14,'(a7,1x,i1)') "istart=",istart
orbit: do orb=sorbit,lorbit
! write(*,*) 'orbit =',orb
h1(1,orb)=1.0d0
alpha=0.0d0
beta =0.0d0
rcstp: do rcs=1,nrec
!`````````````````````````````````````````
! CALCULATION OF h STARTS `
!`````````````````````````````````````````
sitestp: do site=1,nsite
do i=1,lorbit
h2(site,i)=h2(site,i)+(cmat(i)+dmat(i)*str(0,i,i)&
*dmat(i))*h1(site,i)
end do

nnloop: do itr=1,nn
k=npos(site,itr)
do i=1,9
do j=1,9
str1(i,j)=dmat(i)*str(itr,i,j)*dmat(j)
end do
end do

do i=1,lorbit
pp=0.0d0
do j=1,lorbit
pp=pp+str1(i,j)*h1(site,j)
end do
h2(k,i)=h2(k,i)+pp
end do
end do nnloop
end do sitestp
!`````````````````````````````````````````
! CALCULATION OF h FINISHED `
!`````````````````````````````````````````

!`````````````````````````````````````````
! CALCULATION OF COEFFICIENTS `
! alpha and beta starts `
!`````````````````````````````````````````
beta(0)=1.0d0
d11=0.0d0
d12=0.0d0
do i=1,nmax
do j=1,lorbit
d11=d11+h1(i,j)*h1(i,j)
d12=d12+h1(i,j)*h2(i,j)
end do
end do
alpha(rcs)=d12/d11

do i=1,nmax
do j=1,lorbit
h2(i,j)=h2(i,j)-alpha(rcs)*h1(i,j)-beta(rcs-1)*h3(i,j)
end do
end do

d22=0.0d0
do i=1,nmax
do j=1,lorbit
d22=d22+h2(i,j)*h2(i,j)
end do
end do

beta(rcs)=d22/d11
!`````````````````````````````````````````
! CALCULATION OF COEFFICIENTS `
! alpha and beta over `
!`````````````````````````````````````````

h3=h1
h1=h2
h2=0.0d0

end do rcstp
! writing results ro file
do q=1,nrec
write(22,*) q,alpha(q),beta(q)
end do
! write(22,*) ""
write(*,*) ""

write(*,'(a28,1x,i1)')"calculation done for orbital",orb
write(14,*)"calculation done for orbital",orb
backspace(14)
end do orbit
! deallocate(h1,h2,h3,npos)
close(22)
end subroutine coefficient