2005-11-01 04:13:22 +00:00
|
|
|
<?php
|
2008-08-05 22:43:14 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2005-11-01 04:13:22 +00:00
|
|
|
|
2008-01-09 20:12:13 +00:00
|
|
|
// 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.
|
|
|
|
//
|
2005-11-01 04:13:22 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-01-09 20:12:13 +00:00
|
|
|
function normalized_variance($x) {
|
2005-11-01 04:13:22 +00:00
|
|
|
$sum = 0;
|
|
|
|
$n = count($x);
|
|
|
|
$m = mean($x);
|
|
|
|
for ($i=0; $i<$n; $i++) {
|
|
|
|
$d = $x[$i] - $m;
|
|
|
|
$sum += $d*$d;
|
2008-01-09 20:29:09 +00:00
|
|
|
//echo "$x[$i] ";
|
2005-11-01 04:13:22 +00:00
|
|
|
}
|
2008-01-09 20:29:09 +00:00
|
|
|
//echo "\n";
|
|
|
|
$nv = sqrt($sum)/($n*$m);
|
|
|
|
//echo "nresults $n mean $m sum $sum nv $nv\n";
|
|
|
|
return $nv;
|
2005-11-01 04:13:22 +00:00
|
|
|
}
|
|
|
|
|
2008-01-09 20:12:13 +00:00
|
|
|
// returns the claimed credit for a given result/host and FP weight
|
|
|
|
//
|
2005-11-01 04:13:22 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-01-09 20:12:13 +00:00
|
|
|
// $x is an array of result/host objects;
|
|
|
|
// return the variance among claimed credits given an FP weight
|
2005-11-01 04:13:22 +00:00
|
|
|
//
|
2008-01-09 20:12:13 +00:00
|
|
|
function fpw_var($results, $fpw) {
|
2005-11-01 04:13:22 +00:00
|
|
|
$cc = array();
|
2008-01-09 20:12:13 +00:00
|
|
|
foreach ($results as $r) {
|
|
|
|
$cc[] = cc($r, $fpw);
|
2005-11-01 04:13:22 +00:00
|
|
|
}
|
2008-01-09 20:12:13 +00:00
|
|
|
return normalized_variance($cc);
|
2005-11-01 04:13:22 +00:00
|
|
|
}
|
|
|
|
|
2008-01-09 20:12:13 +00:00
|
|
|
// 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
|
|
|
|
//
|
2005-11-01 04:13:22 +00:00
|
|
|
function get_data() {
|
2008-01-09 20:29:09 +00:00
|
|
|
$nwus = 4000;
|
|
|
|
|
2005-11-01 04:13:22 +00:00
|
|
|
$sum = array();
|
2008-01-09 20:12:13 +00:00
|
|
|
for ($i=0; $i<=10; $i++) {
|
2008-01-09 20:29:09 +00:00
|
|
|
$sum[] = 0;
|
2005-11-01 04:13:22 +00:00
|
|
|
}
|
|
|
|
$r1 = mysql_query(
|
2008-01-09 20:29:09 +00:00
|
|
|
"select id from workunit where canonical_resultid>0 limit $nwus"
|
2005-11-01 04:13:22 +00:00
|
|
|
);
|
|
|
|
$n = 0;
|
|
|
|
while ($wu = mysql_fetch_object($r1)) {
|
2008-01-09 20:12:13 +00:00
|
|
|
$results = array();
|
2005-11-01 04:13:22 +00:00
|
|
|
$r2 = mysql_query("select * from result where workunitid=$wu->id");
|
|
|
|
$found_zero = false;
|
|
|
|
while ($result = mysql_fetch_object($r2)) {
|
2008-01-09 20:12:13 +00:00
|
|
|
if ($result->granted_credit==0) continue; // skip invalid
|
2005-11-01 04:13:22 +00:00
|
|
|
$host = lookup_host($result->hostid);
|
2008-01-09 20:12:13 +00:00
|
|
|
$r = null;
|
|
|
|
$r->cpu_time = $result->cpu_time;
|
|
|
|
$r->p_fpops = $host->p_fpops;
|
|
|
|
$r->p_iops = $host->p_iops;
|
|
|
|
$results[] = $r;
|
2005-11-01 04:13:22 +00:00
|
|
|
}
|
2008-01-09 20:29:09 +00:00
|
|
|
//echo "Wu $wu->id -------------\n";
|
2008-01-09 20:12:13 +00:00
|
|
|
if (count($results)<2) continue;
|
|
|
|
for ($i=0; $i<=10; $i++) {
|
|
|
|
$fpw = $i/10.;
|
|
|
|
$sum[$i] += fpw_var($results, $fpw);
|
2005-11-01 04:13:22 +00:00
|
|
|
}
|
|
|
|
$n++;
|
|
|
|
}
|
2008-01-09 20:12:13 +00:00
|
|
|
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.
|
2008-01-09 20:29:09 +00:00
|
|
|
It examines at most $nwus WUs (edit the script to change this).
|
2008-01-09 20:12:13 +00:00
|
|
|
|
|
|
|
Number of workunits analyzed: $n
|
|
|
|
|
|
|
|
";
|
|
|
|
for ($i=0; $i<=10; $i++) {
|
|
|
|
$fpw = $i/10.;
|
2005-11-01 04:13:22 +00:00
|
|
|
$r = $sum[$i]/$n;
|
2008-01-09 20:12:13 +00:00
|
|
|
echo "FP weight $fpw: variance is $r\n";
|
|
|
|
if ($i == 0) {
|
|
|
|
$best = $r;
|
|
|
|
$fbest = $fpw;
|
|
|
|
} else {
|
|
|
|
if ($r < $best) {
|
|
|
|
$best = $r;
|
|
|
|
$fbest = $fpw;
|
|
|
|
}
|
|
|
|
}
|
2005-11-01 04:13:22 +00:00
|
|
|
}
|
|
|
|
|
2008-01-09 20:12:13 +00:00
|
|
|
echo "
|
|
|
|
Recommended value: $fbest
|
|
|
|
";
|
|
|
|
}
|
2005-11-01 04:13:22 +00:00
|
|
|
|
|
|
|
get_data();
|
|
|
|
|
|
|
|
?>
|