Maximum number of continuation line `&`

@davidpfister ,

I am dabbling with Fortran after a long, long time, actually I was pointed to your thread by a colleague at work who has to support one of a few remaining codebases in Fortran and who too was looking into compile-time computations and who reached out to me after noticing some old posts of mine (e.g., this). This colleague is adding some capabilities to the Fortran codebase in order to help it get consumed in cloud service requests, meaning concurrent execution.

Here’s the code example I suggested to this colleague who requested I also post here: the gist is a) use “named constant” facilities in Fortran as much as possible for “compile-time” data / database, etc. and b) avoid DATA statements, if possible, for you will find it’s not strictly compile-time computation and you are in effect applying the “static” (implied SAVE in Fortran parlance) attribute to the object that can prove pernicious in concurrent / parallel computing.

module kinds_m
   use ieee_arithmetic, only : ieee_selected_real_kind
   integer, parameter :: sp = ieee_selected_real_kind( p=6 )
   integer, parameter :: rp = sp
end module
 
module item_m
   use kinds_m, only : rp
   integer, parameter :: LENNAME = 8
   type :: item_t
      character(len=LENNAME) :: item_name
      real(kind=rp) :: val = 0.0_rp
   end type 
end module

program p

   use kinds_m, only : rp
   use item_m, only : item_t

   ! Compile time "database"
   integer, parameter :: n = 10000
   type(item_t), parameter :: db(*) =  &
      [( item_t( item_name="item1", val=real(i, kind=rp)), integer :: i = 1, n )]

   print *, "item ", "1", ": ", db(1)
   print *, "item ", "2", ": ", db(2)
   print *, ".. "
   print *, "item ", n, ": ", db(n)

end program 

You can execute this with a modern Fortran compiler of your choice to get response as follows:

C:\Temp>ifx /free /standard-semantics p.f
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2023.0.0 Build 20221201
Copyright (C) 1985-2022 Intel Corporation. All rights reserved.

Microsoft (R) Incremental Linker Version 14.36.32548.0
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:p.exe
-subsystem:console
p.obj

C:\Temp>p.exe
 item 1: item1    1.000000
 item 2: item1    2.000000
 ..
 item  10000 : item1    10000.00

C:\Temp>

Add CONSTEXPR procedures in Fortran · Issue #214 · j3-fortran/fortran_proposals
Perhaps you will review this suggestion of mine to Fortran language workers re: CONSTEXPR attribute on suitable functions in Fortran but it is languishing. Such a facility may help you - some 40 to 50 years from now - with better setting up of “compile-time” database viz. not having to name each item as item1 :winking_face_with_tongue: (.. item(‘item1’, 1.0_rp), .. item(‘item1’, 2.0_rp))

1 Like