Archive for the ‘cfam-matrix’ Category

cfam-matrix Prime Sieves (java code): reporting/formatting utility

January 13, 2010


import java.io.*;

// __
class SUtils24{
private final byte[] _bHEX_TABLE = "0123456789abcdef".getBytes();
// __
SUtils24(){}

// __
public String getAsHex(byte[] bAr) throws UnsupportedEncodingException{
byte[] bHex = new byte[2 * bAr.length];
// __
for(int i = 0; (i >> 4];
bHex[2*i + 1] = _bHEX_TABLE[v & 0xF];
}
// __
return new String(bHex, "ASCII");
}

// __ @! comp.lang.java.help: "how to print integer with alignment" Java doesn't? Does jakarta.commons?
public String padString(int iCs, String aIS, int iSpc){
String aFS = null; // formatted String
int iISL = aIS.length();
int iPadL = (iSpc - iISL);
if(iPadL > 0){
StringBuffer aB = new StringBuffer();
for(int i = 0; i 0)
else{ aFS = aIS; }
// __
return(aFS);
}
}

cfam-matrix Prime Sieves: rationale

January 13, 2010

~
This is part of the discussions we have been having about the importance of java.lang.Rational
~
comp.lang.java.programmer: “java.lang.Rational …”
~
I would (fully agreeing with Arne Vajhøj’s comment) say that “I am just arguing that it (java.lang.Rational) is not “any” class.”
~
After checking existing libraries out there I have decided to try to fine tune my kind of wheel and see how it rolls. Critical part of the implementation of this class would be to have all prime and composite numbers (along with their factorization) -within a certain range-
~
So, you are going to first need the prime numbers within that range and the fastest way to get them I know of is using sieves (or sieve windows (which my code strategizes depending on the range checked (larger sieves can be used for larger ranges))) Let me know (proving it with actual code ;-)) if you know of any better way to serially and exhaustively calculate primes.
~
Sieve window strategies would nicely fit the best of all times programming paradigm, “the fastest and most optimal way to do something is not doing it” ;-) With sieves you only check numbers that fall through their holes, that means those that
-may be- prime numbers
~
this piece of code calculates sieve windows in Java taking into consideration that 53 is the first prime which multiplication goes over Long_MAX_VALUE:
~
. . .
~
// __ ( 2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23 * 29 * 31 * 37 * 41 * 43 ): | 13082761331670030 | 43
~
// __ ( 2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23 * 29 * 31 * 37 * 41 * 43 * 47 ): | 614889782588491410 | 47
~
// __ ( 2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23 * 29 * 31 * 37 * 41 * 43 * 47 * 53 ): | -4304329670229058502 | 53
~
// __ ( 2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23 * 29 * 31 * 37 * 41 * 43 * 47 * 53 * 59 ): | 4298966488419271006 | 59
~
I did test my code in various ways (both functionally and stressing it to the point of making something break (and it was not my code/algorithm which kept crunching data alone. It was my I/O subsystem (no more disk space + exhuasted processor)), but the relatively modest box I have right now would not let me test as much as I would wish. The JVM itself wasn’t complaining at all, but I wish it would have used the two processors of my dual core system
~
# java -version
java version “1.6.0_16”
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing)
~
based on knoppix/Debian/Linux kernel 2.6.31.6
~
At a certain point you gain “no return on investment”. If you only use the first prime, 2, for sieving you would obviously discard all even numbers (so right there you get a 50% gain), but if you use 2 and 3 you will cover (4/6) of all natural numbers, that is 66% (wich only gives you a 16% gain) and so on …
~
// __ file length / sieve window’s scope
~
2 / (2*3) = 2 / 6 = 0.(3)
~
8 / (2*3*5) = 8 / 30 = 0.2(6)
~
48 / (2*3*5*7) = 48 / 210 = 0.2(285714)
~
480 / (2*3*5*7*11) = 480 / 2310 = 0.(207792)
~
5760 / (2*3*5*7*11*13) = 5760 / 30030 = 0.(191808)
~
92160 / (2*3*5*7*11*13*17) = 92160 / 510510 = 0.18052535699594523123934888640770993712
~
1658880 / (2*3*5*7*11*13*17*19) = 1658880 / 9699690 = 0.17102402241721127170043578712309362464
~
36495360 / (2*3*5*7*11*13*17*19*23) = 36495360 / 223092870 = 0.1635881953555933903221559702916547714
~
1021870080 / (2*3*5*7*11*13*17*19*23*29) = 1021870080 / 6469693230 = 0.15794722310195223893173679890228736549
~
30656102400 / (2*3*5*7*11*13*17*19*23*29*31) = 30656102400 / 200560490130 = 0.15285215138898603767587432151834261176
~
* / (2*3*5*7*11*13*17*19*23*29*31*37) = * / 7420738134810 = (based on previous quotient, it would need more than 1 TeraByte)
~
I heavily commented the algorithm I used. Basically I coded myself a strategy to handle bit sieves (java’s BitSet, BigNumbers, … weren’t really helpful and made me waste my time) that scales very nicely and as you can read the core of it can be reduced to one page (well almost ;-)).
~
Before you start making fun of the way I code Java, let me tell you that I code like this because I am coding it in ANSI C and ANSI C++ as well and honestly syntax sugar gives me a stomach ache. This is what happens to you when you are an old dog that learned to code in FORTRAN using puch cards ;-) I think the reason why we computer programmers tend to waste so much time with nonsensical marginal stuff is because we like to think of ourselves as philosophers/scientists, when in fact we are just carpenters ;-)
~
To understand the code (if you don’t) just go through the procedure used by those great old-time Greek Mathematicians and read up/refresh on the basic concepts. All I did was implementing an extensible bit sieve using a file:
~
http://en.wikipedia.org/wiki/Prime_numbers
http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
http://demonstrations.wolfram.com/SieveOfEratosthenes/
http://en.wikipedia.org/wiki/Prime_gap
http://en.wikipedia.org/wiki/Prime_number_theorem
Prime Numbers: A Computational Perspective by Crandall & Pomerance (2005, 597 pages) ISBN-10: 0387252827
Factorization and Primality Testing by Bressoud (1989, 260 pages) ISBN-10: 0387970401
~
I did find some code in ANSI C, ANSI C++ and Java out there, e.g.:
~
http://www.algolist.net/Algorithms/Number_theoretic/Sieve_of_Eratosthenes
~
but I found it unrealistically naive, heck even Java itself game me sh!t to no end! Besides, I decided to own the code since it is going to be part of a larger library for exact, fast and efficient (without even using the Math coprocessor) mathematical calculations
~
The ouput of your code should look like this:
~
// __ largest sequence of products of primes for a sieve will be ( 2 * 3 * 5 * 7 * 11 * 13 * 17 ) := 510510

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// __ iPrms: | 2 |, lFctr: | 6 := ( 2 * 3 ) |, lTtlBytes: | 1 |, bSvBfr.length: | 1 |
// __ iRngs[0][0]: | 1 |, iRngs[0][1]: | 1 |
// __ iRngs[1][0]: | -1 |, iRngs[1][1]: | 0 |
// __ lTtlHGps: | 2 |, largest Gap: |4 |, sieve coverage: | 0.666667 | gain from previous sieve: 16.6666667%
// __ Sieve window with range 6 calculated in 2 (ms) 3.000 integers (per ms). Used memory by JVM : | 143208 | bytes.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// __ iPrms: | 3 |, lFctr: | 30 := ( 2 * 3 * 5 ) |, lTtlBytes: | 4 |, bSvBfr.length: | 4 |
// __ iRngs[0][0]: | 4 |, iRngs[0][1]: | 1 |
// __ iRngs[1][0]: | -1 |, iRngs[1][1]: | 0 |
// __ lTtlHGps: | 8 |, largest Gap: |6 |, sieve coverage: | 0.733333 | gain from previous sieve: 6.6666667%
// __ Sieve window with range 30 calculated in 2 (ms) 15.000 integers (per ms). Used memory by JVM : | 171128 | bytes.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// __ iPrms: | 4 |, lFctr: | 210 := ( 2 * 3 * 5 * 7 ) |, lTtlBytes: | 27 |, bSvBfr.length: | 27 |
// __ iRngs[0][0]: | 27 |, iRngs[0][1]: | 1 |
// __ iRngs[1][0]: | -1 |, iRngs[1][1]: | 0 |
// __ lTtlHGps: | 48 |, largest Gap: |10 |, sieve coverage: | 0.771429 | gain from previous sieve: 3.8095238%
// __ Sieve window with range 210 calculated in 1 (ms) 210.000 integers (per ms). Used memory by JVM : | 172128 | bytes.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// __ iPrms: | 5 |, lFctr: | 2310 := ( 2 * 3 * 5 * 7 * 11 ) |, lTtlBytes: | 289 |, bSvBfr.length: | 289 |
// __ iRngs[0][0]: | 289 |, iRngs[0][1]: | 1 |
// __ iRngs[1][0]: | -1 |, iRngs[1][1]: | 0 |
// __ lTtlHGps: | 480 |, largest Gap: |14 |, sieve coverage: | 0.792208 | gain from previous sieve: 2.0779221%
// __ Sieve window with range 2310 calculated in 5 (ms) 462.000 integers (per ms). Used memory by JVM : | 170208 | bytes.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// __ iPrms: | 6 |, lFctr: | 30030 := ( 2 * 3 * 5 * 7 * 11 * 13 ) |, lTtlBytes: | 3754 |, bSvBfr.length: | 3754 |
// __ iRngs[0][0]: | 3754 |, iRngs[0][1]: | 1 |
// __ iRngs[1][0]: | -1 |, iRngs[1][1]: | 0 |
// __ lTtlHGps: | 5760 |, largest Gap: |22 |, sieve coverage: | 0.808192 | gain from previous sieve: 1.5984016%
// __ Sieve window with range 30030 calculated in 82 (ms) 366.220 integers (per ms). Used memory by JVM : | 171568 | bytes.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// __ iPrms: | 7 |, lFctr: | 510510 := ( 2 * 3 * 5 * 7 * 11 * 13 * 17 ) |, lTtlBytes: | 63814 |, bSvBfr.length: | 16384 |
// __ iRngs[0][0]: | 16384 |, iRngs[0][1]: | 3 |
// __ iRngs[1][0]: | 14662 |, iRngs[1][1]: | 1 |
// __ lTtlHGps: | 92160 |, largest Gap: |26 |, sieve coverage: | 0.819475 | gain from previous sieve: 1.1282835%
// __ Sieve window with range 510510 calculated in 61 (ms) 8369.016 integers (per ms). Used memory by JVM : | 173128 | bytes.
~
root@Microknoppix:/media/sdb3/prjx/cfam-matrix/Java/prms/prms04# ls -l *.bin *.thrd.log *.txt
-rwxrwxrwx 1 knoppix knoppix 3019 Jan 12 20:55 PrmSieve18Test_20100112205515.out.txt
-rwxrwxrwx 1 knoppix knoppix 354 Jan 12 20:55 Thread[Thread-0,5,main]_2-3_20100112205515.thrd.log
-rwxrwxrwx 1 knoppix knoppix 354 Jan 12 20:55 Thread[Thread-1,5,main]_2-5_20100112205515.thrd.log
-rwxrwxrwx 1 knoppix knoppix 355 Jan 12 20:55 Thread[Thread-2,5,main]_2-7_20100112205515.thrd.log
-rwxrwxrwx 1 knoppix knoppix 360 Jan 12 20:55 Thread[Thread-3,5,main]_2-11_20100112205515.thrd.log
-rwxrwxrwx 1 knoppix knoppix 361 Jan 12 20:55 Thread[Thread-4,5,main]_2-13_20100112205515.thrd.log
-rwxrwxrwx 1 knoppix knoppix 376 Jan 12 20:55 Thread[Thread-5,5,main]_2-17_20100112205515.thrd.log
-rwxrwxrwx 1 knoppix knoppix 480 Jan 12 20:55 hgps_2-11.bin
-rwxrwxrwx 1 knoppix knoppix 2904 Jan 12 20:55 hgps_2-11.txt
-rwxrwxrwx 1 knoppix knoppix 5760 Jan 12 20:55 hgps_2-13.bin
-rwxrwxrwx 1 knoppix knoppix 40680 Jan 12 20:55 hgps_2-13.txt
-rwxrwxrwx 1 knoppix knoppix 92160 Jan 12 20:55 hgps_2-17.bin
-rwxrwxrwx 1 knoppix knoppix 2 Jan 12 20:55 hgps_2-3.bin
-rwxrwxrwx 1 knoppix knoppix 6 Jan 12 20:55 hgps_2-3.txt
-rwxrwxrwx 1 knoppix knoppix 8 Jan 12 20:55 hgps_2-5.bin
-rwxrwxrwx 1 knoppix knoppix 32 Jan 12 20:55 hgps_2-5.txt
-rwxrwxrwx 1 knoppix knoppix 48 Jan 12 20:55 hgps_2-7.bin
-rwxrwxrwx 1 knoppix knoppix 242 Jan 12 20:55 hgps_2-7.txt

