File: credit_study.php

package info (click to toggle)
boinc 5.4.11-4%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 21,440 kB
  • ctags: 16,986
  • sloc: cpp: 70,682; ansic: 45,747; php: 35,513; xml: 10,487; sh: 9,324; python: 4,291; makefile: 1,958; asm: 1,258; perl: 914; sql: 395; csh: 126; pascal: 124
file content (109 lines) | stat: -rw-r--r-- 2,611 bytes parent folder | download | duplicates (2)
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
<?php

// Use this script to find an optimal value for fp_benchmark_weight.
// This 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 spread($x) {
    $sum = 0;
    $n = count($x);
    $m = mean($x);
    for ($i=0; $i<$n; $i++) {
        $d = $x[$i] - $m;
        $sum += $d*$d;
    }
    return sqrt($sum)/$n;
}

function cc($x, $fpw) {
    $cps = $x->p_fpops*$fpw + $x->p_iops*(1-$fpw);
    $cps /= 1e9;
    $cps /= 864;
    $cc = $x->cpu_time * $cps;
    //if ($x->duration_correction_factor) {
    //    $cc /= $x->duration_correction_factor;
    //}
    return $cc;
}

// $x is a vector of objects
//
function handle_wu($x) {
    $cc = array();
    for ($i=0; $i<=12; $i++) {
        array_push($cc, array());
    }
    for ($j=0; $j<count($x); $j++) {
        $y = $x[$j];
        for ($i=0; $i<=12; $i++) {
            $r = $i/10.;
            array_push($cc[$i], cc($y, $r));
        }
    }
    $res = array();
    for ($i=0; $i<=12; $i++) {
        $c = $cc[$i];
        $m = mean($c);
        $s = spread($c);
        $rs = $s/$m;
        array_push($res, $rs);
    }
    return $res;
}

function get_data() {
    $sum = array();
    for ($i=0; $i<=12; $i++) {
        array_push($sum, 0);
    }
    $r1 = mysql_query(
        "select id from workunit where canonical_resultid>0 limit 10000"
    );
    $n = 0;
    while ($wu = mysql_fetch_object($r1)) {
        $x = 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;
            if ($result->claimed_credit==0) $found_zero = true;
            $host = lookup_host($result->hostid);
            $y->claimed_credit = $result->claimed_credit;
            $y->granted_credit = $result->granted_credit;
            $y->cpu_time = $result->cpu_time;
            $y->p_fpops = $host->p_fpops;
            $y->p_iops = $host->p_iops;
            $y->duration_correction_factor = $host->duration_correction_factor;
            $y->id = $result->id;
            array_push($x, $y);
        }
        if (count($x)==0) continue;
        if ($found_zero) continue;
        $res = handle_wu($x);
        for ($i=0; $i<=12; $i++) {
            $sum[$i] += $res[$i];
        }
        $n++;
    }
    for ($i=0; $i<=12; $i++) {
        $r = $sum[$i]/$n;
        echo "$i $r\n";
    }
}


get_data();

?>