Array problem

Array problem

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?

 

 

 

 

 

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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?)

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.

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

Leave a Comment

Please sign in to add a comment. Not a member? Join today