2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2007-05-08 01:55:28 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2007-05-08 01:55:28 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2007-05-08 01:55:28 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2007-05-08 01:55:28 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2007-05-08 01:55:28 +00:00
|
|
|
|
|
|
|
// BOINC client simulator.
|
|
|
|
//
|
|
|
|
// usage:
|
|
|
|
// sim [--duration x] [--delta x] [--dirs dir ...]
|
|
|
|
// duration = simulation duration (default 86400)
|
|
|
|
// delta = simulation time step (default 10)
|
|
|
|
//
|
|
|
|
// If no dirs are specified:
|
|
|
|
// reads input files
|
|
|
|
// sim_projects.xml, sim_host.xml, sim_prefs.xml, cc_config.xml
|
|
|
|
// and does simulation, generating output files
|
|
|
|
// sim_log.txt, sim_out.html
|
|
|
|
//
|
|
|
|
// If dirs are specified, chdir into each directory in sequence,
|
|
|
|
// do the above for each one, and write summary info to stdout
|
|
|
|
|
2009-08-22 17:00:19 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define finite _finite
|
|
|
|
#endif
|
|
|
|
|
2009-07-06 16:33:02 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2007-05-08 01:55:28 +00:00
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "str_util.h"
|
2010-09-24 20:02:42 +00:00
|
|
|
#include "util.h"
|
2009-06-16 20:54:44 +00:00
|
|
|
#include "str_replace.h"
|
2007-05-08 01:55:28 +00:00
|
|
|
#include "log_flags.h"
|
|
|
|
#include "filesys.h"
|
|
|
|
#include "client_msgs.h"
|
2010-09-24 20:02:42 +00:00
|
|
|
#include "client_state.h"
|
2007-05-08 01:55:28 +00:00
|
|
|
#include "sim.h"
|
|
|
|
|
|
|
|
//////////////// FUNCTIONS MODIFIED OR STUBBED OUT /////////////
|
|
|
|
|
|
|
|
void HOST_INFO::generate_host_cpid() {}
|
|
|
|
|
2008-01-11 23:52:49 +00:00
|
|
|
//int get_connected_state() {return 1;}
|
2007-05-08 01:55:28 +00:00
|
|
|
|
2010-08-01 06:09:33 +00:00
|
|
|
void show_message(PROJECT *p, char* msg, int priority, const char*) {
|
2007-05-08 01:55:28 +00:00
|
|
|
const char* x;
|
|
|
|
char message[1024];
|
|
|
|
char* time_string = time_to_string(gstate.now);
|
|
|
|
|
|
|
|
if (priority == MSG_INTERNAL_ERROR) {
|
|
|
|
strcpy(message, "[error] ");
|
|
|
|
strlcpy(message+8, msg, sizeof(message)-8);
|
|
|
|
} else {
|
|
|
|
strlcpy(message, msg, sizeof(message));
|
|
|
|
}
|
|
|
|
while (strlen(message)&&message[strlen(message)-1] == '\n') {
|
|
|
|
message[strlen(message)-1] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p) {
|
|
|
|
x = p->get_project_name();
|
|
|
|
} else {
|
|
|
|
x = "---";
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(logfile, "%s [%s] %s\n", time_string, x, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
APP_CLIENT_SHM::APP_CLIENT_SHM() {}
|
|
|
|
GRAPHICS_MSG::GRAPHICS_MSG() {}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////// FUNCTIONS WE NEED TO IMPLEMENT /////////////
|
|
|
|
|
|
|
|
int ACTIVE_TASK::suspend() {
|
|
|
|
if (task_state() != PROCESS_EXECUTING) {
|
|
|
|
msg_printf(0, MSG_INFO, "Internal error: expected process to be executing");
|
|
|
|
}
|
|
|
|
set_task_state(PROCESS_SUSPENDED, "suspend");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ACTIVE_TASK::request_exit() {
|
|
|
|
set_task_state(PROCESS_UNINITIALIZED, "request_exit");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ACTIVE_TASK::resume_or_start(bool first_time) {
|
|
|
|
if (log_flags.task) {
|
|
|
|
msg_printf(result->project, MSG_INFO,
|
2010-09-27 20:34:47 +00:00
|
|
|
"[task] %s task %s: time left %f",
|
|
|
|
first_time?"Starting":"Resuming", result->name, cpu_time_left
|
2007-05-08 01:55:28 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
set_task_state(PROCESS_EXECUTING, "start");
|
|
|
|
char buf[256];
|
|
|
|
sprintf(buf, "Starting %s: %f<br>", result->name, cpu_time_left);
|
2010-10-08 23:18:12 +00:00
|
|
|
html_msg += buf;
|
2007-05-08 01:55:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ACTIVE_TASK::init(RESULT* rp) {
|
|
|
|
result = rp;
|
|
|
|
wup = rp->wup;
|
|
|
|
app_version = rp->avp;
|
2009-02-26 22:04:53 +00:00
|
|
|
max_elapsed_time = rp->wup->rsc_fpops_bound/result->avp->flops;
|
2007-05-08 01:55:28 +00:00
|
|
|
max_disk_usage = rp->wup->rsc_disk_bound;
|
|
|
|
max_mem_usage = rp->wup->rsc_memory_bound;
|
|
|
|
cpu_time_left = rp->final_cpu_time;
|
|
|
|
_task_state = PROCESS_UNINITIALIZED;
|
|
|
|
scheduler_state = CPU_SCHED_UNINITIALIZED;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////// OTHER
|
|
|
|
|
|
|
|
// http://www.cs.wm.edu/~va/software/park/rvgs.c
|
|
|
|
double NORMAL_DIST::sample() {
|
|
|
|
const double p0 = 0.322232431088; const double q0 = 0.099348462606;
|
|
|
|
const double p1 = 1.0; const double q1 = 0.588581570495;
|
|
|
|
const double p2 = 0.342242088547; const double q2 = 0.531103462366;
|
|
|
|
const double p3 = 0.204231210245e-1; const double q3 = 0.103537752850;
|
|
|
|
const double p4 = 0.453642210148e-4; const double q4 = 0.385607006340e-2;
|
|
|
|
double u, t, p, q, z;
|
|
|
|
|
|
|
|
u = drand();
|
|
|
|
if (u < 0.5)
|
|
|
|
t = sqrt(-2.0 * log(u));
|
|
|
|
else
|
|
|
|
t = sqrt(-2.0 * log(1.0 - u));
|
|
|
|
p = p0 + t * (p1 + t * (p2 + t * (p3 + t * p4)));
|
|
|
|
q = q0 + t * (q1 + t * (q2 + t * (q3 + t * q4)));
|
|
|
|
if (u < 0.5)
|
|
|
|
z = (p / q) - t;
|
|
|
|
else
|
|
|
|
z = t - (p / q);
|
|
|
|
return (mean + stdev * z);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
inline double exponential(double mean) {
|
|
|
|
return -mean*log(1-drand());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RANDOM_PROCESS::sample(double t) {
|
|
|
|
if (frac==1) return true;
|
|
|
|
double diff = t-last_time;
|
|
|
|
last_time = t;
|
|
|
|
time_left -= diff;
|
|
|
|
if (time_left < 0) {
|
|
|
|
if (value) {
|
|
|
|
time_left += exponential(off_lambda);
|
|
|
|
value = false;
|
|
|
|
} else {
|
|
|
|
time_left += exponential(lambda);
|
|
|
|
value = true;
|
|
|
|
}
|
|
|
|
}
|
2010-01-21 00:14:56 +00:00
|
|
|
msg_printf(0, MSG_INFO,
|
|
|
|
"value: %d lambda: %f t %f time_left %f",
|
|
|
|
value, lambda, t, time_left
|
|
|
|
);
|
2007-05-08 01:55:28 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
RANDOM_PROCESS::RANDOM_PROCESS() {
|
|
|
|
frac = 1;
|
|
|
|
}
|
|
|
|
|
2010-01-21 00:14:56 +00:00
|
|
|
void RANDOM_PROCESS::init(double st) {
|
|
|
|
last_time = st;
|
2007-05-08 01:55:28 +00:00
|
|
|
value = true;
|
|
|
|
time_left = exponential(lambda);
|
|
|
|
off_lambda = lambda/frac - lambda;
|
|
|
|
}
|
|
|
|
|
2010-09-24 20:02:42 +00:00
|
|
|
int NORMAL_DIST::parse(XML_PARSER& xp, const char* end_tag) {
|
2007-05-08 01:55:28 +00:00
|
|
|
char tag[256];
|
|
|
|
bool is_tag;
|
|
|
|
while(!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (!is_tag) return ERR_XML_PARSE;
|
|
|
|
if (xp.parse_double(tag, "mean", mean)) continue;
|
|
|
|
else if (xp.parse_double(tag, "stdev", stdev)) continue;
|
|
|
|
else if (!strcmp(tag, end_tag)) return 0;
|
|
|
|
else {
|
|
|
|
printf("unrecognized: %s\n", tag);
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
2010-09-24 20:02:42 +00:00
|
|
|
int UNIFORM_DIST::parse(XML_PARSER& xp, const char* end_tag) {
|
2007-05-08 01:55:28 +00:00
|
|
|
char tag[256];
|
|
|
|
bool is_tag;
|
|
|
|
while(!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (!is_tag) return ERR_XML_PARSE;
|
|
|
|
if (xp.parse_double(tag, "lo", lo)) continue;
|
|
|
|
else if (xp.parse_double(tag, "hi", hi)) continue;
|
|
|
|
else if (!strcmp(tag, end_tag)) return 0;
|
|
|
|
else {
|
|
|
|
printf("unrecognized: %s\n", tag);
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
2010-09-24 20:02:42 +00:00
|
|
|
int RANDOM_PROCESS::parse(XML_PARSER& xp, const char* end_tag) {
|
2007-05-08 01:55:28 +00:00
|
|
|
char tag[256];
|
|
|
|
bool is_tag;
|
|
|
|
while(!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (!is_tag) return ERR_XML_PARSE;
|
|
|
|
if (xp.parse_double(tag, "frac", frac)) continue;
|
|
|
|
else if (xp.parse_double(tag, "lambda", lambda)) continue;
|
|
|
|
else if (!strcmp(tag, end_tag)) return 0;
|
|
|
|
else {
|
|
|
|
printf("unrecognized: %s\n", tag);
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|