[MITgcm-support] G95 build issue: f2c name mangling

Mark Hadfield m.hadfield at niwa.co.nz
Mon Oct 9 16:31:54 EDT 2006


Mark Hadfield wrote:
> The preprocessor logic in timers.F is pretty convoluted. I'm not sure 
> if it's entirely right, either, eg if IGNORE_TIME is set, the only 
> thing that's done is to set local variable wtime to zero, which seems 
> rather pointless. I would try to clean it up, but I think I'll break 
> something.
Oh what the hell. Below (following my signature) is my attempt at a 
rewrite of subroutine TIMER_GET_TIME in timers.F. Make of it what you will.

To keep track of the nested #if statements, I've used a simple 
convention: an extra space is left after the "#" for every level of 
nesting, eg:

#ifdef A
# ifdef B
# else
# endif
#endif

This is used throughout the ROMS model and seems to work on pretty much 
every preprocessor in the world.

To avoid mismatches between the declarations and the executable code, 
I've used exactly the same preprocessor structure in both. I've brought 
the IGNORE_TIME case to the beginning of the routine to get it out of 
the way.

I've tested this on every platform I could, which unfortunately isn't 
very many (Cygwin g77, g95, gfortran; Linux g77, g95, gfortran, ifort).

To me, this looks more maintainable than the original, but others may 
differ!


-- 
Mark Hadfield          "Kei puwaha te tai nei, Hoea tahi tatou"
m.hadfield at niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)


C     !ROUTINE: TIMER_GET_TIME

C     !INTERFACE:
      SUBROUTINE TIMER_GET_TIME( 
     O                           userTime, 
     O                           systemTime, 
     O                           wallClockTime )
      IMPLICIT NONE

C     !DESCRIPTION:
C     *==========================================================*
C     | SUBROUTINE TIMER\_GET\_TIME                                 
C     | o Query system timer routines.                            
C     *==========================================================*
C     | Routine returns total elapsed time for program so far.    
C     | Three times are returned that conventionally are used as  
C     | user time, system time and wall-clock time. Not all these 
C     | numbers are available on all machines.                    
C     *==========================================================*

C     !INPUT/OUTPUT PARAMETERS:
C     userTime      :: User time returned
C     systemTime    :: System time returned
C     wallClockTime :: Wall clock time returned

      Real*8 userTime
      Real*8 systemTime
      Real*8 wallClockTime

C     The following was seriously hacked around by Mark Hadfield
C     October 2006

#ifdef IGNORE_TIME

      userTime = 0.
      systemTime = 0.
      wallClockTime = 0.

#else

C     Declarations follow the same preprocessor structure as the
C     executable code below.

# ifdef TARGET_AIX
      Real*4 etime_
      Real*8 timenow
      external etime_, timenow
      Real*4 actual, tarray(2)
# elif (defined (TARGET_T3E) || defined (TARGET_CRAY_VECTOR))
C     No declarations necessary
# else
#  ifdef HAVE_ETIME
      Real*4 etime
      EXTERNAL etime
      Real*4 actual, tarray(2)
#  else
      Real*8 system_time, user_time
      external system_time, user_time
#  endif
#  if defined HAVE_CLOC
      Real*8 wtime
#  elif (defined (ALLOW_USE_MPI) && defined (USE_MPI_WTIME))
C     No declarations necessary
#  else 
      Real*8 timenow
      external timenow
#  endif /* HAVE_CLOC */
# endif

C     Executable code

# ifdef TARGET_AIX
      actual = ETIME_(tarray)
      userTime      = tarray(1)
      systemTime    = tarray(2)
      wallClockTime = timenow()
# elif (defined (TARGET_T3E) || defined (TARGET_CRAY_VECTOR))
      userTime      = SECOND()
      systemTime    = 0.
      wallClockTime = SECONDR()
# else
#  ifdef HAVE_ETIME
      actual = etime(tarray)
      userTime = tarray(1)
      systemTime = tarray(2)
#  else
      userTime = user_time()
      systemTime = system_time()
#  endif
#  if defined HAVE_CLOC
      CALL cloc(wTime)
      wallClockTime = wtime
#  elif (defined (ALLOW_USE_MPI) && defined (USE_MPI_WTIME))
      wallClockTime = MPI_Wtime()
#  else 
      wallClockTime = timenow()
#  endif
# endif
      
#endif

      RETURN
      END






More information about the MITgcm-support mailing list