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

Array problem

Kate_Johnson
Beginner
495 Views

I am using the following code for random permutations:

    subroutine rperm(nsim, IPERM1)

    integer, intent(in) :: nsim 
    integer, dimension(:), intent(out) :: IPERM1

    integer :: mynumber, i, j, k
    real, dimension(nsim) :: rand2

    call random_number(rand2)

    IPERM1= 0
    do i=1,nsim
    print*, 'HEREHEREHERE: i=', i
        mynumber=1
        do j=1,nsim
            if (rand2(i) > rand2(j)) then
                mynumber = mynumber+1
            end if
        end do
        if (i>1) then
            do k=1,i-1

                if (rand2(i) <= rand2(k) .and. rand2(i) >= rand2(k)) then
                    mynumber = mynumber+1
                end if
            end do
c        
        end if
        print*, 'RPERM WORKS HERE'
        IPERM1(i) = mynumber


    end do

    return
    
    end subroutine rperm

However, it is getting stuck at the line:         IPERM1(i) = mynumber           and exits the subroutine.

Why is this happening?

 

 

 

 

 

0 Kudos
3 Replies
IanH
Honored Contributor III
496 Views

How are you calling the procedure?  Does it have an explicit interface?

(Is the argument nsim redundant given the size of the IPERM1 argument is available inside the procedure?)

0 Kudos
TimP
Honored Contributor III
496 Views

I'm guessing you don't have an explicit interface, and so iperm1(:) must be assumed size.  Otherwise, as Ian hinted, size(iperm1) would be defined, and nsim > size(iperm1) could be checked to detect an obvious problem.  In any case, violating that condition would make behavior unpredictable.

If iperm1 is meant to have dimension(nsize), writing it that way and invoking ifort interface checking would give you an automatic indication of the violation.

0 Kudos
Kate_Johnson
Beginner
496 Views

Got it.  I needed to declare it's size. Thanks

0 Kudos
Reply