Segmentation fault (Was: Runtime error in Forte compiled program) 
Author Message
 Segmentation fault (Was: Runtime error in Forte compiled program)

Hello fortran Gurus,

I have carefully checked program structure which I want to question
about (still may have some mistakes locatable by experienced people).
A while ago, I sent a wrong form of this structure which was also not
as clear as this one is. I apologize for previous unclear versions of
this problem.

My program structure is as follws:

Module Numeric_Constants
    Integer, Parameter :: dp=Selected_Real_Kind(P=14, R=300)  ! Double
Precision
End Module Numeric_Constants

! Globals.f90
Module Globals
   Use Numeric_Constants
   ......
   Integer :: n
   Real(kind = dp), Allocatable, Dimension(:) :: vec1, vec2
   Real(kind = dp), Allocatable, Dimension(:) :: res_vec
   ......
End Module Globals

! Other modules defining subroutines and using Globals module.
Module A
      Use Numeric_Constants
      Use Globals
Contains
       Subroutine first_in_A
           Allocate(vec1(n))
           Allocate(vec2(n))
           Allocate(res_vec(n))
           vec1 = 0.0_dp
           vec2 = 0.0_dp
       ....
           ! Some statements which assign new values to elements of
vec1 and vec2
       End Subroutine first_in_A
!
       Subroutine second_in_A
       ....
           Call first_in_A
           ! computation which are based on vectors vec1 and vec2 and
save the results in res_vec
           Call third_in_A
       End Subroutine second_in_A
!
       Subroutine third_in_A
                  ....
             Deallocate(vec1, vec2)   ! NOTE THAT res_vec IS NOT
DEALLOCATED HERE
      End Subroutine third_in_A
End Module A

Module B
Use A
Use Globals
Contains
       Subroutine first_in_B
       ....
           n = 6                                          ! or some
number
       ....
       End Subroutine first_in_B
!
       Subroutine second_in_B
             Call first_in_B
      ......
             Call second_in_A
       ....
             Deallocate(res_vec)
       End Subroutine second_in_B
End Module B
!
Main Program
===========
program main
  Use Numeric_Constants
  Use Globals
  Use A
  Use B

  ....

   Call Subroutine second_in_B
   ....
end program main

My questions:
=============
1) The actual program with this layout works perfectly on Nag f95 (Sun
Machines) and Compaq Fortran f95 (Alpha machines) compilers, and runs
smoothly with all optmization switches. Using Sun Forte Compiler
(Developer - 6U2), the actual program with same layout compiled and
ran smoothly upto the optmization level -O2.

The program worked smoothly with -g -O3 options, without indicating
any error and generated correct results. With -O3 option alone, it
terminated with a runtime {*filter*}TATION FAULT (core dump). Is this an
indication that this layout does not conform to a protable (standard)
way of writing Fortran programs?

2) As the segmentation faults commonly occur when the arrays access
memory contents such that their index variables have an invalid value,
I used the old style of programming and inserted a lot of WRTIE
statements to locate such a memory access. I could not find any such
array bound violation.

What can be possible reasons for this? I have learnt from other
persons' experience that some times segmentation faults are very hard
to trace as they may cause the program halt at a location in the code
which is far from the source of this error.

The exercise of inserting WRITE statements showed that the subroutine
second_in_A in module A did not 'know' about vec1 and vec2 global
arrays after the Call first_in_A in it. Upon USEing the module Globals
explicitly in the subroutine second_in_A, the program started working
smoothly even with -O3 option alone. But I donot need to USE Globals
explicitly there, as this is not standard.

However, it skewed the performance result (CPU time)of the actual
program with this layout, which I guess because of the extra 'Use
Globals' statement explicitly written in the subroutine second_in_A.

Please suggest to me other ways to track down the source of this
error. I have already tried the -C option on Forte compiler.

Thanks for your help
Mahmood



Fri, 21 Jan 2005 22:30:56 GMT  
 Segmentation fault (Was: Runtime error in Forte compiled program)
Did you try to give the SAVE attribute to your variables in module Globals ?
My experience is that some compilers have problems in following
what the definition status should become at return for complex call graphs.
I myself find that the standard is not clear on what is the processor-dependent
case in 6.3.1.2 " when execution of a RETURN or END statement results in no
scoping unit having access to the module", so I usually avoid going scratching
my hair about it with a SAVE.

Michel

--

 http://www.ifremer.fr/metocean/group/michel/michel_olagnon.htm
 http://www.fortran-2000.com/



Fri, 21 Jan 2005 23:41:53 GMT  
 Segmentation fault (Was: Runtime error in Forte compiled program)

Quote:

> Please suggest to me other ways to track down the source of this
> error. I have already tried the -C option on Forte compiler.

dbx will(should) tell you where the seg fault occurred. In my experience, it's always
stopped at some lowlevel system-type of call. If you then type "up" at the dbx prompt, you
should be taken back up the call sequence until you hit your own code and this may give
you a hint as to where the segfault problem begins.

Quote:
> The exercise of inserting WRITE statements showed that the subroutine
> second_in_A in module A did not 'know' about vec1 and vec2 global
> arrays after the Call first_in_A in it. Upon USEing the module Globals
> explicitly in the subroutine second_in_A, the program started working
> smoothly even with -O3 option alone

This *sounds* like a compiler bug that has been mentioned here before. A google search on
this newsgroup may turn up something specific.

cheers,

paulv

p.s. Regarding the -g -O3 option working and the -O3 not, some compilers may ignore
optimisation switches when the -g "debug" switch is specified. Don't know if that's the
case with your particular setup though.

--
Paul van Delst

Ph: (301)763-8000 x7274             My wife.
Fax:(301)763-8545



Sat, 22 Jan 2005 00:06:22 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. g77 segmentation fault possible error allocating large arrays during runtime

2. Runtime error on Sun FORTE compiler

3. Segmentation Fault while compiling Eiffel classes.

4. Segmentation fault while compiling TclAppInit.c with Tcl7.6

5. Segmentation Faults and Bus Errors

6. Segmentation fault error

7. Error: Segmentation Fault

8. Segmentation Fault error FOUND !

9. Bus error/ segmentation fault--help?

10. Segmentation fault and other strange errors with extended Wish

11. "Program received signal SIGSEGV, Segmentation fault".

12. Segmentation fault for medium-sized program on g77

 

 
Powered by phpBB® Forum Software