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

Submodules - Experience and VS2015 integration issue

Johannes_Rieke
New Contributor III
469 Views

Dear all,

I recently played around with the new submodule capabilities in PSXE2016 and some questions arose.

The first one is a question of experience of other users: Do you take advantage of the procedure definition (example foo) or do you repeat the interface in the submodule (example bar)? I find it difficult to decide which one I should use.

The second is more a feature request. Staying at modules the "go to definition" works well and is really helpful. This does not work in any way with submodules (VS2015 sp1, PSXE2016 update 2, example code shows that it does not work). Please, Intel, enhance the VS2015 integration.

The third one is a question whether it makes sense to allow either 'end procedure foo' or alternatively 'end subroutine foo' within the submodule smod_test. The other way round the compiler gives an error ('end subroutine bar' vs. 'end procedure bar').

Here is the example code (4 different files):

submodule (mod_test) smod_test
  contains
  
  ! this version is without repeating the interface
  module procedure foo
    implicit none
  
    d = real(i*j*k,rk)
    return
  !end subroutine foo ! -> this does work too, but does it make sense?
  end procedure foo
  
  
  ! this version repeats the interface
  module subroutine bar(i, j, k, d)  
    use mod_parameter
    implicit none
    integer(ik), intent(in ) :: i, j, k
    real(rk)   , intent(out) :: d
  
    d = real(i*j*k,rk)
    return
  end subroutine bar
  !end procedure bar ! -> this does not work
  
end submodule

module mod_parameter
  use ISO_FORTRAN_ENV, only : ik => int32
  use ISO_FORTRAN_ENV, only : rk => real64
  implicit none
  
  private
  public :: ik, rk
end module mod_parameter

module mod_test
  use mod_parameter
  implicit none
  
  private
  public :: foo, bar
  
  interface 
  
    module subroutine foo(i, j, k, d) 
      implicit none
      integer(ik), intent(in ) :: i, j, k
      real(rk)   , intent(out) :: d
    end subroutine foo
  
    module subroutine bar(i, j, k, d)  
      use mod_parameter
      implicit none
      integer(ik), intent(in ) :: i, j, k
      real(rk)   , intent(out) :: d
    end subroutine bar
  
  end interface
  
end module mod_test

program submodule_test2
  use mod_parameter
  use mod_test
  implicit none
  
  integer(ik) :: i, j, k
  real   (rk) :: d
  
  ! ----------------------------------------------
  
  i = 2
  j = 5
  k = 3
  call foo(i,j,k,d)
  write(*,'(1ES18.4)') d
  call bar(i,j,k,d)
  write(*,'(1ES18.4)') d
  
  
end program submodule_test2

Any comment is highly welcome, Johannes

0 Kudos
12 Replies
Steven_L_Intel1
Employee
469 Views

It's a compiler bug that it allows "end subroutine" to match "module procedure". We're fixing that.

I will let the developers know about the Go To Definition issue.

0 Kudos
FortranFan
Honored Contributor II
469 Views

Johannes wrote:

.. The first one is a question of experience of other users: Do you take advantage of the procedure definition (example foo) or do you repeat the interface in the submodule (example bar)? I find it difficult to decide which one I should use. ..

The good doctor perhaps presumed you've read his bog: if not, see it here: https://software.intel.com/en-us/blogs/2015/07/07/doctor-fortran-in-we-all-live-in-a-yellow-submodule

I prefer to repeat the interface in the submodule.

0 Kudos
Johannes_Rieke
New Contributor III
469 Views

Dear Steve, dear FortranFan,

thanks for the replies.

@Steve: Thanks for addressing the Go To Definition issue to the developers.

@FortranFan: Yes, I've read Steve's thread regrading submodules (more than once... ;-) ) and I agree that it seems to be a matter of taste or if you want to drive code maintainers into madness (including me myself in a year or two...). I tend like you to repeat the interface, but maybe there is some reason not do this... Too many choices makes it sometimes not easier.

Best regards, Johannes

0 Kudos
Steven_L_Intel1
Employee
469 Views

My view is that it is strictly a matter of personal preference, and may largely depend on how you've programmed in the past. You can always add comments.

0 Kudos
Andrew_Smith
New Contributor III
469 Views

Having separate visual options "Go To Definition" and "Go To Declaration" like c++ does might help swing the argument for not repeating the argument list.

0 Kudos
Simon_Geard
New Contributor I
469 Views

I've just started using submodules and after consultation agreed that repeating the declaration will make code maintenance easier so that's what we'll be doing. If there is a mismatch the error message is unnecessarily obscure

BTW I don't know why I've started getting 'name withheld' on my posts. I never used to and I've never asked for it, moreover I can't figure out how to stop it - there doesn't seem to be any option to not withhold my name. Does anyone know how to do this?

0 Kudos
Arjen_Markus
Honored Contributor I
469 Views

It has to do with a privacy issue. The solution is to go to your profile and explicitly set the display name. There was a thread some time ago on the matter. Don't remember when, though.

0 Kudos
Simon_Geard
New Contributor I
469 Views

Thanks. The problem was that the display name was my email address and that is no longer allowed.

0 Kudos
Johannes_Rieke
New Contributor III
469 Views

Thanks for the answers. It seems that the most users prefer to repeat the interface definition and I think this is a good option for me too, since the change in the code from normal subroutine to a submodule contained subroutine is very small.

From the post of Andrew I assume that "Go To Definition" and "Go To Declaration" would distinguish between the interface in the parent module and the repetition in the submodule? Where would a pure "Go To Definition" go to in the case of repetition? Into the submodule or the parent module?

 

0 Kudos
Steven_L_Intel1
Employee
469 Views

I would expect Go To Declaration to go to the interface in the module and Go To Definition to go to the actual procedure. That probably is what it does in C++.

0 Kudos
Johannes_Rieke
New Contributor III
469 Views

Hi Steve, thanks for the explanation. Do you think the development team will/ can implement both features ("Go To Definition" and "Go To Declaration") in future for Fortran?

0 Kudos
Steven_L_Intel1
Employee
469 Views

I will submit a feature request. The team is pretty good about such things but I can't make any promises.

0 Kudos
Reply