root@Microknoppix:/media/sdb3/prjx/cfam-matrix/Java/prms/prms04# cat hgps_2-11.txt
1 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89
97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 169 173 179 181 191
193 197 199 211 221 223 227 229 233 239 241 247 251 257 263 269 271 277 281 283
289 293 299 307 311 313 317 323 331 337 347 349 353 359 361 367 373 377 379 383
389 391 397 401 403 409 419 421 431 433 437 439 443 449 457 461 463 467 479 481
487 491 493 499 503 509 521 523 527 529 533 541 547 551 557 559 563 569 571 577
587 589 593 599 601 607 611 613 617 619 629 631 641 643 647 653 659 661 667 673
677 683 689 691 697 701 703 709 713 719 727 731 733 739 743 751 757 761 767 769
773 779 787 793 797 799 809 811 817 821 823 827 829 839 841 851 853 857 859 863
871 877 881 883 887 893 899 901 907 911 919 923 929 937 941 943 947 949 953 961
967 971 977 983 989 991 997 1003 1007 1009 1013 1019 1021 1027 1031 1033 1037 1039 1049 1051
1061 1063 1069 1073 1079 1081 1087 1091 1093 1097 1103 1109 1117 1121 1123 1129 1139 1147 1151 1153
1157 1159 1163 1171 1181 1187 1189 1193 1201 1207 1213 1217 1219 1223 1229 1231 1237 1241 1247 1249
1259 1261 1271 1273 1277 1279 1283 1289 1291 1297 1301 1303 1307 1313 1319 1321 1327 1333 1339 1343
1349 1357 1361 1363 1367 1369 1373 1381 1387 1391 1399 1403 1409 1411 1417 1423 1427 1429 1433 1439
1447 1451 1453 1457 1459 1469 1471 1481 1483 1487 1489 1493 1499 1501 1511 1513 1517 1523 1531 1537
1541 1543 1549 1553 1559 1567 1571 1577 1579 1583 1591 1597 1601 1607 1609 1613 1619 1621 1627 1633
1637 1643 1649 1651 1657 1663 1667 1669 1679 1681 1691 1693 1697 1699 1703 1709 1711 1717 1721 1723
1733 1739 1741 1747 1751 1753 1759 1763 1769 1777 1781 1783 1787 1789 1801 1807 1811 1817 1819 1823
1829 1831 1843 1847 1849 1853 1861 1867 1871 1873 1877 1879 1889 1891 1901 1907 1909 1913 1919 1921
1927 1931 1933 1937 1943 1949 1951 1957 1961 1963 1973 1979 1987 1993 1997 1999 2003 2011 2017 2021
2027 2029 2033 2039 2041 2047 2053 2059 2063 2069 2071 2077 2081 2083 2087 2089 2099 2111 2113 2117
2119 2129 2131 2137 2141 2143 2147 2153 2159 2161 2171 2173 2179 2183 2197 2201 2203 2207 2209 2213
2221 2227 2231 2237 2239 2243 2249 2251 2257 2263 2267 2269 2273 2279 2281 2287 2291 2293 2297 2309

