Nvfortran - Subroutine alternate entry not recognized, yields NVFORTRAN-S-0084

Hi all,
I’m encountering an error when compiling a Fortran module that involves a subroutine with an alternate entry point, using the entry keyword. Here is a small example:

First, the module:

module entry_testing_m
  implicit none
  private
  public :: foo, bar

contains
  subroutine foo()
    integer :: x, y, z
    logical :: came_from_foo

    came_from_foo = .true.
    print *, 'came from foo'
    x = 1
    y = 2
  entry bar()
    if (.not. came_from_foo) then
      print *, 'came from bar'
      x = 1000
      y = 2000
    end if

    z = x + y
    print *, z
  end subroutine foo
end module entry_testing_m

Next, the program that calls the subroutines:

program main_testing
  use entry_testing_m, only: foo, bar
  implicit none

  print *, 'testing foo'
  call foo()
  print *, 'testing bar'
  call bar()

end program main_testing

Finally, a makefile for the program:

# gfortran compiles and works correctly (prints 3, then 3000)
FC=gfortran
# nvfortran doesn't compile...
FC=nvfortran
FFLAGS=-g -O0

OBJS = entry_testing.o main_testing.o

moduletest.out:	$(OBJS)
	$(FC) $(FFLAGS) -o $@ $^
	chmod +x $@

%.o:	%.f90
	$(FC) -c $(FFLAGS) -o $@ $^

clean:
	rm -rf *.o *.mod moduletest.out

I can compile this code successfully using gfortran, and I get the expected output of 3 from foo and 3000 from bar. But nvfortran doesn’t seem to recognize the entry keyword, and the compilation fails:

nvfortran -c -g -O0 -o entry_testing.o entry_testing.f90
NVFORTRAN-W-0155-MODULE PROCEDURE not defined: bar (entry_testing.f90: 25)
  0 inform,   1 warnings,   0 severes, 0 fatal for foo
nvfortran -c -g -O0 -o main_testing.o main_testing.f90
NVFORTRAN-S-0084-Illegal use of symbol bar - attempt to CALL a non-SUBROUTINE (main_testing.f90: 8)
  0 inform,   0 warnings,   1 severes, 0 fatal for main_testing
make: *** [Makefile:18: main_testing.o] Error 2

Is this a bug with nvfortran or an error on my part?

I know this could be solved by defining bar as a separate subroutine instead of an entry to foo. In my real program, it would be possible to rewrite the code to not use such entries, but I would like to avoid refactoring like that as it would lead to duplicating a bunch of code with only 1-2 line differences.

Any advice is welcome. Thanks!

Hi vle2696,

Hmm, “entry” is an old F77 construct that has been declared obsolete in F2008. I believe it’s not recommended, as this page notes, Entry “is incompatible with the best principles of structured programming, and leads to programs which are hard to understand.”

While I’m not 100% sure, I believe the behavior of using entry inside a module is undefined. If you remove the module so F77 style calling is used, then you’ll get the expected results with nvfortran. Though in the module, we expect routines to have interfaces. I’m not sure if why gfortran works is intentional or is luck.

Personally I agree with the statement from the above page “a better structure can generally be obtained using either a single entry point with optional arguments, or else several thin shells with individual argument lists, all of which call the same lower-level routine. In either case a lot of refactoring is required.”

-Mat

Thanks for the additional context around entry’s obsolescence. Personally, I also agree that “entry” made things more confusing; glad to see that perspective didn’t just stem from my own inexperience.

Looks like the best move is to simply do away with the entries in the main project. Thanks, Mat!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.