Dear GMP developers,
I am making a program that calculate pi using GMP.
There is a memory leak that seems to be the cause of GMP.
It seems that a memory leak occurs when a huge number of digits
 multiplying and square root calculation.
The following test program(test_mul.c, test_sqrt.c) causes a memory leak.
Run vmstat 5 -SM on another terminal.
Run the program,vmstat memory free value at "clear end any key in so end"
 output ,and vmstat memory free value after enterring key,
differrence between the value is memory leak.
My result of changing the number of multiplication digits by 
several patterns at test_mul.c:
num= 2*10^8 : memory leak= 32MiB
num= 10^8    : memory leak= 25MiB
num= 5*10^7 : memory leak= 12MiB
num= 4*10^8 : memory leak= 48MiB
num= 8*10^8 : memory leak= 48MiB
Similary my result of canging the number of mpf_sqrt_ui digits
by several patterns at test_sqrt.c:
num= 10^9    : memory leak= 51MiB
num= 4*10^8 : memory leak= 41MiB
num= 2*10^8 : memory leak=  0Mib
num= 10^8    : memory leak=  0MiB
num= 2*10^9 : memory leak= 50MiB
Test bed:
ubuntu 20.04.2 LTS
GMP 6.2.0
gcc 9.3.0
Best regarde.
Susumu Tsukamoto
/* test_mul.c g++  -Wall test_mul.c -o test_mul01 -lgmp*/#include "gmp.h"
#include <locale.h>int main()
{     
    long int num = 200000000; // 200,000,000 
    long int ik;
    char dm[5];
    setlocale(LC_ALL,"ja_JP.utf-8");    mpz_t DC;        
    printf(" start:  num= %'ld \n", num);
             
    mpz_init_set_str(DC, "10000000000000000000",10); // DC=10^19
                                    
    ik = 19;        // DC=10^ik set   num/2 <= ik < num
    while (ik * 2 < num) {     
        mpz_mul(DC, DC, DC);
        ik = ik * 2;
    }                   mpz_clear(DC); 
             
    printf(" clear end any key in so end \n");
    scanf("%s", dm);
}
/* test_sqrt.c g++ -Wall test_sqrt.c -o test_sqrt01 -lgmp*/#include "math.h"
#include "gmp.h"
#include <locale.h>int main()
{      
        long int num = 400000000; // 400,000,000
        long int lims;
        setlocale(LC_ALL,"ja_JP.utf-8");        printf(" start:  
mpf_sqrt_ui(CC) num= %'ld \n", num);
 
        mpf_t CC;      
        lims = num/((log(2)*64)/log(10));
        mpf_set_default_prec(lims*64);         
        mpf_init(CC);              mpf_sqrt_ui(CC, 2);
            
        mpf_clear(CC);
             
        printf(" clear end any key in so end\n");
        char dm[5];
        scanf("%s", dm);
}
_______________________________________________
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs

Reply via email to