root@Microknoppix:/media/sdb3/prjx/cfam-matrix/Java/prms/prms04# find . -type f -name “*.bin” 2>/dev/null -exec ls -l {} \;
-rwxrwxrwx 1 knoppix knoppix 2 Jan 12 20:55 ./hgps_2-3.bin
-rwxrwxrwx 1 knoppix knoppix 8 Jan 12 20:55 ./hgps_2-5.bin
-rwxrwxrwx 1 knoppix knoppix 48 Jan 12 20:55 ./hgps_2-7.bin
-rwxrwxrwx 1 knoppix knoppix 480 Jan 12 20:55 ./hgps_2-11.bin
-rwxrwxrwx 1 knoppix knoppix 5760 Jan 12 20:55 ./hgps_2-13.bin
-rwxrwxrwx 1 knoppix knoppix 92160 Jan 12 20:55 ./hgps_2-17.bin

root@Microknoppix:/media/sdb3/prjx/cfam-matrix/Java/prms/prms04# find . -type f -name “*.bin” 2>/dev/null -exec sha256sum -b {} \;
a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222 *./hgps_2-3.bin
a4d089b2804186e4d60b69adc3866c773f8a965a5a4c970c43eb12f3685a46e1 *./hgps_2-5.bin
d31e26a6f5854b83d85374b258b3174352e121883f38e84eb0ed224d8dbccffe *./hgps_2-7.bin
b780ecfa30aa779da041b65615f161001e1991e5f6ae3ac7d83696c6b8957ba2 *./hgps_2-11.bin
2df966944198159452836876529b358cce7b8f1ba8b658d2f7e11f14e5d13469 *./hgps_2-13.bin
128fa738b24b344e94971d86ad4b39695e318e129f53e833f1f3dd0bec3b9737 *./hgps_2-17.bin

root@Microknoppix:/media/sdb3/prjx/cfam-matrix/Java/prms/prms04# find /media/sda1 -type f -name “*.bin” 2>/dev/null -exec ls -l {} \;
-rw-r–r– 1 root root 2 Jan 12 09:34 /media/sda1/prjx/primes/data/hgps_2-3.bin
-rw-r–r– 1 root root 8 Jan 12 09:34 /media/sda1/prjx/primes/data/hgps_2-5.bin
-rw-r–r– 1 root root 48 Jan 12 09:34 /media/sda1/prjx/primes/data/hgps_2-7.bin
-rw-r–r– 1 root root 480 Jan 12 09:34 /media/sda1/prjx/primes/data/hgps_2-11.bin
-rw-r–r– 1 root root 5760 Jan 12 09:34 /media/sda1/prjx/primes/data/hgps_2-13.bin
-rw-r–r– 1 root root 92160 Jan 12 09:34 /media/sda1/prjx/primes/data/hgps_2-17.bin
-rw-r–r– 1 root root 1658880 Jan 12 09:34 /media/sda1/prjx/primes/data/hgps_2-19.bin
-rw-r–r– 1 root root 36495360 Jan 12 09:34 /media/sda1/prjx/primes/data/hgps_2-23.bin
-rw-r–r– 1 root root 1021870080 Jan 12 09:46 /media/sda1/prjx/primes/data/hgps_2-29.bin
-rw-r–r– 1 root root 30656102400 Jan 12 15:47 /media/sda1/prjx/primes/data/hgps_2-31.bin

root@Microknoppix:/media/sdb3/prjx/cfam-matrix/Java/prms/prms04# find /media/sda1 -type f -name “*.bin” 2>/dev/null -exec sha256sum -b {} \;
a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222 */media/sda1/prjx/primes/data/hgps_2-3.bin
a4d089b2804186e4d60b69adc3866c773f8a965a5a4c970c43eb12f3685a46e1 */media/sda1/prjx/primes/data/hgps_2-5.bin
d31e26a6f5854b83d85374b258b3174352e121883f38e84eb0ed224d8dbccffe */media/sda1/prjx/primes/data/hgps_2-7.bin
b780ecfa30aa779da041b65615f161001e1991e5f6ae3ac7d83696c6b8957ba2 */media/sda1/prjx/primes/data/hgps_2-11.bin
2df966944198159452836876529b358cce7b8f1ba8b658d2f7e11f14e5d13469 */media/sda1/prjx/primes/data/hgps_2-13.bin
128fa738b24b344e94971d86ad4b39695e318e129f53e833f1f3dd0bec3b9737 */media/sda1/prjx/primes/data/hgps_2-17.bin
03c9d51763ceb3892339a348c9527998c679b791b4afd9b5338c7f77124babf5 */media/sda1/prjx/primes/data/hgps_2-19.bin
eb83efeb7c794d322ff66a55ac79cefb25427c76f10dcb6db6227db3069c2a08 */media/sda1/prjx/primes/data/hgps_2-23.bin
4ba2e310a296bb3e291bf8a8732bd83c3fed0ae98b8af76bc673005242464b27 */media/sda1/prjx/primes/data/hgps_2-29.bin
c6d52ee080215cc229c3c65a60cd9a840f297a6af7a70c050b68e8a1512d5733 */media/sda1/prjx/primes/data/hgps_2-31.bin

~
these are functional tests I made with various values for the sieve buffer
~
private final int iSvBfr = 16384; // sieve buffer (I did test many options)
~

