soccer jersey forums.silverfrost.com :: View topic - Fortran 2003 and 2008 features
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Fortran 2003 and 2008 features
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Suggestions
View previous topic :: View next topic  
Author Message
DanRRight



Joined: 10 Mar 2008
Posts: 2867
Location: South Pole, Antarctica

PostPosted: Mon Sep 05, 2022 9:08 am    Post subject: Reply with quote

Meantime let's return to our sheep.
This example does not compile with FTN95

Code:
module basis_module
  implicit none

  type, abstract :: Basis
    integer :: NBasis
  contains
    procedure(allocBasisR1Interface), deferred :: allocateBasisR1
    generic :: allocateBasis => allocateBasisR1
  end type Basis

  interface
    ! Interface for real basis allocation
    subroutine allocBasisR1Interface(self, array)
      import
      class(Basis), intent(inout) :: self
      real, intent(in) :: array(:)
    end subroutine allocBasisR1Interface
  end interface

end module basis_module


module extension_module
  use basis_module
  implicit none

  type, extends(Basis) :: GridBasis
  contains
    ! Extending the mapping allocateBasis => allocateBasisR1 of
    ! the parent type.
    generic :: allocateBasis => allocateBasisC1
    procedure :: allocateBasisC1
    ! Implementation for the deferred procedure in Basis
    procedure :: allocateBasisR1
  end type GridBasis

contains

  subroutine allocateBasisR1(self, array)
    class(GridBasis), intent(inout) :: self
    real, intent(in) :: array(:)

    self%NBasis = size(array)
    print *, "GridBasis:allocateBasisR1"

  end subroutine allocateBasisR1


  subroutine allocateBasisC1(self, array)
    class(GridBasis), intent(inout) :: self
    complex, intent(in) :: array(:)

    self%NBasis = size(array)
    print *, "GridBasis:allocateBasisC1"

  end subroutine allocateBasisC1

end module extension_module


program test
  use extension_module
  implicit none

  type(GridBasis) :: mybasis
  real :: myRealArray(10)
  complex :: myComplexArray(5)

  call mybasis%allocateBasis(myRealArray)
  call mybasis%allocateBasis(myComplexArray)

end program test
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8018
Location: Salford, UK

PostPosted: Mon Sep 05, 2022 9:38 am    Post subject: Reply with quote

Dan
Would you use this feature of Fortran 2003/8 if it was added to FTN95?
These "suggestions" should be about useful additions.
Back to top
View user's profile Send private message AIM Address
DanRRight



Joined: 10 Mar 2008
Posts: 2867
Location: South Pole, Antarctica

PostPosted: Mon Sep 05, 2022 11:07 am    Post subject: Reply with quote

Paul,

This is another demo of another 2003-2008 feature from the codes i learn and i try to use which are compiled with gFortran, Intel etc but not with FTN95. If these codes would compile with FTN95 that would simplify the life immensely as there are no such nice GUI debuggers for other Linux compilers like SDBG64. Without such GUI debugger just to understand how these codes doing even elementary things is like deciphering Enigma machine.

When i find new unknown to FTN95 features in the codes i then search the web and find good demo which demonstrates this feature.

My postings would be unnecessary if you guys at Silverfrost just try to compile these codes i mentioned before and find what the other programmers seems very widely using. My shocking discovery of last months was that if in some other respects FTN95 is by far ahead of other compilers (GUI, OpenGL, fast compilation, HDMI, graphics, bug hunting in older codes) but in the Fortran 2003-2008, OpenMP and OpenMPI parallelization, fast execution, C/C++ integration it is not just the last but lagging far behind all other Fortran compilers which all compile these codes. This is leaving FTN95 not only as the one which can not compile modern codes but which seems is not even close. Intel for example is already fully Fortran-2018 capable.

Additionally what FTN95 missing are the major features which are associated in the perception of absolutely all people with why to use Fortran, not some other compilers Like C, Python, Matlab or new fashion Julia. Because all think that first of all Fortran means being #1 in speed. I afraid the lag here is like a decade or more because the same Intel for example is using all cores of processors by auto-parallelization and in some even single core tests beating FTN95 by an order of magnitude. It also supports all other parallelization techniques including graphics GPU-based like NVIDIA CUDA what all other compilers also do (GPU is a new unstoppable trend) while FTN95 has none excluding one proprietary workaround (i mean FTN95 specific multithreading subroutine. I may also add linear algebra libraries like Laipe or MKL). That in most cases gives additional orders and orders of magnitude ahead of FTN95.

