]> git.sesse.net Git - freerainbowtables/blob - BOINC software/BOINC server apps/distrrtgen_validator/part_validator.cpp
initial
[freerainbowtables] / BOINC software / BOINC server apps / distrrtgen_validator / part_validator.cpp
1 // This file is part of BOINC.
2 // http://boinc.berkeley.edu
3 // Copyright (C) 2008 University of California
4 //
5 // BOINC is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Lesser General Public License
7 // as published by the Free Software Foundation,
8 // either version 3 of the License, or (at your option) any later version.
9 //
10 // BOINC is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 // See the GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
17
18 // A sample validator that grants credit if the majority of results are
19 // bitwise identical.
20 // This is useful only if either
21 // 1) your application does no floating-point math, or
22 // 2) you use homogeneous redundancy
23
24
25 #include "config.h"
26 #include "util.h"
27 #include "sched_util.h"
28 #include "sched_msgs.h"
29 #include "validate_util.h"
30 #include "ChainWalkContext.h"
31 #include "MemoryPool.h"
32 #include "filesys.h"
33 #include "error_numbers.h"
34 #include "part_validator.h"
35 using std::string;
36 using std::vector;
37
38
39 int read_file_binary(const char *path, RainbowPartFile *data, int &isize)
40 {
41     int retval;
42     double size;
43
44     retval = file_size(path, size);
45     if (retval) return retval;
46     FILE *f = fopen(path, "rb");
47     if (!f) return ERR_FOPEN;
48     isize = (int) size;
49         log_messages.printf(MSG_DEBUG,
50                     "malloc %i bytes. size: %i\n",
51                     (isize / 18 * sizeof(RainbowPartFile)), sizeof(RainbowPartFile)
52                 );           
53     data->pChain = (RainbowChainCP*)malloc(isize / 18 * sizeof(RainbowChainCP));
54     data->numchains = isize / 18;
55     for(int i = 0; i < data->numchains; i++)
56     {   
57         size_t n = fread(&data->pChain[i].nIndexS, 1, 8, f);
58         n = fread(&data->pChain[i].nIndexE, 1, 8, f);
59         n = fread(&data->pChain[i].nCheckPoint, 1, 2, f);
60     }
61     fclose(f);
62     return 0;   
63 }
64 int init_result(RESULT& result, void*& data) {
65     int retval;
66     vector<FILE_INFO> files;
67
68     retval = get_output_file_infos(result, files);
69     if (retval) {
70         log_messages.printf(MSG_CRITICAL,
71             "[RESULT#%d %s] check_set: can't get output filenames\n",
72             result.id, result.name
73         );
74         return retval;
75     }
76
77     RainbowPartFile *filedata = new RainbowPartFile();
78     int filelen;
79     for (unsigned int i=0; i<files.size(); i++) {
80         FILE_INFO& fi = files[i];
81         if (fi.no_validate) continue;
82         retval = read_file_binary(fi.path.c_str(), filedata, filelen);
83         if (retval) {
84             if (fi.optional) {
85                 filedata = NULL;
86             } else {
87                 log_messages.printf(MSG_CRITICAL,
88                     "[RESULT#%d %s] Couldn't open %s\n",
89                     result.id, result.name, fi.path.c_str()
90                 );
91                 return retval;
92             }
93              
94         }
95         log_messages.printf(MSG_DEBUG,
96                     "[RESULT#%d %s] Size of file %s is %u\n",
97                     result.id, result.name, fi.path.c_str(), filelen
98                 );           
99         data = (void*)filedata;
100     }
101     return 0;
102 }
103
104 int cleanup_result(RESULT const& /*result*/, void *data) {
105     if(data)
106     {
107     delete ((RainbowPartFile*)data)->pChain;
108         delete ((RainbowPartFile*)data);
109     }
110     return 0;
111 }
112
113 double compute_granted_credit(WORKUNIT& wu, vector<RESULT>& results) {
114     return median_mean_credit(wu, results);
115 }
116
117 const char *BOINC_RCSID_7ab2b7189c = "$Id: sample_bitwise_validator.cpp 16069 2008-09-26 18:20:24Z davea $";