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

SUBMODULE error #6645: The name of the module procedure conflicts....

andrew_4619
Honored Contributor II
1,532 Views

Loaded PSXE2016 start night and today had a first play with the much awaited SUBMODULES. consider the following code:

MODULE BILL
    implicit none
    public
    integer, parameter          :: axs6_irk = kind(1.D0)            ! real kind for dp
    integer, parameter, private :: irk = axs6_irk
    INTERFACE
        MODULE FUNCTION IS_LEAP_YEAR(IYEAR)
            INTEGER(KIND=2), INTENT(IN) :: IYEAR
            LOGICAL(KIND=4) :: IS_LEAP_YEAR
        END FUNCTION IS_LEAP_YEAR
        MODULE SUBROUTINE DVECRS(V1XV2,V1,V2)
            REAL(KIND=IRK) :: V1XV2(3)
            REAL(KIND=IRK), INTENT(IN) :: V1(3)
            REAL(KIND=IRK), INTENT(IN) :: V2(3)
        END SUBROUTINE DVECRS  
    END INTERFACE
END MODULE BILL

This compiles OK with no errors or warnings. Then we have.

submodule (BILL) BILL_SUBS1
    contains    
    function is_leap_year(iyear)
       ! returns true if iyear is a leap year and false otherwise
       implicit none
       logical(4)              :: is_leap_year
       integer(2), intent (in) :: iyear  
       if     (mod(iyear,400_2) == 0) then ! special case for every 4th century
           is_leap_year=.true.
       elseif (mod(iyear,100_2) == 0) then ! centuries are not leap years
           is_leap_year=.false.
       elseif (mod(iyear,4_2) /= 0 ) then  ! not divisible by 4 and not special case so not a leap year
           is_leap_year=.false.
       else
           is_leap_year=.true.             ! divisible by 4 and not a special case to leap year 
       endif          
    end function is_leap_year
    subroutine dvecrs(V1XV2,V1,V2 )
        !     THIS FORMS THE CROSS PRODUCT OF V1 AND V2 AS V1XV2
        implicit none
        REAL(irk)             :: V1XV2(3)
        REAL(irk), intent(in) :: V1(3) , V2(3)
        V1XV2 = [V1(2)*V2(3) - V1(3)*V2(2), -V1(1)*V2(3) + V1(3)*V2(1), V1(1)*V2(2) - V1(2)*V2(1)]
    end subroutine dvecrs
end submodule BILL_SUBS1

This was a simple example using one function and one subroutine. I get the errors>>>>

sample2.f90(3): error #6645: The name of the module procedure conflicts with a name in the encompassing scoping unit.   [IS_LEAP_YEAR]

sample2.f90(18): error #6645: The name of the module procedure conflicts with a name in the encompassing scoping unit.   [DVECRS]

what have a done wrong? I have read various example etc and I can't see it though I may be suffering that brand of selective blindness that sometime filters out the glaring errors...

0 Kudos
3 Replies
IanH
Honored Contributor II
1,532 Views

You need the MODULE prefix on the subprograms in the submodule, otherwise they are not separate module subprograms, and are considered to be definitions of different procedures.

That said, there may still be an issue here - I thought a submodule accessed the module that it extends by host association, and host association permits things in the local scope to hide host associated things.  The ancestor module (or submodule) of a submodule is certainly its host, but the relationship between a submodule and its host is not explicitly called out as being host association.  Um...  I don't know.
 

0 Kudos
andrew_4619
Honored Contributor II
1,532 Views

Thanks Ian that is indeed correct. The foobah bypass filter had been applied to my glasses. That answer was staring at me in the Intel help (BTW that would be better with some formatting to make it more readable if you are reading this Intel).

That said , Dear Doctor Fortran please tweek your useful blog https://software.intel.com/en-us/blogs/2015/07/07/doctor-fortran-in-we-all-live-in-a-yellow-submodule and add  the  the MODULE prefix on the subprograms in the submodule and remove the spurious ::: in the submodule header definition. :-)....

 

0 Kudos
Kevin_D_Intel
Employee
1,532 Views

@app4619 - I reported the formatting and other issues to the Documentation team (internal tracking id below) for the color_points example on the SUBMODULE page (https://software.intel.com/en-us/node/581257). Thank you for noting this.

I updated the good Doctor’s blog accordingly. The MODULE prefix is only needed for SUB1. As the Doctor points out, there are two syntaxes available. Where you *do not* repeat the variable declarations for the subprogram you use the MODULE PROCEDURE prefix; where you repeats those, you use MODULE.

@IanH - In the Fortran 2008 J3/10-007r1 (F2008 Working Document) I have, it seems like the NOTE 2.4 appearing in section 2.2.5 Submodule establishes the relationship as being host association. I don't know whether that appears in the final standard nor if I am reading that correctly.

(Internal tracking id:  DPD200375906)

0 Kudos
Reply