forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Access violation during compilation

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
mecej4



Joined: 31 Oct 2006
Posts: 1412

PostPosted: Mon Aug 10, 2020 1:12 am    Post subject: Access violation during compilation Reply with quote

FTN95 aborts with an access violation (attempting to read from location 0000000C) when asked to compile the following simplified version of John Campbell's adaptation of Arjen Markus's quicksort in a recent thread, please see http://forums.silverfrost.com/viewtopic.php?t=4280 . The access violation occurs whether or not the /64 option is specified.

Code:
module qsort_m
contains
 subroutine test_sort (N)
   integer N
   integer, allocatable :: ia(:), ia_sort(:)
   real, allocatable :: aa(:)
!
    allocate ( aa(N), ia(N), ia_sort(N) )
    call random_number (aa)
    ia = nint(aa*1023.0)
    deallocate(aa)
    print 10,n, ia
!
    ia_sort = qsort_int ( ia )
    print 10,n,ia_sort
 10 format(1x,i3,(4x,10I6))
!
 end subroutine test_sort

 recursive function qsort_int ( data ) result ( sorted )
    integer, dimension(:), intent(in) :: data
    integer, dimension(1:size(data))  :: sorted

    if ( size(data) > 1 ) then
        sorted = (/ qsort_int(pack(data(2:), data(2:) <  data(1))), &
                                pack(data(1:), data(1:) == data(1)),  &
                    qsort_int(pack(data(2:), data(2:) >  data(1))) /)
    else
        sorted = data
    endif
  end function qsort_int
 end module
 
  Program test_sort_int
  use qsort_m
   integer n

    N = 5
    call test_sort(N)

 end Program test_sort_int
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1412

PostPosted: Mon Aug 10, 2020 2:44 am    Post subject: Reply with quote

Here is a second version of the program, with the sorting algorithm slightly changed to preserve the order of items that match the pivot element.

Code:
module qsort_m
    implicit none
 contains
  recursive function qsort_int ( data ) result ( sorted )
    integer, dimension(:), intent(in) :: data
    integer, dimension(1:size(data))  :: sorted
    integer ilt, ieq, igt

    if ( size(data) > 1 ) then
        ilt = count(data < data(1))
        if(ilt > 0)then
           sorted(1:ilt) = pack( data, data < data(1) )
           if(ilt > 1)sorted(1:ilt) = qsort_int(sorted(1:ilt))
        endif
        ieq = count(data == data(1))
        if(ieq > 0)then
           sorted(ilt+1:ilt+ieq) = pack( data, data == data(1) )
        endif
        igt = count(data > data(1))
        if(igt > 0)then
           sorted(ilt+ieq+1:) = pack(data,data > data(1))
           if(igt > 1)sorted(ilt+ieq+1:) = qsort_int(sorted(ilt+ieq+1:))
        endif
    endif
  end function qsort_int

end module qsort_m

Program test_sort_int
   use qsort_m
   integer n
   integer, allocatable :: aa(:), aa_sort(:)
!
   N = 5
   allocate ( aa(N), aa_sort(N) )
   aa = (/ 204, 158, 835, 774, 932 /)
   write (*,10) aa

   aa_sort = qsort_int ( aa )

   write (*,10) aa_sort
10 format(1x,5I10)
!
 end program test_sort_int


With other compilers, I get the expected output

Code:
158       204       774       835       932


With FTN95 (32-bit) this program starts running but aborts with Stack Overflow. Compiled with /64, the program aborts with Access Violation. Compiled with /check, the 32-bit program runs to completion but the output is

Code:
   56687580  56687580  56687580  56687580  56687580


With /check /64, the program aborts, saying this about Line-6:

Code:
Attempt to call a routine with an incorrect or missing INTERFACE regarding argument number one, which needs to be declared as assumed-shape in both the caller and callee at address ...
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6516
Location: Salford, UK

PostPosted: Mon Aug 10, 2020 8:30 am    Post subject: Reply with quote

Thank you for the feedback. I have logged both of these issues.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6516
Location: Salford, UK

PostPosted: Tue Aug 18, 2020 11:58 am    Post subject: Reply with quote

The second version will now run when using the next release of FTN95.

The first version remains outstanding.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6516
Location: Salford, UK

PostPosted: Thu Sep 24, 2020 3:20 pm    Post subject: Reply with quote

Regarding the first program and qsort_int, a number of FTN95 issues connected with this program have now been fixed.

Unfortunately FTN95 has a major issue when it comes to recursive functions that are called within an array constructor so for the time being it has proved necessary to simply flag this as a known limitation of FTN95.

As it happens, this algorithm, although very clever, does not appear to present an efficient way of sorting. You will see that it uses array sections that are passed to PACK which is a function returning an array of varying size. The result is passed to qsort_int which also returns an array of varying size (as well as being recursive); all of this is within an array constructor.
Back to top
View user's profile Send private message AIM Address
mecej4



Joined: 31 Oct 2006
Posts: 1412

PostPosted: Thu Sep 24, 2020 6:00 pm    Post subject: Reply with quote

Quote:
As it happens, this algorithm, although very clever, does not appear to present an efficient way of sorting.


I agree completely; it would, however, be worthwhile to know how inefficient it is. For arrays of size less than 100, say, with elements of a user-defined type with diverse components, it may be worth using simply because it is so readable.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group