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
連結已複製
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.
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
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?
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?
