提问人:Clerni 提问时间:11/5/2023 更新时间:11/5/2023 访问量:32
在 Fortran 中使用可分配的字符串协数组
Using an allocatable string coarray in Fortran
问:
我正在使用 Fortran CoArrays(使用 OpenCoarrays 和来自 OpenCoarrays)编写一些代码,这些代码需要具有可分配长度的 coarray 字符串。它可以通过以下代码来举例说明:caf
cafrun
program CoarrayExample
character(:), allocatable :: string[:]
integer :: numImages, image, stringLength
stringLength = 50
allocate(character(stringLength) :: string[*])
numImages = num_images()
sync all
do image = 1, numImages
if (this_image() == image) then
write(string, '(A,I0)') "Image ", this_image()
end if
end do
sync all
if (this_image() == 1) then
do image = 1, numImages
write(*,*) string[image]
end do
end if
sync all
end program CoarrayExample
该代码应为每个包含文本的图像存储一个字符串副本,其中是图像的编号。然后,第一个图像应将数据输出到 。"Image <n>"
<n>
stdout
编译器编译(command:)没有问题,但是在运行(command:)时,我得到不一致的行为。有时我只得到空行,有时我得到字符串,但它们被切断了,有时我什至得到错误:caf example.f90 -o example
cafrun -np 4 ./example
stdout
Image 1
--------------------------------------------------------------------------
Primary job terminated normally, but 1 process returned
a non-zero exit code. Per user-direction, the job has been aborted.
--------------------------------------------------------------------------
--------------------------------------------------------------------------
mpiexec noticed that process rank 0 with PID 0 on node pop-os exited on signal 11 (Segmentation fault).
--------------------------------------------------------------------------
Error: Command:
`/usr/bin/mpiexec -n 4 ./example`
failed to run.
当我删除分配时,所有问题都消失了。例如,以下代码工作正常:
program CoarrayExample
character(len=50) :: string[*]
integer :: numImages, image
numImages = num_images()
sync all
do image = 1, numImages
if (this_image() == image) then
write(string, '(A,I0)') "Image ", this_image()
end if
end do
sync all
if (this_image() == 1) then
do image = 1, numImages
write(*,*) string[image]
end do
end if
sync all
end program CoarrayExample
知道问题可能是什么吗?
引用
答: 暂无答案
评论