fortran66のブログ

fortran について書きます。

Intel Fortran Ver.18 出る!

Intel Fortran v.18.0  2018

ベータ版を配っていた Intel Fortran v.18 が正式版となってリリースされました。

coarray を少しいじってみましたが、なかなか思い通りに使えません。あびゃー


メモ帳

イメージ1番が、任意の順番で来るイメージ2以降に、先着順に着順を与えるプログラムを書きました。本当は先着1名様に景品を与え、2番目以降には豪華粗品を与えるプログラムを書きたかったのですが、難航したので番号で。

実行結果

           1           0
           2           5
           3           6
           4           3
           7           4
           8           7
           6           1
           5           2

  0
  6
  5
  4
  7
  2
  3
  8
  1
  2 text from 1           5
  3 text from 1           6
  4 text from 1           3
  5 text from 1           2
  6 text from 1           1
  7 text from 1           4
  8 text from 1           7
続行するには何かキーを押してください . . .

ソース・プログラム

critical でも lock でもいいが、critical 中では sync 等が使えない。イメージ1側のループでは、sync memory がないとうまくゆかない。

    program caflock
      use, intrinsic :: iso_fortran_env 
      implicit none
      type(lock_type) :: lock[*]
      integer :: i = 1, me, ne, no = 0, nn[*] = 0
      integer, allocatable :: mm(:)[:]
      character(len = 80) :: text[*], buff
      me = this_image()
      ne = num_images()
      allocate(mm(ne)[*]) ! implicitly sync all
      if (me /= 1) then
        critical
!         lock(lock[1])   
          no = nn[1] + 1
          nn[1] = no
          mm(no + 1)[1] = me
!         unlock(lock[1]) 
        end critical
      else
        do
          sync memory  
          if (nn >= i) then
            if (mm(i + 1) == 0) cycle
            write(buff, *) 'text from 1', i  
            i = i + 1
            text[mm(i)] = buff
          end if  
          sync memory
          if (i == ne) exit  
        end do
      end if    
      sync all
      print *, me, no   
      sync all
      if (me == 1) print '(/(i3))', mm
      if (me > 1) sync images(me - 1)
        print '(i3, a)', me, trim(text)
      if (me < ne) sync images(me + 1)
    end program caflock