I have written a Fortran code using MPI, as I am new to valgrind I could not manage to find the problem. I get this error while running the check:
==3040== Invalid write of size 4
==3040== at 0x804BFE0: MAIN__ (NS.f90:174)
==3040== by 0x804E190: main (NS.f90:321)
==3040== Address 0x5746f20 is 0 bytes after a block of size 8 alloc'd
==3040== at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==3040== by 0x804C5F3: MAIN__ (NS.f90:198)
==3040== by 0x804E190: main (NS.f90:321)
==3040==
==3041== Invalid write of size 4
==3041== at 0x804BFE0: MAIN__ (NS.f90:174)
==3040== Invalid write of size 4
==3040== at 0x804C036: MAIN__ (NS.f90:175)
==3040== by 0x804E190: main (NS.f90:321)
==3041== by 0x804E190: main (NS.f90:321)
==3041== Address 0x5748bbc is 0 bytes after a block of size 12 alloc'd
==3041== at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==3040== Address 0x5746f58 is 0 bytes after a block of size 8 alloc'd
==3040== at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==3040== by 0x804C729: MAIN__ (NS.f90:198)
==3040== by 0x804E190: main (NS.f90:321)
==3040==
==3041== by 0x804C5F3: MAIN__ (NS.f90:198)
==3041== by 0x804E190: main (NS.f90:321)
==3041==
==3040== Invalid write of size 4
==3040== at 0x804C087: MAIN__ (NS.f90:176)
==3040== by 0x804E190: main (NS.f90:321)
==3040== Address 0x5746f90 is 0 bytes after a block of size 8 alloc'd
==3040== at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==3040== by 0x804C862: MAIN__ (NS.f90:198)
==3040== by 0x804E190: main (NS.f90:321)
==3040==
==3041== Invalid write of size 4
==3041== at 0x804C036: MAIN__ (NS.f90:175)
==3041== by 0x804E190: main (NS.f90:321)
==3041== Address 0x5748bfc is 0 bytes after a block of size 12 alloc'd
==3041== at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==3041== by 0x804C729: MAIN__ (NS.f90:198)
==3041== by 0x804E190: main (NS.f90:321)
==3041==
==3040== Invalid write of size 4
==3040== at 0x804C1C5: MAIN__ (NS.f90:178)
==3040== by 0x804E190: main (NS.f90:321)
==3040== Address 0x5746fc8 is 0 bytes after a block of size 8 alloc'd
==3040== at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==3040== by 0x804C99B: MAIN__ (NS.f90:198)
==3040== by 0x804E190: main (NS.f90:321)
==3040==
==3041== Invalid write of size 4
==3041== at 0x804C087: MAIN__ (NS.f90:176)
==3041== by 0x804E190: main (NS.f90:321)
==3041== Address 0x5748c3c is 0 bytes after a block of size 12 alloc'd
==3041== at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==3041== by 0x804C862: MAIN__ (NS.f90:198)
==3041== by 0x804E190: main (NS.f90:321)
==3041==
==3040==
==3041== Invalid write of size 4
==3041== at 0x804C1C5: MAIN__ (NS.f90:178)
==3041== by 0x804E190: main (NS.f90:321)
==3041== Address 0x5748c7c is 0 bytes after a block of size 12 alloc'd
==3041== at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
Line 174 to 178 contains this piece of code:
A(I) = -0.5 * (0.5 * (1.0 + EPX) * CX(I-1, J) + DX)
B(I) = (1 + DX + 0.5 * EPX * CX(I, J))
C(I) = 0.5 * (0.5 * (1 - EPX) * CX(I+1, J) - DX)
R(I) = 0.5 * (0.5 * (1 + EPY) * CY(I, J-1) + DY) * OMEGA(I, J-1) + (1 - DY - 0.5 * EPY * CY(I, J)) * OMEGA(I, J) + 0.5 * (-0.5 * (1 - EPY) * CY(I, J+1) + DY) * OMEGA(I, J+1)
Can anybody tell me what is wrong here? I am also getting other errors like:
==3041== Invalid read of size 4
==3041== at 0x804C271: MAIN__ (NS.f90:183)
==3041== by 0x804E190: main (NS.f90:321)
==3041== Address 0x5748c40 is 4 bytes after a block of size 12 alloc'd
==3041== at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
where line 183 referring to:
R(N) = R(N) - C(N) * OMEGA(N+1, J)
I would appreciate if someone can tell me where the problem lies.
Here is the block of code:
A = 0.0
B = 0.0
C = 0.0
R = 0.0
X = 0.0
DO J = 1, M
DO I = 1, N
IF (U(I, J) > 0.0) THEN
EPX = 1.0
ELSE
EPX = -1.0
ENDIF
IF (V(I, J) > 0.0) THEN
EPY = 1.0
ELSE
EPY = -1.0
ENDIF
A(I) = -0.5 * (0.5 * (1.0 + EPX) * CX(I-1, J) + DX)
B(I) = (1 + DX + 0.5 * EPX * CX(I, J))
C(I) = 0.5 * (0.5 * (1 - EPX) * CX(I+1, J) - DX)
R(I) = 0.5 * (0.5 * (1 + EPY) * CY(I, J-1) + DY) * OMEGA(I, J-1) + (1 - DY - 0.5 * EPY * CY(I, J)) * OMEGA(I, J) + 0.5 * (-0.5 * (1 - EPY) * CY(I, J+1) + DY) * OMEGA(I, J+1)
ENDDO
R(1) = R(1) - A(1) * OMEGA(0, J)
R(N) = R(N) - C(N) * OMEGA(N+1, J)
ENDDO
It is very probable you are getting index errors and you overflow the array boundaries. This is a common mistake and the compilers can assist in debugging. For gfortran use -fcheck=all, for Intel us -check all. Other compilers also have similar capabilities.
After that, you have to make sure your arrays have proper dimensions and you are running the loops with proper upper and lower values.
We cannot say where the error is in this case, because you do not show the declarations of your variables.
Related
#include <iostream>
#include <random>
int main()
{
int a;
int *arr;
a = 3;
arr = new int[a];
#pragma omp parallel for
for (int i = 0; i < a; i++)
arr[i] = i;
delete[] arr;
return 0;
}
When I test this simple code with valgrind, it saids:
==2606== HEAP SUMMARY:
==2606== in use at exit: 3,360 bytes in 7 blocks
==2606== total heap usage: 10 allocs, 3 frees, 108,892 bytes allocated
==2606==
==2606== LEAK SUMMARY:
==2606== definitely lost: 0 bytes in 0 blocks
==2606== indirectly lost: 0 bytes in 0 blocks
==2606== possibly lost: 912 bytes in 3 blocks
==2606== still reachable: 2,448 bytes in 4 blocks
==2606== suppressed: 0 bytes in 0 blocks
Am I misunderstanding openmp or memory allocation usage?
Without "#pragma omp parallel for", it doesn't make any issues.
UPDATE
==2682== 912 bytes in 3 blocks are possibly lost in loss record 4 of 5
==2682== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==2682== by 0x40149DA: allocate_dtv (dl-tls.c:286)
==2682== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532)
==2682== by 0x4DE4322: allocate_stack (allocatestack.c:622)
==2682== by 0x4DE4322: pthread_create##GLIBC_2.2.5 (pthread_create.c:660)
==2682== by 0x4A4FDEA: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
==2682== by 0x4A478E0: GOMP_parallel (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
==2682== by 0x109184: main (main.cpp:10)
This is what --leak-check-full says.
I'm trying to follow this tutorial on how to implement a solver, but I'm having troubles setting up the case.
The original case can be found here. At first, when running blockMesh my version of OpenFOAM didn't recognize #eval() in blockMeshDict, so I changed it for #calc:
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.5 |
| \\ / A nd | Web: http://www.openfoam.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
scale 1e-4;
mergeType points; //Or: blockMesh -merge-points
wedgeAngle 2.5;
rodRadius 9.9;
airRadius 999;
tanAlpha #calc"tan(0.5*degToRad($wedgeAngle))";
posRodZ #calc"$rodRadius*$tanAlpha";
negRodZ #calc"-$posRodZ";
posAirZ #calc"$airRadius*$tanAlpha";
negAirZ #calc"-$posAirZ";
vertices
(
(0 0 0) // vertex #0
(100 0 0) // vertex #1
(100 $rodRadius $posRodZ) // vertex #2
(0 $rodRadius $posRodZ) // vertex #3
(0 $rodRadius $negRodZ) // vertex #4
(100 $rodRadius $negRodZ) // vertex #5
(0 $airRadius $posAirZ) // vertex #6
(100 $airRadius $posAirZ) // vertex #7
(100 $airRadius $negAirZ) // vertex #8
(0 $airRadius $negAirZ) // vertex #9
);
blocks
(
hex (0 1 5 4 0 1 2 3) (30 6 1) simpleGrading (1 1 1) // block #0
hex (4 5 8 9 3 2 7 6) (30 599 1) simpleGrading (1 1 1) // block #1
);
edges
(
);
boundary
(
leftWall
{
type patch;
faces
(
(3 4 0 0)
);
}
rightWall
{
type patch;
faces
(
(1 5 2 1)
);
}
atmosphereTop
{
type patch;
faces
(
(9 6 7 8)
);
}
atmosphereRight
{
type patch;
faces
(
(3 6 9 4)
);
}
atmosphereLeft
{
type patch;
faces
(
(5 8 7 2)
);
}
axis
{
type empty;
faces
(
(0 1 1 0)
);
}
rodBack
{
type wedge;
faces
(
(0 4 5 1)
);
}
rodFront
{
type wedge;
faces
(
(0 1 2 3)
);
}
airBack
{
type wedge;
faces
(
(4 9 8 5)
);
}
airFront
{
type wedge;
faces
(
(3 2 7 6)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
And now, when running blockMesh, I get the following errors:
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
Build : 9-c8374a4890ad
Exec : blockMesh
Date : Dec 16 2021
Time : 12:59:36
Host : "endeavouros"
PID : 346839
I/O : uncollated
Case : /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster (fileModificationSkew 10)
allowSystemOperations : Allowing user-supplied system call operations
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time
Reading "blockMeshDict"
Creating block mesh from
"system/blockMeshDict"
Using #calcEntry at line 26 in file "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict"
Using #codeStream with "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_28b21b5898ba159392899d5ac4d05a7158e0c6d6.so"
Creating new library in "dynamicCode/_28b21b5898ba159392899d5ac4d05a7158e0c6d6/platforms/linux64GccDPInt32Opt/lib/libcodeStream_28b21b5898ba159392899d5ac4d05a7158e0c6d6.so"
"/opt/OpenFOAM/OpenFOAM-9/etc/codeTemplates/dynamicCode/codeStreamTemplate.C" "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_28b21b5898ba159392899d5ac4d05a7158e0c6d6/codeStreamTemplate.C"
Invoking "wmake -s libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_28b21b5898ba159392899d5ac4d05a7158e0c6d6"
wmake libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_28b21b5898ba159392899d5ac4d05a7158e0c6d6
ln: ./lnInclude
wmkdep: codeStreamTemplate.C
Ctoo: codeStreamTemplate.C
ld: /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_28b21b5898ba159392899d5ac4d05a7158e0c6d6/../platforms/linux64GccDPInt32Opt/lib/libcodeStream_28b21b5898ba159392899d5ac4d05a7158e0c6d6.so
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Opening cached dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_28b21b5898ba159392899d5ac4d05a7158e0c6d6.so"
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Using #calcEntry at line 27 in file "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict"
Using #codeStream with "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_efc80fd5ffbc4db1928cd9ff3362f686671433be.so"
Creating new library in "dynamicCode/_efc80fd5ffbc4db1928cd9ff3362f686671433be/platforms/linux64GccDPInt32Opt/lib/libcodeStream_efc80fd5ffbc4db1928cd9ff3362f686671433be.so"
"/opt/OpenFOAM/OpenFOAM-9/etc/codeTemplates/dynamicCode/codeStreamTemplate.C" "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_efc80fd5ffbc4db1928cd9ff3362f686671433be/codeStreamTemplate.C"
Invoking "wmake -s libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_efc80fd5ffbc4db1928cd9ff3362f686671433be"
wmake libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_efc80fd5ffbc4db1928cd9ff3362f686671433be
ln: ./lnInclude
wmkdep: codeStreamTemplate.C
Ctoo: codeStreamTemplate.C
ld: /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_efc80fd5ffbc4db1928cd9ff3362f686671433be/../platforms/linux64GccDPInt32Opt/lib/libcodeStream_efc80fd5ffbc4db1928cd9ff3362f686671433be.so
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Opening cached dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_efc80fd5ffbc4db1928cd9ff3362f686671433be.so"
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Using #calcEntry at line 28 in file "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict"
Using #codeStream with "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_dc962d55c61555e401d9aa57fd57792f105fea79.so"
Creating new library in "dynamicCode/_dc962d55c61555e401d9aa57fd57792f105fea79/platforms/linux64GccDPInt32Opt/lib/libcodeStream_dc962d55c61555e401d9aa57fd57792f105fea79.so"
"/opt/OpenFOAM/OpenFOAM-9/etc/codeTemplates/dynamicCode/codeStreamTemplate.C" "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_dc962d55c61555e401d9aa57fd57792f105fea79/codeStreamTemplate.C"
Invoking "wmake -s libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_dc962d55c61555e401d9aa57fd57792f105fea79"
wmake libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_dc962d55c61555e401d9aa57fd57792f105fea79
ln: ./lnInclude
wmkdep: codeStreamTemplate.C
Ctoo: codeStreamTemplate.C
ld: /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_dc962d55c61555e401d9aa57fd57792f105fea79/../platforms/linux64GccDPInt32Opt/lib/libcodeStream_dc962d55c61555e401d9aa57fd57792f105fea79.so
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Opening cached dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_dc962d55c61555e401d9aa57fd57792f105fea79.so"
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Using #calcEntry at line 29 in file "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict"
Using #codeStream with "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_4510c2296fa7a962a6a70dda03e9219ebc01dac4.so"
Creating new library in "dynamicCode/_4510c2296fa7a962a6a70dda03e9219ebc01dac4/platforms/linux64GccDPInt32Opt/lib/libcodeStream_4510c2296fa7a962a6a70dda03e9219ebc01dac4.so"
"/opt/OpenFOAM/OpenFOAM-9/etc/codeTemplates/dynamicCode/codeStreamTemplate.C" "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_4510c2296fa7a962a6a70dda03e9219ebc01dac4/codeStreamTemplate.C"
Invoking "wmake -s libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_4510c2296fa7a962a6a70dda03e9219ebc01dac4"
wmake libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_4510c2296fa7a962a6a70dda03e9219ebc01dac4
ln: ./lnInclude
wmkdep: codeStreamTemplate.C
Ctoo: codeStreamTemplate.C
ld: /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_4510c2296fa7a962a6a70dda03e9219ebc01dac4/../platforms/linux64GccDPInt32Opt/lib/libcodeStream_4510c2296fa7a962a6a70dda03e9219ebc01dac4.so
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Opening cached dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_4510c2296fa7a962a6a70dda03e9219ebc01dac4.so"
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Using #calcEntry at line 30 in file "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict"
Using #codeStream with "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_0af64279ad3a68c6091e4927dfe1317848075c64.so"
Creating new library in "dynamicCode/_0af64279ad3a68c6091e4927dfe1317848075c64/platforms/linux64GccDPInt32Opt/lib/libcodeStream_0af64279ad3a68c6091e4927dfe1317848075c64.so"
"/opt/OpenFOAM/OpenFOAM-9/etc/codeTemplates/dynamicCode/codeStreamTemplate.C" "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_0af64279ad3a68c6091e4927dfe1317848075c64/codeStreamTemplate.C"
Invoking "wmake -s libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_0af64279ad3a68c6091e4927dfe1317848075c64"
wmake libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_0af64279ad3a68c6091e4927dfe1317848075c64
ln: ./lnInclude
wmkdep: codeStreamTemplate.C
Ctoo: codeStreamTemplate.C
ld: /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_0af64279ad3a68c6091e4927dfe1317848075c64/../platforms/linux64GccDPInt32Opt/lib/libcodeStream_0af64279ad3a68c6091e4927dfe1317848075c64.so
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Opening cached dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_0af64279ad3a68c6091e4927dfe1317848075c64.so"
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Creating block edges
No non-planar block faces defined
Creating topology blocks
#0 Foam::error::printStack(Foam::Ostream&) at ??:?
#1 Foam::sigFpe::sigHandler(int) at ??:?
#2 ? in "/usr/lib/libc.so.6"
#3 Foam::face::centre(Foam::Field<Foam::Vector<double> > const&) const at ??:?
#4 Foam::blockDescriptor::check(Foam::Istream const&) at ??:?
#5 Foam::blockDescriptor::blockDescriptor(Foam::dictionary const&, int, Foam::Field<Foam::Vector<double> > const&, Foam::PtrList<Foam::blockEdge> const&, Foam::PtrList<Foam::blockFace> const&, Foam::Istream&) at ??:?
#6 Foam::block::block(Foam::dictionary const&, int, Foam::Field<Foam::Vector<double> > const&, Foam::PtrList<Foam::blockEdge> const&, Foam::PtrList<Foam::blockFace> const&, Foam::Istream&) at ??:?
#7 Foam::block::New(Foam::dictionary const&, int, Foam::Field<Foam::Vector<double> > const&, Foam::PtrList<Foam::blockEdge> const&, Foam::PtrList<Foam::blockFace> const&, Foam::Istream&) at ??:?
#8 void Foam::PtrList<Foam::block>::read<Foam::block::iNew>(Foam::Istream&, Foam::block::iNew const&) at ??:?
#9 Foam::blockMesh::createTopology(Foam::IOdictionary const&, Foam::word const&) at ??:?
#10 Foam::blockMesh::blockMesh(Foam::IOdictionary const&, Foam::word const&) at ??:?
#11 ? in "/opt/OpenFOAM/OpenFOAM-9/platforms/linux64GccDPInt32Opt/bin/blockMesh"
#12 __libc_start_main in "/usr/lib/libc.so.6"
#13 ? in "/opt/OpenFOAM/OpenFOAM-9/platforms/linux64GccDPInt32Opt/bin/blockMesh"
fish: Job 2, 'blockMesh' terminated by signal SIGFPE (Floating point exception)
So, I'm a bit at lost on where to look and I'd appreciate some tips to try and solve the error.
Besides changing #eval() for #calc in blockMeshDict, everything else is pretty much the same as in the original case but here are the rest of my files.
The given case appears to be built for OpenFOAM v2, and I'm trying to run it on OpenFOAM v9 (installed from the package openfoam-org from the AUR). So, maybe that would be a problem? Nonetheless, in the course the case was given in 2020 (look at Implement electromagnetic solver Case: rodFoamCase.tgz in Proceedings 2020).
Thanks in advance.
It would be worthwhile to test with "openfoam-com" as well to see if there is a difference there. Can either use an AUR recipe or (probably faster) test with a docker instance and openfom.com
https://develop.openfoam.com/Development/openfoam/-/wikis/precompiled/docker
I'm trying to implement a function mergeSort that returns a dynamic array of type intervalo_t. As it is, the function is working nicely, the problem I have is that when I run Valgrind to check for memory loss, turns out I'm loosing quite a bit.
Intervalo_t definition:
struct intervalo_t {
nat inicio;
nat fin;
};
This is the code:
intervalo_t* mergeSort(intervalo_t *intervalos, nat n)
{
intervalo_t* ret=new intervalo_t[n];
if(n==2){
if (intervalos[0].fin>intervalos[1].fin){
ret[0]=intervalos[1];
ret[1]=intervalos[0];
}else{
ret[0]=intervalos[0];
ret[1]=intervalos[1];
}
//caso base
}else if (n==1){
ret[0]=intervalos[0];
//caso base
}else{
nat k=0;
if((n%2)!=0){
k=1;
}//Si es par o no
intervalo_t* interA =new intervalo_t[n/2 + k];
intervalo_t* interB =new intervalo_t[n/2];
for (nat i=0; i<n/2; i++){
interA[i]=intervalos[i];
interB[i]=intervalos[i+(n/2)];
}//for
if (k==1){
interA[(n/2)]=intervalos[n-1];
}
interA=mergeSort(interA, n/2 + k);
interB=mergeSort(interB, n/2);
nat i=0;
nat j=0;
nat r=0;
while((i<((n/2)+k)) && (j<(n/2))){
if (interA[i].fin>interB[j].fin){
ret[r]=interB[j];
j++;
}else{
ret[r]=interA[i];
i++;
}
r++;
}
while(i<(n/2)+k){
ret[r]=interA[i];
i++;
r++;
}
while(j<(n/2)){
ret[r]=interA[j];
i++;
j++;
}
delete[] interA;
delete[] interB;
//recursion
}
return ret;
}
And this is Valgrind's output:
==15556==
==15556== HEAP SUMMARY:
==15556== in use at exit: 24 bytes in 2 blocks
==15556== total heap usage: 12 allocs, 10 frees, 77,959 bytes allocated
==15556==
==15556== 8 bytes in 1 blocks are definitely lost in loss record 1 of 2
==15556== at 0x4C2F06F: operator new[](unsigned long) (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==15556== by 0x401536: mergeSort(intervalo_t*, unsigned int) (intervalos.cpp:26)
==15556== by 0x4017C3: max_cantidad(intervalo_t*, unsigned int) (intervalos.cpp:67)
==15556== by 0x401130: main (principal.cpp:170)
==15556==
==15556== 16 bytes in 1 blocks are definitely lost in loss record 2 of 2
==15556== at 0x4C2F06F: operator new[](unsigned long) (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==15556== by 0x401509: mergeSort(intervalo_t*, unsigned int) (intervalos.cpp:25)
==15556== by 0x4017C3: max_cantidad(intervalo_t*, unsigned int) (intervalos.cpp:67)
==15556== by 0x401130: main (principal.cpp:170)
==15556==
==15556== LEAK SUMMARY:
==15556== definitely lost: 24 bytes in 2 blocks
==15556== indirectly lost: 0 bytes in 0 blocks
==15556== possibly lost: 0 bytes in 0 blocks
==15556== still reachable: 0 bytes in 0 blocks
==15556== suppressed: 0 bytes in 0 blocks
==15556==
==15556== For lists of detected and suppressed errors, rerun with: -s
==15556== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
I ran valgrind with:
valgrind --leak-check=full ./myFile <test.in
Test.in:
mergeSort
15
30
45
Thanks in advance for your help!
The problem is that the memory you allocated here:
intervalo_t* interA =new intervalo_t[n/2 + k];
intervalo_t* interB =new intervalo_t[n/2];
leaks when you overwrite those pointers here:
interA=mergeSort(interA, n/2 + k);
interB=mergeSort(interB, n/2);
It is rarely a good idea to reuse variables for multiple purposes, so use separate variables for the recursive results:
intervalo_t* resultA=mergeSort(interA, n/2 + k);
intervalo_t* resultB=mergeSort(interB, n/2);
and then use those for merging (and remember to release them).
I would also recommend disposing of the inputs immediately after recursing so you don't forget it.
Or, you could use std::vector and save yourself some headaches.
I have been trying to fix this issue for a while and I am out of ideas.
I would like to use libpropcs-dev api to access the /proc directory in Linux.
I have this peice of code so far:
#include <stdio.h>
#include <stdlib.h>
#include <proc/readproc.h>
#include <string.h>
#include <iostream>
using namespace std;
int main (){
PROCTAB* proc = openproc(PROC_FILLMEM | PROC_FILLSTAT | PROC_FILLSTATUS);
proc_t proc_info;
memset(&proc_info, 0, sizeof(proc_info));
while (readproc(proc, &proc_info) != NULL) {
fprintf(stdout, "%20s: \t%5d\t%5ld\n",
proc_info.cmd, proc_info.ppid,
proc_info.rss);
}
cout << "size of proc " << sizeof(proc) << "\n";
cout << "size of proc_info " << sizeof(proc_info) << "\n";
closeproc(proc);
return 1;
}
However, if I run it I get segfault. This is the output of valgrind:
==6492== Memcheck, a memory error detector
==6492== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==6492== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==6492== Command: ./a.out
==6492==
==6492== Invalid free() / delete / delete[] / realloc()
==6492== at 0x4C2EDEB: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6492== by 0x4E43846: readproc (in /lib/x86_64-linux-gnu/libprocps.so.4.0.0)
==6492== by 0x400B37: main (in /home/mohamad/Work/3000-myrepo/a.out)
==6492== Address 0x9ad2de89d83bae00 is not stack'd, malloc'd or (recently) free'd
==6492==
==6492== Invalid free() / delete / delete[] / realloc()
==6492== at 0x4C2EDEB: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6492== by 0x4E43857: readproc (in /lib/x86_64-linux-gnu/libprocps.so.4.0.0)
==6492== by 0x400B37: main (in /home/mohamad/Work/3000-myrepo/a.out)
==6492== Address 0x400c50 is in the Text segment of /home/mohamad/Work/3000-myrepo/a.out
==6492== at 0x400C50: __libc_csu_init (in /home/mohamad/Work/3000-myrepo/a.out)
==6492==
==6492== Invalid free() / delete / delete[] / realloc()
==6492== at 0x4C2EDEB: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6492== by 0x4E43868: readproc (in /lib/x86_64-linux-gnu/libprocps.so.4.0.0)
==6492== by 0x400B37: main (in /home/mohamad/Work/3000-myrepo/a.out)
==6492== Address 0x5409830 is in the Text segment of /lib/x86_64-linux-gnu/libc-2.23.so
==6492== at 0x5409830: (below main) (libc-start.c:325)
==6492==
==6492== Conditional jump or move depends on uninitialised value(s)
==6492== at 0x4E43873: readproc (in /lib/x86_64-linux-gnu/libprocps.so.4.0.0)
==6492== by 0x400B37: main (in /home/mohamad/Work/3000-myrepo/a.out)
==6492==
==6492== Invalid free() / delete / delete[] / realloc()
==6492== at 0x4C2EDEB: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6492== by 0x4E4388A: readproc (in /lib/x86_64-linux-gnu/libprocps.so.4.0.0)
==6492== by 0x400B37: main (in /home/mohamad/Work/3000-myrepo/a.out)
==6492== Address 0xffefffc38 is on thread 1's stack
==6492==
==6492== Conditional jump or move depends on uninitialised value(s)
==6492== at 0x4E43895: readproc (in /lib/x86_64-linux-gnu/libprocps.so.4.0.0)
==6492== by 0x400B37: main (in /home/mohamad/Work/3000-myrepo/a.out)
==6492==
==6492== Conditional jump or move depends on uninitialised value(s)
==6492== at 0x4C2EDA1: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6492== by 0x4E4389B: readproc (in /lib/x86_64-linux-gnu/libprocps.so.4.0.0)
==6492== by 0x400B37: main (in /home/mohamad/Work/3000-myrepo/a.out)
==6492==
==6492== Invalid free() / delete / delete[] / realloc()
==6492== at 0x4C2EDEB: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6492== by 0x4E4389B: readproc (in /lib/x86_64-linux-gnu/libprocps.so.4.0.0)
==6492== by 0x400B37: main (in /home/mohamad/Work/3000-myrepo/a.out)
==6492== Address 0x100000000 is not stack'd, malloc'd or (recently) free'd
==6492==
==6492== Invalid free() / delete / delete[] / realloc()
==6492== at 0x4C2EDEB: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6492== by 0x4E438AC: readproc (in /lib/x86_64-linux-gnu/libprocps.so.4.0.0)
==6492== by 0x400B37: main (in /home/mohamad/Work/3000-myrepo/a.out)
==6492== Address 0x400ad6 is in the Text segment of /home/mohamad/Work/3000-myrepo/a.out
==6492== at 0x400AD6: main (in /home/mohamad/Work/3000-myrepo/a.out)
==6492==
systemd: 0 1476
kthreadd: 0 0
kworker/0:0H: 2 0
mm_percpu_wq: 2 0
ksoftirqd/0: 2 0
rcu_sched: 2 0
rcu_bh: 2 0
migration/0: 2 0
watchdog/0: 2 0
cpuhp/0: 2 0
cpuhp/1: 2 0
watchdog/1: 2 0
migration/1: 2 0
ksoftirqd/1: 2 0
kworker/1:0H: 2 0
cpuhp/2: 2 0
watchdog/2: 2 0
migration/2: 2 0
ksoftirqd/2: 2 0
kworker/2:0H: 2 0
cpuhp/3: 2 0
watchdog/3: 2 0
migration/3: 2 0
ksoftirqd/3: 2 0
kworker/3:0H: 2 0
kdevtmpfs: 2 0
**continues to print all the processess running ...**
size of proc 8
size of proc_info 888
*** stack smashing detected ***: ./a.out terminated
==6492==
==6492== Process terminating with default action of signal 6 (SIGABRT)
==6492== at 0x541E428: raise (raise.c:54)
==6492== by 0x5420029: abort (abort.c:89)
==6492== by 0x54607E9: __libc_message (libc_fatal.c:175)
==6492== by 0x550215B: __fortify_fail (fortify_fail.c:37)
==6492== by 0x55020FF: __stack_chk_fail (stack_chk_fail.c:28)
==6492== by 0x400BF9: main (in /home/mohamad/Work/3000-myrepo/a.out)
==6492==
==6492== HEAP SUMMARY:
==6492== in use at exit: 336,896 bytes in 4 blocks
==6492== total heap usage: 235 allocs, 237 frees, 376,803 bytes allocated
==6492==
==6492== LEAK SUMMARY:
==6492== definitely lost: 0 bytes in 0 blocks
==6492== indirectly lost: 0 bytes in 0 blocks
==6492== possibly lost: 0 bytes in 0 blocks
==6492== still reachable: 336,896 bytes in 4 blocks
==6492== suppressed: 0 bytes in 0 blocks
==6492== Rerun with --leak-check=full to see details of leaked memory
==6492==
==6492== For counts of detected and suppressed errors, rerun with: -v
==6492== Use --track-origins=yes to see where uninitialised values come from
==6492== ERROR SUMMARY: 9 errors from 9 contexts (suppressed: 0 from 0)
Aborted (core dumped)
Once I run it under gdb I get the following:
Program received signal SIGSEGV, Segmentation fault.
__GI___libc_free (mem=0x57a7587f19463b00) at malloc.c:2951
2951 malloc.c: No such file or directory.
Help or pointers regarding my issue would be awesome. Thanks!
I have a cross platform console application. The purpose of it is to transfer data between two peers. Sometimes packets received are not complete so we append the data into a string while the complete packet has been arrived. But it get crashed in appending data in string after sometime. Here is the back tarce -
1 libsystem_c.dylib 0x93b77acf pthread_kill + 101
2 libsystem_c.dylib 0x93bae4f8 abort + 168
3 libc++abi.dylib 0x9698180c abort_message + 151
4 libc++abi.dylib 0x9697f275 default_terminate() + 34
5 libc++abi.dylib 0x9697f2b5 safe_handler_caller(void (*)()) + 13
6 libc++abi.dylib 0x9697f31d std::terminate() + 23
7 libc++abi.dylib 0x96980412 __cxa_throw + 110
8 libstdc++.6.dylib 0x90e23d6c std::__throw_length_error(char const*) + 104
9 libstdc++.6.dylib 0x90e4f3a9 std::string::append(char const*, unsigned long) + 175
10 libConnector.dylib 0x13905228 ConnectionSocket::AdjustPartialData(char const*, int)
14 libConnector.dylib 0x1383e0b6 ConnectionChannel::ProcessData(int, void const*, int, char*, int) + 7886
15 libConnector.dylib 0x13861ecb ConnectionManager::BaseThreadImpl() + 1185
16 libConnector.dylib 0x13861a23 ConnectionManager::BaseThread(void*) + 17
17 libsystem_c.dylib 0x93b76557 _pthread_start + 344
18 libsystem_c.dylib 0x93b60cee thread_start + 34
Can someone give any idea about this issue?
EXAMPLE CODE:
AdjustPartialData(char* const pData, int dataLen)
{
if (true == packetIncomplete)
{
partialDataBuffer.append(pData, dataLen); // crash occurs in this line
}
}
if partialDataBuffer.size() + dataLen > partialDataBuffer.max_size() then append throws a length_error (http://en.cppreference.com/w/cpp/string/basic_string/append)
Either partialDataBuffer or dataLen are too big.
Finally I have resolved the issue by discarding the extra data which causes the overflow. Previously I thought this will not be feasible solution as it could lead to possible data loss. But I found that TCP stream size shouldn't be greater than 65535 which is 16 bit. But found another issue when the following condition added -
if(partialDataBuffer.size() + dataLen >= partialDataBuffer.max_size())
{
// do not append data
}
else partialDataBuffer.append(pData, dataLen);
The issue was in windows platform it always crashes even though size of partialDataBuffer is much less than partialDataBuffer.max_size(). So, for resolving this issue I have done the following -
try{
partialDataBuffer.append(pData, dataLen);
}
catch(...)
{
// got exception, return
}
And it worked fine for me.
N.B: I have posted my answer because it will be helpful for others who are facing similar issue.