我有一个程序崩溃,如果在shell中执行一个简单的"中止"。这通常指向一些内存问题,所以我在valgrind下运行程序。奇怪的是,它现在运行并提供预期的输出。我在两个测试中都使用了完全相同的构建。这是Valgrind的输出:
valgrind --leak-check=yes --track-origins=yes ./datar_test
==1203== Memcheck, a memory error detector
==1203== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==1203== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==1203== Command: ./datar_test
==1203==
==1203== Conditional jump or move depends on uninitialised value(s)
==1203== at 0x60382D: __intel_sse2_strcpy (in /home/SERVER-hoffmann/sync/04_DATAR/datar_shared/Unittest/datar_test)
==1203== by 0x57EE17: for__add_to_lf_table (in /home/SERVER-hoffmann/sync/04_DATAR/datar_shared/Unittest/datar_test)
==1203== by 0x5BC0E8: for__open_proc (in /home/SERVER-hoffmann/sync/04_DATAR/datar_shared/Unittest/datar_test)
==1203== by 0x585DAF: for__open_default (in /home/SERVER-hoffmann/sync/04_DATAR/datar_shared/Unittest/datar_test)
==1203== by 0x5A97C3: for_write_seq_lis (in /home/SERVER-hoffmann/sync/04_DATAR/datar_shared/Unittest/datar_test)
==1203== by 0x40E302: fruit_mp_init_fruit_ (fruit.f90:635)
==1203== by 0x44B58B: MAIN__ (datar_test.f90:18)
==1203== by 0x4032DD: main (in /home/SERVER-hoffmann/sync/04_DATAR/datar_shared/Unittest/datar_test)
==1203== Uninitialised value was created by a heap allocation
==1203== at 0x4C29110: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==1203== by 0x59221C: for__get_vm (in /home/SERVER-hoffmann/sync/04_DATAR/datar_shared/Unittest/datar_test)
==1203== by 0x5BA84D: for__open_proc (in /home/SERVER-hoffmann/sync/04_DATAR/datar_shared/Unittest/datar_test)
==1203== by 0x585DAF: for__open_default (in /home/SERVER-hoffmann/sync/04_DATAR/datar_shared/Unittest/datar_test)
==1203== by 0x5A97C3: for_write_seq_lis (in /home/SERVER-hoffmann/sync/04_DATAR/datar_shared/Unittest/datar_test)
==1203== by 0x40E302: fruit_mp_init_fruit_ (fruit.f90:635)
==1203== by 0x44B58B: MAIN__ (datar_test.f90:18)
==1203== by 0x4032DD: main (in /home/SERVER-hoffmann/sync/04_DATAR/datar_shared/Unittest/datar_test)
==1203==
Test module initialized
. : successful assert, F : failed assert
--------------
Starting contact force spectrum test
==1203== Syscall param sched_setaffinity(mask) points to unaddressable byte(s)
==1203== at 0x6B6EFB9: syscall (in /lib64/libc-2.19.so)
==1203== by 0x40A0787: __kmp_affinity_determine_capable (in /global/linux/64_bit/opt/intel/mkl/10.2.2.025/lib/em64t/libiomp5.so)
==1203== by 0x4089F97: __kmp_env_initialize(char const*) (in /global/linux/64_bit/opt/intel/mkl/10.2.2.025/lib/em64t/libiomp5.so)
==1203== by 0x4081175: ??? (in /global/linux/64_bit/opt/intel/mkl/10.2.2.025/lib/em64t/libiomp5.so)
==1203== by 0x4074428: __kmp_get_global_thread_id_reg (in /global/linux/64_bit/opt/intel/mkl/10.2.2.025/lib/em64t/libiomp5.so)
==1203== by 0x407FF98: __kmp_parallel_initialize (in /global/linux/64_bit/opt/intel/mkl/10.2.2.025/lib/em64t/libiomp5.so)
==1203== by 0x406EC7D: omp_get_num_procs (in /global/linux/64_bit/opt/intel/mkl/10.2.2.025/lib/em64t/libiomp5.so)
==1203== by 0x54211FA: MKL_get_N_Cores (in /global/linux/64_bit/opt/intel/mkl/10.2.2.025/lib/em64t/libmkl_intel_thread.so)
==1203== by 0x5420CA8: mkl_read_threads_env (in /global/linux/64_bit/opt/intel/mkl/10.2.2.025/lib/em64t/libmkl_intel_thread.so)
==1203== by 0x5420694: mkl_serv_mkl_domain_get_max_threads (in /global/linux/64_bit/opt/intel/mkl/10.2.2.025/lib/em64t/libmkl_intel_thread.so)
==1203== by 0x57BB632: mkl_dft_commit_descriptor_d_c2c_1d_omp (in /global/linux/64_bit/opt/intel/mkl/10.2.2.025/lib/em64t/libmkl_intel_thread.so)
==1203== by 0x4F4279C: mkl_dft_dfti_commit_descriptor_external (in /global/linux/64_bit/opt/intel/mkl/10.2.2.025/lib/em64t/libmkl_intel_lp64.so)
==1203== Address 0x0 is not stack'd, malloc'd or (recently) free'd
==1203==
OMP: Warning #2: Cannot open message catalog "libiomp5.cat":
OMP: System error #2: No such file or directory
OMP: Hint: Check NLSPATH environment variable, its value is "/global/linux/64_bit/opt/intel/mkl/10.2.2.025/lib/em64t/locale/%l_%t/%N".
OMP: Info #3: Default messages will be used.
==2910==
==2910== HEAP SUMMARY:
==2910== in use at exit: 2,594 bytes in 8 blocks
==2910== total heap usage: 2,462 allocs, 2,454 frees, 7,276,535 bytes allocated
==2910==
==2910== LEAK SUMMARY:
==2910== definitely lost: 0 bytes in 0 blocks
==2910== indirectly lost: 0 bytes in 0 blocks
==2910== possibly lost: 0 bytes in 0 blocks
==2910== still reachable: 2,594 bytes in 8 blocks
==2910== suppressed: 0 bytes in 0 blocks
==2910== Reachable blocks (those to which a pointer was found) are not shown.
==2910== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==2910==
==2910== For counts of detected and suppressed errors, rerun with: -v
==2910== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
请注意,我正在使用MKL进行编译。可以发现Valgrind给出了MKL的误报(所有指向mkl库的东西)。 我现在正在努力理解为什么它在Valgrind下运行而不是没有它。你能解释一下吗?
编辑:我删除了一些消息,我更新了Valgrind输出。
更新:这是一个例子,它也不会在Valgrind下运行。它归结为一些记忆泄漏我认为,但我无法解决它。 代码:
module math
real, parameter :: pi = 4*atan(1.0)
contains
function fft(x, DirectionKey)
use MKL_DFTI
implicit none
! Declaring part
complex, dimension(:) :: x
complex, dimension(size(x)) :: fft
type(DFTI_DESCRIPTOR), pointer :: DFTI
integer :: DirectionKey, Status
! Executing part
fft = 0
Status = DftiCreateDescriptor(DFTI,DFTI_DOUBLE, DFTI_COMPLEX, 1, size(x) )
Status = DftiCommitDescriptor(DFTI)
select case (DirectionKey)
case (1)
Status = DftiComputeForward(DFTI,x)
fft = x/size(x)
case (-1)
Status = DftiComputeBackward(DFTI,x)
fft = x
end select
Status = DftiFreeDescriptor(DFTI)
end function fft
! ============================================================================
subroutine NonlinearContactForcePoint(RelativeDisplacementPoint, NormalForcePoint, FricCoeff, Stiffness, ContactForceOUT, ContactForceJacobianOUT)
implicit none
! Declaring part
real, dimension(:), intent(in) :: RelativeDisplacementPoint
real, dimension(size(RelativeDisplacementPoint)), intent(in) :: NormalForcePoint
real, intent(in) :: FricCoeff, Stiffness
real, dimension(size(RelativeDisplacementPoint)) :: ContactForce
real, dimension(size(RelativeDisplacementPoint),2) :: ContactForcePrime
integer, dimension(size(RelativeDisplacementPoint)) :: ContactStatus
real, dimension(2), intent(out) :: ContactForceOUT
real, dimension(2,2), intent(out) :: ContactForceJacobianOUT
! Executing part
call ContactModel(RelativeDisplacementPoint, NormalForcePoint, FricCoeff, Stiffness, ContactForce, ContactStatus)
call ContactModelPrime(ContactStatus, Stiffness, ContactForcePrime)
call TimeToFourier(ContactForce, ContactForcePrime, 1, ContactForceOUT, ContactForceJacobianOUT)
end subroutine NonlinearContactForcePoint
! ============================================================================
subroutine ContactModel(Displacement, NormalForce, FrictionCoefficient, TangentialStiffness, ContactForce, ContactStatus)
implicit none
! Declaring part
real, dimension(:), intent(in) :: Displacement
real, dimension(size(Displacement)), intent(in) :: NormalForce
real, dimension(size(Displacement)) :: DisplacementSlider
real :: FrictionCoefficient, TangentialStiffness
real, dimension(size(Displacement)), intent(out) :: ContactForce
integer, dimension(size(Displacement)), intent(out) :: ContactStatus
integer :: ii
! Executing part
ContactForce = 0.0
ContactStatus = 0
DisplacementSlider = 0.0
do ii = 2,size(Displacement)
if (NormalForce(ii)==0) then
ContactForce(ii) = 0.0
DisplacementSlider(ii) = Displacement(ii)
ContactStatus(ii) = -1
else
! Slip in positive direction
if (TangentialStiffness*(Displacement(ii) - DisplacementSlider(ii-1))- FrictionCoefficient*NormalForce(ii) > 0) then
ContactForce(ii) = -FrictionCoefficient*NormalForce(ii);
DisplacementSlider(ii) = Displacement(ii) + ContactForce(ii)/TangentialStiffness;
ContactStatus(ii) = 1
! Slip in negative direction
elseif (-TangentialStiffness*(Displacement(ii) - DisplacementSlider(ii-1))- FrictionCoefficient*NormalForce(ii) > 0) then
ContactForce(ii) = FrictionCoefficient*NormalForce(ii);
DisplacementSlider(ii) = Displacement(ii) + ContactForce(ii)/TangentialStiffness;
ContactStatus(ii) = 1
! General stick
elseif (TangentialStiffness*(Displacement(ii) - DisplacementSlider(ii-1))- FrictionCoefficient*NormalForce(ii) <= 0) then
ContactForce(ii) = -TangentialStiffness*(Displacement(ii) - DisplacementSlider(ii-1));
DisplacementSlider(ii) = DisplacementSlider(ii-1);
ContactStatus(ii) = 0
end if
end if
end do
end subroutine ContactModel
! ============================================================================
subroutine TimeToFourier(TimeSeries, TimeSeriesPrime, Harmonics, RealCoefficients, RealJacobianCoefficients)
implicit none
! Declaring part
real, dimension(:), intent(in) :: TimeSeries
real, dimension(:,:), intent(in) :: TimeSeriesPrime
integer, intent(in) :: Harmonics
integer :: N
complex, dimension(1) :: Spectrum, SpectrumPrimeR, SpectrumPrimeI
real, dimension(2), intent(out) :: RealCoefficients
real, dimension(2,2), intent(out) :: RealJacobianCoefficients
! Executing part
N = size(TimeSeries)
Spectrum = CreateSpectrum(TimeSeries(N/2+1:N), Harmonics)
SpectrumPrimeR = CreateSpectrum(TimeSeriesPrime(N/2+1:N,1), Harmonics)
SpectrumPrimeI = CreateSpectrum(TimeSeriesPrime(N/2+1:N,2), Harmonics)
RealCoefficients = [real(Spectrum), -aimag(Spectrum)]
RealJacobianCoefficients = reshape([real(SpectrumPrimeR), -aimag(SpectrumPrimeR), real(SpectrumPrimeI), -aimag(SpectrumPrimeI)],[2,2])
end subroutine TimeToFourier
! ============================================================================
subroutine ContactModelPrime(ContactStatus, TangentialStiffness, Prime)
implicit none
! Declaring part
integer, dimension(:), intent(in) :: ContactStatus
real, dimension(size(ContactStatus)) :: dfdrQ, dfdiQ
real :: TangentialStiffness
real, dimension(size(ContactStatus),2) :: Prime
real :: dfdrQ_OLD, dfdiQ_OLD
integer :: ii
! Executing part
dfdrQ = 0.0
dfdiQ = 0.0
dfdrQ_OLD = 0.0
dfdiQ_OLD = 0.0
Prime = 0.0
do ii = 2,size(ContactStatus)
! Stick
if (ContactStatus(ii) == 0) then
dfdrQ(ii) = -TangentialStiffness*(cos(2*2*pi/size(ContactStatus)*(ii-1))-cos(2*2*pi/size(ContactStatus)*(ii-2))) + dfdrQ_OLD;
dfdiQ(ii) = -TangentialStiffness*(sin(2*2*pi/size(ContactStatus)*(ii-1))-sin(2*2*pi/size(ContactStatus)*(ii-2))) + dfdiQ_OLD;
end if
dfdrQ_OLD = dfdrQ(ii)
dfdiQ_OLD = dfdiQ(ii)
end do
Prime = reshape([dfdrQ, dfdiQ],[size(ContactStatus),2])
end subroutine ContactModelPrime
! ============================================================================
function CreateSpectrum(TimeSignal, Harmonics)
implicit none
! Declaring part
real, dimension(:), intent(in) :: TimeSignal
complex, dimension(size(TimeSignal)) :: Spectrum
integer, intent(in) :: Harmonics
complex, dimension(:), allocatable :: CreateSpectrum
integer :: ii
! Executing part
Spectrum = fft(cmplx(TimeSignal),1)
if (Harmonics == 0) then
allocate(CreateSpectrum(1))
CreateSpectrum = Spectrum(1)
else
allocate(CreateSpectrum(Harmonics))
do ii=1,Harmonics
CreateSpectrum = 2*Spectrum(Harmonics+1)
end do
end if
end function
end module math
! ============================================================================
program test
use MKL_RCI
use MKL_RCI_type
use math
implicit none
real, dimension(12,12) :: ContactForceJacobian
real, dimension(12) :: Displacement
external :: NonlinearContactForce
Displacement = [1.0e-5,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]
if (djacobi(NonlinearContactForce,12,12,ContactForceJacobian,Displacement,1e-8) /= TR_SUCCESS) then
write(*,*), '| error in djacobi'
call MKL_FREE_BUFFERS
stop 1;
end if
end program test
! ============================================================================
subroutine NonlinearContactForce(m,n,RelativeDisplacement, ContactForce, ContactForceJacobian)
use math
implicit none
! Declaring part
integer :: m, n
real, dimension(12) :: RelativeDisplacement
real, dimension(6) :: RelativeDisplacementPoint
real, dimension(2) :: ContactForceXi
real, dimension(2,2) :: ContactForceJacobianXi
! Time domain variables
real, dimension(32) :: NormalForce
complex, dimension(32) :: RelativeDisplacementPointSpectrum
real, dimension(32) :: RelativeDisplacementPointTime
real, dimension(2) :: ContactForceLocal
real, dimension(2,2) :: ContactForceJacobianLocal
! Output variables
real, dimension(12), intent(out) :: ContactForce
real, dimension(12,12), intent(out) :: ContactForceJacobian
! Executing part
ContactForce(1:12) = 0
ContactForceJacobian(1:12,1:12) = 0
RelativeDisplacementPointTime = 0
NormalForce = 1
RelativeDisplacementPointSpectrum = 0
RelativeDisplacementPointSpectrum(3) = cmplx(RelativeDisplacement(1)/2.0,-RelativeDisplacement(2)/2.0)
RelativeDisplacementPointSpectrum(32-1) = cmplx(RelativeDisplacement(1)/2.0,RelativeDisplacement(2)/2.0)
RelativeDisplacementPointTime = real(fft(RelativeDisplacementPointSpectrum,-1))
call NonlinearContactForcePoint(RelativeDisplacementPointTime, NormalForce,1.0, 1e6, ContactForceLocal, ContactForceJacobianLocal)
ContactForce(1:2) = ContactForceLocal
ContactForceJacobian(1:2,1:2) = ContactForceJacobianLocal
end subroutine NonlinearContactForce
编译命令(ifort 17.0.1):
ifort -g -O0 -CB -CA -CU -fstack-protector -fp-stack-check -traceback -real-size 64 -mkl -I${MKL_ROOT}/include test.f90
MKL版本:2017