1 // This file is part of BOINC.
2 // http://boinc.berkeley.edu
3 // Copyright (C) 2008 University of California
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.
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.
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/>.
18 // A sample validator that grants credit if the majority of results are
20 // This is useful only if either
21 // 1) your application does no floating-point math, or
22 // 2) you use homogeneous redundancy
27 #include "sched_util.h"
28 #include "sched_msgs.h"
29 #include "validate_util.h"
30 #include "ChainWalkContext.h"
31 #include "MemoryPool.h"
33 #include "error_numbers.h"
34 #include "part_validator.h"
39 int read_file_binary(const char *path, RainbowPartFile *data, int &isize)
44 retval = file_size(path, size);
45 if (retval) return retval;
46 FILE *f = fopen(path, "rb");
47 if (!f) return ERR_FOPEN;
49 log_messages.printf(MSG_DEBUG,
50 "malloc %i bytes. size: %i\n",
51 (isize / 18 * sizeof(RainbowPartFile)), sizeof(RainbowPartFile)
53 data->pChain = (RainbowChainCP*)malloc(isize / 18 * sizeof(RainbowChainCP));
54 data->numchains = isize / 18;
55 for(int i = 0; i < data->numchains; i++)
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);
64 int init_result(RESULT& result, void*& data) {
66 vector<FILE_INFO> files;
68 retval = get_output_file_infos(result, files);
70 log_messages.printf(MSG_CRITICAL,
71 "[RESULT#%d %s] check_set: can't get output filenames\n",
72 result.id, result.name
77 RainbowPartFile *filedata = new RainbowPartFile();
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);
87 log_messages.printf(MSG_CRITICAL,
88 "[RESULT#%d %s] Couldn't open %s\n",
89 result.id, result.name, fi.path.c_str()
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
99 data = (void*)filedata;
104 int cleanup_result(RESULT const& /*result*/, void *data) {
107 delete ((RainbowPartFile*)data)->pChain;
108 delete ((RainbowPartFile*)data);
113 double compute_granted_credit(WORKUNIT& wu, vector<RESULT>& results) {
114 return median_mean_credit(wu, results);
117 const char *BOINC_RCSID_7ab2b7189c = "$Id: sample_bitwise_validator.cpp 16069 2008-09-26 18:20:24Z davea $";