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

Compiler complains about declaration conflicts and functions not being declared that are

CoryG
Novice
588 Views

I am compiling the following file as part of a much larger project:

 

 

subroutine GetSoftwareLicense
    ! Checks out a license for this instance
    use Globals
    use Licensing
    implicit none

    LOGICAL :: CheckoutSuccessful
   
    !**********************************************************************************************
    !******************* CHECK OUT SOFTWARE LICENSE **********************
    !**********************************************************************************************
    CheckoutSuccessful = initialize_license(1, 50)

    if (.not. CheckoutSuccessful) call NoLicenseExit(3)

    write(szLogText,'("Success!")')
    call GlobalWriter(0,.TRUE.,.FALSE.)

end subroutine GetSoftwareLicense


subroutine NoLicenseExit(iType)
    ! Exits based on there not being a valid license
    use Globals
    implicit none
   
    INTEGER, INTENT(IN) :: iType
    CHARACTER(100) :: StringLoader
    INTEGER :: iret
   
    StringLoader = "License Error"//CHAR(0)
   
    if (iType == 1) iret = MessageBox(ghWindow,"License failed to be checked out."//CHAR(0),StringLoader,IOR(MB_OK,MB_ICONERROR))
! More such checks... Just display a relevant message based on iType
   
    iret = SendMessage(ghWindow,WM_DESTROY,0,0)

end subroutine NoLicenseExit


integer function GetCostForThreads(threads)
    implicit none
   
    integer, intent(in) :: threads
    integer, parameter :: baseline = 5

    ! Baseline
    if (threads <= 4) then
        GetCostForThreads = baseline

    ! Scaling
    else
        GetCostForThreads = INT((threads-4)*1) + baseline
    endif

end function GetCostForThreads


logical function UpdateOMPThreadCount(threads)
    use Licensing
    use Globals
    implicit none
   
    integer, intent(in) :: threads

    integer :: cost, actual_threads
    logical :: success

    ! Obviously
    if (threads <= 1) then
        actual_threads = 1
    else
        actual_threads = threads
    endif

    ! Get cost
    cost = GetCostForThreads(actual_threads)

    ! Check with licensing
    success = update_cost(cost)
    if (success) then
        call omp_set_num_threads(actual_threads)
    else
        call GlobalErrorHandler(14)
    endif

    UpdateOMPThreadCount = success

end function UpdateOMPThreadCount

 

When compiling, I get the following error messages:

 

Severity Code Description Project File Line Suppression State
Error error #6404: This name does not have a type, and must have an explicit type. [GETCOSTFORTHREADS] Licenses.f90
Severity Code Description Project File Line Suppression State
Error error #5508: Declaration of routine 'NOLICENSEEXIT' conflicts with a previous declaration Licenses.f90

 

 
Why are these popping up? I have clearly declared GetCostForThreads, and nowhere else have I declared NoLicenseExit. I've tried rebuilding the solution multiple times. I've also tried deleting the entire "Debug" directory. Neither works. These are the only error messages that appear when compiling the entire project.
Labels (2)
0 Kudos
1 Solution
jimdempseyatthecove
Honored Contributor III
527 Views

 >>I have clearly declared GetCostForThreads, 

In UpdateOMPThreadCount you have implicit none

You are calling the function GetCostForThreads

Within the scope of UpdateOMPThreadCount, GetCostForThreads is undefined.

 

A suggestion is to place this code into a module then (elsewhere) use this module:

 

module YourModuleNameHere
! module data follows
! ...
contains
! module procedures follow
subroutine GetSoftwareLicense
...
end function UpdateOMPThreadCount
end module YourModuleNameHere

subroutine SomeCodeElsewhere
  use YourModuleNameHere
  implicit none
...

 

If (when) you cannot place that code inside a module, then create a module containing the interfaces and use that to declare your interfaces:

 

module YourInterfacesNameHere
interface
  subroutine GetSoftwareLicense
  end subroutine GetSoftwareLicense

  subroutine NoLicenseExit(iType)
    INTEGER, INTENT(IN) :: iType
  end subroutine NoLicenseExit

 integer function GetCostForThreads(threads)
    integer, intent(in) :: threads
  end function GetCostForThreads

  logical function UpdateOMPThreadCount(threads)
    integer, intent(in) :: threads
  end function UpdateOMPThreadCount
end module YourInterfacesNameHere
...
! other file
subroutine something
   use YourInterfacesNameHere
...

 

EDIT: Note, in the second case your subroutine GetCostForThreads will require the USE YourInterfacesNameHere.

Jim Dempsey

 

View solution in original post

5 Replies
TobiasK
Moderator
549 Views

@CoryG probably the error is elsewhere in your code / compilation. Any chance that we can get a full reproducer and the full compilation log?
Please also check with the latest release (2024.2).

0 Kudos
jimdempseyatthecove
Honored Contributor III
528 Views

 >>I have clearly declared GetCostForThreads, 

In UpdateOMPThreadCount you have implicit none

You are calling the function GetCostForThreads

Within the scope of UpdateOMPThreadCount, GetCostForThreads is undefined.

 

A suggestion is to place this code into a module then (elsewhere) use this module:

 

module YourModuleNameHere
! module data follows
! ...
contains
! module procedures follow
subroutine GetSoftwareLicense
...
end function UpdateOMPThreadCount
end module YourModuleNameHere

subroutine SomeCodeElsewhere
  use YourModuleNameHere
  implicit none
...

 

If (when) you cannot place that code inside a module, then create a module containing the interfaces and use that to declare your interfaces:

 

module YourInterfacesNameHere
interface
  subroutine GetSoftwareLicense
  end subroutine GetSoftwareLicense

  subroutine NoLicenseExit(iType)
    INTEGER, INTENT(IN) :: iType
  end subroutine NoLicenseExit

 integer function GetCostForThreads(threads)
    integer, intent(in) :: threads
  end function GetCostForThreads

  logical function UpdateOMPThreadCount(threads)
    integer, intent(in) :: threads
  end function UpdateOMPThreadCount
end module YourInterfacesNameHere
...
! other file
subroutine something
   use YourInterfacesNameHere
...

 

EDIT: Note, in the second case your subroutine GetCostForThreads will require the USE YourInterfacesNameHere.

Jim Dempsey

 

TobiasK
Moderator
509 Views

@jimdempseyatthecove good catch:)
For omp_set_num_threads it would also be better if you would add "use omp_lib". For the GETCOSTFORTHREADS function, you could also declare it as "integer, external :: GETCOSTFORTHREADS"

CoryG
Novice
470 Views

Ah I'd forgotten about "use omp_lib". Thanks!

0 Kudos
Reply