Re: Module Cruelly Kissed to Death by -O2
- From: Frank <merrill@xxxxxxxxxxxxxxxxx>
- Date: Sat, 18 Jul 2009 19:01:54 -0700 (PDT)
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,
.
- Follow-Ups:
- Re: Module Cruelly Kissed to Death by -O2
- From: viper-2
- Re: Module Cruelly Kissed to Death by -O2
- References:
- Module Cruelly Kissed to Death by -O2
- From: viper-2
- Module Cruelly Kissed to Death by -O2
- Prev by Date: Re: Pointers
- Next by Date: Re: Pointers
- Previous by thread: Re: Module Cruelly Kissed to Death by -O2
- Next by thread: Re: Module Cruelly Kissed to Death by -O2
- Index(es):
Relevant Pages
|