Fortran在gdb中打印可分配数组 [英] Fortran print allocatable array in gdb

查看:184
本文介绍了Fortran在gdb中打印可分配数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一些功能添加到开源科学代码中。我使用了很多allocatables,但我在正确打印时遇到了一些麻烦。例如,我声明并分配,然后使用:

  real(dp),allocatable :: psi_n_phi(:) 
!一些其他的东西在这里
分配(psi_n_phi(1:fock_info%nocc(isp)))
!在这种情况下,nocc(isp)简直等于1
!一些其他的东西在这里
do n = 1,fock_info%nocc(isp)
psi_n_phi(n)= dot_product(fock_info%psi(:, n,isp),p)
enddo

后来我得到一个数组不匹配的问题,我正在使用gdb来找出原因。如果我打印:

 (gdb)p psi_n_phi 
$ 23 =(0)

但显然情况并非如此:

 (gdb)p psi_n_phi @ 1 
$ 25 =((0))
(gdb)p psi_n_phi @ 2
$ 26 =((0)(0))
(gdb)p psi_n_phi @ 10
$ 28 =((0)(0)(0)(2.0162819006781271e-320)(2.2600760244771319e-316)(2.3792209431030402e-316)(6.9179818424594845e-310) )(2.2598704931684619e-316)(6.9179818424672413e-310)(0))

关于使用 @ 符号。 htmlrel =nofollow> http://numericalnoob.blogspot.co.il/2012/08/fortran-allocatable-arrays-and-pointers.html 。这只是我在这个问题上找到的唯一来源,尽管我还看到过其他一些问题,人们遇到类似的问题(但他们都无法修复它)。



这里的任何想法?我想知道为什么打印它只是以((0))的形式出现,以及如何使它像普通数组一样打印。

解决方案

更新:在Ubuntu 16.04 LTS中直接使用

已经讨论了将近十年(例如 https://sourceware.org/bugzilla/ show_bug.cgi?id = 9395 ),并且在一些发行版中部分修复。我有报告 gdb中与Ubuntu相同的问题14.04 LTS。解决方法与Francois Jacq在这里所建议的类似,但不会破坏dpkg控制的目录。



我使用本地Ubuntu repo的外来工具将gdb RPM从Fedora(即GNU gdb(GDB)Fedora 7.9-10.fc23)转换成.deb包,然后使用dpkg进行安装。现在我已经以类似的方式从OpenSUSE安装了gdb-7.9.1-7.1.x86_64.rpm:

  fakeroot alien gdb- 7.9.1-7.1.x86_64.rpm 
sudo dpkg -i gdb_7.9.1-8.1_amd64.deb

在很多情况下,它可以通过简单的指针和可分配数组正确工作。虽然gdb的段错误通常是在尝试触及大型和/或复杂结构时。也许,这就是为什么许多维护人员不愿意将fortran补丁包含到主流中的原因。



请考虑确认发行版错误跟踪器中的错误,以便维护人员支付更多费用注意它。


I'm adding some functionality on to an open-source scientific code. I work with a lot of allocatables, but I'm having some trouble printing them properly. For example, I declare and allocate, and then use:

real(dp), allocatable :: psi_n_phi(:)
! some other stuff here
allocate(psi_n_phi(1:fock_info%nocc(isp)))
! nocc(isp) is simply equal to 1 in this context
! some other stuff here
do n = 1, fock_info%nocc(isp)
    psi_n_phi(n) = dot_product(fock_info%psi(:, n, isp), p)
enddo

I later get an array mismatch and I am using gdb to figure out why. If I print:

(gdb) p psi_n_phi 
$23 = (0)

But this clearly is not the case, as evidenced by:

(gdb) p psi_n_phi@1
$25 = (( 0) )
(gdb) p psi_n_phi@2
$26 = (( 0) ( 0) )
(gdb) p psi_n_phi@10
$28 = (( 0) ( 0) ( 0) ( 2.0162819006781271e-320) ( 2.2600760244771319e-316) ( 2.3792209431030402e-316) ( 6.9179818424594845e-310) ( 2.2598704931684619e-316) ( 6.9179818424672413e-310) ( 0) )

I got the information about using the @ notation from http://numericalnoob.blogspot.co.il/2012/08/fortran-allocatable-arrays-and-pointers.html. This is just about the only source I can find on the issue, although I have seen some other questions where people run into similar issues (but none of them were able to fix it).

Any ideas here? I would like to understand why printing it just comes out as ((0)), and how I can get it to print like a normal array.

解决方案

UPDATE: Works out-of-the-box in Ubuntu 16.04 LTS

The issue is being discussed for almost a decade already (e.g. https://sourceware.org/bugzilla/show_bug.cgi?id=9395) and is partially fixed in some distros. I have reported the same problem in gdb that comes with Ubuntu 14.04 LTS. The workaround was in a similar fashion as Francois Jacq suggested here, but without damaging dpkg-controlled directories.

I have used alien tool from native Ubuntu repo to convert a gdb RPM from Fedora (namely GNU gdb (GDB) Fedora 7.9-10.fc23) into .deb package, and then used dpkg to install it. Now i have installed gdb-7.9.1-7.1.x86_64.rpm from OpenSUSE in a similar manner:

fakeroot alien gdb-7.9.1-7.1.x86_64.rpm
sudo dpkg -i gdb_7.9.1-8.1_amd64.deb

In many cases it works correctly with simple pointers and allocatable arrays. Though segfaults of gdb are often when trying to touch large and/or complex structures. Probably, that is why many maintainers prefer not to include the fortran patch into mainstream...

Please consider confirming the bug in your distro bug trackers, so maintainers will pay more attention to it.

这篇关于Fortran在gdb中打印可分配数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