Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.
29305 Discussions

FFTW segmentation fault with ifort 17.0

liam_jongsu_k_
Beginner
1,221 Views

I compiled this code with ifort 17.0 and it gives segfault.

https://gist.github.com/appleparan/be9eb47be87f5440c8008118492b4f10

It works with gfortran 6.2 but ifort fails. Is this ifort's bug?

This is traceback

#0  0x0000003a06a7a96c in free () from /lib64/libc.so.6
#1  0x0000000000563e7b in for_dealloc_allocatable ()
#2  0x00000000004057ca in MAIN__ ()
#3  0x0000000000403ade in main ()
#4  0x0000003a06a1ecdd in __libc_start_main () from /lib64/libc.so.6
#5  0x0000000000403969 in _start ()

gnu libc version status

ldd (GNU libc) 2.12
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

ifort version status

ifort (IFORT) 17.0.0 20160721
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

FFTW version 3.3.5 compiled with --enable-avx --enable-openmp

I have this issue with ifort 12.1 as well as 17.0

0 Kudos
4 Replies
Steven_L_Intel1
Employee
1,221 Views

I think this is your bug. The description of the fftw_alloc_xxx routines say:

Data allocated by fftw_malloc must be deallocated by fftw_free and not by the ordinary free.

In other words, don't use Fortran DEALLOCATE on storage allocated by fftw.

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,221 Views

You cannot use a Fortran deallocate using a pointer that was not directly allocated. e.g.

ALLOCATE(yourPointer(nX, nY, nZ))

IOW, if the pointer were initializes with => or with c_f_pointer, you must not DEALLOCATE.
If initialized with =OtherPointer (that was directly allocated) then you are walking on thin ice.

In the sample code, you should be calling fftw_free(p_ffttest), fftw_free(p_ffttest_c) and remember to nullify the pointers (both Fortran and C_PTR).

Jim Dempsey

0 Kudos
liam_jongsu_k_
Beginner
1,221 Views

Oh, yes. Thank you. It is my fault, sorry.
 

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,221 Views

Don't be embarrassed. It is a common mistake in multi-language programming that allocation/deallocation are freely interchangeable between languages. While this may have been the case some time ago, it is not necessarily true as languages develop. C++ may have dtor's to call, C# has garbage collection, Fortran may have Final routines (dtor-like), etc...

Jim Dempsey

0 Kudos
Reply