mirror of https://github.com/BOINC/boinc.git
129 lines
3.2 KiB
PHP
129 lines
3.2 KiB
PHP
<?php
|
|
|
|
// Use this script to find an optimal value for fp_benchmark_weight,
|
|
// i.e. the weight which minimizes the variation between
|
|
// claimed credit and granted credit
|
|
// over the validated WUs currently in the database.
|
|
//
|
|
// Evaluates the variation for weights 0, .1, ... 1.
|
|
//
|
|
|
|
require_once("../inc/db.inc");
|
|
|
|
db_init();
|
|
|
|
function mean($x) {
|
|
$sum = 0;
|
|
$n = count($x);
|
|
for ($i=0; $i<$n; $i++) {
|
|
$sum += $x[$i];
|
|
}
|
|
return $sum/$n;
|
|
}
|
|
|
|
function normalized_variance($x) {
|
|
$sum = 0;
|
|
$n = count($x);
|
|
$m = mean($x);
|
|
for ($i=0; $i<$n; $i++) {
|
|
$d = $x[$i] - $m;
|
|
$sum += $d*$d;
|
|
//echo "$x[$i] ";
|
|
}
|
|
//echo "\n";
|
|
$nv = sqrt($sum)/($n*$m);
|
|
//echo "nresults $n mean $m sum $sum nv $nv\n";
|
|
return $nv;
|
|
}
|
|
|
|
// returns the claimed credit for a given result/host and FP weight
|
|
//
|
|
function cc($x, $fpw) {
|
|
$cps = $x->p_fpops*$fpw + $x->p_iops*(1-$fpw);
|
|
$cps /= 1e9;
|
|
$cps /= 864;
|
|
$cc = $x->cpu_time * $cps;
|
|
return $cc;
|
|
}
|
|
|
|
// $x is an array of result/host objects;
|
|
// return the variance among claimed credits given an FP weight
|
|
//
|
|
function fpw_var($results, $fpw) {
|
|
$cc = array();
|
|
foreach ($results as $r) {
|
|
$cc[] = cc($r, $fpw);
|
|
}
|
|
return normalized_variance($cc);
|
|
}
|
|
|
|
// scan WUs for which credit has been granted,
|
|
// and for which there at least 2 valid results.
|
|
// For each of these, compute the variance among claimed credits
|
|
// given various FP weights (0, .1, ... 1).
|
|
// Maintain the sum of these in an array
|
|
//
|
|
function get_data() {
|
|
$nwus = 4000;
|
|
|
|
$sum = array();
|
|
for ($i=0; $i<=10; $i++) {
|
|
$sum[] = 0;
|
|
}
|
|
$r1 = mysql_query(
|
|
"select id from workunit where canonical_resultid>0 limit $nwus"
|
|
);
|
|
$n = 0;
|
|
while ($wu = mysql_fetch_object($r1)) {
|
|
$results = array();
|
|
$r2 = mysql_query("select * from result where workunitid=$wu->id");
|
|
$found_zero = false;
|
|
while ($result = mysql_fetch_object($r2)) {
|
|
if ($result->granted_credit==0) continue; // skip invalid
|
|
$host = lookup_host($result->hostid);
|
|
$r = null;
|
|
$r->cpu_time = $result->cpu_time;
|
|
$r->p_fpops = $host->p_fpops;
|
|
$r->p_iops = $host->p_iops;
|
|
$results[] = $r;
|
|
}
|
|
//echo "Wu $wu->id -------------\n";
|
|
if (count($results)<2) continue;
|
|
for ($i=0; $i<=10; $i++) {
|
|
$fpw = $i/10.;
|
|
$sum[$i] += fpw_var($results, $fpw);
|
|
}
|
|
$n++;
|
|
}
|
|
echo "This script recommends value for <fp_benchmark_weight> in config.xml.
|
|
It does this by finding the value that minimizes the variance
|
|
among claimed credit for workunits currently in your database.
|
|
It examines at most $nwus WUs (edit the script to change this).
|
|
|
|
Number of workunits analyzed: $n
|
|
|
|
";
|
|
for ($i=0; $i<=10; $i++) {
|
|
$fpw = $i/10.;
|
|
$r = $sum[$i]/$n;
|
|
echo "FP weight $fpw: variance is $r\n";
|
|
if ($i == 0) {
|
|
$best = $r;
|
|
$fbest = $fpw;
|
|
} else {
|
|
if ($r < $best) {
|
|
$best = $r;
|
|
$fbest = $fpw;
|
|
}
|
|
}
|
|
}
|
|
|
|
echo "
|
|
Recommended value: $fbest
|
|
";
|
|
}
|
|
|
|
get_data();
|
|
|
|
?>
|