我遇到了deallocate的问题,并分配了部分FORTRAN代码的各个方面。特别是,我认为这个问题与通过搜索我在网络上的错误消息的内存分配有关。错误消息谈论无效指针,但是,我没有在我的程序中使用任何指针
完成我的f循环的迭代#2(见下文)后,程序崩溃,或者大部分时间它崩溃,有时它只是冻结。我相信这就是bug的关键所在。因为程序运行到了这一点。
我有子程序没有显示,但由于它们适用于其他模拟组合,我有理由相信它们不是问题。我正在使用deallocate并在程序中的其他地方分配(成功)所以我很惊讶它在这里不起作用。
我只是为了便于阅读而展示了该计划的一部分。特别是,我已经删除了对我编写的子程序的调用。我希望我已经为你的程序员提供了足够的信息来帮我解决问题。如果没有,请说明您想要的其他信息,我将很乐意遵守。我已经使用各种编译器选项编译了程序,并修复了一些错误并删除了任何警告。但是,此时,编译器选项不再向我提供任何信息。
allocate(poffvect(1:6))
allocate(phi1out(1:1))
allocate(phi2out(1:1))
allocate(phi1outs1(1:1))
allocate(phi2outs1(1:1))
dummy allocation
allocate(phi1outind(1:1))
allocate(phi2outind(1:1))
allocate(phi1outinds1(1:1))
allocate(phi2outinds1(1:1))
do e = 1, 6
print *,"e", e
do f = 1, 3
print *,"f", f, iteratst1(f), trim(filenumcharimp)
deallocate(phi1outinds1, STAT = AllocateStatus)
if (AllocateStatus /= 0) stop "Error during deallocation of phi1outinds1"
print *, "Allocatestatus of phi1outinds1 is", AllocateStatus
deallocate(phi2outinds1, STAT = AllocateStatus)
print *, "DeAllocatestatus of phi1outinds2 is", AllocateStatus
if (AllocateStatus /= 0) stop "Error during deallocation of phi2outinds1"
print *, "we deallocate f loop ok", iteratst1(f)
allocate(phi1outinds1(1:iteratst1(f)), STAT = AllocateStatus)
if (AllocateStatus /= 0) stop "Error during allocation of phi1outinds1"
allocate(phi2outinds1(1:iteratst1(f)), STAT = AllocateStatus)
if (AllocateStatus /= 0) stop "Error during deallocation of phi1outinds1"
end do
end do
编译器选项
ifort -free -check -traceback -o adatptmultistage1new.out adatptmultistage1new.f90
输出
e 1
f 1 5000 43
DeAllocatestatus of phi1outinds1 is 0
DeAllocatestatus of phi1outinds2 is 0
we deallocate f loop ok 5000
f loop done 1
f 2 10000 43
Allocatestatus of phi1outinds1 is 0
DeAllocatestatus of phi1outinds2 is 0
we deallocate f loop ok 10000
f loop done 2
f 3 15000 43
Allocatestatus of phi1outinds1 is 0
错误消息
*** glibc detected *** ./adatptmultistage1new.out: munmap_chunk(): invalid pointer: 0x0000000000d3ddd0 ***
======= Backtrace: =========
/lib/libc.so.6(+0x77806)[0x7f5863b7b806]
. /adatptmultistage1new.out[0x43247c]
. /adatptmultistage1new.out[0x404368]
./adatptmultistage1new.out[0x4031ec]
/lib/libc.so.6(__libc_start_main+0xfd)[0x7f5863b22c4d]
. /adatptmultistage1new.out[0x4030e9]
======= Memory map: ========
00400000-004d4000 r-xp 00000000 08:03 9642201
/home/jgold/smwcv/error_infect/test/surfaces/multistage/adaptonly/adatptmultistage1new.out
006d4000-006dc000 rw-p 000d4000 08:03 9642201
[为简洁起见未显示其余错误消息]
7fffb004d000-7fffb00bc000 rw-p 00000000 00:00 0 [stack]
7fffb01d7000-7fffb01d8000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Aborted
答案 0 :(得分:5)
这是我们试图弄清楚的很多代码。您是否使用尽可能多的编译器调试选项编译它?特别是,你使用数组边界检查?你用的是什么编译器?我没有看到“使用”语句......最好将子程序放入模块并“使用”该模块,以便编译器可以检查实际参数和伪参数之间的参数一致性。
编辑:“双重免费或腐败”表明内存已损坏。由于您似乎没有任何指针,因此有三种可能的方法来破坏内存:-check bounds
或-check all
。通过检查,尝试:-O2 -stand f03 -check all -traceback -warn all -fstack-protector -assume protect_parens -implicitnone