fortran66のブログ

fortran について書きます。

【メモ帳】Fortran 2018 の CAF 機能を試す

Jupyter 上の OpenCoarrays

Sourcery Institute の好意で Jupyter 上で OpenCoarrays を試すことができます。(以下のページより)
github.com

少し、新しい CAF 機能を試してみることにします。

event post

ソース・プログラム
program test
  use, intrinsic :: iso_fortran_env
  implicit none
  type (event_type) :: et[*]
  integer :: m[*]
  event post(et[2])
  call event_query(et, m)
  print *, m
  sync all
  if (this_image() == 2) then 
    event wait(et, until_count = 4)
  else
    event wait(et, until_count = 0)
  end if   
  print *, m, this_image()
end program test
実行結果
           3
           0
           0
           0
           0           1
           0           3
           0           4
           3           2

reduction 計算

ソース・プログラム
module m_test
  implicit none
contains
  pure integer function im(i0, i1)
    integer, intent(in) :: i0, i1
    im = i0 + i1
  end function im  
end module m_test

program test
  use  m_test
  use, intrinsic :: iso_fortran_env
  use, intrinsic :: iso_c_binding, only: c_int
  implicit none
  integer:: m
  m = this_image()
  call co_sum(m, 1)
  print *, m
  call co_broadcast(m, 1)
  print *, m
  call co_reduce(m, im)
  print *, m, this_image()
end program test
実行結果
          10
          10
           2
          10
           3
          10
           4
          10
          40           1
          40           2
          40           3
          40           4

atomic 演算

ソース・プログラム
program test
  use, intrinsic :: iso_fortran_env
  implicit none
  integer(atomic_int_kind) :: ka[*]
  integer :: n
  ka = 0
  call atomic_add(ka[1], this_image())
  sync all
  if (this_image() == 1) print *, ka
end program test
実行結果
          10

Fortran 2018 in Fortran Wiki

CoArrays: Parallel Programming in Fortran (Chapman & Hall/CRC Computational Science)

CoArrays: Parallel Programming in Fortran (Chapman & Hall/CRC Computational Science)

Modern Fortran Explained (Numerical Mathematics and Scientific Computation)

Modern Fortran Explained (Numerical Mathematics and Scientific Computation)

Modern Fortran:: Software Engineering for Scientists (Chapman & Hall/CRC Computational Science)

Modern Fortran:: Software Engineering for Scientists (Chapman & Hall/CRC Computational Science)

Numerical Computing with Modern Fortran (Applied Mathematics)

Numerical Computing with Modern Fortran (Applied Mathematics)