root@Microknoppix:/media/sdb3/prjx/cfam-matrix/Java/prms/prms04# find /media/sdc1 -type f -name “*.bin” 2>/dev/null -exec ls -l {} \;
-rw-r–r– 1 root root 92160 Jan 9 05:07 /media/sdc1/prjx/primes/data/hgps_2-17.bin
-rw-r–r– 1 root root 5760 Jan 9 05:07 /media/sdc1/prjx/primes/data/hgps_2-13.bin
-rw-r–r– 1 root root 480 Jan 9 05:07 /media/sdc1/prjx/primes/data/hgps_2-11.bin
-rw-r–r– 1 root root 8 Jan 9 05:07 /media/sdc1/prjx/primes/data/hgps_2-5.bin
-rw-r–r– 1 root root 1021870080 Jan 9 05:20 /media/sdc1/prjx/primes/data/hgps_2-29.bin
-rw-r–r– 1 root root 48 Jan 9 05:07 /media/sdc1/prjx/primes/data/hgps_2-7.bin
-rw-r–r– 1 root root 1658880 Jan 9 05:07 /media/sdc1/prjx/primes/data/hgps_2-19.bin
-rw-r–r– 1 root root 2 Jan 9 05:07 /media/sdc1/prjx/primes/data/hgps_2-3.bin
-rw-r–r– 1 root root 36495360 Jan 9 05:08 /media/sdc1/prjx/primes/data/hgps_2-23.bin

-rw-r–r– 1 root root 92160 Jan 8 04:22 /media/sdc1/prjx/primes/data/1053/hgps_2-17.bin
-rw-r–r– 1 root root 5760 Jan 8 04:22 /media/sdc1/prjx/primes/data/1053/hgps_2-13.bin
-rw-r–r– 1 root root 480 Jan 8 04:22 /media/sdc1/prjx/primes/data/1053/hgps_2-11.bin
-rw-r–r– 1 root root 8 Jan 8 04:22 /media/sdc1/prjx/primes/data/1053/hgps_2-5.bin
-rw-r–r– 1 root root 48 Jan 8 04:22 /media/sdc1/prjx/primes/data/1053/hgps_2-7.bin
-rw-r–r– 1 root root 1658880 Jan 8 04:22 /media/sdc1/prjx/primes/data/1053/hgps_2-19.bin
-rw-r–r– 1 root root 2 Jan 8 04:22 /media/sdc1/prjx/primes/data/1053/hgps_2-3.bin
-rw-r–r– 1 root root 36495360 Jan 8 04:22 /media/sdc1/prjx/primes/data/1053/hgps_2-23.bin

-rw-r–r– 1 root root 92160 Jan 8 03:59 /media/sdc1/prjx/primes/data/32768/hgps_2-17.bin
-rw-r–r– 1 root root 5760 Jan 8 03:59 /media/sdc1/prjx/primes/data/32768/hgps_2-13.bin
-rw-r–r– 1 root root 480 Jan 8 03:59 /media/sdc1/prjx/primes/data/32768/hgps_2-11.bin
-rw-r–r– 1 root root 8 Jan 8 03:59 /media/sdc1/prjx/primes/data/32768/hgps_2-5.bin
-rw-r–r– 1 root root 48 Jan 8 03:59 /media/sdc1/prjx/primes/data/32768/hgps_2-7.bin
-rw-r–r– 1 root root 1658880 Jan 8 03:59 /media/sdc1/prjx/primes/data/32768/hgps_2-19.bin
-rw-r–r– 1 root root 2 Jan 8 03:59 /media/sdc1/prjx/primes/data/32768/hgps_2-3.bin
-rw-r–r– 1 root root 36495360 Jan 8 03:59 /media/sdc1/prjx/primes/data/32768/hgps_2-23.bin

-rw-r–r– 1 root root 92160 Jan 8 04:09 /media/sdc1/prjx/primes/data/3/hgps_2-17.bin
-rw-r–r– 1 root root 5760 Jan 8 04:09 /media/sdc1/prjx/primes/data/3/hgps_2-13.bin
-rw-r–r– 1 root root 480 Jan 8 04:09 /media/sdc1/prjx/primes/data/3/hgps_2-11.bin
-rw-r–r– 1 root root 8 Jan 8 04:09 /media/sdc1/prjx/primes/data/3/hgps_2-5.bin
-rw-r–r– 1 root root 48 Jan 8 04:09 /media/sdc1/prjx/primes/data/3/hgps_2-7.bin
-rw-r–r– 1 root root 1658880 Jan 8 04:09 /media/sdc1/prjx/primes/data/3/hgps_2-19.bin
-rw-r–r– 1 root root 2 Jan 8 04:09 /media/sdc1/prjx/primes/data/3/hgps_2-3.bin
-rw-r–r– 1 root root 36495360 Jan 8 04:09 /media/sdc1/prjx/primes/data/3/hgps_2-23.bin

-rw-r–r– 1 root root 92160 Jan 8 04:26 /media/sdc1/prjx/primes/data/19/hgps_2-17.bin
-rw-r–r– 1 root root 5760 Jan 8 04:26 /media/sdc1/prjx/primes/data/19/hgps_2-13.bin
-rw-r–r– 1 root root 480 Jan 8 04:26 /media/sdc1/prjx/primes/data/19/hgps_2-11.bin
-rw-r–r– 1 root root 8 Jan 8 04:26 /media/sdc1/prjx/primes/data/19/hgps_2-5.bin
-rw-r–r– 1 root root 48 Jan 8 04:26 /media/sdc1/prjx/primes/data/19/hgps_2-7.bin
-rw-r–r– 1 root root 1658880 Jan 8 04:26 /media/sdc1/prjx/primes/data/19/hgps_2-19.bin
-rw-r–r– 1 root root 2 Jan 8 04:26 /media/sdc1/prjx/primes/data/19/hgps_2-3.bin
-rw-r–r– 1 root root 36495360 Jan 8 04:26 /media/sdc1/prjx/primes/data/19/hgps_2-23.bin

-rw-r–r– 1 root root 92160 Jan 8 04:16 /media/sdc1/prjx/primes/data/7/hgps_2-17.bin
-rw-r–r– 1 root root 5760 Jan 8 04:16 /media/sdc1/prjx/primes/data/7/hgps_2-13.bin
-rw-r–r– 1 root root 480 Jan 8 04:16 /media/sdc1/prjx/primes/data/7/hgps_2-11.bin
-rw-r–r– 1 root root 8 Jan 8 04:16 /media/sdc1/prjx/primes/data/7/hgps_2-5.bin
-rw-r–r– 1 root root 48 Jan 8 04:16 /media/sdc1/prjx/primes/data/7/hgps_2-7.bin
-rw-r–r– 1 root root 1658880 Jan 8 04:16 /media/sdc1/prjx/primes/data/7/hgps_2-19.bin
-rw-r–r– 1 root root 2 Jan 8 04:16 /media/sdc1/prjx/primes/data/7/hgps_2-3.bin
-rw-r–r– 1 root root 36495360 Jan 8 04:16 /media/sdc1/prjx/primes/data/7/hgps_2-23.bin

