From 671446ced132dbfffd2c7001df3c3b78535fd3db Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 27 Jul 2016 15:15:08 -0700 Subject: [PATCH] code cleanup: in scheduler, factor project prefs into their own struct --- lib/filesys.cpp | 1 - sched/sched_array.cpp | 8 ++--- sched/sched_check.cpp | 8 ++--- sched/sched_locality.cpp | 2 +- sched/sched_nci.cpp | 4 +-- sched/sched_score.cpp | 4 +-- sched/sched_send.cpp | 77 +++++++--------------------------------- sched/sched_send.h | 2 +- sched/sched_types.cpp | 52 +++++++++++++++++++++++++++ sched/sched_types.h | 27 +++++++++----- sched/sched_version.cpp | 4 +-- 11 files changed, 99 insertions(+), 90 deletions(-) diff --git a/lib/filesys.cpp b/lib/filesys.cpp index fd8710a7c2..f2b57ed2db 100644 --- a/lib/filesys.cpp +++ b/lib/filesys.cpp @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include diff --git a/sched/sched_array.cpp b/sched/sched_array.cpp index 67ef67c49f..661dbf846f 100644 --- a/sched/sched_array.cpp +++ b/sched/sched_array.cpp @@ -381,7 +381,7 @@ void send_work_old() { // (projects should load beta work with care, // otherwise your users won't get production work done! // - if (g_wreq->allow_beta_work) { + if (g_wreq->project_prefs.allow_beta_work) { g_wreq->beta_only = true; if (config.debug_send_scan) { log_messages.printf(MSG_NORMAL, @@ -429,12 +429,12 @@ void send_work_old() { // If user has selected apps but will accept any, // and we haven't found any jobs for selected apps, try others // - if (!g_wreq->njobs_sent && g_wreq->allow_non_preferred_apps ) { + if (!g_wreq->njobs_sent && g_wreq->project_prefs.allow_non_selected_apps ) { g_wreq->user_apps_only = false; - preferred_app_message_index = g_wreq->no_work_messages.size(); + selected_app_message_index = g_wreq->no_work_messages.size(); if (config.debug_send_scan) { log_messages.printf(MSG_NORMAL, - "[send_scan] scanning for jobs from non-preferred applications\n" + "[send_scan] scanning for jobs from non-selected applications\n" ); } if (scan_work_array()) return; diff --git a/sched/sched_check.cpp b/sched/sched_check.cpp index d08fed2ca9..a34a6e398e 100644 --- a/sched/sched_check.cpp +++ b/sched/sched_check.cpp @@ -50,10 +50,10 @@ const char* infeasible_string(int code) { bool app_not_selected(int appid) { unsigned int i; - if (g_wreq->preferred_apps.size() == 0) return false; - for (i=0; ipreferred_apps.size(); i++) { - if (appid == g_wreq->preferred_apps[i].appid) { - g_wreq->preferred_apps[i].work_available = true; + if (g_wreq->project_prefs.selected_apps.size() == 0) return false; + for (i=0; iproject_prefs.selected_apps.size(); i++) { + if (appid == g_wreq->project_prefs.selected_apps[i].appid) { + g_wreq->project_prefs.selected_apps[i].work_available = true; return false; } } diff --git a/sched/sched_locality.cpp b/sched/sched_locality.cpp index d3c062e0be..a98891fc95 100644 --- a/sched/sched_locality.cpp +++ b/sched/sched_locality.cpp @@ -296,7 +296,7 @@ static int possibly_send_result(SCHED_DB_RESULT& result) { retval = wu.lookup_id(result.workunitid); if (retval) return ERR_DB_NOT_FOUND; - // This doesn't take into account g_wreq->allow_non_preferred_apps, + // This doesn't take into account g_wreq->allow_non_selected_apps, // however Einstein@Home, which is the only project that currently uses // this locality scheduler, doesn't support the respective project-specific // preference setting diff --git a/sched/sched_nci.cpp b/sched/sched_nci.cpp index 6ee3f6dc35..1bfc6abc1f 100644 --- a/sched/sched_nci.cpp +++ b/sched/sched_nci.cpp @@ -163,14 +163,14 @@ int send_nci() { } continue; } - if (app.beta && !g_wreq->allow_beta_work) { + if (app.beta && !g_wreq->project_prefs.allow_beta_work) { if (config.debug_send) { log_messages.printf(MSG_NORMAL, "%s is beta\n", app.name); } continue; } if (app_not_selected(app.id)) { - if (!g_wreq->allow_non_preferred_apps) { + if (!g_wreq->project_prefs.allow_non_selected_apps) { if (config.debug_send) { log_messages.printf(MSG_NORMAL, "%s is not selected\n", app.name diff --git a/sched/sched_score.cpp b/sched/sched_score.cpp index d11130d894..0c6a968bd6 100644 --- a/sched/sched_score.cpp +++ b/sched/sched_score.cpp @@ -64,7 +64,7 @@ bool JOB::get_score(WU_RESULT& wu_result) { } if (app->beta) { - if (g_wreq->allow_beta_work) { + if (g_wreq->project_prefs.allow_beta_work) { score += 1; } else { if (config.debug_send_job) { @@ -78,7 +78,7 @@ bool JOB::get_score(WU_RESULT& wu_result) { } if (app_not_selected(app->id)) { - if (g_wreq->allow_non_preferred_apps) { + if (g_wreq->project_prefs.allow_non_selected_apps) { score -= 1; } else { if (config.debug_send_job) { diff --git a/sched/sched_send.cpp b/sched/sched_send.cpp index 54f2e27179..1699e6dfde 100644 --- a/sched/sched_send.cpp +++ b/sched/sched_send.cpp @@ -64,7 +64,7 @@ // const double DEFAULT_RAM_SIZE = 64000000; -int preferred_app_message_index=0; +int selected_app_message_index=0; static inline bool file_present_on_host(const char* name) { for (unsigned i=0; ifile_infos.size(); i++) { @@ -481,59 +481,6 @@ double estimate_duration(WORKUNIT& wu, BEST_APP_VERSION& bav) { return ed; } -// Parse user's project prferences. -// TODO: use XML_PARSER -// -static void get_prefs_info() { - char buf[8096]; - std::string str; - unsigned int pos = 0; - int temp_int=0; - bool flag; - - extract_venue(g_reply->user.project_prefs, g_reply->host.venue, buf, sizeof(buf)); - str = buf; - - // scan user's project prefs for elements of the form N, - // indicating the apps they want to run. - // - g_wreq->preferred_apps.clear(); - while (parse_int(str.substr(pos,str.length()-pos).c_str(), "", temp_int)) { - APP_INFO ai; - ai.appid = temp_int; - ai.work_available = false; - g_wreq->preferred_apps.push_back(ai); - - pos = str.find("", pos) + 1; - } - if (parse_bool(buf,"allow_non_preferred_apps", flag)) { - g_wreq->allow_non_preferred_apps = flag; - } - if (parse_bool(buf,"allow_beta_work", flag)) { - g_wreq->allow_beta_work = flag; - } - if (parse_bool(buf,"no_gpus", flag)) { - // deprecated, but need to handle - if (flag) { - for (int i=1; idont_use_proc_type[i] = true; - } - } - } - if (parse_bool(buf,"no_cpu", flag)) { - g_wreq->dont_use_proc_type[PROC_TYPE_CPU] = flag; - } - if (parse_bool(buf,"no_cuda", flag)) { - g_wreq->dont_use_proc_type[PROC_TYPE_NVIDIA_GPU] = flag; - } - if (parse_bool(buf,"no_ati", flag)) { - g_wreq->dont_use_proc_type[PROC_TYPE_AMD_GPU] = flag; - } - if (parse_bool(buf,"no_intel_gpu", flag)) { - g_wreq->dont_use_proc_type[PROC_TYPE_INTEL_GPU] = flag; - } -} - void update_n_jobs_today() { for (unsigned int i=0; ihost_app_versions.size(); i++) { DB_HOST_APP_VERSION& hav = g_wreq->host_app_versions[i]; @@ -1256,16 +1203,16 @@ static void send_user_messages() { // Inform the user about applications with no work // - for (i=0; ipreferred_apps.size(); i++) { - if (!g_wreq->preferred_apps[i].work_available) { - APP* app = ssp->lookup_app(g_wreq->preferred_apps[i].appid); + for (i=0; iproject_prefs.selected_apps.size(); i++) { + if (!g_wreq->project_prefs.selected_apps[i].work_available) { + APP* app = ssp->lookup_app(g_wreq->project_prefs.selected_apps[i].appid); // don't write message if the app is deprecated // if (app) { char explanation[256]; sprintf(explanation, "No tasks are available for %s", - find_user_friendly_name(g_wreq->preferred_apps[i].appid) + find_user_friendly_name(g_wreq->project_prefs.selected_apps[i].appid) ); g_reply->insert_message( explanation, "low"); } @@ -1274,7 +1221,7 @@ static void send_user_messages() { // Tell the user about applications they didn't qualify for // - for (j=0; jinsert_message(g_wreq->no_work_messages.at(j)); } g_reply->insert_message( @@ -1295,14 +1242,14 @@ static void send_user_messages() { // Tell the user about applications with no work // - for (i=0; ipreferred_apps.size(); i++) { - if (!g_wreq->preferred_apps[i].work_available) { - APP* app = ssp->lookup_app(g_wreq->preferred_apps[i].appid); + for (i=0; iproject_prefs.selected_apps.size(); i++) { + if (!g_wreq->project_prefs.selected_apps[i].work_available) { + APP* app = ssp->lookup_app(g_wreq->project_prefs.selected_apps[i].appid); // don't write message if the app is deprecated if (app != NULL) { sprintf(buf, "No tasks are available for %s", find_user_friendly_name( - g_wreq->preferred_apps[i].appid + g_wreq->project_prefs.selected_apps[i].appid ) ); g_reply->insert_message(buf, "low"); @@ -1357,7 +1304,7 @@ static void send_user_messages() { ); } for (i=0; idont_use_proc_type[i] && ssp->have_apps_for_proc_type[i]) { + if (g_wreq->project_prefs.dont_use_proc_type[i] && ssp->have_apps_for_proc_type[i]) { sprintf(buf, _("Tasks for %s are available, but your preferences are set to not accept them"), proc_type_name(i) @@ -1410,7 +1357,7 @@ void send_work_setup() { // parse project preferences (e.g. no GPUs) // - get_prefs_info(); + g_wreq->project_prefs.parse(); if (g_wreq->anonymous_platform) { estimate_flops_anon_platform(); diff --git a/sched/sched_send.h b/sched/sched_send.h index eebeca54ee..cee6498575 100644 --- a/sched/sched_send.h +++ b/sched/sched_send.h @@ -56,7 +56,7 @@ extern const char* find_user_friendly_name(int appid); extern bool work_needed(bool); extern void send_work_setup(); extern int effective_ncpus(); -extern int preferred_app_message_index; +extern int selected_app_message_index; extern void update_n_jobs_today(); extern int nfiles_on_host(WORKUNIT&); diff --git a/sched/sched_types.cpp b/sched/sched_types.cpp index 8f47c59819..871a12e2b3 100644 --- a/sched/sched_types.cpp +++ b/sched/sched_types.cpp @@ -169,6 +169,58 @@ int CLIENT_PLATFORM::parse(XML_PARSER& xp) { return ERR_XML_PARSE; } +// Parse user's project preferences. +// TODO: use XML_PARSER +// +void PROJECT_PREFS::parse() { + char buf[8096]; + std::string str; + unsigned int pos = 0; + int temp_int=0; + bool flag; + + extract_venue(g_reply->user.project_prefs, g_reply->host.venue, buf, sizeof(buf)); + str = buf; + + // scan user's project prefs for elements of the form N, + // indicating the apps they want to run. + // + selected_apps.clear(); + while (parse_int(str.substr(pos,str.length()-pos).c_str(), "", temp_int)) { + APP_INFO ai; + ai.appid = temp_int; + ai.work_available = false; + selected_apps.push_back(ai); + + pos = str.find("", pos) + 1; + } + if (parse_bool(buf,"allow_non_selected_apps", flag)) { + allow_non_selected_apps = flag; + } + if (parse_bool(buf,"allow_beta_work", flag)) { + allow_beta_work = flag; + } + if (parse_bool(buf,"no_gpus", flag)) { + // deprecated, but need to handle + if (flag) { + for (int i=1; i selected_apps; + bool dont_use_proc_type[NPROC_TYPES]; + bool allow_non_selected_apps; + bool allow_beta_work; + void parse(); + + PROJECT_PREFS() { + memset(&dont_use_proc_type, 0, sizeof(dont_use_proc_type)); + allow_non_selected_apps = false; + allow_beta_work = false; + } +}; + // summary of a client's request for work, and our response to it -// Note: this is zeroed out in SCHEDULER_REPLY constructor +// Note: this is zeroed out in SCHEDULER_REPLY constructor, +// so don't put any vectors here // struct WORK_REQ_BASE { bool anonymous_platform; @@ -389,12 +406,6 @@ struct WORK_REQ_BASE { // by the client. It may have contained results, // so check and resend just in case. - // user preferences - // - bool dont_use_proc_type[NPROC_TYPES]; - bool allow_non_preferred_apps; - bool allow_beta_work; - bool has_reliable_version; // whether the host has a reliable app version @@ -489,7 +500,7 @@ struct WORK_REQ_BASE { }; struct WORK_REQ : public WORK_REQ_BASE { - std::vector preferred_apps; + PROJECT_PREFS project_prefs; std::vector no_work_messages; std::vector best_app_versions; std::vector host_app_versions; diff --git a/sched/sched_version.cpp b/sched/sched_version.cpp index b0e165d468..bc9559eece 100644 --- a/sched/sched_version.cpp +++ b/sched/sched_version.cpp @@ -699,7 +699,7 @@ BEST_APP_VERSION* get_app_version( if (av.appid != wu.appid) continue; if (av.platformid != p->id) continue; if (av.beta) { - if (!g_wreq->allow_beta_work) { + if (!g_wreq->project_prefs.allow_beta_work) { continue; } } @@ -732,7 +732,7 @@ BEST_APP_VERSION* get_app_version( // skip versions that go against resource prefs // int pt = host_usage.proc_type; - if (g_wreq->dont_use_proc_type[pt]) { + if (g_wreq->project_prefs.dont_use_proc_type[pt]) { if (config.debug_version_select) { log_messages.printf(MSG_NORMAL, "[version] [AV#%lu] Skipping %s version - user prefs say no %s\n",