These are chat archives for symengine/symengine

12th
Sep 2016
Francesco Biscani
@bluescarni
Sep 12 2016 09:28
@isuruf just as an update on the new integer class: I have implemented the string conversion changes we discussed, and now it is possible to select at compile time how many limbs you want in static storage. I worked quite a bit on the addition routines, and they are now faster than both piranha::integer and the vanilla GMP without using any 128 integer type (so they are compatible with MSVC as well). I am working now on the mul routines and on the caching.
Francesco Biscani
@bluescarni
Sep 12 2016 11:31
@isuruf you mentioned the mpz cache used by SAGE earlier. How does it work exactly? Does it keep just a list of recently-used mpzs to pool from or does it categorize them in terms of how many allocated limbs they have?
Isuru Fernando
@isuruf
Sep 12 2016 12:20
It's like a stack with a max size of 100.
Francesco Biscani
@bluescarni
Sep 12 2016 12:20
it just contains the last 100 mpzs on which mpz_clear() has been called?
Isuru Fernando
@isuruf
Sep 12 2016 12:21
first 100 mpzs i guess.
Francesco Biscani
@bluescarni
Sep 12 2016 12:21
and it does not divide them by size or anything of the sort?
Isuru Fernando
@isuruf
Sep 12 2016 12:22
no. although it does reallocate if the limb size is greater than 10.
Francesco Biscani
@bluescarni
Sep 12 2016 12:23
ok. the design I am considering now groups them by alloc size, so that you can request specifically mpzs with a certain number of preallocated limbs
Isuru Fernando
@isuruf
Sep 12 2016 12:27
Cool. I think sage shrinks the sizes because the pool might take a lot of memory.
Francesco Biscani
@bluescarni
Sep 12 2016 12:28
at the moment I am thinking of caching only up to a certain size (10 limbs currently)
the current implementation consists of a vector of 10 vectors of mpz_t
each vector can have up to 100 elements
Francesco Biscani
@bluescarni
Sep 12 2016 12:34
there are some tricky considerations arising from the fact that the cache is a global variable
usual nastiness of working with static variables
at the moment the cache is a thread local, function-level static variable:
class mpz_cache {
//...
};

inline mpz_cache &get_mpz_cache()
{
    static thread_local mpz_cache cache;
    return cache;
}
so this basically means that the cache is created the first time it is used from the current thread
I am wondering what kind of interactions can happen if you want to store an integer as a global static variable somewhere
Francesco Biscani
@bluescarni
Sep 12 2016 12:39
what might happen (I am not sure...) is the following: when the program ends, the global static integer's dtor is called, but its dtor wants to access the cache in order to push the deallocated mpz to the cache stack
but the cache might have already been destroyed, as it is also a static variable?
Isuru Fernando
@isuruf
Sep 12 2016 12:49
yes, that's a problem. I think this is a common problem and therefore there should be an answer to this already
Francesco Biscani
@bluescarni
Sep 12 2016 12:50
yeah I need to look and think about it