Subject: CGAL users discussion list
List archive
- From: Alexander Kobel <>
- To:
- Subject: [cgal-discuss] Gmpfi: a black hole for memory?
- Date: Wed, 15 Dec 2010 00:50:43 +0100
Hi, all,
I suspect that the CGAL::Gmpfi interval number type is severely leaking memory. I ran the following small app (code shortened, complete in attachment):
int main (int argc, char **argv) {
typedef CGAL::GMP_arithmetic_kernel AK;
typedef AK::Bigfloat_interval BFI; // Gmpfi
CGAL::set_precision (BFI(), 256);
BFI A (BF (-1.), BF (1.));
BFI B (BF (-1.), BF (1.));
BFI C;
max_iter = <something from command line>;
for (int i = 0; i < max_iter; ++i) {
A *= B;
C = A+B;
}
}
I assume this is supposed to take basically constant memory, and time linearly with max_iter. While the latter holds, in each iteration some memory seems to leak.
/usr/bin/time yields the following results (on Ubuntu 10.10 64bit, gcc 4.4.4, libmpfr 3.0.0-2, libmpfi 1.5-3, libgmp 4.3.2, all from the Ubuntu repositories, compiled with -O3 -frounding-math):
Command being timed: "./test_Gmpfi 100"
User time (seconds): 0.01
Maximum resident set size (kbytes): 28544
Command being timed: "./test_Gmpfi 1000000"
User time (seconds): 1.89
Maximum resident set size (kbytes): 403584
Command being timed: "./test_Gmpfi 5000000"
User time (seconds): 9.21
Maximum resident set size (kbytes): 1903936
No surprise, Valgrind complains as well:
==10543== Command: ./test_Gmpfi 100
==10543== 4,000 bytes in 100 blocks are definitely lost in loss record 13 of 14
==10543== by 0x5717208: mpfi_init2 (in /usr/lib/libmpfi.so.0.0.0)
==10543== by 0x4088A0: boost::operator+(CGAL::Gmpfi const&, CGAL::Gmpfi const&)
==10543==
==10543== 4,000 bytes in 100 blocks are definitely lost in loss record 14 of 14
==10543== by 0x5284BA3: mpfr_init2 (in /usr/lib/libmpfr.so.4.0.0)
==10543== by 0x4088A0: boost::operator+(CGAL::Gmpfi const&, CGAL::Gmpfi const&)
==10546== Command: ./test_Gmpfi 100000
==10546== 3,999,960 bytes in 99,999 blocks are definitely lost in loss record 14 of 15
==10546== by 0x5284BA3: mpfr_init2 (in /usr/lib/libmpfr.so.4.0.0)
==10546== by 0x4088A0: boost::operator+(CGAL::Gmpfi const&, CGAL::Gmpfi const&)
==10546==
==10546== 4,000,000 bytes in 100,000 blocks are definitely lost in loss record 15 of 15
==10546== by 0x5717208: mpfi_init2 (in /usr/lib/libmpfi.so.0.0.0)
==10546== by 0x4088A0: boost::operator+(CGAL::Gmpfi const&, CGAL::Gmpfi const&)
Multiplication and division are affected as well, but I've omitted them in the test for the sake of simplicity. In a more-or-less real world application, the leaks get so bad that a theoretically simple input causes the machine to starve from memory...
Any suggestions? Somebody got a similar setup to cross-check my results?
Thanks in advance, and cheers,
Alexander
#include <CGAL/GMP_arithmetic_kernel.h> #include <iostream> #include <boost/lexical_cast.hpp> int main (int argc, char **argv) { int max_iter = 1000; if (argc > 1) max_iter = boost::lexical_cast< int > (argv[1]); typedef CGAL::GMP_arithmetic_kernel AK; typedef AK::Bigfloat BF; // Gmpfr typedef AK::Bigfloat_interval BFI; // Gmpfi CGAL::set_precision (BFI(), 256); BFI A (BF (-1.), BF (1.)); BFI B (BF (-1.), BF (1.)); BFI C; for (int i = 0; i < max_iter; ++i) { A *= B; C = A+B; } std::cout << "C = " << C << std::endl; mpfr_free_cache(); return 0; }C = [-1e1,1e1]
Command being timed: "./test_Gmpfi 100"
User time (seconds): 0.01
System time (seconds): 0.00
Percent of CPU this job got: 58%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.01
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 28544
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 1872
Voluntary context switches: 1
Involuntary context switches: 2
Swaps: 0
File system inputs: 0
File system outputs: 8
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
C = [-1e1,1e1]
Command being timed: "./test_Gmpfi 1000000"
User time (seconds): 1.89
System time (seconds): 0.04
Percent of CPU this job got: 99%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:01.93
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 403584
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 25311
Voluntary context switches: 1
Involuntary context switches: 194
Swaps: 0
File system inputs: 0
File system outputs: 8
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
C = [-1e1,1e1]
Command being timed: "./test_Gmpfi 5000000"
User time (seconds): 9.21
System time (seconds): 0.45
Percent of CPU this job got: 99%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:09.69
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 1903936
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 119085
Voluntary context switches: 1
Involuntary context switches: 987
Swaps: 0
File system inputs: 0
File system outputs: 8
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
==10543== Memcheck, a memory error detector
==10543== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==10543== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for
copyright info
==10543== Command: ./test_Gmpfi 100
==10543==
C = [-1e1,1e1]
==10543== Invalid free() / delete / delete[]
==10543== at 0x4C27D71: free (vg_replace_malloc.c:366)
==10543== by 0x61F3A0A: free_mem (in /lib/libc-2.12.1.so)
==10543== by 0x61F35A1: __libc_freeres (in /lib/libc-2.12.1.so)
==10543== by 0x4A2366B: _vgnU_freeres (vg_preloaded.c:62)
==10543== by 0x60FA4A4: exit (exit.c:93)
==10543== by 0x60DFD94: (below main) (libc-start.c:258)
==10543== Address 0x4054230 is not stack'd, malloc'd or (recently) free'd
==10543==
==10543==
==10543== HEAP SUMMARY:
==10543== in use at exit: 19,984 bytes in 213 blocks
==10543== total heap usage: 3,468 allocs, 3,256 frees, 795,612 bytes
allocated
==10543==
==10543== 4,000 bytes in 100 blocks are definitely lost in loss record 13 of
14
==10543== at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==10543== by 0x54B4C18: __gmp_default_allocate (in
/usr/lib/libgmp.so.3.5.2)
==10543== by 0x5284BA3: mpfr_init2 (in /usr/lib/libmpfr.so.4.0.0)
==10543== by 0x5717208: mpfi_init2 (in /usr/lib/libmpfi.so.0.0.0)
==10543== by 0x4088A0: boost::operator+(CGAL::Gmpfi const&, CGAL::Gmpfi
const&) (in
/home/perpeduumimmobile/CGAL/SVN/branches/unsorted-branches/akobel/Arcavoid/test/test_Gmpfi)
==10543== by 0x40584B: main (in
/home/perpeduumimmobile/CGAL/SVN/branches/unsorted-branches/akobel/Arcavoid/test/test_Gmpfi)
==10543==
==10543== 4,000 bytes in 100 blocks are definitely lost in loss record 14 of
14
==10543== at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==10543== by 0x54B4C18: __gmp_default_allocate (in
/usr/lib/libgmp.so.3.5.2)
==10543== by 0x5284BA3: mpfr_init2 (in /usr/lib/libmpfr.so.4.0.0)
==10543== by 0x4088A0: boost::operator+(CGAL::Gmpfi const&, CGAL::Gmpfi
const&) (in
/home/perpeduumimmobile/CGAL/SVN/branches/unsorted-branches/akobel/Arcavoid/test/test_Gmpfi)
==10543== by 0x40584B: main (in
/home/perpeduumimmobile/CGAL/SVN/branches/unsorted-branches/akobel/Arcavoid/test/test_Gmpfi)
==10543==
==10543== LEAK SUMMARY:
==10543== definitely lost: 8,000 bytes in 200 blocks
==10543== indirectly lost: 0 bytes in 0 blocks
==10543== possibly lost: 0 bytes in 0 blocks
==10543== still reachable: 11,984 bytes in 13 blocks
==10543== suppressed: 0 bytes in 0 blocks
==10543== Reachable blocks (those to which a pointer was found) are not shown.
==10543== To see them, rerun with: --leak-check=full --show-reachable=yes
==10543==
==10543== For counts of detected and suppressed errors, rerun with: -v
==10543== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 4 from 4)
==10546== Memcheck, a memory error detector
==10546== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==10546== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for
copyright info
==10546== Command: ./test_Gmpfi 100000
==10546==
C = [-1e1,1e1]
==10546== Invalid free() / delete / delete[]
==10546== at 0x4C27D71: free (vg_replace_malloc.c:366)
==10546== by 0x61F3A0A: free_mem (in /lib/libc-2.12.1.so)
==10546== by 0x61F35A1: __libc_freeres (in /lib/libc-2.12.1.so)
==10546== by 0x4A2366B: _vgnU_freeres (vg_preloaded.c:62)
==10546== by 0x60FA4A4: exit (exit.c:93)
==10546== by 0x60DFD94: (below main) (libc-start.c:258)
==10546== Address 0x4054230 is not stack'd, malloc'd or (recently) free'd
==10546==
==10546==
==10546== HEAP SUMMARY:
==10546== in use at exit: 8,011,984 bytes in 200,013 blocks
==10546== total heap usage: 1,801,668 allocs, 1,601,656 frees, 64,731,612
bytes allocated
==10546==
==10546== 40 bytes in 1 blocks are possibly lost in loss record 3 of 15
==10546== at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==10546== by 0x54B4C18: __gmp_default_allocate (in
/usr/lib/libgmp.so.3.5.2)
==10546== by 0x5284BA3: mpfr_init2 (in /usr/lib/libmpfr.so.4.0.0)
==10546== by 0x4088A0: boost::operator+(CGAL::Gmpfi const&, CGAL::Gmpfi
const&) (in
/home/perpeduumimmobile/CGAL/SVN/branches/unsorted-branches/akobel/Arcavoid/test/test_Gmpfi)
==10546== by 0x40584B: main (in
/home/perpeduumimmobile/CGAL/SVN/branches/unsorted-branches/akobel/Arcavoid/test/test_Gmpfi)
==10546==
==10546== 3,999,960 bytes in 99,999 blocks are definitely lost in loss record
14 of 15
==10546== at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==10546== by 0x54B4C18: __gmp_default_allocate (in
/usr/lib/libgmp.so.3.5.2)
==10546== by 0x5284BA3: mpfr_init2 (in /usr/lib/libmpfr.so.4.0.0)
==10546== by 0x4088A0: boost::operator+(CGAL::Gmpfi const&, CGAL::Gmpfi
const&) (in
/home/perpeduumimmobile/CGAL/SVN/branches/unsorted-branches/akobel/Arcavoid/test/test_Gmpfi)
==10546== by 0x40584B: main (in
/home/perpeduumimmobile/CGAL/SVN/branches/unsorted-branches/akobel/Arcavoid/test/test_Gmpfi)
==10546==
==10546== 4,000,000 bytes in 100,000 blocks are definitely lost in loss
record 15 of 15
==10546== at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==10546== by 0x54B4C18: __gmp_default_allocate (in
/usr/lib/libgmp.so.3.5.2)
==10546== by 0x5284BA3: mpfr_init2 (in /usr/lib/libmpfr.so.4.0.0)
==10546== by 0x5717208: mpfi_init2 (in /usr/lib/libmpfi.so.0.0.0)
==10546== by 0x4088A0: boost::operator+(CGAL::Gmpfi const&, CGAL::Gmpfi
const&) (in
/home/perpeduumimmobile/CGAL/SVN/branches/unsorted-branches/akobel/Arcavoid/test/test_Gmpfi)
==10546== by 0x40584B: main (in
/home/perpeduumimmobile/CGAL/SVN/branches/unsorted-branches/akobel/Arcavoid/test/test_Gmpfi)
==10546==
==10546== LEAK SUMMARY:
==10546== definitely lost: 7,999,960 bytes in 199,999 blocks
==10546== indirectly lost: 0 bytes in 0 blocks
==10546== possibly lost: 40 bytes in 1 blocks
==10546== still reachable: 11,984 bytes in 13 blocks
==10546== suppressed: 0 bytes in 0 blocks
==10546== Reachable blocks (those to which a pointer was found) are not shown.
==10546== To see them, rerun with: --leak-check=full --show-reachable=yes
==10546==
==10546== For counts of detected and suppressed errors, rerun with: -v
==10546== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 4 from 4)
- [cgal-discuss] Gmpfi: a black hole for memory?, Alexander Kobel, 12/15/2010
- Re: [cgal-discuss] Gmpfi: a black hole for memory?, Marc Glisse, 12/15/2010
- Re: [cgal-discuss] Gmpfi: a black hole for memory?, Alexander Kobel, 12/15/2010
- Re: [cgal-discuss] Gmpfi: a black hole for memory?, Marc Glisse, 12/15/2010
- Re: [cgal-discuss] Gmpfi: a black hole for memory?, Eric Berberich, 12/15/2010
- Re: [cgal-discuss] Gmpfi: a black hole for memory?, Alexander Kobel, 12/15/2010
- Re: [cgal-discuss] Gmpfi: a black hole for memory?, Marc Glisse, 12/15/2010
Archive powered by MHonArc 2.6.16.