co_reduce命令(
https://gcc.gnu.org/onlinedocs/gfortran/CO_005fREDUCE.html#CO_005fREDUCE)的标准示例似乎不起作用.使用np处理器运行示例应该返回产品值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)
最佳答案 再次编辑:
你是对的,这是GFortran和/或OpenCoarrays中的一个错误而不是你的代码.请关注:https://github.com/sourceryinstitute/opencoarrays/issues/172
我们正在将@dantopa的代码添加到我们的回归测试中,并希望在GFortran的7.x版本之前解决此问题…我将尽力记住在修复此问题后更新此问题.
作为解决方法,用intent(in)替换value属性
通过将值属性更改为纯函数myProd()的intent(in)来解决此问题.我不确定这是否是GFortran的实现和/或value属性处理中的错误,IMO编译器应该发出警告/错误(至少我读过MRC的“Modern Fortran Explained”,第117页) ,ii)’必须声明伪参数的意图,除非它是一个过程或一个指针,并且这个意图必须在函数’)的情况下.此外,需要修复用于co_reduce的GFortran示例.