1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
<?php
// 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/>.
// 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.
//
$cli_only = true;
require_once("../inc/util_ops.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 = BoincHost::lookup_id($result->hostid);
$r = new StdClass;
$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();
?>
|