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

Internal procedure as actual argument (error)

Ferdinand_T_
Novo colaborador II
1.683 Visualizações

Dear readers, I am seeking you for advice on passing internal procedures as actual arguments, which is a fortran 2008 feature supported by ifort 15.0. The following module does not compile in ifort 15.0, because

error #7069: The characteristics of the associated actual function result
 differ from the characteristics of the dummy function result.   [NESTED]
		call with_dummy_function(nested)
-----------------------------------------^
compilation aborted for test.f90 (code 1)

Here is the code:

module m
	implicit none

	abstract interface
		function dummy_function()
			logical :: dummy_function
		end function
	end interface

contains

	subroutine host()
		call with_dummy_function(nested)
	contains
		function nested()
			logical :: nested
			nested = .true.
		end function
	end subroutine

	subroutine with_dummy_function(func)
		procedure(dummy_function), pointer, intent(in) :: func
	end subroutine
end module 

While I managed to compile and run the same code with ifort 14 (service packs .3 and .4 ), any tips on how to get this feature to work with ifort 15.0 are appreciated!

Best regards

Ferdinand

0 Kudos
1 Solução
Steven_L_Intel1
Funcionário
1.683 Visualizações

Escalated as issue DPD200370165. A workaround is to create a procedure pointer, assign the pointer to the internal procedure and pass the pointer. As a note of information, you should be using "abstract interface" for dummy_function.

Ver solução na publicação original

6 Respostas
Steven_L_Intel1
Funcionário
1.683 Visualizações

The issue here is that you are passing an internal procedure to a procedure pointer. If the argument to with_dummy_function was just a procedure, not a procedure pointer, it works.  I had at first thought that it was not allowable to use an internal procedure in this context, but on research I find that it is. I will escalate this to the developers.

Steven_L_Intel1
Funcionário
1.684 Visualizações

Escalated as issue DPD200370165. A workaround is to create a procedure pointer, assign the pointer to the internal procedure and pass the pointer. As a note of information, you should be using "abstract interface" for dummy_function.

Ferdinand_T_
Novo colaborador II
1.683 Visualizações

Thank you, Steve, for the prompt reply.

Indeed, dropping the pointer attribute

    subroutine with_dummy_function(func)
        !procedure(dummy_function), pointer, intent(in) :: func
        procedure(dummy_function) :: func
    end subroutine

does work fine.

 

 

Ferdinand_T_
Novo colaborador II
1.683 Visualizações

Steve Lionel (Intel) wrote:

Escalated as issue DPD200370165. A workaround is to create a procedure pointer, assign the pointer to the internal procedure and pass the pointer. As a note of information, you should be using "abstract interface" for dummy_function.

Thank you for the hint, I edited my code. I never fully understood where to use abstract - and where to use "normal" - interfaces. Probably I should always go with "abstract" in f2k code unless something breaks... 

I implemented the workaround you suggested and it works well!

	subroutine host()
		procedure(dummy_function), pointer :: nested_ptr
		nested_ptr => nested
		call with_dummy_function(nested_ptr)
	contains
		function nested()
			logical :: nested
			nested = .true.
		end function
	end subroutine

	subroutine with_dummy_function(func)
		procedure(dummy_function), pointer, intent(in) :: func
	end subroutine

Best regards

Ferdinand

Steven_L_Intel1
Funcionário
1.683 Visualizações

It's really simple - if you don't use "abstract", you are declaring an external procedure which is assumed to exist. With "abstract", you're just defining the interface.

Steven_L_Intel1
Funcionário
1.683 Visualizações

I expect the problem to be fixed in Update 1 to Parallel Studio XE 2017. If it doesn't make that, then Update 2.

Responder