Skip to content

fmanquehual/fortran2018-examples

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fortran 2018 Examples

Actions Status Actions Status Actions Status

Easy examples of scientific computing with modern, powerful, easy Fortran 2018 standard. Fortran 2018 began as the TS18508 extension, formerly known as Fortran 2015.

Modern Fortran benefits from modern CMake, which supports Fortran features such as

  • submodule
  • preprocessing
  • detecting specific support of Fortran features (so users know their compiler is too old)

Based on widespread compiler support and beneficial features, most new and upgraded Fortran programs should use at least portions of the Fortran 2008 standard.

Prereq

  • Linux: apt install cmake gfortran libhdf5-dev libopenmpi-dev libcoarrays-dev open-coarrays-bin
  • Mac: brew install gcc cmake open-mpi opencoarrays
  • Windows MSYS2: pacman -S mingw-w64-x86_64-gcc-fortran mingw-w64-x86_64-msmpi and install Microsoft MS-MPI

Build

The CMake or Meson build system automatically walks through the subdirectories:

CMake

One step CMake build and test:

ctest -S setup.cmake -VV

OR more manually:

cmake -B build
cmake --build build --parallel

cd build
ctest --parallel --output-on-failure

Meson

meson build

meson test -C build

Compilers

ifort Intel

Be sure you have the Intel Parallel Studio Cluster Edition that has mpiifort.

FC=ifort CC=icc CXX=icpc cmake ..

Flang / Clang

Flang is a Free compiler.

FC=flang CC=clang CXX=clang++ cmake ..

PGI

PGI is available at no cost.

FC=pgf90 CC=pgcc CXX=pgc++ cmake ..

Programs

Each directory has its own README and examples.

  • array/: Array math in modern CMake and Fortran, including MKL, BLAS, LAPACK and LAPACK95.
  • block/: Highly useful block element is demonstrated
  • coarray/: modern Fortran is the only major compiled language standard with intrinsic massively parallel arrays.
  • contiguous/: Fortran 2008 contiguous array examples, including Fortran preprocessor with modern CMake.
  • mpi/: MPI parallel computing examples
  • namelist/: Fortran 90 / 2003 Namelist parsing -- native text config files for Fortran
  • openmp/: OpenMP threading exmaples
  • random/: random numbers with modern Fortran

  • io/: modern Fortran File I/O including resolving absolute path

  • cxx/: standard Fortran C / C++ bindings
  • real/: Numerous examples dealing with practical features of real floating point numbers, including sentinel NaN and polymorphism.
  • character/: String handling is easy and performant in modern Fortran.
  • standard/: advanced features that can be done with Fortran standard coding
  • submodule: Fortran 2008 and CMake ≥ 3.12 enable even better large program architecture with submodule
  • system/: system (hardware) functionality accessible via Fortran

Companion libraries

Bugs

iso_fortran_env

Flang 6 and PGI 18.10 seem to have a bug with iso_fortran_env that doesn't allow compiler_version and compiler_options to work unless use iso_fortran_env is ONLY used in program and NOT module even if using only. Thus, simple programs like pragma.f90 work, but not the usual programs to print the compiler versions and options with Flang and PGI.

Resources

Fortran standards

Books

Compiler User Guides

Surveys

About

Modern Fortran basic examples with broad applications

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Fortran 53.5%
  • CMake 26.9%
  • Meson 10.6%
  • Python 6.7%
  • C++ 1.4%
  • Shell 0.8%
  • C 0.1%