Big Arrays

Décio Luiz Gazzoni Filho decio at decpp.net
Sat Jun 11 19:11:58 CEST 2005


On Jun 11, 2005, at 12:14 PM, Emanuele Laface wrote:

> I'm sorry to post this question here but I looked for some hours on  
> google
> and I didn't find the reply to my problem.
>
> I would create a "big" vector of mpz_t.

No, you probably don't. I see two possibilities here:
1. You want to create a `small' vector but the vector size in  
question is stored in an mpz_t, although it would comfortably fit an  
unsigned long or at most overflow by a bit and require an unsigned  
long long.
2. You want to create a `big' vector, something that doesn't fit even  
on a long long. I'm sorry, but you don't have enough memory for that.  
It's actually more memory than your computer can address.

If 1 is what you truly want to do, then try converting your mpz_t to  
an unsigned long using the function mpz_get_ui(). Now if your array  
size doesn't fit in an unsigned long and requires an unsigned long  
long, then first beware that you'll need several gigabytes just to  
initialize the vector -- a 64-bit pointer is 8 bytes long, and  
unsigned longs store values up to 4G, so you're looking at, at the  
very least, 32 GB just to store a pointer to your data structure.  
You'll probably need some hundreds of GB to store the GMP data  
structure (pointer to the actual data, size of each limb, memory  
allocated for each, etc.), and god forbid you actually need to store  
your data in there -- I hope you're not dealing with anything beyond  
a few kilobits, or you're gonna need more than a terabyte of RAM to  
store that data. But supposing you really want to do that, you could  
try printing your 64-bit integer to a string then using strtoull to  
convert it to an unsigned long long. It's kludgy but I think there's  
no better way.

If your situation is 2, then reevaluate your application or whatever  
algorithm you're using, because it's completely infeasible. Maybe  
half a century from now, if we keep our current pace of growth in the  
semiconductor industry (and still I doubt it).

Décio
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : http://gmplib.org/list-archives/gmp-discuss/attachments/20050611/d13e5c8f/PGP.bin


More information about the gmp-discuss mailing list