- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It works for the ( nxn ) matrix when n is smaller, and the result and argument of the transpose function are the same.
For larger n, it produces a segmentation fault.
A way out is transposing through a temporary matrix, as shown in the code below.
I am using Intel Fortran Compiler Classic version: ifort (IFORT) 2021.7.0 20220726.
gfortran (v-10.4.0) does not produce the segmentation fault.
Am I missing something in the Fortran standards?
program TransposeBug
implicit none
integer, parameter :: dp = selected_real_kind(15, 307)
real(dp), dimension(:, :), allocatable :: Mat, Mat_tmp
integer :: n
! ================================ Small vlaue of n works ================================ !
n = 81
allocate( Mat(n, n) )
call random_number( Mat )
Mat = transpose( Mat )
write(*, *) "Transpose of Matrix complete"
! ================================ Small vlaue of n works ================================ !
deallocate( Mat )
! ==================== Large vlaue of n works through temporary matrix =================== !
n = 11838
allocate( Mat(n, n) )
call random_number( Mat )
allocate( Mat_tmp(n, n) )
Mat_tmp = transpose( Mat )
Mat = Mat_tmp
write(*, *) "Transpose of Matrix complete"
! ==================== Large vlaue of n works through temporary matrix =================== !
deallocate( Mat_tmp )
deallocate( Mat )
! ============================= Large vlaue of n do not works ============================ !
n = 11838
allocate( Mat(n, n) )
call random_number( Mat )
Mat = transpose( Mat )
write(*, *) "Transpose of Matrix complete"
! ============================= Large vlaue of n do not works ============================ !
end program TransposeBug
Result:
Transpose of Matrix complete
Transpose of Matrix complete
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
libpthread-2.17.s 00007F47E6766630 Unknown Unknown Unknown
a.out 000000000040572C Unknown Unknown Unknown
a.out 000000000040429D Unknown Unknown Unknown
libc-2.17.so 00007F47E63AB555 __libc_start_main Unknown Unknown
a.out 0000000000404176 Unknown Unknown Unknown
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try enabling heap-arrays to avoid stack overflow.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page