BOINC /
boinc
| 1 | <?php |
||
| 2 | // This file is part of BOINC. |
||
| 3 | // http://boinc.berkeley.edu |
||
| 4 | // Copyright (C) 2008 University of California |
||
| 5 | // |
||
| 6 | // BOINC is free software; you can redistribute it and/or modify it |
||
| 7 | // under the terms of the GNU Lesser General Public License |
||
| 8 | // as published by the Free Software Foundation, |
||
| 9 | // either version 3 of the License, or (at your option) any later version. |
||
| 10 | // |
||
| 11 | // BOINC is distributed in the hope that it will be useful, |
||
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 14 | // See the GNU Lesser General Public License for more details. |
||
| 15 | // |
||
| 16 | // You should have received a copy of the GNU Lesser General Public License |
||
| 17 | // along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
||
| 18 | |||
| 19 | // Use this script to find an optimal value for fp_benchmark_weight, |
||
| 20 | // i.e. the weight which minimizes the variation between |
||
| 21 | // claimed credit and granted credit |
||
| 22 | // over the validated WUs currently in the database. |
||
| 23 | // |
||
| 24 | // Evaluates the variation for weights 0, .1, ... 1. |
||
| 25 | // |
||
| 26 | |||
| 27 | $cli_only = true; |
||
| 28 | require_once("../inc/util_ops.inc"); |
||
| 29 | |||
| 30 | db_init(); |
||
| 31 | |||
| 32 | function mean($x) { |
||
| 33 | $sum = 0; |
||
| 34 | $n = count($x); |
||
| 35 | for ($i=0; $i<$n; $i++) { |
||
| 36 | $sum += $x[$i]; |
||
| 37 | } |
||
| 38 | return $sum/$n; |
||
| 39 | } |
||
| 40 | |||
| 41 | function normalized_variance($x) { |
||
| 42 | $sum = 0; |
||
| 43 | $n = count($x); |
||
| 44 | $m = mean($x); |
||
| 45 | for ($i=0; $i<$n; $i++) { |
||
| 46 | $d = $x[$i] - $m; |
||
| 47 | $sum += $d*$d; |
||
| 48 | //echo "$x[$i] "; |
||
| 49 | } |
||
| 50 | //echo "\n"; |
||
| 51 | $nv = sqrt($sum)/($n*$m); |
||
| 52 | //echo "nresults $n mean $m sum $sum nv $nv\n"; |
||
| 53 | return $nv; |
||
| 54 | } |
||
| 55 | |||
| 56 | // returns the claimed credit for a given result/host and FP weight |
||
| 57 | // |
||
| 58 | function cc($x, $fpw) { |
||
| 59 | $cps = $x->p_fpops*$fpw + $x->p_iops*(1-$fpw); |
||
| 60 | $cps /= 1e9; |
||
| 61 | $cps /= 864; |
||
| 62 | $cc = $x->cpu_time * $cps; |
||
| 63 | return $cc; |
||
| 64 | } |
||
| 65 | |||
| 66 | // $x is an array of result/host objects; |
||
| 67 | // return the variance among claimed credits given an FP weight |
||
| 68 | // |
||
| 69 | function fpw_var($results, $fpw) { |
||
| 70 | $cc = array(); |
||
| 71 | foreach ($results as $r) { |
||
| 72 | $cc[] = cc($r, $fpw); |
||
| 73 | } |
||
| 74 | return normalized_variance($cc); |
||
| 75 | } |
||
| 76 | |||
| 77 | // scan WUs for which credit has been granted, |
||
| 78 | // and for which there at least 2 valid results. |
||
| 79 | // For each of these, compute the variance among claimed credits |
||
| 80 | // given various FP weights (0, .1, ... 1). |
||
| 81 | // Maintain the sum of these in an array |
||
| 82 | // |
||
| 83 | function get_data() { |
||
| 84 | $nwus = 4000; |
||
| 85 | |||
| 86 | $sum = array(); |
||
| 87 | for ($i=0; $i<=10; $i++) { |
||
| 88 | $sum[] = 0; |
||
| 89 | } |
||
| 90 | $r1 = _mysql_query( |
||
| 91 | "select id from workunit where canonical_resultid>0 limit $nwus" |
||
| 92 | ); |
||
| 93 | $n = 0; |
||
| 94 | while ($wu = _mysql_fetch_object($r1)) { |
||
| 95 | $results = array(); |
||
| 96 | $r2 = _mysql_query("select * from result where workunitid=$wu->id"); |
||
| 97 | $found_zero = false; |
||
| 98 | while ($result = _mysql_fetch_object($r2)) { |
||
| 99 | if ($result->granted_credit==0) continue; // skip invalid |
||
| 100 | $host = BoincHost::lookup_id($result->hostid); |
||
| 101 | $r = new StdClass; |
||
| 102 | $r->cpu_time = $result->cpu_time; |
||
| 103 | $r->p_fpops = $host->p_fpops; |
||
| 104 | $r->p_iops = $host->p_iops; |
||
| 105 | $results[] = $r; |
||
| 106 | } |
||
| 107 | //echo "Wu $wu->id -------------\n"; |
||
| 108 | if (count($results)<2) continue; |
||
| 109 | for ($i=0; $i<=10; $i++) { |
||
| 110 | $fpw = $i/10.; |
||
| 111 | $sum[$i] += fpw_var($results, $fpw); |
||
| 112 | } |
||
| 113 | $n++; |
||
| 114 | } |
||
| 115 | echo "This script recommends value for <fp_benchmark_weight> in config.xml. |
||
| 116 | It does this by finding the value that minimizes the variance |
||
| 117 | among claimed credit for workunits currently in your database. |
||
| 118 | It examines at most $nwus WUs (edit the script to change this). |
||
| 119 | |||
| 120 | Number of workunits analyzed: $n |
||
| 121 | |||
| 122 | "; |
||
| 123 | for ($i=0; $i<=10; $i++) { |
||
| 124 | $fpw = $i/10.; |
||
| 125 | $r = $sum[$i]/$n; |
||
| 126 | echo "FP weight $fpw: variance is $r\n"; |
||
| 127 | if ($i == 0) { |
||
| 128 | $best = $r; |
||
| 129 | $fbest = $fpw; |
||
| 130 | } else { |
||
| 131 | if ($r < $best) { |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
| 132 | $best = $r; |
||
| 133 | $fbest = $fpw; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | echo " |
||
| 139 | Recommended value: $fbest |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 140 | "; |
||
| 141 | } |
||
| 142 | |||
| 143 | get_data(); |
||
| 144 | |||
| 145 | ?> |
||
| 146 |