-rw-r–r– 1 root root 92160 Jan 8 04:32 /media/sdc1/prjx/primes/data/1025/hgps_2-17.bin
-rw-r–r– 1 root root 5760 Jan 8 04:32 /media/sdc1/prjx/primes/data/1025/hgps_2-13.bin
-rw-r–r– 1 root root 480 Jan 8 04:32 /media/sdc1/prjx/primes/data/1025/hgps_2-11.bin
-rw-r–r– 1 root root 8 Jan 8 04:32 /media/sdc1/prjx/primes/data/1025/hgps_2-5.bin
-rw-r–r– 1 root root 48 Jan 8 04:32 /media/sdc1/prjx/primes/data/1025/hgps_2-7.bin
-rw-r–r– 1 root root 1658880 Jan 8 04:32 /media/sdc1/prjx/primes/data/1025/hgps_2-19.bin
-rw-r–r– 1 root root 2 Jan 8 04:32 /media/sdc1/prjx/primes/data/1025/hgps_2-3.bin
-rw-r–r– 1 root root 36495360 Jan 8 04:32 /media/sdc1/prjx/primes/data/1025/hgps_2-23.bin

-rw-r–r– 1 root root 92160 Jan 8 04:29 /media/sdc1/prjx/primes/data/16384/hgps_2-17.bin
-rw-r–r– 1 root root 5760 Jan 8 04:29 /media/sdc1/prjx/primes/data/16384/hgps_2-13.bin
-rw-r–r– 1 root root 480 Jan 8 04:29 /media/sdc1/prjx/primes/data/16384/hgps_2-11.bin
-rw-r–r– 1 root root 8 Jan 8 04:29 /media/sdc1/prjx/primes/data/16384/hgps_2-5.bin
-rw-r–r– 1 root root 48 Jan 8 04:29 /media/sdc1/prjx/primes/data/16384/hgps_2-7.bin
-rw-r–r– 1 root root 1658880 Jan 8 04:29 /media/sdc1/prjx/primes/data/16384/hgps_2-19.bin
-rw-r–r– 1 root root 2 Jan 8 04:29 /media/sdc1/prjx/primes/data/16384/hgps_2-3.bin
-rw-r–r– 1 root root 36495360 Jan 8 04:29 /media/sdc1/prjx/primes/data/16384/hgps_2-23.bin

root@Microknoppix:/media/sdb3/prjx/cfam-matrix/Java/prms/prms04# find /media/sdc1 -type f -name “*.bin” 2>/dev/null -exec sha256sum -b {} \;
128fa738b24b344e94971d86ad4b39695e318e129f53e833f1f3dd0bec3b9737 */media/sdc1/prjx/primes/data/hgps_2-17.bin
2df966944198159452836876529b358cce7b8f1ba8b658d2f7e11f14e5d13469 */media/sdc1/prjx/primes/data/hgps_2-13.bin
b780ecfa30aa779da041b65615f161001e1991e5f6ae3ac7d83696c6b8957ba2 */media/sdc1/prjx/primes/data/hgps_2-11.bin
a4d089b2804186e4d60b69adc3866c773f8a965a5a4c970c43eb12f3685a46e1 */media/sdc1/prjx/primes/data/hgps_2-5.bin
4ba2e310a296bb3e291bf8a8732bd83c3fed0ae98b8af76bc673005242464b27 */media/sdc1/prjx/primes/data/hgps_2-29.bin
eb83efeb7c794d322ff66a55ac79cefb25427c76f10dcb6db6227db3069c2a08 */media/sdc1/prjx/primes/data/hgps_2-23.bin
d31e26a6f5854b83d85374b258b3174352e121883f38e84eb0ed224d8dbccffe */media/sdc1/prjx/primes/data/hgps_2-7.bin
03c9d51763ceb3892339a348c9527998c679b791b4afd9b5338c7f77124babf5 */media/sdc1/prjx/primes/data/hgps_2-19.bin
a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222 */media/sdc1/prjx/primes/data/hgps_2-3.bin

128fa738b24b344e94971d86ad4b39695e318e129f53e833f1f3dd0bec3b9737 */media/sdc1/prjx/primes/data/1053/hgps_2-17.bin
2df966944198159452836876529b358cce7b8f1ba8b658d2f7e11f14e5d13469 */media/sdc1/prjx/primes/data/1053/hgps_2-13.bin
b780ecfa30aa779da041b65615f161001e1991e5f6ae3ac7d83696c6b8957ba2 */media/sdc1/prjx/primes/data/1053/hgps_2-11.bin
a4d089b2804186e4d60b69adc3866c773f8a965a5a4c970c43eb12f3685a46e1 */media/sdc1/prjx/primes/data/1053/hgps_2-5.bin
d31e26a6f5854b83d85374b258b3174352e121883f38e84eb0ed224d8dbccffe */media/sdc1/prjx/primes/data/1053/hgps_2-7.bin
03c9d51763ceb3892339a348c9527998c679b791b4afd9b5338c7f77124babf5 */media/sdc1/prjx/primes/data/1053/hgps_2-19.bin
a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222 */media/sdc1/prjx/primes/data/1053/hgps_2-3.bin
eb83efeb7c794d322ff66a55ac79cefb25427c76f10dcb6db6227db3069c2a08 */media/sdc1/prjx/primes/data/1053/hgps_2-23.bin

128fa738b24b344e94971d86ad4b39695e318e129f53e833f1f3dd0bec3b9737 */media/sdc1/prjx/primes/data/32768/hgps_2-17.bin
2df966944198159452836876529b358cce7b8f1ba8b658d2f7e11f14e5d13469 */media/sdc1/prjx/primes/data/32768/hgps_2-13.bin
b780ecfa30aa779da041b65615f161001e1991e5f6ae3ac7d83696c6b8957ba2 */media/sdc1/prjx/primes/data/32768/hgps_2-11.bin
a4d089b2804186e4d60b69adc3866c773f8a965a5a4c970c43eb12f3685a46e1 */media/sdc1/prjx/primes/data/32768/hgps_2-5.bin
d31e26a6f5854b83d85374b258b3174352e121883f38e84eb0ed224d8dbccffe */media/sdc1/prjx/primes/data/32768/hgps_2-7.bin
03c9d51763ceb3892339a348c9527998c679b791b4afd9b5338c7f77124babf5 */media/sdc1/prjx/primes/data/32768/hgps_2-19.bin
a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222 */media/sdc1/prjx/primes/data/32768/hgps_2-3.bin
eb83efeb7c794d322ff66a55ac79cefb25427c76f10dcb6db6227db3069c2a08 */media/sdc1/prjx/primes/data/32768/hgps_2-23.bin

128fa738b24b344e94971d86ad4b39695e318e129f53e833f1f3dd0bec3b9737 */media/sdc1/prjx/primes/data/3/hgps_2-17.bin
2df966944198159452836876529b358cce7b8f1ba8b658d2f7e11f14e5d13469 */media/sdc1/prjx/primes/data/3/hgps_2-13.bin
b780ecfa30aa779da041b65615f161001e1991e5f6ae3ac7d83696c6b8957ba2 */media/sdc1/prjx/primes/data/3/hgps_2-11.bin
a4d089b2804186e4d60b69adc3866c773f8a965a5a4c970c43eb12f3685a46e1 */media/sdc1/prjx/primes/data/3/hgps_2-5.bin
d31e26a6f5854b83d85374b258b3174352e121883f38e84eb0ed224d8dbccffe */media/sdc1/prjx/primes/data/3/hgps_2-7.bin
03c9d51763ceb3892339a348c9527998c679b791b4afd9b5338c7f77124babf5 */media/sdc1/prjx/primes/data/3/hgps_2-19.bin
a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222 */media/sdc1/prjx/primes/data/3/hgps_2-3.bin
eb83efeb7c794d322ff66a55ac79cefb25427c76f10dcb6db6227db3069c2a08 */media/sdc1/prjx/primes/data/3/hgps_2-23.bin

