@@ -157,14 +157,16 @@ void Instance::init(const Configuration &configuration) {
157157
158158 const auto initialBits (configuration.initialBits );
159159 _sieveWorkers = configuration.sieveWorkers ;
160+ const double primorialLog2Approx (static_cast <double >(configuration.initialTargetBits ) - 40 .);
160161 if (_sieveWorkers == 0 ) {
161- double proportion;
162- if (_pattern.size () >= 7 ) proportion = 0.85 - initialBits/1920 .;
163- else if (_pattern.size () == 6 ) proportion = 0.75 - initialBits/1792 .;
164- else if (_pattern.size () == 5 ) proportion = 0.7 - initialBits/1280 .;
165- else if (_pattern.size () == 4 ) proportion = 0.5 - initialBits/1280 .;
166- else proportion = 0 .;
167- if (proportion < 0 .) proportion = 0 .;
162+ double proportion (0 .);
163+ if (_pattern.size () >= 10 ) proportion = std::exp (-0.00053 *primorialLog2Approx);
164+ else if (_pattern.size () == 9 ) proportion = std::exp (-0.00065 *primorialLog2Approx);
165+ else if (_pattern.size () == 8 ) proportion = std::exp (-0.00088 *primorialLog2Approx);
166+ else if (_pattern.size () == 7 ) proportion = std::exp (-0.0013 *primorialLog2Approx);
167+ else if (_pattern.size () == 6 ) proportion = std::exp (-0.0021 *primorialLog2Approx);
168+ else if (_pattern.size () == 5 ) proportion = std::exp (-0.0037 *primorialLog2Approx);
169+ else if (_pattern.size () == 4 ) proportion = std::exp (-0.0059 *primorialLog2Approx);
168170 if (proportion > 1 .) proportion = 1 .;
169171 _sieveWorkers = std::ceil (proportion*static_cast <double >(_threads));
170172 }
@@ -175,14 +177,16 @@ void Instance::init(const Configuration &configuration) {
175177
176178 _primeTableLimit = configuration.primeTableLimit ;
177179 if (_primeTableLimit == 0 ) {
178- uint64_t primeTableLimitMax (2147483648ULL );
179- if (sysInfo.getPhysicalMemory () < 536870912ULL )
180+ uint64_t primeTableLimitMax (4294967296ULL );
181+ if (sysInfo.getPhysicalMemory () == 0ULL ) // Could not detect Ram, reasonable default for a machine with 4 GiB.
182+ primeTableLimitMax = 1073741824ULL ;
183+ else if (sysInfo.getPhysicalMemory () < 536870912ULL ) // A Vintage Computer, maybe...
180184 primeTableLimitMax = 67108864ULL ;
181- else if (sysInfo.getPhysicalMemory () < 17179869184ULL )
185+ else if (sysInfo.getPhysicalMemory () < 34359738368ULL )
182186 primeTableLimitMax = sysInfo.getPhysicalMemory ()/8ULL ;
183187 _primeTableLimit = std::pow (initialBits, 6 .)/std::pow (2 ., 3 .*static_cast <double >(_pattern.size ()) + 7 .);
184- if (_threads > 16 ) {
185- _primeTableLimit *= 16 ;
188+ if (_threads > 32 ) {
189+ _primeTableLimit *= 32 ;
186190 _primeTableLimit /= static_cast <double >(_threads);
187191 }
188192 _primeTableLimit = std::min (_primeTableLimit, primeTableLimitMax);
0 commit comments