Fortran coarray与co_reduce的异常

时间:2016-04-15 23:15:47

标签: gcc parallel-processing fortran gfortran

co_reduce命令(https://gcc.gnu.org/onlinedocs/gfortran/CO_005fREDUCE.html#CO_005fREDUCE)的标准示例似乎不起作用。使用np处理器运行示例应返回Product value np!第一个图像的值以看似随机的方式被破坏:

 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, ...

使用np = 4,预期答案= 24;计算答案= 1690042368。

示例的检验版本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

如何更正代码?

Coarray 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) 

1 个答案:

答案 0 :(得分:1)

再次编辑:

你是对的,这是GFortran和/或OpenCoarrays中的错误而不是你的代码。请跟随:https://github.com/sourceryinstitute/opencoarrays/issues/172

我们正在将@ dantopa的代码添加到我们的回归测试中,并希望在GFortran的7.x版本之前解决此问题...我会尝试记住更新此问题已经修好了。

要解决此问题,请将value属性替换为intent(in)

通过将value的{​​{1}}属性更改为intent(in)来解决问题。我不确定这是否是GFortran的实现和/或pure function myProd()属性处理中的错误,IMO编译器应该发出警告/错误(至少我的阅读"现代Fortran解释"由MRC,第117页,ii)'必须声明伪参数的意图,除非它是一个过程或一个指针,并且这个意图必须是value在函数')的情况下。此外,需要修复co_reduce的GFortran示例。