128fa738b24b344e94971d86ad4b39695e318e129f53e833f1f3dd0bec3b9737 */media/sdc1/prjx/primes/data/19/hgps_2-17.bin
2df966944198159452836876529b358cce7b8f1ba8b658d2f7e11f14e5d13469 */media/sdc1/prjx/primes/data/19/hgps_2-13.bin
b780ecfa30aa779da041b65615f161001e1991e5f6ae3ac7d83696c6b8957ba2 */media/sdc1/prjx/primes/data/19/hgps_2-11.bin
a4d089b2804186e4d60b69adc3866c773f8a965a5a4c970c43eb12f3685a46e1 */media/sdc1/prjx/primes/data/19/hgps_2-5.bin
d31e26a6f5854b83d85374b258b3174352e121883f38e84eb0ed224d8dbccffe */media/sdc1/prjx/primes/data/19/hgps_2-7.bin
03c9d51763ceb3892339a348c9527998c679b791b4afd9b5338c7f77124babf5 */media/sdc1/prjx/primes/data/19/hgps_2-19.bin
a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222 */media/sdc1/prjx/primes/data/19/hgps_2-3.bin
eb83efeb7c794d322ff66a55ac79cefb25427c76f10dcb6db6227db3069c2a08 */media/sdc1/prjx/primes/data/19/hgps_2-23.bin

128fa738b24b344e94971d86ad4b39695e318e129f53e833f1f3dd0bec3b9737 */media/sdc1/prjx/primes/data/7/hgps_2-17.bin
2df966944198159452836876529b358cce7b8f1ba8b658d2f7e11f14e5d13469 */media/sdc1/prjx/primes/data/7/hgps_2-13.bin
b780ecfa30aa779da041b65615f161001e1991e5f6ae3ac7d83696c6b8957ba2 */media/sdc1/prjx/primes/data/7/hgps_2-11.bin
a4d089b2804186e4d60b69adc3866c773f8a965a5a4c970c43eb12f3685a46e1 */media/sdc1/prjx/primes/data/7/hgps_2-5.bin
d31e26a6f5854b83d85374b258b3174352e121883f38e84eb0ed224d8dbccffe */media/sdc1/prjx/primes/data/7/hgps_2-7.bin
03c9d51763ceb3892339a348c9527998c679b791b4afd9b5338c7f77124babf5 */media/sdc1/prjx/primes/data/7/hgps_2-19.bin
a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222 */media/sdc1/prjx/primes/data/7/hgps_2-3.bin
eb83efeb7c794d322ff66a55ac79cefb25427c76f10dcb6db6227db3069c2a08 */media/sdc1/prjx/primes/data/7/hgps_2-23.bin

128fa738b24b344e94971d86ad4b39695e318e129f53e833f1f3dd0bec3b9737 */media/sdc1/prjx/primes/data/1025/hgps_2-17.bin
2df966944198159452836876529b358cce7b8f1ba8b658d2f7e11f14e5d13469 */media/sdc1/prjx/primes/data/1025/hgps_2-13.bin
b780ecfa30aa779da041b65615f161001e1991e5f6ae3ac7d83696c6b8957ba2 */media/sdc1/prjx/primes/data/1025/hgps_2-11.bin
a4d089b2804186e4d60b69adc3866c773f8a965a5a4c970c43eb12f3685a46e1 */media/sdc1/prjx/primes/data/1025/hgps_2-5.bin
d31e26a6f5854b83d85374b258b3174352e121883f38e84eb0ed224d8dbccffe */media/sdc1/prjx/primes/data/1025/hgps_2-7.bin
03c9d51763ceb3892339a348c9527998c679b791b4afd9b5338c7f77124babf5 */media/sdc1/prjx/primes/data/1025/hgps_2-19.bin
a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222 */media/sdc1/prjx/primes/data/1025/hgps_2-3.bin
eb83efeb7c794d322ff66a55ac79cefb25427c76f10dcb6db6227db3069c2a08 */media/sdc1/prjx/primes/data/1025/hgps_2-23.bin

128fa738b24b344e94971d86ad4b39695e318e129f53e833f1f3dd0bec3b9737 */media/sdc1/prjx/primes/data/16384/hgps_2-17.bin
2df966944198159452836876529b358cce7b8f1ba8b658d2f7e11f14e5d13469 */media/sdc1/prjx/primes/data/16384/hgps_2-13.bin
b780ecfa30aa779da041b65615f161001e1991e5f6ae3ac7d83696c6b8957ba2 */media/sdc1/prjx/primes/data/16384/hgps_2-11.bin
a4d089b2804186e4d60b69adc3866c773f8a965a5a4c970c43eb12f3685a46e1 */media/sdc1/prjx/primes/data/16384/hgps_2-5.bin
d31e26a6f5854b83d85374b258b3174352e121883f38e84eb0ed224d8dbccffe */media/sdc1/prjx/primes/data/16384/hgps_2-7.bin
03c9d51763ceb3892339a348c9527998c679b791b4afd9b5338c7f77124babf5 */media/sdc1/prjx/primes/data/16384/hgps_2-19.bin
a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222 */media/sdc1/prjx/primes/data/16384/hgps_2-3.bin
eb83efeb7c794d322ff66a55ac79cefb25427c76f10dcb6db6227db3069c2a08 */media/sdc1/prjx/primes/data/16384/hgps_2-23.bin

cfam-matrix Prime Sieves (java code)

January 13, 2010


import java.io.*;
import java.util.*;
import java.text.*;
import java.text.DecimalFormat.*;
import java.security.*;

