On Sun, 23 Jul 2006, Giorgos Keramidas wrote:

On 2006-07-24 20:49, "P.U.Kruppa" <[EMAIL PROTECTED]> wrote:
Hi,

sorry for posting an [OT], but usually people on this list know
everything :-)

Since I don't know too much about programming I am frequently
fascinated by simple things like Eratosthenes' sieve.  As you might
remember, one has to create a boolean array for that. The longer the
array the more primes can be found.

With malloc() I can create an array of length 100000000 (10^8) and the
first 5761455 primes are calculated in a few seconds.  So of course I
would like to test length 10^9 but here my program crashes.

If this is about integer values, which are probably 32-bit, you are
hitting the kern.maxdsiz limit of 512 MB.  An array of 100,000,000
32-bit values takes up 4 * 100,000,000 = 400,000,000 (close to 400 MiB
of memory to store).  Anything above 512 MB in size will make the data
size of your program so big that it will overflow the data seg size:

   $ ulimit -a
   core file size          (blocks, -c) unlimited
   data seg size           (kbytes, -d) 524288
   ...

You can either increase kern.maxdsiz in your `/boot/loader.conf' file,
or redesign the algorithm to work with larger datasets by splitting them
in chunks that you can still process with 512 MB of data :)
*How* can I effectively split my array up? How can I access an element arr[n] if n is bigger than INT_MAX ? I have tried some kind of linear/linked list, but that becomes disgustingly slow.

Thanks,

Uli.





_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"




*********************************************
* Peter Ulrich Kruppa - Wuppertal - Germany *
*********************************************
_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to