2016-04-15 16 views
4

co_reduceコマンドの標準例(https://gcc.gnu.org/onlinedocs/gfortran/CO_005fREDUCE.html#CO_005fREDUCE)は動作していないようです。 npプロセッサを使用してこの例を実行すると、Product valuenp!と返されます。最初の画像の値は一見ランダムな方法で破損している:np = 4co_reduceを使用したFortranコアアレイ

18:10 rditldmt $ caf co_reduce_example.f08 -o co_reduce_example 
18:10 rditldmt $ cafrun -np 4 ./co_reduce_example 
Number of images = 4 
value [ 1 ] is 1690042368 
value [ 2 ] is 2 
value [ 3 ] is 3 
value [ 4 ] is 4 
Product value = 1690042368 
Expected value = num_images()! 
2! = 2, 3! = 6, 4! = 24, ... 

、予想回答= 24。計算の答え= 1690042368.

Anは例のバージョンをインストルメント、co_reduce_example.f08は、次のとおりです。

program co_reduce_example 

implicit none 
integer :: value[ * ] 
integer :: k 
    value = this_image () 
    call co_reduce (value, result_image = 1, operator = myProd) 
    if (this_image () == 1) then 
     write (* , '("Number of images = ", g0)') num_images () 
     do k = 1, num_images () 
      write (* , '(2(a, i0))') 'value [ ', k, ' ] is ', value [ k ] 
     end do 
     write (* , '("Product value = ", g0)') value ! prints num_images() factorial 
     write (* , 100) 
    end if 
100 format ("Expected value = num_images()!", /, " 2! = 2, 3! = 6, 4! = 24, ...") 

contains 

    pure function myProd (a, b) result (rslt) 
     integer, value :: a, b 
     integer  :: rslt 
      rslt = a * b 
     end function myProd 

end program co_reduce_example 

がどのようにコードを修正しますか?

Co-ArrayのFortranのバージョン:

17:50 rditldmt $ cafrun -v 

OpenCoarrays Coarray Fortran Executable Launcher (caf version 1.3.6) 
Copyright (C) 2015-2016 Sourcery, Inc. 

OpenCoarrays comes with NO WARRANTY, to the extent permitted by law. 
You may redistribute copies of OpenCoarrays under the terms of the 
BSD 3-Clause License. For more information about these matters, see 
the file named LICENSE. 

のgfortranバージョン:

17:54 rditldmt $ gfortran -v 
Using built-in specs. 
COLLECT_GCC=gfortran 
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin15/6.0.0/lto-wrapper 
Target: x86_64-apple-darwin15 
Configured with: /opt/local/var/macports/build/_opt_mports_dports_lang_gcc6/gcc6/work/gcc-6-20160327/configure --prefix=/opt/local --build=x86_64-apple-darwin15 --enable-languages=c,c++,objc,obj-c++,lto,fortran,java --libdir=/opt/local/lib/gcc6 --includedir=/opt/local/include/gcc6 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-6 --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-6 --with-gxx-include-dir=/opt/local/include/gcc6/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-isl=/opt/local --enable-stage1-checking --disable-multilib --enable-lto --enable-libstdcxx-time --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --with-pkgversion='MacPorts gcc6 6-20160327_0' 
Thread model: posix 
gcc version 6.0.0 20160327 (experimental) (MacPorts gcc6 6-20160327_0) 
+3

出血の端をテストしています。 Crayコンパイラでさえこれをサポートしていません。 OpenCoarrayとgfortranの実装にバグがあったとしても驚くことはありません。おそらく、https://github.com/sourceryinstitute/opencoarrays/issuesで問題を開くべきであり、あなたが得ることができる最も知識のある人からの回答を得る可能性が非常に高いです。 –

+1

@VladimirF:いい考えです。 https://github.com/sourceryinstitute/opencoarrays/issues/172 – dantopa

答えて

1

が再編集:

あなたは正しい、これはのgfortranおよび/またはOpenCoarraysのバグとNOTあなたですコード。 https://github.com/sourceryinstitute/opencoarrays/issues/172

回帰テストに@ dantopaのコードを追加しています。この問題はGFortranの7.xリリースより前に解決されていることを願っています...修正されました。

は、回避策として、 pure function myProd()ため intent(in)value属性を変更することにより、 intent(in)


問題が解決されるとvalue属性を交換してください。私はこれがGFortranの実装や、value属性の処理のバグであるかどうか確かではなく、コンパイラが警告/エラーを発したはずです(MRCの "Modern Fortran Explained" 、ii)仮引数の目的は、手続きまたはポインタでなければ宣言しなければならず、この目的は関数の場合にはinでなければならない。さらに、co_reduceのGFortranの例を修正する必要があります。

+1

"C1276純関数サブプログラムの仕様部分は、すべての非ポインタダミーデータオブジェクトがINTENT(IN)**またはVALUE属性を持つことを指定しなければならない** "たぶんco_reduceには他の要件があるかもしれませんが、価値は純粋な手順には合法です。 –

+1

これはgccがhttps://gcc.gnu.org/bugzilla/show_bug.cgi?id=47507を許可する理由です –

関連する問題