// __
class PrmSieve18{
// __ the product of these prime numbers gives you the largest sieve that a java long (2^63 - 1) can cover
private final long[] lSvPrms = new long[]{2L, 3L, 5L, 7L, 11L, 13L, 17L, 19L, 23L, 29L, 31L, 37L, 41L, 43L, 47L};
private int iSL; // sieve length
// __ W
private File PDatDir; // Path of the Data Directory
private final String aPDatDir = "pdat"; // Data Directory
// __
private final int iSvBfr = 16384; // sieve buffer (I did test many options)
private final int iBitsPByte = 8; // defined in java but not in ANSI C/C++
private final byte[] bBitsSet = new byte[]{
(byte)128, // 2^7 10000000 // no unsigned byte in Java
64, // 2^6 01000000
32, // 2^5 00100000
16, // 2^4 00010000
8, // 2^3 00001000
4, // 2^2 00000100
2, // 2^1 00000010
1 // 2^0 00000001
};
private final long lHGapMax = 510L; // ((510/2)=255 max. value that can be represented in a byte)
private final String aNwLn = System.getProperty("line.separator");

// __ rpt
private final int iChrPL = 120; // characters per line
private final String aMrgn = " "; // margin between primes
private final String aPCF = "0.000000#%"; // percent format
private final DecimalFormat DFPerCent = new DecimalFormat(aPCF);
private final String aDF6thP = "0.000000";
private final DecimalFormat DF6thP = new DecimalFormat(aDF6thP);
private final String aDFIPS = "0.000";
private final DecimalFormat DFFIPS = new DecimalFormat(aDFIPS);

// __
PrmSieve18(int iSL) throws IOException{
String aMsx;
// __
if(iSL == 1){
aMsx = aNwLn + "// __ iSL: |" + iSL + "| sieve would consist of even numbers only!";
throw new IOException(aMsx);
}
else if(iSL < 1){
aMsx = aNwLn + "// __ number of primes used for the sieve may maximally be " + lSvPrms.length + " from 2 to " + lSvPrms[lSvPrms.length - 1];
throw new IOException(aMsx);
}
else if(lSvPrms.length < iSL){
aMsx = aNwLn + "// __ Warning! Maximal length of the sequence of multiplied primes is: " + lSvPrms.length ;
System.err.println(aMsx); System.out.println(aMsx);
iSL = lSvPrms.length;
}// (lSvPrms.length < (iSL - 1))
this.iSL = iSL;
long lMultPrms = 2;
for(int i = 1; (i < this.iSL); ++i){ lMultPrms *= lSvPrms[i]; }
aMsx = aNwLn + "// __ largest sequence of products of primes for a sieve will be " + getFctrsAsText(iSL) + " := " + lMultPrms;
System.err.println(aMsx); System.out.println(aMsx);
}

// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

// __
public String getFctrsAsText(int iFctrs){
StringBuffer aB = new StringBuffer();
aB.append("( 2");
for(int i = 1; (i 0){ lDigBs *= lDecBs; lQ = lN/lDigBs; ++iDPlcs; }
return(iDPlcs);
}

// ~ ~ ~ ~ ~ ~ RPT ~ ~ ~ ~ ~ ~
// __ 4 testing/printing purposes
private String getBitSeq(byte b){
StringBuffer aB = new StringBuffer();
for(int i = (bBitsSet.length - 1); (i > -1); --i){
if((b & (bBitsSet[i] & 0xFF)) == (bBitsSet[i] & 0xFF)){ aB.append("1"); }
else{ aB.append("0"); }
}// i [0, bBitsSet.length)
return(aB.toString());
}

// __
public long[][] setSieves(File ODir) throws FileNotFoundException, IOException, NoSuchAlgorithmException{
// __
if(!ODir.exists()){
File OSubDir = new File(System.getProperty("user.dir"));
ODir = new File(OSubDir, aPDatDir);
if(!ODir.exists()){
if(!ODir.mkdirs()){ throw new IOException( aNwLn + "// __ Prime data directory not found and it could not be made! |" + ODir.getAbsolutePath() + " | make sure the partition is mounted rw!"); }
}
}
// __
PDatDir = ODir;
long[][] lSvsL = null;
// __
int iTp = lSvPrms.length, iBSz, iTmsTp, iRmndrTp, iIxByte, iIxBit, iIxBitSeq, iDPlcs, iSpc, iHPL, iDPlcCnt, iIxL;
long lFctr, lPrevFctr = 2, lFctrM1, lTtlBytes, lFrstBitFfst, lTtlCvrd, lQ, lHGap, lHGapGrtr, lHGapD2, lHole, lPrevHole = Long.MIN_VALUE, lTtlHGps, lTm00;
double dCvrd, dPrevCvrd = .5;
long[] lSRng = new long[lSvPrms.length];
String aFctrs, aOFlHGps, aFlNm, aThrdNm;
byte[] bSvBfr;
File OFl;
FileOutputStream FOS;
BufferedOutputStream BOS;
Runtime JRnTm = Runtime.getRuntime();
KThrdPPRptSieve00 KPPThrdS;

// __
for(int iPrms = 2; (iPrms < (iSL + 1)); ++iPrms){
lFctr = 1L; for(int i = 0; (i iBitsPByte*lTtlBytes){ lTtlBytes += 1; }

iBSz = iSvBfr;
if(lTtlBytes < (long)iSvBfr){ iBSz = (int)lTtlBytes; }
bSvBfr = new byte[iBSz];
for(int j = 0; (j < iBSz); ++j){ bSvBfr[j] = (byte)0; }

System.err.println("// __ iPrms: | " + iPrms + " |, lFctr: | " + lFctr + " := " + aFctrs + " |, lTtlBytes: | " + lTtlBytes + " |, bSvBfr.length: | " + bSvBfr.length + " | ");
System.out.println("// __ iPrms: | " + iPrms + " |, lFctr: | " + lFctr + " := " + aFctrs + " |, lTtlBytes: | " + lTtlBytes + " |, bSvBfr.length: | " + bSvBfr.length + " | ");

// __ Start of ranges
lTtlCvrd = 0; lFrstBitFfst = 0;
for(int k = 0; (k 0){ iRngs[1] = new int[]{iRmndrTp, 1}; }
else{ iRngs[1] = new int[]{-1, 0}; };

// __ debugging
for(int i = 0; (i < iRngs.length); ++i){
System.err.println("// __ iRngs[" + i + "][0]: | " + iRngs[i][0] + " |, iRngs[" + i + "][1]: | " + iRngs[i][1] + " |");
System.out.println("// __ iRngs[" + i + "][0]: | " + iRngs[i][0] + " |, iRngs[" + i + "][1]: | " + iRngs[i][1] + " |");
}// i [0, iRngs.length)

// __ file name of hole gaps in primes' sieve
aOFlHGps = "hgps_" + lSvPrms[0] + "-" + lSvPrms[(iPrms - 1)] + ".bin";
OFl = new File(ODir, aOFlHGps);
OFl.delete(); // @! todo do not overwrite if previously calculated. check metadata such as length and sha256 sum

// __
for(int i = 0; (i < iRngs.length); ++i){
for(int j = 0; (j < iRngs[i][1]); ++j){
for(int k = 0; (k < iPrms); ++k){
for(long l = lSRng[k]; ((l < lFctrM1) && ((l - lFrstBitFfst) < (long)iBitsPByte*iRngs[i][0])); l += lSvPrms[k]){
iIxByte = ((int)(l - lFrstBitFfst))/iBitsPByte;
iIxBit = (int)(l - lFrstBitFfst - iBitsPByte*iIxByte);
iIxBitSeq = bBitsSet.length - iIxBit - 1;
// __
if((bSvBfr[iIxByte] & (bBitsSet[iIxBitSeq] & 0xFF)) != (bBitsSet[iIxBitSeq] & 0xFF)){
bSvBfr[iIxByte] = (byte)((bSvBfr[iIxByte] + bBitsSet[iIxBitSeq]) & 0xFF);
++lTtlCvrd;
}
}// l
}// k [0, iPrms)
// __
BOS = new BufferedOutputStream(new FileOutputStream(OFl, true));
// __
for(int iSB = 0; (iSB < iRngs[i][0]); ++iSB){
// __ ((lFrstBitFfst + iBitsPByte*iSB + iBFfst) < lFctrM1)) because last bit may be within a byte
for(int iBFfst = 0; ((iBFfst < bBitsSet.length) && ((lFrstBitFfst + iBitsPByte*iSB + iBFfst) < lFctrM1)); ++iBFfst){
iIxBitSeq = bBitsSet.length - iBFfst - 1;
if((bSvBfr[iSB] & (bBitsSet[iIxBitSeq] & 0xFF)) == 0){
lHole = lFrstBitFfst + iBitsPByte*iSB + iBFfst;
lHGap = lHole - lPrevHole;
// __
if(lHGap 0){ lHGapD2 = (lHGap >> 1); BOS.write((byte)lHGapD2); }
else{ BOS.write((byte)1); }
lPrevHole = lHole; ++lTtlHGps;
if(lHGap > lHGapGrtr){ lHGapGrtr = lHGap; }
}// (lHGap < lHGapMax)
else{ throw new IOException( aNwLn + "// __ !(lHGap < lHGapMax) lHGap: | " + lHGap + " |, lHGapMax: | " + lHGapMax + " | "); }
}// ((bSvBfr[iSB] & (bBitsSet[iIxBitSeq] & 0xFF)) == 0)
}// iBFfst [0, bBitsSet.length) bit offsets (0:= holes) in current buffer
}// iSB sieve buffer
// __
BOS.close();

// __ resetting firstr bit offset, start of range and buffer with 0`s
lFrstBitFfst += (long)iBitsPByte*iRngs[i][0];
for(int k = 0; (k < iPrms); ++k){
lQ = (long)(lFrstBitFfst/lSvPrms[k]); long lR = (lFrstBitFfst - lQ*lSvPrms[k]);
lSRng[k] = lFrstBitFfst + (lSvPrms[k] - lR) - 1; // remainder form previous buffer & only diffs needed
}// k [0, iPrms)
// __
for(int k = 0; (k iSvBfr), IsRmv = IsZip;
aThrdNm = "_" + lSvPrms[0] + "-" + lSvPrms[(iPrms - 1)] + "_" + (new SimpleDateFormat("yyyyMMddHHmmss")).format(new Date(OFl.lastModified()));
rptSieves00(aThrdNm, OFl.getAbsolutePath(), iDPlcs, iHPL, aOTxtFl, IsOverWrite, IsZip, IsRmv);
// __
lPrevFctr = lFctr;
}// ((lFctr/lPrevFctr) == lSvPrms[iPrms - 1])
}// iPrms [2, (iTp + 1))
// __
return(lSvsL);
}

// __ @! "synchronized" paranoid safety thread's work is independent and self reporting
private synchronized void rptSieves00(String aThrdNm, String aIFlPath, int iDPlcs, int iHPL, String aOTxtFl, boolean IsOverWrite, boolean IsZip, boolean IsRmv) throws FileNotFoundException, NoSuchAlgorithmException{
(new KThrdPPRptSieve00(aThrdNm, aIFlPath, iDPlcs, iHPL, aOTxtFl, IsOverWrite, IsZip, IsRmv)).start();
}
}

// __
public class PrmSieve18Test{
private static final String aNwLn = System.getProperty("line.separator");
private static final String aEnc = "UTF-8";
// __
private static final void setOutErr(File ODir, String aPrfx, long lTm00, boolean IsOut, boolean IsErr){
String aLogFl = aPrfx + "_" + (new SimpleDateFormat("yyyyMMddHHmmss")).format(new Date(lTm00));
try{
if(IsOut){ PrintStream POS = new PrintStream((new FileOutputStream(new File(ODir, aLogFl + ".out.txt"))), true, aEnc); System.setOut(POS); }
if(IsErr){ PrintStream PES = new PrintStream((new FileOutputStream(new File(ODir, aLogFl + ".err.txt"))), true, aEnc); System.setErr(PES); }
}catch(FileNotFoundException FNFX){ FNFX.printStackTrace(); }
catch(IOException IOX){ IOX.printStackTrace(); }
}

// __
public static void main(String[] args){
// __
long lTm00 = System.currentTimeMillis();
String aKNm = "PrmSieve18Test";
File ODir = new File(System.getProperty("user.dir"));
setOutErr(ODir, aKNm, lTm00, true, false);
// __
int iSvL = 1;
iSvL = 7;
try{
PrmSieve18 PS = new PrmSieve18(iSvL);
PS.setSieves(ODir);
}catch(FileNotFoundException FNFX){ FNFX.printStackTrace(System.err); }
catch(IOException IOX){ IOX.printStackTrace(System.err); }
catch(NoSuchAlgorithmException NSxAlgoX){ NSxAlgoX.printStackTrace(System.err); }
// __
}
}

cfam-matrix Prime Sieves (java code): post processing and reporting threads

January 13, 2010


import java.io.*;
import java.util.*;
import java.util.zip.*;
import java.util.zip.Deflater.*;
import java.security.*;

// __ rpt post processing and reporting thread
class KThrdPPRptSieve00 extends Thread{
private String aIFlPath;
private int iDPlcs;
private int iHPL;
private String aOFlPath;
private boolean IsOverWrite;
private boolean IsZip;
private boolean IsRmv;

private String aFlSHA256;
private MessageDigest MD = null;
private SUtils24 SUtils;
// __ W
private final String aRngSHA256 = "SHA-256";
private final String aNwLn = System.getProperty("line.separator");
private final int iBfrL = 8192;

// __
KThrdPPRptSieve00(String aThrdNm, String aIFlPath, int iDPlcs, int iHPL, String aOFlPath, boolean IsOverWrite, boolean IsZip, boolean IsRmv) throws FileNotFoundException, NoSuchAlgorithmException{
File IFl = new File(aIFlPath);
if(IFl.exists()){
// __
this.aIFlPath = aIFlPath;
this.iDPlcs = iDPlcs;
this.iHPL = iHPL;
this.aOFlPath = aOFlPath;
this.IsOverWrite = IsOverWrite;
this.IsZip = IsZip;
this.IsRmv = IsRmv;
// __
// aThrdNm = this + aThrdNm;
setName(this + aThrdNm);
MD = MessageDigest.getInstance(aRngSHA256);
SUtils = new SUtils24();
}
else{ throw new FileNotFoundException( aNwLn + "// __ Input file does not exist! | " + IFl.getAbsolutePath() + " | "); }
}

// __
public void run(){
long lTm00 = System.currentTimeMillis();
StringBuffer aB = new StringBuffer();
aB.append(aNwLn).append("// __ thread start time (in ms): |" + lTm00 + "|");
// __
try{
BufferedInputStream BIS = null;
BufferedOutputStream BOS = null;
if(aOFlPath != null){
aOFlPath = aOFlPath.trim();
if(aOFlPath.length() > 0){
File OFl = new File(aOFlPath);
if(OFl.exists()){
if(IsOverWrite){ OFl.delete(); }
else{ throw new IOException( aNwLn + "// __ Output file exists and is not overwritten! : | " + OFl.getAbsolutePath() + " | "); }
}// (OFl.exists())
// __
File IFl = new File(aIFlPath);
BIS = new BufferedInputStream(new FileInputStream(IFl));
BOS = new BufferedOutputStream(new FileOutputStream(OFl));
// __
int iHGap = BIS.read(), lRdCnt = 2;
long lH = iHGap;
BOS.write(SUtils.padString(-1, (new Long(lH)).toString(), iDPlcs).getBytes()); // first is 1 (no left shifting)
iHGap = BIS.read();
while(iHGap != -1){
lH += (iHGap < 0)
else{ throw new IOException( aNwLn + "// __ Undefined output file aOFlPath: | " + aOFlPath + " | "); }
}// (aOFlPath != null)
}catch(FileNotFoundException FNFX){ FNFX.printStackTrace(System.err); }
catch(IOException IOX){ IOX.printStackTrace(System.err); }
}
}