gcc - 带有 co_reduce 的 Fortran coarray 异常

标签 gcc parallel-processing fortran gfortran

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

 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) 

最佳答案

再次编辑:

您是对的,这是 GFortran 和/或 OpenCoarrays 中的错误,而不是您的代码。关注:https://github.com/sourceryinstitute/opencoarrays/issues/172

我们正在将@dantopa 的代码添加到我们的回归测试中,并希望在 GFortran 7.x 版本之前解决这个问题......一旦它被修复,我会尽量记住更新这个问题。

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

关于gcc - 带有 co_reduce 的 Fortran coarray 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36658286/

相关文章:

c++ - C++中的简单客户端服务器程序无法正常工作

c - 有助于理解 C 和 C++ 中#define、const 和 enum 在汇编级别上的差异

Python 多进程丢失了进程并在不应该完成的时候完成了连接

c - 当我尝试使用 ./secondo 执行此代码时,我收到此错误

c++ - 使用 GCC 在 Linux 上 boost 链接

matlab - 减少 Matlab 表

macos - Mac OS X 版本 10.6.7 上 .parallel=TRUE 时 ddply 速度较慢

memory - fortran 函数是否总是将返回值的结果复制到接受变量中?

fortran - 派生类型中的可变长度数组

multithreading - omp_get_num_threads() 和 omp_get_thread_num() 返回废话