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

Subroutine argument values

Kate_Johnson
Beginner
646 Views
I have a subroutine, rank1, that calls another subroutine, sub1 like so: call sub1(m, n, A, kra), and Subroutine sub1(m, n, X, M_rank). Am I wrong in thinking that after sub1 is called, if I am to print kra, which is an array,in rank1 it should be the same values as M_rank at the very end of sub1? Because this is not the case and I cannot figure out the reason for this. Or maybe I am way off base and I just don't understand how this works. Thanks
0 Kudos
3 Replies
Steven_L_Intel1
Employee
646 Views
Kate, we'd at least need to see the declarations of all of these arguments, both in rank1 and sub1. Also it would be helpful to know how the values are different - does it seem that they are "shifted" to the wrong element number, or are the values wildly different? Most helpful would be a small but complete test case that demonstrates the problem. If you can't give us a full test case, please show the actual code and not "like" code.
0 Kudos
Kate_Johnson
Beginner
646 Views
Got it, here's the code:

Subroutine rank1(m, n, A, B)

use Mod_A

Integer m, n, i, j, k

Real(8), Dimension (:,:) :: A(m,n), B(m,n)

c This program first finds out the rank matrix KR of A, then

c re-arrange the the elements in matrix B according to this

c rank matrix, so A and B will have the rank correlation matrix.

c ******************************************************************

c

Allocate(kra(m,n))

Allocate(krb(m,n))

Call sub1(m, n, A, kra)

print*, 'kra(1,1)=',kra(1,1)

! print*, 'size of kra=',size(kra)

! print*, 'inbetween'

Call sub1(m, n, B, krb)

print*, 'krb(1,1)=',krb(1,1)

! print*, 'size of krb=',size(krb)

print*, 'Done'

Deallocate (C)

Allocate(C(m,n))

print*, 'kra(1,1)=',kra(1,1)

print*, 'krb(1,1)=',krb(1,1)

do 500 k=1,n

do 600 i=1, m

! C(krb(i,k),k)=B(i,k)

600 continue

do 610 i=1,m

! B(i,k)=C(kra(i,k),k)

610 continue

500 continue

c

Deallocate(kra)

Deallocate(krb)

Return

End

c

c

c

c Sub1 is the program to find out the rank matrix M_rank for X matrix

c *********************************************************************

c

Subroutine sub1(m, n, X, M_rank)

use Mod_A

Real(8), Dimension(:,:), Target :: X(m,n)

Integer, dimension(:,:), Pointer :: M_rank(:,:)

allocate(M_rank(m,n))

do 10 i=1, m

do 10 j=1,n

M_rank(i,j)=1

10 continue

do 100 k=1, n

do 200 i=1, m

do 200 j=i+1, m

if (x(i,k) .GT. x(j,k)) then

M_rank(i,k)= M_rank(i,k)+1

M_rank(j,k)= M_rank(j,k)-1

endif

200 continue

100 continue

print*, 'M_rank(1,1)=',M_rank(1,1)

! print*, 'size of M_rank=',size(M_rank)

! print*, 'M_rank 10=',M_rank(1:10,1:10)

! pause

c

Return

End

0 Kudos
Steven_L_Intel1
Employee
646 Views
Please show the contents of mod_A. It is required that the caller of rank1 and the caller of sub1 have explicit interfaces for those routines visible, because you have deferred-shape and pointer array arguments. In particular, if rank1 does not see a correct explicit interface for sub1, arguments X and M_rank will be incorrectly passed. I can tell by context that kra is a POINTER array, so it's ok that far, but I'm not seeing the explicit interfaces. It is also clear that these are separate procedures and not in a module.
0 Kudos
Reply