mirror of https://github.com/BOINC/boinc.git
*** empty log message ***
svn path=/trunk/boinc/; revision=2090
This commit is contained in:
parent
b68ddd89a2
commit
d5680bc822
|
@ -5696,3 +5696,37 @@ Karl 2003/08/13
|
|||
_autosetup
|
||||
aclocal.m4
|
||||
|
||||
|
||||
Karl 2003/08/13
|
||||
- test script fixes: increase delay_bound to reasonable value since it's
|
||||
now checked by handle_request
|
||||
|
||||
test/
|
||||
testbase.py
|
||||
test_uc.py
|
||||
|
||||
|
||||
Karl 2003/08/13
|
||||
- create validation routines which generalize what used to be
|
||||
validate_test, but more efficiently and safer (from buffer overruns and
|
||||
allows NULL character in files). Rewrote validate_test using this, and
|
||||
created validate_trivial which grants credit to all results.
|
||||
|
||||
Sched/
|
||||
Makefile.am
|
||||
validate.C
|
||||
validate_test.C
|
||||
validate_trivial.C (new)
|
||||
validate_trivial.h (new)
|
||||
validate_util.C (new)
|
||||
validate_util.h (new)
|
||||
|
||||
|
||||
Karl 2003/08/13
|
||||
- added '-return_results_immediately' flag to client to allow it to
|
||||
ignore the report deadline when deciding when to report a result
|
||||
|
||||
client/
|
||||
cs_scheduler.C
|
||||
client_state.C
|
||||
client_state.h
|
||||
|
|
|
@ -68,6 +68,7 @@ CLIENT_STATE::CLIENT_STATE() {
|
|||
scheduler_op = new SCHEDULER_OP(http_ops);
|
||||
client_state_dirty = false;
|
||||
exit_when_idle = false;
|
||||
return_results_immediately = false;
|
||||
run_cpu_benchmarks = false;
|
||||
skip_cpu_benchmarks = false;
|
||||
file_xfer_giveup_period = PERS_GIVEUP;
|
||||
|
@ -1436,6 +1437,8 @@ void CLIENT_STATE::parse_cmdline(int argc, char** argv) {
|
|||
for (i=1; i<argc; i++) {
|
||||
if (!strcmp(argv[i], "-exit_when_idle")) {
|
||||
exit_when_idle = true;
|
||||
} else if (!strcmp(argv[i], "-return_results_immediately")) {
|
||||
return_results_immediately = true;
|
||||
} else if (!strcmp(argv[i], "-skip_cpu_benchmarks")) {
|
||||
skip_cpu_benchmarks = true;
|
||||
} else if (!strcmp(argv[i], "-exit_after_app_start")) {
|
||||
|
|
|
@ -105,6 +105,7 @@ public:
|
|||
int user_run_request;
|
||||
bool start_saver;
|
||||
bool exit_when_idle;
|
||||
bool return_results_immediately;
|
||||
bool show_projects;
|
||||
bool requested_exit;
|
||||
bool use_http_proxy;
|
||||
|
|
|
@ -292,8 +292,11 @@ PROJECT* CLIENT_STATE::find_project_with_overdue_results() {
|
|||
if (r->project->waiting_until_min_rpc_time(now)) continue;
|
||||
// NOTE: early versions of scheduler (<2003/08/07) did not send
|
||||
// report_deadline (in which case it is 0)
|
||||
// 'return_results_immediately' is a debug flag that makes the client
|
||||
// ignore the report deadline when deciding when to report a result
|
||||
if (r->ready_to_ack &&
|
||||
r->report_deadline <= now+SECONDS_BEFORE_REPORT_DEADLINE_TO_REPORT)
|
||||
(return_results_immediately ||
|
||||
r->report_deadline <= now+SECONDS_BEFORE_REPORT_DEADLINE_TO_REPORT))
|
||||
{
|
||||
return r->project;
|
||||
}
|
||||
|
@ -425,7 +428,7 @@ int CLIENT_STATE::handle_scheduler_reply(
|
|||
need_to_install_prefs = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// if the scheduler reply includes global preferences,
|
||||
// insert extra elements, write to disk, and parse
|
||||
//
|
||||
|
@ -442,7 +445,7 @@ int CLIENT_STATE::handle_scheduler_reply(
|
|||
scheduler_url,
|
||||
sr.global_prefs_xml
|
||||
);
|
||||
fclose(f);
|
||||
fclose(f);
|
||||
need_to_install_prefs = true;
|
||||
}
|
||||
|
||||
|
|
27
lib/util.C
27
lib/util.C
|
@ -17,20 +17,21 @@
|
|||
// Contributor(s):
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <ctype.h>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
#include <cctype>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef HAVE_SYS_FILE_H
|
||||
#include <sys/file.h>
|
||||
#endif
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
#include <fstream>
|
||||
using std::ifstream;
|
||||
using std::min;
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <time.h>
|
||||
|
@ -490,3 +491,15 @@ string timediff_format(long tdiff)
|
|||
sprintf(buf, "%d weeks, %d days, %d hours, %d minutes, and %d seconds", (int)tdiff, days, hours, min, sex);
|
||||
return buf;
|
||||
}
|
||||
|
||||
// read entire file into string
|
||||
int read_file_string(const char* pathname, string& result)
|
||||
{
|
||||
result.erase();
|
||||
ifstream f(pathname);
|
||||
if (!f) return -1;
|
||||
|
||||
char c;
|
||||
while (f.get(c)) result += c;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ extern void safe_strncpy(char*, char*, int);
|
|||
#define safe_strcat(x, y) if (strlen(x)+strlen(y)<sizeof(x)) strcat(x, y)
|
||||
extern char* timestamp();
|
||||
string timediff_format(long tdiff);
|
||||
int read_file_string(const char* pathname, string& result);
|
||||
|
||||
// NOTE: use #include <functional> to get max,min
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
include $(top_srcdir)/Makefile.incl
|
||||
|
||||
noinst_PROGRAMS = \
|
||||
cgi feeder show_shmem file_upload_handler \
|
||||
validate_test make_work timeout_check file_deleter \
|
||||
noinst_PROGRAMS = \
|
||||
cgi feeder show_shmem file_upload_handler \
|
||||
validate_test validate_trivial make_work timeout_check file_deleter \
|
||||
assimilator db_dump update_stats
|
||||
|
||||
noinst_LIBRARIES = libsched.a
|
||||
|
@ -54,9 +54,12 @@ feeder_DEPENDENCIES = $(LIB_SCHED)
|
|||
show_shmem_SOURCES = show_shmem.C
|
||||
show_shmem_DEPENDENCIES = $(LIB_SCHED)
|
||||
|
||||
validate_test_SOURCES = validate.C validate_test.C
|
||||
validate_test_SOURCES = validate.C validate_test.C validate_util.C validate_util.h
|
||||
validate_test_DEPENDENCIES = $(LIB_SCHED)
|
||||
|
||||
validate_trivial_SOURCES = validate.C validate_trivial.C validate_util.C validate_util.h
|
||||
validate_trivial_DEPENDENCIES = $(LIB_SCHED)
|
||||
|
||||
file_deleter_SOURCES = file_deleter.C
|
||||
file_deleter_DEPENDENCIES = $(LIB_SCHED)
|
||||
|
||||
|
|
|
@ -177,8 +177,8 @@ AM_CPPFLAGS = \
|
|||
LIBRSA = $(top_builddir)/RSAEuro/source/librsaeuro.a
|
||||
|
||||
noinst_PROGRAMS = \
|
||||
cgi feeder show_shmem file_upload_handler \
|
||||
validate_test make_work timeout_check file_deleter \
|
||||
cgi feeder show_shmem file_upload_handler \
|
||||
validate_test validate_trivial make_work timeout_check file_deleter \
|
||||
assimilator db_dump update_stats
|
||||
|
||||
|
||||
|
@ -231,9 +231,12 @@ feeder_DEPENDENCIES = $(LIB_SCHED)
|
|||
show_shmem_SOURCES = show_shmem.C
|
||||
show_shmem_DEPENDENCIES = $(LIB_SCHED)
|
||||
|
||||
validate_test_SOURCES = validate.C validate_test.C
|
||||
validate_test_SOURCES = validate.C validate_test.C validate_util.C validate_util.h
|
||||
validate_test_DEPENDENCIES = $(LIB_SCHED)
|
||||
|
||||
validate_trivial_SOURCES = validate.C validate_trivial.C validate_util.C validate_util.h
|
||||
validate_trivial_DEPENDENCIES = $(LIB_SCHED)
|
||||
|
||||
file_deleter_SOURCES = file_deleter.C
|
||||
file_deleter_DEPENDENCIES = $(LIB_SCHED)
|
||||
|
||||
|
@ -287,7 +290,8 @@ libsched_a_OBJECTS = $(am_libsched_a_OBJECTS)
|
|||
EXTRA_PROGRAMS = fcgi$(EXEEXT)
|
||||
noinst_PROGRAMS = cgi$(EXEEXT) feeder$(EXEEXT) show_shmem$(EXEEXT) \
|
||||
file_upload_handler$(EXEEXT) validate_test$(EXEEXT) \
|
||||
make_work$(EXEEXT) timeout_check$(EXEEXT) file_deleter$(EXEEXT) \
|
||||
validate_trivial$(EXEEXT) make_work$(EXEEXT) \
|
||||
timeout_check$(EXEEXT) file_deleter$(EXEEXT) \
|
||||
assimilator$(EXEEXT) db_dump$(EXEEXT) update_stats$(EXEEXT)
|
||||
PROGRAMS = $(noinst_PROGRAMS)
|
||||
|
||||
|
@ -335,10 +339,16 @@ am_update_stats_OBJECTS = update_stats.$(OBJEXT)
|
|||
update_stats_OBJECTS = $(am_update_stats_OBJECTS)
|
||||
update_stats_LDADD = $(LDADD)
|
||||
update_stats_LDFLAGS =
|
||||
am_validate_test_OBJECTS = validate.$(OBJEXT) validate_test.$(OBJEXT)
|
||||
am_validate_test_OBJECTS = validate.$(OBJEXT) validate_test.$(OBJEXT) \
|
||||
validate_util.$(OBJEXT)
|
||||
validate_test_OBJECTS = $(am_validate_test_OBJECTS)
|
||||
validate_test_LDADD = $(LDADD)
|
||||
validate_test_LDFLAGS =
|
||||
am_validate_trivial_OBJECTS = validate.$(OBJEXT) \
|
||||
validate_trivial.$(OBJEXT) validate_util.$(OBJEXT)
|
||||
validate_trivial_OBJECTS = $(am_validate_trivial_OBJECTS)
|
||||
validate_trivial_LDADD = $(LDADD)
|
||||
validate_trivial_LDFLAGS =
|
||||
SCRIPTS = $(bin_SCRIPTS)
|
||||
|
||||
|
||||
|
@ -368,7 +378,9 @@ am__depfiles_maybe = depfiles
|
|||
@AMDEP_TRUE@ ./$(DEPDIR)/timeout_check.Po \
|
||||
@AMDEP_TRUE@ ./$(DEPDIR)/update_stats.Po ./$(DEPDIR)/util.Po \
|
||||
@AMDEP_TRUE@ ./$(DEPDIR)/validate.Po \
|
||||
@AMDEP_TRUE@ ./$(DEPDIR)/validate_test.Po
|
||||
@AMDEP_TRUE@ ./$(DEPDIR)/validate_test.Po \
|
||||
@AMDEP_TRUE@ ./$(DEPDIR)/validate_trivial.Po \
|
||||
@AMDEP_TRUE@ ./$(DEPDIR)/validate_util.Po
|
||||
CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
|
||||
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
|
||||
CXXLD = $(CXX)
|
||||
|
@ -383,9 +395,10 @@ DIST_SOURCES = $(libsched_a_SOURCES) $(assimilator_SOURCES) \
|
|||
$(feeder_SOURCES) $(file_deleter_SOURCES) \
|
||||
$(file_upload_handler_SOURCES) $(make_work_SOURCES) \
|
||||
$(show_shmem_SOURCES) $(timeout_check_SOURCES) \
|
||||
$(update_stats_SOURCES) $(validate_test_SOURCES)
|
||||
$(update_stats_SOURCES) $(validate_test_SOURCES) \
|
||||
$(validate_trivial_SOURCES)
|
||||
DIST_COMMON = $(top_srcdir)/Makefile.incl Makefile.am Makefile.in
|
||||
SOURCES = $(libsched_a_SOURCES) $(assimilator_SOURCES) $(cgi_SOURCES) $(db_dump_SOURCES) $(fcgi_SOURCES) $(feeder_SOURCES) $(file_deleter_SOURCES) $(file_upload_handler_SOURCES) $(make_work_SOURCES) $(show_shmem_SOURCES) $(timeout_check_SOURCES) $(update_stats_SOURCES) $(validate_test_SOURCES)
|
||||
SOURCES = $(libsched_a_SOURCES) $(assimilator_SOURCES) $(cgi_SOURCES) $(db_dump_SOURCES) $(fcgi_SOURCES) $(feeder_SOURCES) $(file_deleter_SOURCES) $(file_upload_handler_SOURCES) $(make_work_SOURCES) $(show_shmem_SOURCES) $(timeout_check_SOURCES) $(update_stats_SOURCES) $(validate_test_SOURCES) $(validate_trivial_SOURCES)
|
||||
|
||||
all: all-am
|
||||
|
||||
|
@ -444,6 +457,9 @@ update_stats$(EXEEXT): $(update_stats_OBJECTS) $(update_stats_DEPENDENCIES)
|
|||
validate_test$(EXEEXT): $(validate_test_OBJECTS) $(validate_test_DEPENDENCIES)
|
||||
@rm -f validate_test$(EXEEXT)
|
||||
$(CXXLINK) $(validate_test_LDFLAGS) $(validate_test_OBJECTS) $(validate_test_LDADD) $(LIBS)
|
||||
validate_trivial$(EXEEXT): $(validate_trivial_OBJECTS) $(validate_trivial_DEPENDENCIES)
|
||||
@rm -f validate_trivial$(EXEEXT)
|
||||
$(CXXLINK) $(validate_trivial_LDFLAGS) $(validate_trivial_OBJECTS) $(validate_trivial_LDADD) $(LIBS)
|
||||
binSCRIPT_INSTALL = $(INSTALL_SCRIPT)
|
||||
install-binSCRIPTS: $(bin_SCRIPTS)
|
||||
@$(NORMAL_INSTALL)
|
||||
|
@ -503,6 +519,8 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/util.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/validate.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/validate_test.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/validate_trivial.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/validate_util.Po@am__quote@
|
||||
|
||||
distclean-depend:
|
||||
-rm -rf ./$(DEPDIR)
|
||||
|
|
|
@ -54,7 +54,7 @@ using namespace std;
|
|||
#define PIDFILE "validate.pid"
|
||||
|
||||
extern int check_set(vector<RESULT>&, int& canonical, double& credit);
|
||||
extern int check_pair(RESULT&, RESULT&, bool&);
|
||||
extern int check_pair(RESULT const&, RESULT const&, bool&);
|
||||
|
||||
CONFIG config;
|
||||
char app_name[256];
|
||||
|
|
|
@ -17,163 +17,76 @@
|
|||
// Contributor(s):
|
||||
//
|
||||
|
||||
using namespace std;
|
||||
#include <vector>
|
||||
|
||||
#include "boinc_db.h"
|
||||
#include "config.h"
|
||||
#include "parse.h"
|
||||
#include "validate_util.h"
|
||||
#include "sched_util.h"
|
||||
|
||||
extern CONFIG config;
|
||||
// TODO: use md5 hash
|
||||
|
||||
// get the name of a result's (first) output file
|
||||
//
|
||||
int get_output_file_path(RESULT& result, char* path) {
|
||||
char buf[256];
|
||||
bool flag;
|
||||
// read file into memory
|
||||
int init_result_read_file(RESULT const& result, void*& data)
|
||||
{
|
||||
int retval;
|
||||
string path;
|
||||
|
||||
retval = get_output_file_path(result, path);
|
||||
if (retval) {
|
||||
log_messages.printf(
|
||||
SchedMessages::CRITICAL,
|
||||
"[RESULT#%d %s] check_set: can't get output filename\n",
|
||||
result.id, result.name
|
||||
);
|
||||
return retval;
|
||||
}
|
||||
|
||||
string* s = new string;
|
||||
data = (void*) s;
|
||||
|
||||
retval = read_file_string(path.c_str(), *s);
|
||||
if (retval) {
|
||||
log_messages.printf(
|
||||
SchedMessages::CRITICAL,
|
||||
"[RESULT#%d %s] Couldn't open %s\n",
|
||||
result.id, result.name, path.c_str()
|
||||
);
|
||||
return retval;
|
||||
}
|
||||
|
||||
flag = parse_str(result.xml_doc_in, "<name>", buf, sizeof(buf));
|
||||
if (!flag) return -1;
|
||||
sprintf(path, "%s/%s", config.upload_dir, buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// crude example of a validation function.
|
||||
int check_pair_initialized_identical(RESULT const& /*r1*/, void* data1,
|
||||
RESULT const& /*r2*/, void* data2,
|
||||
bool& match)
|
||||
{
|
||||
string const* s1 = (string*) data1;
|
||||
string const* s2 = (string*) data2;
|
||||
|
||||
match = (*s1 == *s2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cleanup_result_string(RESULT const& /*result*/, void* data)
|
||||
{
|
||||
string* s = (string*) data;
|
||||
delete s;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// See if there's a strict majority under equality.
|
||||
//
|
||||
int check_set(vector<RESULT>& results, int& canonicalid, double& credit) {
|
||||
int i, j, n, neq=0, retval, ilow, ihigh, canonical;
|
||||
char* files[100];
|
||||
char path[256];
|
||||
bool found;
|
||||
double c, low=0.0, high=0.0;
|
||||
|
||||
canonical = 0;
|
||||
n = results.size();
|
||||
|
||||
// read the result files into malloc'd memory buffers
|
||||
//
|
||||
for (i=0; i<n; i++) {
|
||||
RESULT& result = results[i];
|
||||
retval = get_output_file_path(result, path);
|
||||
if (retval) {
|
||||
log_messages.printf(
|
||||
SchedMessages::CRITICAL,
|
||||
"check_set: can't get output filename for %s\n",
|
||||
result.name
|
||||
);
|
||||
return retval;
|
||||
}
|
||||
retval = read_file_malloc(path, files[i]);
|
||||
if (retval) {
|
||||
log_messages.printf(
|
||||
SchedMessages::CRITICAL,
|
||||
"[RESULT#%d %s] Couldn't open %s (read_file_malloc()=%d)\n",
|
||||
result.id, result.name, path, retval
|
||||
);
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
// go through the files, compare with the others.
|
||||
// If equal to over half, make it the canonical result
|
||||
//
|
||||
for (i=0; i<n; i++) {
|
||||
neq = 0;
|
||||
for (j=0; j<n; j++) {
|
||||
if (!strcmp(files[i], files[j])) neq++;
|
||||
}
|
||||
if (neq > n/2) {
|
||||
found = true;
|
||||
canonical = i;
|
||||
canonicalid = results[i].id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if we have a canonical result, flag all matching results as valid
|
||||
// Also find the low and high claimed credits
|
||||
//
|
||||
ilow = ihigh = -1;
|
||||
for (i=0; i<n; i++) {
|
||||
if (!strcmp(files[i], files[canonical])) {
|
||||
results[i].validate_state = VALIDATE_STATE_VALID;
|
||||
c = results[i].claimed_credit;
|
||||
if (ilow < 0) {
|
||||
ilow = ihigh = i;
|
||||
low = high = c;
|
||||
} else {
|
||||
if (c < low) {
|
||||
low = c;
|
||||
ilow = i;
|
||||
}
|
||||
if (c > high) {
|
||||
high = c;
|
||||
ihigh = i;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
results[i].validate_state = VALIDATE_STATE_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
// if we have a canonical result, compute a canonical credit as follows:
|
||||
// - if N==1, give that credit
|
||||
// - if N==2, give min credit
|
||||
// - if N>2, toss out min and max, give average of rest
|
||||
//
|
||||
if (neq == 1) {
|
||||
credit = low;
|
||||
} else if (neq == 2) {
|
||||
credit = low;
|
||||
} else {
|
||||
double sum = 0;
|
||||
for (i=0; i<n; i++) {
|
||||
if (i == ilow) continue;
|
||||
if (i == ihigh) continue;
|
||||
if (results[i].validate_state == VALIDATE_STATE_VALID) {
|
||||
sum += results[i].claimed_credit;
|
||||
}
|
||||
}
|
||||
credit = sum/(neq-2);
|
||||
}
|
||||
|
||||
// free malloced files
|
||||
//
|
||||
for (i=0; i<n; i++) {
|
||||
free(files[i]);
|
||||
}
|
||||
return 0;
|
||||
int check_set(vector<RESULT>& results, int& canonicalid, double& credit)
|
||||
{
|
||||
return generic_check_set_majority(results, canonicalid, credit,
|
||||
init_result_read_file,
|
||||
check_pair_initialized_identical,
|
||||
cleanup_result_string);
|
||||
}
|
||||
|
||||
int check_pair(RESULT& r1, RESULT& r2, bool& match) {
|
||||
char path[256];
|
||||
char* p1, *p2;
|
||||
int retval;
|
||||
|
||||
get_output_file_path(r1, path);
|
||||
retval = read_file_malloc(path, p1);
|
||||
if (retval) {
|
||||
log_messages.printf(
|
||||
SchedMessages::CRITICAL,
|
||||
"[RESULT#%d %s] [RESULT#%d %s] Couldn't open %s (r1: read_file_malloc()=%d)\n",
|
||||
r1.id, r1.name, r2.id, r2.name, path, retval
|
||||
);
|
||||
return retval;
|
||||
}
|
||||
get_output_file_path(r2, path);
|
||||
retval = read_file_malloc(path, p2);
|
||||
if (retval) {
|
||||
log_messages.printf(
|
||||
SchedMessages::CRITICAL,
|
||||
"[RESULT#%d %s] [RESULT#%d %s] Couldn't open %s (r2: read_file_malloc()=%d)\n",
|
||||
r1.id, r1.name, r2.id, r2.name, path, retval
|
||||
);
|
||||
return retval;
|
||||
}
|
||||
match = !strcmp(p1, p2);
|
||||
free(p1);
|
||||
free(p2);
|
||||
return 0;
|
||||
int check_pair(RESULT const& r1, RESULT const& r2, bool& match)
|
||||
{
|
||||
return generic_check_pair(r1, r2, match,
|
||||
init_result_read_file,
|
||||
check_pair_initialized_identical,
|
||||
cleanup_result_string);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
// The contents of this file are subject to the BOINC Public License
|
||||
// Version 1.0 (the "License"); you may not use this file except in
|
||||
// compliance with the License. You may obtain a copy of the License at
|
||||
// http://boinc.berkeley.edu/license_1.0.txt
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS"
|
||||
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
// License for the specific language governing rights and limitations
|
||||
// under the License.
|
||||
//
|
||||
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
||||
//
|
||||
// The Initial Developer of the Original Code is the SETI@home project.
|
||||
// Portions created by the SETI@home project are Copyright (C) 2002
|
||||
// University of California at Berkeley. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
//
|
||||
|
||||
#include "validate_util.h"
|
||||
|
||||
// TODO: use md5 hash
|
||||
|
||||
// read file into memory
|
||||
int init_result_trivial(RESULT const& result, void*& data)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int check_pair_initialized_trivial(RESULT const& /*r1*/, void* /*data1*/,
|
||||
RESULT const& /*r2*/, void* /*data2*/,
|
||||
bool& match)
|
||||
{
|
||||
match = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cleanup_result_trivial(RESULT const& /*result*/, void* /*data*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Always grant credit to everybody
|
||||
//
|
||||
int check_set(vector<RESULT>& results, int& canonicalid, double& credit)
|
||||
{
|
||||
return generic_check_set_majority(results, canonicalid, credit,
|
||||
init_result_trivial,
|
||||
check_pair_initialized_trivial,
|
||||
cleanup_result_trivial);
|
||||
}
|
||||
|
||||
int check_pair(RESULT const& r1, RESULT const& r2, bool& match)
|
||||
{
|
||||
// return generic_check_pair(r1, r2, match,
|
||||
// init_result_trivial,
|
||||
// check_pair_initialized_trivial,
|
||||
// cleanup_result_trivial);
|
||||
match = true;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,217 @@
|
|||
// The contents of this file are subject to the BOINC Public License
|
||||
// Version 1.0 (the "License"); you may not use this file except in
|
||||
// compliance with the License. You may obtain a copy of the License at
|
||||
// http://boinc.berkeley.edu/license_1.0.txt
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS"
|
||||
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
// License for the specific language governing rights and limitations
|
||||
// under the License.
|
||||
//
|
||||
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
||||
//
|
||||
// The Initial Developer of the Original Code is the SETI@home project.
|
||||
// Portions created by the SETI@home project are Copyright (C) 2002
|
||||
// University of California at Berkeley. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
//
|
||||
|
||||
#include "validate_util.h"
|
||||
#include "sched_util.h"
|
||||
#include "config.h"
|
||||
#include "parse.h"
|
||||
#include <cassert>
|
||||
|
||||
extern CONFIG config;
|
||||
|
||||
// get the name of a result's (first) output file
|
||||
//
|
||||
int get_output_file_path(RESULT const& result, string& path) {
|
||||
char buf[256];
|
||||
bool flag;
|
||||
|
||||
flag = parse_str(result.xml_doc_in, "<name>", buf, sizeof(buf));
|
||||
if (!flag) return -1;
|
||||
path = config.upload_dir;
|
||||
path += '/';
|
||||
path += buf;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// If we have a canonical result, and N results (including itself) that match
|
||||
// it, compute a canonical credit as follows:
|
||||
// - if N==1, give that credit
|
||||
// - if N==2, give min credit
|
||||
// - if N>2, toss out min and max, give average of rest
|
||||
//
|
||||
double median_mean_credit(vector<RESULT> const& results)
|
||||
{
|
||||
typedef vector<RESULT>::const_iterator it;
|
||||
|
||||
it it_low = results.end(), it_high;
|
||||
double credit_low = 0, credit_high = 0;
|
||||
|
||||
size_t n_valid = 0;
|
||||
|
||||
for (it i = results.begin(); i != results.end(); ++i)
|
||||
{
|
||||
if (i->validate_state != VALIDATE_STATE_VALID) continue;
|
||||
|
||||
++n_valid;
|
||||
|
||||
if (it_low == results.end()) {
|
||||
it_low = it_high = i;
|
||||
credit_low = credit_high = i->claimed_credit;
|
||||
} else {
|
||||
if (i->claimed_credit < credit_low) {
|
||||
it_low = i;
|
||||
credit_low = i->claimed_credit;
|
||||
}
|
||||
if (i->claimed_credit > credit_high) {
|
||||
it_high = i;
|
||||
credit_high = i->claimed_credit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// compute a canonical credit as follows:
|
||||
// - if N==1, give that credit
|
||||
// - if N==2, give min credit
|
||||
// - if N>2, toss out min and max, give average of rest
|
||||
//
|
||||
if (n_valid == 1) {
|
||||
return credit_low;
|
||||
} else if (n_valid == 2) {
|
||||
return credit_low;
|
||||
} else {
|
||||
double sum = 0;
|
||||
|
||||
for (it i = results.begin(); i != results.end(); ++i)
|
||||
{
|
||||
if (i == it_low) continue;
|
||||
if (i == it_high) continue;
|
||||
if (i->validate_state != VALIDATE_STATE_VALID) continue;
|
||||
|
||||
sum += i->claimed_credit;
|
||||
}
|
||||
return sum/(n_valid-2);
|
||||
}
|
||||
}
|
||||
|
||||
// Generic validation function that compares each result to each other one
|
||||
// and sees if there is a strict majority. The comparison function is
|
||||
// similar to check_pair but takes an additional initialization parameter.
|
||||
//
|
||||
// This function takes 3 call-back functions, each of which accept a void*
|
||||
// and should return !=0 on error:
|
||||
//
|
||||
// 1. init_result - initialize all results - for example, call
|
||||
// read_file_string and compute an MD5. Return a void*
|
||||
// 2. check_pair_with_data - same as check_pair but with extra data from
|
||||
// init_result
|
||||
// 3. cleanup_result - deallocate anything created by init_result
|
||||
//
|
||||
// see validate_test.C example usage.
|
||||
//
|
||||
int generic_check_set_majority(vector<RESULT>& results, int& canonicalid, double& credit,
|
||||
init_result_f init_result_f,
|
||||
check_pair_with_data_f check_pair_with_data_f,
|
||||
cleanup_result_f cleanup_result_f)
|
||||
{
|
||||
assert (!results.empty());
|
||||
|
||||
vector<void*> data;
|
||||
vector<RESULT>::size_type i, j, neq = 0, n = results.size();
|
||||
data.resize(n);
|
||||
|
||||
// 1. INITIALIZE DATA
|
||||
for (i = 0; i != n; ++i)
|
||||
{
|
||||
if (init_result_f(results[i], data[i])) {
|
||||
log_messages.printf(
|
||||
SchedMessages::CRITICAL,
|
||||
"check_set_majority: init_result([RESULT#%d %s]) failed\n",
|
||||
results[i].id, results[i].name);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. COMPARE
|
||||
for (i = 0; i != n; ++i)
|
||||
{
|
||||
vector<bool> matches;
|
||||
matches.resize(n);
|
||||
neq = 0;
|
||||
for (j = 0; j != n; ++j) {
|
||||
bool match = false;
|
||||
if (i == j) {
|
||||
++neq;
|
||||
matches[j] = true;
|
||||
} else if (check_pair_with_data_f(results[i], data[i], results[j], data[j], match)) {
|
||||
log_messages.printf(
|
||||
SchedMessages::CRITICAL,
|
||||
"check_set_majority: check_pair_with_data([RESULT#%d %s], [RESULT#%d %s]) failed\n",
|
||||
results[i].id, results[i].name, results[j].id, results[j].name);
|
||||
} else if (match) {
|
||||
++neq;
|
||||
matches[j] = true;
|
||||
}
|
||||
}
|
||||
if (neq > n/2) {
|
||||
// set validate state for each result
|
||||
for (j = 0; j != n; ++j) {
|
||||
results[j].validate_state = matches[j] ? VALIDATE_STATE_VALID : VALIDATE_STATE_INVALID;
|
||||
}
|
||||
canonicalid = results[i].id;
|
||||
credit = median_mean_credit(results);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
// 3. CLEANUP
|
||||
for (i = 0; i != n; ++i) {
|
||||
cleanup_result_f(results[i], data[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int generic_check_pair(RESULT const& r1, RESULT const& r2, bool& match,
|
||||
init_result_f init_result_f,
|
||||
check_pair_with_data_f check_pair_with_data_f,
|
||||
cleanup_result_f cleanup_result_f)
|
||||
{
|
||||
void* data1;
|
||||
void* data2;
|
||||
int retval;
|
||||
|
||||
retval = init_result_f(r1, data1);
|
||||
if (retval) {
|
||||
log_messages.printf(
|
||||
SchedMessages::CRITICAL,
|
||||
"[RESULT#%d %s] [RESULT#%d %s] Couldn't initialize result 1\n",
|
||||
r1.id, r1.name, r2.id, r2.name
|
||||
);
|
||||
return retval;
|
||||
}
|
||||
|
||||
retval = init_result_f(r2, data2);
|
||||
if (retval) {
|
||||
log_messages.printf(
|
||||
SchedMessages::CRITICAL,
|
||||
"[RESULT#%d %s] [RESULT#%d %s] Couldn't initialize result 2\n",
|
||||
r1.id, r1.name, r2.id, r2.name
|
||||
);
|
||||
cleanup_result_f(r1, data1);
|
||||
return retval;
|
||||
}
|
||||
|
||||
retval = check_pair_with_data_f(r1, data1, r2, data2, match);
|
||||
|
||||
cleanup_result_f(r1, data1);
|
||||
cleanup_result_f(r2, data2);
|
||||
|
||||
return retval;
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
// The contents of this file are subject to the BOINC Public License
|
||||
// Version 1.0 (the "License"); you may not use this file except in
|
||||
// compliance with the License. You may obtain a copy of the License at
|
||||
// http://boinc.berkeley.edu/license_1.0.txt
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS"
|
||||
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
// License for the specific language governing rights and limitations
|
||||
// under the License.
|
||||
//
|
||||
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
||||
//
|
||||
// The Initial Developer of the Original Code is the SETI@home project.
|
||||
// Portions created by the SETI@home project are Copyright (C) 2002
|
||||
// University of California at Berkeley. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
//
|
||||
|
||||
#ifndef H_VALIDATE_UTIL
|
||||
#define H_VALIDATE_UTIL
|
||||
|
||||
#include "boinc_db.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
using std::vector;
|
||||
using std::string;
|
||||
|
||||
typedef int (*init_result_f)(RESULT const&, void*&);
|
||||
typedef int (*check_pair_with_data_f)(RESULT const&, void*, RESULT const&, void*, bool&);
|
||||
typedef int (*cleanup_result_f)(RESULT const&, void*);
|
||||
int get_output_file_path(RESULT const& result, string& path);
|
||||
double median_mean_credit(vector<RESULT> const& results);
|
||||
int generic_check_set_majority(vector<RESULT>& results, int& canonicalid, double& credit,
|
||||
init_result_f init_result_f,
|
||||
check_pair_with_data_f check_pair_with_data_f,
|
||||
cleanup_result_f cleanup_result_f);
|
||||
int generic_check_pair(RESULT const& r1, RESULT const& r2, bool& match,
|
||||
init_result_f init_result_f,
|
||||
check_pair_with_data_f check_pair_with_data_f,
|
||||
cleanup_result_f cleanup_result_f);
|
||||
|
||||
#endif
|
|
@ -26,7 +26,7 @@ class WorkUC(Work):
|
|||
self.wu_template = "uc_wu"
|
||||
self.result_template = "uc_result"
|
||||
self.redundancy = redundancy
|
||||
self.delay_bound = 5*redundancy
|
||||
self.delay_bound = 86400*3 # 5*redundancy
|
||||
self.input_files = ['input']
|
||||
# # Say that 1 WU takes 1 day on a ref comp
|
||||
# - note: for test_1sec these values are too high so if you want to
|
||||
|
|
Loading…
Reference in New Issue