Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Problem with is_contiguous

Arjen_Markus
Honored Contributor I
276 Views

Hello,

I was experimenting a bit with the is_contiguous intrinsic function and found a strange effect: the program below outputs two different answers for the same array section:

program test_is_contiguous
    implicit none

    real, dimension(100),   target :: array
    real, dimension(10,10), target :: matrix
    real, dimension(:), pointer    :: parray
    real, dimension(:,:), pointer  :: pmatrix

    write( *, '(a,/)' ) 'Contiguous and non-contiguous arrays and sections:'

    pmatrix => matrix(:,1:1)
    write( *, '(a,a)' ) 'Pointer to matrix section (:,1):     ', report(is_contiguous(pmatrix))

    parray => array(1::2)
    write( *, '(a,a)' ) 'Pointer to section (stride 2):       ', report(is_contiguous(parray))

    pmatrix => matrix(:,1:1)
    write( *, '(a,a)' ) 'Pointer to matrix section (:,1):     ', report(is_contiguous(pmatrix))
contains

function report(condition )
    logical           :: condition

    character(len=14) :: report

    report = merge( 'contiguous    ', 'non-contiguous', is_contiguous(parray) )
end function report

end program test_is_contiguous

Using Intel Fortran 15.0.1.148, I get:

Contiguous and non-contiguous arrays and sections:

Pointer to matrix section (:,1):     contiguous
Pointer to section (stride 2):       non-contiguous
Pointer to matrix section (:,1):     non-contiguous

If I remove the second write statement, the answer is  twice "contiguous"

I compile and link it with just default options.

 

0 Kudos
2 Replies
Steven_L_Intel1
Employee
276 Views

I am not seeing that behavior (removing write changes last value) in 17.0.1.

0 Kudos
Arjen_Markus
Honored Contributor I
276 Views

Ah, in that case, the problem must have been solved already. I was rather surprised about it.

0 Kudos
Reply