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

Bounds of allocatable arrays

Intel_C_Intel
Employee
707 Views

Hello

I dont understand whats wrong.

Code:
program Test

	implicit none

	integer B(6)

	call Arr(B)
	read *

contains

	subroutine Arr(A)

		integer, allocatable :: A(:)

		print *, UBound(A)

	end subroutine Arr

end program Test

(8): Error: If dummy arg is allocatable, actual arg must be a whole array and not a section.

If Arr will be in DLL but I will lie the interface of Arr like:

Code:
interface
        subroutine Arr(A)
            !DEC$ ATTRIBUTES DLLIMPORT, ALIAS : 'Arr' :: Arr
            
            integer A(:)
        end subroutine Arr
end interface

I.e. A will not be declared in interface as allocatable all works!

And the second and main question: how Arr knows UBound of A!? Especially when Arr is a DLLs subroutine. And it doesnt matter if A is allocatable or integer A(:) (taking-form-array).
I hope someone will explain.

Stanislav

0 Kudos
4 Replies
Steven_L_Intel1
Employee
707 Views
The error is a bug, should be fixed in an update due out soon.

When you call a routine where there is an explicit interface saying that the bounds are "assumed-shape" (:), then the compiler knows to pass a "descriptor" rather than just an address. This descriptor has the base address plus all of the bounds information. The called routine expects this and uses info from the descriptor.

It is an error to call a routine with assumed-shape arguments from code that does not have an explicit interface visible for the routine. There are other routine attributes that require an explicit interface - these are listed in the Language Reference.

Steve
0 Kudos
Intel_C_Intel
Employee
707 Views

Hello,

Thx for answer, I understood. What about list I found it (if someone interested):
A procedure must have an explicit interface in the following cases:

If the procedure has any of the following:
A dummy argument that has the ALLOCATABLE, OPTIONAL, POINTER, TARGET, or VOLATILE attribute
A dummy argument that is an assumed-shape array
A result that is an array, or a pointer, or is allocatable (functions only)
A result whose length is neither assumed nor a constant (character functions only)

If a reference to the procedure appears as follows:
With an argument keyword
As a reference by its generic name
As a defined assignment (subroutines only)
In an expression as a defined operator (functions only)
In a context that requires it to be pure

If the procedure is elemental

Actually, I asked this question thats why. Descriptor. Ok. But is he Intel or Fortran specific. I mean, could I give to DLLs subroutine:

interface
	subroutine Arr(A)
        	!DEC$ ATTRIBUTES DLLEXPORT, ALIAS : 'Arr' :: Arr
            
		integer A(:)
	end subroutine Arr
end interface
a C++ array int B[]? Will be all ok?
0 Kudos
Jugoslav_Dujic
Valued Contributor II
707 Views
No it won't -- in general, you can do it with assumed-size (B(*)), but not with assumed-shape.

I recently posted a simple example how an array descriptor (applicable to array pointers, allocatable arrays and assumed-shape arguments) works and what it contains -- see this thread. Since this Forum still screws the attachments, I'll repost the code as-is there.

Note that the structure differs even for CVF and IVF, so you can't port it to other Fortran compilers. In C, you can declare the called Fortran function to have a struct VF_1D_DESCRIPTOR as the argument matching an assumed-shape/allocatable/pointer array. (Note that half of the code is actually C written in Fortran :-)).

Jugoslav
0 Kudos
Steven_L_Intel1
Employee
707 Views
The descriptor layout is documented in the Mixed Language Applications chapter of the Building Applications manual. There is even an example of creating the descriptor in C and calling Fortran with it.
0 Kudos
Reply