Re: Module Cruelly Kissed to Death by -O2



On Jul 16, 12:54 pm, viper-2 <visio...@xxxxxxxxxxxxxxxxx> wrote:
I've been exploring how to use the GNU Autotools for packaging an
application. But my executable got cut off dead after "making" out:

http://tinyurl.com/cruelfortrankiss
;-)

To my surprise, although g95 produces a working executable when
compiled by hand with:

$ g95 -o cgraph fftmod.f90 cgraph.f90

The output of make:

Making all in src
make[1]: Entering directory `/home/Galactica/autotools/src/C-Graph-
build/src'
g95  -g -O2 -c -o fftmod.o fftmod.f90
g95  -g -O2 -c -o C-Graph.o C-Graph.f90
g95  -g -O2   -o cgraph fftmod.o C-Graph.o
make[1]: Leaving directory `/home/Galactica/autotools/src/C-Graph-
build/src'

produced an executable that aborted with a segmentation fault when
run.

On consulting Google (see, e.g. <http://tinyurl.com/lcmhlc>) I found
that turning off the optimization using either:

make FCFLAGS = '-O0 -g'

(or hardwiring the above in my configure.ac)

gave me a working executable. I might find that, not being optimized,
the executable might be less efficient than I would like. Any thoughts
on this problem?

agt

--
Freedom - no pane, all gaiGN!

Code Art Nowhttp://codeartnow.com
Email: a...@xxxxxxxxxxxxxx

Gosh, viper, I'm glad you brought up this flag in the context of g95.
It makes a huge difference in a merge sort and brings g95's
performance on par with gfortran's:

C:\MinGW\source>g95 merge11.f90 -Wall -o f.exe

C:\MinGW\source>f
sort size is 1000
descending 0.
ascending 0.
random 0.
sort size is 10000
descending 0.
ascending 0.
random 0.015625
sort size is 100000
descending 0.03125
ascending 0.
random 0.046875
sort size is 1000000
descending 0.390625
ascending 0.03125
random 0.609375
sort size is 10000000
descending 4.546875
ascending 0.328125
random 7.1875

C:\MinGW\source>g95 merge11.f90 -Wall -O2 -o g.exe

C:\MinGW\source>g
sort size is 1000
descending 0.
ascending 0.
random 0.
sort size is 10000
descending 0.
ascending 0.
random 0.
sort size is 100000
descending 0.015625
ascending 0.
random 0.03125
sort size is 1000000
descending 0.140625
ascending 0.015625
random 0.3125
sort size is 10000000
descending 1.734375
ascending 0.171875
random 3.6875

C:\MinGW\source>type merge11.f90

program sortdriver

implicit none

integer i, j, k
real, allocatable :: a(:), b(:), t(:)
real t0, t2, t4, t6


do j = 3, 7
k = 10 ** j
print *, "sort size is ", k
allocate(a(k), b(k), t((k+1)/2))
! Descending
do i = 1, k
a(i) = 2 - real(i) / real(k)
end do
b = a
call cpu_time(t0)
call MergeSort(b, k, t)
call cpu_time(t2)
t2 = t2 - t0
print *, "descending", t2
! Ascending
do i = 1, k
a(i) = 2 + real(i) / real(k)
end do
b = a
call cpu_time(t0)
call MergeSort(b, k, t)
call cpu_time(t4)
t4 = t4 - t0
print *, "ascending", t4
call random_number(a)
a = 2 + a
b = a
call cpu_time(t0)
call MergeSort(b, k, t)
call cpu_time(t6)
t6 = t6 - t0
print *, "random", t6
deallocate(a, b, t)
end do

contains


subroutine Merge(A,NA,B,NB,C,NC)

integer, intent(in) :: NA,NB,NC
real, intent(in out) :: A(NA)
real, intent(in) :: B(NB)
real, intent(in out) :: C(NC)
integer :: I,J,K

I = 1; J = 1; K = 1;
do while(I <= NA .and. J <= NB)
if (A(I) <= B(J)) then
C(K) = A(I)
I = I+1
else
C(K) = B(J)
J = J+1
endif
K = K + 1
enddo
do while (I <= NA)
C(K) = A(I)
I = I + 1
K = K + 1
enddo
return
end subroutine merge

recursive subroutine MergeSort(A,N,T)
integer, intent(in) :: N
real, dimension(N), intent(in out) :: A
real, dimension((N+1)/2), intent (out) :: T
integer :: NA,NB
real V

if (N < 2) return
if (N == 2) then
if (A(1) > A(2)) then
V = A(1)
A(1) = A(2)
A(2) = V
endif
return
endif

NA=(N+1)/2
NB=N-NA
call MergeSort(A,NA,T)
call MergeSort(A(NA+1),NB,T)
if (A(NA) > A(NA+1)) then
T(1:NA)=A(1:NA)
call Merge(T,NA,A(NA+1),NB,A,N)
endif
return
end subroutine MergeSort

end program sortdriver

! g95 merge11.f90 -Wall -o f.exe
! g95 merge11.f90 -Wall -O2 -o g.exe
C:\MinGW\source>

cheers,
.



Relevant Pages

  • Re: Can this be done?
    ... I ALWAYS sort by name ascending and date descending - its a golden rule ... > In this code page paste in the following sub: ...
    (microsoft.public.excel.misc)
  • Re: Sort Formula
    ... This sorts in ascending order, ... To sort in descending order, text before numbers, replace the SMALL ... No intermediate ancillary calculations in other cells needed. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Complex sort of matrix possible, e.g. like Excel?
    ...  I'd like to sort the matrix on ... column A ascending and, within that, column B descending. ...
    (comp.lang.ruby)
  • Re: Applying Reports Sort Order via code
    ... Ascending is False, Descending is True according to the help file. ... Now the users want to be able to sort the ...
    (microsoft.public.access.reports)
  • Re: finding & sorting unqiue names list
    ... this formula return unique value and sort ascendenting.. ... i wish to extract a list of the unique names ... > sorted out in either ascending or descending order. ... > cell B1, ...
    (microsoft.public.excel.worksheet.functions)