Autoparallelization these my "modern Fortran" codes not using. And not using GPU. Which means that even these my modern codes are not that modern.
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2867
Location: South Pole, Antarctica

PostPosted: Tue Sep 06, 2022 2:38 am    Post subject: Reply with quote

More extractions from these PIC codes which are Fortran 2003/2008 addition:

1) "ERROR STOP" instead of just STOP.

Used for stopping all running images (processes) while STOP just stops execution of the current image.

2) "Protected" (Fortran 2003)
Example:
integer, protected :: GAS_num_gases = 0

3) NEWUNIT in OPEN (Fortran 2008).
The NEWUNIT specifier opens a file on an unused unit number that is automatically chosen.

Example:
open (newunit=my_unit, ....

4) attribute "non_overridable" (Fortran 2003)

Example:
procedure, non_overridable :: set_random_seed

5) Got error here
Code:
if (iand(jmp_c(i), shiftl(1_i8, b)) /= 0) then
*** The second argument (J) to the intrinsic IAND must be of INTEGER type, not
    REAL(KIND=1)
*** SHIFTL must appear in a type declaration because IMPLICIT NONE has been
    used


Looks like SHIFTL(I, SHIFT) (Fortran 2008) is missing or/and IAND does something with possibly boz-literal (?) variable (Fortran 2003)

Also here
Code:
 res = ior(shiftl(x, k), shiftr(x, 64 - k))
*** The first argument (I) to the intrinsic IOR must be of INTEGER type, not
    REAL(KIND=1)
*** The second argument (J) to the intrinsic IOR must be of INTEGER type, not
    REAL(KIND=1)
*** SHIFTR must appear in a type declaration because IMPLICIT NONE has been
    used
*** SHIFTL must appear in a type declaration because IMPLICIT NONE has been
    used


I temporally substituted Error Stop with just the Stop, removed PROTERCTED and non_overridable attributes, changed NEWUNIT with just the UNIT but SHIFTL and IAND putted the stop on my efforts to further compile this code with FTN95
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8018
Location: Salford, UK

PostPosted: Tue Sep 06, 2022 7:02 am    Post subject: Reply with quote

Dan

Although our aim is to provide the best Fortran compiler that we can, it is sensible for us to prioritise and look first at the improvements that are most useful to our current users.

I suggest that you use a different compiler (i.e. not FTN95) when exploring the latest additions to the Fortran Standard. When you see a feature that you understand and would like to use in your own code, then make a request.

Frankly I don't think that you are likely to need or use any of the new features that you have listed. If you are collaborating with others who use these features then you will need to use the same compiler that they are using.

In the meantime, ask for something that is do-able in a matter of days not years. Your request for NORM2, for example, required 2 or 3 man days to implement. It was also something that other FTN95 users might want to use.
Back to top
View user's profile Send private message AIM Address
Kenneth_Smith



Joined: 18 May 2012
Posts: 715
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Sun Oct 16, 2022 10:59 pm    Post subject: Reply with quote

In Fortran 2008, the intrinsic function ATAN now has an extra form ATAN(Y,X), which is exactly the same as ATAN2(Y,X), i.e. the following code is valid in Fortran 2008:

Code:
print*, ATAN(1.d0,1.d0)


Another one to possibly add to the list - sorry Paul. This really had me confused looking at a colleague's new code.
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8018
Location: Salford, UK

PostPosted: Mon Oct 17, 2022 7:44 am    Post subject: Reply with quote

Thanks Ken. I will make a note of this.
Back to top
View user's profile Send private message AIM Address
Kenneth_Smith



Joined: 18 May 2012
Posts: 715
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Wed Oct 19, 2022 1:57 pm    Post subject: Reply with quote

Thanks Paul, I think it is important that the core math functions of the later versions of the standard find their way into Silverfrost Fortran - and you have come a long way toward achieving this since this thread was started, for which we are all grateful.

There has been an extension to the support for complex numbers in 2008 that permit the independent assignment of the real and imaginary parts of a complex number. It is also possible to extract these parts without the use of the REAL or AIMAG functions. Below is a simple example of what is now possible via the % operator i.e. the complex number looks like a derived type in this context.

Code:
program new_complex
complex z
!                               ! Classical assignment and extraction of Real and Imaginary parts
z = (0.0,1.0)                   ! z = 0 + j1
print*, real(z), aimag(z)       ! prints  0.00000000       1.00000000

                                ! New ways as permitted by 2008
                               
