Back to mersenne-aries.sili.net main page
credit.php:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>GIMPS PrimeNet CPU credit calculator</title>
<link rel="stylesheet" href="/style.css" type="text/css">
<script type="text/javascript">
function checkCreditForm(theform) {
return true;
}
</script>
</head>
<body>
<a href="/">Back to <i>mersenne-aries.sili.net</i> main page</a>
<hr size="1">
<?php
if (@$_REQUEST['showsource']) {
$filestoshow = array(basename(__FILE__), 'functions.inc.php', 'cpucredit.inc.php');
foreach ($filestoshow as $key => $value) {
echo htmlentities($value).':<blockquote style="border: 1px solid #000000; padding: 10px;">';
highlight_file($value);
echo '</blockquote>';
}
exit;
}
echo '<a href="'.$_SERVER['PHP_SELF'].'?showsource=1" style="font-size: 8pt;">show source</a><hr noshade size="1">';
///////////////////////////////////////////////////////////////////////////
require_once('functions.inc.php');
///////////////////////////////////////////////////////////////////////////
if (!isset($_REQUEST['b1']) && !isset($_REQUEST['b2'])) {
if (@$_REQUEST['guess'] == 'n') {
// guess for never-been-LL'd
$_REQUEST['b1'] = B1bound(@$_REQUEST['exponent'], false);
$_REQUEST['b2'] = $_REQUEST['b1'] * 25;
} elseif (@$_REQUEST['guess'] == 'y') {
// guess for already-been-LL'd-once
$_REQUEST['b1'] = B1bound(@$_REQUEST['exponent'], true);
$_REQUEST['b2'] = $_REQUEST['b1'] * 20;
}
}
echo '<h3>Estimate CPU credit for PrimeNet assignments</h3>';
echo '<form method="get" action="'.$_SERVER['PHP_SELF'].'" name="form1" onSubmit="return checkCreditForm(this);">';
echo '<table border="0">';
$worktypes = array(''=>'--select one--', 'LL'=>'Lucas-Lehmer', 'TF'=>'Trial Factoring', 'P-1'=>'P-1 Factoring', 'ECM'=>'ECM Factoring');
echo '<tr><td>Work Type:<td><select name="worktype">';
foreach ($worktypes as $key => $value) {
echo '<option value="'.htmlentities($key, ENT_QUOTES).'"'.(($key == @$_REQUEST['worktype']) ? ' selected="selected"' : '').'>'.htmlentities($value, ENT_QUOTES).'</option>';
}
echo '</select></td></tr>';
echo '<tr><td>Exponent:</td> <td>M<input type="text" size="9" name="exponent" value="'.htmlentities(@$_REQUEST['exponent'], ENT_QUOTES).'"> (or F<input type="text" size="2" name="f_exponent" value="'.htmlentities(@$_REQUEST['f_exponent'], ENT_QUOTES).'">)</td></tr>';
echo '<tr><td>B1:</td> <td> <input type="text" size="20" name="b1" value="'.htmlentities(@$_REQUEST['b1'], ENT_QUOTES).'"></td></tr>';
echo '<tr><td>B2:</td> <td> <input type="text" size="20" name="b2" value="'.htmlentities(@$_REQUEST['b2'], ENT_QUOTES).'"></td></tr>';
echo '<tr><td>ECMcurves:</td> <td> <input type="text" size="3" name="numcurves" value="'.htmlentities(@$_REQUEST['numcurves'], ENT_QUOTES).'"></td></tr>';
echo '<tr><td>Factor:</td> <td> <input type="text" size="20" name="factor" value="'.htmlentities(@$_REQUEST['factor'], ENT_QUOTES).'"></td></tr>';
echo '<tr><td>Factoring Range:</td><td> <input type="text" size="3" name="frombits" value="'.htmlentities(@$_REQUEST['frombits'], ENT_QUOTES).'"> to <input type="text" size="3" name="tobits" value="'.htmlentities(@$_REQUEST['tobits'], ENT_QUOTES).'"></td></tr>';
echo '<tr><td colspan="2"><input type="submit" name="submitbutton" value="Calculate"></td></tr>';
echo '</table>';
echo '</form>';
$forcenumeric = array('exponent', 'f_exponent', 'factor', 'frombits', 'tobits', 'b1', 'b2', 'numcurves');
foreach ($forcenumeric as $key => $value) {
$_REQUEST[$value] = eregi_replace('[^0-9]', '', @$_REQUEST[$value]);
}
if ($_REQUEST['f_exponent']) {
if ($_REQUEST['f_exponent'] <= 30) {
echo '<div style="color: red;">Fermat exponent F'.$_REQUEST['f_exponent'].' roughly translated to M(2^'.$_REQUEST['f_exponent'].') = M'.pow(2, $_REQUEST['f_exponent']).' for credit-calculation purposes. Credit may be off by up to 25%</div>';
$_REQUEST['exponent'] = pow(2, $_REQUEST['f_exponent']);
} else {
echo 'Fermat exponents larger than 30 not currently supported';
exit;
}
}
if ($_REQUEST['exponent'] && @$_REQUEST['worktype']) {
echo '<hr>';
$savedwork = array(0=>array(),1=>array());
$thisWorkGHzDays = 0;
$thisSaveGHzDays = 0;
switch ($_REQUEST['worktype']) {
case 'LL':
if ($_REQUEST['exponent']) {
// is OK
} else {
echo 'ERROR: "exponent" must be specified';
exit;
}
$thisWorkGHzDays = CalcGHzDaysLL($_REQUEST['exponent']);
$description = 'Lucas-Lehmer test on "'.htmlentities($_REQUEST['exponent']).'"';
$work_done = 'LL test ('.number_format(fft_timings_lookup($_REQUEST['exponent'], -1) / 1024, 0, '.', '').'K FFT)';
break;
case 'TF':
if ($_REQUEST['factor'] || ($_REQUEST['frombits'] && $_REQUEST['tobits'])) {
// is OK
} else {
echo 'ERROR: one of ("factor" or ("tobits" and "frombits")) must be specified';
exit;
}
$thisWorkGHzDays = CalcGHzDaysTrialFactor($_REQUEST['exponent'], $_REQUEST['frombits'], $_REQUEST['tobits'], $_REQUEST['factor']);
if ($_REQUEST['factor']) {
$maxbits = max($_REQUEST['tobits'], FactorBits($_REQUEST['exponent']));
if ($maxbits > $_REQUEST['tobits']) {
$savedstartbits = ($_REQUEST['factor'] ? ceil(log($_REQUEST['factor'], 2)) : $_REQUEST['tobits']);
//var_dump($savedstartbits);
if ($savedstartbits < $maxbits) {
$thissavedGHzDays = CalcGHzDaysTrialFactor($_REQUEST['exponent'], $savedstartbits, $maxbits);
$savedwork[0][] = number_format($thissavedGHzDays, 3);
$savedwork[1][] = 'GHz-days: TF (from 2^'.$savedstartbits.' to 2^'.$maxbits.')';
$thisSaveGHzDays += $thissavedGHzDays;
}
}
$thissavedGHzDays = CalcGHzDaysPminus1($_REQUEST['exponent'], false, false);
$savedwork[0][] = number_format($thissavedGHzDays, 3);
$savedwork[1][] = 'GHz-days: P-1 (B1='.B1bound($_REQUEST['exponent']).',B2='.(25 * B1bound($_REQUEST['exponent'])).')';
$thisSaveGHzDays += $thissavedGHzDays;
$thissavedGHzDays = 2 * CalcGHzDaysLL($_REQUEST['exponent']);
$savedwork[0][] = number_format($thissavedGHzDays, 3);
$savedwork[1][] = 'GHz-days (2x LL tests)';
$thisSaveGHzDays += $thissavedGHzDays;
}
$description = 'Trial Factoring on "M'.htmlentities($_REQUEST['exponent']).'"'.($_REQUEST['factor'] ? ' with '.number_format(log($_REQUEST['factor'], 2), 2).'-bit factor "'.$_REQUEST['factor'].'"' : 'from 2^'.$_REQUEST['frombits'].' to 2^'.$_REQUEST['tobits']);
$work_done = 'TF M'.htmlentities($_REQUEST['exponent']).($_REQUEST['factor'] ? ' with '.ceil(log($_REQUEST['factor'], 2)).'-bit factor' : ' from 2^'.htmlentities($_REQUEST['frombits']).' to 2^'.htmlentities($_REQUEST['tobits']));
break;
case 'P-1':
if ($_REQUEST['factor'] || ($_REQUEST['b1'] && $_REQUEST['b2'])) {
// is OK
} else {
echo 'ERROR: one of ("factor" or ("b1" and "b2")) must be specified';
exit;
}
$_REQUEST['b1'] = ($_REQUEST['b1'] ? $_REQUEST['b1'] : false);
$_REQUEST['b2'] = ($_REQUEST['b2'] ? $_REQUEST['b2'] : false);
$thisWorkGHzDays = CalcGHzDaysPminus1($_REQUEST['exponent'], $_REQUEST['b1'], $_REQUEST['b2']);
if ($_REQUEST['factor']) {
$maxbits = max($_REQUEST['tobits'], FactorBits($_REQUEST['exponent']));
if ($maxbits > $_REQUEST['tobits']) {
$savedstartbits = ($_REQUEST['factor'] ? ceil(log($_REQUEST['factor'], 2)) : $_REQUEST['tobits']);
if ($savedstartbits < $_REQUEST['tobits']) {
$thissavedGHzDays = CalcGHzDaysTrialFactor($_REQUEST['exponent'], $savedstartbits, $maxbits);
$savedwork[0][] = number_format($thissavedGHzDays, 3);
$savedwork[1][] = 'GHz-days: TF (from 2^'.$savedstartbits.' to 2^'.$maxbits.')';
$thisSaveGHzDays += $thissavedGHzDays;
}
}
$thissavedGHzDays = 2 * CalcGHzDaysLL($_REQUEST['exponent']);
$savedwork[0][] = number_format($thissavedGHzDays, 3);
$savedwork[1][] = 'GHz-days (2x LL tests)';
$thisSaveGHzDays += $thissavedGHzDays;
}
$description = 'P-1 Factoring on "'.htmlentities($_REQUEST['exponent']).'"'.($_REQUEST['factor'] ? ' with '.number_format(log($_REQUEST['factor'], 2), 2).'-bit factor "'.$_REQUEST['factor'].'"' : ' (B1='.$_REQUEST['b1'].', B2='.$_REQUEST['b2'].')');
$work_done = 'P-1 M'.htmlentities($_REQUEST['exponent']).($_REQUEST['factor'] ? ' with '.ceil(log($_REQUEST['factor'], 2)).'-bit factor' : ' (B1='.$_REQUEST['b1'].', B2='.$_REQUEST['b2'].')');
break;
case 'ECM':
if ($_REQUEST['factor'] || ($_REQUEST['b1'] && $_REQUEST['b2'] && $_REQUEST['numcurves'])) {
// is OK
} else {
echo 'ERROR: one of ("factor" or ("b1" and "b2" and "numcurves")) must be specified';
exit;
}
$_REQUEST['b1'] = ($_REQUEST['b1'] ? $_REQUEST['b1'] : false);
$_REQUEST['b2'] = ($_REQUEST['b2'] ? $_REQUEST['b2'] : false);
$thisWorkGHzDays = CalcGHzDaysECM($_REQUEST['exponent'], $_REQUEST['numcurves'], $_REQUEST['b1'], $_REQUEST['b2']);
if ($_REQUEST['factor']) {
// no work saved
}
$description = 'ECM Factoring on "'.htmlentities($_REQUEST['exponent']).'"'.($_REQUEST['factor'] ? ' with '.number_format(log($_REQUEST['factor'], 2), 2).'-bit factor "'.$_REQUEST['factor'].'"' : ' (curves='.$_REQUEST['numcurves'].', B1='.$_REQUEST['b1'].', B2='.$_REQUEST['b2'].')');
$work_done = 'ECM M'.htmlentities($_REQUEST['exponent']).($_REQUEST['factor'] ? ' with '.ceil(log($_REQUEST['factor'], 2)).'-bit factor' : ' (curves='.$_REQUEST['numcurves'].', B1='.$_REQUEST['b1'].', B2='.$_REQUEST['b2'].')');
break;
default:
echo 'ERROR: Invalid worktype';
exit;
break;
}
echo $description.':<br>';
echo '<table border="1" cellspacing="0" cellpadding="3">';
echo '<tr><th colspan="2">Work credit</th><th colspan="2">Work saved</th></tr>';
echo '<tr><td colspan="2">'.$work_done.'</td>';
if (!empty($savedwork[0])) {
echo '<td align="right" style="text-align: right; font-family: monospace;">'.implode('<br>', $savedwork[0]).'</td>';
echo '<td>'.implode('<br>', $savedwork[1]).'</td>';
} else {
echo '<td colspan="2" align="center"><i>none</i>';
}
echo '</td></tr>';
echo '<tr>';
echo '<td align="right" style="text-align: right; font-family: monospace;">'.(($thisWorkGHzDays < 0.00001) ? sprintf('%.3e', $thisWorkGHzDays) : number_format($thisWorkGHzDays, 6)).'<br><span style="color: #999999;">'.(($thisWorkGHzDays < 0.00001) ? sprintf('%.3e', GHzDays2P90years($thisWorkGHzDays)) : number_format(GHzDays2P90years($thisWorkGHzDays), 6)).'</span></td><td>GHz-days<br><span style="color: #999999;">P90years</span></td>';
echo '<td align="right" style="text-align: right; font-family: monospace;">'.number_format($thisSaveGHzDays, 3).'<br><span style="color: #999999;">'.number_format(GHzDays2P90years($thisSaveGHzDays), 3).'</span></td><td>GHz-days<br><span style="color: #999999;">P90years</span></td>';
echo '</tr>';
echo '</table>';
}
?>
</body>
</html>
functions.inc.php:
<?php
require_once('db.inc.php');
error_reporting(E_ALL);
ini_set('display_errors', '1');
define('STATS_HTML_CACHE_DIR', dirname(__FILE__).'/statsHTMLcache/');
///////////////////////////////////////////////////////////////////////////
function filesize_remote($remotefile, $timeout=10) {
static $filesize_cache = array();
if (!@$filesize_cache[$remotefile]) {
$filesize_cache[$remotefile] = false;
$url = parse_url($remotefile);
if ($fp = @fsockopen($url['host'], ($url['port'] ? $url['port'] : 80), $errno, $errstr, $timeout)) {
fwrite($fp, 'HEAD '.@$url['path'].@$url['query'].' HTTP/1.0'."\r\n");
fwrite($fp, 'Host: '.@$url['host']."\r\n");
if (@$url['user'] || @$url['pass']) {
fwrite($fp, 'Authorization: Basic '.base64_encode($url['user'].':'.$url['pass'])."\r\n");
}
fwrite($fp, "\r\n");
stream_set_timeout($fp, $timeout);
while (!feof($fp)) {
$headerline = fgets($fp, 4096);
if (eregi('^Content-Length: (.*)', $headerline, $matches)) {
$filesize_cache[$remotefile] = intval($matches[1]);
break;
}
}
fclose ($fp);
}
}
return $filesize_cache[$remotefile];
}
function filedate_remote($remotefile, $timeout=10) {
static $filedate_cache = array();
if (!@$filedate_cache[$remotefile]) {
$filedate_cache[$remotefile] = false;
$url = parse_url($remotefile);
if ($fp = @fsockopen($url['host'], ($url['port'] ? $url['port'] : 80), $errno, $errstr, $timeout)) {
fwrite($fp, 'HEAD '.@$url['path'].@$url['query'].' HTTP/1.0'."\r\n");
fwrite($fp, 'Host: '.@$url['host']."\r\n");
if (@$url['user'] || @$url['pass']) {
fwrite($fp, 'Authorization: Basic '.base64_encode($url['user'].':'.$url['pass'])."\r\n");
}
fwrite($fp, "\r\n");
stream_set_timeout($fp, $timeout);
while (!feof($fp)) {
$headerline = fgets($fp, 4096);
if (eregi('^Last-Modified: (.*)', $headerline, $matches)) {
$filedate_cache[$remotefile] = strtotime($matches[1]) - date('Z');
break;
}
}
fclose($fp);
}
}
return $filedate_cache[$remotefile];
}
function P90years2GHzDays($P90years) {
// straight from George :)
// http://www.mersenneforum.org/showpost.php?p=133207&postcount=3
// One core of a C2D = 1.68 P4
// A P4 = 3.44 PIIs
// A PII = 1.12 Pentium
// Thus, a P-90 CPU year = 365 days * 1 C2GHD * (90MHz / 1000MHz) / 1.68 / 3.44 / 1.12 = 5.075 C2GHDs
return $P90years * 5.075;
}
function GHzDays2P90years($GHzDays) {
// straight from George :)
// http://www.mersenneforum.org/showpost.php?p=133207&postcount=3
// One core of a C2D = 1.68 P4
// A P4 = 3.44 PIIs
// A PII = 1.12 Pentium
// Thus, a P-90 CPU year = 365 days * 1 C2GHD * (90MHz / 1000MHz) / 1.68 / 3.44 / 1.12 = 5.075 C2GHDs
return $GHzDays / 5.075;
}
function CalcGHzDaysPminus1($exponent, $b1=false, $b2=false) {
if ($b1 === false) {
//$alreadyLLd = true; // most Mersenne-aries work will be done with Pfactor=exp,bits,1
$alreadyLLd = false;
$b1 = B1bound($exponent, $alreadyLLd);
}
if ($b2 == false) {
$b2 = $b1 * 25; // rough approximation of default auto-selection
} elseif ($b2 < $b1) {
$b2 = $b1;
}
require_once('cpucredit.inc.php');
return credit_cpu_PM1_factoring($exponent, 0, $b1, $b2);
}
function CalcP90yearsPminus1($exponent, $b1=false, $b2=false) {
return GHzDays2P90years(CalcGHzDaysPminus1($exponent, $b1, $b2));
}
function CalcGHzDaysECM($exponent, $curves_run, $b1, $b2) {
require_once('cpucredit.inc.php');
return credit_cpu_ECM($exponent, 0, $curves_run, $b1, $b2);
}
function CalcP90yearsECM($exponent, $curves_run, $b1, $b2) {
return GHzDays2P90years(CalcGHzDaysECM($exponent, $curves_run, $b1, $b2));
}
function CalcGHzDaysLL($exponent) {
require_once('cpucredit.inc.php');
return credit_cpu_LL($exponent, 0);
}
function CalcP90yearsLL($exponent) {
return GHzDays2P90years(CalcGHzDaysLL($exponent));
}
function BitsInFactor($factor, $intversion=false) {
return ($intversion ? ceil(log($factor, 2)) : log($factor, 2));
}
function ExponentFactorThreshold() {
static $ExponentThreshold = array(
// These breakeven points we're calculated on a 2.0 GHz P4 Northwood:
516000000 => 80,
420400000 => 79,
337400000 => 78,
264600000 => 77,
227300000 => 76,
186400000 => 75,
147500000 => 74,
115300000 => 73,
96830000 => 72,
75670000 => 71,
58520000 => 70,
47450000 => 69,
37800000 => 68,
29690000 => 67,
23390000 => 66,
// These breakevens we're calculated a long time ago on unknown hardware:
13380000 => 65,
8250000 => 64,
6515000 => 63,
5160000 => 62,
3960000 => 61,
2950000 => 60,
2360000 => 59,
1930000 => 58,
1480000 => 57,
1000000 => 56,
0 => 40,
// OLD values from the before-time
//79300000=>72, // Prime95 can't currently handle exponents bigger than this...
//71000000=>72,
//57020000=>71,
//44150000=>70,
//35100000=>69,
//28130000=>68,
//21590000=>67,
//17850000=>66,
);
return $ExponentThreshold;
}
function FactorBits($exponent) {
$ExponentThreshold = ExponentFactorThreshold();
$factorbits = 0;
foreach ($ExponentThreshold as $limit => $bits) {
if ($exponent >= $limit) {
$factorbits = $bits;
break;
}
}
return $factorbits;
}
function CalcGHzDaysTrialFactor($exponent, $frombits=0, $limit=false, $factor='') {
if ($limit === false) {
// how far will Prime95 factor this exponent by default
$limit = FactorBits($exponent);
}
if (!$frombits && !$factor) {
// this is a hack for pre-v25 which didn't always report starting point of TF
// most trial factoring is done from <whatever-the-current-level-is> to
// the reported bit depth, but it doesn't report the current level. So guess :)
if ($limit <= 58) {
$frombits = 32; // anything factored to low bit depths started from nothing, or close-to-nothing (CPU time to factor from 2^0 to 2^32 is insignificant)
} else {
$frombits = $limit - 1; // assume most submitted results will be LMH results increasing factor depth by 1 level
}
}
require_once('cpucredit.inc.php');
if ($factor) {
$frombits = floor(log($factor, 2));
return credit_cpu_TF_factor_p95($exponent, $factor, $frombits);
} else {
return credit_cpu_TF_no_factor($exponent, $frombits, $limit);
}
}
function CalcP90yearsTrialFactor($exponent, $frombits=0, $limit=false, $factor='') {
return GHzDays2P90years(CalcGHzDaysTrialFactor($exponent, $frombits, $limit, $factor));
}
function B1bound($exponent, $alreadyLLd=false) {
// formulae taken from Excel graph of actual values from Prime95
// it's a little off around FFT size changes, but close enough
$exp = $exponent / 1000000;
if ($alreadyLLd) {
//$B1 = (-11 * $exp * $exp) + (5800 * $exp); // projection data up to 79M
$B1 = (-1.3309 * $exp * $exp) + (5232 * $exp); // updated formula from 2008-12-13 with projection data up to 500M
} else {
//$B1 = (-24.529 * $exp * $exp) + (12434 * $exp); // projection data up to 79M
$B1 = (-3.2698 * $exp * $exp) + (11182 * $exp); // updated formula from 2008-12-13 with projection data up to 500M
}
return round($B1 / 5000) * 5000;
}
function B2bound($exponent, $alreadyLLd=false) {
return B1bound($exponent, $alreadyLLd) * ($alreadyLLd ? 20 : 25);
}
function DickmansFunction($x) {
static $savedF = array(
0, 0, 0, 0, 0, 0, 3.3513e-215, 5.63754e-208, 4.00865e-201,
1.65407e-194, 4.53598e-188, 8.93587e-182, 1.33115e-175,
1.55557e-169, 1.46609e-163, 1.13896e-157, 7.42296e-152,
3.80812e-146, 1.56963e-140, 5.32886e-135, 1.51923e-129,
3.69424e-124, 7.76066e-119, 1.42371e-113, 2.30187e-108,
3.30619e-103, 4.24793e-098, 4.80671e-093, 4.78516e-088,
4.22768e-083, 3.33979e-078, 2.37455e-073, 1.52822e-068,
8.94846e-064, 4.78909e-059, 4.65696e-057, 4.49802e-055, 4.31695e-053,
4.07311e-051, 3.81596e-049, 3.61043e-047, 1.73046e-045, 8.26375e-044,
3.9325e-042, 1.86471e-040, 8.8102e-039, 4.14402e-037, 1.99497e-035,
1.83001e-034, 1.59023e-033, 1.45505e-032, 1.24603e-031, 1.15674e-030,
9.70832e-030, 9.23876e-029, 4.20763e-028, 4.24611e-027, 1.61371e-026,
6.59556e-026, 3.17069e-025, 1.12205e-024, 4.65874e-024, 2.01267e-023,
6.2941e-023, 3.02604e-022, 7.84622e-022, 2.3526e-021, 6.7049e-021,
1.88634e-020, 4.59378e-020, 1.37233e-019, 4.00682e-019, 8.34209e-019,
2.21612e-018, 4.84252e-018, 1.02457e-017, 2.03289e-017, 4.07704e-017,
1.33778e-016, 2.4263e-016, 4.14981e-016, 7.0383e-016, 1.20511e-015,
3.85644e-015, 6.52861e-015, 1.06563e-014, 1.67897e-014, 2.79916e-014,
4.54319e-014, 9.83296e-014, 1.66278e-013, 2.61858e-013, 4.03872e-013,
5.98967e-013, 1.09674e-012, 1.70553e-012, 2.56573e-012, 3.72723e-012,
6.14029e-012, 9.33636e-012, 1.36469e-011, 1.89881e-011, 2.68391e-011,
4.12016e-011, 5.94394e-011, 8.43746e-011, 1.12903e-010, 1.66987e-010,
2.36959e-010, 3.11726e-010, 4.28713e-010, 5.90781e-010, 7.79892e-010,
1.05264e-009, 1.4016e-009, 1.87506e-009, 2.42521e-009, 3.14508e-009,
4.38605e-009, 5.43307e-009, 6.96737e-009, 8.84136e-009, 1.16286e-008,
1.42343e-008, 1.79697e-008, 2.30867e-008, 2.88832e-008, 3.52583e-008,
4.31032e-008, 5.46444e-008, 6.66625e-008, 8.06132e-008, 1.00085e-007,
1.20952e-007, 1.4816e-007, 1.80608e-007, 2.13125e-007, 2.5324e-007,
3.094e-007, 3.64545e-007, 4.31692e-007, 5.19078e-007, 6.03409e-007,
7.21811e-007, 8.53856e-007, 9.71749e-007, 1.13949e-006, 1.37042e-006,
1.53831e-006, 1.79066e-006, 2.15143e-006, 2.40216e-006, 2.76872e-006,
3.20825e-006, 3.61263e-006, 4.21315e-006, 4.76404e-006, 5.43261e-006,
6.2041e-006, 6.96243e-006, 7.94979e-006, 8.89079e-006, 1.01387e-005,
1.13376e-005, 1.2901e-005, 1.44183e-005, 1.59912e-005, 1.79752e-005,
1.99171e-005, 2.22665e-005, 2.47802e-005, 2.7678e-005, 3.0492e-005,
3.34189e-005, 3.71902e-005, 4.12605e-005, 4.54706e-005, 4.98411e-005,
5.48979e-005, 6.06015e-005, 6.61278e-005, 7.22258e-005, 7.97193e-005,
8.66574e-005, 9.48075e-005, 0.00010321, 0.000112479, 0.000121776,
0.000133344, 0.000144023, 0.000156667, 0.000168318, 0.000183192,
0.000196527, 0.00021395, 0.000228389, 0.000249223, 0.000264372,
0.000289384, 0.000305707, 0.000333992, 0.000353287, 0.000379868,
0.000408274, 0.00043638, 0.000465319, 0.000496504, 0.000530376,
0.000566008, 0.000602621, 0.000642286, 0.000684543, 0.000723853,
0.000772655, 0.000819418, 0.000868533, 0.000920399, 0.000975529,
0.00103188, 0.00109478, 0.00115777, 0.00122087, 0.00128857,
0.00136288, 0.00143557, 0.00151714, 0.00159747, 0.00167572,
0.00176556, 0.00186199, 0.00195063, 0.00205239, 0.00216102,
0.00225698, 0.00236962, 0.00249145, 0.00259636, 0.00272455,
0.00287006, 0.00297545, 0.00312346, 0.0032634, 0.00340298,
0.00355827, 0.00371195, 0.00387288, 0.00404725, 0.00420016,
0.00439746, 0.00456332, 0.00475936, 0.00495702, 0.00514683,
0.00535284, 0.00557904, 0.00578084, 0.00601028, 0.00623082,
0.00647765, 0.00673499, 0.00696553, 0.00722529, 0.00748878,
0.00775537, 0.00803271, 0.00832199, 0.00861612, 0.00889863,
0.00919876, 0.00953343, 0.00985465, 0.0101993, 0.0105042, 0.0108325,
0.0112019, 0.0115901, 0.0119295, 0.0123009, 0.0127191, 0.0130652,
0.0134855, 0.0139187, 0.0142929, 0.0147541, 0.0151354, 0.0156087,
0.0160572, 0.0165382, 0.0169669, 0.0174693, 0.0179460, 0.0184202,
0.0189555, 0.0194336, 0.0200107, 0.0204863, 0.0210242, 0.0216053,
0.0221361, 0.0226858, 0.0232693, 0.0239027, 0.0244779, 0.025081,
0.0257169, 0.0263059, 0.0269213, 0.0275533, 0.0282065, 0.0289028,
0.0295670, 0.0302268, 0.0309193, 0.0316619, 0.0323147, 0.0330398,
0.0338124, 0.0345267, 0.0353038, 0.0360947, 0.0368288, 0.0376202,
0.0383784, 0.0391894, 0.0399684, 0.0408148, 0.0416403, 0.042545,
0.0433662, 0.0442498, 0.0451003, 0.0460350, 0.0468801, 0.0478059,
0.0487442, 0.0496647, 0.0505752, 0.0515123, 0.0524792, 0.0534474,
0.0544682, 0.0554579, 0.0565024, 0.0574619, 0.0584757, 0.0595123,
0.0605988, 0.0615874, 0.0627190, 0.0637876, 0.0648830, 0.0659551,
0.0670567, 0.0681256, 0.0692764, 0.0704584, 0.0715399, 0.0727237,
0.0738803, 0.0750377, 0.0762275, 0.0773855, 0.0785934, 0.0797802,
0.0810061, 0.0822205, 0.0834827, 0.0847140, 0.0858734, 0.0871999,
0.0884137, 0.0896948, 0.0909820, 0.0922797, 0.0936350, 0.0948243,
0.0961283, 0.0974718, 0.0988291, 0.1000970, 0.1014330, 0.102847,
0.104222, 0.105492, 0.106885, 0.108330, 0.109672, 0.111048, 0.112438,
0.113857, 0.115311, 0.116730, 0.118133, 0.119519, 0.120990, 0.122452,
0.123905, 0.125445, 0.126852, 0.128326, 0.129793, 0.131277, 0.132817,
0.134305, 0.135772, 0.137284, 0.138882, 0.140372, 0.141920, 0.143445,
0.144940, 0.146515, 0.148145, 0.149653, 0.151199, 0.152879, 0.154368,
0.155958, 0.157674, 0.159211, 0.160787, 0.162410, 0.164043, 0.165693,
0.167281, 0.168956, 0.170589, 0.172252, 0.173884, 0.175575, 0.177208,
0.178873, 0.180599, 0.182240, 0.183975, 0.185654, 0.187363, 0.189106,
0.190729, 0.192520, 0.194158, 0.195879, 0.197697, 0.199391, 0.201164,
0.202879, 0.204602, 0.206413, 0.208180, 0.209911, 0.211753, 0.213484,
0.215263, 0.217050, 0.218869, 0.220677, 0.222384, 0.224253, 0.226071,
0.227886, 0.229726, 0.231529, 0.233373, 0.235234, 0.237081, 0.238853,
0.240735, 0.242606, 0.244465, 0.246371, 0.248218, 0.250135, 0.251944,
0.253836, 0.255708, 0.257578, 0.259568, 0.261424, 0.263308, 0.265313,
0.267160, 0.269073, 0.271046, 0.272921, 0.274841, 0.276819, 0.278735,
0.280616, 0.282653, 0.284613, 0.286558, 0.288478, 0.290472, 0.292474,
0.294459, 0.296379, 0.298382, 0.300357, 0.302378, 0.304340, 0.306853
);
if ($x >= 1.0) {
return 1;
} elseif ($x >= 0.5) {
return 1 + log($x);
}
$i = floor($x * 1000);
if (!isset($savedF[$i]) || !isset($savedF[$i + 1])) {
return false;
}
return ($savedF[$i] + (($x * 1000.0) - $i) * ($savedF[$i + 1] - $savedF[$i]));
}
function FactorProbability($exponent, $B1, $B2, $HFF=false) {
if ($B1 < 30) {
return 0;
}
$B2 = max($B2, $B1);
if (!$HFF) {
$HFF = FactorBits($exponent);
}
$ProbabiltyThreshold = 0.001;
$LogK = log(1.5) + (($HFF - 1) * log(2)) - log($exponent);
$LogTemp = $LogK - log($B1 + $B2) + log(2);
$FactorProbability = 0;
$H = $HFF;
while (true) {
$Prob1 = DickmansFunction(log($B1) / $LogK);
$Aux = DickmansFunction(log($B2) / $LogTemp);
$Prob2 = $Prob1 + (DickmansFunction(log($B2) / $LogK) - $Prob1);
if ($Aux != 0) {
$Prob2 *= DickmansFunction(log($B1) / $LogTemp) / $Aux;
}
$H++;
$FactorProbability += $Prob2 / $H;
if ($Prob2 < $ProbabiltyThreshold) {
break;
}
$LogK += log(2);
$LogTemp += log(2);
}
$FudgeFactor = 1.16; // I don't know why, but my numbers are off by approx this much from Prime95
$FactorProbability *= $FudgeFactor;
return $FactorProbability;
}
function AdminErrorEmail($file, $line, $subject, $body) {
$body .= "\n\n".str_repeat('-', 40)."\n";
$body .= '$_REQUEST:'."\n".print_r($_REQUEST, true)."\n".str_repeat('-', 40)."\n";
$body .= '$_GET:' ."\n".print_r($_GET, true)."\n".str_repeat('-', 40)."\n";
$body .= '$_POST:' ."\n".print_r($_POST, true)."\n".str_repeat('-', 40)."\n";
$body .= '$_COOKIE:' ."\n".print_r($_COOKIE, true)."\n".str_repeat('-', 40)."\n";
$body .= '$_SERVER:' ."\n".print_r($_SERVER, true)."\n".str_repeat('-', 40)."\n";
$headers = '';
$headers .= 'From: mersenne-aries.sili.net <'.EMAIL_JAMES.'>'."\r\n";
$headers .= 'Reply-To: '.EMAIL_JAMES."\r\n";
return mail(EMAIL_JAMES, $subject, '==['.basename($file).'::'.$line."]==\n\n".$body, $headers);
}
function SafeSQLquery($SQLquery, $linenum='') {
$result = @mysql_query($SQLquery);
$error = mysql_error();
if ($error) {
if (@$_SERVER['HTTP_HOST'] == 'www.example.com') {
echo '<hr>'.$error.'<hr>';
} elseif (eregi('^Duplicate entry', $error)) {
// ignore
} else {
AdminErrorEmail(__FILE__, __LINE__, 'Mersenne-Aires SQL error', $error."\n\n".'On line '.$linenum."\n".'While processing query:'."\n".$SQLquery);
}
}
return $result;
}
function getUserCompID($usernamestring, $compidstring) {
static $UserCompIDlookup = array();
if (!isset($UserCompIDlookup[$usernamestring][$compidstring])) {
$SQLquery = 'SELECT `usercompid`';
$SQLquery .= ' FROM `usercomp`';
$SQLquery .= ' WHERE (`userid` = "'.mysql_escape_string($usernamestring).'")';
$SQLquery .= ' AND (`compid` = "'.mysql_escape_string($compidstring).'")';
$result = mysql_query($SQLquery);
if ($row = mysql_fetch_assoc($result)) {
$UserCompIDlookup[$usernamestring][$compidstring] = $row['usercompid'];
} else {
$SQLquery = 'INSERT INTO `usercomp` (`userid`, `compid`) VALUES (';
$SQLquery .= '"'.mysql_escape_string($usernamestring).'", ';
$SQLquery .= '"'.mysql_escape_string($compidstring).'")';
mysql_query($SQLquery);
$UserCompIDlookup[$usernamestring][$compidstring] = mysql_insert_id();
}
}
if (!$UserCompIDlookup[$usernamestring][$compidstring]) {
AdminErrorEmail(__FILE__, __LINE__, 'Mersenne-aries: failed to getUserCompID('.$usernamestring.', '.$compidstring.')', $SQLquery."\n\n".mysql_error());
echo 'An error has occurred, sorry. The site administrator has been notified and will fix it shortly.';
exit;
}
return $UserCompIDlookup[$usernamestring][$compidstring];
}
function getCompName($usercompid) {
static $CompNameLookup = array();
if (!isset($CompNameLookup[$usercompid])) {
$CompNameLookup[$usercompid] = '';
$SQLquery = 'SELECT `compid`';
$SQLquery .= ' FROM `usercomp`';
$SQLquery .= ' WHERE (`usercompid` = "'.mysql_escape_string($usercompid).'")';
$result = mysql_query($SQLquery);
if ($row = mysql_fetch_assoc($result)) {
$CompNameLookup[$usercompid] = $row['compid'];
}
}
return $CompNameLookup[$usercompid];
}
function EmailAttachment($from, $to, $subject, $textbody, &$attachmentdata, $attachmentfilename, $base64encode=true) {
$boundary = '_NextPart_'.time().'_'.md5($attachmentdata).'_';
$textheaders = '--'.$boundary."\n";
$textheaders .= 'Content-Type: text/plain; format=flowed; charset="iso-8859-1"'."\n";
$textheaders .= 'Content-Transfer-Encoding: 7bit'."\n\n";
$attachmentheaders = '--'.$boundary."\n";
if ($base64encode) {
$attachmentheaders .= 'Content-Type: application/octet-stream; name="'.$attachmentfilename.'"'."\n";
$attachmentheaders .= 'Content-Transfer-Encoding: base64'."\n";
} else {
$attachmentheaders .= 'Content-Type: text/plain; name="'.$attachmentfilename.'"'."\n";
$attachmentheaders .= 'Content-Transfer-Encoding: 7bit'."\n";
}
$attachmentheaders .= 'Content-Disposition: attachment; filename="'.$attachmentfilename.'"'."\n\n";
$headers[] = 'From: '.$from;
$headers[] = 'Content-Type: multipart/mixed; boundary="'.$boundary.'"';
return @mail($to, $subject, $textheaders.ereg_replace("[\x80-\xFF]", '?', $textbody)."\n\n".$attachmentheaders.($base64encode ? wordwrap(base64_encode($attachmentdata), 76, "\n", true) : $attachmentdata)."\n\n".'--'.$boundary."--\n\n", implode("\r\n", $headers));
}
function caseinsensitivesortsub($a, $b) {
$a = strtolower($a);
$b = strtolower($b);
if ($a == $b) {
return 0;
} elseif ($a > $b) {
return 1;
}
return -1;
}
function BarGraph($width, $height=10, $color='0033CC', $title='') {
return '<img src="index.php?px='.$color.'" height="'.max(1, round($height)).'" width="'.max(1, round($width)).'" border="0" title="'.htmlentities($title).'">';
}
function GetPct($numerator, $denominator) {
if ($denominator == 0) {
return 0;
}
return (($numerator / $denominator) * 100);
}
function NonZeroMin() {
$arg_list = func_get_args();
$NonZeroValues = array();
if ((func_num_args() == 1) && is_array($arg_list[0])) {
$values_to_check = $arg_list[0];
} else {
$values_to_check = $arg_list;
}
foreach ($values_to_check as $key => $value) {
if ($value) {
$NonZeroValues[] = $value;
}
}
if (count($NonZeroValues) == 0) {
return false;
}
return min($NonZeroValues);
}
function Range2bgcolor($value, $maxvalue, $emptyvalue=null) {
if ((strlen($value) == 0) && !is_null($emptyvalue)) {
return $emptyvalue;
}
$value = min(max(0, $value), $maxvalue);
$scale = round(($value / $maxvalue) * 255);
$r = str_pad(dechex( $scale), 2, '0', STR_PAD_LEFT);
$g = str_pad(dechex( 255 - $scale), 2, '0', STR_PAD_LEFT);
$b = str_pad(dechex(round(255 * (1 - abs((128 - $scale) / 128)))), 2, '0', STR_PAD_LEFT);
return $r.$g.$b;
}
function NiceTimeFormatting($seconds, $precision=1, $returnparts=false) {
$sign = (($seconds < 0) ? -1 : 1);
$seconds = abs($seconds);
do {
if ($seconds < 100) {
$value = number_format($seconds, 0);
$unit = 'second'.(($seconds > 1) ? 's' : '');
break;
}
$minutes = $seconds / 60;
if ($minutes < 60) {
$value = number_format($minutes, $precision);
$unit = 'minutes';
break;
}
$hours = $seconds / 3600;
if ($hours < 24) {
$value = number_format($hours, $precision);
$unit = 'hours';
break;
}
$days = $seconds / 86400;
if ($days < 60) {
$value = number_format($days, $precision);
$unit = 'days';
break;
}
$months = $seconds / (30 * 86400);
if ($months < 12) {
$value = number_format($months, $precision);
$unit = 'months';
break;
}
$years = $seconds / (365 * 86400);
if (true) {
$value = number_format($years, $precision);
$unit = 'years';
break;
}
} while (false);
$value *= $sign;
if ($returnparts) {
return array($value, $unit);
}
return $value.' '.$unit;
}
?>
cpucredit.inc.php:
<?php
//$MODULE_NAME_ = $app_name . '/' . $api_version . '_cpu_credit.inc.php';
//if ( $DEBUG_FLAG ) print "DEBUG: MODULE $MODULE_NAME_ ($function_module) reporting<br>";
function fft_lookup_table() {
static $fft_lookup_table = array();
if (empty($fft_lookup_table)) {
//$fft_lookup_table[FFTSIZE] = array(TIMING, MIN_EXPONENT, MAX_EXPONENT);
$fft_lookup_table[32] = array(8.7840E-7, 0, 743);
$fft_lookup_table[48] = array(1.1400E-6, 743, 1099);
$fft_lookup_table[64] = array(1.4088E-6, 1099, 1469);
$fft_lookup_table[80] = array(1.7592E-6, 1469, 1827);
$fft_lookup_table[96] = array(2.0520E-6, 1827, 2179);
$fft_lookup_table[112] = array(2.4624E-6, 2179, 2539);
$fft_lookup_table[128] = array(2.5272E-6, 2539, 2905);
$fft_lookup_table[160] = array(3.5640E-6, 2905, 3613);
$fft_lookup_table[192] = array(4.2936E-6, 3613, 4311);
$fft_lookup_table[224] = array(5.2512E-6, 4311, 5029);
$fft_lookup_table[256] = array(5.4744E-6, 5029, 5755);
$fft_lookup_table[320] = array(7.3440E-6, 5755, 7149);
$fft_lookup_table[384] = array(8.7840E-6, 7149, 8527);
$fft_lookup_table[448] = array(1.0536E-5, 8527, 9933);
$fft_lookup_table[512] = array(1.1328E-5, 9933, 11359);
$fft_lookup_table[640] = array(1.7040E-5, 11359, 14119);
$fft_lookup_table[768] = array(2.0592E-5, 14119, 16839);
$fft_lookup_table[896] = array(2.5416E-5, 16839, 19639);
$fft_lookup_table[1024] = array(2.7648E-5, 19639, 22477);
$fft_lookup_table[1280] = array(3.9120E-5, 22477, 27899);
$fft_lookup_table[1536] = array(4.7592E-5, 27899, 33289);
$fft_lookup_table[1792] = array(5.6880E-5, 33289, 38799);
$fft_lookup_table[2048] = array(6.1680E-5, 38799, 44339);
$fft_lookup_table[2560] = array(8.5200E-5, 44339, 55099);
$fft_lookup_table[3072] = array(1.0248E-4, 55099, 65729);
$fft_lookup_table[3584] = array(1.2648E-4, 65729, 76559);
$fft_lookup_table[4096] = array(1.2960E-4, 76559, 87549);
$fft_lookup_table[5120] = array(1.9200E-4, 87549, 108800);
$fft_lookup_table[6144] = array(2.2560E-4, 108800, 129900);
$fft_lookup_table[7168] = array(2.7600E-4, 129900, 151300);
$fft_lookup_table[8192] = array(2.8560E-4, 151300, 172700);
$fft_lookup_table[10240] = array(3.9840E-4, 172700, 214400);
$fft_lookup_table[12288] = array(4.8480E-4, 214400, 255300);
$fft_lookup_table[14336] = array(5.9040E-4, 255300, 297300);
$fft_lookup_table[16384] = array(6.1440E-4, 297300, 340400);
$fft_lookup_table[20480] = array(8.3760E-4, 340400, 423300);
$fft_lookup_table[24576] = array(1.0176E-3, 423300, 504600);
$fft_lookup_table[28672] = array(1.2600E-3, 504600, 587500);
$fft_lookup_table[32768] = array(1.3128E-3, 587500, 671400);
$fft_lookup_table[40960] = array(1.7256E-3, 671400, 835200);
$fft_lookup_table[49152] = array(2.0952E-3, 835200, 995500);
$fft_lookup_table[57344] = array(2.5608E-3, 995500, 1158000);
$fft_lookup_table[65536] = array(2.7384E-3, 1158000, 1325000);
$fft_lookup_table[81920] = array(3.8592E-3, 1325000, 1648000);
$fft_lookup_table[98304] = array(4.6872E-3, 1648000, 1966000);
$fft_lookup_table[114688] = array(5.6808E-3, 1966000, 2287000);
$fft_lookup_table[131072] = array(5.9928E-3, 2287000, 2614000);
$fft_lookup_table[163840] = array(7.3536E-3, 2614000, 3251000);
$fft_lookup_table[196608] = array(9.0744E-3, 3251000, 3875000);
$fft_lookup_table[229376] = array(1.0776E-2, 3875000, 4512000);
$fft_lookup_table[262144] = array(1.1976E-2, 4512000, 5158000);
$fft_lookup_table[327680] = array(1.5312E-2, 5158000, 6421000);
$fft_lookup_table[393216] = array(1.8840E-2, 6421000, 7651000);
$fft_lookup_table[458752] = array(2.2560E-2, 7651000, 8908000);
$fft_lookup_table[524288] = array(2.5200E-2, 8908000, 10180000);
$fft_lookup_table[655360] = array(3.3264E-2, 10180000, 12650000);
$fft_lookup_table[786432] = array(4.1376E-2, 12650000, 15070000);
$fft_lookup_table[917504] = array(4.9200E-2, 15070000, 17550000);
$fft_lookup_table[1048576] = array(5.5920E-2, 17550000, 20050000);
$fft_lookup_table[1310720] = array(7.0080E-2, 20050000, 24930000);
$fft_lookup_table[1572864] = array(8.5920E-2, 24930000, 29690000);
$fft_lookup_table[1835008] = array(1.0224E-1, 29690000, 34560000);
$fft_lookup_table[2097152] = array(1.1376E-1, 34560000, 39500000);
$fft_lookup_table[2621440] = array(1.5000E-1, 39500000, 49100000);
$fft_lookup_table[3145728] = array(1.8312E-1, 49100000, 58520000);
$fft_lookup_table[3670016] = array(2.1840E-1, 58520000, 68130000);
$fft_lookup_table[4194304] = array(2.4360E-1, 68130000, 77910000);
$fft_lookup_table[5242880] = array(3.1296E-1, 77910000, 96830000);
$fft_lookup_table[6291456] = array(3.7920E-1, 96830000, 115300000);
$fft_lookup_table[7340032] = array(4.5840E-1, 115300000, 134200000);
$fft_lookup_table[8388608] = array(5.0400E-1, 134200000, 153400000);
$fft_lookup_table[10485760] = array(6.7200E-1, 153400000, 190700000);
$fft_lookup_table[12582912] = array(8.1120E-1, 190700000, 227300000);
$fft_lookup_table[14680064] = array(9.8400E-1, 227300000, 264600000);
$fft_lookup_table[16777216] = array(1.0800E-0, 264600000, 302600000);
$fft_lookup_table[20971520] = array(1.4904E-0, 302600000, 376100000);
$fft_lookup_table[25165824] = array(1.8216E-0, 376100000, 448000000);
$fft_lookup_table[29360128] = array(2.1792E-0, 448000000, 521500000);
$fft_lookup_table[33554432] = array(2.3832E-0, 521500000, 596000000);
}
return $fft_lookup_table;
}
function fft_timings_lookup($exponent=0, $fftlen=0) {
static $fft_lookup_table = array();
if (empty($fft_lookup_table)) {
$fft_lookup_table = fft_lookup_table();
}
if (($fftlen > 0) && isset($fft_lookup_table[$fftlen])) {
return $fft_lookup_table[$fftlen][0];
}
if ($exponent) {
foreach ($fft_lookup_table as $fftLength => $dataarray) {
if (($exponent >= $dataarray[1]) && ($exponent <= $dataarray[2])) {
if ($fftlen == -1) {
return $fftLength;
} else {
return $dataarray[0];
}
}
}
}
return null;
}
// CPU credit - background information:
//
// In Primenet v4 we used a 90 MHz Pentium CPU as the benchmark machine
// for calculating CPU credit. The official unit of measure became the
// P-90 CPU year. In 2007, not many people own a plain Pentium CPU, so we
// adopted a new benchmark machine - a single core of a 2.4 GHz Core 2 Duo.
// Our official unit of measure became the C2GHD (Core 2 GHz Day). That is,
// the amount of work produced by the single core of a hypothetical
// 1 GHz Core 2 Duo machine. A 2.4 GHz should be able to produce 4.8 C2GHD
// per day.
//
// To compare P-90 CPU years to C2GHDs, we need to factor in both the
// the raw speed improvements of modern chips and the architectural
// improvements of modern chips. Examining prime95 version 24.14 benchmarks
// for 640K to 2048K FFTs from a P100, PII-400, P4-2000, and a C2D-2400
// and compensating for speed differences, we get the following architectural
// multipliers:
//
// One core of a C2D = 1.68 P4.
// A P4 = 3.44 PIIs
// A PII = 1.12 Pentium
//
// Thus, a P-90 CPU year = 365 days * 1 C2GHD *
// (90MHz / 1000MHz) / 1.68 / 3.44 / 1.12
// = 5.075 C2GHDs
// v4 conversion
function credit_v4_C2D_CPU_GhzDays( $v4_P90_years )
{
// A P-90 CPU year = 5.075 C2D_GHzDays
return ( 5.075 * $v4_P90_years );
}
/* Return the timing (in seconds) for a single core of a hypothetical
1GHz Core 2 Duo to perform one LL iteration (a single squaring).
We need to look up timing in two ways.
1) Given an fftlen - return the timing.
2) Given an exponent, finds the likely fftlen
using min_exp and max_exp and return the timing.
We need two lookups because users that manually
reported results will not know the fftlen.
Prime95 should always pass in the fft length.
*/
function credit_get_FFT_timing( $exponent, $fftlen )
{
// $exponent is REQUIRED, $fftlen is PREFERRED
// returns NULL or float of timing found
return fft_timings_lookup($exponent, $fftlen);
// // try FFT length first
// if ( $fftlen ) {
// $t_timing = sql_select_rows_array_where('t_gimps_credit_timings', "fftlen = $fftlen" );
// }
// // else match by exponent range
// if ( !$t_timing )
// $t_timing = sql_select_rows_array_where(
// 't_gimps_credit_timings',
// "$exponent >= min_exponent and $exponent <= max_exponent" );
// return $t_timing[timing];
}
// An LL test (prime or composite)
// timing / 86400 * exponent
function credit_cpu_LL( $exponent, $fftlen )
{
$timing = credit_get_FFT_timing( $exponent, $fftlen );
return ( $timing * $exponent / 86400.0 );
}
// ECM (whether factor found or not)
// timing / 86400 * curves * (13.0 * B1 + 0.06 * B2)
// Note: the user gets a slight cpu bonus when factor found in stage 1
function credit_cpu_ECM( $exponent, $fftlen, $curves_run, $B1, $B2 )
{
$timing = credit_get_FFT_timing( $exponent, $fftlen );
return ( $timing * $curves_run * ( 13.0 * $B1 + 0.06 * $B2) / 86400.0 );
}
// P-1 - no factor
// timing / 86400 * (1.5 * B1 + 0.05 * B2)
// P-1 - factor found in stage 2
// timing / 86400 * (1.5 * B1 + 0.05 * B2)
// P-1 - factor found in stage 1, B2 = 0
// timing / 86400 * (1.5 * B1)
function credit_cpu_PM1_factoring( $exponent, $fftlen, $B1, $B2 )
{
$timing = credit_get_FFT_timing( $exponent, $fftlen );
// revised formula posted by George 26-Jan-2009:
// http://mersenneforum.org/showthread.php?t=11411
// > P-1 was being under-credited. The new formula is:
// > GHz_days = timing * ( 1.45 * B1 + 0.079 * (B2 - B1) ) / 86400.0
// DEPRECATED (as of 26-Jan-2009): return ( $timing * ( 1.5 * $B1 + 0.05 * $B2) / 86400.0 );
if ($B1 >= $B2) {
return ( $timing * ( 1.45 * $B1 ) / 86400.0 );
} else {
return ( $timing * ( 1.45 * $B1 + 0.079 * ($B2 - $B1) ) / 86400.0 );
}
}
// Trial factoring needs a different timing table
// (or else hardwire the timings in PHP code):
//bits tf_timing
//---- ---------
//<=62 0.00465
//63-64 0.00743
//>=65 0.00707
function credit_get_TF_timing( $bits )
{
// will later move to table maybe so we don't maintain in code
if ( $bits <= 62 ) return (2.4*0.00465);
elseif ( $bits == 63 || $bits == 64 ) return (2.4*0.00743);
elseif ( $bits >= 65 ) return (2.4*0.00707);
}
// Trial factoring - no factor found:
function credit_cpu_TF_no_factor( $exponent, $sf, $ef )
{
// modifications by james@jamesheinrich.com 2008-12-13
$est = 0.0;
if ($exponent && $ef) {
for ( $i = $sf+1; $i <= $ef; $i++ ) {
//if ($i < 48) continue; // marginally faster calculations if this is present, but will return zero for small factors <2^48 factoring, instead of <smallvalue>
$tf_timing = credit_get_TF_timing( $i );
//$est += $tf_timing * (1 << ($i - 48)) * 1680.0 / $exponent; // broken above $i=78 due to 32bit-signed integers
$est += $tf_timing * pow(2, ($i - 48)) * 1680.0 / $exponent;
}
}
return $est;
}
function credit_factor_mod_120( $factor )
{
// $factor must be a string of decimal digits
// Chinese Remainder Theorem mod 120:
// m = 3, n = 40, u = -13, v = 1
// a = factor mod 3, b = factor mod 40
// m120 = factor mod 120
$a = 0;
$L = strlen($factor);
for ( $i = 0; $i < $L; $i++ ) {
$d = ord($factor{$i}) - ord('0');
if ( $d < 0 || $d > 9 ) return -1; // digit check
$a += $d;
}
$a %= 3; // sum of digits, mod 3
$b = substr($factor,$L-3,3) % 40; // right 3 digits, mod 40
$m120 = 40*$a - 39*$b; // mod 120
while ( $m120 < 0 ) $m120 += 120;
return ( $m120 );
}
// approximate log2( decimal digits string )
function credit_log2_factor( $factor )
{
// $factor must be a string of decimal digits
$L = strlen($factor);
if ($L > 6) {
$msd = substr($factor, 0, 6);
$i = log($msd, 2) + 3.322 * ($L - 6);
} else {
$i = log($factor, 2);
}
return $i;
}
//// get sf value from t_gimps_factoring_effort table
//function credit_get_sf_from_exponent( $exponent )
//{
// $t_fe = sql_select_rows_array_where( 't_gimps_factoring_effort', "exponent = $exponent" );
// return ( $t_fe[no_factor_to_bits] );
//}
// Trial factoring - factor found by prime95
// pass = lookup (factor mod 120) in
// {1,7,17,23,31,41,47,49,71,73,79,89,97,103,113,119}
// (pass is now integer between 0 and 15)
// i = log2 (factor)
// ef = sf+1;
// assume we did (pass + (i - sf)) / 16 * credit-for-tfing-from-sf-to-ef.
function credit_cpu_TF_factor_p95( $exponent, $factor, $sf )
{
$fact_mod_120 = credit_factor_mod_120($factor);
$passes = array(1, 7, 17, 23, 31, 41, 47, 49, 71, 73, 79, 89, 97, 103, 113, 119);
for ($pass = 0; $pass < count($passes); $pass++) {
if ($passes[$pass] == $fact_mod_120) {
break;
}
}
if ($pass == count($passes)) {
return 0.0;
}
$i = credit_log2_factor($factor);
$floor_i = floor($i);
$ef = $floor_i + 1;
return ( credit_cpu_TF_no_factor( $exponent, $sf, $floor_i ) + ($pass + ($i - $floor_i)) / 16.0 * credit_cpu_TF_no_factor( $exponent, $floor_i, $ef ) );
}
// Trial factoring - factor found by other client
// Caller must get $sf from t_gimps_factoring_effort prior to calling the
// record_common_factor_routine. This is because recording the factor will
// delete the t_gimps_factoring_effort row.
// i = log2 (factor)
// sf = trunc (i);
// ef = sf+1;
// assume we did (i - sf) * credit-for-tfing-from-sf-to-ef.
function credit_cpu_TF_factor_other( $exponent, $factor, $sf )
{
$i = credit_log2_factor( $factor );
$floor_i = floor( $i );
$ef = $floor_i + 1;
return ( credit_cpu_TF_no_factor( $exponent, $sf, $floor_i ) +
($i - $floor_i) * credit_cpu_TF_no_factor( $exponent, $floor_i, $ef ) );
}
?>