print*, z%re, z%im              ! Instead of print*, real(z), aimag(z), prints  0.00000000       1.00000000
z%re = 1.0                      ! Set real part only
print*, z%re, z%im              ! Prints    1.00000000       1.00000000 
z%im = 0.0                      ! Set imaginary part only
print*, z%re, z%im              ! Prints    1.00000000       0.00000000
end program new_complex


I suspect this may be a more difficult one to implement, but please take a look at this to see if it may be possible to implement this extension within FTN95. The multiple/sequential/independent assignment of real and imaginary parts in code written for a 2008 compiler using this "derived type" would be rather time-consuming/error-prone to reverse into FTN95 format.
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8018
Location: Salford, UK

PostPosted: Wed Oct 19, 2022 2:47 pm    Post subject: Reply with quote

Thanks Ken. I will add it to the list.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8018
Location: Salford, UK

PostPosted: Sat Oct 22, 2022 11:32 am    Post subject: Reply with quote

ATAN(y,x) has now been added for the next release of FTN95.
Back to top
View user's profile Send private message AIM Address
Kenneth_Smith



Joined: 18 May 2012
Posts: 715
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Tue Oct 25, 2022 10:33 am    Post subject: Reply with quote

Thanks Paul, I can see ATAN(y,x) is implemented in the latest download.
Back to top
View user's profile Send private message Visit poster's website
JohnCampbell



Joined: 16 Feb 2006
Posts: 2586
Location: Sydney

PostPosted: Fri Nov 18, 2022 7:33 am    Post subject: ISO_FORTRAN_ENV Reply with quote

Paul,

I was trying to locate what features had been added to iso_fortran_env but could not find any documentation.

I wrote the following program to see what might come out.

I noted:
"integer_kinds" is not included ?
"iostat_end" /= -1 and "iostat_eor" not included
"numeric_storage_size" and "file_storage_size" not included

("int128" and "real80" are not in the standard, but I think "real128" is)

I think these are just constants so some may be an easy update and may help with documentation ?

Code:
  use iso_fortran_env
!     implicit real( a-h, o-z )
!     implicit integer ( i-n )

     write (*,*) 'input_unit           =', input_unit
     write (*,*) 'output_unit          =', output_unit
     write (*,*) 'error_unit           =', error_unit
     write (*,*) 'numeric_storage_size =', numeric_storage_size
     write (*,*) 'file_storage_size    =', file_storage_size
     write (*,*) 'integer_kinds        =', integer_kinds
     write (*,*) 'real_kinds           =', real_kinds
     write (*,*) 'logical_kinds        =', logical_kinds
     write (*,*) 'iostat_end           =', iostat_end
     write (*,*) 'iostat_eor           =', iostat_eor

     write (*,*) ' int8    =',int8     
     write (*,*) ' int16   =',int16   
     write (*,*) ' int32   =',int32   
     write (*,*) ' int64   =',int64   
     write (*,*) '#int128  =',int128

     write (*,*) ' real32  =',real32   
     write (*,*) ' real64  =',real64
     write (*,*) '#real80  =',real80
     write (*,*) ' real128 =',real128   
     
    end
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8018
Location: Salford, UK

PostPosted: Fri Nov 18, 2022 8:35 am    Post subject: Reply with quote

Thanks John. I have made a note of your suggestion.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8018
Location: Salford, UK

PostPosted: Fri Nov 18, 2022 1:03 pm    Post subject: Reply with quote

iso_fortran_env has been ammended for the next full release of FTN95.

The associated results for real_kinds and real80 relate to 64 bit FTN95 and are:

INTEGER,PARAMETER::REAL80=-1
INTEGER,PARAMETER::REAL_KINDS(2)=(/1,2/)

The values for 32 bit FTN95 are different from those provided by iso_fortran_env and are:

INTEGER,PARAMETER::REAL80=3
INTEGER,PARAMETER::REAL_KINDS(3)=(/1,2,3/)
Back to top
View user's profile Send private message AIM Address
JohnCampbell



Joined: 16 Feb 2006
Posts: 2586
Location: Sydney

PostPosted: Fri Nov 18, 2022 1:27 pm    Post subject: Reply with quote

Paul,

It is good to include in ISO_FORTRAN_ENV, those parameters that are relevant to FTN95 extensions for F03 and F08.

Just to clarify; I was checking if real80 or integer128 possibly might have existed. They are not in the standard, but should be listed in REAL_KINDS and INTEGER_KINDS if relevant.

It is a good change that "real_kinds" differ for 32 and /64

"integer_kinds" are in the standard and are an important report.

Thanks for these prompt updates.

John

( ps : have you considered including a /32 compile option ? )
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Suggestions All times are GMT + 1 Hour
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
Page 8 of 10

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group