diff --git a/qmanager/config/queue_system_defaults.hpp b/qmanager/config/queue_system_defaults.hpp index 058f42db4..a67180d6f 100644 --- a/qmanager/config/queue_system_defaults.hpp +++ b/qmanager/config/queue_system_defaults.hpp @@ -13,14 +13,14 @@ namespace Flux { namespace queue_manager { - const unsigned int MAX_QUEUE_DEPTH = 1000000; - const unsigned int DEFAULT_QUEUE_DEPTH = 32; - const unsigned int MAX_RESERVATION_DEPTH = 100000; - const unsigned int HYBRID_RESERVATION_DEPTH = 64; -} // namespace resource_model -} // namespace Flux +const unsigned int MAX_QUEUE_DEPTH = 1000000; +const unsigned int DEFAULT_QUEUE_DEPTH = 32; +const unsigned int MAX_RESERVATION_DEPTH = 100000; +const unsigned int HYBRID_RESERVATION_DEPTH = 64; +} // namespace queue_manager +} // namespace Flux -#endif // QUEUE_SYSTEM_DEFAULT_HPP +#endif // QUEUE_SYSTEM_DEFAULT_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/qmanager/modules/qmanager.cpp b/qmanager/modules/qmanager.cpp index 040174921..7fbd778e3 100644 --- a/qmanager/modules/qmanager.cpp +++ b/qmanager/modules/qmanager.cpp @@ -31,25 +31,23 @@ using namespace Flux::queue_manager::detail; using namespace Flux::opts_manager; using namespace Flux::cplusplus_wrappers; - - //////////////////////////////////////////////////////////////////////////////// // Queue Manager Service Module Context //////////////////////////////////////////////////////////////////////////////// class fluxion_resource_interface_t { -public: + public: ~fluxion_resource_interface_t (); int fetch_and_reset_notify_rc (); int get_notify_rc () const; void set_notify_rc (int rc); flux_future_t *notify_f{nullptr}; -private: + + private: int m_notify_rc = 0; }; -struct qmanager_ctx_t : public qmanager_cb_ctx_t, - public fluxion_resource_interface_t { +struct qmanager_ctx_t : public qmanager_cb_ctx_t, public fluxion_resource_interface_t { flux_msg_handler_t **hndlr{nullptr}; }; @@ -76,8 +74,7 @@ void fluxion_resource_interface_t::set_notify_rc (int rc) m_notify_rc = rc; } -static int process_args (std::shared_ptr &ctx, - int argc, char **argv) +static int process_args (std::shared_ptr &ctx, int argc, char **argv) { int rc = 0; optmgr_kv_t opts_store; @@ -85,15 +82,13 @@ static int process_args (std::shared_ptr &ctx, for (int i = 0; i < argc; i++) { const std::string kv (argv[i]); - if ( (rc = opts_store.put (kv)) < 0) { - flux_log_error (ctx->h, "%s: optmgr_kv_t::put (%s)", - __FUNCTION__, argv[i]); + if ((rc = opts_store.put (kv)) < 0) { + flux_log_error (ctx->h, "%s: optmgr_kv_t::put (%s)", __FUNCTION__, argv[i]); return rc; } } - if ( (rc = opts_store.parse (info_str)) < 0) { - flux_log_error (ctx->h, "%s: optmgr_kv_t::parse: %s", - __FUNCTION__, info_str.c_str ()); + if ((rc = opts_store.parse (info_str)) < 0) { + flux_log_error (ctx->h, "%s: optmgr_kv_t::parse: %s", __FUNCTION__, info_str.c_str ()); return rc; } if (info_str != "") { @@ -111,7 +106,7 @@ static int subtable_dumps (json_t *o, std::string &value) json_object_foreach (o, k, v) { char *str; - if (!(str = json_dumps (v, JSON_ENCODE_ANY|JSON_COMPACT))) { + if (!(str = json_dumps (v, JSON_ENCODE_ANY | JSON_COMPACT))) { errno = ENOMEM; return -1; } @@ -127,12 +122,14 @@ static int process_config_file (std::shared_ptr &ctx) int rc = 0; json_t *qmanager_conf = NULL, *queues_conf = NULL; - if ( (rc = flux_conf_unpack (flux_get_conf (ctx->h), NULL, - "{ s?:o , s?:o }", - "sched-fluxion-qmanager", - &qmanager_conf, - "queues", - &queues_conf)) < 0) { + if ((rc = flux_conf_unpack (flux_get_conf (ctx->h), + NULL, + "{ s?:o , s?:o }", + "sched-fluxion-qmanager", + &qmanager_conf, + "queues", + &queues_conf)) + < 0) { flux_log_error (ctx->h, "%s: flux_conf_unpack", __FUNCTION__); return rc; } @@ -142,34 +139,37 @@ static int process_config_file (std::shared_ptr &ctx) json_t *v = NULL; optmgr_kv_t opts_store; std::string info_str = ""; - if (queues_conf){ + if (queues_conf) { // workaround to satisfy RFC 33 std::ostringstream queues; json_object_foreach (queues_conf, k, v) { - queues << std::string(k) << " "; + queues << std::string (k) << " "; } - if ( (rc = opts_store.put ("queues", queues.str()) ) < 0) { - flux_log_error (ctx->h, "%s: optmgr_kv_t::put ('queues', %s)", - __FUNCTION__, queues.str().c_str()); + if ((rc = opts_store.put ("queues", queues.str ())) < 0) { + flux_log_error (ctx->h, + "%s: optmgr_kv_t::put ('queues', %s)", + __FUNCTION__, + queues.str ().c_str ()); return rc; } } json_object_foreach (qmanager_conf, k, v) { std::string value; - if (k == std::string("queues")) { - flux_log_error (ctx->h, "%s: 'queues' key not supported, " - "use RFC33 format instead", __FUNCTION__); + if (k == std::string ("queues")) { + flux_log_error (ctx->h, + "%s: 'queues' key not supported, " + "use RFC33 format instead", + __FUNCTION__); return -1; } if (json_is_object (v)) { if (subtable_dumps (v, value) < 0) { - flux_log_error (ctx->h, "%s: sub_table_dumps on key=%s", - __FUNCTION__, k); + flux_log_error (ctx->h, "%s: sub_table_dumps on key=%s", __FUNCTION__, k); } if (!value.empty ()) value = value.substr (0, value.length () - 1); } else { - if (!(tmp = json_dumps (v, JSON_ENCODE_ANY|JSON_COMPACT))) { + if (!(tmp = json_dumps (v, JSON_ENCODE_ANY | JSON_COMPACT))) { errno = ENOMEM; return -1; } @@ -179,15 +179,17 @@ static int process_config_file (std::shared_ptr &ctx) if (json_typeof (v) == JSON_STRING) value = value.substr (1, value.length () - 2); } - if ( (rc = opts_store.put (k, value)) < 0) { - flux_log_error (ctx->h, "%s: optmgr_kv_t::put (%s, %s)", - __FUNCTION__, k, value.c_str ()); + if ((rc = opts_store.put (k, value)) < 0) { + flux_log_error (ctx->h, + "%s: optmgr_kv_t::put (%s, %s)", + __FUNCTION__, + k, + value.c_str ()); return rc; } } - if ( (rc = opts_store.parse (info_str)) < 0) { - flux_log_error (ctx->h, "%s: optmgr_kv_t::parse: %s", - __FUNCTION__, info_str.c_str ()); + if ((rc = opts_store.parse (info_str)) < 0) { + flux_log_error (ctx->h, "%s: optmgr_kv_t::parse: %s", __FUNCTION__, info_str.c_str ()); return rc; } if (info_str != "") { @@ -211,10 +213,10 @@ static void update_on_resource_response (flux_future_t *f, void *arg) int rc = -1; qmanager_ctx_t *ctx = static_cast (arg); - if ( (rc = flux_rpc_get (f, NULL)) < 0) { + if ((rc = flux_rpc_get (f, NULL)) < 0) { flux_log_error (ctx->h, - "%s: exiting due to sched-fluxion-resource.notify failure", - __FUNCTION__); + "%s: exiting due to sched-fluxion-resource.notify failure", + __FUNCTION__); flux_reactor_stop (flux_get_reactor (ctx->h)); goto out; } @@ -234,24 +236,22 @@ static int handshake_resource (std::shared_ptr &ctx) { int rc = -1; - if ( !(ctx->notify_f = flux_rpc (ctx->h, "sched-fluxion-resource.notify", - NULL, - FLUX_NODEID_ANY, - FLUX_RPC_STREAMING))) { + if (!(ctx->notify_f = flux_rpc (ctx->h, + "sched-fluxion-resource.notify", + NULL, + FLUX_NODEID_ANY, + FLUX_RPC_STREAMING))) { flux_log_error (ctx->h, "%s: flux_rpc (notify)", __FUNCTION__); goto out; } update_on_resource_response (ctx->notify_f, ctx.get ()); - if ( (rc = ctx->fetch_and_reset_notify_rc ()) < 0) { - flux_log_error (ctx->h, "%s: update_on_resource_response", - __FUNCTION__); + if ((rc = ctx->fetch_and_reset_notify_rc ()) < 0) { + flux_log_error (ctx->h, "%s: update_on_resource_response", __FUNCTION__); goto out; } - if ( (rc = flux_future_then (ctx->notify_f, - -1.0, - update_on_resource_response, - ctx.get ())) < 0) { + if ((rc = flux_future_then (ctx->notify_f, -1.0, update_on_resource_response, ctx.get ())) + < 0) { flux_log_error (ctx->h, "%s: flux_future_then", __FUNCTION__); goto out; } @@ -262,7 +262,7 @@ static int handshake_resource (std::shared_ptr &ctx) static int handshake_jobmanager (std::shared_ptr &ctx) { int rc = -1; - int queue_depth = 0; /* Not implemented in job-manager */ + int queue_depth = 0; /* Not implemented in job-manager */ if (schedutil_hello (ctx->schedutil) < 0) { flux_log_error (ctx->h, "%s: schedutil_hello", __FUNCTION__); @@ -277,17 +277,14 @@ static int handshake_jobmanager (std::shared_ptr &ctx) return rc; } -static void status_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void status_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { int len = 0; const char *payload; flux_future_t *f = NULL; - if ( !(f = flux_rpc (h, "sched-fluxion-resource.status", NULL, - FLUX_NODEID_ANY, 0))) { - flux_log_error (h, "%s: flux_rpc (sched-fluxion-resource.status)", - __FUNCTION__); + if (!(f = flux_rpc (h, "sched-fluxion-resource.status", NULL, FLUX_NODEID_ANY, 0))) { + flux_log_error (h, "%s: flux_rpc (sched-fluxion-resource.status)", __FUNCTION__); goto out; } if (flux_rpc_get_raw (f, (const void **)&payload, &len) < 0) { @@ -307,24 +304,29 @@ static void status_request_cb (flux_t *h, flux_msg_handler_t *w, flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); } -static void feasibility_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void feasibility_request_cb (flux_t *h, + flux_msg_handler_t *w, + const flux_msg_t *msg, + void *arg) { int size = 0; flux_future_t *f = nullptr; const char *data = nullptr; - if (flux_request_decode_raw (msg, nullptr, (const void**)&data, &size) < 0) + if (flux_request_decode_raw (msg, nullptr, (const void **)&data, &size) < 0) goto error; - if ( !(f = flux_rpc_raw (h, "sched-fluxion-resource.satisfiability", - data, size, FLUX_NODEID_ANY, 0))) { - flux_log_error (h, "%s: flux_rpc (sched-fluxion-resource.satisfiability)", - __FUNCTION__); + if (!(f = flux_rpc_raw (h, + "sched-fluxion-resource.satisfiability", + data, + size, + FLUX_NODEID_ANY, + 0))) { + flux_log_error (h, "%s: flux_rpc (sched-fluxion-resource.satisfiability)", __FUNCTION__); goto error; } - if (flux_rpc_get_raw (f, (const void**)&data, &size) < 0) + if (flux_rpc_get_raw (f, (const void **)&data, &size) < 0) goto error; - if (flux_respond_raw (h, msg, (const void*)data, size) < 0) { + if (flux_respond_raw (h, msg, (const void *)data, size) < 0) { flux_log_error (h, "%s: flux_respond_raw", __FUNCTION__); goto error; } @@ -338,9 +340,7 @@ static void feasibility_request_cb (flux_t *h, flux_msg_handler_t *w, flux_future_destroy (f); } - -static void params_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void params_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { int saved_errno; json_error_t jerr; @@ -351,7 +351,7 @@ static void params_request_cb (flux_t *h, flux_msg_handler_t *w, if (!(d = flux_aux_get (h, "sched-fluxion-qmanager"))) goto error; - ctx = *(static_cast *>(d)); + ctx = *(static_cast *> (d)); if (ctx->opts.jsonify (params) < 0) goto error; if (!(o = json_loads (params.c_str (), 0, &jerr))) { @@ -380,19 +380,17 @@ static int enforce_queue_policy (std::shared_ptr &ctx, { int rc = -1; std::shared_ptr queue; - std::pair>::iterator, - bool> ret; - if ( !(queue = create_queue_policy (p.get_queue_policy (), "module"))) { + std::pair>::iterator, bool> ret; + if (!(queue = create_queue_policy (p.get_queue_policy (), "module"))) { errno = EINVAL; - flux_log_error (ctx->h, "%s: create_queue_policy (%s)", + flux_log_error (ctx->h, + "%s: create_queue_policy (%s)", __FUNCTION__, p.get_queue_policy ().c_str ()); goto out; } ret = ctx->queues.insert ( - std::pair> ( - queue_name, queue)); + std::pair> (queue_name, queue)); if (!ret.second) { errno = EEXIST; goto out; @@ -414,19 +412,24 @@ static int enforce_params (std::shared_ptr &ctx, const std::string &policy_params = prop.get_policy_params (); if (prop.is_queue_params_set () && queue_params != "" && ctx->queues.at (queue_name)->set_queue_params (queue_params) < 0) { - flux_log_error (ctx->h, "%s: queues[%s]->set_queue_params (%s)", - __FUNCTION__, queue_name.c_str (), queue_params.c_str ()); + flux_log_error (ctx->h, + "%s: queues[%s]->set_queue_params (%s)", + __FUNCTION__, + queue_name.c_str (), + queue_params.c_str ()); return -1; } if (prop.is_policy_params_set () && policy_params != "" && ctx->queues.at (queue_name)->set_policy_params (policy_params) < 0) { - flux_log_error (ctx->h, "%s: queues[%s]->set_policy_params (%s)", - __FUNCTION__, queue_name.c_str (), policy_params.c_str ()); + flux_log_error (ctx->h, + "%s: queues[%s]->set_policy_params (%s)", + __FUNCTION__, + queue_name.c_str (), + policy_params.c_str ()); return -1; } if (ctx->queues.at (queue_name)->apply_params () < 0) { - flux_log_error (ctx->h, "%s: queue[%s]->apply_params", - __FUNCTION__, queue_name.c_str ()); + flux_log_error (ctx->h, "%s: queue[%s]->apply_params", __FUNCTION__, queue_name.c_str ()); return -1; } return 0; @@ -436,8 +439,8 @@ static int enforce_queues (std::shared_ptr &ctx) { int rc = 0; ctx->opts.canonicalize (); - const std::map &per_queue_prop - = ctx->opts.get_opt ().get_per_queue_prop (); + const std::map &per_queue_prop = + ctx->opts.get_opt ().get_per_queue_prop (); for (const auto &kv : per_queue_prop) { std::string res_qp = ""; @@ -445,14 +448,16 @@ static int enforce_queues (std::shared_ptr &ctx) const std::string &queue_name = kv.first; const queue_prop_t &queue_prop = kv.second; - if ( (rc = enforce_queue_policy (ctx, queue_name, queue_prop)) < 0) + if ((rc = enforce_queue_policy (ctx, queue_name, queue_prop)) < 0) goto out; - flux_log (ctx->h, LOG_DEBUG, - "enforced policy (queue=%s): %s", queue_name.c_str (), + flux_log (ctx->h, + LOG_DEBUG, + "enforced policy (queue=%s): %s", + queue_name.c_str (), queue_prop.get_queue_policy ().c_str ()); - if ( (rc = enforce_params (ctx, queue_name, queue_prop)) < 0) + if ((rc = enforce_params (ctx, queue_name, queue_prop)) < 0) goto out; ctx->queues.at (queue_name)->get_params (res_qp, res_pp); @@ -460,12 +465,16 @@ static int enforce_queues (std::shared_ptr &ctx) res_qp = std::string ("default"); if (res_pp.empty ()) res_pp = std::string ("default"); - flux_log (ctx->h, LOG_DEBUG, + flux_log (ctx->h, + LOG_DEBUG, "effective queue params (queue=%s): %s", - queue_name.c_str (), res_qp.c_str ()); - flux_log (ctx->h, LOG_DEBUG, + queue_name.c_str (), + res_qp.c_str ()); + flux_log (ctx->h, + LOG_DEBUG, "effective policy params (queue=%s): %s", - queue_name.c_str (), res_pp.c_str ()); + queue_name.c_str (), + res_pp.c_str ()); } out: @@ -476,7 +485,7 @@ static int enforce_options (std::shared_ptr &ctx) { int rc = 0; - if ( (rc = enforce_queues (ctx)) < 0) { + if ((rc = enforce_queues (ctx)) < 0) { flux_log_error (ctx->h, "%s: enforce_queues", __FUNCTION__); return rc; } @@ -487,27 +496,25 @@ static int handshake (std::shared_ptr &ctx) { int rc = 0; - if ( (rc = handshake_resource (ctx)) < 0) { + if ((rc = handshake_resource (ctx)) < 0) { flux_log_error (ctx->h, "%s: handshake_resource", __FUNCTION__); return rc; } - flux_log (ctx->h, LOG_DEBUG, - "handshaking with sched-fluxion-resource completed"); + flux_log (ctx->h, LOG_DEBUG, "handshaking with sched-fluxion-resource completed"); - if ( (rc = handshake_jobmanager (ctx)) < 0) { + if ((rc = handshake_jobmanager (ctx)) < 0) { flux_log_error (ctx->h, "%s: handshake_jobmanager", __FUNCTION__); return rc; } - flux_log (ctx->h, LOG_DEBUG, - "handshaking with job-manager completed"); + flux_log (ctx->h, LOG_DEBUG, "handshaking with job-manager completed"); return rc; } const struct schedutil_ops ops = { - .hello = &qmanager_safe_cb_t::jobmanager_hello_cb, - .alloc = &qmanager_safe_cb_t::jobmanager_alloc_cb, - .free = &qmanager_safe_cb_t::jobmanager_free_cb, + .hello = &qmanager_safe_cb_t::jobmanager_hello_cb, + .alloc = &qmanager_safe_cb_t::jobmanager_alloc_cb, + .free = &qmanager_safe_cb_t::jobmanager_free_cb, .cancel = &qmanager_safe_cb_t::jobmanager_cancel_cb, .prioritize = &qmanager_safe_cb_t::jobmanager_prioritize_cb, }; @@ -526,20 +533,19 @@ static std::shared_ptr qmanager_new (flux_t *h) ctx = nullptr; goto done; } - if (!(ctx->prep = flux_prepare_watcher_create ( - reactor, - &qmanager_safe_cb_t::prep_watcher_cb, - std::static_pointer_cast< - qmanager_ctx_t> (ctx).get ()))) { + if (!(ctx->prep = + flux_prepare_watcher_create (reactor, + &qmanager_safe_cb_t::prep_watcher_cb, + std::static_pointer_cast (ctx) + .get ()))) { flux_log_error (h, "%s: flux_prepare_watcher_create", __FUNCTION__); ctx = nullptr; goto done; } - if (!(ctx->check = flux_check_watcher_create ( - reactor, - &qmanager_safe_cb_t::check_watcher_cb, - std::static_pointer_cast< - qmanager_ctx_t> (ctx).get ()))) { + if (!(ctx->check = flux_check_watcher_create (reactor, + &qmanager_safe_cb_t::check_watcher_cb, + std::static_pointer_cast (ctx) + .get ()))) { flux_log_error (h, "%s: flux_check_watcher_create", __FUNCTION__); ctx = nullptr; goto done; @@ -551,11 +557,11 @@ static std::shared_ptr qmanager_new (flux_t *h) ctx = nullptr; goto done; } - if (!(ctx->schedutil = schedutil_create (ctx->h, - SCHEDUTIL_FREE_NOLOOKUP, - &ops, - std::static_pointer_cast< - qmanager_cb_ctx_t> (ctx).get ()))) { + if (!(ctx->schedutil = + schedutil_create (ctx->h, + SCHEDUTIL_FREE_NOLOOKUP, + &ops, + std::static_pointer_cast (ctx).get ()))) { flux_log_error (ctx->h, "%s: schedutil_create", __FUNCTION__); ctx = nullptr; goto done; @@ -577,8 +583,7 @@ static void qmanager_destroy (std::shared_ptr &ctx) int saved_errno = errno; std::shared_ptr job; for (auto kv : ctx->queues) { - while ( (job = ctx->queues.at (kv.first)->pending_pop ()) - != nullptr) + while ((job = ctx->queues.at (kv.first)->pending_pop ()) != nullptr) flux_respond_error (ctx->h, job->msg, ENOSYS, "unloading"); } schedutil_destroy (ctx->schedutil); @@ -591,17 +596,12 @@ static void qmanager_destroy (std::shared_ptr &ctx) } static const struct flux_msg_handler_spec htab[] = { - { FLUX_MSGTYPE_REQUEST, - "sched.resource-status", status_request_cb, FLUX_ROLE_USER }, - { FLUX_MSGTYPE_REQUEST, - "*.feasibility", feasibility_request_cb, FLUX_ROLE_USER }, - { FLUX_MSGTYPE_REQUEST, - "*.params", params_request_cb, FLUX_ROLE_USER }, + {FLUX_MSGTYPE_REQUEST, "sched.resource-status", status_request_cb, FLUX_ROLE_USER}, + {FLUX_MSGTYPE_REQUEST, "*.feasibility", feasibility_request_cb, FLUX_ROLE_USER}, + {FLUX_MSGTYPE_REQUEST, "*.params", params_request_cb, FLUX_ROLE_USER}, FLUX_MSGHANDLER_TABLE_END, }; - - //////////////////////////////////////////////////////////////////////////////// // Module Main //////////////////////////////////////////////////////////////////////////////// @@ -610,7 +610,7 @@ int mod_start (flux_t *h, int argc, char **argv) { int rc = -1; std::shared_ptr ctx = nullptr; - if ( !(ctx = qmanager_new (h))) { + if (!(ctx = qmanager_new (h))) { flux_log_error (h, "%s: qmanager_new", __FUNCTION__); return rc; } @@ -618,41 +618,41 @@ int mod_start (flux_t *h, int argc, char **argv) // Because mod_main is always active, the following is safe. flux_aux_set (h, "sched-fluxion-qmanager", &ctx, nullptr); - if ( (rc = process_config_file (ctx)) < 0) { + if ((rc = process_config_file (ctx)) < 0) { flux_log_error (h, "%s: config file parsing", __FUNCTION__); qmanager_destroy (ctx); return rc; } - if ( (rc = process_args (ctx, argc, argv)) < 0) { + if ((rc = process_args (ctx, argc, argv)) < 0) { flux_log_error (h, "%s: load line argument parsing", __FUNCTION__); qmanager_destroy (ctx); return rc; } - if ( (rc = enforce_options (ctx)) < 0) { + if ((rc = enforce_options (ctx)) < 0) { flux_log_error (h, "%s: enforce_options", __FUNCTION__); qmanager_destroy (ctx); return rc; } /* Before beginning synchronous handshakes with fluxion-resource - * and job-manager, set module status to 'running' to let flux module load - * return success. - */ - if ( (rc = flux_module_set_running (ctx->h)) < 0) { + * and job-manager, set module status to 'running' to let flux module load + * return success. + */ + if ((rc = flux_module_set_running (ctx->h)) < 0) { flux_log_error (ctx->h, "%s: flux_module_set_running", __FUNCTION__); qmanager_destroy (ctx); return rc; } - if ( (rc = handshake (ctx)) < 0) { + if ((rc = handshake (ctx)) < 0) { flux_log_error (h, "%s: handshake", __FUNCTION__); qmanager_destroy (ctx); return rc; } - if ( (rc = flux_msg_handler_addvec (h, htab, (void *)h, &ctx->hndlr)) < 0) { + if ((rc = flux_msg_handler_addvec (h, htab, (void *)h, &ctx->hndlr)) < 0) { flux_log_error (h, "%s: flux_msg_handler_addvec", __FUNCTION__); qmanager_destroy (ctx); return rc; } - if ( (rc = flux_reactor_run (flux_get_reactor (h), 0)) < 0) + if ((rc = flux_reactor_run (flux_get_reactor (h), 0)) < 0) flux_log_error (h, "%s: flux_reactor_run", __FUNCTION__); qmanager_destroy (ctx); return rc; @@ -666,8 +666,7 @@ extern "C" int mod_main (flux_t *h, int argc, char **argv) int rc = exception_safe_main (mod_start, h, argc, argv); if (exception_safe_main.bad ()) - flux_log_error (h, "%s: %s", __FUNCTION__, - exception_safe_main.get_err_message ()); + flux_log_error (h, "%s: %s", __FUNCTION__, exception_safe_main.get_err_message ()); return rc; } diff --git a/qmanager/modules/qmanager_callbacks.cpp b/qmanager/modules/qmanager_callbacks.cpp index 873310ba1..45bcbf0a2 100644 --- a/qmanager/modules/qmanager_callbacks.cpp +++ b/qmanager/modules/qmanager_callbacks.cpp @@ -49,43 +49,45 @@ int qmanager_cb_ctx_t::find_queue (flux_jobid_t id, return -1; } -int qmanager_cb_t::post_sched_loop (flux_t *h, schedutil_t *schedutil, - std::map> &queues) +int qmanager_cb_t::post_sched_loop ( + flux_t *h, + schedutil_t *schedutil, + std::map> &queues) { int rc = -1; unsigned int qd = 0; std::shared_ptr job = nullptr; - for (auto& kv: queues) { + for (auto &kv : queues) { const std::string &queue_name = kv.first; std::shared_ptr &queue = kv.second; - while ( (job = queue->alloced_pop ()) != nullptr) { - if (schedutil_alloc_respond_success_pack (schedutil, job->msg, + while ((job = queue->alloced_pop ()) != nullptr) { + if (schedutil_alloc_respond_success_pack (schedutil, + job->msg, job->schedule.R.c_str (), "{ s:{s:n} }", "sched", - "t_estimate") < 0) { - flux_log_error (h, "%s: schedutil_alloc_respond_pack (queue=%s)", - __FUNCTION__, queue_name.c_str ()); + "t_estimate") + < 0) { + flux_log_error (h, + "%s: schedutil_alloc_respond_pack (queue=%s)", + __FUNCTION__, + queue_name.c_str ()); goto out; } } - while ( (job = queue->rejected_pop ()) != nullptr) { + while ((job = queue->rejected_pop ()) != nullptr) { std::string note = "alloc denied due to type=\"" + job->note + "\""; - if (schedutil_alloc_respond_deny (schedutil, - job->msg, - note.c_str ()) < 0) { + if (schedutil_alloc_respond_deny (schedutil, job->msg, note.c_str ()) < 0) { flux_log_error (h, "%s: schedutil_alloc_respond_deny (queue=%s)", - __FUNCTION__, queue_name.c_str ()); + __FUNCTION__, + queue_name.c_str ()); goto out; } } - while ( (job = queue->canceled_pop ()) != nullptr) { + while ((job = queue->canceled_pop ()) != nullptr) { if (schedutil_alloc_respond_cancel (schedutil, job->msg) < 0) { - flux_log_error (h, "%s: schedutil_alloc_respond_cancel", - __FUNCTION__); + flux_log_error (h, "%s: schedutil_alloc_respond_cancel", __FUNCTION__); goto out; } } @@ -95,13 +97,13 @@ int qmanager_cb_t::post_sched_loop (flux_t *h, schedutil_t *schedutil, // if old_at == at, then no reason to send this annotation again. if (job->schedule.at == job->schedule.old_at) continue; - if (schedutil_alloc_respond_annotate_pack ( - schedutil, job->msg, - "{ s:{s:f} }", - "sched", - "t_estimate", static_cast (job->schedule.at))) { - flux_log_error (h, "%s: schedutil_alloc_respond_annotate_pack", - __FUNCTION__); + if (schedutil_alloc_respond_annotate_pack (schedutil, + job->msg, + "{ s:{s:f} }", + "sched", + "t_estimate", + static_cast (job->schedule.at))) { + flux_log_error (h, "%s: schedutil_alloc_respond_annotate_pack", __FUNCTION__); goto out; } } @@ -132,8 +134,7 @@ int qmanager_cb_t::post_sched_loop (flux_t *h, schedutil_t *schedutil, * valid queue. This can occur if queues have been reconfigured since job * submission. */ -int qmanager_cb_t::jobmanager_hello_cb (flux_t *h, const flux_msg_t *msg, - const char *R, void *arg) +int qmanager_cb_t::jobmanager_hello_cb (flux_t *h, const flux_msg_t *msg, const char *R, void *arg) { int rc = -1; @@ -156,16 +157,22 @@ int qmanager_cb_t::jobmanager_hello_cb (flux_t *h, const flux_msg_t *msg, */ if (flux_msg_unpack (msg, "{s:I s:i s:i s:f s?o}", - "id", &id, - "priority", &prio, - "userid", &uid, - "t_submit", &ts, - "jobspec", &jobspec) < 0) { + "id", + &id, + "priority", + &prio, + "userid", + &uid, + "t_submit", + &ts, + "jobspec", + &jobspec) + < 0) { flux_log_error (h, "%s: flux_msg_unpack", __FUNCTION__); goto out; } if (!jobspec) { - char key[64] = { 0 }; + char key[64] = {0}; if (flux_job_kvs_key (key, sizeof (key), id, "jobspec") < 0 || !(f = flux_kvs_lookup (h, NULL, 0, key)) || flux_kvs_lookup_get_unpack (f, "o", &jobspec) < 0) { @@ -173,11 +180,7 @@ int qmanager_cb_t::jobmanager_hello_cb (flux_t *h, const flux_msg_t *msg, goto out; } } - if (json_unpack (jobspec, - "{s?{s?{s?s}}}", - "attributes", - "system", - "queue", &qn_attr) < 0) { + if (json_unpack (jobspec, "{s?{s?{s?s}}}", "attributes", "system", "queue", &qn_attr) < 0) { flux_log_error (h, "error parsing jobspec"); goto out; } @@ -195,25 +198,29 @@ int qmanager_cb_t::jobmanager_hello_cb (flux_t *h, const flux_msg_t *msg, goto out; } queue = ctx->queues.at (queue_name); - running_job = std::make_shared (job_state_kind_t::RUNNING, - id, uid, calc_priority (prio), - ts, R); + running_job = + std::make_shared (job_state_kind_t::RUNNING, id, uid, calc_priority (prio), ts, R); if (queue->reconstruct (static_cast (h), running_job, R_out) < 0) { - flux_log_error (h, "%s: reconstruct (id=%jd queue=%s)", __FUNCTION__, - static_cast (id), queue_name.c_str ()); + flux_log_error (h, + "%s: reconstruct (id=%jd queue=%s)", + __FUNCTION__, + static_cast (id), + queue_name.c_str ()); goto out; } - flux_log (h, LOG_DEBUG, "requeue success (queue=%s id=%jd)", - queue_name.c_str (), static_cast (id)); + flux_log (h, + LOG_DEBUG, + "requeue success (queue=%s id=%jd)", + queue_name.c_str (), + static_cast (id)); rc = 0; out: flux_future_destroy (f); return rc; } -void qmanager_cb_t::jobmanager_alloc_cb (flux_t *h, const flux_msg_t *msg, - void *arg) +void qmanager_cb_t::jobmanager_alloc_cb (flux_t *h, const flux_msg_t *msg, void *arg) { qmanager_cb_ctx_t *ctx = nullptr; ctx = static_cast (arg); @@ -230,11 +237,17 @@ void qmanager_cb_t::jobmanager_alloc_cb (flux_t *h, const flux_msg_t *msg, if (flux_msg_unpack (msg, "{s:I s:i s:i s:f s:o}", - "id", &id, - "priority", &priority, - "userid", &userid, - "t_submit", &t_submit, - "jobspec", &jobspec) < 0) { + "id", + &id, + "priority", + &priority, + "userid", + &userid, + "t_submit", + &t_submit, + "jobspec", + &jobspec) + < 0) { flux_log_error (h, "%s: flux_msg_unpack", __FUNCTION__); return; } @@ -249,10 +262,9 @@ void qmanager_cb_t::jobmanager_alloc_cb (flux_t *h, const flux_msg_t *msg, job->priority = calc_priority (priority); try { jobspec_obj = Flux::Jobspec::Jobspec (jobspec_str); - } catch (const Flux::Jobspec::parse_error& e) { + } catch (const Flux::Jobspec::parse_error &e) { if (schedutil_alloc_respond_deny (ctx->schedutil, msg, e.what ()) < 0) - flux_log_error (h, "%s: schedutil_alloc_respond_deny", - __FUNCTION__); + flux_log_error (h, "%s: schedutil_alloc_respond_deny", __FUNCTION__); free (jobspec_str); return; } @@ -261,13 +273,9 @@ void qmanager_cb_t::jobmanager_alloc_cb (flux_t *h, const flux_msg_t *msg, job->jobspec = jobspec_str; free (jobspec_str); if (ctx->queues.find (queue_name) == ctx->queues.end ()) { - snprintf (errbuf, - sizeof (errbuf), - "queue (%s) doesn't exist", - queue_name.c_str()); + snprintf (errbuf, sizeof (errbuf), "queue (%s) doesn't exist", queue_name.c_str ()); if (schedutil_alloc_respond_deny (ctx->schedutil, msg, errbuf) < 0) - flux_log_error (h, "%s: schedutil_alloc_respond_deny", - __FUNCTION__); + flux_log_error (h, "%s: schedutil_alloc_respond_deny", __FUNCTION__); errno = ENOENT; return; } @@ -278,18 +286,18 @@ void qmanager_cb_t::jobmanager_alloc_cb (flux_t *h, const flux_msg_t *msg, snprintf (errbuf, sizeof (errbuf), "fluxion could not insert job into queue %s", - queue_name.c_str()); - flux_log_error (h, "%s: queue insert (id=%jd)", __FUNCTION__, - static_cast (job->id)); + queue_name.c_str ()); + flux_log_error (h, + "%s: queue insert (id=%jd)", + __FUNCTION__, + static_cast (job->id)); if (schedutil_alloc_respond_deny (ctx->schedutil, msg, errbuf) < 0) - flux_log_error (h, "%s: schedutil_alloc_respond_deny", - __FUNCTION__); + flux_log_error (h, "%s: schedutil_alloc_respond_deny", __FUNCTION__); return; } } -void qmanager_cb_t::jobmanager_free_cb (flux_t *h, const flux_msg_t *msg, - const char *R, void *arg) +void qmanager_cb_t::jobmanager_free_cb (flux_t *h, const flux_msg_t *msg, const char *R, void *arg) { flux_jobid_t id; json_t *Res; @@ -299,8 +307,7 @@ void qmanager_cb_t::jobmanager_free_cb (flux_t *h, const flux_msg_t *msg, std::shared_ptr queue; std::string queue_name; - if (flux_request_unpack (msg, NULL, "{s:I s:O}", - "id", &id, "R", &Res) < 0) { + if (flux_request_unpack (msg, NULL, "{s:I s:O}", "id", &id, "R", &Res) < 0) { flux_log_error (h, "%s: flux_request_unpack", __FUNCTION__); return; } @@ -310,13 +317,18 @@ void qmanager_cb_t::jobmanager_free_cb (flux_t *h, const flux_msg_t *msg, goto done; } if (ctx->find_queue (id, queue_name, queue) < 0) { - flux_log_error (h, "%s: can't find queue for job (id=%jd)", - __FUNCTION__, static_cast (id)); + flux_log_error (h, + "%s: can't find queue for job (id=%jd)", + __FUNCTION__, + static_cast (id)); goto done; } - if ( (queue->remove (static_cast (h), id, Rstr)) < 0) { - flux_log_error (h, "%s: remove (queue=%s id=%jd)", __FUNCTION__, - queue_name.c_str (), static_cast (id)); + if ((queue->remove (static_cast (h), id, Rstr)) < 0) { + flux_log_error (h, + "%s: remove (queue=%s id=%jd)", + __FUNCTION__, + queue_name.c_str (), + static_cast (id)); goto done; } if (schedutil_free_respond (ctx->schedutil, msg) < 0) { @@ -330,8 +342,7 @@ void qmanager_cb_t::jobmanager_free_cb (flux_t *h, const flux_msg_t *msg, return; } -void qmanager_cb_t::jobmanager_cancel_cb (flux_t *h, const flux_msg_t *msg, - void *arg) +void qmanager_cb_t::jobmanager_cancel_cb (flux_t *h, const flux_msg_t *msg, void *arg) { std::shared_ptr job; qmanager_cb_ctx_t *ctx = nullptr; @@ -345,22 +356,21 @@ void qmanager_cb_t::jobmanager_cancel_cb (flux_t *h, const flux_msg_t *msg, return; } if (ctx->find_queue (id, queue_name, queue) < 0) { - flux_log_error (h, "%s: queue not found for job (id=%jd)", - __FUNCTION__, static_cast (id)); + flux_log_error (h, + "%s: queue not found for job (id=%jd)", + __FUNCTION__, + static_cast (id)); return; } - if ((job = queue->lookup (id)) == nullptr - || !job->is_pending ()) + if ((job = queue->lookup (id)) == nullptr || !job->is_pending ()) return; if (queue->remove_pending (job.get ()) < 0) { - flux_log_error (h, "%s: remove job (%jd)", __FUNCTION__, - static_cast (id)); + flux_log_error (h, "%s: remove job (%jd)", __FUNCTION__, static_cast (id)); return; } } -void qmanager_cb_t::jobmanager_prioritize_cb (flux_t *h, const flux_msg_t *msg, - void *arg) +void qmanager_cb_t::jobmanager_prioritize_cb (flux_t *h, const flux_msg_t *msg, void *arg) { qmanager_cb_ctx_t *ctx = nullptr; ctx = static_cast (arg); @@ -380,54 +390,55 @@ void qmanager_cb_t::jobmanager_prioritize_cb (flux_t *h, const flux_msg_t *msg, unsigned int priority; if (json_unpack (arr, "[I,i]", &id, &priority) < 0) { - flux_log_error (h, "%s: invalid prioritize entry", - __FUNCTION__); + flux_log_error (h, "%s: invalid prioritize entry", __FUNCTION__); return; } if (ctx->find_queue (id, queue_name, queue) < 0) { - flux_log_error (h, "%s: queue not found for job (id=%jd)", - __FUNCTION__, static_cast (id)); + flux_log_error (h, + "%s: queue not found for job (id=%jd)", + __FUNCTION__, + static_cast (id)); continue; } if (queue->pending_reprioritize (id, calc_priority (priority)) < 0) { if (errno == ENOENT) { - flux_log_error (h, "invalid job reprioritized (id=%jd)", + flux_log_error (h, + "invalid job reprioritized (id=%jd)", static_cast (id)); continue; - } - else if (errno == EINVAL) { - flux_log_error (h, "reprioritized non-pending job (id=%jd)", + } else if (errno == EINVAL) { + flux_log_error (h, + "reprioritized non-pending job (id=%jd)", static_cast (id)); continue; } - flux_log_error (h, "%s: queue pending_reprioritize (id=%jd)", - __FUNCTION__, static_cast (id)); + flux_log_error (h, + "%s: queue pending_reprioritize (id=%jd)", + __FUNCTION__, + static_cast (id)); return; } } } -void qmanager_cb_t::prep_watcher_cb (flux_reactor_t *r, flux_watcher_t *w, - int revents, void *arg) +void qmanager_cb_t::prep_watcher_cb (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg) { qmanager_cb_ctx_t *ctx = nullptr; ctx = static_cast (arg); ctx->pls_sched_loop = false; ctx->pls_post_loop = false; - for (auto &kv: ctx->queues) { + for (auto &kv : ctx->queues) { std::shared_ptr &queue = kv.second; ctx->pls_sched_loop = ctx->pls_sched_loop || queue->is_schedulable (); - ctx->pls_post_loop = ctx->pls_post_loop - || queue->is_scheduled (); + ctx->pls_post_loop = ctx->pls_post_loop || queue->is_scheduled (); } if (ctx->pls_sched_loop || ctx->pls_post_loop) flux_watcher_start (ctx->idle); } -void qmanager_cb_t::check_watcher_cb (flux_reactor_t *r, flux_watcher_t *w, - int revents, void *arg) +void qmanager_cb_t::check_watcher_cb (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg) { qmanager_cb_ctx_t *ctx = nullptr; ctx = static_cast (arg); @@ -437,7 +448,7 @@ void qmanager_cb_t::check_watcher_cb (flux_reactor_t *r, flux_watcher_t *w, if (!ctx->pls_sched_loop && !ctx->pls_post_loop) return; if (ctx->pls_sched_loop) { - for (auto &kv: ctx->queues) { + for (auto &kv : ctx->queues) { std::shared_ptr &queue = kv.second; if (queue->run_sched_loop (static_cast (ctx->h), true) < 0) { if (errno == EAGAIN) @@ -445,7 +456,7 @@ void qmanager_cb_t::check_watcher_cb (flux_reactor_t *r, flux_watcher_t *w, flux_log_error (ctx->h, "%s: run_sched_loop", __FUNCTION__); return; } - } + } } if (post_sched_loop (ctx->h, ctx->schedutil, ctx->queues) < 0) { flux_log_error (ctx->h, "%s: post_sched_loop", __FUNCTION__); @@ -453,99 +464,89 @@ void qmanager_cb_t::check_watcher_cb (flux_reactor_t *r, flux_watcher_t *w, } } -int qmanager_safe_cb_t::jobmanager_hello_cb (flux_t *h, const flux_msg_t *msg, - const char *R, void *arg) +int qmanager_safe_cb_t::jobmanager_hello_cb (flux_t *h, + const flux_msg_t *msg, + const char *R, + void *arg) { eh_wrapper_t exception_safe_wrapper; - int rc = exception_safe_wrapper (qmanager_cb_t::jobmanager_hello_cb, - h, msg, R, arg); + int rc = exception_safe_wrapper (qmanager_cb_t::jobmanager_hello_cb, h, msg, R, arg); if (exception_safe_wrapper.bad ()) - flux_log_error (h, "%s: %s", __FUNCTION__, - exception_safe_wrapper.get_err_message ()); + flux_log_error (h, "%s: %s", __FUNCTION__, exception_safe_wrapper.get_err_message ()); return rc; } -void qmanager_safe_cb_t::jobmanager_alloc_cb (flux_t *h, const flux_msg_t *msg, - void *arg) +void qmanager_safe_cb_t::jobmanager_alloc_cb (flux_t *h, const flux_msg_t *msg, void *arg) { eh_wrapper_t exception_safe_wrapper; - exception_safe_wrapper (qmanager_cb_t::jobmanager_alloc_cb, - h, msg, arg); + exception_safe_wrapper (qmanager_cb_t::jobmanager_alloc_cb, h, msg, arg); if (exception_safe_wrapper.bad ()) - flux_log_error (h, "%s: %s", __FUNCTION__, - exception_safe_wrapper.get_err_message ()); + flux_log_error (h, "%s: %s", __FUNCTION__, exception_safe_wrapper.get_err_message ()); } -void qmanager_safe_cb_t::jobmanager_free_cb (flux_t *h, const flux_msg_t *msg, - const char *R, void *arg) +void qmanager_safe_cb_t::jobmanager_free_cb (flux_t *h, + const flux_msg_t *msg, + const char *R, + void *arg) { eh_wrapper_t exception_safe_wrapper; exception_safe_wrapper (qmanager_cb_t::jobmanager_free_cb, h, msg, R, arg); if (exception_safe_wrapper.bad ()) - flux_log_error (h, "%s: %s", __FUNCTION__, - exception_safe_wrapper.get_err_message ()); + flux_log_error (h, "%s: %s", __FUNCTION__, exception_safe_wrapper.get_err_message ()); } -void qmanager_safe_cb_t::jobmanager_cancel_cb (flux_t *h, const flux_msg_t *msg, - void *arg) +void qmanager_safe_cb_t::jobmanager_cancel_cb (flux_t *h, const flux_msg_t *msg, void *arg) { eh_wrapper_t exception_safe_wrapper; - exception_safe_wrapper (qmanager_cb_t::jobmanager_cancel_cb, - h, msg, arg); + exception_safe_wrapper (qmanager_cb_t::jobmanager_cancel_cb, h, msg, arg); if (exception_safe_wrapper.bad ()) - flux_log_error (h, "%s: %s", __FUNCTION__, - exception_safe_wrapper.get_err_message ()); + flux_log_error (h, "%s: %s", __FUNCTION__, exception_safe_wrapper.get_err_message ()); } -void qmanager_safe_cb_t::jobmanager_prioritize_cb (flux_t *h, - const flux_msg_t *msg, - void *arg) +void qmanager_safe_cb_t::jobmanager_prioritize_cb (flux_t *h, const flux_msg_t *msg, void *arg) { eh_wrapper_t exception_safe_wrapper; - exception_safe_wrapper (qmanager_cb_t::jobmanager_prioritize_cb, - h, msg, arg); + exception_safe_wrapper (qmanager_cb_t::jobmanager_prioritize_cb, h, msg, arg); if (exception_safe_wrapper.bad ()) - flux_log_error (h, "%s: %s", __FUNCTION__, - exception_safe_wrapper.get_err_message ()); + flux_log_error (h, "%s: %s", __FUNCTION__, exception_safe_wrapper.get_err_message ()); } -void qmanager_safe_cb_t::prep_watcher_cb (flux_reactor_t *r, flux_watcher_t *w, - int revents, void *arg) +void qmanager_safe_cb_t::prep_watcher_cb (flux_reactor_t *r, + flux_watcher_t *w, + int revents, + void *arg) { eh_wrapper_t exception_safe_wrapper; exception_safe_wrapper (qmanager_cb_t::prep_watcher_cb, r, w, revents, arg); if (exception_safe_wrapper.bad ()) { flux_t *h = flux_handle_watcher_get_flux (w); - flux_log_error (h, "%s: %s", __FUNCTION__, - exception_safe_wrapper.get_err_message ()); + flux_log_error (h, "%s: %s", __FUNCTION__, exception_safe_wrapper.get_err_message ()); } } -void qmanager_safe_cb_t::check_watcher_cb (flux_reactor_t *r, flux_watcher_t *w, - int revents, void *arg) +void qmanager_safe_cb_t::check_watcher_cb (flux_reactor_t *r, + flux_watcher_t *w, + int revents, + void *arg) { eh_wrapper_t exception_safe_wrapper; - exception_safe_wrapper (qmanager_cb_t::check_watcher_cb, - r, w, revents, arg); + exception_safe_wrapper (qmanager_cb_t::check_watcher_cb, r, w, revents, arg); if (exception_safe_wrapper.bad ()) { flux_t *h = flux_handle_watcher_get_flux (w); - flux_log_error (h, "%s: %s", __FUNCTION__, - exception_safe_wrapper.get_err_message ()); + flux_log_error (h, "%s: %s", __FUNCTION__, exception_safe_wrapper.get_err_message ()); } } -int qmanager_safe_cb_t::post_sched_loop (flux_t *h, schedutil_t *schedutil, - std::map> &queues) +int qmanager_safe_cb_t::post_sched_loop ( + flux_t *h, + schedutil_t *schedutil, + std::map> &queues) { int rc; eh_wrapper_t exception_safe_wrapper; - rc = exception_safe_wrapper (qmanager_cb_t::post_sched_loop, - h, schedutil, queues); + rc = exception_safe_wrapper (qmanager_cb_t::post_sched_loop, h, schedutil, queues); if (exception_safe_wrapper.bad ()) - flux_log_error (h, "%s: %s", __FUNCTION__, - exception_safe_wrapper.get_err_message ()); + flux_log_error (h, "%s: %s", __FUNCTION__, exception_safe_wrapper.get_err_message ()); return rc; } diff --git a/qmanager/modules/qmanager_callbacks.hpp b/qmanager/modules/qmanager_callbacks.hpp index a6d73b2d3..22e416086 100644 --- a/qmanager/modules/qmanager_callbacks.hpp +++ b/qmanager/modules/qmanager_callbacks.hpp @@ -25,64 +25,48 @@ struct qmanager_cb_ctx_t { flux_watcher_t *prep{nullptr}; flux_watcher_t *check{nullptr}; flux_watcher_t *idle{nullptr}; - bool pls_sched_loop {false}; - bool pls_post_loop {false}; + bool pls_sched_loop{false}; + bool pls_post_loop{false}; schedutil_t *schedutil{nullptr}; - Flux::opts_manager::optmgr_composer_t< - Flux::opts_manager::qmanager_opts_t> opts; - std::map> queues; + Flux::opts_manager::optmgr_composer_t opts; + std::map> queues; - int find_queue ( - flux_jobid_t id, std::string &queue_name, - std::shared_ptr &queue); + int find_queue (flux_jobid_t id, + std::string &queue_name, + std::shared_ptr &queue); }; class qmanager_cb_t { -protected: - static int jobmanager_hello_cb (flux_t *h, const flux_msg_t *msg, - const char *R, void *arg); - static void jobmanager_alloc_cb (flux_t *h, const flux_msg_t *msg, - void *arg); - static void jobmanager_free_cb (flux_t *h, const flux_msg_t *msg, - const char *R, void *arg); - static void jobmanager_cancel_cb (flux_t *h, const flux_msg_t *msg, - void *arg); - static void jobmanager_prioritize_cb (flux_t *h, const flux_msg_t *msg, - void *arg); - static void prep_watcher_cb (flux_reactor_t *r, flux_watcher_t *w, - int revents, void *arg); - static void check_watcher_cb (flux_reactor_t *r, flux_watcher_t *w, - int revents, void *arg); - static int post_sched_loop (flux_t *h, + protected: + static int jobmanager_hello_cb (flux_t *h, const flux_msg_t *msg, const char *R, void *arg); + static void jobmanager_alloc_cb (flux_t *h, const flux_msg_t *msg, void *arg); + static void jobmanager_free_cb (flux_t *h, const flux_msg_t *msg, const char *R, void *arg); + static void jobmanager_cancel_cb (flux_t *h, const flux_msg_t *msg, void *arg); + static void jobmanager_prioritize_cb (flux_t *h, const flux_msg_t *msg, void *arg); + static void prep_watcher_cb (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg); + static void check_watcher_cb (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg); + static int post_sched_loop ( + flux_t *h, schedutil_t *schedutil, - std::map> &queues); + std::map> &queues); }; struct qmanager_safe_cb_t : public qmanager_cb_t { - static int jobmanager_hello_cb (flux_t *h, const flux_msg_t *msg, - const char *R, void *arg); - static void jobmanager_alloc_cb (flux_t *h, const flux_msg_t *msg, - void *arg); - static void jobmanager_free_cb (flux_t *h, const flux_msg_t *msg, - const char *R, void *arg); - static void jobmanager_cancel_cb (flux_t *h, const flux_msg_t *msg, - void *arg); - static void jobmanager_prioritize_cb (flux_t *h, const flux_msg_t *msg, - void *arg); - static void prep_watcher_cb (flux_reactor_t *r, flux_watcher_t *w, - int revents, void *arg); - static void check_watcher_cb (flux_reactor_t *r, flux_watcher_t *w, - int revents, void *arg); - static int post_sched_loop (flux_t *h, + static int jobmanager_hello_cb (flux_t *h, const flux_msg_t *msg, const char *R, void *arg); + static void jobmanager_alloc_cb (flux_t *h, const flux_msg_t *msg, void *arg); + static void jobmanager_free_cb (flux_t *h, const flux_msg_t *msg, const char *R, void *arg); + static void jobmanager_cancel_cb (flux_t *h, const flux_msg_t *msg, void *arg); + static void jobmanager_prioritize_cb (flux_t *h, const flux_msg_t *msg, void *arg); + static void prep_watcher_cb (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg); + static void check_watcher_cb (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg); + static int post_sched_loop ( + flux_t *h, schedutil_t *schedutil, - std::map> &queues); + std::map> &queues); }; -#endif // #define QMANAGER_CALLBACKS_HPP +#endif // #define QMANAGER_CALLBACKS_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/qmanager/modules/qmanager_opts.cpp b/qmanager/modules/qmanager_opts.cpp index 403402ed0..765e5b2a9 100644 --- a/qmanager/modules/qmanager_opts.cpp +++ b/qmanager/modules/qmanager_opts.cpp @@ -19,8 +19,6 @@ extern "C" { using namespace Flux; using namespace Flux::opts_manager; - - //////////////////////////////////////////////////////////////////////////////// // Private API for Queue Manager Option Class //////////////////////////////////////////////////////////////////////////////// @@ -30,21 +28,19 @@ int qmanager_opts_t::parse_queues (const std::string &queues) int rc = 0; try { std::vector entries; - if ( (rc = parse_multi (queues.c_str (), ' ', entries)) < 0) + if ((rc = parse_multi (queues.c_str (), ' ', entries)) < 0) goto done; - m_per_queue_prop.clear (); // clear the default queue entry - for (const auto &entry: entries) { + m_per_queue_prop.clear (); // clear the default queue entry + for (const auto &entry : entries) { auto ret = m_per_queue_prop.insert ( - std::pair ( - entry, queue_prop_t ())); + std::pair (entry, queue_prop_t ())); if (!ret.second) { errno = EEXIST; rc = -1; goto done; } } - } - catch (std::bad_alloc &e) { + } catch (std::bad_alloc &e) { errno = ENOMEM; rc = -1; } @@ -52,8 +48,6 @@ int qmanager_opts_t::parse_queues (const std::string &queues) return rc; } - - //////////////////////////////////////////////////////////////////////////////// // Private API for Queue Property Class //////////////////////////////////////////////////////////////////////////////// @@ -61,14 +55,11 @@ int qmanager_opts_t::parse_queues (const std::string &queues) bool queue_prop_t::known_queue_policy (const std::string &policy) { bool rc = false; - if (policy == "fcfs" || policy == "easy" - || policy == "hybrid" || policy == "conservative") + if (policy == "fcfs" || policy == "easy" || policy == "hybrid" || policy == "conservative") rc = true; return rc; } - - //////////////////////////////////////////////////////////////////////////////// // Public API for Queue Manager Option Class //////////////////////////////////////////////////////////////////////////////// @@ -124,18 +115,14 @@ bool queue_prop_t::is_policy_params_set () const json_t *queue_prop_t::jsonify () const { return json_pack ("{ s:s? s:s? s:s? }", - "queue-policy", is_queue_policy_set () - ? queue_policy.c_str () - : nullptr, - "queue-params", is_queue_params_set () - ? queue_params.c_str () - : nullptr, - "policy-params", is_policy_params_set () - ? policy_params.c_str () - : nullptr); + "queue-policy", + is_queue_policy_set () ? queue_policy.c_str () : nullptr, + "queue-params", + is_queue_params_set () ? queue_params.c_str () : nullptr, + "policy-params", + is_policy_params_set () ? policy_params.c_str () : nullptr); } - qmanager_opts_t::qmanager_opts_t () { // Note: std::pair<>() is guaranteed to throw only an exception @@ -145,33 +132,35 @@ qmanager_opts_t::qmanager_opts_t () bool inserted = true; - auto ret = m_tab.insert (std::pair ( - "queues", - static_cast (qmanager_opts_key_t::QUEUES))); + auto ret = m_tab.insert ( + std::pair ("queues", static_cast (qmanager_opts_key_t::QUEUES))); inserted &= ret.second; - ret = m_tab.insert (std::pair ( - "queue-policy", - static_cast (qmanager_opts_key_t::QUEUE_POLICY))); + ret = m_tab.insert ( + std::pair ("queue-policy", + static_cast (qmanager_opts_key_t::QUEUE_POLICY))); inserted &= ret.second; - ret = m_tab.insert (std::pair ( - "queue-params", - static_cast (qmanager_opts_key_t::QUEUE_PARAMS))); + ret = m_tab.insert ( + std::pair ("queue-params", + static_cast (qmanager_opts_key_t::QUEUE_PARAMS))); inserted &= ret.second; - ret= m_tab.insert (std::pair ( - "policy-params", - static_cast (qmanager_opts_key_t::POLICY_PARAMS))); + ret = m_tab.insert ( + std::pair ("policy-params", + static_cast (qmanager_opts_key_t::POLICY_PARAMS))); inserted &= ret.second; - ret= m_tab.insert (std::pair ( - "queue-policy-per-queue", - static_cast (qmanager_opts_key_t::QUEUE_POLICY_PER_QUEUE))); + ret = m_tab.insert ( + std::pair ("queue-policy-per-queue", + static_cast ( + qmanager_opts_key_t::QUEUE_POLICY_PER_QUEUE))); inserted &= ret.second; - ret= m_tab.insert (std::pair ( - "queue-params-per-queue", - static_cast (qmanager_opts_key_t::QUEUE_PARAMS_PER_QUEUE))); + ret = m_tab.insert ( + std::pair ("queue-params-per-queue", + static_cast ( + qmanager_opts_key_t::QUEUE_PARAMS_PER_QUEUE))); inserted &= ret.second; - ret= m_tab.insert (std::pair ( - "policy-params-per-queue", - static_cast (qmanager_opts_key_t::POLICY_PARAMS_PER_QUEUE))); + ret = m_tab.insert ( + std::pair ("policy-params-per-queue", + static_cast ( + qmanager_opts_key_t::POLICY_PARAMS_PER_QUEUE))); inserted &= ret.second; if (!inserted) @@ -218,8 +207,7 @@ const std::string &qmanager_opts_t::get_policy_params () const return m_queue_prop.get_policy_params (); } -const std::map & - qmanager_opts_t::get_per_queue_prop () const +const std::map &qmanager_opts_t::get_per_queue_prop () const { return m_per_queue_prop; } @@ -243,9 +231,8 @@ qmanager_opts_t &qmanager_opts_t::canonicalize () { if (m_per_queue_prop.empty ()) { std::string qn = m_default_queue_name; - auto ret = m_per_queue_prop.insert ( - std::pair (qn, - queue_prop_t ())); + auto ret = + m_per_queue_prop.insert (std::pair (qn, queue_prop_t ())); if (!ret.second) throw std::bad_alloc (); } @@ -273,11 +260,9 @@ qmanager_opts_t &qmanager_opts_t::operator+= (const qmanager_opts_t &src) return *this; } -bool qmanager_opts_t::operator ()(const std::string &k1, - const std::string &k2) const +bool qmanager_opts_t::operator() (const std::string &k1, const std::string &k2) const { - if (m_tab.find (k1) == m_tab.end () - || m_tab.find (k2) == m_tab.end ()) + if (m_tab.find (k1) == m_tab.end () || m_tab.find (k2) == m_tab.end ()) return k1 < k2; return m_tab.at (k1) < m_tab.at (k2); } @@ -320,8 +305,7 @@ int qmanager_opts_t::jsonify (std::string &json_out) const return rc; } -int qmanager_opts_t::parse (const std::string &k, const std::string &v, - std::string &info) +int qmanager_opts_t::parse (const std::string &k, const std::string &v, std::string &info) { int rc = 0; std::string dflt; @@ -332,79 +316,78 @@ int qmanager_opts_t::parse (const std::string &k, const std::string &v, key = m_tab[k]; switch (key) { - case static_cast (qmanager_opts_key_t::QUEUES): - rc = parse_queues (v); - break; - - case static_cast (qmanager_opts_key_t::QUEUE_POLICY): - if (!m_queue_prop.set_queue_policy (v)) { - info += "Unknown queuing policy (" + v + ")! "; - info += "Using default."; - } - break; + case static_cast (qmanager_opts_key_t::QUEUES): + rc = parse_queues (v); + break; - case static_cast (qmanager_opts_key_t::QUEUE_PARAMS): - m_queue_prop.set_queue_params (v); - break; + case static_cast (qmanager_opts_key_t::QUEUE_POLICY): + if (!m_queue_prop.set_queue_policy (v)) { + info += "Unknown queuing policy (" + v + ")! "; + info += "Using default."; + } + break; - case static_cast (qmanager_opts_key_t::POLICY_PARAMS): - m_queue_prop.set_policy_params (v); - break; + case static_cast (qmanager_opts_key_t::QUEUE_PARAMS): + m_queue_prop.set_queue_params (v); + break; - case static_cast (qmanager_opts_key_t::QUEUE_POLICY_PER_QUEUE): - tmp_mp.clear (); - if ( (rc = parse_multi_options (v, ' ', ':', tmp_mp)) < 0) + case static_cast (qmanager_opts_key_t::POLICY_PARAMS): + m_queue_prop.set_policy_params (v); break; - for (const auto &kv : tmp_mp) { - if (m_per_queue_prop.find (kv.first) == m_per_queue_prop.end ()) { - info += "Unknown queue (" + kv.first + ")."; - errno = ENOENT; - rc = -1; + + case static_cast (qmanager_opts_key_t::QUEUE_POLICY_PER_QUEUE): + tmp_mp.clear (); + if ((rc = parse_multi_options (v, ' ', ':', tmp_mp)) < 0) break; + for (const auto &kv : tmp_mp) { + if (m_per_queue_prop.find (kv.first) == m_per_queue_prop.end ()) { + info += "Unknown queue (" + kv.first + ")."; + errno = ENOENT; + rc = -1; + break; + } + if (!m_per_queue_prop[kv.first].set_queue_policy (kv.second)) { + info += "Unknown queuing policy (" + v + ") for queue (" + kv.second + ")! "; + info += "Using default. "; + } } - if (!m_per_queue_prop[kv.first].set_queue_policy (kv.second)) { - info += "Unknown queuing policy (" + v + ") for queue (" - + kv.second + ")! "; - info += "Using default. "; - } - } - break; - - case static_cast (qmanager_opts_key_t::QUEUE_PARAMS_PER_QUEUE): - tmp_mp.clear (); - if ( (rc = parse_multi_options (v, ' ', ':', tmp_mp)) < 0) break; - for (const auto &kv : tmp_mp) { - if (m_per_queue_prop.find (kv.first) == m_per_queue_prop.end ()) { - info += "Unknown queue (" + kv.first + ")."; - errno = ENOENT; - rc = -1; + + case static_cast (qmanager_opts_key_t::QUEUE_PARAMS_PER_QUEUE): + tmp_mp.clear (); + if ((rc = parse_multi_options (v, ' ', ':', tmp_mp)) < 0) break; + for (const auto &kv : tmp_mp) { + if (m_per_queue_prop.find (kv.first) == m_per_queue_prop.end ()) { + info += "Unknown queue (" + kv.first + ")."; + errno = ENOENT; + rc = -1; + break; + } + m_per_queue_prop[kv.first].set_queue_params (kv.second); } - m_per_queue_prop[kv.first].set_queue_params (kv.second); - } - break; - - case static_cast (qmanager_opts_key_t::POLICY_PARAMS_PER_QUEUE): - tmp_mp.clear (); - if ( (rc = parse_multi_options (v, ' ', ':', tmp_mp)) < 0) break; - for (const auto &kv : tmp_mp) { - if (m_per_queue_prop.find (kv.first) == m_per_queue_prop.end ()) { - info += "Unknown queue (" + kv.first + ")."; - errno = ENOENT; - rc = -1; + + case static_cast (qmanager_opts_key_t::POLICY_PARAMS_PER_QUEUE): + tmp_mp.clear (); + if ((rc = parse_multi_options (v, ' ', ':', tmp_mp)) < 0) break; + for (const auto &kv : tmp_mp) { + if (m_per_queue_prop.find (kv.first) == m_per_queue_prop.end ()) { + info += "Unknown queue (" + kv.first + ")."; + errno = ENOENT; + rc = -1; + break; + } + m_per_queue_prop[kv.first].set_policy_params (kv.second); } - m_per_queue_prop[kv.first].set_policy_params (kv.second); - } - break; + break; - default: - info += "Unknown option (" + k + ")."; - errno = EINVAL; - rc = -1; - break; + default: + info += "Unknown option (" + k + ")."; + errno = EINVAL; + rc = -1; + break; } return rc; diff --git a/qmanager/modules/qmanager_opts.hpp b/qmanager/modules/qmanager_opts.hpp index 93e7b9c4d..1f402d9c1 100644 --- a/qmanager/modules/qmanager_opts.hpp +++ b/qmanager/modules/qmanager_opts.hpp @@ -26,7 +26,7 @@ namespace opts_manager { const std::string QMANAGER_OPTS_UNSET_STR = "0xdeadbeef"; class queue_prop_t { -public: + public: const std::string &get_queue_policy () const; const std::string &get_queue_params () const; const std::string &get_policy_params () const; @@ -41,7 +41,7 @@ class queue_prop_t { json_t *jsonify () const; -private: + private: bool known_queue_policy (const std::string &policy); std::string queue_policy = QMANAGER_OPTS_UNSET_STR; @@ -53,17 +53,17 @@ class queue_prop_t { * */ class qmanager_opts_t : public optmgr_parse_t { -public: + public: enum class qmanager_opts_key_t : int { - QUEUES = 0, // queues - DEFAULT_QUEUE = 1, // default-queue - QUEUE_POLICY = 10, // queue-policy - QUEUE_PARAMS = 20, // queue-params - POLICY_PARAMS = 30, // policy-params - QUEUE_POLICY_PER_QUEUE = 40, // queue-policy-per_queue - QUEUE_PARAMS_PER_QUEUE = 50, // queue-params-per_queue - POLICY_PARAMS_PER_QUEUE = 60, // policy-params-per_queue - UNKNOWN = 5000 + QUEUES = 0, // queues + DEFAULT_QUEUE = 1, // default-queue + QUEUE_POLICY = 10, // queue-policy + QUEUE_PARAMS = 20, // queue-params + POLICY_PARAMS = 30, // policy-params + QUEUE_POLICY_PER_QUEUE = 40, // queue-policy-per_queue + QUEUE_PARAMS_PER_QUEUE = 50, // queue-params-per_queue + POLICY_PARAMS_PER_QUEUE = 60, // policy-params-per_queue + UNKNOWN = 5000 }; // These constructors can throw std::bad_alloc exception @@ -112,7 +112,7 @@ class qmanager_opts_t : public optmgr_parse_t { * \param k2 comparing key * \return true if k1 should precede k2 during iteration. */ - bool operator ()(const std::string &k1, const std::string &k2) const; + bool operator() (const std::string &k1, const std::string &k2) const; /*! Parse the value string (v) according to the key string (k). * The parsed results are stored in "this" object. @@ -131,7 +131,7 @@ class qmanager_opts_t : public optmgr_parse_t { */ int jsonify (std::string &json_out) const; -private: + private: int parse_queues (const std::string &queues); std::string m_default_queue_name = "default"; @@ -146,10 +146,10 @@ class qmanager_opts_t : public optmgr_parse_t { std::map m_tab; }; -} // namespace Flux -} // namespace opts_manager +} // namespace opts_manager +} // namespace Flux -#endif // QMANAGER_OPTS_HPP +#endif // QMANAGER_OPTS_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/qmanager/policies/base/queue_policy_base.hpp b/qmanager/policies/base/queue_policy_base.hpp index 76ec7442a..7d48d3c35 100644 --- a/qmanager/policies/base/queue_policy_base.hpp +++ b/qmanager/policies/base/queue_policy_base.hpp @@ -34,24 +34,20 @@ extern "C" { namespace Flux { namespace queue_manager { -enum class job_state_kind_t { INIT, - PENDING, - REJECTED, - RUNNING, - ALLOC_RUNNING, - CANCELED, - COMPLETE }; +enum class job_state_kind_t { INIT, PENDING, REJECTED, RUNNING, ALLOC_RUNNING, CANCELED, COMPLETE }; /*! Type to store schedule information such as the * allocated or reserved (for backfill) resource set (R). */ struct schedule_t { schedule_t () = default; - schedule_t (const std::string &r) : R (r) { } + schedule_t (const std::string &r) : R (r) + { + } schedule_t (schedule_t &&s) = default; schedule_t (const schedule_t &s) = default; - schedule_t& operator= (schedule_t &&s) = default; - schedule_t& operator= (const schedule_t &s) = default; + schedule_t &operator= (schedule_t &&s) = default; + schedule_t &operator= (const schedule_t &s) = default; std::string R = ""; bool reserved = false; int64_t at = 0; @@ -80,27 +76,34 @@ using job_map_iter = job_map_t::iterator; /*! Type to store a job's attributes. */ class job_t { -public: - ~job_t () { flux_msg_destroy (msg); } + public: + ~job_t () + { + flux_msg_destroy (msg); + } job_t () = default; - job_t (job_state_kind_t s, flux_jobid_t jid, - uint32_t uid, unsigned int p, double t_s, const std::string &R) - : state (s), id (jid), userid (uid), - priority (p), t_submit (t_s), schedule (R) { } + job_t (job_state_kind_t s, + flux_jobid_t jid, + uint32_t uid, + unsigned int p, + double t_s, + const std::string &R) + : state (s), id (jid), userid (uid), priority (p), t_submit (t_s), schedule (R) + { + } job_t (job_t &&j) = default; job_t (const job_t &j) = default; - job_t& operator= (job_t &&s) = default; - job_t& operator= (const job_t &s) = default; - - bool is_pending () { return state == job_state_kind_t::PENDING; } - pending_key get_key () { - return { - priority, - t_submit, - t_stamps.pending_ts - }; - } + job_t &operator= (job_t &&s) = default; + job_t &operator= (const job_t &s) = default; + bool is_pending () + { + return state == job_state_kind_t::PENDING; + } + pending_key get_key () + { + return {priority, t_submit, t_stamps.pending_ts}; + } flux_msg_t *msg = NULL; job_state_kind_t state = job_state_kind_t::INIT; @@ -114,15 +117,13 @@ class job_t { schedule_t schedule; }; - /*! Queue policy base interface abstract class. Derived classes must * implement its run_sched_loop and destructor methods. Insert, remove * and pending_pop interface implementations are provided through * its parent class (detail::queue_policy_base_impl_t). */ -class queue_policy_base_t : public resource_model::queue_adapter_base_t -{ -public: +class queue_policy_base_t : public resource_model::queue_adapter_base_t { + public: /*! The destructor that must be implemented by derived classes. * */ @@ -165,7 +166,8 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t * execution. * EINVAL: invalid argument. */ - virtual int cancel_sched_loop () { + virtual int cancel_sched_loop () + { if (is_sched_loop_active ()) { errno = EINVAL; return -1; @@ -192,11 +194,11 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t * EPROTO: job->schedule.R doesn't comply. * ENOTSUP: job->schedule.R has unsupported feature. */ - virtual int reconstruct_resource (void *h, std::shared_ptr job, - std::string &ret_R) = 0; + virtual int reconstruct_resource (void *h, std::shared_ptr job, std::string &ret_R) = 0; /// @brief move any jobs in blocked state to pending - void process_provisional_reconsider () { + void process_provisional_reconsider () + { if (!m_pending_reconsider) return; m_pending_reconsider = false; @@ -209,7 +211,8 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t } /// @brief move any jobs in blocked state to pending - void reconsider_blocked_jobs () { + void reconsider_blocked_jobs () + { m_pending_reconsider = true; if (!is_sched_loop_active ()) { process_provisional_reconsider (); @@ -223,7 +226,8 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t * \return 0 on success; -1 on error. * EINVAL: invalid argument. */ - int set_queue_params (const std::string ¶ms) { + int set_queue_params (const std::string ¶ms) + { return set_params (params, m_qparams); } @@ -234,19 +238,20 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t * \return 0 on success; -1 on error. * EINVAL: invalid argument. */ - int set_policy_params (const std::string ¶ms) { + int set_policy_params (const std::string ¶ms) + { return set_params (params, m_pparams); } /*! Apply the set policy parameters to the queuing policy. */ - virtual int apply_params () { + virtual int apply_params () + { int rc = 0; int depth = 0; try { std::unordered_map::const_iterator i; - if ((i = m_qparams.find ("max-queue-depth")) - != m_qparams.end ()) { + if ((i = m_qparams.find ("max-queue-depth")) != m_qparams.end ()) { // We pre-check the input string to see if it is a positive number // before passing it to std::stoi. This works around issues // in some compilers where std::stoi aborts on certain @@ -255,7 +260,7 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t errno = EINVAL; rc += -1; } else { - if ( (depth = std::stoi (i->second)) < 1) { + if ((depth = std::stoi (i->second)) < 1) { errno = ERANGE; rc += -1; } else { @@ -275,7 +280,7 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t errno = EINVAL; rc += -1; } else { - if ( (depth = std::stoi (i->second)) < 1) { + if ((depth = std::stoi (i->second)) < 1) { errno = ERANGE; rc += -1; } else { @@ -304,7 +309,8 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t * \param p_p string to which to print queue parameters * (e.g., "reservation-depth=1024,foo=bar") */ - void get_params (std::string &q_p, std::string &p_p) { + void get_params (std::string &q_p, std::string &p_p) + { std::unordered_map::const_iterator i; for (i = m_qparams.begin (); i != m_qparams.end (); i++) { if (!q_p.empty ()) @@ -322,7 +328,8 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t * is the depth of its pending-job queue only upto which it * considers for scheduling to deal with unbounded queue length. */ - unsigned int get_queue_depth () { + unsigned int get_queue_depth () + { return m_queue_depth; } @@ -332,7 +339,8 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t * \return a shared pointer pointing to the job on success; * nullptr on error. ENOENT: unknown id. */ - const std::shared_ptr lookup (flux_jobid_t id) { + const std::shared_ptr lookup (flux_jobid_t id) + { std::shared_ptr job = nullptr; if (m_jobs.find (id) == m_jobs.end ()) { errno = ENOENT; @@ -360,19 +368,20 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t * EPROTO: job->schedule.R doesn't comply. * ENOTSUP: job->schedule.R has unsupported feature. */ - int reconstruct (void *h, std::shared_ptr job, std::string &R_out) { + int reconstruct (void *h, std::shared_ptr job, std::string &R_out) + { int rc = 0; - if ( (rc = reconstruct_resource (h, job, R_out)) < 0) + if ((rc = reconstruct_resource (h, job, R_out)) < 0) return rc; return reconstruct_queue (job); } - /* Query the first job from the pending job queue. * \return a shared pointer pointing to a job_t object * on success; nullptr when the queue is empty. */ - std::shared_ptr pending_begin () { + std::shared_ptr pending_begin () + { std::shared_ptr job_p = nullptr; m_pending_iter = m_pending.begin (); if (m_pending_iter == m_pending.end ()) { @@ -390,7 +399,8 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t * \return a shared pointer pointing to a job_t object * on success; nullptr when the queue is empty. */ - std::shared_ptr pending_next () { + std::shared_ptr pending_next () + { std::shared_ptr job_p = nullptr; if (!m_iter_valid) goto ret; @@ -427,8 +437,7 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t job->state = job_state_kind_t::PENDING; job->t_stamps.pending_ts = m_pq_cnt++; m_pending_provisional.emplace (job->get_key (), job->id); - m_jobs.insert (std::pair> (job->id, - job)); + m_jobs.insert (std::pair> (job->id, job)); set_schedulability (true); rc = 0; out: @@ -444,7 +453,7 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t * \return 0 on success; -1 on error. * ENOENT: unknown id. */ - int remove_pending (job_t *job) + int remove_pending (job_t *job) { int rc = -1; @@ -461,8 +470,7 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t // cannot be determined. There is "MAYBE pending state" where // a request has been sent out to the match service. auto res = m_pending_cancel_provisional.insert ( - std::pair ( - job->t_stamps.canceled_ts, job->id)); + std::pair (job->t_stamps.canceled_ts, job->id)); if (!res.second) { errno = EEXIST; goto out; @@ -473,8 +481,7 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t goto out; job->state = job_state_kind_t::CANCELED; auto res = m_canceled.insert ( - std::pair ( - job->t_stamps.canceled_ts, job->id)); + std::pair (job->t_stamps.canceled_ts, job->id)); if (!res.second) { errno = EEXIST; goto out; @@ -503,45 +510,45 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t */ int remove (void *h, flux_jobid_t id, const char *R) { - int rc = -1; - bool full_removal = false; + int rc = -1; + bool full_removal = false; - auto job_it = m_jobs.find (id); - if (job_it == m_jobs.end ()) { - errno = ENOENT; - goto out; - } + auto job_it = m_jobs.find (id); + if (job_it == m_jobs.end ()) { + errno = ENOENT; + goto out; + } - switch (job_it->second->state) { - case job_state_kind_t::PENDING: - this->remove_pending(job_it->second.get ()); - break; - case job_state_kind_t::ALLOC_RUNNING: - // deliberately fall through - case job_state_kind_t::RUNNING: - if ( (rc = cancel (h, job_it->second->id, R, true, full_removal) != 0)) - break; - if (full_removal) { - m_alloced.erase (job_it->second->t_stamps.running_ts); - m_running.erase (job_it->second->t_stamps.running_ts); - job_it->second->t_stamps.complete_ts = m_cq_cnt++; - job_it->second->state = job_state_kind_t::COMPLETE; - m_jobs.erase (job_it); + switch (job_it->second->state) { + case job_state_kind_t::PENDING: + this->remove_pending (job_it->second.get ()); + break; + case job_state_kind_t::ALLOC_RUNNING: + // deliberately fall through + case job_state_kind_t::RUNNING: + if ((rc = cancel (h, job_it->second->id, R, true, full_removal) != 0)) + break; + if (full_removal) { + m_alloced.erase (job_it->second->t_stamps.running_ts); + m_running.erase (job_it->second->t_stamps.running_ts); + job_it->second->t_stamps.complete_ts = m_cq_cnt++; + job_it->second->state = job_state_kind_t::COMPLETE; + m_jobs.erase (job_it); + } + set_schedulability (true); + break; + default: + break; } - set_schedulability (true); - break; - default: - break; - } - cancel_sched_loop (); - // blocked jobs must be reconsidered after a job completes - // this covers cases where jobs that couldn't run because of an - // existing job's reservation can when it completes early - reconsider_blocked_jobs (); - - rc = 0; -out: - return rc; + cancel_sched_loop (); + // blocked jobs must be reconsidered after a job completes + // this covers cases where jobs that couldn't run because of an + // existing job's reservation can when it completes early + reconsider_blocked_jobs (); + + rc = 0; + out: + return rc; } /*! Remove a job whose jobid is id from any internal queues @@ -561,8 +568,7 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t * \return 0 on success; -1 on error. * ENOENT: unknown id. */ - virtual int cancel (void *h, flux_jobid_t id, const char *R, bool noent_ok, - bool &full_removal) + virtual int cancel (void *h, flux_jobid_t id, const char *R, bool noent_ok, bool &full_removal) { full_removal = true; return 0; @@ -644,8 +650,12 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t * resource API. When a match succeeds, this method is called back * by reapi_t. */ - int handle_match_success (flux_jobid_t jobid, const char *status, - const char *R, int64_t at, double ov) override { + int handle_match_success (flux_jobid_t jobid, + const char *status, + const char *R, + int64_t at, + double ov) override + { return 0; } @@ -654,18 +664,19 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t * resource API. When a match fails, this method is called back * by reapi_t. */ - int handle_match_failure (flux_jobid_t jobid, int errcode) override { + int handle_match_failure (flux_jobid_t jobid, int errcode) override + { return 0; } - /*! Pop the first job from the pending job queue. The popped * job is completely graduated from the queue policy layer. * * \return a shared pointer pointing to a job_t object * on success; nullptr when the queue is empty. */ - std::shared_ptr pending_pop () { + std::shared_ptr pending_pop () + { std::shared_ptr job; flux_jobid_t id; @@ -686,7 +697,8 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t * \return a shared pointer pointing to a job_t object * on success; nullptr when the queue is empty. */ - std::shared_ptr alloced_pop () { + std::shared_ptr alloced_pop () + { std::shared_ptr job; flux_jobid_t id; if (m_alloced.empty ()) @@ -704,7 +716,8 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t * \return a shared pointer pointing to a job_t object * on success; nullptr when the queue is empty. */ - std::shared_ptr rejected_pop () { + std::shared_ptr rejected_pop () + { std::shared_ptr job; flux_jobid_t id; if (m_rejected.empty ()) @@ -714,7 +727,7 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t return nullptr; job = m_jobs[id]; m_rejected.erase (job->t_stamps.rejected_ts); - return job; + return job; } /*! Pop the first job from the internal canceled job queue. @@ -722,7 +735,8 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t * \return a shared pointer pointing to a job_t object * on success; nullptr when the queue is empty. */ - std::shared_ptr canceled_pop () { + std::shared_ptr canceled_pop () + { std::shared_ptr job; flux_jobid_t id; if (m_canceled.empty ()) @@ -739,8 +753,7 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t /* This doesn't appear to be used anywhere */ std::shared_ptr reserved_pop (); - job_map_iter to_running (job_map_iter pending_iter, - bool use_alloced_queue) + job_map_iter to_running (job_map_iter pending_iter, bool use_alloced_queue) { flux_jobid_t id = pending_iter->second; if (m_jobs.find (id) == m_jobs.end ()) { @@ -751,8 +764,8 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t std::shared_ptr job = m_jobs[id]; job->state = job_state_kind_t::RUNNING; job->t_stamps.running_ts = m_rq_cnt++; - auto res = m_running.insert (std::pair( - job->t_stamps.running_ts, job->id)); + auto res = m_running.insert ( + std::pair (job->t_stamps.running_ts, job->id)); if (!res.second) { errno = ENOMEM; return pending_iter; @@ -760,8 +773,8 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t if (use_alloced_queue) { job->state = job_state_kind_t::ALLOC_RUNNING; - auto res = m_alloced.insert (std::pair( - job->t_stamps.running_ts, job->id)); + auto res = m_alloced.insert ( + std::pair (job->t_stamps.running_ts, job->id)); if (!res.second) { errno = ENOMEM; return pending_iter; @@ -773,7 +786,6 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t return m_pending.erase (pending_iter); } - /*! Reprioritize a job with a new priority. * * \param id jobid of flux_jobid_t type. @@ -783,7 +795,8 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t * EEXIST: id already exists * EINVAL: job not pending */ - int pending_reprioritize (flux_jobid_t id, unsigned int priority) { + int pending_reprioritize (flux_jobid_t id, unsigned int priority) + { std::shared_ptr job = nullptr; if (m_jobs.find (id) == m_jobs.end ()) { @@ -797,9 +810,9 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t } auto res = m_pending_reprio_provisional.insert ( - std::pair> ( - m_reprio_cnt, std::make_pair (job->id, priority))); + std::pair> (m_reprio_cnt, + std::make_pair (job->id, + priority))); m_reprio_cnt++; if (!res.second) { errno = EEXIST; @@ -811,10 +824,7 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t return 0; } - -protected: - - + protected: /*! Reconstruct the queue. * * \param job shared pointer to a running job whose resource @@ -827,11 +837,11 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t * EPROTO: job->schedule.R doesn't comply. * ENOTSUP: job->schedule.R has unsupported feature. */ - int reconstruct_queue (std::shared_ptr job) { + int reconstruct_queue (std::shared_ptr job) + { int rc = -1; std::pair::iterator, bool> ret; - std::pair>::iterator, bool> ret2; + std::pair>::iterator, bool> ret2; if (job == nullptr || m_jobs.find (job->id) != m_jobs.end ()) { errno = EINVAL; @@ -839,15 +849,14 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t } job->t_stamps.running_ts = m_rq_cnt++; - ret = m_running.insert (std::pair( - job->t_stamps.running_ts, job->id)); + ret = m_running.insert ( + std::pair (job->t_stamps.running_ts, job->id)); if (ret.second == false) { rc = -1; errno = ENOMEM; goto out; } - ret2 = m_jobs.insert (std::pair> ( - job->id, job)); + ret2 = m_jobs.insert (std::pair> (job->id, job)); if (ret2.second == false) { m_running.erase (ret.first); rc = -1; @@ -875,8 +884,7 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t return -1; job->state = job_state_kind_t::CANCELED; auto res = m_canceled.insert ( - std::pair ( - job->t_stamps.canceled_ts, job->id)); + std::pair (job->t_stamps.canceled_ts, job->id)); if (!res.second) { errno = EEXIST; return -1; @@ -916,9 +924,7 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t return 0; } - - int insert_pending_job (std::shared_ptr &job, - bool into_provisional) + int insert_pending_job (std::shared_ptr &job, bool into_provisional) { auto &pending_map = into_provisional ? m_pending_provisional : m_pending; auto res = pending_map.emplace (job->get_key (), job->id); @@ -950,8 +956,7 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t return 0; } - job_map_iter to_rejected (job_map_iter pending_iter, - const std::string ¬e) + job_map_iter to_rejected (job_map_iter pending_iter, const std::string ¬e) { flux_jobid_t id = pending_iter->second; if (m_jobs.find (id) == m_jobs.end ()) { @@ -963,8 +968,8 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t job->state = job_state_kind_t::REJECTED; job->note = note; job->t_stamps.rejected_ts = m_dq_cnt++; - auto res = m_rejected.insert (std::pair( - job->t_stamps.rejected_ts, job->id)); + auto res = m_rejected.insert ( + std::pair (job->t_stamps.rejected_ts, job->id)); if (!res.second) { errno = ENOMEM; return pending_iter; @@ -993,8 +998,7 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t std::map m_pending_provisional; std::map m_pending_cancel_provisional; bool m_pending_reconsider = false; - std::map> m_pending_reprio_provisional; + std::map> m_pending_reprio_provisional; std::map m_running; std::map m_alloced; std::map m_rejected; @@ -1003,10 +1007,8 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t std::unordered_map m_qparams; std::unordered_map m_pparams; -private: - - int set_params (const std::string ¶ms, std::unordered_map &p_map) + private: + int set_params (const std::string ¶ms, std::unordered_map &p_map) { int rc = -1; size_t pos = 0; @@ -1034,8 +1036,7 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t return rc; } - int set_param (std::string &p_pair, std::unordered_map &p_map) + int set_param (std::string &p_pair, std::unordered_map &p_map) { int rc = -1; size_t pos = 0; @@ -1056,17 +1057,19 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t v.erase (std::remove_if (v.begin (), v.end (), ::isspace), v.end ()); if (p_map.find (k) != p_map.end ()) p_map.erase (k); - p_map.insert (std::pair(k, v)); + p_map.insert (std::pair (k, v)); rc = 0; done: return rc; } - bool is_number (const std::string &num_str) { + bool is_number (const std::string &num_str) + { if (num_str.empty ()) return false; - auto i = std::find_if (num_str.begin (), num_str.end (), - [] (unsigned char c) { return !std::isdigit (c); }); + auto i = std::find_if (num_str.begin (), num_str.end (), [] (unsigned char c) { + return !std::isdigit (c); + }); return i == num_str.end (); } @@ -1074,10 +1077,10 @@ class queue_policy_base_t : public resource_model::queue_adapter_base_t bool m_iter_valid = false; }; -} // namespace Flux::queue_manager -} // namespace Flux +} // namespace queue_manager +} // namespace Flux -#endif // QUEUE_POLICY_BASE_HPP +#endif // QUEUE_POLICY_BASE_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/qmanager/policies/queue_policy_bf_base.hpp b/qmanager/policies/queue_policy_bf_base.hpp index 01cb11227..124c15555 100644 --- a/qmanager/policies/queue_policy_bf_base.hpp +++ b/qmanager/policies/queue_policy_bf_base.hpp @@ -19,26 +19,30 @@ namespace queue_manager { namespace detail { template -class queue_policy_bf_base_t : public queue_policy_base_t -{ -public: +class queue_policy_bf_base_t : public queue_policy_base_t { + public: virtual ~queue_policy_bf_base_t (); virtual int run_sched_loop (void *h, bool use_alloced_queue); int cancel_sched_loop () override; - virtual int reconstruct_resource (void *h, std::shared_ptr job, - std::string &R_out); + virtual int reconstruct_resource (void *h, std::shared_ptr job, std::string &R_out); virtual int apply_params (); - virtual int handle_match_success (flux_jobid_t jobid, const char *status, - const char *R, int64_t at, double ov); + virtual int handle_match_success (flux_jobid_t jobid, + const char *status, + const char *R, + int64_t at, + double ov); virtual int handle_match_failure (flux_jobid_t jobid, int errcode); - int cancel (void *h, flux_jobid_t id, const char *R, bool noent_ok, + int cancel (void *h, + flux_jobid_t id, + const char *R, + bool noent_ok, bool &full_removal) override; -protected: + protected: unsigned int m_reservation_depth; unsigned int m_max_reservation_depth = MAX_RESERVATION_DEPTH; -private: + private: int next_match_iter (); int cancel_reserved_jobs (void *h); int allocate_orelse_reserve_jobs (void *h); @@ -46,17 +50,16 @@ class queue_policy_bf_base_t : public queue_policy_base_t int m_reservation_cnt; int m_scheduled_cnt; bool m_try_reserve = false; - decltype (m_pending)::iterator m_in_progress_iter = m_pending.end(); + decltype (m_pending)::iterator m_in_progress_iter = m_pending.end (); void *m_handle = NULL; }; -} // namespace Flux::queue_manager::detail -} // namespace Flux::queue_manager -} // namespace Flux +} // namespace detail +} // namespace queue_manager +} // namespace Flux -#endif // QUEUE_POLICY_BF_BASE_HPP +#endif // QUEUE_POLICY_BF_BASE_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab */ - diff --git a/qmanager/policies/queue_policy_bf_base_impl.hpp b/qmanager/policies/queue_policy_bf_base_impl.hpp index f1c712f45..37af0f1a1 100644 --- a/qmanager/policies/queue_policy_bf_base_impl.hpp +++ b/qmanager/policies/queue_policy_bf_base_impl.hpp @@ -19,7 +19,6 @@ namespace Flux { namespace queue_manager { namespace detail { - //////////////////////////////////////////////////////////////////////////////// // Private Methods of Queue Policy Backfill Base //////////////////////////////////////////////////////////////////////////////// @@ -36,7 +35,8 @@ int queue_policy_bf_base_t::cancel_reserved_jobs (void *h) } template -int queue_policy_bf_base_t::next_match_iter () { +int queue_policy_bf_base_t::next_match_iter () +{ bool reached_queue_depth = m_scheduled_cnt >= m_queue_depth; bool reached_end_of_queue = m_in_progress_iter == m_pending.end (); if (reached_end_of_queue || reached_queue_depth) { @@ -52,20 +52,21 @@ int queue_policy_bf_base_t::next_match_iter () { auto &job = m_jobs[m_in_progress_iter->second]; m_try_reserve = m_reservation_cnt < m_reservation_depth; - json_t *jobarray_ptr = json_pack ("[{s:I s:s}]", "jobid", job->id, "jobspec", job->jobspec.c_str ()); - if ( !jobarray_ptr) { + json_t *jobarray_ptr = + json_pack ("[{s:I s:s}]", "jobid", job->id, "jobspec", job->jobspec.c_str ()); + if (!jobarray_ptr) { errno = ENOMEM; return -1; } - auto _jdecref = [](json_t *p) { json_decref (p); }; + auto _jdecref = [] (json_t *p) { json_decref (p); }; std::unique_ptr jobarray (jobarray_ptr, _jdecref); char *jobs_ptr = json_dumps (jobarray.get (), JSON_INDENT (0)); - if ( !jobs_ptr) { + if (!jobs_ptr) { errno = ENOMEM; return -1; } - auto _free = [](char *p) { free (p); }; - std::unique_ptr jobs_str (jobs_ptr, _free); + auto _free = [] (char *p) { free (p); }; + std::unique_ptr jobs_str (jobs_ptr, _free); return reapi_type::match_allocate_multi (m_handle, m_try_reserve, jobs_str.get (), this); } @@ -103,8 +104,10 @@ int queue_policy_bf_base_t::allocate_orelse_reserve_jobs (void *h) } template -int queue_policy_bf_base_t::cancel (void *h, flux_jobid_t id, - const char *R, bool noent_ok, +int queue_policy_bf_base_t::cancel (void *h, + flux_jobid_t id, + const char *R, + bool noent_ok, bool &full_removal) { return reapi_type::cancel (h, id, R, noent_ok, full_removal); @@ -126,9 +129,11 @@ int queue_policy_bf_base_t::apply_params () } template -int queue_policy_bf_base_t::handle_match_success ( - flux_jobid_t jobid, const char *status, - const char *R, int64_t at, double ov) +int queue_policy_bf_base_t::handle_match_success (flux_jobid_t jobid, + const char *status, + const char *R, + int64_t at, + double ov) { if (!is_sched_loop_active ()) { errno = EINVAL; @@ -146,7 +151,7 @@ int queue_policy_bf_base_t::handle_match_success ( return -1; } auto &sched = job->schedule; - sched.reserved = std::string ("RESERVED") == status? true : false; + sched.reserved = std::string ("RESERVED") == status ? true : false; sched.R = R; sched.old_at = sched.at; sched.at = at; @@ -184,8 +189,8 @@ int queue_policy_bf_base_t::handle_match_failure (flux_jobid_t jobid } else if (errno != EBUSY) { // The request must be rejected. The job is enqueued into // rejected job queue to the upper layer to react on this. - m_in_progress_iter = to_rejected (m_in_progress_iter, - (errno == ENODEV) ? "unsatisfiable" : "match error"); + m_in_progress_iter = + to_rejected (m_in_progress_iter, (errno == ENODEV) ? "unsatisfiable" : "match error"); } else { // errno is EBUSY and match_allocate returned -1 diff --git a/qmanager/policies/queue_policy_conservative.hpp b/qmanager/policies/queue_policy_conservative.hpp index e7a9d1d34..a7659db02 100644 --- a/qmanager/policies/queue_policy_conservative.hpp +++ b/qmanager/policies/queue_policy_conservative.hpp @@ -18,27 +18,23 @@ namespace queue_manager { namespace detail { template -class queue_policy_conservative_t : public queue_policy_bf_base_t -{ -public: +class queue_policy_conservative_t : public queue_policy_bf_base_t { + public: virtual ~queue_policy_conservative_t (); queue_policy_conservative_t (); - queue_policy_conservative_t ( - const queue_policy_conservative_t &p) = default; + queue_policy_conservative_t (const queue_policy_conservative_t &p) = default; queue_policy_conservative_t (queue_policy_conservative_t &&p) = default; - queue_policy_conservative_t &operator= ( - const queue_policy_conservative_t &p) = default; - queue_policy_conservative_t &operator= ( - queue_policy_conservative_t &&p) = default; + queue_policy_conservative_t &operator= (const queue_policy_conservative_t &p) = default; + queue_policy_conservative_t &operator= (queue_policy_conservative_t &&p) = default; virtual int apply_params (); }; -} // namespace Flux::queue_manager::detail -} // namespace Flux::queue_manager -} // namespace Flux +} // namespace detail +} // namespace queue_manager +} // namespace Flux -#endif // QUEUE_POLICY_CONSERVATIVE_HPP +#endif // QUEUE_POLICY_CONSERVATIVE_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/qmanager/policies/queue_policy_conservative_impl.hpp b/qmanager/policies/queue_policy_conservative_impl.hpp index 00502732d..2ce5a1cda 100644 --- a/qmanager/policies/queue_policy_conservative_impl.hpp +++ b/qmanager/policies/queue_policy_conservative_impl.hpp @@ -20,14 +20,13 @@ namespace detail { template queue_policy_conservative_t::~queue_policy_conservative_t () { - } template int queue_policy_conservative_t::apply_params () { int rc = -1; - if ( (rc = queue_policy_base_t::apply_params ()) == 0) { + if ((rc = queue_policy_base_t::apply_params ()) == 0) { unsigned int depth = queue_policy_bf_base_t::m_queue_depth; if (queue_policy_bf_base_t::m_reservation_depth > depth) queue_policy_bf_base_t::m_reservation_depth = depth; @@ -36,17 +35,16 @@ int queue_policy_conservative_t::apply_params () try { std::unordered_map::const_iterator i; - if ((i = queue_policy_base_t - ::m_pparams.find ("max-reservation-depth")) - != queue_policy_base_t::m_pparams.end ()) { + if ((i = queue_policy_base_t ::m_pparams.find ("max-reservation-depth")) + != queue_policy_base_t::m_pparams.end ()) { int depth = 0; - if ( (depth = std::stoi (i->second)) < 1) { + if ((depth = std::stoi (i->second)) < 1) { errno = ERANGE; rc = -1; } queue_policy_bf_base_t::m_max_reservation_depth = depth; if (static_cast (depth) - < queue_policy_bf_base_t::m_reservation_depth) { + < queue_policy_bf_base_t::m_reservation_depth) { queue_policy_bf_base_t::m_reservation_depth = depth; } } @@ -62,15 +60,14 @@ int queue_policy_conservative_t::apply_params () template queue_policy_conservative_t::queue_policy_conservative_t () { - queue_policy_bf_base_t:: - m_reservation_depth = MAX_RESERVATION_DEPTH; + queue_policy_bf_base_t::m_reservation_depth = MAX_RESERVATION_DEPTH; } -} // namespace Flux::queue_manager::detail -} // namespace Flux::queue_manager -} // namespace Flux +} // namespace detail +} // namespace queue_manager +} // namespace Flux -#endif // QUEUE_POLICY_CONSERVATIVE_IMPL_HPP +#endif // QUEUE_POLICY_CONSERVATIVE_IMPL_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/qmanager/policies/queue_policy_easy.hpp b/qmanager/policies/queue_policy_easy.hpp index 49f22041e..4e5748b9d 100644 --- a/qmanager/policies/queue_policy_easy.hpp +++ b/qmanager/policies/queue_policy_easy.hpp @@ -18,9 +18,8 @@ namespace queue_manager { namespace detail { template -class queue_policy_easy_t : public queue_policy_bf_base_t -{ -public: +class queue_policy_easy_t : public queue_policy_bf_base_t { + public: virtual ~queue_policy_easy_t (); queue_policy_easy_t (); queue_policy_easy_t (const queue_policy_easy_t &p) = default; @@ -30,13 +29,12 @@ class queue_policy_easy_t : public queue_policy_bf_base_t virtual int apply_params (); }; -} // namespace Flux::queue_manager::detail -} // namespace Flux::queue_manager -} // namespace Flux +} // namespace detail +} // namespace queue_manager +} // namespace Flux -#endif // QUEUE_POLICY_EASY_HPP +#endif // QUEUE_POLICY_EASY_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab */ - diff --git a/qmanager/policies/queue_policy_easy_impl.hpp b/qmanager/policies/queue_policy_easy_impl.hpp index 1acb945fe..e9b652c42 100644 --- a/qmanager/policies/queue_policy_easy_impl.hpp +++ b/qmanager/policies/queue_policy_easy_impl.hpp @@ -20,7 +20,6 @@ namespace detail { template queue_policy_easy_t::~queue_policy_easy_t () { - } template @@ -35,11 +34,11 @@ queue_policy_easy_t::queue_policy_easy_t () queue_policy_bf_base_t::m_reservation_depth = 1; } -} // namespace Flux::queue_manager::detail -} // namespace Flux::queue_manager -} // namespace Flux +} // namespace detail +} // namespace queue_manager +} // namespace Flux -#endif // QUEUE_POLICY_EASY_IMPL_HPP +#endif // QUEUE_POLICY_EASY_IMPL_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/qmanager/policies/queue_policy_factory.hpp b/qmanager/policies/queue_policy_factory.hpp index 4f466871d..3d4e2c791 100644 --- a/qmanager/policies/queue_policy_factory.hpp +++ b/qmanager/policies/queue_policy_factory.hpp @@ -18,14 +18,13 @@ namespace Flux { namespace queue_manager { -std::shared_ptr create_queue_policy ( - const std::string &policy, - const std::string &reapi); +std::shared_ptr create_queue_policy (const std::string &policy, + const std::string &reapi); -} // namespace Flux::queue_manager -} // namespace Flux +} // namespace queue_manager +} // namespace Flux -#endif // QUEUE_POLICY_FACTORY_HPP +#endif // QUEUE_POLICY_FACTORY_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/qmanager/policies/queue_policy_factory_impl.hpp b/qmanager/policies/queue_policy_factory_impl.hpp index 5949fa110..bdec8dd87 100644 --- a/qmanager/policies/queue_policy_factory_impl.hpp +++ b/qmanager/policies/queue_policy_factory_impl.hpp @@ -32,9 +32,8 @@ namespace detail { using namespace resource_model; using namespace resource_model::detail; -std::shared_ptr create_queue_policy ( - const std::string &policy, - const std::string &reapi) +std::shared_ptr create_queue_policy (const std::string &policy, + const std::string &reapi) { std::shared_ptr p = nullptr; @@ -42,19 +41,15 @@ std::shared_ptr create_queue_policy ( if (policy == "fcfs") { if (reapi == "module") p = std::make_shared> (); - } - else if (policy == "easy") { + } else if (policy == "easy") { if (reapi == "module") p = std::make_shared> (); - } - else if (policy == "hybrid") { + } else if (policy == "hybrid") { if (reapi == "module") p = std::make_shared> (); - } - else if (policy == "conservative") { + } else if (policy == "conservative") { if (reapi == "module") - p = std::make_shared> (); + p = std::make_shared> (); } } catch (std::bad_alloc &e) { errno = ENOMEM; @@ -64,11 +59,11 @@ std::shared_ptr create_queue_policy ( return p; } -} // namespace Flux::queue_manager::detail -} // namespace Flux::queue_manager -} // namespace Flux +} // namespace detail +} // namespace queue_manager +} // namespace Flux -#endif // QUEUE_POLICY_FACTORY_IMPL_HPP +#endif // QUEUE_POLICY_FACTORY_IMPL_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/qmanager/policies/queue_policy_fcfs.hpp b/qmanager/policies/queue_policy_fcfs.hpp index 744a03794..6fd470c54 100644 --- a/qmanager/policies/queue_policy_fcfs.hpp +++ b/qmanager/policies/queue_policy_fcfs.hpp @@ -19,32 +19,36 @@ namespace queue_manager { namespace detail { template -class queue_policy_fcfs_t : public queue_policy_base_t -{ -public: +class queue_policy_fcfs_t : public queue_policy_base_t { + public: virtual ~queue_policy_fcfs_t (); virtual int run_sched_loop (void *h, bool use_alloced_queue); - virtual int reconstruct_resource (void *h, std::shared_ptr job, - std::string &R_out); + virtual int reconstruct_resource (void *h, std::shared_ptr job, std::string &R_out); virtual int apply_params (); - virtual int handle_match_success (flux_jobid_t jobid, const char *status, - const char *R, int64_t at, double ov); + virtual int handle_match_success (flux_jobid_t jobid, + const char *status, + const char *R, + int64_t at, + double ov); virtual int handle_match_failure (flux_jobid_t jobid, int errcode); - int cancel (void *h, flux_jobid_t id, const char *R, bool noent_ok, + int cancel (void *h, + flux_jobid_t id, + const char *R, + bool noent_ok, bool &full_removal) override; -private: + private: int pack_jobs (json_t *jobs); int allocate_jobs (void *h, bool use_alloced_queue); bool m_queue_depth_limit = false; job_map_iter m_iter; }; -} // namespace Flux::queue_manager::detail -} // namespace Flux::queue_manager -} // namespace Flux +} // namespace detail +} // namespace queue_manager +} // namespace Flux -#endif // QUEUE_POLICY_FCFS_HPP +#endif // QUEUE_POLICY_FCFS_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/qmanager/policies/queue_policy_fcfs_impl.hpp b/qmanager/policies/queue_policy_fcfs_impl.hpp index 1181e0040..599a2a341 100644 --- a/qmanager/policies/queue_policy_fcfs_impl.hpp +++ b/qmanager/policies/queue_policy_fcfs_impl.hpp @@ -19,8 +19,6 @@ namespace Flux { namespace queue_manager { namespace detail { - - //////////////////////////////////////////////////////////////////////////////// // Private Methods of Queue Policy FCFS //////////////////////////////////////////////////////////////////////////////// @@ -34,9 +32,8 @@ int queue_policy_fcfs_t::pack_jobs (json_t *jobs) while (iter != m_pending.end () && qd < m_queue_depth) { json_t *jobdesc; job = m_jobs[iter->second]; - if ( !(jobdesc = json_pack ("{s:I s:s}", - "jobid", job->id, - "jobspec", job->jobspec.c_str ()))) { + if (!(jobdesc = + json_pack ("{s:I s:s}", "jobid", job->id, "jobspec", job->jobspec.c_str ()))) { json_decref (jobs); errno = ENOMEM; return -1; @@ -56,8 +53,7 @@ int queue_policy_fcfs_t::pack_jobs (json_t *jobs) } template -int queue_policy_fcfs_t::allocate_jobs (void *h, - bool use_alloced_queue) +int queue_policy_fcfs_t::allocate_jobs (void *h, bool use_alloced_queue) { json_t *jobs = nullptr; char *jobs_str = nullptr; @@ -67,8 +63,7 @@ int queue_policy_fcfs_t::allocate_jobs (void *h, // m_pending. Note that c++11 doesn't have a clean way // to "move" elements between two std::map objects so // we use copy for the time being. - m_pending.insert (m_pending_provisional.begin (), - m_pending_provisional.end ()); + m_pending.insert (m_pending_provisional.begin (), m_pending_provisional.end ()); m_pending_provisional.clear (); m_iter = m_pending.begin (); if (m_pending.empty ()) @@ -81,25 +76,28 @@ int queue_policy_fcfs_t::allocate_jobs (void *h, return -1; set_sched_loop_active (true); - if ( !(jobs_str = json_dumps (jobs, JSON_INDENT (0)))) { + if (!(jobs_str = json_dumps (jobs, JSON_INDENT (0)))) { errno = ENOMEM; json_decref (jobs); return -1; - } + } json_decref (jobs); if (reapi_type::match_allocate_multi (h, false, jobs_str, this) < 0) { free (jobs_str); set_sched_loop_active (false); - return -1;; + return -1; + ; }; free (jobs_str); return 0; } template -int queue_policy_fcfs_t::handle_match_success ( - flux_jobid_t jobid, const char *status, - const char *R, int64_t at, double ov) +int queue_policy_fcfs_t::handle_match_success (flux_jobid_t jobid, + const char *status, + const char *R, + int64_t at, + double ov) { if (!is_sched_loop_active ()) { errno = EINVAL; @@ -110,7 +108,7 @@ int queue_policy_fcfs_t::handle_match_success ( errno = EINVAL; return -1; } - job->schedule.reserved = std::string ("RESERVED") == status? true : false; + job->schedule.reserved = std::string ("RESERVED") == status ? true : false; job->schedule.R = R; job->schedule.at = at; job->schedule.ov = ov; @@ -126,9 +124,7 @@ int queue_policy_fcfs_t::handle_match_failure (flux_jobid_t jobid, i return -1; } if (errcode != EBUSY && errcode != ENODATA) { - m_iter = to_rejected (m_iter, - (errcode == ENODEV)? "unsatisfiable" - : "match error"); + m_iter = to_rejected (m_iter, (errcode == ENODEV) ? "unsatisfiable" : "match error"); } if (errcode == ENODATA && m_queue_depth_limit) { // Because the scheduling loop is being terminated @@ -145,14 +141,15 @@ int queue_policy_fcfs_t::handle_match_failure (flux_jobid_t jobid, i } template -int queue_policy_fcfs_t::cancel (void *h, flux_jobid_t id, - const char *R, bool noent_ok, +int queue_policy_fcfs_t::cancel (void *h, + flux_jobid_t id, + const char *R, + bool noent_ok, bool &full_removal) { return reapi_type::cancel (h, id, R, noent_ok, full_removal); } - //////////////////////////////////////////////////////////////////////////////// // Public API of Queue Policy FCFS //////////////////////////////////////////////////////////////////////////////// @@ -160,7 +157,6 @@ int queue_policy_fcfs_t::cancel (void *h, flux_jobid_t id, template queue_policy_fcfs_t::~queue_policy_fcfs_t () { - } template @@ -170,8 +166,7 @@ int queue_policy_fcfs_t::apply_params () } template -int queue_policy_fcfs_t::run_sched_loop (void *h, - bool use_alloced_queue) +int queue_policy_fcfs_t::run_sched_loop (void *h, bool use_alloced_queue) { if (is_sched_loop_active ()) return 1; @@ -182,20 +177,23 @@ int queue_policy_fcfs_t::run_sched_loop (void *h, } template -int queue_policy_fcfs_t::reconstruct_resource ( - void *h, std::shared_ptr job, std::string &R_out) +int queue_policy_fcfs_t::reconstruct_resource (void *h, + std::shared_ptr job, + std::string &R_out) { - return reapi_type::update_allocate (h, job->id, job->schedule.R, + return reapi_type::update_allocate (h, + job->id, + job->schedule.R, job->schedule.at, - job->schedule.ov, R_out); + job->schedule.ov, + R_out); } +} // namespace detail +} // namespace queue_manager +} // namespace Flux -} // namespace Flux::queue_manager::detail -} // namespace Flux::queue_manager -} // namespace Flux - -#endif // QUEUE_POLICY_FCFS_IMPL_HPP +#endif // QUEUE_POLICY_FCFS_IMPL_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/qmanager/policies/queue_policy_hybrid.hpp b/qmanager/policies/queue_policy_hybrid.hpp index 45dcf2f35..7dd89123b 100644 --- a/qmanager/policies/queue_policy_hybrid.hpp +++ b/qmanager/policies/queue_policy_hybrid.hpp @@ -18,9 +18,8 @@ namespace queue_manager { namespace detail { template -class queue_policy_hybrid_t : public queue_policy_bf_base_t -{ -public: +class queue_policy_hybrid_t : public queue_policy_bf_base_t { + public: virtual ~queue_policy_hybrid_t (); queue_policy_hybrid_t (); queue_policy_hybrid_t (const queue_policy_hybrid_t &p) = default; @@ -31,11 +30,11 @@ class queue_policy_hybrid_t : public queue_policy_bf_base_t virtual int apply_params (); }; -} // namespace Flux::queue_manager::detail -} // namespace Flux::queue_manager -} // namespace Flux +} // namespace detail +} // namespace queue_manager +} // namespace Flux -#endif // QUEUE_POLICY_HYBRID_HPP +#endif // QUEUE_POLICY_HYBRID_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/qmanager/policies/queue_policy_hybrid_impl.hpp b/qmanager/policies/queue_policy_hybrid_impl.hpp index d024f276a..6257f52b5 100644 --- a/qmanager/policies/queue_policy_hybrid_impl.hpp +++ b/qmanager/policies/queue_policy_hybrid_impl.hpp @@ -20,14 +20,12 @@ namespace detail { template queue_policy_hybrid_t::~queue_policy_hybrid_t () { - } template queue_policy_hybrid_t::queue_policy_hybrid_t () { - queue_policy_bf_base_t::m_reservation_depth = - HYBRID_RESERVATION_DEPTH; + queue_policy_bf_base_t::m_reservation_depth = HYBRID_RESERVATION_DEPTH; } template @@ -37,28 +35,26 @@ int queue_policy_hybrid_t::apply_params () int depth = 0; try { std::unordered_map::const_iterator i; - if ((i = queue_policy_base_t - ::m_pparams.find ("max-reservation-depth")) - != queue_policy_base_t::m_pparams.end ()) { - if ( (depth = std::stoi (i->second)) < 1) { + if ((i = queue_policy_base_t ::m_pparams.find ("max-reservation-depth")) + != queue_policy_base_t::m_pparams.end ()) { + if ((depth = std::stoi (i->second)) < 1) { errno = ERANGE; rc += -1; } queue_policy_bf_base_t::m_max_reservation_depth = depth; } - if ((i = queue_policy_base_t - ::m_pparams.find ("reservation-depth")) - != queue_policy_base_t::m_pparams.end ()) { - if ( (depth = std::stoi (i->second)) < 1) { + if ((i = queue_policy_base_t ::m_pparams.find ("reservation-depth")) + != queue_policy_base_t::m_pparams.end ()) { + if ((depth = std::stoi (i->second)) < 1) { errno = ERANGE; rc += -1; } - if (static_cast (depth) < queue_policy_bf_base_t - ::m_max_reservation_depth) { + if (static_cast (depth) + < queue_policy_bf_base_t::m_max_reservation_depth) { queue_policy_bf_base_t::m_reservation_depth = depth; } else { - queue_policy_bf_base_t::m_reservation_depth - = queue_policy_bf_base_t::m_reservation_depth; + queue_policy_bf_base_t::m_reservation_depth = + queue_policy_bf_base_t::m_reservation_depth; } } rc += 0; @@ -70,11 +66,11 @@ int queue_policy_hybrid_t::apply_params () return rc; } -} // namespace Flux::queue_manager::detail -} // namespace Flux::queue_manager -} // namespace Flux +} // namespace detail +} // namespace queue_manager +} // namespace Flux -#endif // QUEUE_POLICY_HYBRID_IMPL_HPP +#endif // QUEUE_POLICY_HYBRID_IMPL_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/config/system_defaults.hpp b/resource/config/system_defaults.hpp index a8c33b8b8..42e3a9ac4 100644 --- a/resource/config/system_defaults.hpp +++ b/resource/config/system_defaults.hpp @@ -15,13 +15,13 @@ namespace Flux { namespace resource_model { namespace detail { - const int64_t SYSTEM_DEFAULT_DURATION = 43200; // 12 hours - const int64_t SYSTEM_MAX_DURATION = 3153600000; // 100 years -} // namespace detail -} // namespace resource_model -} // namespace Flux +const int64_t SYSTEM_DEFAULT_DURATION = 43200; // 12 hours +const int64_t SYSTEM_MAX_DURATION = 3153600000; // 100 years +} // namespace detail +} // namespace resource_model +} // namespace Flux -#endif // SYSTEM_DEFAULT_HPP +#endif // SYSTEM_DEFAULT_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/evaluators/edge_eval_api.cpp b/resource/evaluators/edge_eval_api.cpp index 3d52d5180..d7a6acd8f 100644 --- a/resource/evaluators/edge_eval_api.cpp +++ b/resource/evaluators/edge_eval_api.cpp @@ -19,36 +19,27 @@ extern "C" { namespace Flux { namespace resource_model { - - //////////////////////////////////////////////////////////////////////////////// // Edge Evaluator Public Method Definitions //////////////////////////////////////////////////////////////////////////////// eval_edg_t::eval_edg_t (unsigned int c, unsigned int n, unsigned int x, edg_t e) - : count (c), needs (n), exclusive (x), edge (e) + : count (c), needs (n), exclusive (x), edge (e) { - } eval_edg_t::eval_edg_t (unsigned int c, unsigned int n, unsigned int x) - : count (c), needs (n), exclusive (x) + : count (c), needs (n), exclusive (x) { - } - eval_egroup_t::eval_egroup_t () { - } -eval_egroup_t::eval_egroup_t (int64_t s, unsigned int c, unsigned int n, - unsigned int x, bool r) - : score (s), count (c), needs (n), exclusive (x), - root (r) +eval_egroup_t::eval_egroup_t (int64_t s, unsigned int c, unsigned int n, unsigned int x, bool r) + : score (s), count (c), needs (n), exclusive (x), root (r) { - } eval_egroup_t::eval_egroup_t (const eval_egroup_t &o) @@ -72,25 +63,19 @@ eval_egroup_t &eval_egroup_t::operator= (const eval_egroup_t &o) return *this; } - namespace detail { evals_t::evals_t () { - } evals_t::evals_t (int64_t cutline, const std::string &res_type) - : m_resrc_type (res_type), m_cutline (cutline) + : m_resrc_type (res_type), m_cutline (cutline) { - } - -evals_t::evals_t (const std::string &res_type) - : m_resrc_type (res_type) +evals_t::evals_t (const std::string &res_type) : m_resrc_type (res_type) { - } evals_t::evals_t (const evals_t &o) @@ -181,7 +166,8 @@ int evals_t::merge (evals_t &o) m_qual_count += o.m_qual_count; m_total_count += o.m_total_count; m_cutline = o.m_cutline; - m_eval_egroups.insert (m_eval_egroups.end (), o.m_eval_egroups.begin (), + m_eval_egroups.insert (m_eval_egroups.end (), + o.m_eval_egroups.begin (), o.m_eval_egroups.end ()); return 0; } @@ -196,8 +182,7 @@ std::vector::iterator evals_t::eval_egroups_iter_next () if (m_iter_cur_reset) { m_iter_cur = m_eval_egroups.begin (); m_iter_cur_reset = false; - } - else if (m_iter_cur != m_eval_egroups.end ()) { + } else if (m_iter_cur != m_eval_egroups.end ()) { m_iter_cur++; } return m_iter_cur; @@ -208,10 +193,9 @@ std::vector::iterator evals_t::eval_egroups_end () return m_eval_egroups.end (); } - -} // Flux::resource_model::detail -} // Flux::resource_model -} // Flux +} // namespace detail +} // namespace resource_model +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/evaluators/edge_eval_api.hpp b/resource/evaluators/edge_eval_api.hpp index 33356ee10..b9bc4f395 100644 --- a/resource/evaluators/edge_eval_api.hpp +++ b/resource/evaluators/edge_eval_api.hpp @@ -31,8 +31,7 @@ struct eval_edg_t { struct eval_egroup_t { eval_egroup_t (); - eval_egroup_t (int64_t s, unsigned int c, unsigned int n, - unsigned int x, bool r); + eval_egroup_t (int64_t s, unsigned int c, unsigned int n, unsigned int x, bool r); eval_egroup_t (const eval_egroup_t &o); eval_egroup_t &operator= (const eval_egroup_t &o); @@ -47,7 +46,7 @@ struct eval_egroup_t { namespace detail { class evals_t { -public: + public: evals_t (); evals_t (int64_t cutline, const std::string &res_type); evals_t (const std::string &res_type); @@ -97,7 +96,7 @@ class evals_t { } template - int64_t accum_best_k (binary_op accum, int init=0) + int64_t accum_best_k (binary_op accum, int init = 0) { if (m_best_k == 0 || m_best_i == 0) { errno = EINVAL; @@ -112,13 +111,10 @@ class evals_t { template output_it transform (output_it o_it, unary_op uop) { - return std::transform (m_eval_egroups.begin (), - m_eval_egroups.end (), - o_it, uop); + return std::transform (m_eval_egroups.begin (), m_eval_egroups.end (), o_it, uop); } - -private: + private: std::vector m_eval_egroups; std::vector::iterator m_iter_cur; bool m_iter_cur_reset = true; @@ -126,16 +122,16 @@ class evals_t { int64_t m_cutline = 0; unsigned int m_qual_count = 0; unsigned int m_total_count = 0; - unsigned int m_best_k = 0; //validate (key, value)) < 0) { + if ((rc = (&target)->validate (key, value)) < 0) { errno = EINVAL; goto done; } @@ -147,22 +141,22 @@ int expr_eval_api_t::validate_leaf (const std::string &e, int expr_eval_api_t::validate_paren (const std::string &e, const expr_eval_target_base_t &target, - size_t at, size_t &nx) + size_t at, + size_t &nx) { int rc = -1; std::size_t tok; std::size_t len; if (!is_paren (e, at)) { - if ( (rc = parse_expr_leaf (e, at, tok, len)) < 0) + if ((rc = parse_expr_leaf (e, at, tok, len)) < 0) goto done; - if ( (rc = validate_leaf (e.substr (tok, len), target)) < 0) + if ((rc = validate_leaf (e.substr (tok, len), target)) < 0) goto done; - } - else { - if ( (rc = parse_expr_paren (e, at, tok, len)) < 0) + } else { + if ((rc = parse_expr_paren (e, at, tok, len)) < 0) goto done; - if ( (rc = validate (e.substr (tok+1, len-2), target)) < 0) + if ((rc = validate (e.substr (tok + 1, len - 2), target)) < 0) goto done; } nx = tok + len; @@ -175,13 +169,13 @@ int expr_eval_api_t::validate_pred (pred_op_t op) const { int rc = 0; switch (op) { - case pred_op_t::AND: - break; - case pred_op_t::OR: - break; - default: - rc = -1; - errno = EINVAL; + case pred_op_t::AND: + break; + case pred_op_t::OR: + break; + default: + rc = -1; + errno = EINVAL; } return rc; } @@ -194,17 +188,17 @@ int expr_eval_api_t::evaluate_leaf (const std::string &e, std::size_t delim; std::string key, value; - if ( (delim = e.find_first_of ("=")) == std::string::npos) { + if ((delim = e.find_first_of ("=")) == std::string::npos) { errno = EINVAL; goto done; } key = e.substr (0, delim); value = e.substr (delim + 1); - if ( (rc = (&target)->validate (key, value)) < 0) { + if ((rc = (&target)->validate (key, value)) < 0) { errno = EINVAL; goto done; } - if ( (rc = (&target)->evaluate (key, value, result)) < 0) { + if ((rc = (&target)->evaluate (key, value, result)) < 0) { errno = EINVAL; goto done; } @@ -215,22 +209,23 @@ int expr_eval_api_t::evaluate_leaf (const std::string &e, int expr_eval_api_t::evaluate_paren (const std::string &e, const expr_eval_target_base_t &target, - size_t at, size_t &nx, bool &result) + size_t at, + size_t &nx, + bool &result) { int rc = -1; std::size_t tok; std::size_t len; if (!is_paren (e, at)) { - if ( (rc = parse_expr_leaf (e, at, tok, len)) < 0) + if ((rc = parse_expr_leaf (e, at, tok, len)) < 0) goto done; - if ( (rc = evaluate_leaf (e.substr (tok, len), target, result)) < 0) + if ((rc = evaluate_leaf (e.substr (tok, len), target, result)) < 0) goto done; - } - else { - if ( (rc = parse_expr_paren (e, at, tok, len)) < 0) + } else { + if ((rc = parse_expr_paren (e, at, tok, len)) < 0) goto done; - if ( (rc = evaluate (e.substr (tok+1, len-2), target, result)) < 0) + if ((rc = evaluate (e.substr (tok + 1, len - 2), target, result)) < 0) goto done; } nx = tok + len; @@ -239,50 +234,46 @@ int expr_eval_api_t::evaluate_paren (const std::string &e, return rc; } -int expr_eval_api_t::evaluate_pred (pred_op_t op, - bool result2, bool &result1) const +int expr_eval_api_t::evaluate_pred (pred_op_t op, bool result2, bool &result1) const { int rc = 0; switch (op) { - case pred_op_t::AND: - result1 = result1 && result2; - break; - case pred_op_t::OR: - result1 = result1 || result2; - break; - default: - rc = -1; - errno = EINVAL; + case pred_op_t::AND: + result1 = result1 && result2; + break; + case pred_op_t::OR: + result1 = result1 || result2; + break; + default: + rc = -1; + errno = EINVAL; } return rc; } - - //////////////////////////////////////////////////////////////////////////////// // Expression Evaluation API Public Method Definitions //////////////////////////////////////////////////////////////////////////////// -int expr_eval_api_t::validate (const std::string &e, - const expr_eval_target_base_t &target) +int expr_eval_api_t::validate (const std::string &e, const expr_eval_target_base_t &target) { int rc = -1; pred_op_t op; std::size_t next, at; - if ( (rc = validate_paren (e, target, 0, next)) < 0) + if ((rc = validate_paren (e, target, 0, next)) < 0) goto done; at = next; while (at <= e.find_last_not_of (" \t")) { - if ( (op = parse_pred_op (e, at, next)) == pred_op_t::UNKNOWN) { + if ((op = parse_pred_op (e, at, next)) == pred_op_t::UNKNOWN) { rc = -1; goto done; } at = next; - if ( (rc = validate_paren (e, target, at, next)) < 0) + if ((rc = validate_paren (e, target, at, next)) < 0) goto done; - if ( (rc = validate_pred (op)) < 0) + if ((rc = validate_pred (op)) < 0) goto done; at = next; } @@ -301,19 +292,19 @@ int expr_eval_api_t::evaluate (const std::string &e, std::size_t next, at; bool result1, result2; - if ( (rc = evaluate_paren (e, target, 0, next, result1)) < 0) + if ((rc = evaluate_paren (e, target, 0, next, result1)) < 0) goto done; at = next; while (at <= e.find_last_not_of (" \t")) { - if ( (op = parse_pred_op (e, at, next)) == pred_op_t::UNKNOWN) { + if ((op = parse_pred_op (e, at, next)) == pred_op_t::UNKNOWN) { rc = -1; goto done; } at = next; - if ( (rc = evaluate_paren (e, target, at, next, result2)) < 0) + if ((rc = evaluate_paren (e, target, at, next, result2)) < 0) goto done; - if ( (rc = evaluate_pred (op, result2, result1)) < 0) + if ((rc = evaluate_pred (op, result2, result1)) < 0) goto done; at = next; } @@ -324,9 +315,8 @@ int expr_eval_api_t::evaluate (const std::string &e, return rc; } - -} // Flux::resource_model -} // Flux +} // namespace resource_model +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/evaluators/expr_eval_api.hpp b/resource/evaluators/expr_eval_api.hpp index 73d3f0dfc..83407cd6a 100644 --- a/resource/evaluators/expr_eval_api.hpp +++ b/resource/evaluators/expr_eval_api.hpp @@ -28,8 +28,7 @@ namespace resource_model { * with these operators used in predicate calculus. */ class expr_eval_api_t { -public: - + public: /*! Validate if an expression is valid w/ respect to the target state. * * \param expr expression string @@ -37,8 +36,7 @@ class expr_eval_api_t { * of expr_eval_target_base_t type * \return 0 on success; -1 on error */ - int validate (const std::string &expr, - const expr_eval_target_base_t &target); + int validate (const std::string &expr, const expr_eval_target_base_t &target); /*! Evaluate if an expression is valid w/ respect to the target state. * @@ -47,49 +45,43 @@ class expr_eval_api_t { * of expr_eval_target_base_t type * \return 0 on success; -1 on error */ - int evaluate (const std::string &expr, - const expr_eval_target_base_t &target, bool &result); - -private: + int evaluate (const std::string &expr, const expr_eval_target_base_t &target, bool &result); - enum class pred_op_t : int { - AND=0, - OR=1, - UNKNOWN=2 - }; + private: + enum class pred_op_t : int { AND = 0, OR = 1, UNKNOWN = 2 }; bool is_paren (const std::string &expr, std::size_t at) const; size_t find_closing_paren (const std::string &expr, size_t at) const; /* Parse methods */ - int parse_expr_leaf (const std::string &expr, - size_t at, size_t &tok, size_t &len) const; - int parse_expr_paren (const std::string &expr, - size_t at, size_t &tok, size_t &len) const; - pred_op_t parse_pred_op (const std::string &e, - size_t at, size_t &next) const; + int parse_expr_leaf (const std::string &expr, size_t at, size_t &tok, size_t &len) const; + int parse_expr_paren (const std::string &expr, size_t at, size_t &tok, size_t &len) const; + pred_op_t parse_pred_op (const std::string &e, size_t at, size_t &next) const; /* Validate methods */ - int validate_leaf (const std::string &expr, - const expr_eval_target_base_t &target); + int validate_leaf (const std::string &expr, const expr_eval_target_base_t &target); int validate_paren (const std::string &expr, const expr_eval_target_base_t &target, - size_t at, size_t &nx); + size_t at, + size_t &nx); int validate_pred (pred_op_t op) const; /* Evaluate methods */ int evaluate_leaf (const std::string &expr, - const expr_eval_target_base_t &target, bool &result); + const expr_eval_target_base_t &target, + bool &result); int evaluate_paren (const std::string &expr, const expr_eval_target_base_t &target, - size_t at, size_t &next, bool &result); + size_t at, + size_t &next, + bool &result); int evaluate_pred (pred_op_t op, bool result2, bool &result1) const; }; -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // EXPR_EVAL_API_HPP +#endif // EXPR_EVAL_API_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/evaluators/expr_eval_target.hpp b/resource/evaluators/expr_eval_target.hpp index 67e92e876..fea16fd08 100644 --- a/resource/evaluators/expr_eval_target.hpp +++ b/resource/evaluators/expr_eval_target.hpp @@ -16,7 +16,6 @@ namespace Flux { namespace resource_model { - /*! Expression evaluation target base abstract class. * Define the interfaces that expr_eval_api_t uses to evaluate * and validate a leaf-level expression predicate: p(x). @@ -24,15 +23,14 @@ namespace resource_model { * Therefore, a derived class must override and implement them. */ class expr_eval_target_base_t { -public: - + public: /*! Validate a predicate expression. * As a predicate is often denoted as p(x), the method parameters * follow this convention: i.e., p for predicate name and x * for the input to the predicate. * * \param p predicate name - * \param x input to the predicate + * \param x input to the predicate * \return 0 on success; -1 on error */ virtual int validate (const std::string &p, const std::string &x) const = 0; @@ -48,14 +46,13 @@ class expr_eval_target_base_t { * this expression evaluation target. * \return 0 on success; -1 on error */ - virtual int evaluate (const std::string &p, - const std::string &x, bool &result) const = 0; + virtual int evaluate (const std::string &p, const std::string &x, bool &result) const = 0; }; -} // resource_model -} // Flux +} // namespace resource_model +} // namespace Flux -#endif // EXPR_EVAL_TARGET_HPP +#endif // EXPR_EVAL_TARGET_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/evaluators/expr_eval_vtx_target.cpp b/resource/evaluators/expr_eval_vtx_target.cpp index d5a738be1..77719ecaa 100644 --- a/resource/evaluators/expr_eval_vtx_target.cpp +++ b/resource/evaluators/expr_eval_vtx_target.cpp @@ -23,16 +23,15 @@ namespace resource_model { void vtx_predicates_override_t::set (bool sd, bool sna, bool sfr) { - if (sd) - status_down = true; - if (sna) - sched_now_allocated = true; - if (sfr) - sched_future_reserved = true; + if (sd) + status_down = true; + if (sna) + sched_now_allocated = true; + if (sfr) + sched_future_reserved = true; } -int expr_eval_vtx_target_t::validate (const std::string &p, - const std::string &x) const +int expr_eval_vtx_target_t::validate (const std::string &p, const std::string &x) const { int rc = -1; std::string lcx = x; @@ -41,13 +40,13 @@ int expr_eval_vtx_target_t::validate (const std::string &p, errno = EINVAL; goto done; } - std::transform (x.begin(), x.end(), lcx.begin(), ::tolower); + std::transform (x.begin (), x.end (), lcx.begin (), ::tolower); if (p == "status") - rc = (lcx == "down" || lcx == "up")? 0 : -1; + rc = (lcx == "down" || lcx == "up") ? 0 : -1; else if (p == "sched-now") - rc = (lcx == "allocated" || lcx == "free")? 0 : -1; + rc = (lcx == "allocated" || lcx == "free") ? 0 : -1; else if (p == "sched-future") - rc = (lcx == "reserved" || lcx == "free")? 0 : -1; + rc = (lcx == "reserved" || lcx == "free") ? 0 : -1; else errno = EINVAL; done: @@ -55,37 +54,36 @@ int expr_eval_vtx_target_t::validate (const std::string &p, } int expr_eval_vtx_target_t::evaluate (const std::string &p, - const std::string &x, bool &result) const + const std::string &x, + bool &result) const { int rc = 0; std::string lcx = x; - if ( (rc = validate (p, x)) < 0) + if ((rc = validate (p, x)) < 0) goto done; - std::transform (x.begin(), x.end(), lcx.begin(), ::tolower); + std::transform (x.begin (), x.end (), lcx.begin (), ::tolower); if (p == "status") { if (lcx == "down") { - result = m_overridden.status_down - || ((*m_g)[m_u].status == resource_pool_t::status_t::DOWN); + result = + m_overridden.status_down || ((*m_g)[m_u].status == resource_pool_t::status_t::DOWN); } else if (lcx == "up") { - result = !m_overridden.status_down - && (*m_g)[m_u].status == resource_pool_t::status_t::UP; + result = + !m_overridden.status_down && (*m_g)[m_u].status == resource_pool_t::status_t::UP; } } else if (p == "sched-now") { if (lcx == "allocated") { - result = m_overridden.sched_now_allocated - || !(*m_g)[m_u].schedule.allocations.empty (); + result = m_overridden.sched_now_allocated || !(*m_g)[m_u].schedule.allocations.empty (); } else if (lcx == "free") { - result = !m_overridden.sched_now_allocated - && (*m_g)[m_u].schedule.allocations.empty (); + result = !m_overridden.sched_now_allocated && (*m_g)[m_u].schedule.allocations.empty (); } } else if (p == "sched-future") { if (lcx == "reserved") { - result = m_overridden.sched_future_reserved - || !(*m_g)[m_u].schedule.reservations.empty (); + result = + m_overridden.sched_future_reserved || !(*m_g)[m_u].schedule.reservations.empty (); } else if (lcx == "free") { - result = !m_overridden.sched_future_reserved - && (*m_g)[m_u].schedule.reservations.empty (); + result = + !m_overridden.sched_future_reserved && (*m_g)[m_u].schedule.reservations.empty (); } } else { rc = -1; @@ -105,8 +103,8 @@ void expr_eval_vtx_target_t::initialize (const vtx_predicates_override_t &p, m_u = u; } -} // Flux::resource_model -} // Flux +} // namespace resource_model +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/evaluators/expr_eval_vtx_target.hpp b/resource/evaluators/expr_eval_vtx_target.hpp index f4c1b2f1c..d5b5d2d54 100644 --- a/resource/evaluators/expr_eval_vtx_target.hpp +++ b/resource/evaluators/expr_eval_vtx_target.hpp @@ -36,7 +36,6 @@ struct vtx_predicates_override_t { void set (bool sd, bool sna, bool sfr); }; - /*! Expression evaluation resource vertex target class. * Each resource vertex defines a set of predicates that * return true or false based on its current state. @@ -46,8 +45,7 @@ struct vtx_predicates_override_t { * its validate and evaluate interfaces to do this work. */ class expr_eval_vtx_target_t : public expr_eval_target_base_t { -public: - + public: /*! Validate if a predicate expression is valid w/ respect to * a resource vertex. * As a predicate is often denoted as p(x), the method parameters @@ -71,8 +69,7 @@ class expr_eval_vtx_target_t : public expr_eval_target_base_t { * this vertex expression evaluation target. * \return 0 on success; -1 on error */ - virtual int evaluate (const std::string &p, - const std::string &x, bool &result) const; + virtual int evaluate (const std::string &p, const std::string &x, bool &result) const; /*! Initialize the object of this class with a resource vertex. * This must be called before the validate and evaluate interfaces @@ -90,17 +87,17 @@ class expr_eval_vtx_target_t : public expr_eval_target_base_t { */ bool is_initialized () const; -private: + private: bool m_initialized{false}; vtx_predicates_override_t m_overridden; const resource_graph_t *m_g; vtx_t m_u; }; -} // resource_model -} // Flux +} // namespace resource_model +} // namespace Flux -#endif // EXPR_EVAL_VTX_TARGET_HPP +#endif // EXPR_EVAL_VTX_TARGET_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/evaluators/fold.hpp b/resource/evaluators/fold.hpp index 10a31658c..b0f9f419d 100644 --- a/resource/evaluators/fold.hpp +++ b/resource/evaluators/fold.hpp @@ -50,25 +50,23 @@ struct interval_less { }; struct plus { - inline const int64_t operator() (const int64_t &result, - const eval_egroup_t &a) const + inline const int64_t operator() (const int64_t &result, const eval_egroup_t &a) const { return result + a.score; } }; -inline boost::icl::interval_set::interval_type to_interval ( - const eval_egroup_t &ev) +inline boost::icl::interval_set::interval_type to_interval (const eval_egroup_t &ev) { using namespace boost::icl; int64_t tmp = ev.score; return interval_set::interval_type::closed (tmp, tmp); } -} // namespace fold +} // namespace fold -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // FOLD_HPP +#endif // FOLD_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/evaluators/scoring_api.cpp b/resource/evaluators/scoring_api.cpp index 83d4f57c7..2ac2f4ba8 100644 --- a/resource/evaluators/scoring_api.cpp +++ b/resource/evaluators/scoring_api.cpp @@ -19,14 +19,11 @@ extern "C" { namespace Flux { namespace resource_model { - - //////////////////////////////////////////////////////////////////////////////// // Scoring API Private Method Definitions //////////////////////////////////////////////////////////////////////////////// -void scoring_api_t::handle_new_keys (const subsystem_t &s, - const std::string &r) +void scoring_api_t::handle_new_keys (const subsystem_t &s, const std::string &r) { handle_new_subsystem (s); handle_new_resrc_type (s, r); @@ -35,13 +32,12 @@ void scoring_api_t::handle_new_keys (const subsystem_t &s, void scoring_api_t::handle_new_subsystem (const subsystem_t &s) { if (m_ssys_map.find (s) == m_ssys_map.end ()) { - auto o = new std::map(); + auto o = new std::map (); m_ssys_map.insert (std::make_pair (s, o)); } } -void scoring_api_t::handle_new_resrc_type (const subsystem_t &s, - const std::string &r) +void scoring_api_t::handle_new_resrc_type (const subsystem_t &s, const std::string &r) { if (m_ssys_map[s]->find (r) == m_ssys_map[s]->end ()) { auto e = new detail::evals_t (r); @@ -49,22 +45,19 @@ void scoring_api_t::handle_new_resrc_type (const subsystem_t &s, } } - - //////////////////////////////////////////////////////////////////////////////// // Scoring API Public Method Definitions //////////////////////////////////////////////////////////////////////////////// scoring_api_t::scoring_api_t () { - } scoring_api_t::scoring_api_t (const scoring_api_t &o) { for (auto &p : o.m_ssys_map) { const subsystem_t &s = p.first; - auto obj = new std::map(); + auto obj = new std::map (); m_ssys_map.insert (std::make_pair (s, obj)); auto &tmap = *(p.second); for (auto &p2 : tmap) { @@ -80,7 +73,7 @@ const scoring_api_t &scoring_api_t::operator= (const scoring_api_t &o) { for (auto &p : o.m_ssys_map) { const subsystem_t &s = p.first; - auto obj = new std::map(); + auto obj = new std::map (); m_ssys_map.insert (std::make_pair (s, obj)); auto &tmap = *(p.second); for (auto &p2 : tmap) { @@ -115,43 +108,37 @@ int64_t scoring_api_t::cutline (const subsystem_t &s, const std::string &r) return res_evals->cutline (); } -int64_t scoring_api_t::set_cutline (const subsystem_t &s, const std::string &r, - int64_t c) +int64_t scoring_api_t::set_cutline (const subsystem_t &s, const std::string &r, int64_t c) { handle_new_keys (s, r); auto res_evals = (*m_ssys_map[s])[r]; return res_evals->set_cutline (c); } - -void scoring_api_t::eval_egroups_iter_reset (const subsystem_t &s, - const std::string &r) +void scoring_api_t::eval_egroups_iter_reset (const subsystem_t &s, const std::string &r) { handle_new_keys (s, r); auto res_evals = (*m_ssys_map[s])[r]; res_evals->eval_egroups_iter_reset (); } -std::vector::iterator scoring_api_t::eval_egroups_iter_next ( - const subsystem_t &s, - const std::string &r) +std::vector::iterator scoring_api_t::eval_egroups_iter_next (const subsystem_t &s, + const std::string &r) { handle_new_keys (s, r); auto res_evals = (*m_ssys_map[s])[r]; return res_evals->eval_egroups_iter_next (); } -std::vector::iterator scoring_api_t::eval_egroups_end ( - const subsystem_t &s, - const std::string &r) +std::vector::iterator scoring_api_t::eval_egroups_end (const subsystem_t &s, + const std::string &r) { handle_new_keys (s, r); auto res_evals = (*m_ssys_map[s])[r]; return res_evals->eval_egroups_end (); } -int scoring_api_t::add (const subsystem_t &s, const std::string &r, - const eval_egroup_t &eg) +int scoring_api_t::add (const subsystem_t &s, const std::string &r, const eval_egroup_t &eg) { handle_new_keys (s, r); auto res_evals = (*m_ssys_map[s])[r]; @@ -159,32 +146,28 @@ int scoring_api_t::add (const subsystem_t &s, const std::string &r, } //! Can throw an out_of_range exception -const eval_egroup_t &scoring_api_t::at (const subsystem_t &s, - const std::string &r, unsigned int i) +const eval_egroup_t &scoring_api_t::at (const subsystem_t &s, const std::string &r, unsigned int i) { handle_new_keys (s, r); auto res_evals = (*m_ssys_map[s])[r]; - return res_evals->at(i); + return res_evals->at (i); } -unsigned int scoring_api_t::qualified_count (const subsystem_t &s, - const std::string &r) +unsigned int scoring_api_t::qualified_count (const subsystem_t &s, const std::string &r) { handle_new_keys (s, r); auto res_evals = (*m_ssys_map[s])[r]; return res_evals->qualified_count (); } -unsigned int scoring_api_t::qualified_granules (const subsystem_t &s, - const std::string &r) +unsigned int scoring_api_t::qualified_granules (const subsystem_t &s, const std::string &r) { handle_new_keys (s, r); auto res_evals = (*m_ssys_map[s])[r]; return res_evals->qualified_granules (); } -unsigned int scoring_api_t::total_count (const subsystem_t &s, - const std::string &r) +unsigned int scoring_api_t::total_count (const subsystem_t &s, const std::string &r) { handle_new_keys (s, r); auto res_evals = (*m_ssys_map[s])[r]; @@ -225,8 +208,7 @@ void scoring_api_t::merge (const scoring_api_t &o) } } -void scoring_api_t::resrc_types (const subsystem_t &s, - std::vector &v) +void scoring_api_t::resrc_types (const subsystem_t &s, std::vector &v) { handle_new_subsystem (s); for (auto &kv : *(m_ssys_map[s])) @@ -255,8 +237,7 @@ void scoring_api_t::set_avail (unsigned int avail) m_avail = avail; } -bool scoring_api_t::is_contained (const subsystem_t &s, - const std::string &r) +bool scoring_api_t::is_contained (const subsystem_t &s, const std::string &r) { bool rc = false; if (m_ssys_map.find (s) != m_ssys_map.end ()) { @@ -267,9 +248,8 @@ bool scoring_api_t::is_contained (const subsystem_t &s, return rc; } - -} // Flux::resource_model -} // Flux +} // namespace resource_model +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/evaluators/scoring_api.hpp b/resource/evaluators/scoring_api.hpp index 28bb6bf74..3494b9c37 100644 --- a/resource/evaluators/scoring_api.hpp +++ b/resource/evaluators/scoring_api.hpp @@ -26,7 +26,7 @@ namespace Flux { namespace resource_model { class scoring_api_t { -public: + public: scoring_api_t (); scoring_api_t (const scoring_api_t &o); const scoring_api_t &operator= (const scoring_api_t &o); @@ -36,17 +36,14 @@ class scoring_api_t { int64_t set_cutline (const subsystem_t &s, const std::string &r, int64_t c); void eval_egroups_iter_reset (const subsystem_t &s, const std::string &r); - std::vector::iterator eval_egroups_iter_next ( - const subsystem_t &s, - const std::string &r); + std::vector::iterator eval_egroups_iter_next (const subsystem_t &s, + const std::string &r); std::vector::iterator eval_egroups_end (const subsystem_t &s, const std::string &r); - int add (const subsystem_t &s, const std::string &r, - const eval_egroup_t &eg); + int add (const subsystem_t &s, const std::string &r, const eval_egroup_t &eg); //! Can throw an out_of_range exception - const eval_egroup_t &at (const subsystem_t &s, const std::string &r, - unsigned int i); + const eval_egroup_t &at (const subsystem_t &s, const std::string &r, unsigned int i); unsigned int qualified_count (const subsystem_t &s, const std::string &r); unsigned int qualified_granules (const subsystem_t &s, const std::string &r); unsigned int total_count (const subsystem_t &s, const std::string &r); @@ -62,15 +59,16 @@ class scoring_api_t { bool is_contained (const subsystem_t &s, const std::string &r); template - int64_t choose_accum_best_k (const subsystem_t &s, const std::string &r, + int64_t choose_accum_best_k (const subsystem_t &s, + const std::string &r, unsigned int k, - compare_op comp = fold::greater(), + compare_op comp = fold::greater (), binary_op accum = fold::plus ()) { int64_t rc; handle_new_keys (s, r); auto res_evals = (*m_ssys_map[s])[r]; - if ( (rc = res_evals->choose_best_k (k, comp)) != -1) { + if ((rc = res_evals->choose_best_k (k, comp)) != -1) { m_hier_constrain_now = true; rc = res_evals->accum_best_k (accum); } @@ -78,7 +76,8 @@ class scoring_api_t { } template - int64_t choose_accum_all (const subsystem_t &s, const std::string &r, + int64_t choose_accum_all (const subsystem_t &s, + const std::string &r, compare_op comp = fold::greater (), binary_op accum = fold::plus ()) { @@ -86,7 +85,7 @@ class scoring_api_t { handle_new_keys (s, r); auto res_evals = (*m_ssys_map[s])[r]; unsigned int k = res_evals->qualified_count (); - if ( (rc = res_evals->choose_best_k (k, comp)) != -1) { + if ((rc = res_evals->choose_best_k (k, comp)) != -1) { m_hier_constrain_now = true; rc = res_evals->accum_best_k (accum); } @@ -94,30 +93,28 @@ class scoring_api_t { } template - output_it transform (const subsystem_t &s, const std::string &r, - output_it o_it, unary_op uop) + output_it transform (const subsystem_t &s, const std::string &r, output_it o_it, unary_op uop) { handle_new_keys (s, r); auto res_evals = (*m_ssys_map[s])[r]; return res_evals->transform (o_it, uop); } -private: + private: void handle_new_keys (const subsystem_t &s, const std::string &r); void handle_new_subsystem (const subsystem_t &s); void handle_new_resrc_type (const subsystem_t &s, const std::string &r); - std::map *> m_ssys_map; + std::map *> m_ssys_map; bool m_hier_constrain_now = false; int64_t m_overall_score = -1; unsigned int m_avail = 0; }; -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // SCORING_API_HPP +#endif // SCORING_API_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/evaluators/test/expr_eval_test01.cpp b/resource/evaluators/test/expr_eval_test01.cpp index 37bf50e6f..0596b1e69 100644 --- a/resource/evaluators/test/expr_eval_test01.cpp +++ b/resource/evaluators/test/expr_eval_test01.cpp @@ -24,31 +24,29 @@ using namespace Flux; using namespace Flux::resource_model; class expr_eval_test_target_t : public expr_eval_target_base_t { -public: - + public: virtual int validate (const std::string &p, const std::string &x) const; - virtual int evaluate (const std::string &p, - const std::string &x, bool &result) const; + virtual int evaluate (const std::string &p, const std::string &x, bool &result) const; }; -int expr_eval_test_target_t::validate (const std::string &p, - const std::string &x) const +int expr_eval_test_target_t::validate (const std::string &p, const std::string &x) const { if (p != "status" && p != "sched-now") return -1; if (p == "status" && (x != "up" && x != "down")) return -1; if (p == "sched-now" && (x != "allocated" && x != "free")) - return -1; + return -1; return 0; } int expr_eval_test_target_t::evaluate (const std::string &p, - const std::string &x, bool &result) const + const std::string &x, + bool &result) const { int rc = -1; - if ( (rc = validate (p, x)) < 0) + if ((rc = validate (p, x)) < 0) return rc; result = true; return rc; @@ -85,7 +83,8 @@ void build_simple_expr (std::vector &expr_vector) void build_paren_expr (std::vector &expr_vector) { - expr_vector.push_back ("(status=up and sched-now=allocated) " + expr_vector.push_back ( + "(status=up and sched-now=allocated) " "and (sched-now=free and status=down)"); expr_vector.push_back ( "status=up and sched-now=allocated " @@ -93,35 +92,40 @@ void build_paren_expr (std::vector &expr_vector) expr_vector.push_back ( "status=up and sched-now=allocated " "and sched-now=free and status=down "); + expr_vector.push_back ("status=up sched-now=allocated (( sched-now=free status=down))"); expr_vector.push_back ( - "status=up sched-now=allocated (( sched-now=free status=down))"); - expr_vector.push_back ("status=up sched-now=allocated " + "status=up sched-now=allocated " "(( sched-now=free and (status=down or sched-now=allocated)))"); - expr_vector.push_back ("status=up sched-now=allocated " + expr_vector.push_back ( + "status=up sched-now=allocated " "(sched-now=free (status=down or sched-now=allocated))"); - expr_vector.push_back ("sched-now=free and " + expr_vector.push_back ( + "sched-now=free and " "(status=down or sched-now=allocated) and status=up"); } void build_invalid_expr (std::vector &expr_vector) { - expr_vector.push_back ( - "status=up sched-now=allocated (( sched=free status=down)"); + expr_vector.push_back ("status=up sched-now=allocated (( sched=free status=down)"); expr_vector.push_back ("status=up and sched-now=foo"); expr_vector.push_back ("sched-now=free status=down and"); expr_vector.push_back ("sched-now=free status=d own"); - expr_vector.push_back ("(status=up (sched-now=allocated) " + expr_vector.push_back ( + "(status=up (sched-now=allocated) " "and (sched-now=free and) status=down)"); - expr_vector.push_back ("(status=up (sched-now=allocated) " + expr_vector.push_back ( + "(status=up (sched-now=allocated) " "and (sched-now=free)status=down)"); - expr_vector.push_back ("(status=up)(sched-now=allocated)" + expr_vector.push_back ( + "(status=up)(sched-now=allocated)" "(sched-now=free)(status=down)"); expr_vector.push_back ("(status=up and sched-now=allocated))"); expr_vector.push_back ("(status=up and sched-now=allocated)))"); } void test_validation (std::vector &expr_vector, - const std::string &label, bool must_success) + const std::string &label, + bool must_success) { int rc = 0; bool expected = false; @@ -130,13 +134,14 @@ void test_validation (std::vector &expr_vector, for (const auto &expr : expr_vector) { rc = evaluator.validate (expr, expr_eval_test_target); - expected = must_success? rc == 0 : rc < 0; + expected = must_success ? rc == 0 : rc < 0; ok (expected, "%s: ^%s$", label.c_str (), expr.c_str ()); } } void test_evaluation (std::vector &expr_vector, - const std::string &label, bool must_success) + const std::string &label, + bool must_success) { int rc = 0; bool expected = false; @@ -148,10 +153,9 @@ void test_evaluation (std::vector &expr_vector, for (const auto &expr : expr_vector) { result = false; rc = evaluator.evaluate (expr, expr_eval_test_target, result); - expected = must_success? rc == 0 : rc < 0; - expected_result = must_success? result : !result; - ok (expected && expected_result, - "%s: ^%s$", label.c_str (), expr.c_str ()); + expected = must_success ? rc == 0 : rc < 0; + expected_result = must_success ? result : !result; + ok (expected && expected_result, "%s: ^%s$", label.c_str (), expr.c_str ()); } } @@ -168,8 +172,8 @@ int main (int argc, char *argv[]) build_invalid_expr (expr_vector3); - ntests = expr_vector1.size () - + expr_vector2.size () + expr_vector3.size ();; + ntests = expr_vector1.size () + expr_vector2.size () + expr_vector3.size (); + ; plan (2 * ntests); diff --git a/resource/jobinfo/jobinfo.cpp b/resource/jobinfo/jobinfo.cpp index 10bc77553..577610aa2 100644 --- a/resource/jobinfo/jobinfo.cpp +++ b/resource/jobinfo/jobinfo.cpp @@ -20,47 +20,58 @@ extern "C" { namespace Flux { namespace resource_model { -job_info_t::job_info_t (uint64_t j, job_lifecycle_t s, int64_t at, const std::string &fn, - const std::string &jstr, const std::string &R_str, double o) - : jobid (j), state (s), scheduled_at (at), jobspec_fn (fn), jobspec_str (jstr), - R (R_str), overhead (o) +job_info_t::job_info_t (uint64_t j, + job_lifecycle_t s, + int64_t at, + const std::string &fn, + const std::string &jstr, + const std::string &R_str, + double o) + : jobid (j), + state (s), + scheduled_at (at), + jobspec_fn (fn), + jobspec_str (jstr), + R (R_str), + overhead (o) { - } -job_info_t::job_info_t (uint64_t j, job_lifecycle_t s, int64_t at, const std::string &fn, - const std::string &jstr, double o) - : jobid (j), state (s), scheduled_at (at), jobspec_fn (fn), jobspec_str (jstr), - overhead (o) +job_info_t::job_info_t (uint64_t j, + job_lifecycle_t s, + int64_t at, + const std::string &fn, + const std::string &jstr, + double o) + : jobid (j), state (s), scheduled_at (at), jobspec_fn (fn), jobspec_str (jstr), overhead (o) { - } void get_jobstate_str (job_lifecycle_t state, std::string &status) { switch (state) { - case job_lifecycle_t::ALLOCATED: - status = "ALLOCATED"; - break; - case job_lifecycle_t::RESERVED: - status = "RESERVED"; - break; - case job_lifecycle_t::CANCELED: - status = "CANCELED"; - break; - case job_lifecycle_t::ERROR: - status = "ERROR"; - break; - case job_lifecycle_t::INIT: - default: - status = "INIT"; - break; + case job_lifecycle_t::ALLOCATED: + status = "ALLOCATED"; + break; + case job_lifecycle_t::RESERVED: + status = "RESERVED"; + break; + case job_lifecycle_t::CANCELED: + status = "CANCELED"; + break; + case job_lifecycle_t::ERROR: + status = "ERROR"; + break; + case job_lifecycle_t::INIT: + default: + status = "INIT"; + break; } return; } -} -} +} // namespace resource_model +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/jobinfo/jobinfo.hpp b/resource/jobinfo/jobinfo.hpp index 6c0507a47..3d268fc3b 100644 --- a/resource/jobinfo/jobinfo.hpp +++ b/resource/jobinfo/jobinfo.hpp @@ -20,12 +20,20 @@ namespace resource_model { enum class job_lifecycle_t { INIT, ALLOCATED, RESERVED, CANCELED, ERROR }; struct job_info_t { - job_info_t (uint64_t j, job_lifecycle_t s, int64_t at, - const std::string &j_fn, const std::string &jstr, - const std::string &R_str, double o); - - job_info_t (uint64_t j, job_lifecycle_t s, int64_t at, - const std::string &j_fn, const std::string &jstr, double o); + job_info_t (uint64_t j, + job_lifecycle_t s, + int64_t at, + const std::string &j_fn, + const std::string &jstr, + const std::string &R_str, + double o); + + job_info_t (uint64_t j, + job_lifecycle_t s, + int64_t at, + const std::string &j_fn, + const std::string &jstr, + double o); uint64_t jobid = UINT64_MAX; job_lifecycle_t state = job_lifecycle_t::INIT; @@ -38,10 +46,10 @@ struct job_info_t { void get_jobstate_str (job_lifecycle_t state, std::string &status); -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // JOBINFO_HPP +#endif // JOBINFO_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/libjobspec/constraint.cpp b/resource/libjobspec/constraint.cpp index 821066503..fab8d4972 100644 --- a/resource/libjobspec/constraint.cpp +++ b/resource/libjobspec/constraint.cpp @@ -27,30 +27,30 @@ using namespace Flux::Jobspec; // Derived Constraint classes: // class PropertyConstraint : public Constraint { -public: - PropertyConstraint (const YAML::Node&); + public: + PropertyConstraint (const YAML::Node &); PropertyConstraint (); ~PropertyConstraint () = default; -private: + private: std::vector values; -public: + public: virtual bool match (const Flux::resource_model::resource_t &resource) const; virtual YAML::Node as_yaml () const; }; class ConditionalConstraint : public Constraint { -public: - ConditionalConstraint (std::string&, const YAML::Node&); + public: + ConditionalConstraint (std::string &, const YAML::Node &); ConditionalConstraint () = default; ~ConditionalConstraint () {}; -private: + private: std::string op; std::vector> values; -public: + public: virtual bool match (const Flux::resource_model::resource_t &resource) const; bool match_and (const Flux::resource_model::resource_t &resource) const; bool match_or (const Flux::resource_model::resource_t &resource) const; @@ -58,8 +58,7 @@ class ConditionalConstraint : public Constraint { virtual YAML::Node as_yaml () const; }; -std::unique_ptr -Flux::Jobspec::constraint_parser (const YAML::Node &constraint) +std::unique_ptr Flux::Jobspec::constraint_parser (const YAML::Node &constraint) { YAML::const_iterator it; YAML::Node operands; @@ -67,35 +66,31 @@ Flux::Jobspec::constraint_parser (const YAML::Node &constraint) if (!constraint.IsMap ()) throw parse_error (constraint, "constraint is not a mapping"); if (constraint.size () > 1) - throw parse_error (constraint, - "constraint map may not contain > 1 operation"); + throw parse_error (constraint, "constraint map may not contain > 1 operation"); if (constraint.size () == 0) - return std::unique_ptr(new Constraint()); + return std::unique_ptr (new Constraint ()); - it = constraint.begin(); - std::string operation = it->first.as(); + it = constraint.begin (); + std::string operation = it->first.as (); operands = it->second; if (!operands.IsSequence ()) { std::string msg = operation + " operator value must be an array"; - throw parse_error (operands, msg.c_str()); + throw parse_error (operands, msg.c_str ()); } if (operation == "properties") - return std::unique_ptr - (new PropertyConstraint (operands)); + return std::unique_ptr (new PropertyConstraint (operands)); else if (operation == "hostlist") - return std::unique_ptr - (new HostlistConstraint (operands)); + return std::unique_ptr (new HostlistConstraint (operands)); else if (operation == "ranks") - return std::unique_ptr - (new RankConstraint (operands)); + return std::unique_ptr (new RankConstraint (operands)); else if (operation == "and" || operation == "or" || operation == "not") - return std::unique_ptr - (new ConditionalConstraint (operation, operands)); + return std::unique_ptr ( + new ConditionalConstraint (operation, operands)); std::string msg = "unknown constraint operator: " + operation; - throw parse_error (constraint, msg.c_str()); + throw parse_error (constraint, msg.c_str ()); } // base Constraint implementation @@ -104,7 +99,7 @@ Flux::Jobspec::constraint_parser (const YAML::Node &constraint) // Base Constraint returns an empty map YAML::Node Constraint::as_yaml () const { - return YAML::Node(YAML::NodeType::Map); + return YAML::Node (YAML::NodeType::Map); } // Base Constraint always matches @@ -118,29 +113,29 @@ bool Constraint::match (const Flux::resource_model::resource_t &r) const PropertyConstraint::PropertyConstraint (const YAML::Node &properties) { - for (auto&& property: properties) { + for (auto &&property : properties) { // YAML::Node::as will work on a non-string YAML node. // use Tag() instead to determine if the scalar is a quoted string, // in which case "!" is returned. // // Ref: https://yaml.org/spec/1.2-old/spec.html#id2804923 - if (!property.IsScalar() || property.Tag() != "!") + if (!property.IsScalar () || property.Tag () != "!") throw parse_error (properties, "non-string property specified"); - std::string prop = property.as(); + std::string prop = property.as (); if (prop[0] == '^') prop = prop.substr (1); if (prop.find_first_of ("!&\'\"^`|()") != std::string::npos) { - std::string errmsg = property.as() + " is invalid"; + std::string errmsg = property.as () + " is invalid"; throw parse_error (properties, errmsg.c_str ()); } - values.push_back(property.as()); + values.push_back (property.as ()); } } bool PropertyConstraint::match (const Flux::resource_model::resource_t &r) const { - for (auto&& value: values) { + for (auto &&value : values) { std::string property = value; bool negate = false; @@ -160,44 +155,39 @@ bool PropertyConstraint::match (const Flux::resource_model::resource_t &r) const YAML::Node PropertyConstraint::as_yaml () const { YAML::Node node; - for (auto && property: values) + for (auto &&property : values) node["properties"].push_back (property); return node; } - // ConditionalConstraint implementation -ConditionalConstraint::ConditionalConstraint (std::string &operation, - const YAML::Node &vals) +ConditionalConstraint::ConditionalConstraint (std::string &operation, const YAML::Node &vals) { op = operation; - for (auto&& constraint: vals) + for (auto &&constraint : vals) values.emplace_back (constraint_parser (constraint)); } -bool -ConditionalConstraint::match_and (const Flux::resource_model::resource_t &r) const +bool ConditionalConstraint::match_and (const Flux::resource_model::resource_t &r) const { - for (auto&& constraint: values) { + for (auto &&constraint : values) { if (!constraint->match (r)) return false; } return true; } -bool -ConditionalConstraint::match_or (const Flux::resource_model::resource_t &r) const +bool ConditionalConstraint::match_or (const Flux::resource_model::resource_t &r) const { - for (auto&& constraint: values) { + for (auto &&constraint : values) { if (constraint->match (r)) return true; } return false; } -bool -ConditionalConstraint::match (const Flux::resource_model::resource_t &r) const +bool ConditionalConstraint::match (const Flux::resource_model::resource_t &r) const { if (op == "and") return match_and (r); @@ -211,8 +201,7 @@ ConditionalConstraint::match (const Flux::resource_model::resource_t &r) const YAML::Node ConditionalConstraint::as_yaml () const { YAML::Node node; - for (auto&& constraint: values) - node[op].push_back(constraint->as_yaml ()); + for (auto &&constraint : values) + node[op].push_back (constraint->as_yaml ()); return node; } - diff --git a/resource/libjobspec/constraint.hpp b/resource/libjobspec/constraint.hpp index 7b4b5524b..0940e97f0 100644 --- a/resource/libjobspec/constraint.hpp +++ b/resource/libjobspec/constraint.hpp @@ -26,7 +26,7 @@ namespace Flux { namespace Jobspec { class Constraint { -public: + public: Constraint () = default; virtual ~Constraint () = default; virtual bool match (const Flux::resource_model::resource_t &resource) const; @@ -35,7 +35,7 @@ class Constraint { std::unique_ptr constraint_parser (const YAML::Node &constraint); -} // namespace Jobspec -} // namespace Flux +} // namespace Jobspec +} // namespace Flux -#endif // JOBSPEC_CONSTRAINT_HPP +#endif // JOBSPEC_CONSTRAINT_HPP diff --git a/resource/libjobspec/flux-jobspec-validate.cpp b/resource/libjobspec/flux-jobspec-validate.cpp index 6995b4a9b..e8167800f 100644 --- a/resource/libjobspec/flux-jobspec-validate.cpp +++ b/resource/libjobspec/flux-jobspec-validate.cpp @@ -23,10 +23,10 @@ extern "C" { using namespace std; using namespace Flux::Jobspec; -void parse_yaml_stream_docs (std::istream& js_stream) +void parse_yaml_stream_docs (std::istream &js_stream) { bool first = true; - for (auto&& rootnode: YAML::LoadAll (js_stream)) { + for (auto &&rootnode : YAML::LoadAll (js_stream)) { Jobspec js; if (!first) cout << endl; @@ -37,7 +37,7 @@ void parse_yaml_stream_docs (std::istream& js_stream) } } -int main(int argc, char *argv[]) +int main (int argc, char *argv[]) { try { if (argc == 1) { @@ -45,14 +45,14 @@ int main(int argc, char *argv[]) } else { for (int i = 1; i < argc; i++) { std::ifstream js_file (argv[i]); - if (js_file.fail()) { + if (js_file.fail ()) { cerr << argv[0] << ": Unable to open file \"" << argv[i] << "\"" << endl; return 1; } parse_yaml_stream_docs (js_file); } } - } catch (parse_error& e) { + } catch (parse_error &e) { cerr << argv[0] << ": "; if (e.position != -1) cerr << argv[0] << "position " << e.position << ", "; @@ -60,7 +60,7 @@ int main(int argc, char *argv[]) cerr << argv[0] << "line " << e.line << ", "; if (e.column != -1) cerr << "column " << e.column << ", "; - cerr << e.what() << endl; + cerr << e.what () << endl; return 2; } catch (...) { cerr << argv[0] << ": Unknown non-standard exception" << endl; diff --git a/resource/libjobspec/hostlist_constraint.cpp b/resource/libjobspec/hostlist_constraint.cpp index 0f75f30ff..62f2fc075 100644 --- a/resource/libjobspec/hostlist_constraint.cpp +++ b/resource/libjobspec/hostlist_constraint.cpp @@ -22,12 +22,12 @@ HostlistConstraint::HostlistConstraint (const YAML::Node &values) { if (!(hl = hostlist_create ())) throw parse_error (values, "Out of memory"); - for (auto&& val: values) { - std::string hosts = val.as(); - if (hostlist_append (hl, hosts.c_str()) < 0) { + for (auto &&val : values) { + std::string hosts = val.as (); + if (hostlist_append (hl, hosts.c_str ()) < 0) { hostlist_destroy (hl); std::string msg = "Invalid hostlist `" + hosts + "'"; - throw parse_error (val, msg.c_str()); + throw parse_error (val, msg.c_str ()); } } } @@ -35,7 +35,7 @@ HostlistConstraint::HostlistConstraint (const YAML::Node &values) bool HostlistConstraint::match (const Flux::resource_model::resource_t &r) const { int saved_errno = errno; - int rc = hostlist_find (hl, r.name.c_str()); + int rc = hostlist_find (hl, r.name.c_str ()); errno = saved_errno; return rc < 0 ? false : true; } diff --git a/resource/libjobspec/hostlist_constraint.hpp b/resource/libjobspec/hostlist_constraint.hpp index 9ccb7e18b..7c51b103e 100644 --- a/resource/libjobspec/hostlist_constraint.hpp +++ b/resource/libjobspec/hostlist_constraint.hpp @@ -20,20 +20,23 @@ namespace Flux { namespace Jobspec { class HostlistConstraint : public Constraint { -public: - HostlistConstraint (const YAML::Node&); + public: + HostlistConstraint (const YAML::Node &); HostlistConstraint () = default; - ~HostlistConstraint () { hostlist_destroy (hl); }; + ~HostlistConstraint () + { + hostlist_destroy (hl); + }; -private: + private: struct hostlist *hl = nullptr; -public: + public: virtual bool match (const Flux::resource_model::resource_t &resource) const; virtual YAML::Node as_yaml () const; }; -} // namespace Jobspec -} // namespace Flux +} // namespace Jobspec +} // namespace Flux -#endif // HOSTLIST_CONSTRAINT_HPP +#endif // HOSTLIST_CONSTRAINT_HPP diff --git a/resource/libjobspec/jobspec.cpp b/resource/libjobspec/jobspec.cpp index d57b20fd2..e1bfc5244 100644 --- a/resource/libjobspec/jobspec.cpp +++ b/resource/libjobspec/jobspec.cpp @@ -22,38 +22,37 @@ extern "C" { using namespace Flux::Jobspec; -parse_error::parse_error(const char *msg) - : runtime_error(msg), - position(-1), - line(-1), - column(-1) -{} - -parse_error::parse_error(const YAML::Node &node, const char *msg) - : runtime_error(msg), +parse_error::parse_error (const char *msg) + : runtime_error (msg), position (-1), line (-1), column (-1) +{ +} + +parse_error::parse_error (const YAML::Node &node, const char *msg) + : runtime_error (msg), #ifdef HAVE_YAML_MARK - position(node.Mark().pos), - line(node.Mark().line+1), - column(node.Mark().column) + position (node.Mark ().pos), + line (node.Mark ().line + 1), + column (node.Mark ().column) #else - position(-1), - line(-1), - column(-1) + position (-1), + line (-1), + column (-1) #endif -{} +{ +} namespace { -void parse_yaml_count (Resource& res, const YAML::Node &cnode) +void parse_yaml_count (Resource &res, const YAML::Node &cnode) { /* count can have an unsigned integer value */ - if (cnode.IsScalar()) { - res.count.min = cnode.as(); + if (cnode.IsScalar ()) { + res.count.min = cnode.as (); res.count.max = res.count.min; return; } /* or count may be a more complicated verbose form */ - if (!cnode.IsMap()) { + if (!cnode.IsMap ()) { throw parse_error (cnode, "count is not a mapping"); } @@ -61,31 +60,29 @@ void parse_yaml_count (Resource& res, const YAML::Node &cnode) if (!cnode["min"]) { throw parse_error (cnode, "Key \"min\" missing from count"); } - if (!cnode["min"].IsScalar()) { + if (!cnode["min"].IsScalar ()) { throw parse_error (cnode["min"], "Value of \"min\" must be a scalar"); } - if (cnode["max"] && !cnode["max"].IsScalar()) { + if (cnode["max"] && !cnode["max"].IsScalar ()) { throw parse_error (cnode["max"], "Value of \"max\" must be a scalar"); } - if (cnode["operator"] && !cnode["operator"].IsScalar()) { - throw parse_error (cnode["operator"], - "Value of \"operator\" must be a scalar"); + if (cnode["operator"] && !cnode["operator"].IsScalar ()) { + throw parse_error (cnode["operator"], "Value of \"operator\" must be a scalar"); } - if (cnode["operand"] && !cnode["operand"].IsScalar()) { - throw parse_error (cnode["operand"], - "Value of \"operand\" must be a scalar"); + if (cnode["operand"] && !cnode["operand"].IsScalar ()) { + throw parse_error (cnode["operand"], "Value of \"operand\" must be a scalar"); } /* Validate values of entries */ - res.count.min = cnode["min"].as(); + res.count.min = cnode["min"].as (); if (cnode["max"]) { - res.count.max = cnode["max"].as(); + res.count.max = cnode["max"].as (); } if (cnode["operator"]) { - res.count.oper = cnode["operator"].as(); + res.count.oper = cnode["operator"].as (); } if (cnode["operand"]) { - res.count.operand = cnode["operand"].as(); + res.count.operand = cnode["operand"].as (); } if (res.count.min < 1) { @@ -95,19 +92,18 @@ void parse_yaml_count (Resource& res, const YAML::Node &cnode) throw parse_error (cnode["max"], "\"max\" must be greater than zero"); } if (res.count.max < res.count.min) { - throw parse_error (cnode["max"], - "\"max\" must be greater than or equal to \"min\""); + throw parse_error (cnode["max"], "\"max\" must be greater than or equal to \"min\""); } switch (res.count.oper) { - case '+': - case '*': - case '^': - break; - default: - throw parse_error (cnode["operator"], "Invalid count operator"); + case '+': + case '*': + case '^': + break; + default: + throw parse_error (cnode["operator"], "Invalid count operator"); } } -} +} // namespace namespace { std::vector parse_yaml_resources (const YAML::Node &resources); @@ -118,17 +114,16 @@ Resource::Resource (const YAML::Node &resnode) unsigned field_count = 0; /* The resource must be a mapping */ - if (!resnode.IsMap()) { + if (!resnode.IsMap ()) { throw parse_error (resnode, "resource is not a mapping"); } if (!resnode["type"]) { throw parse_error (resnode, "Key \"type\" missing from resource"); } - if (!resnode["type"].IsScalar()) { - throw parse_error (resnode["type"], - "Value of \"type\" must be a scalar"); + if (!resnode["type"].IsScalar ()) { + throw parse_error (resnode["type"], "Value of \"type\" must be a scalar"); } - type = resnode["type"].as(); + type = resnode["type"].as (); field_count++; if (!resnode["count"]) { @@ -138,20 +133,18 @@ Resource::Resource (const YAML::Node &resnode) field_count++; if (resnode["unit"]) { - if (!resnode["unit"].IsScalar()) { - throw parse_error (resnode["unit"], - "Value of \"unit\" must be a scalar"); + if (!resnode["unit"].IsScalar ()) { + throw parse_error (resnode["unit"], "Value of \"unit\" must be a scalar"); } field_count++; - unit = resnode["unit"].as(); + unit = resnode["unit"].as (); } if (resnode["exclusive"]) { - if (!resnode["exclusive"].IsScalar()) { - throw parse_error (resnode["exclusive"], - "Value of \"exclusive\" must be a scalar"); + if (!resnode["exclusive"].IsScalar ()) { + throw parse_error (resnode["exclusive"], "Value of \"exclusive\" must be a scalar"); } field_count++; - std::string val = resnode["exclusive"].as(); + std::string val = resnode["exclusive"].as (); if (val == "false") { exclusive = tristate_t::FALSE; } else if (val == "true") { @@ -168,99 +161,89 @@ Resource::Resource (const YAML::Node &resnode) } if (resnode["label"]) { - if (!resnode["label"].IsScalar()) { - throw parse_error (resnode["label"], - "Value of \"label\" must be a scalar"); + if (!resnode["label"].IsScalar ()) { + throw parse_error (resnode["label"], "Value of \"label\" must be a scalar"); } field_count++; - label = resnode["label"].as(); + label = resnode["label"].as (); } else if (type == "slot") { throw parse_error (resnode, "All slots must be labeled"); } if (resnode["id"]) { - if (!resnode["id"].IsScalar()) { - throw parse_error (resnode["id"], - "Value of \"id\" must be a scalar"); + if (!resnode["id"].IsScalar ()) { + throw parse_error (resnode["id"], "Value of \"id\" must be a scalar"); } field_count++; - id = resnode["id"].as(); + id = resnode["id"].as (); } - if (field_count != resnode.size()) { + if (field_count != resnode.size ()) { throw parse_error (resnode, "Unrecognized key in resource mapping"); } - if (resnode.size() < 2 || resnode.size() > 10) { - throw parse_error (resnode, - "impossible number of entries in resource mapping"); + if (resnode.size () < 2 || resnode.size () > 10) { + throw parse_error (resnode, "impossible number of entries in resource mapping"); } - } Task::Task (const YAML::Node &tasknode) { /* The task node must be a mapping */ - if (!tasknode.IsMap()) { + if (!tasknode.IsMap ()) { throw parse_error (tasknode, "task is not a mapping"); } if (!tasknode["command"]) { throw parse_error (tasknode, "Key \"command\" missing from task"); } - if (tasknode["command"].IsSequence()) { - command = tasknode["command"].as>(); + if (tasknode["command"].IsSequence ()) { + command = tasknode["command"].as> (); } else { - throw parse_error (tasknode["command"], - "\"command\" value must be a sequence"); + throw parse_error (tasknode["command"], "\"command\" value must be a sequence"); } /* Import slot */ if (!tasknode["slot"]) { throw parse_error (tasknode, "Key \"slot\" missing from task"); } - if (!tasknode["slot"].IsScalar()) { - throw parse_error (tasknode["slot"], - "Value of task \"slot\" must be a YAML scalar"); + if (!tasknode["slot"].IsScalar ()) { + throw parse_error (tasknode["slot"], "Value of task \"slot\" must be a YAML scalar"); } - slot = tasknode["slot"].as(); + slot = tasknode["slot"].as (); /* Import count mapping */ if (tasknode["count"]) { YAML::Node count_node = tasknode["count"]; - if (!count_node.IsMap()) { - throw parse_error (count_node, - "\"count\" in task is not a mapping"); + if (!count_node.IsMap ()) { + throw parse_error (count_node, "\"count\" in task is not a mapping"); } - for (auto&& entry : count_node) { - count[entry.first.as()] - = entry.second.as(); + for (auto &&entry : count_node) { + count[entry.first.as ()] = entry.second.as (); } } /* Import distribution if it is present */ if (tasknode["distribution"]) { - if (!tasknode["distribution"].IsScalar()) { + if (!tasknode["distribution"].IsScalar ()) { throw parse_error (tasknode["distribution"], "Value of task \"distribution\" must be a YAML scalar"); } - distribution = tasknode["distribution"].as(); + distribution = tasknode["distribution"].as (); } /* Import attributes mapping if it is present */ if (tasknode["attributes"]) { YAML::Node attrs = tasknode["attributes"]; - if (!attrs.IsMap()) { + if (!attrs.IsMap ()) { throw parse_error (attrs, "\"attributes\" in task is not a mapping"); } - for (auto&& attr : attrs) { - attributes[attr.first.as()] - = attr.second.as(); + for (auto &&attr : attrs) { + attributes[attr.first.as ()] = attr.second.as (); } } - if (tasknode.size() < 3 || tasknode.size() > 5) { - throw parse_error (tasknode, - "impossible number of entries in task mapping"); + if (tasknode.size () < 3 || tasknode.size () > 5) { + throw parse_error (tasknode, "impossible number of entries in task mapping"); } } @@ -270,17 +253,17 @@ std::vector parse_yaml_tasks (const YAML::Node &tasks) std::vector taskvec; /* "tasks" must be a sequence */ - if (!tasks.IsSequence()) { + if (!tasks.IsSequence ()) { throw parse_error (tasks, "\"tasks\" is not a sequence"); } - for (auto&& task : tasks) { + for (auto &&task : tasks) { taskvec.push_back (Task (task)); } return taskvec; } -} +} // namespace namespace { std::vector parse_yaml_resources (const YAML::Node &resources) @@ -288,17 +271,17 @@ std::vector parse_yaml_resources (const YAML::Node &resources) std::vector resvec; /* "resources" must be a sequence */ - if (!resources.IsSequence()) { + if (!resources.IsSequence ()) { throw parse_error (resources, "\"resources\" is not a sequence"); } - for (auto&& resource : resources) { + for (auto &&resource : resources) { resvec.push_back (Resource (resource)); } return resvec; } -} +} // namespace namespace { Attributes parse_yaml_attributes (const YAML::Node &attrs) @@ -308,47 +291,41 @@ Attributes parse_yaml_attributes (const YAML::Node &attrs) if (!attrs.IsMap ()) { throw parse_error (attrs, "\"attributes\" is not a map"); } - for (auto&& kv : attrs) { - if (kv.first.as() == "user") { + for (auto &&kv : attrs) { + if (kv.first.as () == "user") { a.user = kv.second; - } - else if (kv.first.as() == "system") { - for (auto&& s : kv.second) { - if (s.first.as() == "duration") { - a.system.duration = s.second.as(); - } - else if (s.first.as() == "queue") { - a.system.queue = s.second.as(); - } - else if (s.first.as() == "cwd") { - a.system.cwd = s.second.as(); - } - else if (s.first.as() == "environment") { - for (auto&& e : s.second) { - a.system.environment[e.first.as()] - = e.second.as(); + } else if (kv.first.as () == "system") { + for (auto &&s : kv.second) { + if (s.first.as () == "duration") { + a.system.duration = s.second.as (); + } else if (s.first.as () == "queue") { + a.system.queue = s.second.as (); + } else if (s.first.as () == "cwd") { + a.system.cwd = s.second.as (); + } else if (s.first.as () == "environment") { + for (auto &&e : s.second) { + a.system.environment[e.first.as ()] = + e.second.as (); } - } - else if (s.first.as() == "constraints") { + } else if (s.first.as () == "constraints") { a.system.constraint = constraint_parser (s.second); } else { - a.system.optional[s.first.as()] = s.second; + a.system.optional[s.first.as ()] = s.second; } } - } - else { + } else { throw parse_error (kv.second, "Unknown key in \"attributes\""); } } return a; } -} +} // namespace -Jobspec::Jobspec(const YAML::Node &top) +Jobspec::Jobspec (const YAML::Node &top) { try { /* The top yaml node of the jobspec must be a mapping */ - if (!top.IsMap()) { + if (!top.IsMap ()) { throw parse_error (top, "Top level of jobspec is not a mapping"); } /* The four keys must be the following */ @@ -365,19 +342,17 @@ Jobspec::Jobspec(const YAML::Node &top) throw parse_error (top, "Missing key \"attributes\" in top level mapping"); } /* There must be exactly four entries in the mapping */ - if (top.size() != 4) { + if (top.size () != 4) { throw parse_error (top, "Top mapping in jobspec must have exactly four entries"); } /* Import version */ - if (!top["version"].IsScalar()) { - throw parse_error (top["version"], - "\"version\" must be an unsigned integer"); + if (!top["version"].IsScalar ()) { + throw parse_error (top["version"], "\"version\" must be an unsigned integer"); } - version = top["version"].as(); + version = top["version"].as (); if (version < 1 || version > 9999) { - throw parse_error (top["version"], - "Only jobspec \"version\" 1-9999 is supported"); + throw parse_error (top["version"], "Only jobspec \"version\" 1-9999 is supported"); } /* Import attributes mappings */ @@ -389,27 +364,21 @@ Jobspec::Jobspec(const YAML::Node &top) /* Import tasks section */ tasks = parse_yaml_tasks (top["tasks"]); - } catch (YAML::Exception& e) { - throw parse_error(e.what()); + } catch (YAML::Exception &e) { + throw parse_error (e.what ()); } } -Jobspec::Jobspec(std::istream &is) -try - : Jobspec {YAML::Load (is)} -{ -} -catch (YAML::Exception& e) { - throw parse_error(e.what()); +Jobspec::Jobspec (std::istream &is) +try : Jobspec{YAML::Load (is)} { +} catch (YAML::Exception &e) { + throw parse_error (e.what ()); } -Jobspec::Jobspec(const std::string &s) -try - : Jobspec {YAML::Load (s)} -{ -} -catch (YAML::Exception& e) { - throw parse_error(e.what()); +Jobspec::Jobspec (const std::string &s) +try : Jobspec{YAML::Load (s)} { +} catch (YAML::Exception &e) { + throw parse_error (e.what ()); } namespace { @@ -419,70 +388,70 @@ namespace { * it goes out of scope and is destroyed, the indenting * disappears. */ -class IndentingOStreambuf : public std::streambuf -{ - std::streambuf* myDest; +class IndentingOStreambuf : public std::streambuf { + std::streambuf *myDest; bool myIsAtStartOfLine; std::string myIndent; - std::ostream* myOwner; -protected: - virtual int overflow( int ch ) + std::ostream *myOwner; + + protected: + virtual int overflow (int ch) { if (myIsAtStartOfLine && ch != '\n') { - myDest->sputn (myIndent.data(), myIndent.size()); + myDest->sputn (myIndent.data (), myIndent.size ()); } myIsAtStartOfLine = ch == '\n'; return myDest->sputc (ch); } -public: - explicit IndentingOStreambuf (std::streambuf* dest, int indent = 2) - : myDest (dest) - , myIsAtStartOfLine (true) - , myIndent (indent, ' ') - , myOwner(NULL) + + public: + explicit IndentingOStreambuf (std::streambuf *dest, int indent = 2) + : myDest (dest), myIsAtStartOfLine (true), myIndent (indent, ' '), myOwner (NULL) { } - explicit IndentingOStreambuf (std::ostream& dest, int indent = 2) - : myDest (dest.rdbuf ()) - , myIsAtStartOfLine (true) - , myIndent (indent, ' ') - , myOwner (&dest) + explicit IndentingOStreambuf (std::ostream &dest, int indent = 2) + : myDest (dest.rdbuf ()), myIsAtStartOfLine (true), myIndent (indent, ' '), myOwner (&dest) { myOwner->rdbuf (this); } - virtual ~IndentingOStreambuf() + virtual ~IndentingOStreambuf () { - if ( myOwner != NULL ) { + if (myOwner != NULL) { myOwner->rdbuf (myDest); } } }; -} +} // namespace -std::ostream& Flux::Jobspec::operator<<(std::ostream& s, Jobspec const& jobspec) +std::ostream &Flux::Jobspec::operator<< (std::ostream &s, Jobspec const &jobspec) { s << "version: " << jobspec.version << std::endl; s << "resources: " << std::endl; - for (auto&& resource : jobspec.resources) { + for (auto &&resource : jobspec.resources) { IndentingOStreambuf indent (s); s << resource; } s << "tasks: " << std::endl; - for (auto&& task : jobspec.tasks) { + for (auto &&task : jobspec.tasks) { IndentingOStreambuf indent (s); s << task; } s << "attributes:" << std::endl; - s << " " << "system:" << std::endl; - s << " " << "duration: " << jobspec.attributes.system.duration - << std::endl; - s << " " << "cwd: " << jobspec.attributes.system.cwd << std::endl; - s << " " << "queue: " << jobspec.attributes.system.queue << std::endl; - s << " " << "environment:" << std::endl; - for (auto&& e : jobspec.attributes.system.environment) { + s << " " + << "system:" << std::endl; + s << " " + << "duration: " << jobspec.attributes.system.duration << std::endl; + s << " " + << "cwd: " << jobspec.attributes.system.cwd << std::endl; + s << " " + << "queue: " << jobspec.attributes.system.queue << std::endl; + s << " " + << "environment:" << std::endl; + for (auto &&e : jobspec.attributes.system.environment) { s << " " << e.first << ": " << e.second << std::endl; } - s << " " << "constraints:" << std::endl; + s << " " + << "constraints:" << std::endl; if (jobspec.attributes.system.constraint != nullptr) { std::stringstream ss; std::string line; @@ -493,8 +462,7 @@ std::ostream& Flux::Jobspec::operator<<(std::ostream& s, Jobspec const& jobspec) return s; } -std::ostream& Flux::Jobspec::operator<<(std::ostream& s, - Resource const& resource) +std::ostream &Flux::Jobspec::operator<< (std::ostream &s, Resource const &resource) { s << "- type: " << resource.type << std::endl; s << " count:" << std::endl; @@ -502,20 +470,20 @@ std::ostream& Flux::Jobspec::operator<<(std::ostream& s, s << " max: " << resource.count.max << std::endl; s << " operator: " << resource.count.oper << std::endl; s << " operand: " << resource.count.operand << std::endl; - if (resource.unit.size() > 0) + if (resource.unit.size () > 0) s << " unit: " << resource.unit << std::endl; - if (resource.label.size() > 0) + if (resource.label.size () > 0) s << " label: " << resource.label << std::endl; - if (resource.id.size() > 0) + if (resource.id.size () > 0) s << " id: " << resource.id << std::endl; if (resource.exclusive == tristate_t::TRUE) - s << " exclusive: true" << std::endl; + s << " exclusive: true" << std::endl; else if (resource.exclusive == tristate_t::FALSE) - s << " exclusive: false" << std::endl; - if (resource.with.size() > 0) { + s << " exclusive: false" << std::endl; + if (resource.with.size () > 0) { s << " with:" << std::endl; IndentingOStreambuf indent (s, 4); - for (auto&& child_resource : resource.with) { + for (auto &&child_resource : resource.with) { s << child_resource; } } @@ -523,12 +491,11 @@ std::ostream& Flux::Jobspec::operator<<(std::ostream& s, return s; } -std::ostream& Flux::Jobspec::operator<<(std::ostream& s, - Task const& task) +std::ostream &Flux::Jobspec::operator<< (std::ostream &s, Task const &task) { bool first = true; s << "command: [ "; - for (auto&& field : task.command) { + for (auto &&field : task.command) { if (!first) s << ", "; else @@ -537,19 +504,19 @@ std::ostream& Flux::Jobspec::operator<<(std::ostream& s, } s << " ]" << std::endl; s << "slot: " << task.slot << std::endl; - if (task.count.size() > 0) { + if (task.count.size () > 0) { s << "count:" << std::endl; IndentingOStreambuf indent (s); - for (auto&& c : task.count) { + for (auto &&c : task.count) { s << c.first << ": " << c.second << std::endl; } } - if (task.distribution.size() > 0) + if (task.distribution.size () > 0) s << "distribution: " << task.distribution << std::endl; - if (task.attributes.size() > 0) { + if (task.attributes.size () > 0) { s << "attributes:" << std::endl; IndentingOStreambuf indent (s); - for (auto&& attr : task.attributes) { + for (auto &&attr : task.attributes) { s << attr.first << ": " << attr.second; } } diff --git a/resource/libjobspec/jobspec.hpp b/resource/libjobspec/jobspec.hpp index bf3517284..44773752d 100644 --- a/resource/libjobspec/jobspec.hpp +++ b/resource/libjobspec/jobspec.hpp @@ -46,11 +46,11 @@ namespace Jobspec { enum class tristate_t { FALSE, TRUE, UNSPECIFIED }; class Resource { -public: + public: std::string type; struct { unsigned min; - unsigned max = std::numeric_limits::max(); + unsigned max = std::numeric_limits::max (); char oper = '+'; int operand = 1; } count; @@ -64,18 +64,18 @@ class Resource { // entirely for the convenience of external code std::unordered_map user_data; - Resource(const YAML::Node&); + Resource (const YAML::Node &); }; class Task { -public: + public: std::vector command; std::string slot; std::unordered_map count; std::string distribution; std::unordered_map attributes; - Task(const YAML::Node&); + Task (const YAML::Node &); }; struct System { @@ -86,42 +86,42 @@ struct System { std::unordered_map optional; std::shared_ptr constraint = nullptr; - System() = default; - System(const System &s) = delete; // Force to use move ctor - System(System &&s) = default; - System& operator=(const System &&a) = delete; // Force to use move operator= - System& operator=(System &&a) = default; + System () = default; + System (const System &s) = delete; // Force to use move ctor + System (System &&s) = default; + System &operator= (const System &&a) = delete; // Force to use move operator= + System &operator= (System &&a) = default; }; struct Attributes { YAML::Node user; System system; - Attributes() = default; - Attributes(const Attributes &a) = delete; // Force to use move ctor - Attributes(Attributes &&a) = default; - Attributes& operator=(const Attributes &&a) = delete; - Attributes& operator=(Attributes &&a) = default; + Attributes () = default; + Attributes (const Attributes &a) = delete; // Force to use move ctor + Attributes (Attributes &&a) = default; + Attributes &operator= (const Attributes &&a) = delete; + Attributes &operator= (Attributes &&a) = default; }; class Jobspec { -public: + public: unsigned int version; std::vector resources; std::vector tasks; Attributes attributes; - Jobspec() = default; - Jobspec(const YAML::Node&); - Jobspec(std::istream &is); - Jobspec(const std::string &s); + Jobspec () = default; + Jobspec (const YAML::Node &); + Jobspec (std::istream &is); + Jobspec (const std::string &s); }; -std::ostream& operator<<(std::ostream& s, Jobspec const& js); -std::ostream& operator<<(std::ostream& s, Resource const& r); -std::ostream& operator<<(std::ostream& s, Task const& t); +std::ostream &operator<< (std::ostream &s, Jobspec const &js); +std::ostream &operator<< (std::ostream &s, Resource const &r); +std::ostream &operator<< (std::ostream &s, Task const &t); -} // namespace Jobspec -} // namespace Flux +} // namespace Jobspec +} // namespace Flux -#endif // JOBSPEC_HPP +#endif // JOBSPEC_HPP diff --git a/resource/libjobspec/parse_error.hpp b/resource/libjobspec/parse_error.hpp index be3a34260..df0a6cfe2 100644 --- a/resource/libjobspec/parse_error.hpp +++ b/resource/libjobspec/parse_error.hpp @@ -22,15 +22,15 @@ namespace Flux { namespace Jobspec { class parse_error : public std::runtime_error { -public: + public: int position; int line; int column; - parse_error(const char *msg); - parse_error(const YAML::Node& node, const char *msg); + parse_error (const char *msg); + parse_error (const YAML::Node &node, const char *msg); }; -} // namespace Jobspec -} // namespace Flux +} // namespace Jobspec +} // namespace Flux -#endif // JOBSPEC_PARSE_ERROR_HPP +#endif // JOBSPEC_PARSE_ERROR_HPP diff --git a/resource/libjobspec/rank_constraint.cpp b/resource/libjobspec/rank_constraint.cpp index 11e78de8e..4b5520c28 100644 --- a/resource/libjobspec/rank_constraint.cpp +++ b/resource/libjobspec/rank_constraint.cpp @@ -34,12 +34,12 @@ RankConstraint::RankConstraint (const YAML::Node &values) { if (!(ranks = idset_create (0, IDSET_FLAG_AUTOGROW))) throw parse_error (values, "Out of memory"); - for (auto&& val: values) { - std::string ids = val.as(); - if (add_idset_string (ranks, ids.c_str()) < 0) { + for (auto &&val : values) { + std::string ids = val.as (); + if (add_idset_string (ranks, ids.c_str ()) < 0) { idset_destroy (ranks); std::string msg = "Invalid idset `" + ids + "'"; - throw parse_error (val, msg.c_str()); + throw parse_error (val, msg.c_str ()); } } } diff --git a/resource/libjobspec/rank_constraint.hpp b/resource/libjobspec/rank_constraint.hpp index 8290a2f31..4e24f740d 100644 --- a/resource/libjobspec/rank_constraint.hpp +++ b/resource/libjobspec/rank_constraint.hpp @@ -20,20 +20,23 @@ namespace Flux { namespace Jobspec { class RankConstraint : public Constraint { -public: - RankConstraint (const YAML::Node&); + public: + RankConstraint (const YAML::Node &); RankConstraint () = default; - ~RankConstraint () { idset_destroy (ranks); }; + ~RankConstraint () + { + idset_destroy (ranks); + }; -private: + private: struct idset *ranks = nullptr; -public: + public: virtual bool match (const Flux::resource_model::resource_t &resource) const; virtual YAML::Node as_yaml () const; }; -} // namespace Jobspec -} // namespace Flux +} // namespace Jobspec +} // namespace Flux -#endif // RANK_CONSTRAINT_HPP +#endif // RANK_CONSTRAINT_HPP diff --git a/resource/libjobspec/test/constraint.cpp b/resource/libjobspec/test/constraint.cpp index 4777f27b1..9c4f8fa49 100644 --- a/resource/libjobspec/test/constraint.cpp +++ b/resource/libjobspec/test/constraint.cpp @@ -26,8 +26,9 @@ extern "C" { // fake resource type for testing struct resource : Flux::resource_model::resource_t { resource () {}; - void add_property (std::string name) { - properties.insert(std::pair(name, "t")); + void add_property (std::string name) + { + properties.insert (std::pair (name, "t")); } }; @@ -50,91 +51,104 @@ struct validate_test { /* These tests all assume a node object foo0 with properties xx and yy. */ struct match_test match_tests[] = { - { "empty json object matches everything", "{}", true }, - { "empty properties dict matches everything", - "{\"properties\": [] }", - true - }, - { "property matches", - "{\"properties\": [\"xx\"]}", + {"empty json object matches everything", "{}", true}, + {"empty properties dict matches everything", "{\"properties\": [] }", true}, + { + "property matches", + "{\"properties\": [\"xx\"]}", true, }, - { "logical not on property", - "{\"properties\": [\"^xx\"]}", + { + "logical not on property", + "{\"properties\": [\"^xx\"]}", false, }, - { "logical not on unset property", - "{\"properties\": [\"^zz\"]}", + { + "logical not on unset property", + "{\"properties\": [\"^zz\"]}", true, }, - { "property list matches like 'and'", - "{\"properties\": [\"xx\", \"yy\"]}", + { + "property list matches like 'and'", + "{\"properties\": [\"xx\", \"yy\"]}", true, }, - { "property list match fails unless node has all", - "{\"properties\": [\"xx\", \"zz\"]}", + { + "property list match fails unless node has all", + "{\"properties\": [\"xx\", \"zz\"]}", false, }, - { "property list match fails if property missing", - "{\"properties\": [\"zz\"]}", + { + "property list match fails if property missing", + "{\"properties\": [\"zz\"]}", false, }, - { "and with two true statements", - "{\"and\": [ {\"properties\": [\"xx\"]}, \ + { + "and with two true statements", + "{\"and\": [ {\"properties\": [\"xx\"]}, \ {\"properties\": [\"yy\"]} \ ]}", true, }, - { "and with one false statement", - "{\"and\": [ {\"properties\": [\"xx\"]}, \ + { + "and with one false statement", + "{\"and\": [ {\"properties\": [\"xx\"]}, \ {\"properties\": [\"zz\"]} \ ]}", false, }, - { "or with two true statements", - "{\"or\": [ {\"properties\": [\"xx\"]}, \ + { + "or with two true statements", + "{\"or\": [ {\"properties\": [\"xx\"]}, \ {\"properties\": [\"yy\"]} \ ]}", true, }, - { "or with one true statements", - "{\"or\": [ {\"properties\": [\"zz\"]}, \ + { + "or with one true statements", + "{\"or\": [ {\"properties\": [\"zz\"]}, \ {\"properties\": [\"yy\"]} \ ]}", true, }, - { "or with two false statements", - "{\"or\": [ {\"properties\": [\"zz\"]}, \ + { + "or with two false statements", + "{\"or\": [ {\"properties\": [\"zz\"]}, \ {\"properties\": [\"aa\"]} \ ]}", false, }, - { "not with or with one true statement", - "{\"not\": [ \ + { + "not with or with one true statement", + "{\"not\": [ \ {\"or\": [ {\"properties\": [\"zz\"]}, \ {\"properties\": [\"yy\"]} \ ]} \ ] \ }", - false, + false, }, - { "hostlist operator works", - "{\"hostlist\": [\"foo[0-2]\"]}", - true, + { + "hostlist operator works", + "{\"hostlist\": [\"foo[0-2]\"]}", + true, }, - { "hostlist operator works with non-matching hostlist", - "{\"hostlist\": [\"foo[1-3]\"]}", - false, + { + "hostlist operator works with non-matching hostlist", + "{\"hostlist\": [\"foo[1-3]\"]}", + false, }, - { "ranks operator works", - "{\"ranks\": [\"0-2\"]}", - true, + { + "ranks operator works", + "{\"ranks\": [\"0-2\"]}", + true, }, - { "ranks operator works with non-intersecting ranks", - "{\"ranks\": [\"1-3\"]}", - false, + { + "ranks operator works with non-intersecting ranks", + "{\"ranks\": [\"1-3\"]}", + false, }, - { NULL, NULL, false }, + {NULL, NULL, false}, }; void test_match () @@ -157,68 +171,60 @@ void test_match () } } -struct validate_test validate_tests[] = { - { "non-object fails", - "[]", - -1, - "constraint is not a mapping", - }, - { "Unknown operation fails", - "{ \"foo\": [] }", - -1, - "unknown constraint operator: foo", - }, - { "multiple operations in one object fails", - "{\"properties\": [\"xx\"], \"hostlist\": [\"foo\"]}", - -1, - "constraint map may not contain > 1 operation", - }, - { "non-array argument to 'and' fails", - "{ \"and\": \"foo\" }", - -1, - "and operator value must be an array", - }, - { "non-array argument to 'or' fails", - "{ \"or\": \"foo\" }", - -1, - "or operator value must be an array", - }, - { "non-array argument to 'properties' fails", - "{ \"properties\": \"foo\" }", - -1, - "properties operator value must be an array", - }, - { "non-string property fails", - "{ \"properties\": [ \"foo\", 42 ] }", - -1, - "non-string property specified", - }, - { "invalid property string fails", - "{ \"properties\": [ \"foo\", \"bar&\" ] }", - -1, - "bar& is invalid", - }, - { "empty object is valid constraint", - "{}", - 0, - NULL - }, - { "empty and object is valid constraint", - "{ \"and\": [] }", - 0, - NULL - }, - { "empty or object is valid constraint", - "{ \"or\": [] }", - 0, - NULL - }, - { "empty properties object is valid constraint", - "{ \"properties\": [] }", - 0, - NULL - }, - { "complex conditional works", +struct validate_test validate_tests[] = + {{ + "non-object fails", + "[]", + -1, + "constraint is not a mapping", + }, + { + "Unknown operation fails", + "{ \"foo\": [] }", + -1, + "unknown constraint operator: foo", + }, + { + "multiple operations in one object fails", + "{\"properties\": [\"xx\"], \"hostlist\": [\"foo\"]}", + -1, + "constraint map may not contain > 1 operation", + }, + { + "non-array argument to 'and' fails", + "{ \"and\": \"foo\" }", + -1, + "and operator value must be an array", + }, + { + "non-array argument to 'or' fails", + "{ \"or\": \"foo\" }", + -1, + "or operator value must be an array", + }, + { + "non-array argument to 'properties' fails", + "{ \"properties\": \"foo\" }", + -1, + "properties operator value must be an array", + }, + { + "non-string property fails", + "{ \"properties\": [ \"foo\", 42 ] }", + -1, + "non-string property specified", + }, + { + "invalid property string fails", + "{ \"properties\": [ \"foo\", \"bar&\" ] }", + -1, + "bar& is invalid", + }, + {"empty object is valid constraint", "{}", 0, NULL}, + {"empty and object is valid constraint", "{ \"and\": [] }", 0, NULL}, + {"empty or object is valid constraint", "{ \"or\": [] }", 0, NULL}, + {"empty properties object is valid constraint", "{ \"properties\": [] }", 0, NULL}, + {"complex conditional works", "{ \"and\": \ [ { \"or\": \ [ {\"properties\": [\"foo\"]}, \ @@ -233,31 +239,22 @@ struct validate_test validate_tests[] = { ] \ }", 0, - NULL - }, - { "hostlist can be included", - "{\"hostlist\": [\"foo[0-10]\"]}", - 0, - NULL - }, - { "invalid hostlist fails", - "{\"hostlist\": [\"foo0-10]\"]}", - -1, - "Invalid hostlist `foo0-10]'", - }, - { "ranks can be included", - "{\"ranks\": [\"0-10\"]}", - 0, - NULL - }, - { "invalid ranks entry fails", - "{\"ranks\": [\"5,1-3\"]}", - -1, - "Invalid idset `5,1-3'", - }, - { NULL, NULL, 0, NULL } -}; - + NULL}, + {"hostlist can be included", "{\"hostlist\": [\"foo[0-10]\"]}", 0, NULL}, + { + "invalid hostlist fails", + "{\"hostlist\": [\"foo0-10]\"]}", + -1, + "Invalid hostlist `foo0-10]'", + }, + {"ranks can be included", "{\"ranks\": [\"0-10\"]}", 0, NULL}, + { + "invalid ranks entry fails", + "{\"ranks\": [\"5,1-3\"]}", + -1, + "Invalid idset `5,1-3'", + }, + {NULL, NULL, 0, NULL}}; void test_validate () { @@ -268,16 +265,14 @@ void test_validate () try { constraint_parser (YAML::Load (t->json)); - } - catch (Flux::Jobspec::parse_error& e) { + } catch (Flux::Jobspec::parse_error &e) { exception = true; errmsg = e.what (); } if (t->rc != 0) { ok (exception, "%s", t->desc); - is (errmsg.c_str(), t->err, "%s: got expected error", t->desc); - } - else { + is (errmsg.c_str (), t->err, "%s: got expected error", t->desc); + } else { ok (!exception, "%s", t->desc); } t++; @@ -292,4 +287,3 @@ int main (int ac, char *argv[]) done_testing (); return 0; } - diff --git a/resource/modules/resource_match.cpp b/resource/modules/resource_match.cpp index c9d2b3f27..f42e2ad05 100644 --- a/resource/modules/resource_match.cpp +++ b/resource/modules/resource_match.cpp @@ -39,20 +39,20 @@ using namespace Flux::opts_manager; // Global perf struct from schema extern struct Flux::resource_model::match_perf_t Flux::resource_model::perf; - //////////////////////////////////////////////////////////////////////////////// // Resource Matching Service Module Context //////////////////////////////////////////////////////////////////////////////// class msg_wrap_t { -public: + public: msg_wrap_t () = default; msg_wrap_t (const msg_wrap_t &o); msg_wrap_t &operator= (const msg_wrap_t &o); ~msg_wrap_t (); const flux_msg_t *get_msg () const; void set_msg (const flux_msg_t *msg); -private: + + private: const flux_msg_t *m_msg = nullptr; }; @@ -63,7 +63,7 @@ struct resobj_t { }; class resource_interface_t { -public: + public: resource_interface_t () = default; resource_interface_t (const resource_interface_t &o); resource_interface_t &operator= (const resource_interface_t &o); @@ -78,7 +78,7 @@ class resource_interface_t { bool is_ups_set () const; flux_future_t *update_f = nullptr; -private: + private: std::string m_ups = ""; int m_update_rc = 0; }; @@ -87,22 +87,21 @@ struct resource_ctx_t : public resource_interface_t { ~resource_ctx_t (); flux_t *h; /* Flux handle */ flux_msg_handler_t **handlers; /* Message handlers */ - Flux::opts_manager::optmgr_composer_t< - Flux::opts_manager::resource_opts_t> opts; /* Option manager */ - std::shared_ptr matcher; /* Match callback object */ - std::shared_ptr traverser; /* Graph traverser object */ - std::shared_ptr db; /* Resource graph data store */ - std::shared_ptr writers; /* Vertex/Edge writers */ - std::shared_ptr reader; /* resource reader */ + Flux::opts_manager::optmgr_composer_t + opts; /* Option manager */ + std::shared_ptr matcher; /* Match callback object */ + std::shared_ptr traverser; /* Graph traverser object */ + std::shared_ptr db; /* Resource graph data store */ + std::shared_ptr writers; /* Vertex/Edge writers */ + std::shared_ptr reader; /* resource reader */ std::map> jobs; /* Jobs table */ - std::map allocations; /* Allocation table */ - std::map reservations; /* Reservation table */ + std::map allocations; /* Allocation table */ + std::map reservations; /* Reservation table */ std::map> notify_msgs; - bool m_resources_updated = true; /* resources have been updated */ + bool m_resources_updated = true; /* resources have been updated */ bool m_resources_down_updated = true; /* down resources have been updated */ /* last time allocated resources search updated */ - std::chrono::time_point< - std::chrono::system_clock> m_resources_alloc_updated; + std::chrono::time_point m_resources_alloc_updated; /* R caches */ json_t *m_r_all; json_t *m_r_down; @@ -150,8 +149,7 @@ resource_interface_t::resource_interface_t (const resource_interface_t &o) flux_future_incref (update_f); } -resource_interface_t &resource_interface_t::operator= ( - const resource_interface_t &o) +resource_interface_t &resource_interface_t::operator= (const resource_interface_t &o) { m_ups = o.m_ups; m_update_rc = o.m_update_rc; @@ -202,111 +200,93 @@ resource_ctx_t::~resource_ctx_t () } } - - //////////////////////////////////////////////////////////////////////////////// // Request Handler Prototypes //////////////////////////////////////////////////////////////////////////////// -static void match_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg); - -static void match_multi_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg); - -static void update_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg); - -static void cancel_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg); - -static void partial_cancel_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg); - -static void info_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg); - -static void stat_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg); - -static void stat_clear_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg); - -static void next_jobid_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg); - -static void set_property_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg); - -static void get_property_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg); - -static void notify_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg); - -static void disconnect_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg); - -static void find_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg); - -static void status_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg); - -static void ns_info_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg); - -static void satisfiability_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg); - -static void params_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg); - -static void set_status_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg); - -static const struct flux_msg_handler_spec htab[] = { - { FLUX_MSGTYPE_REQUEST, - "sched-fluxion-resource.match", match_request_cb, 0 }, - { FLUX_MSGTYPE_REQUEST, - "sched-fluxion-resource.match_multi", match_multi_request_cb, 0 }, - { FLUX_MSGTYPE_REQUEST, - "sched-fluxion-resource.update", update_request_cb, 0}, - { FLUX_MSGTYPE_REQUEST, - "sched-fluxion-resource.cancel", cancel_request_cb, 0 }, - { FLUX_MSGTYPE_REQUEST, - "sched-fluxion-resource.partial-cancel", partial_cancel_request_cb, 0 }, - { FLUX_MSGTYPE_REQUEST, - "sched-fluxion-resource.info", info_request_cb, 0 }, - { FLUX_MSGTYPE_REQUEST, - "sched-fluxion-resource.stats-get", stat_request_cb, FLUX_ROLE_USER }, - { FLUX_MSGTYPE_REQUEST, - "sched-fluxion-resource.stats-clear", stat_clear_cb, FLUX_ROLE_USER }, - { FLUX_MSGTYPE_REQUEST, - "sched-fluxion-resource.next_jobid", next_jobid_request_cb, 0 }, - { FLUX_MSGTYPE_REQUEST, - "sched-fluxion-resource.set_property", set_property_request_cb, 0 }, - { FLUX_MSGTYPE_REQUEST, - "sched-fluxion-resource.get_property", get_property_request_cb, 0 }, - { FLUX_MSGTYPE_REQUEST, - "sched-fluxion-resource.notify", notify_request_cb, 0 }, - { FLUX_MSGTYPE_REQUEST, - "sched-fluxion-resource.disconnect", disconnect_request_cb, 0 }, - { FLUX_MSGTYPE_REQUEST, - "sched-fluxion-resource.find", find_request_cb, 0 }, - { FLUX_MSGTYPE_REQUEST, - "sched-fluxion-resource.status", status_request_cb, 0 }, - { FLUX_MSGTYPE_REQUEST, - "sched-fluxion-resource.ns-info", ns_info_request_cb, 0 }, - { FLUX_MSGTYPE_REQUEST, - "sched-fluxion-resource.satisfiability", satisfiability_request_cb, 0 }, - { FLUX_MSGTYPE_REQUEST, - "sched-fluxion-resource.params", params_request_cb, 0 }, - { FLUX_MSGTYPE_REQUEST, - "sched-fluxion-resource.set_status", set_status_request_cb, 0 }, - FLUX_MSGHANDLER_TABLE_END -}; +static void match_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg); + +static void match_multi_request_cb (flux_t *h, + flux_msg_handler_t *w, + const flux_msg_t *msg, + void *arg); + +static void update_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg); + +static void cancel_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg); + +static void partial_cancel_request_cb (flux_t *h, + flux_msg_handler_t *w, + const flux_msg_t *msg, + void *arg); + +static void info_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg); + +static void stat_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg); + +static void stat_clear_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg); + +static void next_jobid_request_cb (flux_t *h, + flux_msg_handler_t *w, + const flux_msg_t *msg, + void *arg); + +static void set_property_request_cb (flux_t *h, + flux_msg_handler_t *w, + const flux_msg_t *msg, + void *arg); +static void get_property_request_cb (flux_t *h, + flux_msg_handler_t *w, + const flux_msg_t *msg, + void *arg); + +static void notify_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg); + +static void disconnect_request_cb (flux_t *h, + flux_msg_handler_t *w, + const flux_msg_t *msg, + void *arg); + +static void find_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg); + +static void status_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg); + +static void ns_info_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg); + +static void satisfiability_request_cb (flux_t *h, + flux_msg_handler_t *w, + const flux_msg_t *msg, + void *arg); + +static void params_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg); + +static void set_status_request_cb (flux_t *h, + flux_msg_handler_t *w, + const flux_msg_t *msg, + void *arg); + +static const struct flux_msg_handler_spec htab[] = + {{FLUX_MSGTYPE_REQUEST, "sched-fluxion-resource.match", match_request_cb, 0}, + {FLUX_MSGTYPE_REQUEST, "sched-fluxion-resource.match_multi", match_multi_request_cb, 0}, + {FLUX_MSGTYPE_REQUEST, "sched-fluxion-resource.update", update_request_cb, 0}, + {FLUX_MSGTYPE_REQUEST, "sched-fluxion-resource.cancel", cancel_request_cb, 0}, + {FLUX_MSGTYPE_REQUEST, "sched-fluxion-resource.partial-cancel", partial_cancel_request_cb, 0}, + {FLUX_MSGTYPE_REQUEST, "sched-fluxion-resource.info", info_request_cb, 0}, + {FLUX_MSGTYPE_REQUEST, "sched-fluxion-resource.stats-get", stat_request_cb, FLUX_ROLE_USER}, + {FLUX_MSGTYPE_REQUEST, "sched-fluxion-resource.stats-clear", stat_clear_cb, FLUX_ROLE_USER}, + {FLUX_MSGTYPE_REQUEST, "sched-fluxion-resource.next_jobid", next_jobid_request_cb, 0}, + {FLUX_MSGTYPE_REQUEST, "sched-fluxion-resource.set_property", set_property_request_cb, 0}, + {FLUX_MSGTYPE_REQUEST, "sched-fluxion-resource.get_property", get_property_request_cb, 0}, + {FLUX_MSGTYPE_REQUEST, "sched-fluxion-resource.notify", notify_request_cb, 0}, + {FLUX_MSGTYPE_REQUEST, "sched-fluxion-resource.disconnect", disconnect_request_cb, 0}, + {FLUX_MSGTYPE_REQUEST, "sched-fluxion-resource.find", find_request_cb, 0}, + {FLUX_MSGTYPE_REQUEST, "sched-fluxion-resource.status", status_request_cb, 0}, + {FLUX_MSGTYPE_REQUEST, "sched-fluxion-resource.ns-info", ns_info_request_cb, 0}, + {FLUX_MSGTYPE_REQUEST, "sched-fluxion-resource.satisfiability", satisfiability_request_cb, 0}, + {FLUX_MSGTYPE_REQUEST, "sched-fluxion-resource.params", params_request_cb, 0}, + {FLUX_MSGTYPE_REQUEST, "sched-fluxion-resource.set_status", set_status_request_cb, 0}, + FLUX_MSGHANDLER_TABLE_END}; //////////////////////////////////////////////////////////////////////////////// // Module Initialization Routines @@ -329,8 +309,8 @@ static std::shared_ptr getctx (flux_t *h) void *d = NULL; std::shared_ptr ctx = nullptr; - if ( (d = flux_aux_get (h, "sched-fluxion-resource")) != NULL) - ctx = *(static_cast *>(d)); + if ((d = flux_aux_get (h, "sched-fluxion-resource")) != NULL) + ctx = *(static_cast *> (d)); if (!ctx) { try { ctx = std::make_shared (); @@ -358,8 +338,7 @@ static std::shared_ptr getctx (flux_t *h) return ctx; } -static int process_args (std::shared_ptr &ctx, - int argc, char **argv) +static int process_args (std::shared_ptr &ctx, int argc, char **argv) { int rc = 0; optmgr_kv_t opts_store; @@ -367,15 +346,13 @@ static int process_args (std::shared_ptr &ctx, for (int i = 0; i < argc; i++) { const std::string kv (argv[i]); - if ( (rc = opts_store.put (kv)) < 0) { - flux_log_error (ctx->h, "%s: optmgr_kv_t::put (%s)", - __FUNCTION__, argv[i]); + if ((rc = opts_store.put (kv)) < 0) { + flux_log_error (ctx->h, "%s: optmgr_kv_t::put (%s)", __FUNCTION__, argv[i]); return rc; } } - if ( (rc = opts_store.parse (info_str)) < 0) { - flux_log_error (ctx->h, "%s: optmgr_kv_t::parse: %s", - __FUNCTION__, info_str.c_str ()); + if ((rc = opts_store.parse (info_str)) < 0) { + flux_log_error (ctx->h, "%s: optmgr_kv_t::parse: %s", __FUNCTION__, info_str.c_str ()); return rc; } if (info_str != "") { @@ -390,10 +367,12 @@ static int process_config_file (std::shared_ptr &ctx) int rc = 0; json_t *conf = nullptr; - if ( (rc = flux_conf_unpack (flux_get_conf (ctx->h), nullptr, - "{ s?:o }", - "sched-fluxion-resource", - &conf)) < 0) { + if ((rc = flux_conf_unpack (flux_get_conf (ctx->h), + nullptr, + "{ s?:o }", + "sched-fluxion-resource", + &conf)) + < 0) { flux_log_error (ctx->h, "%s: flux_conf_unpack", __FUNCTION__); return rc; } @@ -405,7 +384,7 @@ static int process_config_file (std::shared_ptr &ctx) std::string info_str = ""; json_object_foreach (conf, k, v) { std::string value; - if (!(tmp = json_dumps (v, JSON_ENCODE_ANY|JSON_COMPACT))) { + if (!(tmp = json_dumps (v, JSON_ENCODE_ANY | JSON_COMPACT))) { errno = ENOMEM; return -1; } @@ -414,15 +393,17 @@ static int process_config_file (std::shared_ptr &ctx) tmp = nullptr; if (json_typeof (v) == JSON_STRING) value = value.substr (1, value.length () - 2); - if ( (rc = opts_store.put (k, value)) < 0) { - flux_log_error (ctx->h, "%s: optmgr_kv_t::put (%s, %s)", - __FUNCTION__, k, value.c_str ()); + if ((rc = opts_store.put (k, value)) < 0) { + flux_log_error (ctx->h, + "%s: optmgr_kv_t::put (%s, %s)", + __FUNCTION__, + k, + value.c_str ()); return rc; } } - if ( (rc = opts_store.parse (info_str)) < 0) { - flux_log_error (ctx->h, "%s: optmgr_kv_t::parse: %s", - __FUNCTION__, info_str.c_str ()); + if ((rc = opts_store.parse (info_str)) < 0) { + flux_log_error (ctx->h, "%s: optmgr_kv_t::parse: %s", __FUNCTION__, info_str.c_str ()); return rc; } if (info_str != "") { @@ -432,25 +413,21 @@ static int process_config_file (std::shared_ptr &ctx) return rc; } -static std::shared_ptr init_module (flux_t *h, - int argc, char **argv) +static std::shared_ptr init_module (flux_t *h, int argc, char **argv) { std::shared_ptr ctx = nullptr; uint32_t rank = 1; if (!(ctx = getctx (h))) { - flux_log (h, LOG_ERR, "%s: can't allocate the context", - __FUNCTION__); + flux_log (h, LOG_ERR, "%s: can't allocate the context", __FUNCTION__); return nullptr; } if (flux_get_rank (h, &rank) < 0) { - flux_log (h, LOG_ERR, "%s: can't determine rank", - __FUNCTION__); + flux_log (h, LOG_ERR, "%s: can't determine rank", __FUNCTION__); goto error; } if (rank) { - flux_log (h, LOG_ERR, "%s: resource module must only run on rank 0", - __FUNCTION__); + flux_log (h, LOG_ERR, "%s: resource module must only run on rank 0", __FUNCTION__); goto error; } if (process_config_file (ctx) < 0) { @@ -463,8 +440,7 @@ static std::shared_ptr init_module (flux_t *h, } ctx->opts.canonicalize (); if (flux_msg_handler_addvec (h, htab, (void *)h, &ctx->handlers) < 0) { - flux_log_error (h, "%s: error registering resource event handler", - __FUNCTION__); + flux_log_error (h, "%s: error registering resource event handler", __FUNCTION__); goto error; } return ctx; @@ -473,24 +449,19 @@ static std::shared_ptr init_module (flux_t *h, return nullptr; } - - //////////////////////////////////////////////////////////////////////////////// // Resource Graph and Traverser Initialization //////////////////////////////////////////////////////////////////////////////// -static int create_reader (std::shared_ptr &ctx, - const std::string &format) +static int create_reader (std::shared_ptr &ctx, const std::string &format) { - if ( (ctx->reader = create_resource_reader (format)) == nullptr) + if ((ctx->reader = create_resource_reader (format)) == nullptr) return -1; if (ctx->opts.get_opt ().is_load_allowlist_set ()) { - if (ctx->reader->set_allowlist ( - ctx->opts.get_opt ().get_load_allowlist ()) < 0) + if (ctx->reader->set_allowlist (ctx->opts.get_opt ().get_load_allowlist ()) < 0) flux_log (ctx->h, LOG_ERR, "%s: setting allowlist", __FUNCTION__); if (!ctx->reader->is_allowlist_supported ()) - flux_log (ctx->h, LOG_WARNING, "%s: allowlist unsupported", - __FUNCTION__); + flux_log (ctx->h, LOG_WARNING, "%s: allowlist unsupported", __FUNCTION__); } return 0; } @@ -511,8 +482,7 @@ static int populate_resource_db_file (std::shared_ptr &ctx) saved_errno = errno; errno = 0; - in_file.open (ctx->opts.get_opt ().get_load_file ().c_str (), - std::ifstream::in); + in_file.open (ctx->opts.get_opt ().get_load_file ().c_str (), std::ifstream::in); if (!in_file.good ()) { if (errno == 0) { // C++ standard doesn't guarantee to set errno but @@ -520,16 +490,21 @@ static int populate_resource_db_file (std::shared_ptr &ctx) // we manually set errno only when it is not set at all. errno = EIO; } - flux_log_error (ctx->h, "%s: opening %s", __FUNCTION__, - ctx->opts.get_opt ().get_load_file ().c_str ()); + flux_log_error (ctx->h, + "%s: opening %s", + __FUNCTION__, + ctx->opts.get_opt ().get_load_file ().c_str ()); goto done; } errno = saved_errno; buffer << in_file.rdbuf (); in_file.close (); - if ( (rc = ctx->db->load (buffer.str (), ctx->reader)) < 0) { - flux_log (ctx->h, LOG_ERR, "%s: reader: %s", - __FUNCTION__, ctx->reader->err_message ().c_str ()); + if ((rc = ctx->db->load (buffer.str (), ctx->reader)) < 0) { + flux_log (ctx->h, + LOG_ERR, + "%s: reader: %s", + __FUNCTION__, + ctx->reader->err_message ().c_str ()); goto done; } ctx->db->metadata.set_graph_duration (duration); @@ -545,33 +520,44 @@ static int populate_resource_db_file (std::shared_ptr &ctx) * rank == IDSET_INVALID_ID, to instantiate an empty graph. */ static int grow (std::shared_ptr &ctx, - vtx_t v, unsigned int rank, const char *hwloc_xml) + vtx_t v, + unsigned int rank, + const char *hwloc_xml) { int rc = -1; resource_graph_db_t &db = *(ctx->db); if (rank == IDSET_INVALID_ID) { // Grow cluster vertex and leave - if ( (rc = db.load ("", ctx->reader, rank)) < 0) { - flux_log (ctx->h, LOG_ERR, "%s: reader: %s", - __FUNCTION__, ctx->reader->err_message ().c_str ()); + if ((rc = db.load ("", ctx->reader, rank)) < 0) { + flux_log (ctx->h, + LOG_ERR, + "%s: reader: %s", + __FUNCTION__, + ctx->reader->err_message ().c_str ()); } goto ret; } if (v == boost::graph_traits::null_vertex ()) { - if ( (rc = db.load (hwloc_xml, ctx->reader, rank)) < 0) { - flux_log (ctx->h, LOG_ERR, "%s: reader: %s", - __FUNCTION__, ctx->reader->err_message ().c_str ()); + if ((rc = db.load (hwloc_xml, ctx->reader, rank)) < 0) { + flux_log (ctx->h, + LOG_ERR, + "%s: reader: %s", + __FUNCTION__, + ctx->reader->err_message ().c_str ()); goto ret; } } else { - if ( (rc = db.load (hwloc_xml, ctx->reader, v, rank)) < 0) { - flux_log (ctx->h, LOG_ERR, "%s: reader: %s", - __FUNCTION__, ctx->reader->err_message ().c_str ()); + if ((rc = db.load (hwloc_xml, ctx->reader, v, rank)) < 0) { + flux_log (ctx->h, + LOG_ERR, + "%s: reader: %s", + __FUNCTION__, + ctx->reader->err_message ().c_str ()); goto ret; } - } + } ret: return rc; @@ -582,8 +568,7 @@ static const char *get_array_string (json_t *array, size_t index) json_t *entry; const char *s; - if (!(entry = json_array_get (array, index)) - || !(s = json_string_value (entry))) { + if (!(entry = json_array_get (array, index)) || !(s = json_string_value (entry))) { errno = EINVAL; return NULL; } @@ -596,12 +581,12 @@ static int expand_ids (const char *resources, std::vector &id_vec) struct idset *ids = NULL; try { unsigned int id; - if ( !(ids = idset_decode (resources))) + if (!(ids = idset_decode (resources))) goto inval; - if ( (id = idset_first (ids)) == IDSET_INVALID_ID) + if ((id = idset_first (ids)) == IDSET_INVALID_ID) goto inval; id_vec.push_back (id); - while ( (id = idset_next (ids, id)) != IDSET_INVALID_ID) + while ((id = idset_next (ids, id)) != IDSET_INVALID_ID) id_vec.push_back (id); rc = 0; } catch (std::bad_alloc &) { @@ -619,8 +604,10 @@ static int expand_ids (const char *resources, std::vector &id_vec) /* Given 'resobj' in Rv1 form, decode the set of execution target ranks * contained in it as well as r_lite key. */ -static int unpack_resources (json_t *resobj, struct idset **idset, - json_t **r_lite_p, json_t **jgf_p, +static int unpack_resources (json_t *resobj, + struct idset **idset, + json_t **r_lite_p, + json_t **jgf_p, graph_duration_t &duration) { int rc = 0; @@ -637,12 +624,18 @@ static int unpack_resources (json_t *resobj, struct idset **idset, if (resobj) { if (json_unpack (resobj, "{s:i s:{s:o s?F s?F} s?:o}", - "version", &version, + "version", + &version, "execution", - "R_lite", &r_lite, - "starttime", &start, - "expiration", &end, - "scheduling", &jgf) < 0) + "R_lite", + &r_lite, + "starttime", + &start, + "expiration", + &end, + "scheduling", + &jgf) + < 0) goto inval; // flux-core validates these numbers, but checking here // in case Fluxin is plugged into another resource manager @@ -656,26 +649,33 @@ static int unpack_resources (json_t *resobj, struct idset **idset, goto inval; // Greatest lower bound is int64_t in the rest of Fluxion if (start > static_cast (std::numeric_limits::max ()) - || end > static_cast - (std::numeric_limits::max ())) + || end > static_cast (std::numeric_limits::max ())) goto inval; // Ensure start and end are representable in system clock - if (start > static_cast - (std::chrono::duration_cast - (std::chrono::time_point::max ().time_since_epoch ()).count ()) - || end > static_cast - (std::chrono::duration_cast - (std::chrono::time_point::max ().time_since_epoch ()).count ())) + if (start > static_cast ( + std::chrono::duration_cast ( + std::chrono::time_point::max ().time_since_epoch ()) + .count ()) + || end > static_cast ( + std::chrono::duration_cast ( + std::chrono::time_point::max () + .time_since_epoch ()) + .count ())) goto inval; // Expects int type argument - duration.graph_start = std::chrono::system_clock::from_time_t (static_cast (start)); + duration.graph_start = + std::chrono::system_clock::from_time_t (static_cast (start)); duration.graph_end = std::chrono::system_clock::from_time_t (static_cast (end)); // Ensure there is no overflow in system clock representation // (should be handled by previous check). - if (std::chrono::duration_cast - (duration.graph_start.time_since_epoch ()).count () < 0 - || std::chrono::duration_cast - (duration.graph_end.time_since_epoch ()).count () < 0) { + if (std::chrono::duration_cast ( + duration.graph_start.time_since_epoch ()) + .count () + < 0 + || std::chrono::duration_cast ( + duration.graph_end.time_since_epoch ()) + .count () + < 0) { goto inval; } json_array_foreach (r_lite, index, val) { @@ -710,8 +710,7 @@ static int unpack_resources (json_t *resobj, struct idset **idset, } static int unpack_resobj (json_t *resobj, - std::map> &out) + std::map> &out) { if (!resobj) goto inval; @@ -723,11 +722,16 @@ static int unpack_resobj (json_t *resobj, std::string range; std::istringstream istr; const char *rank = NULL, *core = NULL, *gpu = NULL; - if (json_unpack (val, "{s:s s:{s?:s s?:s}}", - "rank", &rank, - "children", - "core", &core, - "gpu", &gpu) < 0) + if (json_unpack (val, + "{s:s s:{s?:s s?:s}}", + "rank", + &rank, + "children", + "core", + &core, + "gpu", + &gpu) + < 0) goto inval; // Split the rank idset in resobj, convert each entry into // distict_range_t and use it as the key to std::map. @@ -738,8 +742,9 @@ static int unpack_resobj (json_t *resobj, istr.str (rank); while (std::getline (istr, range, ',')) { uint64_t low, high; - std::pair>::iterator, bool> res; + std::pair>::iterator, + bool> + res; std::shared_ptr robj = std::make_shared (); if (distinct_range_t::get_low_high (range, low, high) < 0) goto error; @@ -748,9 +753,9 @@ static int unpack_resobj (json_t *resobj, goto error; if (gpu && expand_ids (gpu, robj->gpu) < 0) goto error; - res = out.insert (std::pair> ( - distinct_range_t{low, high}, robj)); + res = out.insert ( + std::pair> (distinct_range_t{low, high}, robj)); if (res.second == false) { errno = EEXIST; goto error; @@ -770,8 +775,7 @@ static int unpack_resobj (json_t *resobj, return -1; } -static int remap_hwloc_namespace (std::shared_ptr &ctx, - json_t *r_lite) +static int remap_hwloc_namespace (std::shared_ptr &ctx, json_t *r_lite) { std::map> resobjs; if (unpack_resobj (r_lite, resobjs) < 0) @@ -780,11 +784,11 @@ static int remap_hwloc_namespace (std::shared_ptr &ctx, /* hwloc reader only needs to remap gpu IDs */ size_t logical; for (logical = 0; logical < kv.second->gpu.size (); logical++) { - if (ctx->reader->namespace_remapper.add ( - kv.second->exec_target_range, - "gpu", - logical, - kv.second->gpu[logical]) < 0) + if (ctx->reader->namespace_remapper.add (kv.second->exec_target_range, + "gpu", + logical, + kv.second->gpu[logical]) + < 0) return -1; } } @@ -792,7 +796,8 @@ static int remap_hwloc_namespace (std::shared_ptr &ctx, } static int remap_jgf_namespace (std::shared_ptr &ctx, - json_t *resobj, json_t *p_resobj) + json_t *resobj, + json_t *p_resobj) { size_t i, j; uint64_t cur_rank = 0; @@ -819,8 +824,7 @@ static int remap_jgf_namespace (std::shared_ptr &ctx, // to C's "1-2" range. B's "3" to C's "3". And B's "4-5" to C's "4-5". for (auto kv : p_robjs) { distinct_range_t new_range{cur_rank, - kv.first.get_high () - - kv.first.get_low () + cur_rank}; + kv.first.get_high () - kv.first.get_low () + cur_rank}; std::shared_ptr entry = nullptr; std::shared_ptr p_entry = kv.second; if (robjs.find (new_range) == robjs.end ()) { @@ -830,14 +834,16 @@ static int remap_jgf_namespace (std::shared_ptr &ctx, goto error; } entry = robjs[new_range]; - if (ctx->reader->namespace_remapper.add_exec_target_range ( - p_entry->exec_target_range, - new_range) < 0) + if (ctx->reader->namespace_remapper.add_exec_target_range (p_entry->exec_target_range, + new_range) + < 0) goto error; for (j = 0; j < p_entry->core.size (); j++) { - if (ctx->reader->namespace_remapper.add ( - p_entry->exec_target_range, "core", - p_entry->core[j], entry->core[j]) < 0) + if (ctx->reader->namespace_remapper.add (p_entry->exec_target_range, + "core", + p_entry->core[j], + entry->core[j]) + < 0) goto error; } cur_rank += (kv.first.get_high () - kv.first.get_low () + 1); @@ -856,7 +862,8 @@ static int remap_jgf_namespace (std::shared_ptr &ctx, * If 'ids' is the empty set, an empty resource vertex will be instantiated. */ static int grow_resource_db_hwloc (std::shared_ptr &ctx, - struct idset *ids, json_t *resobj) + struct idset *ids, + json_t *resobj) { int rc = -1; resource_graph_db_t &db = *(ctx->db); @@ -876,13 +883,12 @@ static int grow_resource_db_hwloc (std::shared_ptr &ctx, if (rank != IDSET_INVALID_ID) { if (!(hwloc_xml = get_array_string (xml_array, rank))) goto done; - } - else + } else hwloc_xml = NULL; // before hwloc reader is used, set remap - if ( (rc = remap_hwloc_namespace (ctx, resobj)) < 0) + if ((rc = remap_hwloc_namespace (ctx, resobj)) < 0) goto done; - if ( (rc = grow (ctx, v, rank, hwloc_xml)) < 0) + if ((rc = grow (ctx, v, rank, hwloc_xml)) < 0) goto done; } @@ -891,8 +897,7 @@ static int grow_resource_db_hwloc (std::shared_ptr &ctx, if (db.metadata.roots.find ("containment") == db.metadata.roots.end ()) { rc = -1; errno = EINVAL; - flux_log (ctx->h, LOG_ERR, "%s: cluster vertex is unavailable", - __FUNCTION__); + flux_log (ctx->h, LOG_ERR, "%s: cluster vertex is unavailable", __FUNCTION__); goto done; } v = db.metadata.roots.at ("containment"); @@ -902,13 +907,12 @@ static int grow_resource_db_hwloc (std::shared_ptr &ctx, // For the rest of the ranks -- general case if (!(hwloc_xml = get_array_string (xml_array, rank))) goto done; - if ( (rc = grow (ctx, v, rank, hwloc_xml)) < 0) + if ((rc = grow (ctx, v, rank, hwloc_xml)) < 0) goto done; rank = idset_next (ids, rank); } - flux_log (ctx->h, LOG_DEBUG, - "resource graph datastore loaded with hwloc reader"); + flux_log (ctx->h, LOG_DEBUG, "resource graph datastore loaded with hwloc reader"); done: flux_future_destroy (f); @@ -916,7 +920,8 @@ static int grow_resource_db_hwloc (std::shared_ptr &ctx, } static int grow_resource_db_rv1exec (std::shared_ptr &ctx, - struct idset *ids, json_t *resobj) + struct idset *ids, + json_t *resobj) { int rc = -1; int saved_errno; @@ -924,17 +929,18 @@ static int grow_resource_db_rv1exec (std::shared_ptr &ctx, char *rv1_str = nullptr; if (db.metadata.roots.find ("containment") == db.metadata.roots.end ()) { - if ( (rv1_str = json_dumps (resobj, JSON_INDENT (0))) == NULL) { + if ((rv1_str = json_dumps (resobj, JSON_INDENT (0))) == NULL) { errno = ENOMEM; goto done; } - if ( (rc = db.load (rv1_str, ctx->reader, -1)) < 0) { - flux_log_error (ctx->h, "%s: db.load: %s", - __FUNCTION__, ctx->reader->err_message ().c_str ()); + if ((rc = db.load (rv1_str, ctx->reader, -1)) < 0) { + flux_log_error (ctx->h, + "%s: db.load: %s", + __FUNCTION__, + ctx->reader->err_message ().c_str ()); goto done; } - flux_log (ctx->h, LOG_DEBUG, - "resource graph datastore loaded with rv1exec reader"); + flux_log (ctx->h, LOG_DEBUG, "resource graph datastore loaded with rv1exec reader"); } done: saved_errno = errno; @@ -943,8 +949,7 @@ static int grow_resource_db_rv1exec (std::shared_ptr &ctx, return rc; } -static int get_parent_job_resources (std::shared_ptr &ctx, - json_t **resobj_p) +static int get_parent_job_resources (std::shared_ptr &ctx, json_t **resobj_p) { int rc = -1; json_t *resobj; @@ -954,23 +959,29 @@ static int get_parent_job_resources (std::shared_ptr &ctx, flux_t *parent_h = NULL; const char *uri, *jobid, *resobj_str; - if ( !(uri = flux_attr_get (ctx->h, "parent-uri"))) + if (!(uri = flux_attr_get (ctx->h, "parent-uri"))) return 0; - if ( !(jobid = flux_attr_get (ctx->h, "jobid"))) + if (!(jobid = flux_attr_get (ctx->h, "jobid"))) return 0; if (flux_job_id_parse (jobid, &id) < 0) { flux_log_error (ctx->h, "%s: parsing jobid %s", __FUNCTION__, jobid); return -1; } - if ( !(parent_h = flux_open (uri, 0))) { + if (!(parent_h = flux_open (uri, 0))) { flux_log_error (ctx->h, "%s: flux_open (%s)", __FUNCTION__, uri); goto done; } - if ( !(f = flux_rpc_pack (parent_h, "job-info.lookup", FLUX_NODEID_ANY, 0, - "{s:I s:[s] s:i}", - "id", id, - "keys", "R", - "flags", 0))) { + if (!(f = flux_rpc_pack (parent_h, + "job-info.lookup", + FLUX_NODEID_ANY, + 0, + "{s:I s:[s] s:i}", + "id", + id, + "keys", + "R", + "flags", + 0))) { flux_log_error (ctx->h, "%s: flux_rpc_pack (R)", __FUNCTION__); goto done; } @@ -978,7 +989,7 @@ static int get_parent_job_resources (std::shared_ptr &ctx, flux_log_error (ctx->h, "%s: flux_rpc_get_unpack (R)", __FUNCTION__); goto done; } - if ( !(resobj = json_loads (resobj_str, 0, &json_err))) { + if (!(resobj = json_loads (resobj_str, 0, &json_err))) { errno = ENOMEM; flux_log (ctx->h, LOG_ERR, "%s: json_loads", __FUNCTION__); goto done; @@ -991,8 +1002,7 @@ static int get_parent_job_resources (std::shared_ptr &ctx, return rc; } -static int unpack_parent_job_resources (std::shared_ptr &ctx, - json_t **p_r_lite_p) +static int unpack_parent_job_resources (std::shared_ptr &ctx, json_t **p_r_lite_p) { int rc = 0; int saved_errno; @@ -1002,18 +1012,16 @@ static int unpack_parent_job_resources (std::shared_ptr &ctx, json_t *p_r_lite = NULL; json_t *p_resources = NULL; struct idset *p_grow_set = NULL; - if ( (rc = get_parent_job_resources (ctx, &p_resources)) < 0 - || !p_resources) + if ((rc = get_parent_job_resources (ctx, &p_resources)) < 0 || !p_resources) goto done; - if ( (rc = unpack_resources (p_resources, &p_grow_set, &p_r_lite, - &p_jgf, duration)) < 0) + if ((rc = unpack_resources (p_resources, &p_grow_set, &p_r_lite, &p_jgf, duration)) < 0) goto done; if (!p_grow_set || !p_r_lite || !p_jgf) { errno = EINVAL; rc = -1; goto done; } - if ( (*p_r_lite_p = json_deep_copy (p_r_lite)) == NULL) { + if ((*p_r_lite_p = json_deep_copy (p_r_lite)) == NULL) { errno = ENOMEM; rc = -1; goto done; @@ -1027,8 +1035,7 @@ static int unpack_parent_job_resources (std::shared_ptr &ctx, return rc; } -static int grow_resource_db_jgf (std::shared_ptr &ctx, - json_t *r_lite, json_t *jgf) +static int grow_resource_db_jgf (std::shared_ptr &ctx, json_t *r_lite, json_t *jgf) { int rc = -1; int saved_errno; @@ -1037,31 +1044,30 @@ static int grow_resource_db_jgf (std::shared_ptr &ctx, char *jgf_str = NULL; vtx_t v = boost::graph_traits::null_vertex (); - if ( (rc = unpack_parent_job_resources (ctx, &p_r_lite)) < 0) { - flux_log_error (ctx->h, "%s: unpack_parent_job_resources", - __FUNCTION__); + if ((rc = unpack_parent_job_resources (ctx, &p_r_lite)) < 0) { + flux_log_error (ctx->h, "%s: unpack_parent_job_resources", __FUNCTION__); goto done; } if (db.metadata.roots.find ("containment") == db.metadata.roots.end ()) { - if ( p_r_lite - && (rc = remap_jgf_namespace (ctx, r_lite, p_r_lite)) < 0) { + if (p_r_lite && (rc = remap_jgf_namespace (ctx, r_lite, p_r_lite)) < 0) { flux_log_error (ctx->h, "%s: remap_jgf_namespace", __FUNCTION__); goto done; } - if ( (jgf_str = json_dumps (jgf, JSON_INDENT (0))) == NULL) { + if ((jgf_str = json_dumps (jgf, JSON_INDENT (0))) == NULL) { rc = -1; errno = ENOMEM; goto done; } - if ( (rc = db.load (jgf_str, ctx->reader, -1)) < 0) { - flux_log_error (ctx->h, "%s: db.load: %s", - __FUNCTION__, ctx->reader->err_message ().c_str ()); + if ((rc = db.load (jgf_str, ctx->reader, -1)) < 0) { + flux_log_error (ctx->h, + "%s: db.load: %s", + __FUNCTION__, + ctx->reader->err_message ().c_str ()); goto done; } } - flux_log (ctx->h, LOG_DEBUG, - "resource graph datastore loaded with JGF reader"); + flux_log (ctx->h, LOG_DEBUG, "resource graph datastore loaded with JGF reader"); done: saved_errno = errno; @@ -1071,8 +1077,7 @@ static int grow_resource_db_jgf (std::shared_ptr &ctx, return rc; } -static int grow_resource_db (std::shared_ptr &ctx, - json_t *resources) +static int grow_resource_db (std::shared_ptr &ctx, json_t *resources) { int rc = 0; graph_duration_t duration; @@ -1080,33 +1085,29 @@ static int grow_resource_db (std::shared_ptr &ctx, json_t *r_lite = NULL; json_t *jgf = NULL; - if ( (rc = unpack_resources (resources, - &grow_set, &r_lite, &jgf, duration)) < 0) { + if ((rc = unpack_resources (resources, &grow_set, &r_lite, &jgf, duration)) < 0) { flux_log_error (ctx->h, "%s: unpack_resources", __FUNCTION__); goto done; } if (jgf) { if (ctx->reader == nullptr && (rc = create_reader (ctx, "jgf")) < 0) { - flux_log (ctx->h, LOG_ERR, "%s: can't create jgf reader", - __FUNCTION__); + flux_log (ctx->h, LOG_ERR, "%s: can't create jgf reader", __FUNCTION__); goto done; } rc = grow_resource_db_jgf (ctx, r_lite, jgf); } else { if (ctx->opts.get_opt ().get_load_format () == "hwloc") { - if ( !ctx->reader && (rc = create_reader (ctx, "hwloc")) < 0) { - flux_log (ctx->h, LOG_ERR, "%s: can't create hwloc reader", - __FUNCTION__); - goto done; - } - rc = grow_resource_db_hwloc (ctx, grow_set, r_lite); + if (!ctx->reader && (rc = create_reader (ctx, "hwloc")) < 0) { + flux_log (ctx->h, LOG_ERR, "%s: can't create hwloc reader", __FUNCTION__); + goto done; + } + rc = grow_resource_db_hwloc (ctx, grow_set, r_lite); } else if (ctx->opts.get_opt ().get_load_format () == "rv1exec") { - if ( !ctx->reader && (rc = create_reader (ctx, "rv1exec")) < 0) { - flux_log (ctx->h, LOG_ERR, "%s: can't create rv1exec reader", - __FUNCTION__); - goto done; - } - rc = grow_resource_db_rv1exec (ctx, grow_set, resources); + if (!ctx->reader && (rc = create_reader (ctx, "rv1exec")) < 0) { + flux_log (ctx->h, LOG_ERR, "%s: can't create rv1exec reader", __FUNCTION__); + goto done; + } + rc = grow_resource_db_rv1exec (ctx, grow_set, resources); } else { errno = EINVAL; rc = -1; @@ -1120,11 +1121,10 @@ static int grow_resource_db (std::shared_ptr &ctx, return rc; } -static int decode_all (std::shared_ptr &ctx, - std::set &ranks) +static int decode_all (std::shared_ptr &ctx, std::set &ranks) { ranks.clear (); - for (auto const& kv: ctx->db->metadata.by_rank) { + for (auto const &kv : ctx->db->metadata.by_rank) { if (kv.first >= 0) ranks.insert (kv.first); } @@ -1132,7 +1132,8 @@ static int decode_all (std::shared_ptr &ctx, } static int decode_rankset (std::shared_ptr &ctx, - const char *ids, std::set &ranks) + const char *ids, + std::set &ranks) { int rc = -1; unsigned int rank; @@ -1143,13 +1144,13 @@ static int decode_rankset (std::shared_ptr &ctx, goto done; } if (std::string ("all") == ids) { - if ( (rc = decode_all (ctx, ranks)) < 0) + if ((rc = decode_all (ctx, ranks)) < 0) goto done; } else { - if ( !(idset = idset_decode (ids))) + if (!(idset = idset_decode (ids))) goto done; - for (rank = idset_first (idset); - rank != IDSET_INVALID_ID; rank = idset_next (idset, rank)) { + for (rank = idset_first (idset); rank != IDSET_INVALID_ID; + rank = idset_next (idset, rank)) { auto ret = ranks.insert (static_cast (rank)); if (!ret.second) { errno = EEXIST; @@ -1165,43 +1166,49 @@ static int decode_rankset (std::shared_ptr &ctx, } static int mark_lazy (std::shared_ptr &ctx, - const char *ids, resource_pool_t::status_t status) + const char *ids, + resource_pool_t::status_t status) { int rc = 0; switch (status) { - case resource_pool_t::status_t::UP: - ctx->set_ups (ids); - break; + case resource_pool_t::status_t::UP: + ctx->set_ups (ids); + break; - case resource_pool_t::status_t::DOWN: - default: - // "down" shouldn't be a part of the first response of resource.acquire - errno = EINVAL; - rc = -1; + case resource_pool_t::status_t::DOWN: + default: + // "down" shouldn't be a part of the first response of resource.acquire + errno = EINVAL; + rc = -1; } return rc; } static int mark_now (std::shared_ptr &ctx, - const char *ids, resource_pool_t::status_t status) + const char *ids, + resource_pool_t::status_t status) { int rc = -1; - std::set ranks; + std::set ranks; if (!ids) { errno = EINVAL; goto done; } - if ( (rc = decode_rankset (ctx, ids, ranks)) < 0) + if ((rc = decode_rankset (ctx, ids, ranks)) < 0) goto done; - if ( (rc = ctx->traverser->mark (ranks, status)) < 0) { - flux_log_error (ctx->h, "%s: traverser::mark: %s", __FUNCTION__, - ctx->traverser->err_message ().c_str ()); + if ((rc = ctx->traverser->mark (ranks, status)) < 0) { + flux_log_error (ctx->h, + "%s: traverser::mark: %s", + __FUNCTION__, + ctx->traverser->err_message ().c_str ()); ctx->traverser->clear_err_message (); goto done; } - flux_log (ctx->h, LOG_DEBUG, + flux_log (ctx->h, + LOG_DEBUG, "resource status changed (rankset=[%s] status=%s)", - ids, resource_pool_t::status_to_str (status).c_str ()); + ids, + resource_pool_t::status_to_str (status).c_str ()); // Updated the ranks ctx->m_resources_down_updated = true; @@ -1211,15 +1218,17 @@ static int mark_now (std::shared_ptr &ctx, } static int mark (std::shared_ptr &ctx, - const char *ids, resource_pool_t::status_t status) + const char *ids, + resource_pool_t::status_t status) { - return (ctx->traverser->is_initialized ())? mark_now (ctx, ids, status) - : mark_lazy (ctx, ids, status); + return (ctx->traverser->is_initialized ()) ? mark_now (ctx, ids, status) + : mark_lazy (ctx, ids, status); } static int update_resource_db (std::shared_ptr &ctx, json_t *resources, - const char *up, const char *down) + const char *up, + const char *down) { int rc = 0; // Will need to get duration update and set graph metadata when @@ -1249,17 +1258,22 @@ static void update_resource (flux_future_t *f, void *arg) json_t *resources = NULL; std::shared_ptr ctx = getctx ((flux_t *)arg); - if ( (rc = flux_rpc_get_unpack (f, "{s?:o s?:s s?:s s?:F}", - "resources", &resources, - "up", &up, - "down", &down, - "expiration", &expiration)) < 0) { - flux_log_error (ctx->h, "%s: exiting due to resource.acquire failure", - __FUNCTION__); + if ((rc = flux_rpc_get_unpack (f, + "{s?:o s?:s s?:s s?:F}", + "resources", + &resources, + "up", + &up, + "down", + &down, + "expiration", + &expiration)) + < 0) { + flux_log_error (ctx->h, "%s: exiting due to resource.acquire failure", __FUNCTION__); flux_reactor_stop (flux_get_reactor (ctx->h)); goto done; } - if ( (rc = update_resource_db (ctx, resources, up, down)) < 0) { + if ((rc = update_resource_db (ctx, resources, up, down)) < 0) { flux_log_error (ctx->h, "%s: update_resource_db", __FUNCTION__); goto done; } @@ -1267,14 +1281,11 @@ static void update_resource (flux_future_t *f, void *arg) /* Update graph duration: */ ctx->db->metadata.graph_duration.graph_end = - std::chrono::system_clock::from_time_t ((time_t) expiration); - flux_log (ctx->h, - LOG_INFO, - "resource expiration updated to %.2f", - expiration); + std::chrono::system_clock::from_time_t ((time_t)expiration); + flux_log (ctx->h, LOG_INFO, "resource expiration updated to %.2f", expiration); } for (auto &kv : ctx->notify_msgs) { - if ( (rc += flux_respond (ctx->h, kv.second->get_msg (), NULL)) < 0) { + if ((rc += flux_respond (ctx->h, kv.second->get_msg (), NULL)) < 0) { flux_log_error (ctx->h, "%s: flux_respond", __FUNCTION__); } } @@ -1288,20 +1299,20 @@ static int populate_resource_db_acquire (std::shared_ptr &ctx) int rc = -1; json_t *o = NULL; - if ( !(ctx->update_f = flux_rpc (ctx->h, "resource.acquire", NULL, - FLUX_NODEID_ANY, FLUX_RPC_STREAMING))) { + if (!(ctx->update_f = + flux_rpc (ctx->h, "resource.acquire", NULL, FLUX_NODEID_ANY, FLUX_RPC_STREAMING))) { flux_log_error (ctx->h, "%s: flux_rpc", __FUNCTION__); goto done; } update_resource (ctx->update_f, static_cast (ctx->h)); - if ( (rc = ctx->fetch_and_reset_update_rc ()) < 0) { + if ((rc = ctx->fetch_and_reset_update_rc ()) < 0) { flux_log_error (ctx->h, "%s: update_resource", __FUNCTION__); goto done; } - if ( (rc = flux_future_then (ctx->update_f, -1.0, update_resource, - static_cast (ctx->h))) < 0) { + if ((rc = flux_future_then (ctx->update_f, -1.0, update_resource, static_cast (ctx->h))) + < 0) { flux_log_error (ctx->h, "%s: flux_future_then", __FUNCTION__); goto done; } @@ -1316,24 +1327,27 @@ static int populate_resource_db (std::shared_ptr &ctx) std::chrono::duration elapsed; if (ctx->opts.get_opt ().is_reserve_vtx_vec_set ()) - ctx->db->resource_graph.m_vertices.reserve ( - ctx->opts.get_opt ().get_reserve_vtx_vec ()); + ctx->db->resource_graph.m_vertices.reserve (ctx->opts.get_opt ().get_reserve_vtx_vec ()); start = std::chrono::system_clock::now (); if (ctx->opts.get_opt ().is_load_file_set ()) { if (populate_resource_db_file (ctx) < 0) goto done; - flux_log (ctx->h, LOG_INFO, "%s: loaded resources from %s", + flux_log (ctx->h, + LOG_INFO, + "%s: loaded resources from %s", __FUNCTION__, ctx->opts.get_opt ().get_load_file ().c_str ()); } else { if (populate_resource_db_acquire (ctx) < 0) { - flux_log (ctx->h, LOG_ERR, + flux_log (ctx->h, + LOG_ERR, "%s: loading resources using resource.acquire", __FUNCTION__); goto done; } - flux_log (ctx->h, LOG_INFO, + flux_log (ctx->h, + LOG_INFO, "%s: loaded resources from core's resource.acquire", __FUNCTION__); } @@ -1375,8 +1389,7 @@ static int select_subsystems (std::shared_ptr &ctx) errno = EINVAL; goto done; } - std::stringstream relations (token.substr (found+1, - std::string::npos)); + std::stringstream relations (token.substr (found + 1, std::string::npos)); std::string relation; while (getline (relations, relation, ':')) ctx->matcher->add_subsystem (subsystem, relation); @@ -1392,37 +1405,36 @@ static int init_resource_graph (std::shared_ptr &ctx) int rc = 0; // Select the appropriate matcher based on CLI policy. - if ( !(ctx->matcher = create_match_cb ( - ctx->opts.get_opt ().get_match_policy ()))) { - flux_log (ctx->h, LOG_ERR, "%s: can't create match callback", - __FUNCTION__); + if (!(ctx->matcher = create_match_cb (ctx->opts.get_opt ().get_match_policy ()))) { + flux_log (ctx->h, LOG_ERR, "%s: can't create match callback", __FUNCTION__); return -1; - } - if ( (rc = populate_resource_db (ctx)) != 0) { - flux_log (ctx->h, LOG_ERR, - "%s: can't populate graph resource database", - __FUNCTION__); + if ((rc = populate_resource_db (ctx)) != 0) { + flux_log (ctx->h, LOG_ERR, "%s: can't populate graph resource database", __FUNCTION__); return rc; } - if ( (rc = select_subsystems (ctx)) != 0) { - flux_log (ctx->h, LOG_ERR, "%s: error processing subsystems %s", + if ((rc = select_subsystems (ctx)) != 0) { + flux_log (ctx->h, + LOG_ERR, + "%s: error processing subsystems %s", __FUNCTION__, ctx->opts.get_opt ().get_match_subsystems ().c_str ()); return rc; } // Create a writers object for matched vertices and edges - match_format_t format = match_writers_factory_t::get_writers_type ( - ctx->opts.get_opt ().get_match_format ()); - if ( !(ctx->writers = match_writers_factory_t::create (format))) + match_format_t format = + match_writers_factory_t::get_writers_type (ctx->opts.get_opt ().get_match_format ()); + if (!(ctx->writers = match_writers_factory_t::create (format))) return -1; if (ctx->opts.get_opt ().is_prune_filters_set () - && ctx->matcher->set_pruning_types_w_spec ( - ctx->matcher->dom_subsystem (), - ctx->opts.get_opt ().get_prune_filters ()) < 0) { - flux_log (ctx->h, LOG_ERR, "%s: error setting pruning types with: %s", + && ctx->matcher->set_pruning_types_w_spec (ctx->matcher->dom_subsystem (), + ctx->opts.get_opt ().get_prune_filters ()) + < 0) { + flux_log (ctx->h, + LOG_ERR, + "%s: error setting pruning types with: %s", __FUNCTION__, ctx->opts.get_opt ().get_prune_filters ().c_str ()); return -1; @@ -1430,8 +1442,7 @@ static int init_resource_graph (std::shared_ptr &ctx) // Initialize the DFU traverser if (ctx->traverser->initialize (ctx->db, ctx->matcher) < 0) { - flux_log (ctx->h, LOG_ERR, "%s: traverser initialization", - __FUNCTION__); + flux_log (ctx->h, LOG_ERR, "%s: traverser initialization", __FUNCTION__); return -1; } @@ -1445,8 +1456,7 @@ static int init_resource_graph (std::shared_ptr &ctx) return -1; } if (ctx->is_ups_set ()) { - if (mark (ctx, ctx->get_ups ().c_str (), - resource_pool_t::status_t::UP) < 0) { + if (mark (ctx, ctx->get_ups ().c_str (), resource_pool_t::status_t::UP) < 0) { flux_log (ctx->h, LOG_ERR, "%s: mark (up)", __FUNCTION__); return -1; } @@ -1455,14 +1465,11 @@ static int init_resource_graph (std::shared_ptr &ctx) return 0; } - - //////////////////////////////////////////////////////////////////////////////// // Request Handler Routines //////////////////////////////////////////////////////////////////////////////// -static void update_match_perf (double elapsed, int64_t jobid, - bool match_success) +static void update_match_perf (double elapsed, int64_t jobid, bool match_success) { if (match_success) perf.succeeded.update_stats (elapsed, jobid, perf.tmp_iter_count); @@ -1472,44 +1479,46 @@ static void update_match_perf (double elapsed, int64_t jobid, static inline std::string get_status_string (int64_t now, int64_t at) { - return (at == now)? "ALLOCATED" : "RESERVED"; + return (at == now) ? "ALLOCATED" : "RESERVED"; } -static inline bool is_existent_jobid ( - const std::shared_ptr &ctx, - uint64_t jobid) +static inline bool is_existent_jobid (const std::shared_ptr &ctx, uint64_t jobid) { - return (ctx->jobs.find (jobid) != ctx->jobs.end ())? true : false; + return (ctx->jobs.find (jobid) != ctx->jobs.end ()) ? true : false; } static int track_schedule_info (std::shared_ptr &ctx, - int64_t id, bool reserved, int64_t at, + int64_t id, + bool reserved, + int64_t at, const std::string &jspec, - const std::stringstream &R, double elapse) + const std::stringstream &R, + double elapse) { if (id < 0 || at < 0) { errno = EINVAL; return -1; } try { - job_lifecycle_t state = (!reserved)? job_lifecycle_t::ALLOCATED - : job_lifecycle_t::RESERVED; - ctx->jobs[id] = std::make_shared (id, state, at, "", - jspec, R.str (), elapse); + job_lifecycle_t state = + (!reserved) ? job_lifecycle_t::ALLOCATED : job_lifecycle_t::RESERVED; + ctx->jobs[id] = std::make_shared (id, state, at, "", jspec, R.str (), elapse); if (!reserved) ctx->allocations[id] = id; else ctx->reservations[id] = id; - } - catch (std::bad_alloc &e) { + } catch (std::bad_alloc &e) { errno = ENOMEM; return -1; } return 0; } -static int parse_R (std::shared_ptr &ctx, const char *R, - std::string &R_graph_fmt, int64_t &starttime, uint64_t &duration, +static int parse_R (std::shared_ptr &ctx, + const char *R, + std::string &R_graph_fmt, + int64_t &starttime, + uint64_t &duration, std::string &format) { int rc = 0; @@ -1522,18 +1531,24 @@ static int parse_R (std::shared_ptr &ctx, const char *R, json_error_t error; char *jgf_str = NULL; - if ( (o = json_loads (R, 0, &error)) == NULL) { + if ((o = json_loads (R, 0, &error)) == NULL) { rc = -1; flux_log (ctx->h, LOG_ERR, "%s: %s", __FUNCTION__, error.text); errno = EINVAL; goto out; } - if ( (rc = json_unpack (o, "{s:i s:{s:I s:I} s?:o}", - "version", &version, - "execution", - "starttime", &st, - "expiration", &et, - "scheduling", &graph)) < 0) { + if ((rc = json_unpack (o, + "{s:i s:{s:I s:I} s?:o}", + "version", + &version, + "execution", + "starttime", + &st, + "expiration", + &et, + "scheduling", + &graph)) + < 0) { errno = EINVAL; flux_log (ctx->h, LOG_ERR, "%s: json_unpack", __FUNCTION__); goto freemem_out; @@ -1541,14 +1556,17 @@ static int parse_R (std::shared_ptr &ctx, const char *R, if (version != 1 || st < 0 || et < st) { rc = -1; errno = EPROTO; - flux_log (ctx->h, LOG_ERR, + flux_log (ctx->h, + LOG_ERR, "%s: version=%d, starttime=%jd, expiration=%jd", - __FUNCTION__, version, - static_cast (st), static_cast (et)); + __FUNCTION__, + version, + static_cast (st), + static_cast (et)); goto freemem_out; } if (graph != NULL) { - if ( !(jgf_str = json_dumps (graph, JSON_INDENT (0)))) { + if (!(jgf_str = json_dumps (graph, JSON_INDENT (0)))) { rc = -1; errno = ENOMEM; flux_log (ctx->h, LOG_ERR, "%s: json_dumps", __FUNCTION__); @@ -1574,8 +1592,7 @@ static int parse_R (std::shared_ptr &ctx, const char *R, return rc; } -static int Rlite_equal (const std::shared_ptr &ctx, - const char *R1, const char *R2) +static int Rlite_equal (const std::shared_ptr &ctx, const char *R1, const char *R2) { int rc = -1; int saved_errno; @@ -1586,29 +1603,25 @@ static int Rlite_equal (const std::shared_ptr &ctx, json_error_t error1; json_error_t error2; - if ( (o1 = json_loads (R1, 0, &error1)) == NULL) { + if ((o1 = json_loads (R1, 0, &error1)) == NULL) { errno = EINVAL; flux_log (ctx->h, LOG_ERR, "%s: %s", __FUNCTION__, error1.text); goto out; } - if ( (rc = json_unpack (o1, "{s:{s:o}}", - "execution", - "R_lite", &rlite1)) < 0) { + if ((rc = json_unpack (o1, "{s:{s:o}}", "execution", "R_lite", &rlite1)) < 0) { errno = EINVAL; goto out; } - if ( (o2 = json_loads (R2, 0, &error2)) == NULL) { + if ((o2 = json_loads (R2, 0, &error2)) == NULL) { errno = EINVAL; flux_log (ctx->h, LOG_ERR, "%s: %s", __FUNCTION__, error2.text); goto out; } - if ( (rc = json_unpack (o2, "{s:{s:o}}", - "execution", - "R_lite", &rlite2)) < 0) { + if ((rc = json_unpack (o2, "{s:{s:o}}", "execution", "R_lite", &rlite2)) < 0) { errno = EINVAL; goto out; } - rc = (json_equal (rlite1, rlite2) == 1)? 0 : 1; + rc = (json_equal (rlite1, rlite2) == 1) ? 0 : 1; out: saved_errno = errno; @@ -1618,34 +1631,34 @@ static int Rlite_equal (const std::shared_ptr &ctx, return rc; } -static int run (std::shared_ptr &ctx, int64_t jobid, - const char *cmd, const std::string &jstr, int64_t *at, +static int run (std::shared_ptr &ctx, + int64_t jobid, + const char *cmd, + const std::string &jstr, + int64_t *at, flux_error_t *errp) { int rc = -1; try { - Flux::Jobspec::Jobspec j {jstr}; + Flux::Jobspec::Jobspec j{jstr}; dfu_traverser_t &tr = *(ctx->traverser); if (std::string ("allocate") == cmd) rc = tr.run (j, ctx->writers, match_op_t::MATCH_ALLOCATE, jobid, at); else if (std::string ("allocate_with_satisfiability") == cmd) - rc = tr.run (j, ctx->writers, match_op_t:: - MATCH_ALLOCATE_W_SATISFIABILITY, jobid, at); + rc = tr.run (j, ctx->writers, match_op_t::MATCH_ALLOCATE_W_SATISFIABILITY, jobid, at); else if (std::string ("allocate_orelse_reserve") == cmd) - rc = tr.run (j, ctx->writers, match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE, - jobid, at); + rc = tr.run (j, ctx->writers, match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE, jobid, at); else if (std::string ("satisfiability") == cmd) - rc = tr.run (j, ctx->writers, match_op_t::MATCH_SATISFIABILITY, - jobid, at); + rc = tr.run (j, ctx->writers, match_op_t::MATCH_SATISFIABILITY, jobid, at); else errno = EINVAL; - } catch (const Flux::Jobspec::parse_error& e) { + } catch (const Flux::Jobspec::parse_error &e) { errno = EINVAL; - if (errp && e.what()) { - int n = snprintf (errp->text, sizeof (errp->text), "%s", e.what()); - if (n > (int) sizeof (errp->text)) + if (errp && e.what ()) { + int n = snprintf (errp->text, sizeof (errp->text), "%s", e.what ()); + if (n > (int)sizeof (errp->text)) errp->text[sizeof (errp->text) - 2] = '+'; } } @@ -1653,8 +1666,11 @@ static int run (std::shared_ptr &ctx, int64_t jobid, return rc; } -static int run (std::shared_ptr &ctx, int64_t jobid, - const std::string &R, int64_t at, uint64_t duration, +static int run (std::shared_ptr &ctx, + int64_t jobid, + const std::string &R, + int64_t at, + uint64_t duration, std::string &format) { int rc = 0; @@ -1663,37 +1679,54 @@ static int run (std::shared_ptr &ctx, int64_t jobid, if (format == "jgf") { if ((rd = create_resource_reader ("jgf")) == nullptr) { rc = -1; - flux_log (ctx->h, LOG_ERR, "%s: create JGF reader (id=%jd)", - __FUNCTION__, static_cast (jobid)); + flux_log (ctx->h, + LOG_ERR, + "%s: create JGF reader (id=%jd)", + __FUNCTION__, + static_cast (jobid)); goto out; } } else if (format == "rv1exec") { if ((rd = create_resource_reader ("rv1exec")) == nullptr) { rc = -1; - flux_log (ctx->h, LOG_ERR, "%s: create rv1exec reader (id=%jd)", - __FUNCTION__, static_cast (jobid)); + flux_log (ctx->h, + LOG_ERR, + "%s: create rv1exec reader (id=%jd)", + __FUNCTION__, + static_cast (jobid)); goto out; } } else { rc = -1; - flux_log (ctx->h, LOG_ERR, "%s: create rv1exec reader (id=%jd)", - __FUNCTION__, static_cast (jobid)); + flux_log (ctx->h, + LOG_ERR, + "%s: create rv1exec reader (id=%jd)", + __FUNCTION__, + static_cast (jobid)); goto out; } if ((rc = tr.run (R, ctx->writers, rd, jobid, at, duration)) < 0) { - flux_log (ctx->h, LOG_ERR, "%s: dfu_traverser_t::run (id=%jd): %s", - __FUNCTION__, static_cast (jobid), + flux_log (ctx->h, + LOG_ERR, + "%s: dfu_traverser_t::run (id=%jd): %s", + __FUNCTION__, + static_cast (jobid), ctx->traverser->err_message ().c_str ()); goto out; } out: - return rc; + return rc; } -static int run_match (std::shared_ptr &ctx, int64_t jobid, - const char *cmd, const std::string &jstr, int64_t *now, - int64_t *at, double *overhead, std::stringstream &o, +static int run_match (std::shared_ptr &ctx, + int64_t jobid, + const char *cmd, + const std::string &jstr, + int64_t *now, + int64_t *at, + double *overhead, + std::stringstream &o, flux_error_t *errp) { int rc = 0; @@ -1703,8 +1736,7 @@ static int run_match (std::shared_ptr &ctx, int64_t jobid, bool rsv = false; start = std::chrono::system_clock::now (); - if (strcmp ("allocate", cmd) != 0 - && strcmp ("allocate_orelse_reserve", cmd) != 0 + if (strcmp ("allocate", cmd) != 0 && strcmp ("allocate_orelse_reserve", cmd) != 0 && strcmp ("allocate_with_satisfiability", cmd) != 0 && strcmp ("satisfiability", cmd) != 0) { rc = -1; @@ -1713,30 +1745,30 @@ static int run_match (std::shared_ptr &ctx, int64_t jobid, goto done; } - epoch = std::chrono::duration_cast - (start.time_since_epoch ()); + epoch = std::chrono::duration_cast (start.time_since_epoch ()); *at = *now = epoch.count (); - if ( (rc = run (ctx, jobid, cmd, jstr, at, errp)) < 0) { + if ((rc = run (ctx, jobid, cmd, jstr, at, errp)) < 0) { elapsed = std::chrono::system_clock::now () - start; *overhead = elapsed.count (); update_match_perf (*overhead, jobid, false); goto done; } - if ( (rc = ctx->writers->emit (o)) < 0) { + if ((rc = ctx->writers->emit (o)) < 0) { flux_log_error (ctx->h, "%s: writer can't emit", __FUNCTION__); goto done; } - rsv = (*now != *at)? true : false; + rsv = (*now != *at) ? true : false; elapsed = std::chrono::system_clock::now () - start; *overhead = elapsed.count (); update_match_perf (*overhead, jobid, true); if (cmd != std::string ("satisfiability")) { - if ( (rc = track_schedule_info (ctx, jobid, - rsv, *at, jstr, o, *overhead)) != 0) { - flux_log_error (ctx->h, "%s: can't add job info (id=%jd)", - __FUNCTION__, (intmax_t)jobid); + if ((rc = track_schedule_info (ctx, jobid, rsv, *at, jstr, o, *overhead)) != 0) { + flux_log_error (ctx->h, + "%s: can't add job info (id=%jd)", + __FUNCTION__, + (intmax_t)jobid); goto done; } } @@ -1745,8 +1777,11 @@ static int run_match (std::shared_ptr &ctx, int64_t jobid, return rc; } -static int run_update (std::shared_ptr &ctx, int64_t jobid, - const char *R, int64_t &at, double &overhead, +static int run_update (std::shared_ptr &ctx, + int64_t jobid, + const char *R, + int64_t &at, + double &overhead, std::stringstream &o) { int rc = 0; @@ -1757,27 +1792,26 @@ static int run_update (std::shared_ptr &ctx, int64_t jobid, std::string format; start = std::chrono::system_clock::now (); - if ( (rc = parse_R (ctx, R, R_graph_fmt, at, duration, format)) < 0) { + if ((rc = parse_R (ctx, R, R_graph_fmt, at, duration, format)) < 0) { flux_log_error (ctx->h, "%s: parsing R", __FUNCTION__); goto done; } - if ( (rc = run (ctx, jobid, R_graph_fmt, at, duration, format)) < 0) { + if ((rc = run (ctx, jobid, R_graph_fmt, at, duration, format)) < 0) { elapsed = std::chrono::system_clock::now () - start; overhead = elapsed.count (); update_match_perf (overhead, jobid, false); flux_log_error (ctx->h, "%s: run", __FUNCTION__); goto done; } - if ( (rc = ctx->writers->emit (o)) < 0) { + if ((rc = ctx->writers->emit (o)) < 0) { flux_log_error (ctx->h, "%s: writers->emit", __FUNCTION__); goto done; } elapsed = std::chrono::system_clock::now () - start; overhead = elapsed.count (); update_match_perf (overhead, jobid, true); - if ( (rc = track_schedule_info (ctx, jobid, false, at, "", o, overhead)) != 0) { - flux_log_error (ctx->h, "%s: can't add job info (id=%jd)", - __FUNCTION__, (intmax_t)jobid); + if ((rc = track_schedule_info (ctx, jobid, false, at, "", o, overhead)) != 0) { + flux_log_error (ctx->h, "%s: can't add job info (id=%jd)", __FUNCTION__, (intmax_t)jobid); goto done; } @@ -1785,8 +1819,7 @@ static int run_update (std::shared_ptr &ctx, int64_t jobid, return rc; } -static void update_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void update_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { char *R = NULL; int64_t at = 0; @@ -1799,23 +1832,23 @@ static void update_request_cb (flux_t *h, flux_msg_handler_t *w, std::chrono::duration elapsed; std::shared_ptr ctx = getctx ((flux_t *)arg); - if (flux_request_unpack (msg, NULL, "{s:I s:s}", - "jobid", &jobid, - "R", &R) < 0) { + if (flux_request_unpack (msg, NULL, "{s:I s:s}", "jobid", &jobid, "R", &R) < 0) { flux_log_error (ctx->h, "%s: flux_request_unpack", __FUNCTION__); goto error; } if (is_existent_jobid (ctx, jobid)) { int rc = 0; start = std::chrono::system_clock::now (); - if ( (rc = Rlite_equal (ctx, R, ctx->jobs[jobid]->R.c_str ())) < 0) { + if ((rc = Rlite_equal (ctx, R, ctx->jobs[jobid]->R.c_str ())) < 0) { flux_log_error (ctx->h, "%s: Rlite_equal", __FUNCTION__); goto error; } else if (rc == 1) { - errno=EINVAL; - flux_log (ctx->h, LOG_ERR, + errno = EINVAL; + flux_log (ctx->h, + LOG_ERR, "%s: jobid (%jd) with different R exists!", - __FUNCTION__, static_cast (jobid)); + __FUNCTION__, + static_cast (jobid)); goto error; } elapsed = std::chrono::system_clock::now () - start; @@ -1824,24 +1857,36 @@ static void update_request_cb (flux_t *h, flux_msg_handler_t *w, get_jobstate_str (ctx->jobs[jobid]->state, status); o << ctx->jobs[jobid]->R; at = ctx->jobs[jobid]->scheduled_at; - flux_log (ctx->h, LOG_DEBUG, "%s: jobid (%jd) with matching R exists", - __FUNCTION__, static_cast (jobid)); + flux_log (ctx->h, + LOG_DEBUG, + "%s: jobid (%jd) with matching R exists", + __FUNCTION__, + static_cast (jobid)); } else if (run_update (ctx, jobid, R, at, overhead, o) < 0) { flux_log_error (ctx->h, "%s: update failed (id=%jd)", - __FUNCTION__, static_cast (jobid)); + __FUNCTION__, + static_cast (jobid)); goto error; } - if ( status == "") + if (status == "") status = get_status_string (at, at); - if (flux_respond_pack (h, msg, "{s:I s:s s:f s:s s:I}", - "jobid", jobid, - "status", status.c_str (), - "overhead", overhead, - "R", o.str ().c_str (), - "at", at) < 0) + if (flux_respond_pack (h, + msg, + "{s:I s:s s:f s:s s:I}", + "jobid", + jobid, + "status", + status.c_str (), + "overhead", + overhead, + "R", + o.str ().c_str (), + "at", + at) + < 0) flux_log_error (h, "%s", __FUNCTION__); return; @@ -1851,8 +1896,11 @@ static void update_request_cb (flux_t *h, flux_msg_handler_t *w, flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); } -static int run_remove (std::shared_ptr &ctx, int64_t jobid, - const char *R, bool part_cancel, bool &full_removal) +static int run_remove (std::shared_ptr &ctx, + int64_t jobid, + const char *R, + bool part_cancel, + bool &full_removal) { int rc = -1; dfu_traverser_t &tr = *(ctx->traverser); @@ -1860,10 +1908,13 @@ static int run_remove (std::shared_ptr &ctx, int64_t jobid, if (part_cancel) { // RV1exec only reader supported in production currently std::shared_ptr reader; - if ( (reader = create_resource_reader ("rv1exec")) == nullptr) { + if ((reader = create_resource_reader ("rv1exec")) == nullptr) { rc = -1; - flux_log (ctx->h, LOG_ERR, "%s: creating rv1exec reader (id=%jd)", - __FUNCTION__, static_cast (jobid)); + flux_log (ctx->h, + LOG_ERR, + "%s: creating rv1exec reader (id=%jd)", + __FUNCTION__, + static_cast (jobid)); goto out; } rc = tr.remove (R, reader, jobid, full_removal); @@ -1873,15 +1924,15 @@ static int run_remove (std::shared_ptr &ctx, int64_t jobid, } if (rc != 0) { if (is_existent_jobid (ctx, jobid)) { - // When this condition arises, we will be less likely - // to be able to reuse this jobid. Having the errored job - // in the jobs map will prevent us from reusing the jobid - // up front. Note that a same jobid can be reserved and - // removed multiple times by the upper queuing layer - // as part of providing advanced queueing policies - // (e.g., conservative backfill). - std::shared_ptr info = ctx->jobs[jobid]; - info->state = job_lifecycle_t::ERROR; + // When this condition arises, we will be less likely + // to be able to reuse this jobid. Having the errored job + // in the jobs map will prevent us from reusing the jobid + // up front. Note that a same jobid can be reserved and + // removed multiple times by the upper queuing layer + // as part of providing advanced queueing policies + // (e.g., conservative backfill). + std::shared_ptr info = ctx->jobs[jobid]; + info->state = job_lifecycle_t::ERROR; } goto out; } @@ -1893,8 +1944,7 @@ static int run_remove (std::shared_ptr &ctx, int64_t jobid, return rc; } -static void match_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void match_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { int64_t at = 0; int64_t now = 0; @@ -1906,20 +1956,28 @@ static void match_request_cb (flux_t *h, flux_msg_handler_t *w, std::stringstream R; std::shared_ptr ctx = getctx ((flux_t *)arg); - if (flux_request_unpack (msg, NULL, "{s:s s:I s:s}", "cmd", &cmd, - "jobid", &jobid, "jobspec", &js_str) < 0) + if (flux_request_unpack (msg, + NULL, + "{s:s s:I s:s}", + "cmd", + &cmd, + "jobid", + &jobid, + "jobspec", + &js_str) + < 0) goto error; if (is_existent_jobid (ctx, jobid)) { errno = EINVAL; - flux_log_error (h, "%s: existent job (%jd).", - __FUNCTION__, (intmax_t)jobid); + flux_log_error (h, "%s: existent job (%jd).", __FUNCTION__, (intmax_t)jobid); goto error; } if (run_match (ctx, jobid, cmd, js_str, &now, &at, &overhead, R, NULL) < 0) { if (errno != EBUSY && errno != ENODEV) flux_log_error (ctx->h, "%s: match failed due to match error (id=%jd)", - __FUNCTION__, (intmax_t)jobid); + __FUNCTION__, + (intmax_t)jobid); // The resources couldn't be allocated *or reserved* // Kicking back to qmanager, remove from tracking if (errno == EBUSY) { @@ -1929,12 +1987,20 @@ static void match_request_cb (flux_t *h, flux_msg_handler_t *w, } status = get_status_string (now, at); - if (flux_respond_pack (h, msg, "{s:I s:s s:f s:s s:I}", - "jobid", jobid, - "status", status.c_str (), - "overhead", overhead, - "R", R.str ().c_str (), - "at", at) < 0) + if (flux_respond_pack (h, + msg, + "{s:I s:s s:f s:s s:I}", + "jobid", + jobid, + "status", + status.c_str (), + "overhead", + overhead, + "R", + R.str ().c_str (), + "at", + at) + < 0) flux_log_error (h, "%s", __FUNCTION__); return; @@ -1944,8 +2010,10 @@ static void match_request_cb (flux_t *h, flux_msg_handler_t *w, flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); } -static void match_multi_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void match_multi_request_cb (flux_t *h, + flux_msg_handler_t *w, + const flux_msg_t *msg, + void *arg) { size_t index; json_t *value; @@ -1962,16 +2030,14 @@ static void match_multi_request_cb (flux_t *h, flux_msg_handler_t *w, errno = EPROTO; goto error; } - if (flux_request_unpack (msg, NULL, "{s:s s:s}", - "cmd", &cmd, - "jobs", &jobs_str) < 0) + if (flux_request_unpack (msg, NULL, "{s:s s:s}", "cmd", &cmd, "jobs", &jobs_str) < 0) goto error; - if ( !(jobs = json_loads (jobs_str, 0, &err))) { + if (!(jobs = json_loads (jobs_str, 0, &err))) { errno = ENOMEM; goto error; } - json_array_foreach(jobs, index, value) { + json_array_foreach (jobs, index, value) { const char *js_str; int64_t at = 0; int64_t now = 0; @@ -1979,21 +2045,22 @@ static void match_multi_request_cb (flux_t *h, flux_msg_handler_t *w, std::string status = ""; std::stringstream R; - if (json_unpack (value, "{s:I s:s}", - "jobid", &jobid, - "jobspec", &js_str) < 0) + if (json_unpack (value, "{s:I s:s}", "jobid", &jobid, "jobspec", &js_str) < 0) goto error; if (is_existent_jobid (ctx, jobid)) { errno = EINVAL; - flux_log_error (h, "%s: existent job (%jd).", - __FUNCTION__, static_cast (jobid)); + flux_log_error (h, + "%s: existent job (%jd).", + __FUNCTION__, + static_cast (jobid)); goto error; } if (run_match (ctx, jobid, cmd, js_str, &now, &at, &overhead, R, NULL) < 0) { if (errno != EBUSY && errno != ENODEV) flux_log_error (ctx->h, - "%s: match failed due to match error (id=%jd)", - __FUNCTION__, static_cast (jobid)); + "%s: match failed due to match error (id=%jd)", + __FUNCTION__, + static_cast (jobid)); // The resources couldn't be allocated *or reserved* // Kicking back to qmanager, remove from tracking if (errno == EBUSY) { @@ -2003,12 +2070,20 @@ static void match_multi_request_cb (flux_t *h, flux_msg_handler_t *w, } status = get_status_string (now, at); - if (flux_respond_pack (h, msg, "{s:I s:s s:f s:s s:I}", - "jobid", jobid, - "status", status.c_str (), - "overhead", overhead, - "R", R.str ().c_str (), - "at", at) < 0) { + if (flux_respond_pack (h, + msg, + "{s:I s:s s:f s:s s:I}", + "jobid", + jobid, + "status", + status.c_str (), + "overhead", + overhead, + "R", + R.str ().c_str (), + "at", + at) + < 0) { flux_log_error (h, "%s", __FUNCTION__); goto error; } @@ -2023,13 +2098,11 @@ static void match_multi_request_cb (flux_t *h, flux_msg_handler_t *w, } if (jobid != 0) errmsg += "jobid=" + std::to_string (jobid); - if (flux_respond_error (h, msg, errno, - !errmsg.empty ()? errmsg.c_str () : nullptr) < 0) + if (flux_respond_error (h, msg, errno, !errmsg.empty () ? errmsg.c_str () : nullptr) < 0) flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); } -static void cancel_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void cancel_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { std::shared_ptr ctx = getctx ((flux_t *)arg); int64_t jobid = -1; @@ -2044,14 +2117,15 @@ static void cancel_request_cb (flux_t *h, flux_msg_handler_t *w, ctx->reservations.erase (jobid); else { errno = ENOENT; - flux_log (h, LOG_DEBUG, "%s: nonexistent job (id=%jd)", - __FUNCTION__, (intmax_t)jobid); + flux_log (h, LOG_DEBUG, "%s: nonexistent job (id=%jd)", __FUNCTION__, (intmax_t)jobid); goto error; } if (run_remove (ctx, jobid, R, false, full_removal) < 0) { - flux_log_error (h, "%s: remove fails due to match error (id=%jd)", - __FUNCTION__, (intmax_t)jobid); + flux_log_error (h, + "%s: remove fails due to match error (id=%jd)", + __FUNCTION__, + (intmax_t)jobid); goto error; } if (flux_respond_pack (h, msg, "{}") < 0) @@ -2064,37 +2138,41 @@ static void cancel_request_cb (flux_t *h, flux_msg_handler_t *w, flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); } -static void partial_cancel_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void partial_cancel_request_cb (flux_t *h, + flux_msg_handler_t *w, + const flux_msg_t *msg, + void *arg) { std::shared_ptr ctx = getctx ((flux_t *)arg); int64_t jobid = -1; char *R = NULL; - decltype(ctx->allocations)::iterator jobid_it; + decltype (ctx->allocations)::iterator jobid_it; bool full_removal = false; int int_full_removal = 0; - if (flux_request_unpack (msg, NULL, "{s:I s:s}", - "jobid", &jobid, - "R", &R) < 0) + if (flux_request_unpack (msg, NULL, "{s:I s:s}", "jobid", &jobid, "R", &R) < 0) goto error; jobid_it = ctx->allocations.find (jobid); if (jobid_it == ctx->allocations.end ()) { errno = ENOENT; - flux_log (h, LOG_DEBUG, "%s: job (id=%jd) not found in allocations", - __FUNCTION__, (intmax_t)jobid); + flux_log (h, + LOG_DEBUG, + "%s: job (id=%jd) not found in allocations", + __FUNCTION__, + (intmax_t)jobid); goto error; } if (run_remove (ctx, jobid, R, true, full_removal) < 0) { - flux_log_error (h, "%s: remove fails due to match error (id=%jd)", - __FUNCTION__, (intmax_t)jobid); + flux_log_error (h, + "%s: remove fails due to match error (id=%jd)", + __FUNCTION__, + (intmax_t)jobid); goto error; } int_full_removal = full_removal; - if (flux_respond_pack (h, msg, "{s:i}", - "full-removal", int_full_removal) < 0) + if (flux_respond_pack (h, msg, "{s:i}", "full-removal", int_full_removal) < 0) flux_log_error (h, "%s", __FUNCTION__); if (full_removal) @@ -2107,8 +2185,7 @@ static void partial_cancel_request_cb (flux_t *h, flux_msg_handler_t *w, flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); } -static void info_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void info_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { std::shared_ptr ctx = getctx ((flux_t *)arg); int64_t jobid = -1; @@ -2119,18 +2196,24 @@ static void info_request_cb (flux_t *h, flux_msg_handler_t *w, goto error; if (!is_existent_jobid (ctx, jobid)) { errno = ENOENT; - flux_log (h, LOG_DEBUG, "%s: nonexistent job (id=%jd)", - __FUNCTION__, (intmax_t)jobid); + flux_log (h, LOG_DEBUG, "%s: nonexistent job (id=%jd)", __FUNCTION__, (intmax_t)jobid); goto error; } info = ctx->jobs[jobid]; get_jobstate_str (info->state, status); - if (flux_respond_pack (h, msg, "{s:I s:s s:I s:f}", - "jobid", jobid, - "status", status.c_str (), - "at", info->scheduled_at, - "overhead", info->overhead) < 0) + if (flux_respond_pack (h, + msg, + "{s:I s:s s:I s:f}", + "jobid", + jobid, + "status", + status.c_str (), + "at", + info->scheduled_at, + "overhead", + info->overhead) + < 0) flux_log_error (h, "%s", __FUNCTION__); return; @@ -2140,7 +2223,7 @@ static void info_request_cb (flux_t *h, flux_msg_handler_t *w, flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); } -static int get_stat_by_rank (std::shared_ptr& ctx, json_t *o) +static int get_stat_by_rank (std::shared_ptr &ctx, json_t *o) { int rc = -1; int saved_errno = 0; @@ -2152,23 +2235,21 @@ static int get_stat_by_rank (std::shared_ptr& ctx, json_t *o) if (kv.first == -1) continue; if (s2r.find (kv.second.size ()) == s2r.end ()) { - if ( !(ids = idset_create (0, IDSET_FLAG_AUTOGROW))) + if (!(ids = idset_create (0, IDSET_FLAG_AUTOGROW))) goto done; s2r[kv.second.size ()] = ids; } - if ( (rc = idset_set (s2r[kv.second.size ()], - static_cast (kv.first))) < 0) + if ((rc = idset_set (s2r[kv.second.size ()], static_cast (kv.first))) < 0) goto done; } for (auto &kv : s2r) { - if ( !(str = idset_encode (kv.second, - IDSET_FLAG_BRACKETS | IDSET_FLAG_RANGE))) { + if (!(str = idset_encode (kv.second, IDSET_FLAG_BRACKETS | IDSET_FLAG_RANGE))) { rc = -1; goto done; } - if ( (rc = json_object_set_new (o, str, - json_integer (static_cast (kv.first)))) < 0) { + if ((rc = json_object_set_new (o, str, json_integer (static_cast (kv.first)))) + < 0) { errno = ENOMEM; goto done; } @@ -2188,8 +2269,7 @@ static int get_stat_by_rank (std::shared_ptr& ctx, json_t *o) return rc; } -static void stat_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void stat_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { std::shared_ptr ctx = getctx ((flux_t *)arg); int saved_errno; @@ -2211,18 +2291,16 @@ static void stat_request_cb (flux_t *h, flux_msg_handler_t *w, avg = perf.succeeded.avg; min = perf.succeeded.min; // Welford's online algorithm - variance = perf.succeeded.M2 - / (double)perf.succeeded.njobs_reset; + variance = perf.succeeded.M2 / (double)perf.succeeded.njobs_reset; } if (perf.failed.njobs_reset > 1) { avg_failed = perf.failed.avg; min_failed = perf.failed.min; // Welford's online algorithm - variance_failed = perf.failed.M2 - / (double)perf.failed.njobs_reset; + variance_failed = perf.failed.M2 / (double)perf.failed.njobs_reset; } - if ( !(o = json_object ()) || !(match_succeeded = json_object ()) - || !(match_failed = json_object ())) { + if (!(o = json_object ()) || !(match_succeeded = json_object ()) + || !(match_failed = json_object ())) { errno = ENOMEM; goto error; } @@ -2232,47 +2310,74 @@ static void stat_request_cb (flux_t *h, flux_msg_handler_t *w, } if (!(match_succeeded = json_pack ("{s:I s:I s:I s:I s:{s:f s:f s:f s:f}}", - "njobs", perf.succeeded.njobs, - "njobs-reset", perf.succeeded.njobs_reset, - "max-match-jobid", perf.succeeded.max_match_jobid, - "max-match-iters", perf.succeeded.match_iter_count, - "stats", - "min", min, - "max", perf.succeeded.max, - "avg", avg, - "variance", variance))) { + "njobs", + perf.succeeded.njobs, + "njobs-reset", + perf.succeeded.njobs_reset, + "max-match-jobid", + perf.succeeded.max_match_jobid, + "max-match-iters", + perf.succeeded.match_iter_count, + "stats", + "min", + min, + "max", + perf.succeeded.max, + "avg", + avg, + "variance", + variance))) { errno = ENOMEM; goto error_free; } if (!(match_failed = json_pack ("{s:I s:I s:I s:I s:{s:f s:f s:f s:f}}", - "njobs", perf.failed.njobs, - "njobs-reset", perf.failed.njobs_reset, - "max-match-jobid", perf.failed.max_match_jobid, - "max-match-iters", perf.failed.match_iter_count, - "stats", - "min", min_failed, - "max", perf.failed.max, - "avg", avg_failed, - "variance", variance_failed))) { + "njobs", + perf.failed.njobs, + "njobs-reset", + perf.failed.njobs_reset, + "max-match-jobid", + perf.failed.max_match_jobid, + "max-match-iters", + perf.failed.match_iter_count, + "stats", + "min", + min_failed, + "max", + perf.failed.max, + "avg", + avg_failed, + "variance", + variance_failed))) { errno = ENOMEM; goto error_free; } now = std::chrono::system_clock::now (); - graph_uptime_s = std::chrono::duration_cast ( - now - perf.graph_uptime).count (); - time_since_reset_s = std::chrono::duration_cast ( - now - perf.time_of_last_reset).count (); - - if (flux_respond_pack (h, msg, "{s:I s:I s:o s:f s:I s:I s:{s:O s:O}}", - "V", num_vertices (ctx->db->resource_graph), - "E", num_edges (ctx->db->resource_graph), - "by_rank", o, - "load-time", perf.load, - "graph-uptime", graph_uptime_s, - "time-since-reset", time_since_reset_s, - "match", - "succeeded", match_succeeded, - "failed", match_failed) < 0) { + graph_uptime_s = + std::chrono::duration_cast (now - perf.graph_uptime).count (); + time_since_reset_s = + std::chrono::duration_cast (now - perf.time_of_last_reset).count (); + + if (flux_respond_pack (h, + msg, + "{s:I s:I s:o s:f s:I s:I s:{s:O s:O}}", + "V", + num_vertices (ctx->db->resource_graph), + "E", + num_edges (ctx->db->resource_graph), + "by_rank", + o, + "load-time", + perf.load, + "graph-uptime", + graph_uptime_s, + "time-since-reset", + time_since_reset_s, + "match", + "succeeded", + match_succeeded, + "failed", + match_failed) + < 0) { flux_log_error (h, "%s: flux_respond_pack", __FUNCTION__); } json_decref (match_succeeded); @@ -2291,8 +2396,7 @@ static void stat_request_cb (flux_t *h, flux_msg_handler_t *w, flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); } -static void stat_clear_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void stat_clear_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { std::shared_ptr ctx = getctx ((flux_t *)arg); @@ -2318,8 +2422,7 @@ static void stat_clear_cb (flux_t *h, flux_msg_handler_t *w, flux_log_error (h, "%s: flux_respond", __FUNCTION__); } -static inline int64_t next_jobid (const std::map> &m) +static inline int64_t next_jobid (const std::map> &m) { int64_t jobid = -1; if (m.empty ()) @@ -2330,8 +2433,10 @@ static inline int64_t next_jobid (const std::map ctx = getctx ((flux_t *)arg); int64_t jobid = -1; @@ -2350,8 +2455,10 @@ static void next_jobid_request_cb (flux_t *h, flux_msg_handler_t *w, flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); } -static void set_property_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void set_property_request_cb (flux_t *h, + flux_msg_handler_t *w, + const flux_msg_t *msg, + void *arg) { const char *rp = NULL, *kv = NULL; std::string resource_path = "", keyval = ""; @@ -2362,9 +2469,7 @@ static void set_property_request_cb (flux_t *h, flux_msg_handler_t *w, std::pair::iterator, bool> ret; vtx_t v; - if (flux_request_unpack (msg, NULL, "{s:s s:s}", - "sp_resource_path", &rp, - "sp_keyval", &kv) < 0) + if (flux_request_unpack (msg, NULL, "{s:s s:s}", "sp_resource_path", &rp, "sp_keyval", &kv) < 0) goto error; resource_path = rp; @@ -2375,8 +2480,7 @@ static void set_property_request_cb (flux_t *h, flux_msg_handler_t *w, if (pos == 0 || (pos == keyval.size () - 1) || pos == std::string::npos) { errno = EINVAL; flux_log_error (h, "%s: Incorrect format.", __FUNCTION__); - flux_log_error (h, "%s: Use set-property PROPERTY=VALUE", - __FUNCTION__); + flux_log_error (h, "%s: Use set-property PROPERTY=VALUE", __FUNCTION__); goto error; } @@ -2387,21 +2491,21 @@ static void set_property_request_cb (flux_t *h, flux_msg_handler_t *w, if (it == ctx->db->metadata.by_path.end ()) { errno = ENOENT; - flux_log_error (h, "%s: Couldn't find %s in resource graph.", - __FUNCTION__, resource_path.c_str ()); + flux_log_error (h, + "%s: Couldn't find %s in resource graph.", + __FUNCTION__, + resource_path.c_str ()); goto error; - } + } for (auto &v : it->second) { ret = ctx->db->resource_graph[v].properties.insert ( - std::pair (property_key, - property_value)); + std::pair (property_key, property_value)); if (ret.second == false) { ctx->db->resource_graph[v].properties.erase (property_key); ctx->db->resource_graph[v].properties.insert ( - std::pair (property_key, - property_value)); + std::pair (property_key, property_value)); } } @@ -2415,8 +2519,10 @@ static void set_property_request_cb (flux_t *h, flux_msg_handler_t *w, flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); } -static void get_property_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void get_property_request_cb (flux_t *h, + flux_msg_handler_t *w, + const flux_msg_t *msg, + void *arg) { const char *rp = NULL, *gp_key = NULL; std::string resource_path = "", property_key = ""; @@ -2427,9 +2533,8 @@ static void get_property_request_cb (flux_t *h, flux_msg_handler_t *w, std::vector resp_values; json_t *resp_array = nullptr; - if (flux_request_unpack (msg, NULL, "{s:s s:s}", - "gp_resource_path", &rp, - "gp_key", &gp_key) < 0) + if (flux_request_unpack (msg, NULL, "{s:s s:s}", "gp_resource_path", &rp, "gp_key", &gp_key) + < 0) goto error; resource_path = rp; @@ -2439,55 +2544,61 @@ static void get_property_request_cb (flux_t *h, flux_msg_handler_t *w, if (it == ctx->db->metadata.by_path.end ()) { errno = ENOENT; - flux_log_error (h, "%s: Couldn't find %s in resource graph.", - __FUNCTION__, resource_path.c_str ()); + flux_log_error (h, + "%s: Couldn't find %s in resource graph.", + __FUNCTION__, + resource_path.c_str ()); goto error; - } + } - for (auto &v : it->second) { + for (auto &v : it->second) { for (p_it = ctx->db->resource_graph[v].properties.begin (); - p_it != ctx->db->resource_graph[v].properties.end (); p_it++) { - - if (property_key.compare (p_it->first) == 0) - resp_values.push_back (p_it->second); - } - } - if (resp_values.empty ()) { - errno = ENOENT; - flux_log_error (h, "%s: Property %s was not found for resource %s.", - __FUNCTION__, property_key.c_str (), - resource_path.c_str ()); - goto error; - } - - if ( !(resp_array = json_array ())) { - errno = ENOMEM; - goto error; - } - for (auto &resp_value : resp_values) { - json_t *value = nullptr; - if ( !(value = json_string (resp_value.c_str ()))) { - errno = EINVAL; - goto error; - } - if (json_array_append_new (resp_array, value) < 0) { - json_decref (value); - errno = EINVAL; - goto error; - } - } - if (flux_respond_pack (h, msg, "{s:o}", "values", resp_array) < 0) - flux_log_error (h, "%s", __FUNCTION__); - - return; + p_it != ctx->db->resource_graph[v].properties.end (); + p_it++) { + if (property_key.compare (p_it->first) == 0) + resp_values.push_back (p_it->second); + } + } + if (resp_values.empty ()) { + errno = ENOENT; + flux_log_error (h, + "%s: Property %s was not found for resource %s.", + __FUNCTION__, + property_key.c_str (), + resource_path.c_str ()); + goto error; + } + + if (!(resp_array = json_array ())) { + errno = ENOMEM; + goto error; + } + for (auto &resp_value : resp_values) { + json_t *value = nullptr; + if (!(value = json_string (resp_value.c_str ()))) { + errno = EINVAL; + goto error; + } + if (json_array_append_new (resp_array, value) < 0) { + json_decref (value); + errno = EINVAL; + goto error; + } + } + if (flux_respond_pack (h, msg, "{s:o}", "values", resp_array) < 0) + flux_log_error (h, "%s", __FUNCTION__); + + return; error: if (flux_respond_error (h, msg, errno, NULL) < 0) flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); } -static void disconnect_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void disconnect_request_cb (flux_t *h, + flux_msg_handler_t *w, + const flux_msg_t *msg, + void *arg) { const char *route; std::shared_ptr ctx = getctx ((flux_t *)arg); @@ -2502,8 +2613,7 @@ static void disconnect_request_cb (flux_t *h, flux_msg_handler_t *w, } } -static void notify_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void notify_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { try { const char *route; @@ -2526,8 +2636,7 @@ static void notify_request_cb (flux_t *h, flux_msg_handler_t *w, m->set_msg (msg); auto ret = ctx->notify_msgs.insert ( - std::pair> (route, m)); + std::pair> (route, m)); if (!ret.second) { errno = EEXIST; flux_log_error (h, "%s: insert", __FUNCTION__); @@ -2548,7 +2657,7 @@ static void notify_request_cb (flux_t *h, flux_msg_handler_t *w, flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); } -static int run_find (std::shared_ptr& ctx, +static int run_find (std::shared_ptr &ctx, const std::string &criteria, const std::string &format_str, json_t **R) @@ -2557,20 +2666,20 @@ static int run_find (std::shared_ptr& ctx, json_t *o = nullptr; std::shared_ptr w = nullptr; - match_format_t format = match_writers_factory_t:: - get_writers_type (format_str); - if ( !(w = match_writers_factory_t::create (format))) + match_format_t format = match_writers_factory_t::get_writers_type (format_str); + if (!(w = match_writers_factory_t::create (format))) goto error; - if ( (rc = ctx->traverser->find (w, criteria)) < 0) { + if ((rc = ctx->traverser->find (w, criteria)) < 0) { if (ctx->traverser->err_message () != "") { - flux_log_error (ctx->h, "%s: %s", + flux_log_error (ctx->h, + "%s: %s", __FUNCTION__, ctx->traverser->err_message ().c_str ()); ctx->traverser->clear_err_message (); } goto error; } - if ( (rc = w->emit_json (&o)) < 0) { + if ((rc = w->emit_json (&o)) < 0) { flux_log_error (ctx->h, "%s: emit", __FUNCTION__); goto error; } @@ -2581,8 +2690,7 @@ static int run_find (std::shared_ptr& ctx, return rc; } -static void find_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void find_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { json_t *R = nullptr; int saved_errno; @@ -2590,16 +2698,19 @@ static void find_request_cb (flux_t *h, flux_msg_handler_t *w, const char *format_str = "rv1_nosched"; std::shared_ptr ctx = getctx ((flux_t *)arg); - if (flux_request_unpack (msg, nullptr, - "{s:s, s?:s}", - "criteria", &criteria, - "format", &format_str) < 0) + if (flux_request_unpack (msg, + nullptr, + "{s:s, s?:s}", + "criteria", + &criteria, + "format", + &format_str) + < 0) goto error; if (run_find (ctx, criteria, format_str, &R) < 0) goto error; - if (flux_respond_pack (h, msg, "{s:o?}", - "R", R) < 0) { + if (flux_respond_pack (h, msg, "{s:o?}", "R", R) < 0) { flux_log_error (h, "%s: flux_respond_pack", __FUNCTION__); goto error; } @@ -2615,8 +2726,7 @@ static void find_request_cb (flux_t *h, flux_msg_handler_t *w, flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); } -static void status_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void status_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { int saved_errno; json_t *R_all = nullptr; @@ -2629,10 +2739,9 @@ static void status_request_cb (flux_t *h, flux_msg_handler_t *w, now = std::chrono::system_clock::now (); elapsed = now - ctx->m_resources_alloc_updated; // Get R alloc whenever m_resources_alloc_updated or - // the elapsed time is greater than configured limit - if ( (elapsed.count () > - static_cast (ctx->opts.get_opt ().get_update_interval ())) || - ctx->m_resources_updated) { + // the elapsed time is greater than configured limit + if ((elapsed.count () > static_cast (ctx->opts.get_opt ().get_update_interval ())) + || ctx->m_resources_updated) { if (run_find (ctx, "sched-now=allocated", "rv1_nosched", &R_alloc) < 0) goto error; ctx->m_r_alloc = json_deep_copy (R_alloc); @@ -2641,8 +2750,7 @@ static void status_request_cb (flux_t *h, flux_msg_handler_t *w, R_alloc = json_deep_copy (ctx->m_r_alloc); if (ctx->m_resources_updated) { - if (run_find (ctx, "status=up or status=down", "rv1_nosched", - &R_all) < 0) + if (run_find (ctx, "status=up or status=down", "rv1_nosched", &R_all) < 0) goto error; ctx->m_r_all = json_deep_copy (R_all); ctx->m_resources_updated = false; @@ -2657,10 +2765,16 @@ static void status_request_cb (flux_t *h, flux_msg_handler_t *w, } else R_down = json_deep_copy (ctx->m_r_down); - if (flux_respond_pack (h, msg, "{s:o? s:o? s:o?}", - "all", R_all, - "down", R_down, - "allocated", R_alloc) < 0) { + if (flux_respond_pack (h, + msg, + "{s:o? s:o? s:o?}", + "all", + R_all, + "down", + R_down, + "allocated", + R_alloc) + < 0) { flux_log_error (h, "%s: flux_respond_pack", __FUNCTION__); goto error; } @@ -2676,35 +2790,35 @@ static void status_request_cb (flux_t *h, flux_msg_handler_t *w, flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); } -static void ns_info_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void ns_info_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { uint64_t rank, id, remapped_id; const char *type_name; std::shared_ptr ctx = getctx ((flux_t *)arg); - if (flux_request_unpack (msg, nullptr, - "{s:I s:s s:I}", - "rank", &rank, - "type-name", &type_name, - "id", &id) < 0) { + if (flux_request_unpack (msg, + nullptr, + "{s:I s:s s:I}", + "rank", + &rank, + "type-name", + &type_name, + "id", + &id) + < 0) { flux_log_error (h, "%s: flux_respond_unpack", __FUNCTION__); goto error; } - if (ctx->reader->namespace_remapper.query (rank, type_name, - id, remapped_id) < 0) { + if (ctx->reader->namespace_remapper.query (rank, type_name, id, remapped_id) < 0) { flux_log_error (h, "%s: namespace_remapper.query", __FUNCTION__); goto error; } - if (remapped_id > - static_cast (std::numeric_limits::max ())) { + if (remapped_id > static_cast (std::numeric_limits::max ())) { errno = EOVERFLOW; flux_log_error (h, "%s: remapped id too large", __FUNCTION__); goto error; } - if (flux_respond_pack (h, msg, "{s:I}", - "id", static_cast ( - remapped_id)) < 0) { + if (flux_respond_pack (h, msg, "{s:I}", "id", static_cast (remapped_id)) < 0) { flux_log_error (h, "%s: flux_respond_pack", __FUNCTION__); goto error; } @@ -2715,8 +2829,10 @@ static void ns_info_request_cb (flux_t *h, flux_msg_handler_t *w, flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); } -static void satisfiability_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void satisfiability_request_cb (flux_t *h, + flux_msg_handler_t *w, + const flux_msg_t *msg, + void *arg) { int64_t at = 0; int64_t now = 0; @@ -2731,20 +2847,12 @@ static void satisfiability_request_cb (flux_t *h, flux_msg_handler_t *w, if (flux_request_unpack (msg, NULL, "{s:o}", "jobspec", &jobspec) < 0) goto error; - if ( !(js_str = json_dumps (jobspec, JSON_INDENT (0)))) { + if (!(js_str = json_dumps (jobspec, JSON_INDENT (0)))) { errno = ENOMEM; goto error; } error.text[0] = '\0'; - if (run_match (ctx, - -1, - "satisfiability", - js_str, - &now, - &at, - &overhead, - R, - &error) < 0) { + if (run_match (ctx, -1, "satisfiability", js_str, &now, &at, &overhead, R, &error) < 0) { if (errno == ENODEV) errmsg = "Unsatisfiable request"; else { @@ -2767,8 +2875,7 @@ static void satisfiability_request_cb (flux_t *h, flux_msg_handler_t *w, flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); } -static void params_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void params_request_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { int saved_errno; json_error_t jerr; @@ -2803,19 +2910,19 @@ static void params_request_cb (flux_t *h, flux_msg_handler_t *w, /* * Mark a vertex as up or down */ -static void set_status_request_cb (flux_t *h, flux_msg_handler_t *w, - const flux_msg_t *msg, void *arg) +static void set_status_request_cb (flux_t *h, + flux_msg_handler_t *w, + const flux_msg_t *msg, + void *arg) { const char *rp = NULL, *st = NULL; std::string resource_path = "", status = "", errmsg = ""; std::shared_ptr ctx = getctx ((flux_t *)arg); resource_pool_t::string_to_status sts = resource_pool_t::str_to_status; - std::map>::const_iterator it {}; - resource_pool_t::string_to_status::iterator status_it {}; + std::map>::const_iterator it{}; + resource_pool_t::string_to_status::iterator status_it{}; - if (flux_request_unpack (msg, NULL, "{s:s, s:s}", - "resource_path", &rp, - "status", &st) < 0){ + if (flux_request_unpack (msg, NULL, "{s:s, s:s}", "resource_path", &rp, "status", &st) < 0) { errmsg = "malformed RPC"; goto error; } @@ -2835,8 +2942,10 @@ static void set_status_request_cb (flux_t *h, flux_msg_handler_t *w, } // mark the vertex if (ctx->traverser->mark (resource_path, status_it->second) < 0) { - flux_log_error (h, "%s: traverser::mark: %s", __FUNCTION__, - ctx->traverser->err_message ().c_str ()); + flux_log_error (h, + "%s: traverser::mark: %s", + __FUNCTION__, + ctx->traverser->err_message ().c_str ()); ctx->traverser->clear_err_message (); errmsg = "Failed to set status of resource vertex"; goto error; @@ -2853,7 +2962,6 @@ static void set_status_request_cb (flux_t *h, flux_msg_handler_t *w, return; } - //////////////////////////////////////////////////////////////////////////////// // Module Main //////////////////////////////////////////////////////////////////////////////// @@ -2868,9 +2976,8 @@ extern "C" int mod_main (flux_t *h, int argc, char **argv) std::shared_ptr ctx = nullptr; uint32_t rank = 1; - if ( !(ctx = init_module (h, argc, argv))) { - flux_log (h, LOG_ERR, "%s: can't initialize resource module", - __FUNCTION__); + if (!(ctx = init_module (h, argc, argv))) { + flux_log (h, LOG_ERR, "%s: can't initialize resource module", __FUNCTION__); goto done; } // Because mod_main is always active, the following is safe. @@ -2880,32 +2987,25 @@ extern "C" int mod_main (flux_t *h, int argc, char **argv) /* Before beginning synchronous resource.acquire RPC, set module status * to 'running' to let flux module load return success. */ - if ( (rc = flux_module_set_running (ctx->h)) < 0) { - flux_log_error (ctx->h, "%s: flux_module_set_running", - __FUNCTION__); + if ((rc = flux_module_set_running (ctx->h)) < 0) { + flux_log_error (ctx->h, "%s: flux_module_set_running", __FUNCTION__); goto done; } - if ( (rc = init_resource_graph (ctx)) != 0) { - flux_log (h, LOG_ERR, - "%s: can't initialize resource graph database", - __FUNCTION__); + if ((rc = init_resource_graph (ctx)) != 0) { + flux_log (h, LOG_ERR, "%s: can't initialize resource graph database", __FUNCTION__); goto done; } - flux_log (h, LOG_DEBUG, "%s: resource graph database loaded", - __FUNCTION__); + flux_log (h, LOG_DEBUG, "%s: resource graph database loaded", __FUNCTION__); - if (( rc = flux_reactor_run (flux_get_reactor (h), 0)) < 0) { - flux_log (h, LOG_ERR, "%s: flux_reactor_run: %s", - __FUNCTION__, strerror (errno)); + if ((rc = flux_reactor_run (flux_get_reactor (h), 0)) < 0) { + flux_log (h, LOG_ERR, "%s: flux_reactor_run: %s", __FUNCTION__, strerror (errno)); goto done; } - } - catch (std::exception &e) { + } catch (std::exception &e) { errno = ENOSYS; flux_log (h, LOG_ERR, "%s: %s", __FUNCTION__, e.what ()); return -1; - } - catch (...) { + } catch (...) { errno = ENOSYS; flux_log (h, LOG_ERR, "%s: caught unknown exception", __FUNCTION__); return -1; diff --git a/resource/modules/resource_match_opts.cpp b/resource/modules/resource_match_opts.cpp index 9fa133cc8..9e6179ae8 100644 --- a/resource/modules/resource_match_opts.cpp +++ b/resource/modules/resource_match_opts.cpp @@ -23,8 +23,6 @@ using namespace Flux; using namespace Flux::resource_model; using namespace Flux::opts_manager; - - //////////////////////////////////////////////////////////////////////////////// // Public API for Resource Match Option Class //////////////////////////////////////////////////////////////////////////////// @@ -182,37 +180,26 @@ bool resource_prop_t::is_update_interval_set () const json_t *resource_prop_t::jsonify () const { return json_pack ("{ s:s? s:s? s:s? s:s? s:s? s:s? s:i s:s? s:i }", - "load-file", is_load_file_set () - ? get_load_file ().c_str () - : nullptr, - "load-format", is_load_format_set () - ? get_load_format ().c_str () - : nullptr, - "load-allowlist", is_load_allowlist_set () - ? get_load_allowlist ().c_str () - : nullptr, - "policy", is_match_policy_set () - ? get_match_policy ().c_str () - : nullptr, - "match-format", is_match_format_set () - ? get_match_format ().c_str () - : nullptr, - "subsystems", is_match_subsystems_set () - ? get_match_subsystems ().c_str () - : nullptr, - "reserve-vtx-vec", is_reserve_vtx_vec_set () - ? get_reserve_vtx_vec () - : 0, - "prune-filters", is_prune_filters_set () - ? get_prune_filters ().c_str () - : nullptr, - "update-interval", is_update_interval_set () - ? get_update_interval () - : 0); + "load-file", + is_load_file_set () ? get_load_file ().c_str () : nullptr, + "load-format", + is_load_format_set () ? get_load_format ().c_str () : nullptr, + "load-allowlist", + is_load_allowlist_set () ? get_load_allowlist ().c_str () : nullptr, + "policy", + is_match_policy_set () ? get_match_policy ().c_str () : nullptr, + "match-format", + is_match_format_set () ? get_match_format ().c_str () : nullptr, + "subsystems", + is_match_subsystems_set () ? get_match_subsystems ().c_str () : nullptr, + "reserve-vtx-vec", + is_reserve_vtx_vec_set () ? get_reserve_vtx_vec () : 0, + "prune-filters", + is_prune_filters_set () ? get_prune_filters ().c_str () : nullptr, + "update-interval", + is_update_interval_set () ? get_update_interval () : 0); } - - //////////////////////////////////////////////////////////////////////////////// // Private API for Resource Match Property Class //////////////////////////////////////////////////////////////////////////////// @@ -221,13 +208,12 @@ bool resource_opts_t::is_number (const std::string &num_str) { if (num_str.empty ()) return false; - auto i = std::find_if (num_str.begin (), num_str.end (), - [] (unsigned char c) { return !std::isdigit (c); }); + auto i = std::find_if (num_str.begin (), num_str.end (), [] (unsigned char c) { + return !std::isdigit (c); + }); return i == num_str.end (); } - - //////////////////////////////////////////////////////////////////////////////// // Public API for Resource Match Property Class //////////////////////////////////////////////////////////////////////////////// @@ -241,65 +227,56 @@ resource_opts_t::resource_opts_t () bool inserted = true; - auto ret = m_tab.insert (std::pair ( - "load-file", - static_cast (resource_opts_t - ::resource_opts_key_t - ::LOAD_FILE))); + auto ret = m_tab.insert ( + std::pair ("load-file", + static_cast ( + resource_opts_t ::resource_opts_key_t ::LOAD_FILE))); inserted &= ret.second; - ret = m_tab.insert (std::pair ( - "load-format", - static_cast (resource_opts_t - ::resource_opts_key_t - ::LOAD_FORMAT))); + ret = m_tab.insert ( + std::pair ("load-format", + static_cast ( + resource_opts_t ::resource_opts_key_t ::LOAD_FORMAT))); inserted &= ret.second; - ret = m_tab.insert (std::pair ( - "load-allowlist", - static_cast (resource_opts_t - ::resource_opts_key_t - ::LOAD_ALLOWLIST))); + ret = m_tab.insert ( + std::pair ("load-allowlist", + static_cast ( + resource_opts_t ::resource_opts_key_t ::LOAD_ALLOWLIST))); inserted &= ret.second; - ret = m_tab.insert (std::pair ( - "policy", - static_cast (resource_opts_t - ::resource_opts_key_t - ::MATCH_POLICY))); + ret = m_tab.insert ( + std::pair ("policy", + static_cast ( + resource_opts_t ::resource_opts_key_t ::MATCH_POLICY))); inserted &= ret.second; - ret = m_tab.insert (std::pair ( - "match-policy", - static_cast (resource_opts_t - ::resource_opts_key_t - ::MATCH_POLICY))); + ret = m_tab.insert ( + std::pair ("match-policy", + static_cast ( + resource_opts_t ::resource_opts_key_t ::MATCH_POLICY))); inserted &= ret.second; - ret = m_tab.insert (std::pair ( - "match-format", - static_cast (resource_opts_t - ::resource_opts_key_t - ::MATCH_FORMAT))); + ret = m_tab.insert ( + std::pair ("match-format", + static_cast ( + resource_opts_t ::resource_opts_key_t ::MATCH_FORMAT))); inserted &= ret.second; - ret = m_tab.insert (std::pair ( - "subsystems", - static_cast (resource_opts_t - ::resource_opts_key_t - ::MATCH_SUBSYSTEMS))); + ret = m_tab.insert ( + std::pair ("subsystems", + static_cast ( + resource_opts_t ::resource_opts_key_t ::MATCH_SUBSYSTEMS))); inserted &= ret.second; - ret= m_tab.insert (std::pair ( - "reserve-vtx-vec", - static_cast (resource_opts_t - ::resource_opts_key_t - ::RESERVE_VTX_VEC))); + ret = m_tab.insert ( + std::pair ("reserve-vtx-vec", + static_cast ( + resource_opts_t ::resource_opts_key_t ::RESERVE_VTX_VEC))); inserted &= ret.second; - ret= m_tab.insert (std::pair ( - "prune-filters", - static_cast (resource_opts_t - ::resource_opts_key_t - ::PRUNE_FILTERS))); + ret = m_tab.insert ( + std::pair ("prune-filters", + static_cast ( + resource_opts_t ::resource_opts_key_t ::PRUNE_FILTERS))); inserted &= ret.second; - ret= m_tab.insert (std::pair ( - "update-interval", - static_cast (resource_opts_t - ::resource_opts_key_t - ::UPDATE_INTERVAL))); + ret = m_tab.insert ( + std::pair ("update-interval", + static_cast ( + resource_opts_t ::resource_opts_key_t ::UPDATE_INTERVAL))); inserted &= ret.second; if (!inserted) @@ -454,40 +431,29 @@ resource_opts_t &resource_opts_t::canonicalize () resource_opts_t &resource_opts_t::operator+= (const resource_opts_t &src) { if (src.m_resource_prop.is_load_file_set ()) - m_resource_prop.set_load_file ( - src.m_resource_prop.get_load_file ()); + m_resource_prop.set_load_file (src.m_resource_prop.get_load_file ()); if (src.m_resource_prop.is_load_format_set ()) - m_resource_prop.set_load_format ( - src.m_resource_prop.get_load_format ()); + m_resource_prop.set_load_format (src.m_resource_prop.get_load_format ()); if (src.m_resource_prop.is_load_allowlist_set ()) - m_resource_prop.set_load_allowlist ( - src.m_resource_prop.get_load_allowlist ()); + m_resource_prop.set_load_allowlist (src.m_resource_prop.get_load_allowlist ()); if (src.m_resource_prop.is_match_policy_set ()) - m_resource_prop.set_match_policy ( - src.m_resource_prop.get_match_policy ()); + m_resource_prop.set_match_policy (src.m_resource_prop.get_match_policy ()); if (src.m_resource_prop.is_match_format_set ()) - m_resource_prop.set_match_format ( - src.m_resource_prop.get_match_format ()); + m_resource_prop.set_match_format (src.m_resource_prop.get_match_format ()); if (src.m_resource_prop.is_match_subsystems_set ()) - m_resource_prop.set_match_subsystems ( - src.m_resource_prop.get_match_subsystems ()); + m_resource_prop.set_match_subsystems (src.m_resource_prop.get_match_subsystems ()); if (src.m_resource_prop.is_reserve_vtx_vec_set ()) - m_resource_prop.set_reserve_vtx_vec ( - src.m_resource_prop.get_reserve_vtx_vec ()); + m_resource_prop.set_reserve_vtx_vec (src.m_resource_prop.get_reserve_vtx_vec ()); if (src.m_resource_prop.is_prune_filters_set ()) - m_resource_prop.set_prune_filters ( - src.m_resource_prop.get_prune_filters ()); + m_resource_prop.set_prune_filters (src.m_resource_prop.get_prune_filters ()); if (src.m_resource_prop.is_update_interval_set ()) - m_resource_prop.set_update_interval ( - src.m_resource_prop.get_update_interval ()); + m_resource_prop.set_update_interval (src.m_resource_prop.get_update_interval ()); return *this; } -bool resource_opts_t::operator ()(const std::string &k1, - const std::string &k2) const +bool resource_opts_t::operator() (const std::string &k1, const std::string &k2) const { - if (m_tab.find (k1) == m_tab.end () - || m_tab.find (k2) == m_tab.end ()) + if (m_tab.find (k1) == m_tab.end () || m_tab.find (k2) == m_tab.end ()) return k1 < k2; return m_tab.at (k1) < m_tab.at (k2); } @@ -519,8 +485,7 @@ int resource_opts_t::jsonify (std::string &json_out) const return rc; } -int resource_opts_t::parse (const std::string &k, - const std::string &v, std::string &info) +int resource_opts_t::parse (const std::string &k, const std::string &v, std::string &info) { int rc = 0; std::string dflt; @@ -531,71 +496,71 @@ int resource_opts_t::parse (const std::string &k, key = m_tab[k]; switch (key) { - case static_cast (resource_opts_key_t::LOAD_FILE): - m_resource_prop.set_load_file (v); - break; - - case static_cast (resource_opts_key_t::LOAD_FORMAT): - if (!m_resource_prop.set_load_format (v)) { - info += "Unknown resource reader (" + v + ")! "; - info += "Using default."; - } - break; - - case static_cast (resource_opts_key_t::LOAD_ALLOWLIST): - m_resource_prop.set_load_allowlist (v); - break; - - case static_cast (resource_opts_key_t::MATCH_POLICY): - if (!m_resource_prop.set_match_policy (v)) { - info += "Unknown match policy (" + v + ")! "; - info += "Using default."; - } - break; - - case static_cast (resource_opts_key_t::MATCH_FORMAT): - if (!m_resource_prop.set_match_format (v)) { - info += "Unknown match format (" + v + ")! "; - info += "Using default."; - } - break; - - case static_cast (resource_opts_key_t::MATCH_SUBSYSTEMS): - m_resource_prop.set_match_subsystems (v); - break; - - case static_cast (resource_opts_key_t::RESERVE_VTX_VEC): - if (is_number (v)) { - int s = std::stoi (v); - if ( !(s <= 0 || s > 2000000)) { - m_resource_prop.set_reserve_vtx_vec (s); + case static_cast (resource_opts_key_t::LOAD_FILE): + m_resource_prop.set_load_file (v); + break; + + case static_cast (resource_opts_key_t::LOAD_FORMAT): + if (!m_resource_prop.set_load_format (v)) { + info += "Unknown resource reader (" + v + ")! "; + info += "Using default."; + } + break; + + case static_cast (resource_opts_key_t::LOAD_ALLOWLIST): + m_resource_prop.set_load_allowlist (v); + break; + + case static_cast (resource_opts_key_t::MATCH_POLICY): + if (!m_resource_prop.set_match_policy (v)) { + info += "Unknown match policy (" + v + ")! "; + info += "Using default."; + } + break; + + case static_cast (resource_opts_key_t::MATCH_FORMAT): + if (!m_resource_prop.set_match_format (v)) { + info += "Unknown match format (" + v + ")! "; + info += "Using default."; } - } - break; - - case static_cast (resource_opts_key_t::PRUNE_FILTERS): - if (v.find_first_not_of(' ') != std::string::npos) { - if (m_resource_prop.is_prune_filters_set ()) - m_resource_prop.add_to_prune_filters (v); - else - m_resource_prop.set_prune_filters (v); - } - break; - - case static_cast (resource_opts_key_t::UPDATE_INTERVAL): - if (is_number (v)) { - int s = std::stoi (v); - if ( !(s <= 0 || s > 2000000)) { - m_resource_prop.set_update_interval (s); + break; + + case static_cast (resource_opts_key_t::MATCH_SUBSYSTEMS): + m_resource_prop.set_match_subsystems (v); + break; + + case static_cast (resource_opts_key_t::RESERVE_VTX_VEC): + if (is_number (v)) { + int s = std::stoi (v); + if (!(s <= 0 || s > 2000000)) { + m_resource_prop.set_reserve_vtx_vec (s); + } } - } - break; - - default: - info += "Unknown option (" + k + ")."; - errno = EINVAL; - rc = -1; - break; + break; + + case static_cast (resource_opts_key_t::PRUNE_FILTERS): + if (v.find_first_not_of (' ') != std::string::npos) { + if (m_resource_prop.is_prune_filters_set ()) + m_resource_prop.add_to_prune_filters (v); + else + m_resource_prop.set_prune_filters (v); + } + break; + + case static_cast (resource_opts_key_t::UPDATE_INTERVAL): + if (is_number (v)) { + int s = std::stoi (v); + if (!(s <= 0 || s > 2000000)) { + m_resource_prop.set_update_interval (s); + } + } + break; + + default: + info += "Unknown option (" + k + ")."; + errno = EINVAL; + rc = -1; + break; } return rc; diff --git a/resource/modules/resource_match_opts.hpp b/resource/modules/resource_match_opts.hpp index 63d5ddb49..002d2b3bf 100644 --- a/resource/modules/resource_match_opts.hpp +++ b/resource/modules/resource_match_opts.hpp @@ -25,7 +25,7 @@ namespace opts_manager { const std::string RESOURCE_OPTS_UNSET_STR = "0xdeadbeef"; class resource_prop_t { -public: + public: const std::string &get_load_file () const; const std::string &get_load_format () const; const std::string &get_load_allowlist () const; @@ -60,7 +60,7 @@ class resource_prop_t { json_t *jsonify () const; -private: + private: std::string m_load_file = RESOURCE_OPTS_UNSET_STR; std::string m_load_format = RESOURCE_OPTS_UNSET_STR; std::string m_load_allowlist = RESOURCE_OPTS_UNSET_STR; @@ -72,22 +72,21 @@ class resource_prop_t { int m_update_interval = 0; }; - /*! resource match option set class */ class resource_opts_t : public optmgr_parse_t { -public: + public: enum class resource_opts_key_t : int { - LOAD_FILE = 1, - LOAD_FORMAT = 10, - LOAD_ALLOWLIST = 20, - MATCH_POLICY = 30, // policy - MATCH_FORMAT = 40, // match-format - MATCH_SUBSYSTEMS = 50, // subsystem - RESERVE_VTX_VEC = 60, // reserve-vtx-vec - PRUNE_FILTERS = 70, // prune-filter - UPDATE_INTERVAL = 80, // update-interval - UNKNOWN = 5000 + LOAD_FILE = 1, + LOAD_FORMAT = 10, + LOAD_ALLOWLIST = 20, + MATCH_POLICY = 30, // policy + MATCH_FORMAT = 40, // match-format + MATCH_SUBSYSTEMS = 50, // subsystem + RESERVE_VTX_VEC = 60, // reserve-vtx-vec + PRUNE_FILTERS = 70, // prune-filter + UPDATE_INTERVAL = 80, // update-interval + UNKNOWN = 5000 }; // These constructors can throw std::bad_alloc exception @@ -151,7 +150,7 @@ class resource_opts_t : public optmgr_parse_t { * \param k2 comparing key * \return true if k1 should precede k2 during iteration. */ - bool operator ()(const std::string &k1, const std::string &k2) const; + bool operator() (const std::string &k1, const std::string &k2) const; /*! Parse the value string (v) according to the key string (k). * The parsed results are stored in "this" object. @@ -170,7 +169,7 @@ class resource_opts_t : public optmgr_parse_t { */ int jsonify (std::string &json_out) const; -private: + private: bool is_number (const std::string &num_str); // default queue properties @@ -180,10 +179,10 @@ class resource_opts_t : public optmgr_parse_t { std::map m_tab; }; -} // namespace opts_manager -} // namespace Flux +} // namespace opts_manager +} // namespace Flux -#endif // RESOURCE_MATCH_OPTS_HPP +#endif // RESOURCE_MATCH_OPTS_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/planner/c++/mintime_resource_tree.cpp b/resource/planner/c++/mintime_resource_tree.cpp index becfef7ec..717225aab 100644 --- a/resource/planner/c++/mintime_resource_tree.cpp +++ b/resource/planner/c++/mintime_resource_tree.cpp @@ -19,8 +19,6 @@ extern "C" { #include "planner_internal_tree.hpp" - - //////////////////////////////////////////////////////////////////////////////// // Private Mintime Resource Tree Methods //////////////////////////////////////////////////////////////////////////////// @@ -31,11 +29,11 @@ int64_t mintime_resource_tree_t::right_branch_mintime (mt_resource_rb_node_t *n) mt_resource_rb_node_t *right = n->get_right (); if (right) min_time = right->subtree_min; - return (n->at < min_time)? n->at : min_time; + return (n->at < min_time) ? n->at : min_time; } -scheduled_point_t *mintime_resource_tree_t::find_mintime_point ( - mt_resource_rb_node_t *anchor, int64_t min_time) const +scheduled_point_t *mintime_resource_tree_t::find_mintime_point (mt_resource_rb_node_t *anchor, + int64_t min_time) const { if (!anchor) return nullptr; @@ -47,8 +45,7 @@ scheduled_point_t *mintime_resource_tree_t::find_mintime_point ( while (node) { if (node->at == min_time) return node->get_point (); - if (node->get_left () - && (node->get_left ()->subtree_min == min_time)) + if (node->get_left () && (node->get_left ()->subtree_min == min_time)) node = node->get_left (); else node = node->get_right (); @@ -60,8 +57,8 @@ scheduled_point_t *mintime_resource_tree_t::find_mintime_point ( return nullptr; } -int64_t mintime_resource_tree_t::find_mintime_anchor ( - int64_t request, mt_resource_rb_node_t **anchor_p) const +int64_t mintime_resource_tree_t::find_mintime_anchor (int64_t request, + mt_resource_rb_node_t **anchor_p) const { mt_resource_rb_node_t *node = m_tree.get_root (); int64_t min_time = std::numeric_limits::max (); @@ -89,15 +86,12 @@ int64_t mintime_resource_tree_t::find_mintime_anchor ( return min_time; } - - //////////////////////////////////////////////////////////////////////////////// // Private Mintime Resource RBTree Node Methods //////////////////////////////////////////////////////////////////////////////// -template -void mt_resource_node_traits::fix ( - mt_resource_rb_node_t *node) +template +void mt_resource_node_traits::fix (mt_resource_rb_node_t *node) { mt_resource_rb_node_t *trav = node; while (trav) { @@ -114,79 +108,81 @@ void mt_resource_node_traits::fix ( trav->subtree_min = right->subtree_min; } // no parent propagation is needed if new subtree_min == old, - if (trav->subtree_min == old) + if (trav->subtree_min == old) break; mt_resource_rb_node_t *parent = trav->get_parent (); // if parent's subtree_min is already smaller than - // new subtree_min, no parent propagation is necessary. - // However, if parent's subtree_min == old, propagation is - // needed, as it could (or in fact is likely to) - // come from the traversing child node and thus needs an update. - if (parent && parent->subtree_min != old - && parent->subtree_min < trav->subtree_min) + // new subtree_min, no parent propagation is necessary. + // However, if parent's subtree_min == old, propagation is + // needed, as it could (or in fact is likely to) + // come from the traversing child node and thus needs an update. + if (parent && parent->subtree_min != old && parent->subtree_min < trav->subtree_min) break; trav = parent; } } - - //////////////////////////////////////////////////////////////////////////////// // Public Mintime Resource RBTree Node Methods //////////////////////////////////////////////////////////////////////////////// -template -template +template +template void mt_resource_node_traits::leaf_inserted ( - mt_resource_rb_node_t &node, BaseTree &tree) + mt_resource_rb_node_t &node, + BaseTree &tree) { node.subtree_min = node.at; mt_resource_rb_node_t *n = &node; - while ( (n = n->get_parent ()) != nullptr - && n->subtree_min > node.subtree_min) + while ((n = n->get_parent ()) != nullptr && n->subtree_min > node.subtree_min) n->subtree_min = node.subtree_min; } -template -template +template +template void mt_resource_node_traits::rotated_left ( - mt_resource_rb_node_t &node, BaseTree &tree) + mt_resource_rb_node_t &node, + BaseTree &tree) { fix (&node); if (node.get_parent ()) - fix (node.get_parent ()); + fix (node.get_parent ()); } -template -template +template +template void mt_resource_node_traits::rotated_right ( - mt_resource_rb_node_t &node, BaseTree &tree) + mt_resource_rb_node_t &node, + BaseTree &tree) { fix (&node); if (node.get_parent ()) - fix (node.get_parent ()); + fix (node.get_parent ()); } -template -template +template +template void mt_resource_node_traits::deleted_below ( - mt_resource_rb_node_t &node, BaseTree &tree) + mt_resource_rb_node_t &node, + BaseTree &tree) { fix (&node); } -template -template +template +template void mt_resource_node_traits::swapped ( - mt_resource_rb_node_t &node1, mt_resource_rb_node_t &node2, BaseTree &t) + mt_resource_rb_node_t &node1, + mt_resource_rb_node_t &node2, + BaseTree &t) { fix (&node1); if (node1.get_parent ()) - fix (node1.get_parent ()); + fix (node1.get_parent ()); fix (&node2); if (node2.get_parent ()) - fix (node2.get_parent ()); + fix (node2.get_parent ()); } bool operator< (const mt_resource_rb_node_t &lhs, const int64_t rhs) @@ -211,12 +207,9 @@ bool mt_resource_rb_node_t::operator== (const mt_resource_rb_node_t &other) cons bool mt_resource_rb_node_t::operator!= (const mt_resource_rb_node_t &other) const { - return !operator == (other); + return !operator== (other); } - - - //////////////////////////////////////////////////////////////////////////////// // Public Minimum Time Resource Tree API //////////////////////////////////////////////////////////////////////////////// diff --git a/resource/planner/c++/mintime_resource_tree.hpp b/resource/planner/c++/mintime_resource_tree.hpp index e98521250..eb7b857a2 100644 --- a/resource/planner/c++/mintime_resource_tree.hpp +++ b/resource/planner/c++/mintime_resource_tree.hpp @@ -17,9 +17,8 @@ struct scheduled_point_t; class rb_node_base_t; -struct mt_resource_rb_node_t - : public rb_node_base_t, - public ygg::RBTreeNodeBase { +struct mt_resource_rb_node_t : public rb_node_base_t, + public ygg::RBTreeNodeBase { int64_t at; int64_t subtree_min; int64_t remaining; @@ -28,53 +27,48 @@ struct mt_resource_rb_node_t bool operator!= (const mt_resource_rb_node_t &other) const; }; -template +template class mt_resource_node_traits : public NodeTraits { -public: - template + public: + template static void leaf_inserted (mt_resource_rb_node_t &node, BaseTree &t); - template + template static void rotated_left (mt_resource_rb_node_t &node, BaseTree &t); - template + template static void rotated_right (mt_resource_rb_node_t &node, BaseTree &t); - template + template static void deleted_below (mt_resource_rb_node_t &node, BaseTree &t); - template - static void swapped (mt_resource_rb_node_t &n1, - mt_resource_rb_node_t &n2, BaseTree &t); + template + static void swapped (mt_resource_rb_node_t &n1, mt_resource_rb_node_t &n2, BaseTree &t); -private: + private: static void fix (mt_resource_rb_node_t *node); }; -using mt_resource_rb_tree_t = ygg::RBTree>; - +using mt_resource_rb_tree_t = + ygg::RBTree>; class mintime_resource_tree_t { -public: + public: int insert (scheduled_point_t *point); int remove (scheduled_point_t *point); scheduled_point_t *get_mintime (int64_t request) const; void clear (); -private: + private: int64_t right_branch_mintime (mt_resource_rb_node_t *n) const; - scheduled_point_t *find_mintime_point (mt_resource_rb_node_t *anchor, - int64_t min_time) const; - int64_t find_mintime_anchor (int64_t request, - mt_resource_rb_node_t **anchor_p) const; + scheduled_point_t *find_mintime_point (mt_resource_rb_node_t *anchor, int64_t min_time) const; + int64_t find_mintime_anchor (int64_t request, mt_resource_rb_node_t **anchor_p) const; mt_resource_rb_tree_t m_tree; }; -#endif // MINTIME_RESOURCE_TREE_HPP +#endif // MINTIME_RESOURCE_TREE_HPP /* * vi: ts=4 sw=4 expandtab diff --git a/resource/planner/c++/planner.cpp b/resource/planner/c++/planner.cpp index 37e59c7ed..3fffe35ee 100644 --- a/resource/planner/c++/planner.cpp +++ b/resource/planner/c++/planner.cpp @@ -20,8 +20,6 @@ extern "C" { #include "planner.hpp" - - //////////////////////////////////////////////////////////////////////////////// // Public Span_t Methods //////////////////////////////////////////////////////////////////////////////// @@ -48,18 +46,19 @@ bool span_t::operator== (const span_t &o) const bool span_t::operator!= (const span_t &o) const { - return !operator == (o); + return !operator== (o); } - //////////////////////////////////////////////////////////////////////////////// // Public Planner Methods //////////////////////////////////////////////////////////////////////////////// planner::planner () = default; -planner::planner (const int64_t base_time, const uint64_t duration, - const uint64_t resource_totals, const char *in_resource_type) +planner::planner (const int64_t base_time, + const uint64_t duration, + const uint64_t resource_totals, + const char *in_resource_type) { m_total_resources = static_cast (resource_totals); m_resource_type = in_resource_type; @@ -83,10 +82,10 @@ planner::planner (const planner &o) // Important: need to copy trees first, // since map copies fetch the scheduled // points inserted into the trees. - if ( (rc = copy_trees (o)) < 0) { + if ((rc = copy_trees (o)) < 0) { throw std::runtime_error ("ERROR copying trees\n"); } - if ( (rc = copy_maps (o)) < 0) { + if ((rc = copy_maps (o)) < 0) { throw std::runtime_error ("ERROR copying maps\n"); } @@ -105,16 +104,16 @@ planner &planner::operator= (const planner &o) { int rc = -1; - if ( (rc = erase ()) != 0) { - throw std::runtime_error ("ERROR erasing *this\n"); + if ((rc = erase ()) != 0) { + throw std::runtime_error ("ERROR erasing *this\n"); } // Important: need to copy trees first, // since map copies fetch the scheduled // points inserted into the trees. - if ( (rc = copy_trees (o)) != 0) { + if ((rc = copy_trees (o)) != 0) { throw std::runtime_error ("ERROR copying trees to *this\n"); } - if ( (rc = copy_maps (o)) != 0) { + if ((rc = copy_maps (o)) != 0) { throw std::runtime_error ("ERROR copying maps to *this\n"); } @@ -151,7 +150,7 @@ bool planner::operator== (const planner &o) const return false; } else if (m_p0 || o.m_p0) { return false; - } // else both nullptr + } // else both nullptr if (!span_lookups_equal (o)) return false; if (!avail_time_iters_equal (o)) @@ -163,13 +162,13 @@ bool planner::operator== (const planner &o) const bool planner::operator!= (const planner &o) const { - return !operator == (o); + return !operator== (o); } planner::~planner () { // Destructor is nothrow - // The destroy function called in the + // The destroy function called in the // scheduled point tree deletes all scheduled // points (including m_p0) // inserted in the class ctor @@ -237,9 +236,9 @@ int planner::update_total (uint64_t resource_total) m_total_resources = static_cast (resource_total); point = m_sched_point_tree.get_state (m_plan_start); while (point) { - // Prevent remaining from taking negative values. This should + // Prevent remaining from taking negative values. This should // reduce likelihood of errors when adding and removing spans. - // If the performance penalty is non-negligible we can + // If the performance penalty is non-negligible we can // investigate letting remaining take negative values. tmp = point->remaining + delta; if (tmp >= 0) @@ -321,14 +320,12 @@ void planner::clear_span_lookup () m_span_lookup.clear (); } -void planner::span_lookup_erase (std::map>::iterator &it) +void planner::span_lookup_erase (std::map>::iterator &it) { m_span_lookup.erase (it); } -const std::map> - &planner::get_span_lookup_const () const +const std::map> &planner::get_span_lookup_const () const { return m_span_lookup; } @@ -343,21 +340,17 @@ size_t planner::span_lookup_get_size () const return m_span_lookup.size (); } -void planner::span_lookup_insert (int64_t span_id, - std::shared_ptr span) +void planner::span_lookup_insert (int64_t span_id, std::shared_ptr span) { - m_span_lookup.insert (std::pair> (span_id, - span)); + m_span_lookup.insert (std::pair> (span_id, span)); } -void planner::set_span_lookup_iter (std::map>::iterator &it) +void planner::set_span_lookup_iter (std::map>::iterator &it) { m_span_lookup_iter = it; } -const std::map>::iterator - planner::get_span_lookup_iter () const +const std::map>::iterator planner::get_span_lookup_iter () const { return m_span_lookup_iter; } @@ -372,8 +365,7 @@ std::map &planner::get_avail_time_iter () return m_avail_time_iter; } -const std::map - &planner::get_avail_time_iter_const () const +const std::map &planner::get_avail_time_iter_const () const { return m_avail_time_iter; } @@ -407,13 +399,12 @@ void planner::incr_span_counter () { m_span_counter++; } - + const uint64_t planner::get_span_counter () const { return m_span_counter; } - //////////////////////////////////////////////////////////////////////////////// // Private Planner Methods //////////////////////////////////////////////////////////////////////////////// @@ -436,9 +427,9 @@ int planner::copy_trees (const planner &o) new_point->ref_count = point->ref_count; new_point->scheduled = point->scheduled; new_point->remaining = point->remaining; - if ( (rc = m_sched_point_tree.insert (new_point)) != 0) + if ((rc = m_sched_point_tree.insert (new_point)) != 0) return rc; - if ( (rc = m_mt_resource_tree.insert (new_point)) != 0) + if ((rc = m_mt_resource_tree.insert (new_point)) != 0) return rc; point = o.m_sched_point_tree.next (point); } @@ -474,8 +465,7 @@ int planner::copy_maps (const planner &o) for (auto const &avail_it : o.m_avail_time_iter) { // Scheduled point already copied into trees, so fetch // from SP tree. - scheduled_point_t *new_avail = - m_sched_point_tree.get_state (avail_it.second->at); + scheduled_point_t *new_avail = m_sched_point_tree.get_state (avail_it.second->at); m_avail_time_iter[avail_it.first] = new_avail; } } else { @@ -535,10 +525,8 @@ bool planner::trees_equal (const planner &o) const if (m_sched_point_tree.get_size () != o.m_sched_point_tree.get_size ()) return false; if (!m_sched_point_tree.empty ()) { - scheduled_point_t *this_pt = - m_sched_point_tree.get_state (m_plan_start); - scheduled_point_t *o_pt = - o.m_sched_point_tree.get_state (o.m_plan_start); + scheduled_point_t *this_pt = m_sched_point_tree.get_state (m_plan_start); + scheduled_point_t *o_pt = o.m_sched_point_tree.get_state (o.m_plan_start); while (this_pt) { if (*this_pt != *o_pt) return false; @@ -549,7 +537,6 @@ bool planner::trees_equal (const planner &o) const return true; } - //////////////////////////////////////////////////////////////////////////////// // Public Planner_t methods //////////////////////////////////////////////////////////////////////////////// @@ -572,13 +559,13 @@ planner_t::planner_t (const planner &o) } } -planner_t::planner_t (const int64_t base_time, const uint64_t duration, +planner_t::planner_t (const int64_t base_time, + const uint64_t duration, const uint64_t resource_totals, const char *in_resource_type) { try { - plan = new planner (base_time, duration, resource_totals, - in_resource_type); + plan = new planner (base_time, duration, resource_totals, in_resource_type); } catch (std::bad_alloc &e) { errno = ENOMEM; } diff --git a/resource/planner/c++/planner.hpp b/resource/planner/c++/planner.hpp index 6d3fceb94..1312541cd 100644 --- a/resource/planner/c++/planner.hpp +++ b/resource/planner/c++/planner.hpp @@ -26,22 +26,24 @@ struct span_t { bool operator== (const span_t &o) const; bool operator!= (const span_t &o) const; - int64_t start; /* start time of the span */ - int64_t last; /* end time of the span */ - int64_t span_id; /* unique span id */ - int64_t planned; /* required resource quantity */ - int in_system; /* 1 when inserted into the system */ - scheduled_point_t *start_p; /* scheduled point object at start */ - scheduled_point_t *last_p; /* scheduled point object at last */ + int64_t start; /* start time of the span */ + int64_t last; /* end time of the span */ + int64_t span_id; /* unique span id */ + int64_t planned; /* required resource quantity */ + int in_system; /* 1 when inserted into the system */ + scheduled_point_t *start_p; /* scheduled point object at start */ + scheduled_point_t *last_p; /* scheduled point object at last */ }; /*! Planner class */ class planner { -public: + public: planner (); - planner (const int64_t base_time, const uint64_t duration, - const uint64_t resource_totals, const char *in_resource_type); + planner (const int64_t base_time, + const uint64_t duration, + const uint64_t resource_totals, + const char *in_resource_type); planner (const planner &o); planner &operator= (const planner &o); bool operator== (const planner &o) const; @@ -52,7 +54,7 @@ class planner { int reinitialize (int64_t base_time, uint64_t duration); int restore_track_points (); int update_total (uint64_t resource_total); - + // Resources and duration int64_t get_total_resources () const; const std::string &get_resource_type () const; @@ -70,22 +72,17 @@ class planner { scheduled_point_t *mt_tree_get_mintime (int64_t request) const; // Span lookup functions void clear_span_lookup (); - void span_lookup_erase (std::map>::iterator &it); - const std::map> - &get_span_lookup_const () const; + void span_lookup_erase (std::map>::iterator &it); + const std::map> &get_span_lookup_const () const; std::map> &get_span_lookup (); size_t span_lookup_get_size () const; void span_lookup_insert (int64_t span_id, std::shared_ptr span); - const std::map>::iterator - get_span_lookup_iter () const; - void set_span_lookup_iter (std::map>::iterator &it); + const std::map>::iterator get_span_lookup_iter () const; + void set_span_lookup_iter (std::map>::iterator &it); void incr_span_lookup_iter (); // Avail_time functions std::map &get_avail_time_iter (); - const std::map - &get_avail_time_iter_const () const; + const std::map &get_avail_time_iter_const () const; void clear_avail_time_iter (); void set_avail_time_iter_set (int atime_iter_set); const int get_avail_time_iter_set () const; @@ -96,20 +93,20 @@ class planner { void incr_span_counter (); const uint64_t get_span_counter () const; -private: + private: int64_t m_total_resources = 0; std::string m_resource_type = ""; - int64_t m_plan_start = 0; /* base time of the planner */ - int64_t m_plan_end = 0; /* end time of the planner */ + int64_t m_plan_start = 0; /* base time of the planner */ + int64_t m_plan_end = 0; /* end time of the planner */ scheduled_point_tree_t m_sched_point_tree; /* scheduled point rb tree */ mintime_resource_tree_t m_mt_resource_tree; /* min-time resource rb tree */ - scheduled_point_t *m_p0 = nullptr; /* system's scheduled point at base time */ - std::map > m_span_lookup; /* span lookup */ - std::map >::iterator m_span_lookup_iter; + scheduled_point_t *m_p0 = nullptr; /* system's scheduled point at base time */ + std::map> m_span_lookup; /* span lookup */ + std::map>::iterator m_span_lookup_iter; std::map m_avail_time_iter; /* MT node track */ - int m_avail_time_iter_set = 0; /* iterator set flag */ - request_t m_current_request; /* the req copy for avail time iteration */ - uint64_t m_span_counter = 0; /* current span counter */ + int m_avail_time_iter_set = 0; /* iterator set flag */ + request_t m_current_request; /* the req copy for avail time iteration */ + uint64_t m_span_counter = 0; /* current span counter */ // Private class utilities int copy_trees (const planner &o); int copy_maps (const planner &o); @@ -121,8 +118,10 @@ class planner { struct planner_t { planner_t (); planner_t (const planner &o); - planner_t (const int64_t base_time, const uint64_t duration, - const uint64_t resource_totals, const char *in_resource_type); + planner_t (const int64_t base_time, + const uint64_t duration, + const uint64_t resource_totals, + const char *in_resource_type); ~planner_t (); planner *plan = nullptr; diff --git a/resource/planner/c++/planner_internal_tree.cpp b/resource/planner/c++/planner_internal_tree.cpp index 7cbffe2bb..a43e035d8 100644 --- a/resource/planner/c++/planner_internal_tree.cpp +++ b/resource/planner/c++/planner_internal_tree.cpp @@ -40,10 +40,9 @@ bool scheduled_point_t::operator== (const scheduled_point_t &o) const bool scheduled_point_t::operator!= (const scheduled_point_t &o) const { - return !operator == (o); + return !operator== (o); } - /* * vi: ts=4 sw=4 expandtab */ diff --git a/resource/planner/c++/planner_internal_tree.hpp b/resource/planner/c++/planner_internal_tree.hpp index 4df95fffa..6a38c6944 100644 --- a/resource/planner/c++/planner_internal_tree.hpp +++ b/resource/planner/c++/planner_internal_tree.hpp @@ -24,15 +24,15 @@ struct scheduled_point_t { scheduled_point_rb_node_t point_rb; /* BST node for scheduled point tree */ mt_resource_rb_node_t resource_rb; /* BST node for min-time resource tree */ - int64_t at; /* Resource-state changing time */ - int in_mt_resource_tree; /* 1 when inserted in min-time resource tree */ - int new_point; /* 1 when this point is newly created */ - int ref_count; /* reference counter */ - int64_t scheduled; /* scheduled quantity at this point */ - int64_t remaining; /* remaining resources (available) */ + int64_t at; /* Resource-state changing time */ + int in_mt_resource_tree; /* 1 when inserted in min-time resource tree */ + int new_point; /* 1 when this point is newly created */ + int ref_count; /* reference counter */ + int64_t scheduled; /* scheduled quantity at this point */ + int64_t remaining; /* remaining resources (available) */ }; -#endif // PLANNER_INTERNAL_TREE_HPP +#endif // PLANNER_INTERNAL_TREE_HPP /* * vi: ts=4 sw=4 expandtab diff --git a/resource/planner/c++/planner_multi.cpp b/resource/planner/c++/planner_multi.cpp index 5545c89a8..02664a8c3 100644 --- a/resource/planner/c++/planner_multi.cpp +++ b/resource/planner/c++/planner_multi.cpp @@ -22,16 +22,17 @@ extern "C" { #include "planner_multi.hpp" - //////////////////////////////////////////////////////////////////////////////// // Public Planner Multi Methods //////////////////////////////////////////////////////////////////////////////// planner_multi::planner_multi () = default; -planner_multi::planner_multi (int64_t base_time, uint64_t duration, +planner_multi::planner_multi (int64_t base_time, + uint64_t duration, const uint64_t *resource_totals, - const char **resource_types, size_t len) + const char **resource_types, + size_t len) { size_t i = 0; std::string type; @@ -42,12 +43,10 @@ planner_multi::planner_multi (int64_t base_time, uint64_t duration, for (i = 0; i < len; ++i) { try { type = std::string (resource_types[i]); - p = new planner_t (base_time, duration, - resource_totals[i], - resource_types[i]); + p = new planner_t (base_time, duration, resource_totals[i], resource_types[i]); } catch (std::bad_alloc &e) { - errno = ENOMEM; - throw std::bad_alloc (); + errno = ENOMEM; + throw std::bad_alloc (); } m_iter.counts[type] = 0; m_types_totals_planners.push_back ({type, resource_totals[i], p}); @@ -67,9 +66,10 @@ planner_multi::planner_multi (const planner_multi &o) } // planner copy ctor can throw runtime_error, resulting in nullptr if (np == nullptr) - throw std::runtime_error ("ERROR in planner copy ctor" - " in planner_multi copy" - " constructor\n"); + throw std::runtime_error ( + "ERROR in planner copy ctor" + " in planner_multi copy" + " constructor\n"); } else { try { np = new planner_t (); @@ -78,8 +78,7 @@ planner_multi::planner_multi (const planner_multi &o) throw std::bad_alloc (); } } - m_types_totals_planners.push_back ({iter.resource_type, - iter.resource_total, np}); + m_types_totals_planners.push_back ({iter.resource_type, iter.resource_total, np}); } m_iter = o.m_iter; m_span_lookup = o.m_span_lookup; @@ -104,9 +103,10 @@ planner_multi &planner_multi::operator= (const planner_multi &o) } // planner copy ctor can throw runtime_error, resulting in nullptr if (np == nullptr) - throw std::runtime_error ("ERROR in planner copy ctor" - " in planner_multi assn" - " operator\n"); + throw std::runtime_error ( + "ERROR in planner copy ctor" + " in planner_multi assn" + " operator\n"); } else { try { np = new planner_t (); @@ -115,8 +115,7 @@ planner_multi &planner_multi::operator= (const planner_multi &o) throw std::bad_alloc (); } } - m_types_totals_planners.push_back ({iter.resource_type, - iter.resource_total, np}); + m_types_totals_planners.push_back ({iter.resource_type, iter.resource_total, np}); } m_iter = o.m_iter; m_span_lookup = o.m_span_lookup; @@ -160,7 +159,7 @@ bool planner_multi::operator== (const planner_multi &o) const bool planner_multi::operator!= (const planner_multi &o) const { - return !operator == (o); + return !operator== (o); } void planner_multi::erase () @@ -181,18 +180,18 @@ planner_multi::~planner_multi () erase (); } -void planner_multi::add_planner (int64_t base_time, uint64_t duration, +void planner_multi::add_planner (int64_t base_time, + uint64_t duration, const uint64_t resource_total, - const char *resource_type, size_t i) + const char *resource_type, + size_t i) { std::string type; planner_t *p = nullptr; try { type = std::string (resource_type); - p = new planner_t (base_time, duration, - resource_total, - resource_type); + p = new planner_t (base_time, duration, resource_total, resource_type); } catch (std::bad_alloc &e) { errno = ENOMEM; throw std::bad_alloc (); @@ -202,10 +201,8 @@ void planner_multi::add_planner (int64_t base_time, uint64_t duration, m_types_totals_planners.push_back ({type, resource_total, p}); else { auto it = m_types_totals_planners.begin () + i; - m_types_totals_planners.insert ( - it, planner_multi_meta{type, resource_total, p}); + m_types_totals_planners.insert (it, planner_multi_meta{type, resource_total, p}); } - } void planner_multi::delete_planners (const std::unordered_set &rtypes) @@ -301,14 +298,12 @@ std::map> &planner_multi::get_span_lookup () return m_span_lookup; } -std::map>::iterator - &planner_multi::get_span_lookup_iter () +std::map>::iterator &planner_multi::get_span_lookup_iter () { return m_span_lookup_iter; } -void planner_multi::set_span_lookup_iter (std::map>::iterator &it) +void planner_multi::set_span_lookup_iter (std::map>::iterator &it) { m_span_lookup_iter = it; } @@ -330,10 +325,9 @@ void planner_multi::set_span_counter (uint64_t sc) void planner_multi::incr_span_counter () { - m_span_counter++; + m_span_counter++; } - //////////////////////////////////////////////////////////////////////////////// // Public Planner_multi_t methods //////////////////////////////////////////////////////////////////////////////// @@ -356,13 +350,14 @@ planner_multi_t::planner_multi_t (const planner_multi &o) } } -planner_multi_t::planner_multi_t (int64_t base_time, uint64_t duration, +planner_multi_t::planner_multi_t (int64_t base_time, + uint64_t duration, const uint64_t *resource_totals, - const char **resource_types, size_t len) + const char **resource_types, + size_t len) { try { - plan_multi = new planner_multi (base_time, duration, resource_totals, - resource_types, len); + plan_multi = new planner_multi (base_time, duration, resource_totals, resource_types, len); } catch (std::bad_alloc &e) { errno = ENOMEM; } diff --git a/resource/planner/c++/planner_multi.hpp b/resource/planner/c++/planner_multi.hpp index 0cfdd71a3..f9d38abef 100644 --- a/resource/planner/c++/planner_multi.hpp +++ b/resource/planner/c++/planner_multi.hpp @@ -27,7 +27,7 @@ struct request_multi { struct planner_multi_meta { std::string resource_type; - mutable uint64_t resource_total; // Not an index; can mutate + mutable uint64_t resource_total; // Not an index; can mutate planner_t *planner; }; @@ -37,39 +37,41 @@ struct res_type {}; template struct polyfill_allocator : std::allocator { - using std::allocator::allocator; - template - struct rebind { - using other = polyfill_allocator; - }; - using pointer = T*; - using const_pointer = T const*; - using reference = T&; - using const_reference = T const&; + using std::allocator::allocator; + template + struct rebind { + using other = polyfill_allocator; + }; + using pointer = T *; + using const_pointer = T const *; + using reference = T &; + using const_reference = T const &; }; using boost::multi_index_container; using namespace boost::multi_index; typedef multi_index_container< - planner_multi_meta, // container data - indexed_by< // list of indexes - random_access< // analogous to vector - tag // index nametag - >, - hashed_unique< // unordered_set-like; faster than ordered_unique in testing - tag, // index nametag - member // index's key - > - >, - polyfill_allocator -> multi_container; + planner_multi_meta, // container data + indexed_by< // list of indexes + random_access< // analogous to vector + tag // index nametag + >, + hashed_unique< // unordered_set-like; faster than ordered_unique in testing + tag, // index nametag + member // index's + // key + >>, + polyfill_allocator> + multi_container; class planner_multi { -public: + public: planner_multi (); - planner_multi (int64_t base_time, uint64_t duration, + planner_multi (int64_t base_time, + uint64_t duration, const uint64_t *resource_totals, - const char **resource_types, size_t len); + const char **resource_types, + size_t len); planner_multi (const planner_multi &o); planner_multi &operator= (const planner_multi &o); bool operator== (const planner_multi &o) const; @@ -91,23 +93,23 @@ class planner_multi { struct request_multi &get_iter (); // Span lookup functions std::map> &get_span_lookup (); - std::map>::iterator - &get_span_lookup_iter (); - void set_span_lookup_iter (std::map>::iterator &it); + std::map>::iterator &get_span_lookup_iter (); + void set_span_lookup_iter (std::map>::iterator &it); void incr_span_lookup_iter (); // Get and set span_counter uint64_t get_span_counter (); void set_span_counter (uint64_t sc); void incr_span_counter (); - void add_planner (int64_t base_time, uint64_t duration, + void add_planner (int64_t base_time, + uint64_t duration, const uint64_t resource_total, - const char *resource_type, size_t i); + const char *resource_type, + size_t i); // Assuming small number of resources, // could try set, too void delete_planners (const std::unordered_set &rtypes); -private: + private: multi_container m_types_totals_planners; struct request_multi m_iter; std::map> m_span_lookup; @@ -118,9 +120,11 @@ class planner_multi { struct planner_multi_t { planner_multi_t (); planner_multi_t (const planner_multi &o); - planner_multi_t (int64_t base_time, uint64_t duration, + planner_multi_t (int64_t base_time, + uint64_t duration, const uint64_t *resource_totals, - const char **resource_types, size_t len); + const char **resource_types, + size_t len); ~planner_multi_t (); planner_multi *plan_multi = nullptr; diff --git a/resource/planner/c++/scheduled_point_tree.cpp b/resource/planner/c++/scheduled_point_tree.cpp index 8b60a55e7..4623a19a5 100644 --- a/resource/planner/c++/scheduled_point_tree.cpp +++ b/resource/planner/c++/scheduled_point_tree.cpp @@ -16,19 +16,16 @@ extern "C" { #include "planner_internal_tree.hpp" - - //////////////////////////////////////////////////////////////////////////////// // Private Scheduled Point Search Tree Methods //////////////////////////////////////////////////////////////////////////////// -scheduled_point_t *scheduled_point_tree_t::get_recent_state ( - scheduled_point_t *new_point, - scheduled_point_t *old_point) const +scheduled_point_t *scheduled_point_tree_t::get_recent_state (scheduled_point_t *new_point, + scheduled_point_t *old_point) const { if (!old_point) return new_point; - return (new_point->at > old_point->at)? new_point : old_point; + return (new_point->at > old_point->at) ? new_point : old_point; } void scheduled_point_tree_t::destroy (scheduled_point_rb_node_t *node) @@ -42,40 +39,35 @@ void scheduled_point_tree_t::destroy (scheduled_point_rb_node_t *node) data = nullptr; } - - //////////////////////////////////////////////////////////////////////////////// // Public Scheduled Point RBTree Node Methods //////////////////////////////////////////////////////////////////////////////// -bool scheduled_point_rb_node_t::operator< ( - const scheduled_point_rb_node_t &other) const +bool scheduled_point_rb_node_t::operator< (const scheduled_point_rb_node_t &other) const { return this->get_point ()->at < other.get_point ()->at; } -bool operator<(const scheduled_point_rb_node_t &lhs, const int64_t rhs) { +bool operator< (const scheduled_point_rb_node_t &lhs, const int64_t rhs) +{ return lhs.get_point ()->at < rhs; } -bool operator<(const int64_t lhs, const scheduled_point_rb_node_t &rhs) { +bool operator< (const int64_t lhs, const scheduled_point_rb_node_t &rhs) +{ return lhs < rhs.get_point ()->at; } -bool scheduled_point_rb_node_t::operator== ( - const scheduled_point_rb_node_t &other) const +bool scheduled_point_rb_node_t::operator== (const scheduled_point_rb_node_t &other) const { return this->get_point ()->at == other.get_point ()->at; } -bool scheduled_point_rb_node_t::operator!= ( - const scheduled_point_rb_node_t &other) const +bool scheduled_point_rb_node_t::operator!= (const scheduled_point_rb_node_t &other) const { - return !operator == (other); + return !operator== (other); } - - //////////////////////////////////////////////////////////////////////////////// // Public Scheduled Point Search Tree Methods //////////////////////////////////////////////////////////////////////////////// @@ -123,7 +115,7 @@ scheduled_point_t *scheduled_point_tree_t::next (scheduled_point_t *point) const scheduled_point_t *scheduled_point_tree_t::search (int64_t tm) { auto iter = m_tree.find (tm); - return (iter != m_tree.end ())? iter->get_point () : nullptr; + return (iter != m_tree.end ()) ? iter->get_point () : nullptr; } /*! While scheduled_point_search returns the exact match scheduled_point_state diff --git a/resource/planner/c++/scheduled_point_tree.hpp b/resource/planner/c++/scheduled_point_tree.hpp index 617f19640..d426b4ee7 100644 --- a/resource/planner/c++/scheduled_point_tree.hpp +++ b/resource/planner/c++/scheduled_point_tree.hpp @@ -13,7 +13,7 @@ #include -#if defined (__clang__) || (__GNUC__ <= 11) +#if defined(__clang__) || (__GNUC__ <= 11) #include "src/common/yggdrasil/rbtree.hpp" #elif (__GNUC__ > 11) #pragma GCC diagnostic push @@ -25,33 +25,35 @@ struct scheduled_point_t; class rb_node_base_t { -public: - void set_point (scheduled_point_t *p) { + public: + void set_point (scheduled_point_t *p) + { m_point = p; } - scheduled_point_t *get_point () { + scheduled_point_t *get_point () + { return m_point; } - scheduled_point_t *get_point () const { + scheduled_point_t *get_point () const + { return m_point; } -private: + + private: scheduled_point_t *m_point = nullptr; }; -struct scheduled_point_rb_node_t - : public rb_node_base_t, - public ygg::RBTreeNodeBase { +struct scheduled_point_rb_node_t : public rb_node_base_t, + public ygg::RBTreeNodeBase { bool operator< (const scheduled_point_rb_node_t &other) const; bool operator== (const scheduled_point_rb_node_t &other) const; bool operator!= (const scheduled_point_rb_node_t &other) const; }; -using scheduled_point_rb_tree_t = ygg::RBTree; +using scheduled_point_rb_tree_t = ygg::RBTree; class scheduled_point_tree_t { -public: + public: ~scheduled_point_tree_t (); scheduled_point_t *next (scheduled_point_t *point) const; scheduled_point_t *next (scheduled_point_t *point); @@ -63,14 +65,14 @@ class scheduled_point_tree_t { bool empty () const; size_t get_size () const; -private: + private: scheduled_point_t *get_recent_state (scheduled_point_t *new_point, scheduled_point_t *old_point) const; void destroy (scheduled_point_rb_node_t *node); scheduled_point_rb_tree_t m_tree; }; -#endif // SCHEDULED_POINT_TREE_HPP +#endif // SCHEDULED_POINT_TREE_HPP /* * vi: ts=4 sw=4 expandtab diff --git a/resource/planner/c/planner.h b/resource/planner/c/planner.h index 7615264ee..711578b4e 100644 --- a/resource/planner/c/planner.h +++ b/resource/planner/c/planner.h @@ -38,8 +38,10 @@ typedef struct planner_t planner_t; * EINVAL: invalid argument. * ERANGE: resource_total is an out-of-range value. */ -planner_t *planner_new (int64_t base_time, uint64_t duration, - uint64_t resource_total, const char *resource_type); +planner_t *planner_new (int64_t base_time, + uint64_t duration, + uint64_t resource_total, + const char *resource_type); /*! Initialize empty planner. * @@ -66,7 +68,7 @@ planner_t *planner_copy (planner_t *p); * \param lhs the base planner which will be assigned to rhs. * \param rhs the base planner which will be copied and returned as * a new planner context. - * + * */ void planner_assign (planner_t *lhs, planner_t *rhs); @@ -118,8 +120,10 @@ const char *planner_resource_type (planner_t *ctx); * ERANGE: request is an out-of-range value. * ENOENT: no scheduleable point */ -int64_t planner_avail_time_first (planner_t *ctx, int64_t on_or_after, - uint64_t duration, uint64_t request); +int64_t planner_avail_time_first (planner_t *ctx, + int64_t on_or_after, + uint64_t duration, + uint64_t request); /*! Find and return the next earliest point in time at which the same request * queried before via either planner_avail_time_first or @@ -135,7 +139,6 @@ int64_t planner_avail_time_first (planner_t *ctx, int64_t on_or_after, */ int64_t planner_avail_time_next (planner_t *ctx); - /*! Test if the given request can be satisfied at the start time. * Note on semantics: Unlike planner_avail_time* functions, this function * can be used to test an arbitrary time span. @@ -151,8 +154,7 @@ int64_t planner_avail_time_next (planner_t *ctx); * ERANGE: request is an out-of-range value. * ENOTSUP: internal error encountered. */ -int planner_avail_during (planner_t *ctx, int64_t at, uint64_t duration, - uint64_t request); +int planner_avail_during (planner_t *ctx, int64_t at, uint64_t duration, uint64_t request); /*! Return how resources are available for the duration starting from at. * @@ -163,8 +165,7 @@ int planner_avail_during (planner_t *ctx, int64_t at, uint64_t duration, * as follows: * EINVAL: invalid argument. */ -int64_t planner_avail_resources_during (planner_t *ctx, int64_t at, - uint64_t duration); +int64_t planner_avail_resources_during (planner_t *ctx, int64_t at, uint64_t duration); /*! Return how many resources are available at the given time. * @@ -176,7 +177,6 @@ int64_t planner_avail_resources_during (planner_t *ctx, int64_t at, */ int64_t planner_avail_resources_at (planner_t *ctx, int64_t at); - /*! Add a new span to the planner and update the planner's resource/time state. * Reset the planner's iterator so that planner_avail_time_next will be made * to return the earliest schedulable point. @@ -193,8 +193,7 @@ int64_t planner_avail_resources_at (planner_t *ctx, int64_t at); * ERANGE: a resource state became out of a valid range, * e.g., reserving more than available. */ -int64_t planner_add_span (planner_t *ctx, int64_t start_time, uint64_t duration, - uint64_t request); +int64_t planner_add_span (planner_t *ctx, int64_t start_time, uint64_t duration, uint64_t request); /*! Remove the existing span from the planner and update its resource/time state. * Reset the planner's iterator such that planner_avail_time_next will be made @@ -225,8 +224,7 @@ int planner_rem_span (planner_t *ctx, int64_t span_id); * the planner's internal data structures. * ERANGE: a resource state became out of a valid range. */ -int planner_reduce_span (planner_t *ctx, int64_t span_id, - int64_t to_remove, bool &removed); +int planner_reduce_span (planner_t *ctx, int64_t span_id, int64_t to_remove, bool &removed); //! Span iterators -- there is no specific iteration order int64_t planner_span_first (planner_t *ctx); @@ -244,7 +242,7 @@ int64_t planner_span_resource_count (planner_t *ctx, int64_t span_id); /* * Returns true if all the member variables and objects are equal. * Used by testsuite. -*/ + */ bool planners_equal (planner_t *lhs, planner_t *rhs); /*! Update the resource count to support elasticity. @@ -257,8 +255,7 @@ bool planners_equal (planner_t *lhs, planner_t *rhs); * \return 0 on success; -1 on an error with errno set as follows: * EINVAL: invalid argument. */ -int planner_update_total (planner_t *ctx, - uint64_t resource_total); +int planner_update_total (planner_t *ctx, uint64_t resource_total); #ifdef __cplusplus } diff --git a/resource/planner/c/planner_c_interface.cpp b/resource/planner/c/planner_c_interface.cpp index 31d69e12f..f63f79502 100644 --- a/resource/planner/c/planner_c_interface.cpp +++ b/resource/planner/c/planner_c_interface.cpp @@ -15,20 +15,16 @@ #include "resource/planner/c++/planner.hpp" - //////////////////////////////////////////////////////////////////////////////// // Scheduled Point and Resource Update APIs //////////////////////////////////////////////////////////////////////////////// -static int track_points (std::map &tracker, - scheduled_point_t *point) +static int track_points (std::map &tracker, scheduled_point_t *point) { // caller will rely on the fact that rc == -1 when key already exists. // don't need to register free */ - auto res = tracker.insert (std::pair (point->at, - point)); - return res.second? 0 : -1; + auto res = tracker.insert (std::pair (point->at, point)); + return res.second ? 0 : -1; } static void restore_track_points (planner_t *ctx) @@ -36,8 +32,7 @@ static void restore_track_points (planner_t *ctx) ctx->plan->restore_track_points (); } -static void update_mintime_resource_tree (planner_t *ctx, - std::list &list) +static void update_mintime_resource_tree (planner_t *ctx, std::list &list) { for (auto &point : list) { if (point->in_mt_resource_tree) @@ -47,7 +42,9 @@ static void update_mintime_resource_tree (planner_t *ctx, } } -static void copy_req (request_t &dest, int64_t on_or_after, uint64_t duration, +static void copy_req (request_t &dest, + int64_t on_or_after, + uint64_t duration, uint64_t resource_count) { dest.on_or_after = on_or_after; @@ -59,7 +56,7 @@ static scheduled_point_t *get_or_new_point (planner_t *ctx, int64_t at) { scheduled_point_t *point = nullptr; try { - if ( !(point = ctx->plan->sp_tree_search (at))) { + if (!(point = ctx->plan->sp_tree_search (at))) { scheduled_point_t *state = ctx->plan->sp_tree_get_state (at); point = new scheduled_point_t (); point->at = at; @@ -77,7 +74,9 @@ static scheduled_point_t *get_or_new_point (planner_t *ctx, int64_t at) return point; } -static void fetch_overlap_points (planner_t *ctx, int64_t at, uint64_t duration, +static void fetch_overlap_points (planner_t *ctx, + int64_t at, + uint64_t duration, std::list &list) { scheduled_point_t *point = ctx->plan->sp_tree_get_state (at); @@ -98,8 +97,7 @@ static int update_points_add_span (planner_t *ctx, for (auto &point : list) { point->scheduled += span->planned; point->remaining -= span->planned; - if ( (point->scheduled > ctx->plan->get_total_resources ()) - || (point->remaining < 0)) { + if ((point->scheduled > ctx->plan->get_total_resources ()) || (point->remaining < 0)) { errno = ERANGE; rc = -1; } @@ -115,8 +113,7 @@ static int update_points_subtract_span (planner_t *ctx, for (auto &point : list) { point->scheduled -= span->planned; point->remaining += span->planned; - if ( (point->scheduled < 0) - || (point->remaining > ctx->plan->get_total_resources ())) { + if ((point->scheduled < 0) || (point->remaining > ctx->plan->get_total_resources ())) { errno = ERANGE; rc = -1; } @@ -125,14 +122,13 @@ static int update_points_subtract_span (planner_t *ctx, } static int update_points_partial_subtract_span (planner_t *ctx, - std::list &list, - int64_t to_remove) + std::list &list, + int64_t to_remove) { for (auto &point : list) { point->scheduled -= to_remove; point->remaining += to_remove; - if ( (point->scheduled < 0) - || (point->remaining > ctx->plan->get_total_resources ())) { + if ((point->scheduled < 0) || (point->remaining > ctx->plan->get_total_resources ())) { errno = ERANGE; return -1; } @@ -140,29 +136,29 @@ static int update_points_partial_subtract_span (planner_t *ctx, return 0; } -static bool span_ok (planner_t *ctx, scheduled_point_t *start_point, - uint64_t duration, int64_t request) +static bool span_ok (planner_t *ctx, + scheduled_point_t *start_point, + uint64_t duration, + int64_t request) { bool ok = true; scheduled_point_t *next_point = nullptr; - for (next_point = start_point; - next_point != nullptr; + for (next_point = start_point; next_point != nullptr; next_point = ctx->plan->sp_tree_next (next_point)) { - if (next_point->at >= (start_point->at + (int64_t)duration)) { - ok = true; - break; - } else if (request > next_point->remaining) { - ctx->plan->mt_tree_remove (start_point); - track_points (ctx->plan->get_avail_time_iter (), start_point); - ok = false; - break; - } + if (next_point->at >= (start_point->at + (int64_t)duration)) { + ok = true; + break; + } else if (request > next_point->remaining) { + ctx->plan->mt_tree_remove (start_point); + track_points (ctx->plan->get_avail_time_iter (), start_point); + ok = false; + break; + } } return ok; } -static int64_t avail_at (planner_t *ctx, int64_t on_or_after, uint64_t duration, - int64_t request) +static int64_t avail_at (planner_t *ctx, int64_t on_or_after, uint64_t duration, int64_t request) { int64_t at = -1; scheduled_point_t *start_point = nullptr; @@ -184,8 +180,7 @@ static int64_t avail_at (planner_t *ctx, int64_t on_or_after, uint64_t duration, return at; } -static bool avail_during (planner_t *ctx, int64_t at, uint64_t duration, - const int64_t request) +static bool avail_during (planner_t *ctx, int64_t at, uint64_t duration, const int64_t request) { bool ok = true; if (static_cast (at + duration) > ctx->plan->get_plan_end ()) { @@ -207,8 +202,7 @@ static bool avail_during (planner_t *ctx, int64_t at, uint64_t duration, return ok; } -static scheduled_point_t *avail_resources_during (planner_t *ctx, int64_t at, - uint64_t duration) +static scheduled_point_t *avail_resources_during (planner_t *ctx, int64_t at, uint64_t duration) { if (static_cast (at + duration) > ctx->plan->get_plan_end ()) { errno = ERANGE; @@ -221,14 +215,12 @@ static scheduled_point_t *avail_resources_during (planner_t *ctx, int64_t at, if (point->at >= (at + (int64_t)duration)) break; else if (min->remaining > point->remaining) - min = point; + min = point; point = ctx->plan->sp_tree_next (point); } return min; } - - //////////////////////////////////////////////////////////////////////////////// // Utilities //////////////////////////////////////////////////////////////////////////////// @@ -238,17 +230,17 @@ static inline void erase (planner_t *ctx) ctx->plan->erase (); } -static inline bool not_feasible (planner_t *ctx, int64_t start_time, - uint64_t duration, int64_t request) +static inline bool not_feasible (planner_t *ctx, + int64_t start_time, + uint64_t duration, + int64_t request) { bool rc = (start_time < ctx->plan->get_plan_start ()) || (duration < 1) - || (static_cast (start_time + duration - 1) - > ctx->plan->get_plan_end ()); + || (static_cast (start_time + duration - 1) > ctx->plan->get_plan_end ()); return rc; } -static int span_input_check (planner_t *ctx, int64_t start_time, - uint64_t duration, int64_t request) +static int span_input_check (planner_t *ctx, int64_t start_time, uint64_t duration, int64_t request) { int rc = -1; if (!ctx || not_feasible (ctx, start_time, duration, request)) { @@ -263,8 +255,10 @@ static int span_input_check (planner_t *ctx, int64_t start_time, return rc; } -static std::shared_ptr span_new (planner_t *ctx, int64_t start_time, - uint64_t duration, uint64_t request) +static std::shared_ptr span_new (planner_t *ctx, + int64_t start_time, + uint64_t duration, + uint64_t request) { std::shared_ptr span = nullptr; try { @@ -287,8 +281,7 @@ static std::shared_ptr span_new (planner_t *ctx, int64_t start_time, // errno = EEXIST condition already checked above ctx->plan->span_lookup_insert (span->span_id, span); - } - catch (std::bad_alloc &e) { + } catch (std::bad_alloc &e) { errno = ENOMEM; } @@ -296,13 +289,12 @@ static std::shared_ptr span_new (planner_t *ctx, int64_t start_time, return span; } - - //////////////////////////////////////////////////////////////////////////////// // PUBLIC PLANNER API //////////////////////////////////////////////////////////////////////////////// -extern "C" planner_t *planner_new (int64_t base_time, uint64_t duration, +extern "C" planner_t *planner_new (int64_t base_time, + uint64_t duration, uint64_t resource_totals, const char *resource_type) { @@ -311,15 +303,13 @@ extern "C" planner_t *planner_new (int64_t base_time, uint64_t duration, if (duration < 1 || !resource_type) { errno = EINVAL; goto done; - } else if (resource_totals > - static_cast (std::numeric_limits::max ())) { + } else if (resource_totals > static_cast (std::numeric_limits::max ())) { errno = ERANGE; goto done; } try { - ctx = new planner_t (base_time, duration, resource_totals, - resource_type); + ctx = new planner_t (base_time, duration, resource_totals, resource_type); } catch (std::bad_alloc &e) { errno = ENOMEM; } @@ -359,8 +349,7 @@ extern "C" planner_t *planner_new_empty () return ctx; } -extern "C" int planner_reset (planner_t *ctx, - int64_t base_time, uint64_t duration) +extern "C" int planner_reset (planner_t *ctx, int64_t base_time, uint64_t duration) { int rc = 0; if (!ctx || duration < 1) { @@ -440,9 +429,8 @@ extern "C" int64_t planner_avail_time_first (planner_t *ctx, } restore_track_points (ctx); ctx->plan->set_avail_time_iter_set (1); - copy_req (ctx->plan->get_current_request (), on_or_after, - duration, request); - if ( (t = avail_at (ctx, on_or_after, duration, (int64_t)request)) == -1) + copy_req (ctx->plan->get_current_request (), on_or_after, duration, request); + if ((t = avail_at (ctx, on_or_after, duration, (int64_t)request)) == -1) errno = ENOENT; return t; } @@ -464,14 +452,15 @@ extern "C" int64_t planner_avail_time_next (planner_t *ctx) errno = ERANGE; return -1; } - if ( (t = avail_at (ctx, on_or_after, duration, (int64_t)request_count)) == - -1) + if ((t = avail_at (ctx, on_or_after, duration, (int64_t)request_count)) == -1) errno = ENOENT; return t; } -extern "C" int planner_avail_during (planner_t *ctx, int64_t start_time, - uint64_t duration, uint64_t request) +extern "C" int planner_avail_during (planner_t *ctx, + int64_t start_time, + uint64_t duration, + uint64_t request) { bool ok = false; if (!ctx || duration < 1) { @@ -483,11 +472,10 @@ extern "C" int planner_avail_during (planner_t *ctx, int64_t start_time, return -1; } ok = avail_during (ctx, start_time, duration, (int64_t)request); - return ok? 0 : -1; + return ok ? 0 : -1; } -extern "C" int64_t planner_avail_resources_during (planner_t *ctx, - int64_t at, uint64_t duration) +extern "C" int64_t planner_avail_resources_during (planner_t *ctx, int64_t at, uint64_t duration) { scheduled_point_t *min_point = nullptr; if (!ctx || at > ctx->plan->get_plan_end () || duration < 1) { @@ -501,8 +489,7 @@ extern "C" int64_t planner_avail_resources_during (planner_t *ctx, extern "C" int64_t planner_avail_resources_at (planner_t *ctx, int64_t at) { const scheduled_point_t *state = nullptr; - if (!ctx || at > ctx->plan->get_plan_end () - || at < ctx->plan->get_plan_start ()) { + if (!ctx || at > ctx->plan->get_plan_end () || at < ctx->plan->get_plan_start ()) { errno = EINVAL; return -1; } @@ -510,8 +497,10 @@ extern "C" int64_t planner_avail_resources_at (planner_t *ctx, int64_t at) return state->remaining; } -extern "C" int64_t planner_add_span (planner_t *ctx, int64_t start_time, - uint64_t duration, uint64_t request) +extern "C" int64_t planner_add_span (planner_t *ctx, + int64_t start_time, + uint64_t duration, + uint64_t request) { std::shared_ptr span = nullptr; scheduled_point_t *start_point = nullptr; @@ -521,7 +510,7 @@ extern "C" int64_t planner_add_span (planner_t *ctx, int64_t start_time, errno = EINVAL; return -1; } - if ( !(span = span_new (ctx, start_time, duration, request))) + if (!(span = span_new (ctx, start_time, duration, request))) return -1; restore_track_points (ctx); @@ -599,8 +588,10 @@ extern "C" int planner_rem_span (planner_t *ctx, int64_t span_id) return rc; } -extern "C" int planner_reduce_span (planner_t *ctx, int64_t span_id, - int64_t to_remove, bool &removed) +extern "C" int planner_reduce_span (planner_t *ctx, + int64_t span_id, + int64_t to_remove, + bool &removed) { int rc = -1; uint64_t duration = 0; @@ -639,7 +630,7 @@ extern "C" int planner_reduce_span (planner_t *ctx, int64_t span_id, } else { // Error errno = EINVAL; - rc -1; + rc - 1; } return rc; @@ -653,8 +644,7 @@ extern "C" int64_t planner_span_first (planner_t *ctx) } auto span_lookup_begin = ctx->plan->get_span_lookup ().begin (); ctx->plan->set_span_lookup_iter (span_lookup_begin); - if (ctx->plan->get_span_lookup_iter () == - ctx->plan->get_span_lookup ().end ()) { + if (ctx->plan->get_span_lookup_iter () == ctx->plan->get_span_lookup ().end ()) { errno = EINVAL; return -1; } @@ -669,8 +659,7 @@ extern "C" int64_t planner_span_next (planner_t *ctx) return -1; } ctx->plan->incr_span_lookup_iter (); - if (ctx->plan->get_span_lookup_iter () == - ctx->plan->get_span_lookup ().end ()) { + if (ctx->plan->get_span_lookup_iter () == ctx->plan->get_span_lookup ().end ()) { errno = EINVAL; return -1; } @@ -694,13 +683,12 @@ extern "C" bool planner_is_active_span (planner_t *ctx, int64_t span_id) return false; } auto it = ctx->plan->get_span_lookup ().find (span_id); - if (ctx->plan->get_span_lookup ().find (span_id) == - ctx->plan->get_span_lookup ().end ()) { + if (ctx->plan->get_span_lookup ().find (span_id) == ctx->plan->get_span_lookup ().end ()) { errno = EINVAL; return false; } std::shared_ptr &span = it->second; - return (span->in_system)? true : false; + return (span->in_system) ? true : false; } extern "C" int64_t planner_span_start_time (planner_t *ctx, int64_t span_id) @@ -710,8 +698,7 @@ extern "C" int64_t planner_span_start_time (planner_t *ctx, int64_t span_id) return -1; } auto it = ctx->plan->get_span_lookup ().find (span_id); - if (ctx->plan->get_span_lookup ().find (span_id) == - ctx->plan->get_span_lookup ().end ()) { + if (ctx->plan->get_span_lookup ().find (span_id) == ctx->plan->get_span_lookup ().end ()) { errno = EINVAL; return -1; } @@ -726,8 +713,7 @@ extern "C" int64_t planner_span_duration (planner_t *ctx, int64_t span_id) return -1; } auto it = ctx->plan->get_span_lookup ().find (span_id); - if (ctx->plan->get_span_lookup ().find (span_id) == - ctx->plan->get_span_lookup ().end ()) { + if (ctx->plan->get_span_lookup ().find (span_id) == ctx->plan->get_span_lookup ().end ()) { errno = EINVAL; return -1; } @@ -735,16 +721,14 @@ extern "C" int64_t planner_span_duration (planner_t *ctx, int64_t span_id) return (span->last - span->start); } -extern "C" int64_t planner_span_resource_count (planner_t *ctx, - int64_t span_id) +extern "C" int64_t planner_span_resource_count (planner_t *ctx, int64_t span_id) { if (!ctx) { errno = EINVAL; return -1; } auto it = ctx->plan->get_span_lookup ().find (span_id); - if (ctx->plan->get_span_lookup ().find (span_id) == - ctx->plan->get_span_lookup ().end ()) { + if (ctx->plan->get_span_lookup ().find (span_id) == ctx->plan->get_span_lookup ().end ()) { errno = EINVAL; return -1; } @@ -757,8 +741,7 @@ extern "C" bool planners_equal (planner_t *lhs, planner_t *rhs) return (*(lhs->plan) == *(rhs->plan)); } -extern "C" int planner_update_total (planner_t *ctx, - uint64_t resource_total) +extern "C" int planner_update_total (planner_t *ctx, uint64_t resource_total) { return ctx->plan->update_total (resource_total); } diff --git a/resource/planner/c/planner_multi.h b/resource/planner/c/planner_multi.h index 528eda982..e195ed8a9 100644 --- a/resource/planner/c/planner_multi.h +++ b/resource/planner/c/planner_multi.h @@ -44,9 +44,11 @@ typedef struct planner_multi_t planner_multi_t; * ERANGE: resource_totals contains an out-of-range * value. */ -planner_multi_t *planner_multi_new (int64_t base_time, uint64_t duration, +planner_multi_t *planner_multi_new (int64_t base_time, + uint64_t duration, const uint64_t *resource_totals, - const char **resource_types, size_t len); + const char **resource_types, + size_t len); /*! Initialize empty planner_multi. * @@ -72,7 +74,7 @@ planner_multi_t *planner_multi_copy (planner_multi_t *mp); * \param lhs the base planner_multi which will be assigned to rhs. * \param rhs the base planner_multi which will be copied and returned as * a new planner_multi context. - * + * */ void planner_multi_assign (planner_multi_t *lhs, planner_multi_t *rhs); @@ -86,8 +88,7 @@ size_t planner_multi_resources_len (planner_multi_t *ctx); const char *planner_multi_resource_type_at (planner_multi_t *ctx, unsigned int i); const uint64_t *planner_multi_resource_totals (planner_multi_t *ctx); int64_t planner_multi_resource_total_at (planner_multi_t *ctx, unsigned int i); -int64_t planner_multi_resource_total_by_type (planner_multi_t *ctx, - const char *resource_type); +int64_t planner_multi_resource_total_by_type (planner_multi_t *ctx, const char *resource_type); /*! Reset the planner_multi_t context with a new time bound. * Destroy all existing planned spans in its managed planner_t objects. @@ -101,8 +102,7 @@ int64_t planner_multi_resource_total_by_type (planner_multi_t *ctx, * \return 0 on success; -1 on error with errno set as follows: * EINVAL: invalid argument. */ -int planner_multi_reset (planner_multi_t *ctx, int64_t base_time, - uint64_t duration); +int planner_multi_reset (planner_multi_t *ctx, int64_t base_time, uint64_t duration); /*! Destroy the planner_multi. * @@ -150,8 +150,10 @@ planner_t *planner_multi_planner_at (planner_multi_t *ctx, unsigned int i); * ENOENT: no scheduleable point */ int64_t planner_multi_avail_time_first (planner_multi_t *ctx, - int64_t on_or_after, uint64_t duration, - const uint64_t *resource_requests, size_t len); + int64_t on_or_after, + uint64_t duration, + const uint64_t *resource_requests, + size_t len); /*! Find and return the next earliest point in time at which the same request * queried before via either planner_avail_time_first or @@ -169,7 +171,6 @@ int64_t planner_multi_avail_time_first (planner_multi_t *ctx, */ int64_t planner_multi_avail_time_next (planner_multi_t *ctx); - /*! Return how many resources of ith type is available at the given time. * * \param ctx opaque planner context returned from planner_multi_new. @@ -179,8 +180,7 @@ int64_t planner_multi_avail_time_next (planner_multi_t *ctx); * as follows: * EINVAL: invalid argument. */ -int64_t planner_multi_avail_resources_at (planner_multi_t *ctx, int64_t at, - unsigned int i); +int64_t planner_multi_avail_resources_at (planner_multi_t *ctx, int64_t at, unsigned int i); /*! Return how many resources are available at the given instant time (at). * @@ -194,8 +194,10 @@ int64_t planner_multi_avail_resources_at (planner_multi_t *ctx, int64_t at, * \return 0 on success; -1 on error with errno set as follows: * EINVAL: invalid argument. */ -int planner_multi_avail_resources_array_at (planner_multi_t *ctx, int64_t at, - int64_t *resource_counts, size_t len); +int planner_multi_avail_resources_array_at (planner_multi_t *ctx, + int64_t at, + int64_t *resource_counts, + size_t len); /*! Test if the given resource request can be satisfied at the start time. * Note on semantics: Unlike planner_multi_avail_time* functions, this function @@ -216,9 +218,11 @@ int planner_multi_avail_resources_array_at (planner_multi_t *ctx, int64_t at, * ERANGE: resource_counts contain an out-of-range value. * ENOTSUP: internal error encountered. */ -int planner_multi_avail_during (planner_multi_t *ctx, int64_t at, +int planner_multi_avail_during (planner_multi_t *ctx, + int64_t at, uint64_t duration, - const uint64_t *resource_requests, size_t len); + const uint64_t *resource_requests, + size_t len); /*! Return how many resources are available for the duration starting from at. * @@ -235,8 +239,10 @@ int planner_multi_avail_during (planner_multi_t *ctx, int64_t at, */ int planner_multi_avail_resources_array_during (planner_multi_t *ctx, - int64_t at, uint64_t duration, - int64_t *resource_counts, size_t len); + int64_t at, + uint64_t duration, + int64_t *resource_counts, + size_t len); /*! Add a new span to the multi-planner and update the planner's resource/time * state. Reset the multi-planner's iterator so that @@ -259,8 +265,10 @@ int planner_multi_avail_resources_array_during (planner_multi_t *ctx, * ERANGE: a resource state became out of a valid * range, e.g., reserving more than available. */ -int64_t planner_multi_add_span (planner_multi_t *ctx, int64_t start_time, - uint64_t duration, const uint64_t *resource_requests, +int64_t planner_multi_add_span (planner_multi_t *ctx, + int64_t start_time, + uint64_t duration, + const uint64_t *resource_requests, size_t len); /*! Remove the existing span from multi-planner and update resource/time state. @@ -280,7 +288,7 @@ int planner_multi_rem_span (planner_multi_t *ctx, int64_t span_id); /*! Reduce the existing span's resources from the planner. * This function will be called for a partial release/cancel. - * If the number of resources to be removed is equal to those + * If the number of resources to be removed is equal to those * allocated to the span, completely remove the span. * * \param ctx opaque multi-planner context returned @@ -302,9 +310,11 @@ int planner_multi_rem_span (planner_multi_t *ctx, int64_t span_id); * the planner's internal data structures. * ERANGE: a resource state became out of a valid range. */ -int planner_multi_reduce_span (planner_multi_t *ctx, int64_t span_id, +int planner_multi_reduce_span (planner_multi_t *ctx, + int64_t span_id, const uint64_t *reduced_totals, - const char **resource_types, size_t len, + const char **resource_types, + size_t len, bool &removed); //! Span iterators -- there is no specific iteration order @@ -318,7 +328,7 @@ size_t planner_multi_span_size (planner_multi_t *ctx); /* * Returns true if all the member variables and objects are equal. * Used by testsuite. -*/ + */ bool planner_multis_equal (planner_multi_t *lhs, planner_multi_t *rhs); /*! Update the counts and resource types to support elasticity. @@ -342,7 +352,6 @@ int planner_multi_update (planner_multi_t *ctx, const char **resource_types, size_t len); - #ifdef __cplusplus } #endif diff --git a/resource/planner/c/planner_multi_c_interface.cpp b/resource/planner/c/planner_multi_c_interface.cpp index 958a3d900..97c6f8104 100644 --- a/resource/planner/c/planner_multi_c_interface.cpp +++ b/resource/planner/c/planner_multi_c_interface.cpp @@ -19,27 +19,29 @@ #include "planner_multi.h" #include "resource/planner/c++/planner_multi.hpp" - //////////////////////////////////////////////////////////////////////////////// // Planner Multi and Resource Update APIs //////////////////////////////////////////////////////////////////////////////// -static void fill_iter_request (planner_multi_t *ctx, struct request_multi *iter, - int64_t at, uint64_t duration, - const uint64_t *resources, size_t len) +static void fill_iter_request (planner_multi_t *ctx, + struct request_multi *iter, + int64_t at, + uint64_t duration, + const uint64_t *resources, + size_t len) { size_t i; iter->on_or_after = at; iter->duration = duration; for (i = 0; i < len; ++i) - iter->counts[ctx->plan_multi->get_resource_type_at (i)] = - resources[i]; + iter->counts[ctx->plan_multi->get_resource_type_at (i)] = resources[i]; } -extern "C" planner_multi_t *planner_multi_new ( - int64_t base_time, uint64_t duration, - const uint64_t *resource_totals, - const char **resource_types, size_t len) +extern "C" planner_multi_t *planner_multi_new (int64_t base_time, + uint64_t duration, + const uint64_t *resource_totals, + const char **resource_types, + size_t len) { size_t i = 0; planner_multi_t *ctx = nullptr; @@ -49,8 +51,7 @@ extern "C" planner_multi_t *planner_multi_new ( goto error; } else { for (i = 0; i < len; ++i) { - if (resource_totals[i] > - static_cast (std::numeric_limits::max ())) { + if (resource_totals[i] > static_cast (std::numeric_limits::max ())) { errno = ERANGE; goto error; } @@ -58,8 +59,7 @@ extern "C" planner_multi_t *planner_multi_new ( } try { - ctx = new planner_multi_t (base_time, duration, resource_totals, - resource_types, len); + ctx = new planner_multi_t (base_time, duration, resource_totals, resource_types, len); } catch (std::bad_alloc &e) { goto nomem_error; } @@ -107,8 +107,7 @@ extern "C" planner_multi_t *planner_multi_copy (planner_multi_t *mp) return ctx; } -extern "C" void planner_multi_assign (planner_multi_t *lhs, - planner_multi_t *rhs) +extern "C" void planner_multi_assign (planner_multi_t *lhs, planner_multi_t *rhs) { (*(lhs->plan_multi) = *(rhs->plan_multi)); } @@ -140,8 +139,7 @@ extern "C" size_t planner_multi_resources_len (planner_multi_t *ctx) return ctx->plan_multi->get_planners_size (); } -extern "C" const char *planner_multi_resource_type_at (planner_multi_t *ctx, - unsigned int i) +extern "C" const char *planner_multi_resource_type_at (planner_multi_t *ctx, unsigned int i) { if (!ctx) { errno = EINVAL; @@ -150,8 +148,7 @@ extern "C" const char *planner_multi_resource_type_at (planner_multi_t *ctx, return ctx->plan_multi->get_resource_type_at (i); } -extern "C" int64_t planner_multi_resource_total_at (planner_multi_t *ctx, - unsigned int i) +extern "C" int64_t planner_multi_resource_total_at (planner_multi_t *ctx, unsigned int i) { int64_t rc = -1; if (ctx) { @@ -165,8 +162,8 @@ extern "C" int64_t planner_multi_resource_total_at (planner_multi_t *ctx, return rc; } -extern "C" int64_t planner_multi_resource_total_by_type ( - planner_multi_t *ctx, const char *resource_type) +extern "C" int64_t planner_multi_resource_total_by_type (planner_multi_t *ctx, + const char *resource_type) { int64_t rc = -1; if (!ctx || !resource_type) @@ -179,8 +176,7 @@ extern "C" int64_t planner_multi_resource_total_by_type ( return rc; } -extern "C" int planner_multi_reset (planner_multi_t *ctx, - int64_t base_time, uint64_t duration) +extern "C" int planner_multi_reset (planner_multi_t *ctx, int64_t base_time, uint64_t duration) { size_t i = 0; int rc = -1; @@ -206,8 +202,7 @@ extern "C" void planner_multi_destroy (planner_multi_t **ctx_p) } } -extern "C" planner_t *planner_multi_planner_at (planner_multi_t *ctx, - unsigned int i) +extern "C" planner_t *planner_multi_planner_at (planner_multi_t *ctx, unsigned int i) { planner_t *planner = nullptr; if (!ctx || i >= ctx->plan_multi->get_planners_size ()) { @@ -219,39 +214,50 @@ extern "C" planner_t *planner_multi_planner_at (planner_multi_t *ctx, return planner; } -extern "C" int64_t planner_multi_avail_time_first ( - planner_multi_t *ctx, int64_t on_or_after, - uint64_t duration, - const uint64_t *resource_requests, size_t len) +extern "C" int64_t planner_multi_avail_time_first (planner_multi_t *ctx, + int64_t on_or_after, + uint64_t duration, + const uint64_t *resource_requests, + size_t len) { size_t i = 0; int unmet = 0; int64_t t = -1; if (!ctx || !resource_requests || ctx->plan_multi->get_planners_size () < 1 - || ctx->plan_multi->get_planners_size () != len) { + || ctx->plan_multi->get_planners_size () != len) { errno = EINVAL; goto done; } - fill_iter_request (ctx, &(ctx->plan_multi->get_iter ()), - on_or_after, duration, resource_requests, len); + fill_iter_request (ctx, + &(ctx->plan_multi->get_iter ()), + on_or_after, + duration, + resource_requests, + len); - if ((t = planner_avail_time_first (ctx->plan_multi->get_planner_at ( - static_cast (0)), on_or_after, - duration, resource_requests[0])) == -1) + if ((t = planner_avail_time_first (ctx->plan_multi->get_planner_at (static_cast (0)), + on_or_after, + duration, + resource_requests[0])) + == -1) goto done; do { unmet = 0; for (i = 1; i < ctx->plan_multi->get_planners_size (); ++i) { if ((unmet = planner_avail_during (ctx->plan_multi->get_planner_at (i), - t, duration, - resource_requests[i])) == -1) + t, + duration, + resource_requests[i])) + == -1) break; } - } while (unmet && (t = planner_avail_time_next ( - ctx->plan_multi->get_planner_at (static_cast (0)))) != -1); + } while ( + unmet + && (t = planner_avail_time_next (ctx->plan_multi->get_planner_at (static_cast (0)))) + != -1); done: return t; @@ -271,13 +277,16 @@ extern "C" int64_t planner_multi_avail_time_next (planner_multi_t *ctx) do { unmet = 0; if ((t = planner_avail_time_next ( - ctx->plan_multi->get_planner_at (static_cast (0)))) == -1) + ctx->plan_multi->get_planner_at (static_cast (0)))) + == -1) break; for (i = 1; i < ctx->plan_multi->get_planners_size (); ++i) { type = ctx->plan_multi->get_resource_type_at (i); - if ((unmet = planner_avail_during (ctx->plan_multi->get_planner_at (i), t, + if ((unmet = planner_avail_during (ctx->plan_multi->get_planner_at (i), + t, ctx->plan_multi->get_iter ().duration, - ctx->plan_multi->get_iter ().counts.at (type))) == -1) + ctx->plan_multi->get_iter ().counts.at (type))) + == -1) break; } } while (unmet); @@ -286,8 +295,9 @@ extern "C" int64_t planner_multi_avail_time_next (planner_multi_t *ctx) return t; } -extern "C" int64_t planner_multi_avail_resources_at ( - planner_multi_t *ctx, int64_t at, unsigned int i) +extern "C" int64_t planner_multi_avail_resources_at (planner_multi_t *ctx, + int64_t at, + unsigned int i) { if (!ctx || i >= ctx->plan_multi->get_planners_size ()) { errno = EINVAL; @@ -296,9 +306,10 @@ extern "C" int64_t planner_multi_avail_resources_at ( return planner_avail_resources_at (ctx->plan_multi->get_planner_at (i), at); } -extern "C" int planner_multi_avail_resources_array_at ( - planner_multi_t *ctx, int64_t at, - int64_t *resource_counts, size_t len) +extern "C" int planner_multi_avail_resources_array_at (planner_multi_t *ctx, + int64_t at, + int64_t *resource_counts, + size_t len) { size_t i = 0; int64_t rc = 0; @@ -312,12 +323,14 @@ extern "C" int planner_multi_avail_resources_array_at ( break; resource_counts[i] = rc; } - return (rc == -1)? -1 : 0; + return (rc == -1) ? -1 : 0; } -extern "C" int planner_multi_avail_during ( - planner_multi_t *ctx, int64_t at, uint64_t duration, - const uint64_t *resource_requests, size_t len) +extern "C" int planner_multi_avail_during (planner_multi_t *ctx, + int64_t at, + uint64_t duration, + const uint64_t *resource_requests, + size_t len) { size_t i = 0; int rc = 0; @@ -326,7 +339,9 @@ extern "C" int planner_multi_avail_during ( return -1; } for (i = 0; i < ctx->plan_multi->get_planners_size (); ++i) { - rc = planner_avail_during (ctx->plan_multi->get_planner_at (i), at, duration, + rc = planner_avail_during (ctx->plan_multi->get_planner_at (i), + at, + duration, resource_requests[i]); if (rc == -1) break; @@ -334,14 +349,15 @@ extern "C" int planner_multi_avail_during ( return rc; } -extern "C" int planner_multi_avail_resources_array_during ( - planner_multi_t *ctx, int64_t at, - uint64_t duration, int64_t *resource_counts, size_t len) +extern "C" int planner_multi_avail_resources_array_during (planner_multi_t *ctx, + int64_t at, + uint64_t duration, + int64_t *resource_counts, + size_t len) { size_t i = 0; int64_t rc = 0; - if (!ctx || !resource_counts - || ctx->plan_multi->get_planners_size () < 1 + if (!ctx || !resource_counts || ctx->plan_multi->get_planners_size () < 1 || ctx->plan_multi->get_planners_size () != len) { errno = EINVAL; return -1; @@ -352,13 +368,14 @@ extern "C" int planner_multi_avail_resources_array_during ( break; resource_counts[i] = rc; } - return (rc == -1)? -1 : 0; + return (rc == -1) ? -1 : 0; } -extern "C" int64_t planner_multi_add_span ( - planner_multi_t *ctx, int64_t start_time, - uint64_t duration, - const uint64_t *resource_requests, size_t len) +extern "C" int64_t planner_multi_add_span (planner_multi_t *ctx, + int64_t start_time, + uint64_t duration, + const uint64_t *resource_requests, + size_t len) { size_t i = 0; int64_t span = -1; @@ -369,8 +386,7 @@ extern "C" int64_t planner_multi_add_span ( mspan = ctx->plan_multi->get_span_counter (); auto res = ctx->plan_multi->get_span_lookup ().insert ( - std::pair> ( - mspan, std::vector ())); + std::pair> (mspan, std::vector ())); if (!res.second) { errno = EEXIST; return -1; @@ -379,9 +395,11 @@ extern "C" int64_t planner_multi_add_span ( ctx->plan_multi->incr_span_counter (); for (i = 0; i < len; ++i) { - if ( (span = planner_add_span (ctx->plan_multi->get_planner_at (i), - start_time, duration, - resource_requests[i])) == -1) { + if ((span = planner_add_span (ctx->plan_multi->get_planner_at (i), + start_time, + duration, + resource_requests[i])) + == -1) { ctx->plan_multi->get_span_lookup ().erase (mspan); return -1; } @@ -409,7 +427,7 @@ extern "C" int planner_multi_rem_span (planner_multi_t *ctx, int64_t span_id) goto done; } ctx->plan_multi->get_span_lookup ().erase (it); - rc = 0; + rc = 0; done: return rc; } @@ -439,8 +457,7 @@ extern "C" int planner_multi_reduce_span (planner_multi_t *ctx, return -1; } for (i = 0; i < len; ++i) { - if (reduced_totals[i] > - static_cast (std::numeric_limits::max ())) { + if (reduced_totals[i] > static_cast (std::numeric_limits::max ())) { errno = ERANGE; return -1; } @@ -453,11 +470,11 @@ extern "C" int planner_multi_reduce_span (planner_multi_t *ctx, continue; tmp_removed = false; - if ( (rc = planner_reduce_span ( - ctx->plan_multi->get_planner_at (mspan_idx), - span_it->second.at (mspan_idx), - reduced_totals[i], - tmp_removed)) == -1) { + if ((rc = planner_reduce_span (ctx->plan_multi->get_planner_at (mspan_idx), + span_it->second.at (mspan_idx), + reduced_totals[i], + tmp_removed)) + == -1) { // Could return -1 if the span with 0 resource request had been removed // by a previous cancellation, so need to check if the span exists. if (planner_is_active_span (ctx->plan_multi->get_planner_at (mspan_idx), @@ -488,10 +505,11 @@ extern "C" int planner_multi_reduce_span (planner_multi_t *ctx, // Check if the resource type was already processed in a previous // loop. if (ext_res_types.find (i) == ext_res_types.end ()) { - if ( (rc = planner_reduce_span (ctx->plan_multi->get_planner_at (i), - span_it->second.at (i), - 0, - tmp_removed)) == -1) { + if ((rc = planner_reduce_span (ctx->plan_multi->get_planner_at (i), + span_it->second.at (i), + 0, + tmp_removed)) + == -1) { // Could return -1 if the span with 0 resource request had been // removed by a previous cancellation, so need to check if the // span exists. @@ -511,14 +529,15 @@ extern "C" int planner_multi_reduce_span (planner_multi_t *ctx, } mspan_sum = std::accumulate (span_it->second.begin (), span_it->second.end (), - 0, std::plus ()); + 0, + std::plus ()); // Delete if all entries are -1 if (mspan_sum == (-1 * span_it->second.size ())) { ctx->plan_multi->get_span_lookup ().erase (span_it); removed = true; } - rc = 0; + rc = 0; error: return rc; } @@ -526,7 +545,8 @@ extern "C" int planner_multi_reduce_span (planner_multi_t *ctx, int64_t planner_multi_span_first (planner_multi_t *ctx) { int64_t rc = -1; - std::map>::iterator tmp_it = ctx->plan_multi->get_span_lookup ().begin (); + std::map>::iterator tmp_it = + ctx->plan_multi->get_span_lookup ().begin (); if (!ctx) { errno = EINVAL; goto done; @@ -535,7 +555,6 @@ int64_t planner_multi_span_first (planner_multi_t *ctx) if (ctx->plan_multi->get_span_lookup_iter () == ctx->plan_multi->get_span_lookup ().end ()) { errno = ENOENT; goto done; - } rc = ctx->plan_multi->get_span_lookup_iter ()->first; done: @@ -553,7 +572,6 @@ extern "C" int64_t planner_multi_span_next (planner_multi_t *ctx) if (ctx->plan_multi->get_span_lookup_iter () == ctx->plan_multi->get_span_lookup ().end ()) { errno = ENOENT; goto done; - } rc = ctx->plan_multi->get_span_lookup_iter ()->first; done: @@ -562,15 +580,14 @@ extern "C" int64_t planner_multi_span_next (planner_multi_t *ctx) extern "C" size_t planner_multi_span_size (planner_multi_t *ctx) { - if (!ctx) { + if (!ctx) { errno = EINVAL; return 0; } return ctx->plan_multi->get_span_lookup ().size (); } -extern "C" bool planner_multis_equal (planner_multi_t *lhs, - planner_multi_t *rhs) +extern "C" bool planner_multis_equal (planner_multi_t *lhs, planner_multi_t *rhs) { return (*(lhs->plan_multi) == *(rhs->plan_multi)); } @@ -592,31 +609,30 @@ extern "C" int planner_multi_update (planner_multi_t *ctx, errno = EINVAL; goto done; } - base_time = planner_base_time ( - ctx->plan_multi->get_planner_at (static_cast (0))); - duration = planner_duration ( - ctx->plan_multi->get_planner_at (static_cast (0))); + base_time = planner_base_time (ctx->plan_multi->get_planner_at (static_cast (0))); + duration = planner_duration (ctx->plan_multi->get_planner_at (static_cast (0))); if (duration < 0) { errno = EINVAL; goto done; } for (i = 0; i < len; ++i) { - if (resource_totals[i] > - static_cast (std::numeric_limits::max ())) { - errno = ERANGE; - goto done; + if (resource_totals[i] > static_cast (std::numeric_limits::max ())) { + errno = ERANGE; + goto done; } rtypes.insert (resource_types[i]); if (!ctx->plan_multi->planner_at (resource_types[i])) { // Assume base_time same as parent - ctx->plan_multi->add_planner (base_time, static_cast (duration), - resource_totals[i], resource_types[i], i); + ctx->plan_multi->add_planner (base_time, + static_cast (duration), + resource_totals[i], + resource_types[i], + i); } else { // Index could have changed ctx->plan_multi->update_planner_index (resource_types[i], i); - if ( (rc = ctx->plan_multi->update_planner_total (resource_totals[i], - i)) != 0) { + if ((rc = ctx->plan_multi->update_planner_total (resource_totals[i], i)) != 0) { errno = EINVAL; goto done; } diff --git a/resource/planner/test/planner_test01.cpp b/resource/planner/test/planner_test01.cpp index 560278abb..b8d674ef3 100644 --- a/resource/planner/test/planner_test01.cpp +++ b/resource/planner/test/planner_test01.cpp @@ -10,7 +10,7 @@ extern "C" { #if HAVE_CONFIG_H - #include "config.h" +#include "config.h" #endif } #include @@ -24,12 +24,16 @@ extern "C" { #include "planner.h" #include "src/common/libtap/tap.h" -static void to_stream (int64_t base_time, uint64_t duration, uint64_t cnts, - const char *type, std::stringstream &ss) +static void to_stream (int64_t base_time, + uint64_t duration, + uint64_t cnts, + const char *type, + std::stringstream &ss) { if (base_time != -1) ss << "B(" << base_time << "):"; - ss << "D(" << duration << "):" << "R_"; + ss << "D(" << duration << "):" + << "R_"; ss << type << "(" << cnts << ")"; } @@ -390,7 +394,7 @@ int test_remove_more () uint64_t resource_total = 10; char resource_type[] = "core"; uint64_t count = 5; - int overlap_factor = resource_total/count; + int overlap_factor = resource_total / count; std::vector query_times; planner_t *ctx = NULL; std::stringstream ss; @@ -402,7 +406,7 @@ int test_remove_more () std::vector spans; for (i = 0; i < 10000; ++i) { - at = i/overlap_factor * 1000; + at = i / overlap_factor * 1000; span = planner_add_span (ctx, at, 1000, count); spans.push_back (span); bo = (bo || span == -1); @@ -416,7 +420,6 @@ int test_remove_more () ok (!bo, "removing more works"); planner_destroy (&ctx); return 0; - } int test_stress_fully_overlap () @@ -503,7 +506,7 @@ static int test_resource_service_flow () std::map types; std::vector global_totals; std::vector global_types; - std::vector locals; + std::vector locals; planner_t *global1 = NULL, *global2 = NULL, *global3 = NULL; std::stringstream ss; @@ -519,8 +522,7 @@ static int test_resource_service_flow () for (auto &kv : totals) global_totals.push_back (L2_size * kv.second); for (int i = 0; i < L1_size; ++i) - locals.push_back (planner_new (0, INT64_MAX, totals[i % L2_size], - types[i%L2_size])); + locals.push_back (planner_new (0, INT64_MAX, totals[i % L2_size], types[i % L2_size])); global1 = planner_new (0, INT64_MAX, global_totals[0], global_types[0]); global2 = planner_new (0, INT64_MAX, global_totals[1], global_types[1]); @@ -555,7 +557,7 @@ static int test_resource_service_flow () global = global3; t = planner_avail_time_first (global, at, duration, totals[j]); - bo = (bo || t != (int64_t)(at + (i/L1_size)*duration)); + bo = (bo || t != (int64_t)(at + (i / L1_size) * duration)); // Descend/Reserve lower-level resource at this schedule point rc = planner_avail_during (locals[k], t, duration, totals[j]); @@ -584,8 +586,7 @@ static int test_resource_service_flow () static int test_more_add_remove () { int rc; - int64_t span1 = -1, span2 = -1, span3 = -1, span4 = -1, span5 = -1, - span6 = -1; + int64_t span1 = -1, span2 = -1, span3 = -1, span4 = -1, span5 = -1, span6 = -1; bool bo = false; uint64_t resource_total = 100000; uint64_t resource1 = 36; @@ -717,8 +718,9 @@ static int test_constructors_and_overload () bo = (bo || !(planners_equal (ctx, ctx4))); ok (!bo, "copy constructor works on planners with state"); - bo = (bo || !(planner_avail_resources_at (ctx, 57600) == - planner_avail_resources_at (ctx4, 57600))); + bo = + (bo + || !(planner_avail_resources_at (ctx, 57600) == planner_avail_resources_at (ctx4, 57600))); ok (!bo, "test for avail time equality"); planner_destroy (&ctx); @@ -776,8 +778,9 @@ static int test_update () bo = (bo || (planners_equal (ctx, ctx2)) || span != -1); ok (!bo, "reducing resources below request should prevent scheduling"); span = planner_add_span (ctx, 1152000, 57600, 40000); - //rc = planner_reduce_span (ctx, span, 40000, removed); - //std::cout << "Reduce span rc: " << rc << " removed: " << removed << " errno: " << errno << "\n"; + // rc = planner_reduce_span (ctx, span, 40000, removed); + // std::cout << "Reduce span rc: " << rc << " removed: " << removed << " errno: " << errno << + // "\n"; rc = planner_rem_span (ctx, span); planner_destroy (&ctx); diff --git a/resource/planner/test/planner_test02.cpp b/resource/planner/test/planner_test02.cpp index f6fa54196..a9d5481d0 100644 --- a/resource/planner/test/planner_test02.cpp +++ b/resource/planner/test/planner_test02.cpp @@ -10,7 +10,7 @@ extern "C" { #if HAVE_CONFIG_H -# include +#include #endif } #include @@ -24,13 +24,18 @@ extern "C" { #include "resource/planner/c/planner_multi.h" #include "src/common/libtap/tap.h" -static void to_stream (int64_t base_time, uint64_t duration, const uint64_t *cnts, - const char **types, size_t len, std::stringstream &ss) +static void to_stream (int64_t base_time, + uint64_t duration, + const uint64_t *cnts, + const char **types, + size_t len, + std::stringstream &ss) { if (base_time != -1) ss << "B(" << base_time << "):"; - ss << "D(" << duration << "):" << "R(<"; + ss << "D(" << duration << "):" + << "R(<"; for (unsigned int i = 0; i < len; ++i) ss << types[i] << "(" << cnts[i] << ")"; @@ -254,8 +259,7 @@ static int test_multi_strictly_larger () t = planner_multi_avail_time_next (ctx); ok ((t == 5000), "avail_time_next for (%s)", ss.str ().c_str ()); t = planner_multi_avail_time_next (ctx); - ok ((t == -1 && errno == ENOENT), "avail_time_next for (%s)", - ss.str ().c_str ()); + ok ((t == -1 && errno == ENOENT), "avail_time_next for (%s)", ss.str ().c_str ()); ss.str (""); to_stream (0, 1000, requestB, (const char **)resource_types, len, ss); @@ -272,16 +276,14 @@ static int test_multi_strictly_larger () t = planner_multi_avail_time_next (ctx); ok ((t == 5000), "avail_time_next for (%s)", ss.str ().c_str ()); t = planner_multi_avail_time_next (ctx); - ok ((t == -1 && errno == ENOENT), "avail_time_next for (%s)", - ss.str ().c_str ()); + ok ((t == -1 && errno == ENOENT), "avail_time_next for (%s)", ss.str ().c_str ()); t = planner_multi_avail_time_first (ctx, 3500, 1000, requestB, len); ok ((t == 4000), "avail_time_first for (%s)", ss.str ().c_str ()); t = planner_multi_avail_time_next (ctx); ok ((t == 5000), "avail_time_next for (%s)", ss.str ().c_str ()); t = planner_multi_avail_time_next (ctx); - ok ((t == -1 && errno == ENOENT), "avail_time_next for (%s)", - ss.str ().c_str ()); + ok ((t == -1 && errno == ENOENT), "avail_time_next for (%s)", ss.str ().c_str ()); ss.str (""); to_stream (0, 1000, requestC, (const char **)resource_types, len, ss); @@ -292,8 +294,7 @@ static int test_multi_strictly_larger () t = planner_multi_avail_time_next (ctx); ok ((t == 5000), "avail_time_next for (%s)", ss.str ().c_str ()); t = planner_multi_avail_time_next (ctx); - ok ((t == -1 && errno == ENOENT), "avail_time_next for (%s)", - ss.str ().c_str ()); + ok ((t == -1 && errno == ENOENT), "avail_time_next for (%s)", ss.str ().c_str ()); planner_multi_destroy (&ctx); return 0; @@ -379,8 +380,7 @@ static int test_multi_partially_larger () t = planner_multi_avail_time_first (ctx, 0, 1000, requestA, len); ok ((t == 5000), "avail_time_first for (%s)", ss.str ().c_str ()); t = planner_multi_avail_time_next (ctx); - ok ((t == -1 && errno == ENOENT), "avail_time_next for (%s)", - ss.str ().c_str ()); + ok ((t == -1 && errno == ENOENT), "avail_time_next for (%s)", ss.str ().c_str ()); ss.str (""); to_stream (-1, 1000, requestB, (const char **)resource_types, len, ss); @@ -393,8 +393,7 @@ static int test_multi_partially_larger () t = planner_multi_avail_time_next (ctx); ok ((t == 5000), "avail_time_next for (%s)", ss.str ().c_str ()); t = planner_multi_avail_time_next (ctx); - ok ((t == -1 && errno == ENOENT), "avail_time_next for (%s)", - ss.str ().c_str ()); + ok ((t == -1 && errno == ENOENT), "avail_time_next for (%s)", ss.str ().c_str ()); ss.str (""); to_stream (-1, 1000, requestC, (const char **)resource_types, len, ss); @@ -403,8 +402,7 @@ static int test_multi_partially_larger () t = planner_multi_avail_time_next (ctx); ok ((t == 5000), "avail_time_next for (%s)", ss.str ().c_str ()); t = planner_multi_avail_time_next (ctx); - ok ((t == -1 && errno == ENOENT), "avail_time_next for (%s)", - ss.str ().c_str ()); + ok ((t == -1 && errno == ENOENT), "avail_time_next for (%s)", ss.str ().c_str ()); planner_multi_destroy (&ctx); return 0; @@ -436,11 +434,9 @@ static int test_multi_many_spans () request[1] = 99 - (i % 100); request[2] = i % 100; - rc = planner_multi_avail_during (ctx, i*1000, 1000, - (const uint64_t *)request, len); + rc = planner_multi_avail_during (ctx, i * 1000, 1000, (const uint64_t *)request, len); bo = (bo || rc); - span = planner_multi_add_span (ctx, i*1000, 1000, - (const uint64_t *)request, len); + span = planner_multi_add_span (ctx, i * 1000, 1000, (const uint64_t *)request, len); bo = (bo || span == -1); } ok (!bo, "many multi_add_spans work"); @@ -450,8 +446,7 @@ static int test_multi_many_spans () t = planner_multi_avail_time_first (ctx, 0, 1000, requestA, len); ok ((t == 1000000), "avail_time_first for (%s)", ss.str ().c_str ()); t = planner_multi_avail_time_next (ctx); - ok ((t == -1) && errno == ENOENT , "avail_time_next for (%s)", - ss.str ().c_str ()); + ok ((t == -1) && errno == ENOENT, "avail_time_next for (%s)", ss.str ().c_str ()); ss.str (""); bo = false; @@ -541,7 +536,6 @@ static int test_multi_add_remove () planner_multi_destroy (&ctx); return 0; - } static int test_constructors_and_overload () @@ -558,8 +552,7 @@ static int test_constructors_and_overload () const uint64_t request3[] = {0, 0, 3, 0, 0}; planner_multi_t *ctx = NULL, *ctx2 = NULL, *ctx3 = NULL, *ctx4 = NULL; - ctx = planner_multi_new (0, INT64_MAX, resource_totals, resource_types, - len); + ctx = planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); planner_multi_add_span (ctx, 0, 1000, request1, len); span = planner_multi_add_span (ctx, 1000, 1000, request2, len); @@ -608,8 +601,9 @@ static int test_constructors_and_overload () bo = (bo || !(planner_multis_equal (ctx, ctx4))); ok (!bo, "copy constructor works on planners with updated state"); - bo = (bo || !(planner_multi_avail_resources_at (ctx, 500, 1) == - planner_multi_avail_resources_at (ctx4, 500, 1))); + bo = (bo + || !(planner_multi_avail_resources_at (ctx, 500, 1) + == planner_multi_avail_resources_at (ctx4, 500, 1))); ok (!bo, "test for avail time equality"); planner_multi_destroy (&ctx); @@ -618,7 +612,6 @@ static int test_constructors_and_overload () planner_multi_destroy (&ctx4); return 0; - } static int test_multi_update () @@ -683,8 +676,7 @@ static int test_multi_update () ok (!bo, "can allocate full added resources"); for (int i = 0; i < planner_multi_resources_len (ctx); ++i) { - if (planner_multi_resource_total_by_type (ctx, resource_types2[i]) - != resource_totals2[i]) { + if (planner_multi_resource_total_by_type (ctx, resource_types2[i]) != resource_totals2[i]) { found = false; break; } @@ -696,18 +688,16 @@ static int test_multi_update () planner_multi_destroy (&ctx2); return 0; - } static int test_partial_cancel () { - bool bo = false, removed = false, removed1 = false, removed2 = false, - removed3 = false, removed4 = false; + bool bo = false, removed = false, removed1 = false, removed2 = false, removed3 = false, + removed4 = false; size_t len = 5; int rc = -1; - int64_t span1 = -1, span2 = -1, span3 = -1, span4 = -1, avail1 = -1, - avail2 = -1, avail3 = -1, avail4 = -1, avail5 = -1, avail6 = -1, - avail7 = -1; + int64_t span1 = -1, span2 = -1, span3 = -1, span4 = -1, avail1 = -1, avail2 = -1, avail3 = -1, + avail4 = -1, avail5 = -1, avail6 = -1, avail7 = -1; const uint64_t resource_totals[] = {10, 20, 30, 40, 50}; const char *resource_types[] = {"A", "B", "C", "D", "E"}; const char *resource_types1[] = {"B", "A", "E"}; @@ -730,43 +720,37 @@ static int test_partial_cancel () span1 = planner_multi_add_span (ctx, 0, 1000, request1, len); span2 = planner_multi_add_span (ctx, 0, 2000, request2, len); - rc = planner_multi_reduce_span (ctx, span1, reduce1, resource_types, - 5, removed); + rc = planner_multi_reduce_span (ctx, span1, reduce1, resource_types, 5, removed); avail1 = planner_multi_avail_resources_at (ctx, 0, 0); bo = (bo || avail1 != 8 || removed || rc != 0); ok (!bo, "reducing span results in expected availability counts and doesn't remove span"); removed = false; - rc = planner_multi_reduce_span (ctx, span1, reduce1, resource_types, - 5, removed); + rc = planner_multi_reduce_span (ctx, span1, reduce1, resource_types, 5, removed); avail1 = planner_multi_avail_resources_at (ctx, 0, 0); bo = (bo || avail1 != 9 || !removed || rc != 0); ok (!bo, "two partial reductions with appropriate removals totally remove span"); removed = false; - rc = planner_multi_reduce_span (ctx, span2, reduce2, resource_types1, - 3, removed); + rc = planner_multi_reduce_span (ctx, span2, reduce2, resource_types1, 3, removed); avail2 = planner_multi_avail_resources_at (ctx, 0, 1); bo = (bo || avail2 != 20 || removed || rc != 0); ok (!bo, "underspecified and reordered reduction types is handled correctly"); removed = false; - rc = planner_multi_reduce_span (ctx, span2, reduce3, resource_types2, - 7, removed); + rc = planner_multi_reduce_span (ctx, span2, reduce3, resource_types2, 7, removed); avail2 = planner_multi_avail_resources_at (ctx, 0, 2); bo = (bo || avail2 != 27 || removed || rc != -1); ok (!bo, "incorrect resource type reduction does not change availability"); removed = false; - rc = planner_multi_reduce_span (ctx, span2, reduce4, resource_types3, - 5, removed); + rc = planner_multi_reduce_span (ctx, span2, reduce4, resource_types3, 5, removed); avail2 = planner_multi_avail_resources_at (ctx, 0, 3); bo = (bo || avail2 != 39 || removed || rc != 0); ok (!bo, "reordered partial reduction results in correct availability"); removed = false; - rc = planner_multi_reduce_span (ctx, span2, reduce5, resource_types4, - 1, removed); + rc = planner_multi_reduce_span (ctx, span2, reduce5, resource_types4, 1, removed); avail2 = planner_multi_avail_resources_at (ctx, 0, 3); bo = (bo || avail2 != 40 || !removed || rc != 0); ok (!bo, "removing final span resource completely removes span"); @@ -777,29 +761,24 @@ static int test_partial_cancel () avail3 = planner_multi_avail_resources_at (ctx, 1000, 2); avail4 = planner_multi_avail_resources_at (ctx, 1000, 3); avail5 = planner_multi_avail_resources_at (ctx, 1000, 4); - bo = (bo || avail1 != 0 || avail2 != 0 || avail3 != 0 || avail4 != 0 - || avail5 != 0 || !removed || rc != 0); + bo = (bo || avail1 != 0 || avail2 != 0 || avail3 != 0 || avail4 != 0 || avail5 != 0 || !removed + || rc != 0); ok (!bo, "can fully allocate resources after partial removals"); span4 = planner_multi_add_span (ctx, 3000, 1000, request3, len); - rc = planner_multi_reduce_span (ctx, span4, reduce5, resource_types5, - 1, removed1); - rc = planner_multi_reduce_span (ctx, span4, reduce5, resource_types5, - 1, removed2); - rc = planner_multi_reduce_span (ctx, span4, reduce5, resource_types6, - 1, removed3); - rc = planner_multi_reduce_span (ctx, span4, reduce5, resource_types6, - 1, removed4); + rc = planner_multi_reduce_span (ctx, span4, reduce5, resource_types5, 1, removed1); + rc = planner_multi_reduce_span (ctx, span4, reduce5, resource_types5, 1, removed2); + rc = planner_multi_reduce_span (ctx, span4, reduce5, resource_types6, 1, removed3); + rc = planner_multi_reduce_span (ctx, span4, reduce5, resource_types6, 1, removed4); avail6 = planner_multi_avail_resources_at (ctx, 3500, 0); avail7 = planner_multi_avail_resources_at (ctx, 3500, 1); - bo = (bo || avail6 != 10 || avail7 != 20 || removed1 || removed2 - || removed3 || !removed4 || rc != 0); + bo = (bo || avail6 != 10 || avail7 != 20 || removed1 || removed2 || removed3 || !removed4 + || rc != 0); ok (!bo, "series of partial removals fully removes span"); planner_multi_destroy (&ctx); return 0; - } int main (int argc, char *argv[]) diff --git a/resource/policies/base/dfu_match_cb.cpp b/resource/policies/base/dfu_match_cb.cpp index 275026e4e..dee8ebff9 100644 --- a/resource/policies/base/dfu_match_cb.cpp +++ b/resource/policies/base/dfu_match_cb.cpp @@ -21,17 +21,13 @@ namespace resource_model { dfu_match_cb_t::dfu_match_cb_t () : m_trav_level (0) { - } -dfu_match_cb_t::dfu_match_cb_t (const std::string &name) - : matcher_data_t (name), m_trav_level (0) +dfu_match_cb_t::dfu_match_cb_t (const std::string &name) : matcher_data_t (name), m_trav_level (0) { - } -dfu_match_cb_t::dfu_match_cb_t (const dfu_match_cb_t &o) - : matcher_data_t (o) +dfu_match_cb_t::dfu_match_cb_t (const dfu_match_cb_t &o) : matcher_data_t (o) { m_trav_level = o.m_trav_level; } @@ -45,63 +41,55 @@ dfu_match_cb_t &dfu_match_cb_t::operator= (const dfu_match_cb_t &o) dfu_match_cb_t::~dfu_match_cb_t () { - } -int dfu_match_cb_t::dom_finish_graph ( - const subsystem_t &subsystem, - const std::vector &resources, - const resource_graph_t &g, - scoring_api_t &dfu) +int dfu_match_cb_t::dom_finish_graph (const subsystem_t &subsystem, + const std::vector &resources, + const resource_graph_t &g, + scoring_api_t &dfu) { return 0; } -int dfu_match_cb_t::dom_finish_slot ( - const subsystem_t &subsystem, - scoring_api_t &dfu) +int dfu_match_cb_t::dom_finish_slot (const subsystem_t &subsystem, scoring_api_t &dfu) { return 0; } -int dfu_match_cb_t::dom_discover_vtx ( - vtx_t u, - const subsystem_t &subsystem, - const std::vector &resources, - const resource_graph_t &g) +int dfu_match_cb_t::dom_discover_vtx (vtx_t u, + const subsystem_t &subsystem, + const std::vector &resources, + const resource_graph_t &g) { m_trav_level++; return 0; } -int dfu_match_cb_t::dom_finish_vtx ( - vtx_t u, - const subsystem_t &subsystem, - const std::vector &resources, - const resource_graph_t &g, - scoring_api_t &dfu) +int dfu_match_cb_t::dom_finish_vtx (vtx_t u, + const subsystem_t &subsystem, + const std::vector &resources, + const resource_graph_t &g, + scoring_api_t &dfu) { m_trav_level--; return 0; } -int dfu_match_cb_t::aux_discover_vtx ( - vtx_t u, - const subsystem_t &subsystem, - const std::vector &resources, - const resource_graph_t &g) +int dfu_match_cb_t::aux_discover_vtx (vtx_t u, + const subsystem_t &subsystem, + const std::vector &resources, + const resource_graph_t &g) { m_trav_level++; return 0; } -int dfu_match_cb_t::aux_finish_vtx ( - vtx_t u, - const subsystem_t &subsystem, - const std::vector &resources, - const resource_graph_t &g, - scoring_api_t &dfu) +int dfu_match_cb_t::aux_finish_vtx (vtx_t u, + const subsystem_t &subsystem, + const std::vector &resources, + const resource_graph_t &g, + scoring_api_t &dfu) { m_trav_level--; return 0; @@ -138,8 +126,8 @@ std::string dfu_match_cb_t::level () return prefix; } -} // resource_model -} // Flux +} // namespace resource_model +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/policies/base/dfu_match_cb.hpp b/resource/policies/base/dfu_match_cb.hpp index c4519751a..69fb56b85 100644 --- a/resource/policies/base/dfu_match_cb.hpp +++ b/resource/policies/base/dfu_match_cb.hpp @@ -29,9 +29,8 @@ namespace resource_model { * Define the set of visitor methods that are called * back by a DFU resource-graph traverser. */ -class dfu_match_cb_t : public matcher_data_t, public matcher_util_api_t -{ -public: +class dfu_match_cb_t : public matcher_data_t, public matcher_util_api_t { + public: dfu_match_cb_t (); dfu_match_cb_t (const std::string &name); dfu_match_cb_t (const dfu_match_cb_t &o); @@ -50,8 +49,7 @@ class dfu_match_cb_t : public matcher_data_t, public matcher_util_api_t * \return return 0 on success; otherwise -1. */ virtual int dom_finish_graph (const subsystem_t &subsystem, - const std::vector< - Flux::Jobspec::Resource> &resources, + const std::vector &resources, const resource_graph_t &g, scoring_api_t &dfu); @@ -60,8 +58,7 @@ class dfu_match_cb_t : public matcher_data_t, public matcher_util_api_t * (resources that can be contained within one or more slots) of the * dominant subsystem. */ - virtual int dom_finish_slot (const subsystem_t &subsystem, - scoring_api_t &dfu); + virtual int dom_finish_slot (const subsystem_t &subsystem, scoring_api_t &dfu); /*! * Called back on each preorder visit of the dominant subsystem. @@ -78,8 +75,7 @@ class dfu_match_cb_t : public matcher_data_t, public matcher_util_api_t */ virtual int dom_discover_vtx (vtx_t u, const subsystem_t &subsystem, - const std::vector< - Flux::Jobspec::Resource> &resources, + const std::vector &resources, const resource_graph_t &g); /*! @@ -100,8 +96,7 @@ class dfu_match_cb_t : public matcher_data_t, public matcher_util_api_t */ virtual int dom_finish_vtx (vtx_t u, const subsystem_t &subsystem, - const std::vector< - Flux::Jobspec::Resource> &resources, + const std::vector &resources, const resource_graph_t &g, scoring_api_t &dfu); @@ -118,8 +113,7 @@ class dfu_match_cb_t : public matcher_data_t, public matcher_util_api_t */ virtual int aux_discover_vtx (vtx_t u, const subsystem_t &subsystem, - const std::vector< - Flux::Jobspec::Resource> &resources, + const std::vector &resources, const resource_graph_t &g); /* @@ -139,8 +133,7 @@ class dfu_match_cb_t : public matcher_data_t, public matcher_util_api_t */ virtual int aux_finish_vtx (vtx_t u, const subsystem_t &subsystem, - const std::vector< - Flux::Jobspec::Resource> &resources, + const std::vector &resources, const resource_graph_t &g, scoring_api_t &dfu); @@ -162,19 +155,18 @@ class dfu_match_cb_t : public matcher_data_t, public matcher_util_api_t */ virtual int get_stop_on_k_matches () const; - void incr (); void decr (); std::string level (); -private: + private: int m_trav_level; }; -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // DFU_MATCH_CB_HPP +#endif // DFU_MATCH_CB_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/policies/base/match_op.h b/resource/policies/base/match_op.h index 4e0a4e5bd..56520aea3 100644 --- a/resource/policies/base/match_op.h +++ b/resource/policies/base/match_op.h @@ -1,34 +1,38 @@ #ifndef MATCH_OP_H #define MATCH_OP_H +typedef enum match_op_t { + MATCH_UNKNOWN, + MATCH_ALLOCATE, + MATCH_ALLOCATE_W_SATISFIABILITY, + MATCH_ALLOCATE_ORELSE_RESERVE, + MATCH_SATISFIABILITY +} match_op_t; -typedef enum match_op_t { MATCH_UNKNOWN, - MATCH_ALLOCATE, - MATCH_ALLOCATE_W_SATISFIABILITY, - MATCH_ALLOCATE_ORELSE_RESERVE, - MATCH_SATISFIABILITY } match_op_t; - -static const char *match_op_to_string (match_op_t match_op) { +static const char *match_op_to_string (match_op_t match_op) +{ switch (match_op) { - case MATCH_ALLOCATE: return "allocate"; - case MATCH_ALLOCATE_ORELSE_RESERVE: return "allocate_orelse_reserve"; - case MATCH_ALLOCATE_W_SATISFIABILITY: return "allocate_with_satisfiability"; - case MATCH_SATISFIABILITY: return "satisfiability"; - default: return "error"; + case MATCH_ALLOCATE: + return "allocate"; + case MATCH_ALLOCATE_ORELSE_RESERVE: + return "allocate_orelse_reserve"; + case MATCH_ALLOCATE_W_SATISFIABILITY: + return "allocate_with_satisfiability"; + case MATCH_SATISFIABILITY: + return "satisfiability"; + default: + return "error"; } } -static bool match_op_valid (match_op_t match_op) { - - if ( (match_op != MATCH_ALLOCATE) && - (match_op != MATCH_ALLOCATE_W_SATISFIABILITY) && - (match_op != MATCH_ALLOCATE_ORELSE_RESERVE) && - (match_op != MATCH_SATISFIABILITY) ) { - +static bool match_op_valid (match_op_t match_op) +{ + if ((match_op != MATCH_ALLOCATE) && (match_op != MATCH_ALLOCATE_W_SATISFIABILITY) + && (match_op != MATCH_ALLOCATE_ORELSE_RESERVE) && (match_op != MATCH_SATISFIABILITY)) { return false; } return true; } -#endif //MATCH_OP_H \ No newline at end of file +#endif // MATCH_OP_H diff --git a/resource/policies/base/matcher.cpp b/resource/policies/base/matcher.cpp index 2446c5063..bed151b9a 100644 --- a/resource/policies/base/matcher.cpp +++ b/resource/policies/base/matcher.cpp @@ -21,19 +21,16 @@ extern "C" { namespace Flux { namespace resource_model { - //////////////////////////////////////////////////////////////////////////////// // Matcher Data Method Definitions //////////////////////////////////////////////////////////////////////////////// matcher_data_t::matcher_data_t () : m_name ("anonymous") { - } matcher_data_t::matcher_data_t (const std::string &name) : m_name (name) { - } matcher_data_t::matcher_data_t (const matcher_data_t &o) @@ -43,7 +40,7 @@ matcher_data_t::matcher_data_t (const matcher_data_t &o) m_subsystems_map = o.m_subsystems_map; } -matcher_data_t &matcher_data_t::operator=(const matcher_data_t &o) +matcher_data_t &matcher_data_t::operator= (const matcher_data_t &o) { m_name = o.m_name; m_subsystems = o.m_subsystems; @@ -85,7 +82,7 @@ const std::vector &matcher_data_t::subsystems () const const subsystem_t &matcher_data_t::dom_subsystem () const { if (m_subsystems.begin () != m_subsystems.end ()) - return *(m_subsystems.begin()); + return *(m_subsystems.begin ()); else return m_err_subsystem; } @@ -95,18 +92,14 @@ const multi_subsystemsS &matcher_data_t::subsystemsS () const return m_subsystems_map; } - - //////////////////////////////////////////////////////////////////////////////// // Matcher Util Method Definitions //////////////////////////////////////////////////////////////////////////////// -unsigned int matcher_util_api_t::calc_count ( - const Flux::Jobspec::Resource &resource, - unsigned int qc) const +unsigned int matcher_util_api_t::calc_count (const Flux::Jobspec::Resource &resource, + unsigned int qc) const { - if (resource.count.min > resource.count.max - || resource.count.min > qc) + if (resource.count.min > resource.count.max || resource.count.min > qc) return 0; unsigned int range = 0; @@ -114,48 +107,45 @@ unsigned int matcher_util_api_t::calc_count ( unsigned int cur = resource.count.min; switch (resource.count.oper) { - case '+': - count = (qc < resource.count.max)? qc : resource.count.max; - range = count - cur; - count -= (range % resource.count.operand); - break; - case '*': - if (resource.count.operand == 1) - count = cur; - else { - while (cur <= qc && cur <= resource.count.max) { + case '+': + count = (qc < resource.count.max) ? qc : resource.count.max; + range = count - cur; + count -= (range % resource.count.operand); + break; + case '*': + if (resource.count.operand == 1) count = cur; - cur *= resource.count.operand; + else { + while (cur <= qc && cur <= resource.count.max) { + count = cur; + cur *= resource.count.operand; + } } - } - break; - case '^': - if (resource.count.operand < 2) - count = cur; - else { - while (cur <= qc && cur <= resource.count.max) { - unsigned int base = cur; + break; + case '^': + if (resource.count.operand < 2) count = cur; - for (int i = 1; - i < resource.count.operand; i++) - cur *= base; + else { + while (cur <= qc && cur <= resource.count.max) { + unsigned int base = cur; + count = cur; + for (int i = 1; i < resource.count.operand; i++) + cur *= base; + } } - } - break; - default: - break; + break; + default: + break; } return count; } -unsigned int matcher_util_api_t::calc_effective_max ( - const Flux::Jobspec::Resource &resource) const +unsigned int matcher_util_api_t::calc_effective_max (const Flux::Jobspec::Resource &resource) const { return calc_count (resource, std::numeric_limits::max ()); } -int matcher_util_api_t::register_resource_pair (const std::string &subsystem, - std::string &r_pair) +int matcher_util_api_t::register_resource_pair (const std::string &subsystem, std::string &r_pair) { int rc = -1; size_t pos = 0; @@ -236,7 +226,7 @@ void matcher_util_api_t::set_pruning_type (const std::string &subsystem, // If prune_type does not exist against ANY_RESOURCE_TYPE // Install it against anchor_type, an individual resource type s[anchor_type].insert (prune_type); - } // orelse NOOP + } // orelse NOOP } else { s[anchor_type].insert (prune_type); } @@ -292,8 +282,7 @@ bool matcher_util_api_t::get_my_pruning_types (const std::string &subsystem, for (auto &k : m) out.push_back (k); } - if (anchor_type != ANY_RESOURCE_TYPE - && s.find (ANY_RESOURCE_TYPE) != s.end ()) { + if (anchor_type != ANY_RESOURCE_TYPE && s.find (ANY_RESOURCE_TYPE) != s.end ()) { auto &m = s.at (ANY_RESOURCE_TYPE); for (auto &k : m) { if (anchor_type != k) @@ -343,9 +332,8 @@ bool matcher_util_api_t::is_resource_type_exclusive (const std::string &type) return m_x_resource_types.find (type) != m_x_resource_types.end (); } - -} // resource_model -} // Flux +} // namespace resource_model +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab */ diff --git a/resource/policies/base/matcher.hpp b/resource/policies/base/matcher.hpp index 8a873baa7..7241f6644 100644 --- a/resource/policies/base/matcher.hpp +++ b/resource/policies/base/matcher.hpp @@ -33,13 +33,12 @@ enum match_score_t { MATCH_UNMET = 0, MATCH_MET = 1 }; * resource relationship types which then allow for filtering the graph * data store for the match callback object. */ -class matcher_data_t -{ -public: +class matcher_data_t { + public: matcher_data_t (); matcher_data_t (const std::string &name); matcher_data_t (const matcher_data_t &o); - matcher_data_t &operator=(const matcher_data_t &o); + matcher_data_t &operator= (const matcher_data_t &o); ~matcher_data_t (); /*! Add a subsystem and the relationship type that this resource base @@ -75,20 +74,17 @@ class matcher_data_t */ const multi_subsystemsS &subsystemsS () const; -private: + private: std::string m_name; subsystem_t m_err_subsystem = "error"; std::vector m_subsystems; multi_subsystemsS m_subsystems_map; }; - /*! Base utility method for matchers. */ -class matcher_util_api_t -{ -public: - +class matcher_util_api_t { + public: /*! Calculate the count that should be allocated, which is a function * of the number of qualifed available resources, minimum/maximum/operator * requirement of the jobspec. @@ -97,17 +93,14 @@ class matcher_util_api_t * \param qual_cnt available qualified resources. * \return 0 when not available; count otherwise. */ - unsigned int calc_count (const Flux::Jobspec::Resource &resource, - unsigned int qual_cnt) const; + unsigned int calc_count (const Flux::Jobspec::Resource &resource, unsigned int qual_cnt) const; /*! Calculate the effective max count that should be allocated. * * \param resource resource section of the jobspec. * \return Effective max count; 0 if an error is encountered. */ - unsigned int calc_effective_max ( - const Flux::Jobspec::Resource &resource) const; - + unsigned int calc_effective_max (const Flux::Jobspec::Resource &resource) const; /*! Set prune filters based on spec. The spec should comply with * the following format: @@ -127,8 +120,7 @@ class matcher_util_api_t * \param subsystem subsystem * \param spec prune filter specification string */ - int set_pruning_types_w_spec (const std::string &subsystem, - const std::string &spec); + int set_pruning_types_w_spec (const std::string &subsystem, const std::string &spec); void set_pruning_type (const std::string &subsystem, const std::string &anchor_type, @@ -138,9 +130,7 @@ class matcher_util_api_t const std::string &anchor_type, const std::string &prune_type); - bool is_pruning_type (const std::string &subsystem, - const std::string &prune_type); - + bool is_pruning_type (const std::string &subsystem, const std::string &prune_type); bool get_my_pruning_types (const std::string &subsystem, const std::string &anchor_type, @@ -154,10 +144,8 @@ class matcher_util_api_t int reset_exclusive_resource_types (const std::set &x_types); -private: - - int register_resource_pair (const std::string &subsystem, - std::string &r_pair); + private: + int register_resource_pair (const std::string &subsystem, std::string &r_pair); std::set m_x_resource_types; @@ -169,15 +157,14 @@ class matcher_util_api_t // m_pruing_type["containment"][ANY_RESOURCE_TYPE] -> {"core"} // in the containment subsystem at any level, please // maintain an aggregate on the available cores under it. - std::map>> m_pruning_types; + std::map>> m_pruning_types; std::map> m_total_set; }; -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // MATCHER_DATA_HPP +#endif // MATCHER_DATA_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/policies/base/test/matcher_util_api_test01.cpp b/resource/policies/base/test/matcher_util_api_test01.cpp index d1544c626..789e070d6 100644 --- a/resource/policies/base/test/matcher_util_api_test01.cpp +++ b/resource/policies/base/test/matcher_util_api_test01.cpp @@ -24,36 +24,34 @@ using namespace Flux; using namespace Flux::Jobspec; using namespace Flux::resource_model; - - //////////////////////////////////////////////////////////////////////////////// // Test Jobspec Template Class //////////////////////////////////////////////////////////////////////////////// class test_jobspec_template { -public: + public: explicit test_jobspec_template (unsigned int min); explicit test_jobspec_template (unsigned int min, unsigned int max); - explicit test_jobspec_template (unsigned int min, unsigned int max, - std::string oper); - explicit test_jobspec_template (unsigned int min, unsigned int max, - std::string oper, unsigned int op); + explicit test_jobspec_template (unsigned int min, unsigned int max, std::string oper); + explicit test_jobspec_template (unsigned int min, + unsigned int max, + std::string oper, + unsigned int op); const std::string &get () const; -private: + private: int emit (json_t *count_obj); json_t *emit_count (unsigned int min); json_t *emit_count (unsigned int min, unsigned int max); - json_t *emit_count (unsigned int min, unsigned int max, - const std::string &oper); - json_t *emit_count (unsigned int min, unsigned int max, - const std::string &oper, unsigned int op); + json_t *emit_count (unsigned int min, unsigned int max, const std::string &oper); + json_t *emit_count (unsigned int min, + unsigned int max, + const std::string &oper, + unsigned int op); std::string m_job_spec_string = ""; }; - - //////////////////////////////////////////////////////////////////////////////// // Private Test Jobspec Template Class Methods //////////////////////////////////////////////////////////////////////////////// @@ -64,32 +62,43 @@ int test_jobspec_template::emit (json_t *count_obj) json_t *tasks_obj{nullptr}; char *json_str{nullptr}; - if ( (tasks_obj = json_pack ("[{s:[s] s:s s:{s:i}}]", - "command", "app", - "slot", "foo", - "count", - "per_slot", 1)) == nullptr) { + if ((tasks_obj = json_pack ("[{s:[s] s:s s:{s:i}}]", + "command", + "app", + "slot", + "foo", + "count", + "per_slot", + 1)) + == nullptr) { errno = ENOMEM; return -1; } - if ( (obj = json_pack ( - "{s:i s:[{s:s s:s s:o s:[{s:s s:i}]}] s:o s:{}}", - "version", 9999, - "resources", - "type", "slot", - "label", "foo", - "count", count_obj, - "with", - "type", "node", - "count", 1, - "tasks", tasks_obj, - "attributes")) == nullptr) { + if ((obj = json_pack ("{s:i s:[{s:s s:s s:o s:[{s:s s:i}]}] s:o s:{}}", + "version", + 9999, + "resources", + "type", + "slot", + "label", + "foo", + "count", + count_obj, + "with", + "type", + "node", + "count", + 1, + "tasks", + tasks_obj, + "attributes")) + == nullptr) { errno = ENOMEM; return -1; } - if ( (json_str = json_dumps (obj, JSON_INDENT (0))) == nullptr) { + if ((json_str = json_dumps (obj, JSON_INDENT (0))) == nullptr) { errno = ENOMEM; return -1; } @@ -110,24 +119,29 @@ json_t *test_jobspec_template::emit_count (unsigned int min, unsigned int max) return json_pack ("{s:i s:i}", "min", min, "max", max); } -json_t *test_jobspec_template::emit_count (unsigned int min, unsigned int max, +json_t *test_jobspec_template::emit_count (unsigned int min, + unsigned int max, const std::string &oper) { - return json_pack ("{s:i s:i s:s}", - "min", min, "max", max, "operator", oper.c_str ()); + return json_pack ("{s:i s:i s:s}", "min", min, "max", max, "operator", oper.c_str ()); } -json_t *test_jobspec_template::emit_count (unsigned int min, unsigned int max, +json_t *test_jobspec_template::emit_count (unsigned int min, + unsigned int max, const std::string &oper, unsigned int op) { return json_pack ("{s:i s:I s:s s:i}", - "min", min, "max", (json_int_t)max, - "operator", oper.c_str (), "operand", op); + "min", + min, + "max", + (json_int_t)max, + "operator", + oper.c_str (), + "operand", + op); } - - //////////////////////////////////////////////////////////////////////////////// // Public Test Jobspec Template Class Methods //////////////////////////////////////////////////////////////////////////////// @@ -135,19 +149,18 @@ json_t *test_jobspec_template::emit_count (unsigned int min, unsigned int max, test_jobspec_template::test_jobspec_template (unsigned int min) { json_t *count_obj{nullptr}; - if ( (count_obj = emit_count (min)) == nullptr) + if ((count_obj = emit_count (min)) == nullptr) throw std::bad_alloc (); - if ( (emit (count_obj)) < 0) + if ((emit (count_obj)) < 0) throw std::bad_alloc (); } -test_jobspec_template::test_jobspec_template (unsigned int min, - unsigned int max) +test_jobspec_template::test_jobspec_template (unsigned int min, unsigned int max) { json_t *count_obj{nullptr}; - if ( (count_obj = emit_count (min, max)) == nullptr) + if ((count_obj = emit_count (min, max)) == nullptr) throw std::bad_alloc (); - if ( (emit (count_obj)) < 0) + if ((emit (count_obj)) < 0) throw std::bad_alloc (); } @@ -157,20 +170,18 @@ test_jobspec_template::test_jobspec_template (unsigned int min, unsigned int op) { json_t *count_obj{nullptr}; - if ( (count_obj = emit_count (min, max, oper, op)) == nullptr) + if ((count_obj = emit_count (min, max, oper, op)) == nullptr) throw std::bad_alloc (); - if ( (emit (count_obj)) < 0) + if ((emit (count_obj)) < 0) throw std::bad_alloc (); } -test_jobspec_template::test_jobspec_template (unsigned int min, - unsigned int max, - std::string oper) +test_jobspec_template::test_jobspec_template (unsigned int min, unsigned int max, std::string oper) { json_t *count_obj{nullptr}; - if ( (count_obj = emit_count (min, max, oper)) == nullptr) + if ((count_obj = emit_count (min, max, oper)) == nullptr) throw std::bad_alloc (); - if ( (emit (count_obj)) < 0) + if ((emit (count_obj)) < 0) throw std::bad_alloc (); } @@ -179,8 +190,6 @@ const std::string &test_jobspec_template::get () const return m_job_spec_string; } - - //////////////////////////////////////////////////////////////////////////////// // Test Routines //////////////////////////////////////////////////////////////////////////////// @@ -190,87 +199,70 @@ void test_plus_op () unsigned int count = 0; matcher_util_api_t api; - // {min=1, max=10, operator='+', operand=1} test_jobspec_template jobin_001 (1, 10); Flux::Jobspec::Jobspec job_001{jobin_001.get ()}; - count = api.calc_count (job_001.resources[0], - std::numeric_limits::max ()); + count = api.calc_count (job_001.resources[0], std::numeric_limits::max ()); ok (count == 10, "{min=1, max=10, oper='+', op=1} is 10"); count = api.calc_count (job_001.resources[0], 5); ok (count == 5, "{min=1, max=10, oper='+', op=1} w/ qc=5 is 5"); - // {min=1, max=10, operator='+', operand=2} test_jobspec_template jobin_002 (1, 10, "+", 2); Flux::Jobspec::Jobspec job_002{jobin_002.get ()}; - count = api.calc_count (job_002.resources[0], - std::numeric_limits::max ()); + count = api.calc_count (job_002.resources[0], std::numeric_limits::max ()); ok (count == 9, "{min=1, max=10, oper='+', op=2} is 9"); count = api.calc_count (job_002.resources[0], 5); ok (count == 5, "{min=1, max=10, oper='+', op=2} w/ qc=5 is 5"); - // {min=1, max=10, operator='+', operand=3} test_jobspec_template jobin_003 (1, 10, "+", 3); Flux::Jobspec::Jobspec job_003{jobin_003.get ()}; - count = api.calc_count (job_003.resources[0], - std::numeric_limits::max ()); + count = api.calc_count (job_003.resources[0], std::numeric_limits::max ()); ok (count == 10, "{min=1, max=10, oper='+', op=3} is 10"); count = api.calc_count (job_003.resources[0], 5); ok (count == 4, "{min=1, max=10, oper='+', op=3} w/ qc=5 is 4"); - // {min=1, max=10, operator='+', operand=5} test_jobspec_template jobin_004 (1, 10, "+", 5); Flux::Jobspec::Jobspec job_004{jobin_004.get ()}; - count = api.calc_count (job_004.resources[0], - std::numeric_limits::max ()); + count = api.calc_count (job_004.resources[0], std::numeric_limits::max ()); ok (count == 6, "{min=1, max=10, oper='+', op=5} is 6"); count = api.calc_count (job_004.resources[0], 5); ok (count == 1, "{min=1, max=10, oper='+', op=5} w/ qc=5 is 1"); - // {min=1, max=10, operator='+', operand=10} test_jobspec_template jobin_005 (1, 10, "+", 10); Flux::Jobspec::Jobspec job_005{jobin_005.get ()}; - count = api.calc_count (job_005.resources[0], - std::numeric_limits::max ()); + count = api.calc_count (job_005.resources[0], std::numeric_limits::max ()); ok (count == 1, "{min=1, max=10, oper='+', op=10} is 1"); count = api.calc_count (job_005.resources[0], 5); ok (count == 1, "{min=1, max=10, oper='+', op=10} w/ qc=5 is 1"); - // {min=1, max=4294967295, operator='+', operand=1} test_jobspec_template jobin_006 (1, 4294967295, "+", 1); Flux::Jobspec::Jobspec job_006{jobin_006.get ()}; - count = api.calc_count (job_006.resources[0], - std::numeric_limits::max ()); - ok (count == 4294967295, - "{min=1, max=4294967295, oper='+', op=1} is 4294967295"); - + count = api.calc_count (job_006.resources[0], std::numeric_limits::max ()); + ok (count == 4294967295, "{min=1, max=4294967295, oper='+', op=1} is 4294967295"); // {min=2, max=4294967295, operator='+', operand=2} test_jobspec_template jobin_007 (2, 4294967295, "+", 2); Flux::Jobspec::Jobspec job_007{jobin_007.get ()}; - count = api.calc_count (job_007.resources[0], - std::numeric_limits::max ()); - ok (count == 4294967294, - "{min=1, max=4294967295, oper='+', op=2} is 4294967294"); + count = api.calc_count (job_007.resources[0], std::numeric_limits::max ()); + ok (count == 4294967294, "{min=1, max=4294967295, oper='+', op=2} is 4294967294"); } - int main (int argc, char *argv[]) { plan (12); diff --git a/resource/policies/dfu_match_high_id_first.hpp b/resource/policies/dfu_match_high_id_first.hpp index fd6cdc5e1..94f83d802 100644 --- a/resource/policies/dfu_match_high_id_first.hpp +++ b/resource/policies/dfu_match_high_id_first.hpp @@ -22,10 +22,10 @@ namespace resource_model { */ using high_first_t = multilevel_id_t; -} // resource_model -} // Flux +} // namespace resource_model +} // namespace Flux -#endif // DFU_MATCH_HIGH_ID_FIRST_HPP +#endif // DFU_MATCH_HIGH_ID_FIRST_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/policies/dfu_match_locality.cpp b/resource/policies/dfu_match_locality.cpp index 5bc07fbb3..44ac35050 100644 --- a/resource/policies/dfu_match_locality.cpp +++ b/resource/policies/dfu_match_locality.cpp @@ -21,24 +21,18 @@ namespace resource_model { greater_interval_first_t::greater_interval_first_t () { - } -greater_interval_first_t::greater_interval_first_t (const std::string &name) - : dfu_match_cb_t (name) +greater_interval_first_t::greater_interval_first_t (const std::string &name) : dfu_match_cb_t (name) { - } -greater_interval_first_t::greater_interval_first_t ( - const greater_interval_first_t &o) +greater_interval_first_t::greater_interval_first_t (const greater_interval_first_t &o) : dfu_match_cb_t (o) { - } -greater_interval_first_t &greater_interval_first_t::operator= ( - const greater_interval_first_t &o) +greater_interval_first_t &greater_interval_first_t::operator= (const greater_interval_first_t &o) { dfu_match_cb_t::operator= (o); return *this; @@ -46,13 +40,13 @@ greater_interval_first_t &greater_interval_first_t::operator= ( greater_interval_first_t::~greater_interval_first_t () { - } int greater_interval_first_t::dom_finish_graph ( const subsystem_t &subsystem, const std::vector &resources, - const resource_graph_t &g, scoring_api_t &dfu) + const resource_graph_t &g, + scoring_api_t &dfu) { using namespace boost::icl; int score = MATCH_MET; @@ -66,18 +60,17 @@ int greater_interval_first_t::dom_finish_graph ( score = MATCH_UNMET; break; } - dfu.transform (subsystem, type, + dfu.transform (subsystem, + type, boost::icl::inserter (comp.ivset, comp.ivset.end ()), fold::to_interval); dfu.choose_accum_best_k (subsystem, type, count, comp); } dfu.set_overall_score (score); - return (score == MATCH_MET)? 0 : -1; + return (score == MATCH_MET) ? 0 : -1; } -int greater_interval_first_t::dom_finish_slot ( - const subsystem_t &subsystem, - scoring_api_t &dfu) +int greater_interval_first_t::dom_finish_slot (const subsystem_t &subsystem, scoring_api_t &dfu) { std::vector types; dfu.resrc_types (subsystem, types); @@ -86,11 +79,11 @@ int greater_interval_first_t::dom_finish_slot ( return 0; } -int greater_interval_first_t::dom_finish_vtx ( - vtx_t u, - const subsystem_t &subsystem, - const std::vector &resources, - const resource_graph_t &g, scoring_api_t &dfu) +int greater_interval_first_t::dom_finish_vtx (vtx_t u, + const subsystem_t &subsystem, + const std::vector &resources, + const resource_graph_t &g, + scoring_api_t &dfu) { int64_t score = MATCH_MET; int64_t overall; @@ -113,14 +106,14 @@ int greater_interval_first_t::dom_finish_vtx ( } } - overall = (score == MATCH_MET)? (score + g[u].id + 1) : score; + overall = (score == MATCH_MET) ? (score + g[u].id + 1) : score; dfu.set_overall_score (overall); decr (); - return (score == MATCH_MET)? 0 : -1; + return (score == MATCH_MET) ? 0 : -1; } -} // resource_model -} // Flux +} // namespace resource_model +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/policies/dfu_match_locality.hpp b/resource/policies/dfu_match_locality.hpp index bc574a5d1..8991c2e76 100644 --- a/resource/policies/dfu_match_locality.hpp +++ b/resource/policies/dfu_match_locality.hpp @@ -25,8 +25,7 @@ namespace resource_model { /*! Locality-aware policy: select resources of each type * where you have more qualified. */ -struct greater_interval_first_t : public dfu_match_cb_t -{ +struct greater_interval_first_t : public dfu_match_cb_t { greater_interval_first_t (); greater_interval_first_t (const std::string &name); greater_interval_first_t (const greater_interval_first_t &o); @@ -35,19 +34,22 @@ struct greater_interval_first_t : public dfu_match_cb_t int dom_finish_graph (const subsystem_t &subsystem, const std::vector &resources, - const resource_graph_t &g, scoring_api_t &dfu); + const resource_graph_t &g, + scoring_api_t &dfu); - int dom_finish_vtx (vtx_t u, const subsystem_t &subsystem, + int dom_finish_vtx (vtx_t u, + const subsystem_t &subsystem, const std::vector &resources, - const resource_graph_t &g, scoring_api_t &dfu); + const resource_graph_t &g, + scoring_api_t &dfu); int dom_finish_slot (const subsystem_t &subsystem, scoring_api_t &dfu); }; -} -} +} // namespace resource_model +} // namespace Flux -#endif //DFU_MATCH_LOCALITY_HPP +#endif // DFU_MATCH_LOCALITY_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/policies/dfu_match_low_id_first.hpp b/resource/policies/dfu_match_low_id_first.hpp index 313e01274..3d7b1da8d 100644 --- a/resource/policies/dfu_match_low_id_first.hpp +++ b/resource/policies/dfu_match_low_id_first.hpp @@ -22,10 +22,10 @@ namespace resource_model { */ using low_first_t = multilevel_id_t; -} // resource_model -} // Flux +} // namespace resource_model +} // namespace Flux -#endif // DFU_MATCH_LOW_ID_FIRST_HPP +#endif // DFU_MATCH_LOW_ID_FIRST_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/policies/dfu_match_multilevel_id.hpp b/resource/policies/dfu_match_multilevel_id.hpp index d9c4a9bce..35c08c05c 100644 --- a/resource/policies/dfu_match_multilevel_id.hpp +++ b/resource/policies/dfu_match_multilevel_id.hpp @@ -28,10 +28,8 @@ namespace resource_model { * resource. */ template -class multilevel_id_t : public dfu_match_cb_t -{ -public: - +class multilevel_id_t : public dfu_match_cb_t { + public: multilevel_id_t (); multilevel_id_t (const std::string &name); multilevel_id_t (const multilevel_id_t &o); @@ -43,7 +41,8 @@ class multilevel_id_t : public dfu_match_cb_t */ int dom_finish_graph (const subsystem_t &subsystem, const std::vector &resources, - const resource_graph_t &g, scoring_api_t &dfu); + const resource_graph_t &g, + scoring_api_t &dfu); /*! Please see its overriding method within * dfu_match_cb_t@base/dfu_match_cb.hpp @@ -61,9 +60,11 @@ class multilevel_id_t : public dfu_match_cb_t /*! Please see its overriding method within * dfu_match_cb_t@base/dfu_match_cb.hpp */ - int dom_finish_vtx (vtx_t u, const subsystem_t &subsystem, + int dom_finish_vtx (vtx_t u, + const subsystem_t &subsystem, const std::vector &resources, - const resource_graph_t &g, scoring_api_t &dfu); + const resource_graph_t &g, + scoring_api_t &dfu); /*! Please see its overriding method within * dfu_match_cb_t@base/dfu_match_cb.hpp @@ -96,21 +97,18 @@ class multilevel_id_t : public dfu_match_cb_t * EEXIST: type already has been added; * ENOMEM: out of memory. */ - int add_score_factor (const std::string &type, - unsigned add_by, unsigned multiply_by); + int add_score_factor (const std::string &type, unsigned add_by, unsigned multiply_by); -private: + private: class score_factor_t { - public: + public: score_factor_t () = default; - score_factor_t (const std::string &type, - unsigned int add_by, - unsigned int multiply_by); + score_factor_t (const std::string &type, unsigned int add_by, unsigned int multiply_by); score_factor_t (const score_factor_t &o) = default; int64_t calc_factor (int64_t base_factor, int64_t break_tie); int64_t m_factor = 0; - private: + private: std::string m_type; unsigned int m_add_by = 0; unsigned int m_multiply_by = 1; @@ -124,10 +122,10 @@ class multilevel_id_t : public dfu_match_cb_t std::unordered_map m_multilevel_factors; }; -} // resource_model -} // Flux +} // namespace resource_model +} // namespace Flux -#endif // DFU_MATCH_MULTILEVEL_ID_HPP +#endif // DFU_MATCH_MULTILEVEL_ID_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/policies/dfu_match_multilevel_id_impl.hpp b/resource/policies/dfu_match_multilevel_id_impl.hpp index b5de20966..ea29f847b 100644 --- a/resource/policies/dfu_match_multilevel_id_impl.hpp +++ b/resource/policies/dfu_match_multilevel_id_impl.hpp @@ -17,8 +17,6 @@ namespace Flux { namespace resource_model { - - //////////////////////////////////////////////////////////////////////////////// // MultiLevel ID Match Policy Class's Private Method Definitions //////////////////////////////////////////////////////////////////////////////// @@ -29,13 +27,10 @@ multilevel_id_t::score_factor_t::score_factor_t (const std::string &type, unsigned multiple_by) : m_type (type), m_add_by (add_by), m_multiply_by (multiple_by) { - } template -int64_t multilevel_id_t::score_factor_t::calc_factor ( - int64_t base_factor, - int64_t break_tie) +int64_t multilevel_id_t::score_factor_t::calc_factor (int64_t base_factor, int64_t break_tie) { int64_t add, mul, tie; if (base_factor < 0 || break_tie < 0) { @@ -64,8 +59,6 @@ int64_t multilevel_id_t::score_factor_t::calc_factor ( return m_factor; } - - //////////////////////////////////////////////////////////////////////////////// // MultiLevel ID Match Policy Class's Public Method Definitions //////////////////////////////////////////////////////////////////////////////// @@ -73,19 +66,15 @@ int64_t multilevel_id_t::score_factor_t::calc_factor ( template multilevel_id_t::multilevel_id_t () { - } template -multilevel_id_t::multilevel_id_t (const std::string &name) - : dfu_match_cb_t (name) +multilevel_id_t::multilevel_id_t (const std::string &name) : dfu_match_cb_t (name) { - } template -multilevel_id_t::multilevel_id_t (const multilevel_id_t &o) - : dfu_match_cb_t (o) +multilevel_id_t::multilevel_id_t (const multilevel_id_t &o) : dfu_match_cb_t (o) { m_stop_on_k_matches = o.m_stop_on_k_matches; m_multilevel_scores = o.m_multilevel_scores; @@ -93,8 +82,7 @@ multilevel_id_t::multilevel_id_t (const multilevel_id_t &o) } template -multilevel_id_t &multilevel_id_t::operator= ( - const multilevel_id_t &o) +multilevel_id_t &multilevel_id_t::operator= (const multilevel_id_t &o) { dfu_match_cb_t::operator= (o); m_stop_on_k_matches = o.m_stop_on_k_matches; @@ -106,16 +94,13 @@ multilevel_id_t &multilevel_id_t::operator= ( template multilevel_id_t::~multilevel_id_t () { - } template -int multilevel_id_t::dom_finish_graph ( - const subsystem_t &subsystem, - const std::vector< - Flux::Jobspec::Resource> &resources, - const resource_graph_t &g, - scoring_api_t &dfu) +int multilevel_id_t::dom_finish_graph (const subsystem_t &subsystem, + const std::vector &resources, + const resource_graph_t &g, + scoring_api_t &dfu) { int64_t score = MATCH_MET; for (auto &resource : resources) { @@ -130,12 +115,11 @@ int multilevel_id_t::dom_finish_graph ( } dfu.set_overall_score (score); m_multilevel_scores = 0; - return (score == MATCH_MET)? 0 : -1; + return (score == MATCH_MET) ? 0 : -1; } template -int multilevel_id_t::dom_finish_slot (const subsystem_t &subsystem, - scoring_api_t &dfu) +int multilevel_id_t::dom_finish_slot (const subsystem_t &subsystem, scoring_api_t &dfu) { std::vector types; dfu.resrc_types (subsystem, types); @@ -145,18 +129,16 @@ int multilevel_id_t::dom_finish_slot (const subsystem_t &subsystem, } template -int multilevel_id_t::dom_discover_vtx ( - vtx_t u, - const subsystem_t &subsystem, - const std::vector< - Flux::Jobspec::Resource> &resources, - const resource_graph_t &g) +int multilevel_id_t::dom_discover_vtx (vtx_t u, + const subsystem_t &subsystem, + const std::vector &resources, + const resource_graph_t &g) { if (m_multilevel_factors.find (g[u].type) != m_multilevel_factors.end ()) { if (g[u].id < -1) return -1; auto &f = m_multilevel_factors[g[u].type]; - int64_t factor = f.calc_factor (g[u].id+1, g[u].uniq_id); + int64_t factor = f.calc_factor (g[u].id + 1, g[u].uniq_id); if (factor < 0) return factor; m_multilevel_scores += factor; @@ -166,13 +148,11 @@ int multilevel_id_t::dom_discover_vtx ( } template -int multilevel_id_t::dom_finish_vtx ( - vtx_t u, - const subsystem_t &subsystem, - const std::vector< - Flux::Jobspec::Resource> &resources, - const resource_graph_t &g, - scoring_api_t &dfu) +int multilevel_id_t::dom_finish_vtx (vtx_t u, + const subsystem_t &subsystem, + const std::vector &resources, + const resource_graph_t &g, + scoring_api_t &dfu) { int64_t score = MATCH_MET; int64_t overall; @@ -198,11 +178,10 @@ int multilevel_id_t::dom_finish_vtx ( if (factor != m_multilevel_factors.end ()) m_multilevel_scores -= factor->second.m_factor; - overall = (score == MATCH_MET)? (score + m_multilevel_scores - + g[u].id + 1) : score; + overall = (score == MATCH_MET) ? (score + m_multilevel_scores + g[u].id + 1) : score; dfu.set_overall_score (overall); decr (); - return (score == MATCH_MET)? 0 : -1; + return (score == MATCH_MET) ? 0 : -1; } template @@ -231,8 +210,7 @@ int multilevel_id_t::add_score_factor (const std::string &type, return -1; } auto ret = m_multilevel_factors.insert ( - std::pair ( - type, {type, add_by, multiple_by})); + std::pair (type, {type, add_by, multiple_by})); if (!ret.second) { errno = ENOMEM; return -1; @@ -244,10 +222,10 @@ int multilevel_id_t::add_score_factor (const std::string &type, } } -} // resource_model -} // Flux +} // namespace resource_model +} // namespace Flux -#endif // DFU_MATCH_MULTILEVEL_ID_IMPL_HPP +#endif // DFU_MATCH_MULTILEVEL_ID_IMPL_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/policies/dfu_match_policy_factory.cpp b/resource/policies/dfu_match_policy_factory.cpp index 73f934784..7fe675aa0 100644 --- a/resource/policies/dfu_match_policy_factory.cpp +++ b/resource/policies/dfu_match_policy_factory.cpp @@ -23,11 +23,10 @@ namespace resource_model { bool known_match_policy (const std::string &policy) { bool rc = true; - if (policy != FIRST_MATCH && policy != FIRST_NODEX_MATCH - && policy != HIGH_ID_FIRST && policy != LOW_ID_FIRST - && policy != LOW_NODE_FIRST && policy != HIGH_NODE_FIRST - && policy != LOW_NODEX_FIRST && policy != HIGH_NODEX_FIRST - && policy != LOCALITY_AWARE && policy != VAR_AWARE) + if (policy != FIRST_MATCH && policy != FIRST_NODEX_MATCH && policy != HIGH_ID_FIRST + && policy != LOW_ID_FIRST && policy != LOW_NODE_FIRST && policy != HIGH_NODE_FIRST + && policy != LOW_NODEX_FIRST && policy != HIGH_NODEX_FIRST && policy != LOCALITY_AWARE + && policy != VAR_AWARE) rc = false; return rc; @@ -39,30 +38,27 @@ std::shared_ptr create_match_cb (const std::string &policy) try { if (policy == FIRST_MATCH || policy == FIRST_NODEX_MATCH) { - std::shared_ptr ptr - = std::make_shared (); + std::shared_ptr ptr = std::make_shared (); ptr->add_score_factor (std::string ("node"), 1, 10000); ptr->set_stop_on_k_matches (1); if (policy == FIRST_NODEX_MATCH) - ptr->add_exclusive_resource_type ("node"); + ptr->add_exclusive_resource_type ("node"); matcher = ptr; } else if (policy == HIGH_ID_FIRST) { matcher = std::make_shared (); } else if (policy == LOW_ID_FIRST) { matcher = std::make_shared (); } else if (policy == LOW_NODE_FIRST || policy == LOW_NODEX_FIRST) { - std::shared_ptr ptr - = std::make_shared (); + std::shared_ptr ptr = std::make_shared (); ptr->add_score_factor (std::string ("node"), 1, 10000); if (policy == LOW_NODEX_FIRST) - ptr->add_exclusive_resource_type ("node"); + ptr->add_exclusive_resource_type ("node"); matcher = ptr; } else if (policy == HIGH_NODE_FIRST || policy == HIGH_NODEX_FIRST) { - std::shared_ptr ptr - = std::make_shared (); + std::shared_ptr ptr = std::make_shared (); ptr->add_score_factor (std::string ("node"), 1, 10000); if (policy == HIGH_NODEX_FIRST) - ptr->add_exclusive_resource_type ("node"); + ptr->add_exclusive_resource_type ("node"); matcher = ptr; } else if (policy == LOCALITY_AWARE) { matcher = std::make_shared (); @@ -77,8 +73,8 @@ std::shared_ptr create_match_cb (const std::string &policy) return matcher; } -} // resource_model -} // Flux +} // namespace resource_model +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/policies/dfu_match_policy_factory.hpp b/resource/policies/dfu_match_policy_factory.hpp index 59742e5a2..5fbbed0f8 100644 --- a/resource/policies/dfu_match_policy_factory.hpp +++ b/resource/policies/dfu_match_policy_factory.hpp @@ -42,10 +42,10 @@ bool known_match_policy (const std::string &policy); */ std::shared_ptr create_match_cb (const std::string &policy); -} // resource_model -} // Flux +} // namespace resource_model +} // namespace Flux -#endif // DFU_MATCH_POLICY_FACTORY_HPP +#endif // DFU_MATCH_POLICY_FACTORY_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/policies/dfu_match_var_aware.cpp b/resource/policies/dfu_match_var_aware.cpp index 43431b958..5b7b009d3 100644 --- a/resource/policies/dfu_match_var_aware.cpp +++ b/resource/policies/dfu_match_var_aware.cpp @@ -21,24 +21,17 @@ namespace resource_model { var_aware_t::var_aware_t () { - } -var_aware_t::var_aware_t (const std::string &name) - : dfu_match_cb_t (name) +var_aware_t::var_aware_t (const std::string &name) : dfu_match_cb_t (name) { - } -var_aware_t::var_aware_t ( - const var_aware_t &o) - : dfu_match_cb_t (o) +var_aware_t::var_aware_t (const var_aware_t &o) : dfu_match_cb_t (o) { - } -var_aware_t &var_aware_t::operator= ( - const var_aware_t &o) +var_aware_t &var_aware_t::operator= (const var_aware_t &o) { dfu_match_cb_t::operator= (o); return *this; @@ -46,13 +39,12 @@ var_aware_t &var_aware_t::operator= ( var_aware_t::~var_aware_t () { - } -int var_aware_t::dom_finish_graph ( - const subsystem_t &subsystem, - const std::vector &resources, - const resource_graph_t &g, scoring_api_t &dfu) +int var_aware_t::dom_finish_graph (const subsystem_t &subsystem, + const std::vector &resources, + const resource_graph_t &g, + scoring_api_t &dfu) { int score = MATCH_MET; fold::less comp; @@ -68,12 +60,10 @@ int var_aware_t::dom_finish_graph ( dfu.choose_accum_best_k (subsystem, type, count, comp); } dfu.set_overall_score (score); - return (score == MATCH_MET)? 0 : -1; + return (score == MATCH_MET) ? 0 : -1; } -int var_aware_t::dom_finish_slot ( - const subsystem_t &subsystem, - scoring_api_t &dfu) +int var_aware_t::dom_finish_slot (const subsystem_t &subsystem, scoring_api_t &dfu) { std::vector types; dfu.resrc_types (subsystem, types); @@ -82,11 +72,11 @@ int var_aware_t::dom_finish_slot ( return 0; } -int var_aware_t::dom_finish_vtx ( - vtx_t u, - const subsystem_t &subsystem, - const std::vector &resources, - const resource_graph_t &g, scoring_api_t &dfu) +int var_aware_t::dom_finish_vtx (vtx_t u, + const subsystem_t &subsystem, + const std::vector &resources, + const resource_graph_t &g, + scoring_api_t &dfu) { int64_t score = MATCH_MET; int64_t overall; @@ -116,28 +106,26 @@ int var_aware_t::dom_finish_vtx ( if (score == MATCH_MET) { try { perf_class = std::stoi (g[u].properties.at ("perf_class")); - } - catch (const std::out_of_range& oor) { + } catch (const std::out_of_range &oor) { perf_class = 9999; - } - catch (const std::invalid_argument& ia) { + } catch (const std::invalid_argument &ia) { perf_class = 9999; } /* Ensure we don't have negative or more than - * 9999 performance classes so we have clear boundaries. */ + * 9999 performance classes so we have clear boundaries. */ if (perf_class < 0 || perf_class > 9999) { perf_class = 9999; } } - overall = (score == MATCH_MET)? (score + perf_class) : score; + overall = (score == MATCH_MET) ? (score + perf_class) : score; dfu.set_overall_score (overall); decr (); - return (score == MATCH_MET)? 0 : -1; + return (score == MATCH_MET) ? 0 : -1; } -} // resource_model -} // Flux +} // namespace resource_model +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/policies/dfu_match_var_aware.hpp b/resource/policies/dfu_match_var_aware.hpp index 626d30051..413d78a23 100644 --- a/resource/policies/dfu_match_var_aware.hpp +++ b/resource/policies/dfu_match_var_aware.hpp @@ -23,8 +23,7 @@ namespace resource_model { /*! Variation-aware policy: allocate resources based on * similar performance class. */ -struct var_aware_t : public dfu_match_cb_t -{ +struct var_aware_t : public dfu_match_cb_t { var_aware_t (); var_aware_t (const std::string &name); var_aware_t (const var_aware_t &o); @@ -33,18 +32,21 @@ struct var_aware_t : public dfu_match_cb_t int dom_finish_graph (const subsystem_t &subsystem, const std::vector &resources, - const resource_graph_t &g, scoring_api_t &dfu); - int dom_finish_vtx (vtx_t u, const subsystem_t &subsystem, + const resource_graph_t &g, + scoring_api_t &dfu); + int dom_finish_vtx (vtx_t u, + const subsystem_t &subsystem, const std::vector &resources, - const resource_graph_t &g, scoring_api_t &dfu); + const resource_graph_t &g, + scoring_api_t &dfu); int dom_finish_slot (const subsystem_t &subsystem, scoring_api_t &dfu); }; -} // resource_model -} // Flux +} // namespace resource_model +} // namespace Flux -#endif // DFU_MATCH_VAR_AWARE_HPP +#endif // DFU_MATCH_VAR_AWARE_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/readers/resource_namespace_remapper.cpp b/resource/readers/resource_namespace_remapper.cpp index 4e6a128f8..1267fbbee 100644 --- a/resource/readers/resource_namespace_remapper.cpp +++ b/resource/readers/resource_namespace_remapper.cpp @@ -25,8 +25,6 @@ extern "C" { using namespace Flux::resource_model; - - //////////////////////////////////////////////////////////////////////////////// // Public Resource Namespace Remapper API //////////////////////////////////////////////////////////////////////////////// @@ -60,25 +58,29 @@ bool distinct_range_t::is_point () const return m_low == m_high; } -bool distinct_range_t::operator< (const distinct_range_t &o) const { +bool distinct_range_t::operator< (const distinct_range_t &o) const +{ // this class is used as key for std::map, which relies on the following // x and y are equivalent if !(x < y) && !(y < x) return m_high < o.m_low; } -bool distinct_range_t::operator== (const distinct_range_t &o) const { +bool distinct_range_t::operator== (const distinct_range_t &o) const +{ // x and y are equal if and only if both high and low // of the operands are equal return m_high == o.m_high && m_low == o.m_low; } -bool distinct_range_t::operator!= (const distinct_range_t &o) const { +bool distinct_range_t::operator!= (const distinct_range_t &o) const +{ // x and y are not equal if either high or low is not equal return m_high != o.m_high || m_low != o.m_low; } int distinct_range_t::get_low_high (const std::string &exec_target_range, - uint64_t &low, uint64_t &high) + uint64_t &low, + uint64_t &high) { try { long int n; @@ -87,11 +89,10 @@ int distinct_range_t::get_low_high (const std::string &exec_target_range, std::istringstream istr{exec_target_range}; std::vector targets; - if ( (ndash = std::count (exec_target_range.begin (), - exec_target_range.end (), '-')) > 1) + if ((ndash = std::count (exec_target_range.begin (), exec_target_range.end (), '-')) > 1) goto inval; while (std::getline (istr, exec_target, '-')) { - if ( (n = std::stol (exec_target)) < 0) + if ((n = std::stol (exec_target)) < 0) goto inval; targets.push_back (static_cast (n)); } @@ -113,15 +114,15 @@ int distinct_range_t::get_low_high (const std::string &exec_target_range, return -1; } - - //////////////////////////////////////////////////////////////////////////////// // Public Resource Namespace Remapper API //////////////////////////////////////////////////////////////////////////////// -int resource_namespace_remapper_t::add (const uint64_t low, const uint64_t high, +int resource_namespace_remapper_t::add (const uint64_t low, + const uint64_t high, const std::string &name_type, - uint64_t ref_id, uint64_t remapped_id) + uint64_t ref_id, + uint64_t remapped_id) { try { const distinct_range_t exec_target_range{low, high}; @@ -129,15 +130,12 @@ int resource_namespace_remapper_t::add (const uint64_t low, const uint64_t high, if (m_remap_iter == m_remap.end ()) { m_remap.emplace (exec_target_range, - std::map> ()); + std::map> ()); } else if (exec_target_range != m_remap_iter->first) - goto inval; // key must be exact + goto inval; // key must be exact - if (m_remap[exec_target_range].find (name_type) - == m_remap[exec_target_range].end ()) - m_remap[exec_target_range][name_type] = std::map (); + if (m_remap[exec_target_range].find (name_type) == m_remap[exec_target_range].end ()) + m_remap[exec_target_range][name_type] = std::map (); if (m_remap[exec_target_range][name_type].find (ref_id) != m_remap[exec_target_range][name_type].end ()) { errno = EEXIST; @@ -159,7 +157,8 @@ int resource_namespace_remapper_t::add (const uint64_t low, const uint64_t high, int resource_namespace_remapper_t::add (const std::string &exec_target_range, const std::string &name_type, - uint64_t ref_id, uint64_t remapped_id) + uint64_t ref_id, + uint64_t remapped_id) { try { uint64_t low, high; @@ -176,8 +175,8 @@ int resource_namespace_remapper_t::add (const std::string &exec_target_range, } int resource_namespace_remapper_t::add_exec_target_range ( - const std::string &exec_target_range, - const distinct_range_t &remapped_exec_target_range) + const std::string &exec_target_range, + const distinct_range_t &remapped_exec_target_range) { try { uint64_t low, high, r_low, r_high, i, j; @@ -208,8 +207,7 @@ int resource_namespace_remapper_t::query (const uint64_t exec_target, uint64_t &remapped_id_out) const { try { - remapped_id_out = m_remap.at (distinct_range_t{exec_target}) - .at (name_type).at (ref_id); + remapped_id_out = m_remap.at (distinct_range_t{exec_target}).at (name_type).at (ref_id); return 0; } catch (std::out_of_range &) { errno = ENOENT; @@ -217,13 +215,12 @@ int resource_namespace_remapper_t::query (const uint64_t exec_target, } } -int resource_namespace_remapper_t::query_exec_target ( - const uint64_t exec_target, uint64_t &remapped_exec_target) const +int resource_namespace_remapper_t::query_exec_target (const uint64_t exec_target, + uint64_t &remapped_exec_target) const { try { - remapped_exec_target = m_remap.at (distinct_range_t{exec_target}) - .at ("exec-target") - .at (exec_target); + remapped_exec_target = + m_remap.at (distinct_range_t{exec_target}).at ("exec-target").at (exec_target); return 0; } catch (std::out_of_range &) { errno = ENOENT; diff --git a/resource/readers/resource_namespace_remapper.hpp b/resource/readers/resource_namespace_remapper.hpp index c15a3ba4c..e90946c51 100644 --- a/resource/readers/resource_namespace_remapper.hpp +++ b/resource/readers/resource_namespace_remapper.hpp @@ -19,7 +19,7 @@ namespace Flux { namespace resource_model { class distinct_range_t { -public: + public: explicit distinct_range_t (uint64_t point); distinct_range_t (uint64_t lo, uint64_t hi); @@ -30,49 +30,44 @@ class distinct_range_t { bool operator== (const distinct_range_t &o) const; bool operator!= (const distinct_range_t &o) const; - static int get_low_high (const std::string &exec_target_range, - uint64_t &low, uint64_t &high); + static int get_low_high (const std::string &exec_target_range, uint64_t &low, uint64_t &high); -private: + private: uint64_t m_low; uint64_t m_high; }; - class resource_namespace_remapper_t { -public: + public: int add (const uint64_t exec_target_high, const uint64_t exec_target_low, const std::string &name_type, - uint64_t ref_id, uint64_t remapped_id); + uint64_t ref_id, + uint64_t remapped_id); int add (const std::string &exec_target_range, const std::string &name_type, - uint64_t ref_id, uint64_t remapped_id); - int add_exec_target_range ( - const std::string &exec_target_range, - const distinct_range_t &remapped_exec_target_range); + uint64_t ref_id, + uint64_t remapped_id); + int add_exec_target_range (const std::string &exec_target_range, + const distinct_range_t &remapped_exec_target_range); int query (const uint64_t exec_target, const std::string &name_type, - uint64_t ref_id, uint64_t &remapped_id_out) const; - int query_exec_target (const uint64_t exec_target, - uint64_t &remapped_exec_target) const; + uint64_t ref_id, + uint64_t &remapped_id_out) const; + int query_exec_target (const uint64_t exec_target, uint64_t &remapped_exec_target) const; bool is_remapped () const; -private: - - int get_low_high (const std::string &exec_target_range, - uint64_t &low, uint64_t &high) const; + private: + int get_low_high (const std::string &exec_target_range, uint64_t &low, uint64_t &high) const; - std::map>> m_remap; + std::map>> + m_remap; }; -} // namespace resource_model -} // namespace Flux - +} // namespace resource_model +} // namespace Flux -#endif // RESOURCE_NAMESPACE_REMAPPER_HPP +#endif // RESOURCE_NAMESPACE_REMAPPER_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/readers/resource_reader_base.cpp b/resource/readers/resource_reader_base.cpp index 61c319a47..aaa31e9f7 100644 --- a/resource/readers/resource_reader_base.cpp +++ b/resource/readers/resource_reader_base.cpp @@ -19,27 +19,21 @@ extern "C" { using namespace Flux::resource_model; - - //////////////////////////////////////////////////////////////////////////////// // Private Base Reader API //////////////////////////////////////////////////////////////////////////////// bool resource_reader_base_t::in_allowlist (const std::string &resource) { - return allowlist.empty () - || (allowlist.find (resource) != allowlist.end ()); + return allowlist.empty () || (allowlist.find (resource) != allowlist.end ()); } - - //////////////////////////////////////////////////////////////////////////////// // Public Base Reader API //////////////////////////////////////////////////////////////////////////////// resource_reader_base_t::~resource_reader_base_t () { - } int resource_reader_base_t::set_allowlist (const std::string &csl) @@ -62,7 +56,7 @@ int resource_reader_base_t::set_allowlist (const std::string &csl) if (csl_copy != "") allowlist.insert (csl_copy); errno = EINVAL; - rc = allowlist.empty ()? -1 : 0; + rc = allowlist.empty () ? -1 : 0; } catch (std::out_of_range &e) { errno = EINVAL; rc = -1; @@ -113,7 +107,7 @@ int resource_reader_base_t::split_hostname (const std::string &hn, first = suffix.find_first_not_of ("0"); if (first == std::string::npos) { - id = 0; // all 0s + id = 0; // all 0s return 0; } @@ -133,8 +127,7 @@ int resource_reader_base_t::split_hostname (const std::string &hn, return -1; } -int resource_reader_base_t::get_hostname_suffix (const std::string &hn, - int64_t &id) const +int resource_reader_base_t::get_hostname_suffix (const std::string &hn, int64_t &id) const { if (hn == "") { errno = EINVAL; @@ -144,8 +137,7 @@ int resource_reader_base_t::get_hostname_suffix (const std::string &hn, return split_hostname (hn, basename, id); } -int resource_reader_base_t::get_host_basename (const std::string &hn, - std::string &basename) const +int resource_reader_base_t::get_host_basename (const std::string &hn, std::string &basename) const { if (hn == "") { errno = EINVAL; diff --git a/resource/readers/resource_reader_base.hpp b/resource/readers/resource_reader_base.hpp index a64aa17a8..2b7252834 100644 --- a/resource/readers/resource_reader_base.hpp +++ b/resource/readers/resource_reader_base.hpp @@ -33,8 +33,7 @@ struct modify_data_t { /*! Base resource reader class. */ class resource_reader_base_t { -public: - + public: virtual ~resource_reader_base_t (); /*! Unpack str into a resource graph. @@ -45,8 +44,10 @@ class resource_reader_base_t { * \param rank assign rank to all of the newly created resource vertices * \return 0 on success; non-zero integer on an error */ - virtual int unpack (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &str, int rank = -1) = 0; + virtual int unpack (resource_graph_t &g, + resource_graph_metadata_t &m, + const std::string &str, + int rank = -1) = 0; /*! Unpack str into a resource graph and graft * the top-level vertices to vtx. @@ -58,8 +59,11 @@ class resource_reader_base_t { * \param rank assign rank to all of the newly created resource vertices * \return 0 on success; non-zero integer on an error */ - virtual int unpack_at (resource_graph_t &g, resource_graph_metadata_t &m, - vtx_t &vtx, const std::string &str, int rank = -1) = 0; + virtual int unpack_at (resource_graph_t &g, + resource_graph_metadata_t &m, + vtx_t &vtx, + const std::string &str, + int rank = -1) = 0; virtual int remove_subgraph (resource_graph_t &g, resource_graph_metadata_t &m, @@ -78,9 +82,14 @@ class resource_reader_base_t { * token to be used by traverser * \return 0 on success; non-zero integer on an error */ - virtual int update (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &str, int64_t jobid, int64_t at, - uint64_t dur, bool rsv, uint64_t trav_token) = 0; + virtual int update (resource_graph_t &g, + resource_graph_metadata_t &m, + const std::string &str, + int64_t jobid, + int64_t at, + uint64_t dur, + bool rsv, + uint64_t trav_token) = 0; /*! Partial cancellation of jobid based on R. * @@ -93,9 +102,10 @@ class resource_reader_base_t { * \return 0 on success; non-zero integer on an error */ virtual int partial_cancel (resource_graph_t &g, - resource_graph_metadata_t &m, - modify_data_t &mod_data, - const std::string &R, int64_t jobid) = 0; + resource_graph_metadata_t &m, + modify_data_t &mod_data, + const std::string &R, + int64_t jobid) = 0; /*! Set the allowlist: only resources that are part of this allowlist * will be unpacked into the graph. @@ -148,19 +158,17 @@ class resource_reader_base_t { */ resource_namespace_remapper_t namespace_remapper; -protected: + protected: bool in_allowlist (const std::string &resource); - int split_hostname (const std::string &hn, - std::string &basename, int64_t &id) const; + int split_hostname (const std::string &hn, std::string &basename, int64_t &id) const; std::set allowlist; std::string m_err_msg = ""; }; -} // namespace resource_model -} // namespace Flux - +} // namespace resource_model +} // namespace Flux -#endif // RESOURCE_READER_BASE_HPP +#endif // RESOURCE_READER_BASE_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/readers/resource_reader_factory.cpp b/resource/readers/resource_reader_factory.cpp index bcc1182b7..4619842bc 100644 --- a/resource/readers/resource_reader_factory.cpp +++ b/resource/readers/resource_reader_factory.cpp @@ -31,8 +31,7 @@ bool known_resource_reader (const std::string &name) return rc; } -std::shared_ptr create_resource_reader ( - const std::string &name) +std::shared_ptr create_resource_reader (const std::string &name) { std::shared_ptr reader = nullptr; try { @@ -55,8 +54,8 @@ std::shared_ptr create_resource_reader ( return reader; } -} -} +} // namespace resource_model +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/readers/resource_reader_factory.hpp b/resource/readers/resource_reader_factory.hpp index e7d2c43c4..cbb6254b6 100644 --- a/resource/readers/resource_reader_factory.hpp +++ b/resource/readers/resource_reader_factory.hpp @@ -19,13 +19,12 @@ namespace Flux { namespace resource_model { bool known_resource_reader (const std::string &name); -std::shared_ptr create_resource_reader ( - const std::string &name); +std::shared_ptr create_resource_reader (const std::string &name); -} // namespace Flux::resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // RESOURCE_READER_FACTORY_HPP +#endif // RESOURCE_READER_FACTORY_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/readers/resource_reader_grug.cpp b/resource/readers/resource_reader_grug.cpp index 808823a7d..88fdaa170 100644 --- a/resource/readers/resource_reader_grug.cpp +++ b/resource/readers/resource_reader_grug.cpp @@ -30,10 +30,9 @@ using namespace Flux::resource_model; * visitor. It must be lightweight. */ class dfs_emitter_t : public boost::default_dfs_visitor { -public: + public: dfs_emitter_t (); - dfs_emitter_t (resource_graph_t *g_p, - resource_graph_metadata_t *gm_p, resource_gen_spec_t *g); + dfs_emitter_t (resource_graph_t *g_p, resource_graph_metadata_t *gm_p, resource_gen_spec_t *g); dfs_emitter_t (const dfs_emitter_t &o); dfs_emitter_t &operator= (const dfs_emitter_t &o); ~dfs_emitter_t (); @@ -45,16 +44,12 @@ class dfs_emitter_t : public boost::default_dfs_visitor { void set_rank (int rank); int get_rank (); -private: - vtx_t emit_vertex (ggv_t u, gge_t e, const gg_t &recipe, - vtx_t src_v, int i, int sz, int j); + private: + vtx_t emit_vertex (ggv_t u, gge_t e, const gg_t &recipe, vtx_t src_v, int i, int sz, int j); int raw_edge (vtx_t src_v, vtx_t tgt_v, edg_t &e); - void emit_edges (gge_t e, const gg_t &recipe, - vtx_t src_v, vtx_t tgt_v); - int path_prefix (const std::string &pth, - int upl, std::string &pref); - int gen_id (gge_t e, const gg_t &recipe, - int i, int sz, int j); + void emit_edges (gge_t e, const gg_t &recipe, vtx_t src_v, vtx_t tgt_v); + int path_prefix (const std::string &pth, int upl, std::string &pref); + int gen_id (gge_t e, const gg_t &recipe, int i, int sz, int j); std::map> m_gen_src_vtx; std::deque m_hier_scales; @@ -65,20 +60,17 @@ class dfs_emitter_t : public boost::default_dfs_visitor { std::string m_err_msg = ""; }; - - //////////////////////////////////////////////////////////////////////////////// // Private DFS Visitor Emitter API //////////////////////////////////////////////////////////////////////////////// -int dfs_emitter_t::path_prefix (const std::string &path, - int uplevel, std::string &prefix) +int dfs_emitter_t::path_prefix (const std::string &path, int uplevel, std::string &prefix) { size_t pos = 0; unsigned int occurrence = 0; auto num_slashes = count (path.begin (), path.end (), '/'); if (uplevel >= num_slashes) - return -1; + return -1; while (occurrence != (num_slashes - uplevel + 1)) { pos = path.find ("/", pos); if (pos == std::string::npos) @@ -114,16 +106,15 @@ int dfs_emitter_t::gen_id (gge_t e, const gg_t &recipe, int i, int sz, int j) else if (scope == 0) return recipe[e].id_start + i; - if (scope > (int) m_hier_scales.size ()) + if (scope > (int)m_hier_scales.size ()) scope = m_hier_scales.size (); j_dim_wrap = 1; std::deque::const_iterator iter; for (h = 0; h < scope; ++h) j_dim_wrap *= m_hier_scales[h]; - return recipe[e].id_start - + (j % j_dim_wrap * sz * recipe[e].id_stride) - + (i * recipe[e].id_stride); + return recipe[e].id_start + (j % j_dim_wrap * sz * recipe[e].id_stride) + + (i * recipe[e].id_stride); } int dfs_emitter_t::raw_edge (vtx_t src_v, vtx_t tgt_v, edg_t &e) @@ -133,7 +124,7 @@ int dfs_emitter_t::raw_edge (vtx_t src_v, vtx_t tgt_v, edg_t &e) resource_graph_t &g = *m_g_p; tie (ei, ee) = out_edges (src_v, g); - for ( ; ei != ee; ++ei) { + for (; ei != ee; ++ei) { if (target (*ei, g) == tgt_v) { e = (*ei); return 0; @@ -142,56 +133,55 @@ int dfs_emitter_t::raw_edge (vtx_t src_v, vtx_t tgt_v, edg_t &e) tie (e, inserted) = add_edge (src_v, tgt_v, g); if (!inserted) { errno = ENOMEM; - m_err_msg += "error inserting a new edge: " - + g[src_v].name + " -> " + g[tgt_v].name + "; "; + m_err_msg += "error inserting a new edge: " + g[src_v].name + " -> " + g[tgt_v].name + "; "; return -1; } // add this edge to by_outedges metadata auto iter = m_gm_p->by_outedges.find (src_v); if (iter == m_gm_p->by_outedges.end ()) { auto ret = m_gm_p->by_outedges.insert ( - std::make_pair ( - src_v, - std::map, edg_t, - std::greater>> ())); + std::make_pair (src_v, + std::map, + edg_t, + std::greater>> ())); if (!ret.second) { errno = ENOMEM; - m_err_msg += "error creating out-edge metadata map: " - + g[src_v].name + " -> " + g[tgt_v].name + "; "; + m_err_msg += "error creating out-edge metadata map: " + g[src_v].name + " -> " + + g[tgt_v].name + "; "; return -1; } iter = m_gm_p->by_outedges.find (src_v); } // Use a temporary for readability - std::pair key = std::make_pair ( - g[e].idata.get_weight (), - g[tgt_v].uniq_id); + std::pair key = std::make_pair (g[e].idata.get_weight (), g[tgt_v].uniq_id); auto ret = iter->second.insert (std::make_pair (key, e)); if (!ret.second) { errno = ENOMEM; - m_err_msg += "error inserting an edge into out-edge metadata map:" - + g[src_v].name + " -> " + g[tgt_v].name + "; "; + m_err_msg += "error inserting an edge into out-edge metadata map:" + g[src_v].name + " -> " + + g[tgt_v].name + "; "; return -1; } return 0; } -void dfs_emitter_t::emit_edges (gge_t ge, const gg_t &recipe, - vtx_t src_v, vtx_t tgt_v) +void dfs_emitter_t::emit_edges (gge_t ge, const gg_t &recipe, vtx_t src_v, vtx_t tgt_v) { edg_t e; int rc = 0; resource_graph_t &g = *m_g_p; - if ( (rc = raw_edge (src_v, tgt_v, e)) < 0) + if ((rc = raw_edge (src_v, tgt_v, e)) < 0) return; - g[e].idata.member_of[recipe[ge].e_subsystem] - = recipe[ge].relation; + g[e].idata.member_of[recipe[ge].e_subsystem] = recipe[ge].relation; g[e].name[recipe[ge].e_subsystem] = recipe[ge].relation; } -vtx_t dfs_emitter_t::emit_vertex (ggv_t u, gge_t e, const gg_t &recipe, - vtx_t src_v, int i, int sz, int j) +vtx_t dfs_emitter_t::emit_vertex (ggv_t u, + gge_t e, + const gg_t &recipe, + vtx_t src_v, + int i, + int sz, + int j) { resource_graph_t &g = *m_g_p; resource_graph_metadata_t &m = *m_gm_p; @@ -199,7 +189,8 @@ vtx_t dfs_emitter_t::emit_vertex (ggv_t u, gge_t e, const gg_t &recipe, if (m.roots.find (recipe[u].subsystem) != m.roots.end ()) return (m.roots)[recipe[u].subsystem]; - vtx_t v = add_vertex (g);; + vtx_t v = add_vertex (g); + ; std::string pref = ""; std::string ssys = recipe[u].subsystem; int id = 0; @@ -214,15 +205,13 @@ vtx_t dfs_emitter_t::emit_vertex (ggv_t u, gge_t e, const gg_t &recipe, pref = g[src_v].paths[ssys]; } - std::string istr = (id != -1)? std::to_string (id) : ""; + std::string istr = (id != -1) ? std::to_string (id) : ""; g[v].type = recipe[u].type; g[v].basename = recipe[u].basename; g[v].size = recipe[u].size; g[v].unit = recipe[u].unit; - g[v].schedule.plans = planner_new (0, INT64_MAX, - recipe[u].size, recipe[u].type.c_str ()); - g[v].idata.x_checker = planner_new (0, INT64_MAX, - X_CHECKER_NJOBS, X_CHECKER_JOBS_STR); + g[v].schedule.plans = planner_new (0, INT64_MAX, recipe[u].size, recipe[u].type.c_str ()); + g[v].idata.x_checker = planner_new (0, INT64_MAX, X_CHECKER_NJOBS, X_CHECKER_JOBS_STR); g[v].id = id; g[v].name = recipe[u].basename + istr; g[v].paths[ssys] = pref + "/" + g[v].name; @@ -240,15 +229,12 @@ vtx_t dfs_emitter_t::emit_vertex (ggv_t u, gge_t e, const gg_t &recipe, return v; } - - //////////////////////////////////////////////////////////////////////////////// // Public DFS Visitor Emitter //////////////////////////////////////////////////////////////////////////////// dfs_emitter_t::dfs_emitter_t () { - } dfs_emitter_t::dfs_emitter_t (resource_graph_t *g_p, @@ -268,13 +254,13 @@ dfs_emitter_t::dfs_emitter_t (const dfs_emitter_t &o) m_err_msg = o.m_err_msg; } -dfs_emitter_t::~dfs_emitter_t() +dfs_emitter_t::~dfs_emitter_t () { m_gen_src_vtx.clear (); m_hier_scales.clear (); } -dfs_emitter_t &dfs_emitter_t::operator=(const dfs_emitter_t &o) +dfs_emitter_t &dfs_emitter_t::operator= (const dfs_emitter_t &o) { m_g_p = o.m_g_p; m_gm_p = o.m_gm_p; @@ -299,92 +285,85 @@ void dfs_emitter_t::tree_edge (gge_t e, const gg_t &recipe) resource_graph_t &g = *m_g_p; resource_graph_metadata_t &m = *m_gm_p; std::string in; - int i = 0, j = 0;; + int i = 0, j = 0; + ; if (recipe[src_ggv].root) { //! ROOT if (m_gen_src_vtx[src_ggv].empty ()) { vtx_t null_v = boost::graph_traits::null_vertex (); - m_gen_src_vtx[src_ggv].push_back (emit_vertex (src_ggv, e, recipe, - null_v, 0, 1, 0)); + m_gen_src_vtx[src_ggv].push_back (emit_vertex (src_ggv, e, recipe, null_v, 0, 1, 0)); } } - m_gen_src_vtx[tgt_ggv] = std::vector(); + m_gen_src_vtx[tgt_ggv] = std::vector (); switch (m_gspec_p->to_gen_method_t (recipe[e].gen_method)) { - case MULTIPLY: - for (src_it = m_gen_src_vtx[src_ggv].begin (); - src_it != m_gen_src_vtx[src_ggv].end (); src_it++, j++) { - - src_vtx = *src_it; - for (i = 0; i < recipe[e].multi_scale; ++i) { - tgt_vtx = emit_vertex (tgt_ggv, e, recipe, src_vtx, i, - recipe[e].multi_scale, j); - emit_edges (e, recipe, src_vtx, tgt_vtx); - // TODO: Next gen src vertex; where do you clear them? - m_gen_src_vtx[tgt_ggv].push_back (tgt_vtx); + case MULTIPLY: + for (src_it = m_gen_src_vtx[src_ggv].begin (); src_it != m_gen_src_vtx[src_ggv].end (); + src_it++, j++) { + src_vtx = *src_it; + for (i = 0; i < recipe[e].multi_scale; ++i) { + tgt_vtx = + emit_vertex (tgt_ggv, e, recipe, src_vtx, i, recipe[e].multi_scale, j); + emit_edges (e, recipe, src_vtx, tgt_vtx); + // TODO: Next gen src vertex; where do you clear them? + m_gen_src_vtx[tgt_ggv].push_back (tgt_vtx); + } } - } - m_hier_scales.push_front (recipe[e].multi_scale); - break; - - case ASSOCIATE_IN: - for (src_it = m_gen_src_vtx[src_ggv].begin (); - src_it != m_gen_src_vtx[src_ggv].end (); src_it++) { - - src_vtx = *src_it; - for (tgt_it = m.by_type[recipe[tgt_ggv].type].begin (); - tgt_it != m.by_type[recipe[tgt_ggv].type].end (); tgt_it++) { - tgt_vtx = (*tgt_it); - g[tgt_vtx].paths[recipe[e].e_subsystem] - = g[src_vtx].paths[recipe[e].e_subsystem] - + "/" + g[tgt_vtx].name; - const std::string &tp = g[tgt_vtx].paths[recipe[e].e_subsystem]; - m.by_path[tp].push_back (tgt_vtx); - g[tgt_vtx].idata.member_of[recipe[e].e_subsystem] - = "*"; - emit_edges (e, recipe, src_vtx, tgt_vtx); - m_gen_src_vtx[tgt_ggv].push_back (tgt_vtx); + m_hier_scales.push_front (recipe[e].multi_scale); + break; + + case ASSOCIATE_IN: + for (src_it = m_gen_src_vtx[src_ggv].begin (); src_it != m_gen_src_vtx[src_ggv].end (); + src_it++) { + src_vtx = *src_it; + for (tgt_it = m.by_type[recipe[tgt_ggv].type].begin (); + tgt_it != m.by_type[recipe[tgt_ggv].type].end (); + tgt_it++) { + tgt_vtx = (*tgt_it); + g[tgt_vtx].paths[recipe[e].e_subsystem] = + g[src_vtx].paths[recipe[e].e_subsystem] + "/" + g[tgt_vtx].name; + const std::string &tp = g[tgt_vtx].paths[recipe[e].e_subsystem]; + m.by_path[tp].push_back (tgt_vtx); + g[tgt_vtx].idata.member_of[recipe[e].e_subsystem] = "*"; + emit_edges (e, recipe, src_vtx, tgt_vtx); + m_gen_src_vtx[tgt_ggv].push_back (tgt_vtx); + } } - } - break; - - case ASSOCIATE_BY_PATH_IN: - in = recipe[e].as_tgt_subsystem; - for (src_it = m_gen_src_vtx[src_ggv].begin (); - src_it != m_gen_src_vtx[src_ggv].end (); src_it++) { - - src_vtx = *src_it; - for (tgt_it = m.by_type[recipe[tgt_ggv].type].begin (); - tgt_it != m.by_type[recipe[tgt_ggv].type].end (); tgt_it++) { - std::string comp_pth1, comp_pth2; - tgt_vtx = (*tgt_it); - path_prefix (g[tgt_vtx].paths[in], - recipe[e].as_tgt_uplvl, comp_pth1); - path_prefix (g[src_vtx].paths[in], - recipe[e].as_src_uplvl, comp_pth2); - - if (comp_pth1 != comp_pth2) - continue; - - g[tgt_vtx].paths[recipe[e].e_subsystem] - = g[src_vtx].paths[recipe[e].e_subsystem] - + "/" + g[tgt_vtx].name; - const std::string &tp = g[tgt_vtx].paths[recipe[e].e_subsystem]; - m.by_path[tp].push_back (tgt_vtx); - g[tgt_vtx].idata.member_of[recipe[e].e_subsystem] - = "*"; - emit_edges (e, recipe, src_vtx, tgt_vtx); - m_gen_src_vtx[tgt_ggv].push_back (tgt_vtx); + break; + + case ASSOCIATE_BY_PATH_IN: + in = recipe[e].as_tgt_subsystem; + for (src_it = m_gen_src_vtx[src_ggv].begin (); src_it != m_gen_src_vtx[src_ggv].end (); + src_it++) { + src_vtx = *src_it; + for (tgt_it = m.by_type[recipe[tgt_ggv].type].begin (); + tgt_it != m.by_type[recipe[tgt_ggv].type].end (); + tgt_it++) { + std::string comp_pth1, comp_pth2; + tgt_vtx = (*tgt_it); + path_prefix (g[tgt_vtx].paths[in], recipe[e].as_tgt_uplvl, comp_pth1); + path_prefix (g[src_vtx].paths[in], recipe[e].as_src_uplvl, comp_pth2); + + if (comp_pth1 != comp_pth2) + continue; + + g[tgt_vtx].paths[recipe[e].e_subsystem] = + g[src_vtx].paths[recipe[e].e_subsystem] + "/" + g[tgt_vtx].name; + const std::string &tp = g[tgt_vtx].paths[recipe[e].e_subsystem]; + m.by_path[tp].push_back (tgt_vtx); + g[tgt_vtx].idata.member_of[recipe[e].e_subsystem] = "*"; + emit_edges (e, recipe, src_vtx, tgt_vtx); + m_gen_src_vtx[tgt_ggv].push_back (tgt_vtx); + } } - } - break; + break; - case GEN_UNKNOWN: - default: - m_err_msg += "unknown generation method; "; - break; + case GEN_UNKNOWN: + default: + m_err_msg += "unknown generation method; "; + break; } } @@ -395,7 +374,7 @@ void dfs_emitter_t::tree_edge (gge_t e, const gg_t &recipe) */ void dfs_emitter_t::finish_vertex (ggv_t u, const gg_t &recipe) { - if (m_hier_scales.size()) + if (m_hier_scales.size ()) m_hier_scales.pop_front (); } @@ -427,20 +406,18 @@ int dfs_emitter_t::get_rank () return m_rank; } - - //////////////////////////////////////////////////////////////////////////////// // Public GRUG Resource Reader Interface //////////////////////////////////////////////////////////////////////////////// resource_reader_grug_t::~resource_reader_grug_t () { - } int resource_reader_grug_t::unpack (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &str, int rank) + const std::string &str, + int rank) { int rc = 0; @@ -462,14 +439,16 @@ int resource_reader_grug_t::unpack (resource_graph_t &g, depth_first_search (m_gspec.gen_graph (), boost::visitor (emitter)); m_err_msg += emitter.err_message (); - return (m_err_msg == "")? rc : -1; + return (m_err_msg == "") ? rc : -1; } int resource_reader_grug_t::unpack_at (resource_graph_t &g, - resource_graph_metadata_t &m, vtx_t &vtx, - const std::string &str, int rank) + resource_graph_metadata_t &m, + vtx_t &vtx, + const std::string &str, + int rank) { - errno = ENOTSUP; // GRUG reader does not support unpack_at + errno = ENOTSUP; // GRUG reader does not support unpack_at return -1; } @@ -477,27 +456,31 @@ int resource_reader_grug_t::remove_subgraph (resource_graph_t &g, resource_graph_metadata_t &m, const std::string &path) { - errno = ENOTSUP; // GRUG reader does not support remove - return -1; + errno = ENOTSUP; // GRUG reader does not support remove + return -1; } int resource_reader_grug_t::update (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &str, int64_t jobid, - int64_t at, uint64_t dur, bool rsv, + const std::string &str, + int64_t jobid, + int64_t at, + uint64_t dur, + bool rsv, uint64_t token) { - errno = ENOTSUP; // GRUG reader currently does not support update + errno = ENOTSUP; // GRUG reader currently does not support update return -1; } int resource_reader_grug_t::partial_cancel (resource_graph_t &g, - resource_graph_metadata_t &m, - modify_data_t &mod_data, - const std::string &R, int64_t jobid) + resource_graph_metadata_t &m, + modify_data_t &mod_data, + const std::string &R, + int64_t jobid) { - errno = ENOTSUP; // GRUG reader does not support partial cancel - return -1; + errno = ENOTSUP; // GRUG reader does not support partial cancel + return -1; } bool resource_reader_grug_t::is_allowlist_supported () diff --git a/resource/readers/resource_reader_grug.hpp b/resource/readers/resource_reader_grug.hpp index 88171160c..8609928a6 100644 --- a/resource/readers/resource_reader_grug.hpp +++ b/resource/readers/resource_reader_grug.hpp @@ -23,7 +23,7 @@ namespace resource_model { /*! GRUG resource reader class. */ class resource_reader_grug_t : public resource_reader_base_t { -public: + public: virtual ~resource_reader_grug_t (); /*! Unpack str into a resource graph. @@ -36,8 +36,10 @@ class resource_reader_grug_t : public resource_reader_base_t { * ENOMEM: out of memory * EINVAL: invalid input or operation */ - virtual int unpack (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &str, int rank = -1); + virtual int unpack (resource_graph_t &g, + resource_graph_metadata_t &m, + const std::string &str, + int rank = -1); /*! Unpack str into a resource graph and graft * the top-level vertices to vtx. @@ -49,14 +51,17 @@ class resource_reader_grug_t : public resource_reader_base_t { * \param rank assign this rank to all the newly created resource vertices * \return -1 with errno=ENOTSUP (Not supported yet) */ - virtual int unpack_at (resource_graph_t &g, resource_graph_metadata_t &m, - vtx_t &vtx, const std::string &str, int rank = -1); + virtual int unpack_at (resource_graph_t &g, + resource_graph_metadata_t &m, + vtx_t &vtx, + const std::string &str, + int rank = -1); virtual int remove_subgraph (resource_graph_t &g, resource_graph_metadata_t &m, const std::string &path); - /*! Update resource graph g with str. + /*! Update resource graph g with str. * * \param g resource graph * \param m resource graph meta data @@ -69,9 +74,14 @@ class resource_reader_grug_t : public resource_reader_base_t { * token to be used by traverser * \return 0 on success; non-zero integer on an error */ - virtual int update (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &str, int64_t jobid, int64_t at, - uint64_t dur, bool rsv, uint64_t trav_token); + virtual int update (resource_graph_t &g, + resource_graph_metadata_t &m, + const std::string &str, + int64_t jobid, + int64_t at, + uint64_t dur, + bool rsv, + uint64_t trav_token); /*! Partial cancellation of jobid based on R. * @@ -84,9 +94,10 @@ class resource_reader_grug_t : public resource_reader_base_t { * \return 0 on success; non-zero integer on an error */ virtual int partial_cancel (resource_graph_t &g, - resource_graph_metadata_t &m, - modify_data_t &mod_data, - const std::string &R, int64_t jobid); + resource_graph_metadata_t &m, + modify_data_t &mod_data, + const std::string &R, + int64_t jobid); /*! Is the selected reader format support allowlist * @@ -94,14 +105,14 @@ class resource_reader_grug_t : public resource_reader_base_t { */ virtual bool is_allowlist_supported (); -private: + private: resource_gen_spec_t m_gspec; }; -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // RESOURCE_READER_GRUG_HPP +#endif // RESOURCE_READER_GRUG_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/readers/resource_reader_hwloc.cpp b/resource/readers/resource_reader_hwloc.cpp index bcaf8b2cf..691602c21 100644 --- a/resource/readers/resource_reader_hwloc.cpp +++ b/resource/readers/resource_reader_hwloc.cpp @@ -21,8 +21,6 @@ extern "C" { using namespace Flux; using namespace resource_model; - - //////////////////////////////////////////////////////////////////////////////// // Private HWLOC Reader API //////////////////////////////////////////////////////////////////////////////// @@ -33,10 +31,8 @@ int resource_reader_hwloc_t::check_hwloc_version (std::string &m_err_msg) if ((hwloc_version >> 16) != (HWLOC_API_VERSION >> 16)) { std::stringstream msg; - msg << "Compiled for hwloc API 0x" - << std::hex << HWLOC_API_VERSION - << " but running on library API 0x" - << hwloc_version << "; "; + msg << "Compiled for hwloc API 0x" << std::hex << HWLOC_API_VERSION + << " but running on library API 0x" << hwloc_version << "; "; m_err_msg += msg.str (); errno = EINVAL; return -1; @@ -44,16 +40,22 @@ int resource_reader_hwloc_t::check_hwloc_version (std::string &m_err_msg) return 0; } -vtx_t resource_reader_hwloc_t::create_cluster_vertex ( - resource_graph_t &g, resource_graph_metadata_t &m) +vtx_t resource_reader_hwloc_t::create_cluster_vertex (resource_graph_t &g, + resource_graph_metadata_t &m) { // generate cluster root vertex const std::string subsys = "containment"; const std::map properties; - vtx_t v = add_new_vertex (g, m, boost:: - graph_traits:: - null_vertex (), 0, subsys, - "cluster", "cluster", "", properties, 1); + vtx_t v = add_new_vertex (g, + m, + boost::graph_traits::null_vertex (), + 0, + subsys, + "cluster", + "cluster", + "", + properties, + 1); m.roots.emplace (subsys, v); m.v_rt_edges.emplace (subsys, relation_infra_t ()); @@ -62,13 +64,15 @@ vtx_t resource_reader_hwloc_t::create_cluster_vertex ( vtx_t resource_reader_hwloc_t::add_new_vertex (resource_graph_t &g, resource_graph_metadata_t &m, - const vtx_t &parent, int64_t id, + const vtx_t &parent, + int64_t id, const std::string &subsys, const std::string &type, const std::string &basename, const std::string &name, const std::map &properties, - int size, int rank) + int size, + int rank) { vtx_t v = boost::add_vertex (g); @@ -76,8 +80,8 @@ vtx_t resource_reader_hwloc_t::add_new_vertex (resource_graph_t &g, bool is_root = false; if (parent == boost::graph_traits::null_vertex ()) is_root = true; - std::string istr = (id != -1)? std::to_string (id) : ""; - std::string prefix = is_root ? "" : g[parent].paths[subsys]; + std::string istr = (id != -1) ? std::to_string (id) : ""; + std::string prefix = is_root ? "" : g[parent].paths[subsys]; g[v].type = type; g[v].basename = basename; @@ -85,10 +89,9 @@ vtx_t resource_reader_hwloc_t::add_new_vertex (resource_graph_t &g, g[v].uniq_id = v; g[v].rank = rank; g[v].schedule.plans = planner_new (0, INT64_MAX, size, type.c_str ()); - g[v].idata.x_checker = planner_new (0, INT64_MAX, - X_CHECKER_NJOBS, X_CHECKER_JOBS_STR); + g[v].idata.x_checker = planner_new (0, INT64_MAX, X_CHECKER_NJOBS, X_CHECKER_JOBS_STR); g[v].id = id; - g[v].name = (name != "")? name : basename + istr; + g[v].name = (name != "") ? name : basename + istr; g[v].paths[subsys] = prefix + "/" + g[v].name; g[v].idata.member_of[subsys] = "*"; g[v].status = resource_pool_t::status_t::UP; @@ -103,35 +106,33 @@ vtx_t resource_reader_hwloc_t::add_new_vertex (resource_graph_t &g, } int resource_reader_hwloc_t::add_metadata (resource_graph_metadata_t &m, - edg_t e, vtx_t src, vtx_t tgt, + edg_t e, + vtx_t src, + vtx_t tgt, resource_graph_t &g) { // add this edge to by_outedges metadata auto iter = m.by_outedges.find (src); if (iter == m.by_outedges.end ()) { auto ret = m.by_outedges.insert ( - std::make_pair ( - src, - std::map, edg_t, - std::greater< - std::pair>> ())); + std::make_pair (src, + std::map, + edg_t, + std::greater>> ())); if (!ret.second) { errno = ENOMEM; - m_err_msg += "error creating out-edge metadata map: " - + g[src].name + " -> " + g[tgt].name + "; "; + m_err_msg += "error creating out-edge metadata map: " + g[src].name + " -> " + + g[tgt].name + "; "; return -1; } iter = m.by_outedges.find (src); } - std::pair key = std::make_pair ( - g[e].idata.get_weight (), - g[tgt].uniq_id); + std::pair key = std::make_pair (g[e].idata.get_weight (), g[tgt].uniq_id); auto ret = iter->second.insert (std::make_pair (key, e)); if (!ret.second) { errno = ENOMEM; - m_err_msg += "error inserting an edge to out-edge metadata map: " - + g[src].name + " -> " + g[tgt].name + "; "; + m_err_msg += "error inserting an edge to out-edge metadata map: " + g[src].name + " -> " + + g[tgt].name + "; "; return -1; } return 0; @@ -141,7 +142,8 @@ int resource_reader_hwloc_t::walk_hwloc (resource_graph_t &g, resource_graph_metadata_t &m, const hwloc_topology_t topo, const hwloc_obj_t obj, - const vtx_t parent, int rank) + const vtx_t parent, + int rank) { bool supported_resource = true; std::string type, basename; @@ -151,204 +153,203 @@ int resource_reader_hwloc_t::walk_hwloc (resource_graph_t &g, unsigned int size = 1; std::map properties; - switch(obj->type) { - case HWLOC_OBJ_MACHINE: { - // TODO: add signature to support multiple ranks per node - const char *hwloc_name = hwloc_obj_get_info_by_name (obj, "HostName"); - if (!hwloc_name || !in_allowlist ("node")) { - supported_resource = false; + switch (obj->type) { + case HWLOC_OBJ_MACHINE: { + // TODO: add signature to support multiple ranks per node + const char *hwloc_name = hwloc_obj_get_info_by_name (obj, "HostName"); + if (!hwloc_name || !in_allowlist ("node")) { + supported_resource = false; + break; + } + type = "node"; + name = hwloc_name; + if (split_hostname (name, basename, id) < 0) { + m_err_msg += "Error converting node id for " + name + "; "; + rc = -1; + } break; } - type = "node"; - name = hwloc_name; - if (split_hostname (name, basename, id) < 0) { - m_err_msg += "Error converting node id for " + name + "; "; - rc = -1; - } - break; - } - case HWLOC_OBJ_GROUP: { - if (!in_allowlist ("group")) { - supported_resource = false; + case HWLOC_OBJ_GROUP: { + if (!in_allowlist ("group")) { + supported_resource = false; + break; + } + type = "group"; + basename = type; break; } - type = "group"; - basename = type; - break; - } - case HWLOC_OBJ_NUMANODE: { - if (!in_allowlist ("numanode")) { - supported_resource = false; + case HWLOC_OBJ_NUMANODE: { + if (!in_allowlist ("numanode")) { + supported_resource = false; + break; + } + type = "numanode"; + basename = type; break; } - type = "numanode"; - basename = type; - break; - } - case HWLOC_OBJ_PACKAGE: { - if (!in_allowlist ("socket")) { - supported_resource = false; + case HWLOC_OBJ_PACKAGE: { + if (!in_allowlist ("socket")) { + supported_resource = false; + break; + } + type = "socket"; + basename = type; break; } - type = "socket"; - basename = type; - break; - } #if HWLOC_API_VERSION < 0x00020000 - case HWLOC_OBJ_CACHE: { - std::string r = "L" + std::to_string (obj->attr->cache.depth) + "cache"; - if (!in_allowlist (r)) { - supported_resource = false; + case HWLOC_OBJ_CACHE: { + std::string r = "L" + std::to_string (obj->attr->cache.depth) + "cache"; + if (!in_allowlist (r)) { + supported_resource = false; + break; + } + type = "cache"; + basename = r; + size = obj->attr->cache.size / 1024; break; } - type = "cache"; - basename = r; - size = obj->attr->cache.size / 1024; - break; - } #else - case HWLOC_OBJ_L1CACHE: { - if (!in_allowlist ("L1cache")) { - supported_resource = false; + case HWLOC_OBJ_L1CACHE: { + if (!in_allowlist ("L1cache")) { + supported_resource = false; + break; + } + type = "cache"; + basename = "L1" + type; + size = obj->attr->cache.size / 1024; break; } - type = "cache"; - basename = "L1" + type; - size = obj->attr->cache.size / 1024; - break; - } - case HWLOC_OBJ_L2CACHE: { - if (!in_allowlist ("L2cache")) { - supported_resource = false; + case HWLOC_OBJ_L2CACHE: { + if (!in_allowlist ("L2cache")) { + supported_resource = false; + break; + } + type = "cache"; + basename = "L2" + type; + size = obj->attr->cache.size / 1024; break; } - type = "cache"; - basename = "L2" + type; - size = obj->attr->cache.size / 1024; - break; - } - case HWLOC_OBJ_L3CACHE: { - if (!in_allowlist ("L3cache")) { - supported_resource = false; + case HWLOC_OBJ_L3CACHE: { + if (!in_allowlist ("L3cache")) { + supported_resource = false; + break; + } + type = "cache"; + basename = "L3" + type; + size = obj->attr->cache.size / 1024; break; } - type = "cache"; - basename = "L3" + type; - size = obj->attr->cache.size / 1024; - break; - } #endif - case HWLOC_OBJ_CORE: { - if (!in_allowlist ("core")) { - supported_resource = false; + case HWLOC_OBJ_CORE: { + if (!in_allowlist ("core")) { + supported_resource = false; + break; + } + type = "core"; + basename = type; break; } - type = "core"; - basename = type; - break; - } - case HWLOC_OBJ_PU: { - if (!in_allowlist ("pu")) { - supported_resource = false; + case HWLOC_OBJ_PU: { + if (!in_allowlist ("pu")) { + supported_resource = false; + break; + } + type = "pu"; + basename = type; break; } - type = "pu"; - basename = type; - break; - } - case HWLOC_OBJ_OS_DEVICE: { - supported_resource = false; - if (!obj->attr) - break; - - /* Detect any COPROC as GPU device. - * Also, some AMD GPUs are detected as type == GPU with - * subtype RSMI (rsmiX), detect those also: - */ - if (obj->attr->osdev.type == HWLOC_OBJ_OSDEV_COPROC - || (obj->attr->osdev.type == HWLOC_OBJ_OSDEV_GPU - && strncmp (obj->name, "rsmi", 4) == 0)) { - if (!in_allowlist ("gpu")) { + case HWLOC_OBJ_OS_DEVICE: { + supported_resource = false; + if (!obj->attr) break; - } - /* hwloc doesn't provide the logical index only amongst CoProc - * devices so we parse this info from the name until hwloc provide - * better support. + + /* Detect any COPROC as GPU device. + * Also, some AMD GPUs are detected as type == GPU with + * subtype RSMI (rsmiX), detect those also: */ - if (strncmp (obj->name, "cuda", 4) == 0) - id = atoi (obj->name + 4); - else if (strncmp (obj->name, "rsmi", 4) == 0) - id = atoi (obj->name + 4); - else if (strncmp (obj->name, "opencl", 6) == 0) { - /* Naming convention of opencl devices for hwloc: - * "opencl" followed by a platform ID followed by a device ID. - * Then, the letter d delimits platform id and device id. + if (obj->attr->osdev.type == HWLOC_OBJ_OSDEV_COPROC + || (obj->attr->osdev.type == HWLOC_OBJ_OSDEV_GPU + && strncmp (obj->name, "rsmi", 4) == 0)) { + if (!in_allowlist ("gpu")) { + break; + } + /* hwloc doesn't provide the logical index only amongst CoProc + * devices so we parse this info from the name until hwloc provide + * better support. */ - const char *delim = strchr (obj->name + 6, 'd'); - id = atoi (delim + 1); - } - if (namespace_remapper.is_remapped ()) { - uint64_t remap_id; - if (namespace_remapper.query (rank, "gpu", id, remap_id) < 0) { - m_err_msg += "Error remapping gpu id=" - + std::to_string (id) +"; "; + if (strncmp (obj->name, "cuda", 4) == 0) + id = atoi (obj->name + 4); + else if (strncmp (obj->name, "rsmi", 4) == 0) + id = atoi (obj->name + 4); + else if (strncmp (obj->name, "opencl", 6) == 0) { + /* Naming convention of opencl devices for hwloc: + * "opencl" followed by a platform ID followed by a device ID. + * Then, the letter d delimits platform id and device id. + */ + const char *delim = strchr (obj->name + 6, 'd'); + id = atoi (delim + 1); + } + if (namespace_remapper.is_remapped ()) { + uint64_t remap_id; + if (namespace_remapper.query (rank, "gpu", id, remap_id) < 0) { + m_err_msg += "Error remapping gpu id=" + std::to_string (id) + "; "; + rc = -1; + break; + } + if (remap_id > static_cast (std::numeric_limits::max ())) { + errno = EOVERFLOW; + m_err_msg += "Remapped gpu id too large; "; + rc = -1; + break; + } + id = static_cast (remap_id); + } + type = "gpu"; + basename = type; + supported_resource = true; + } else if (obj->attr->osdev.type == HWLOC_OBJ_OSDEV_BLOCK) { + if (!in_allowlist ("storage")) { + break; + } + // Size from hwloc is in kBs (base 10) + const char *size_str = hwloc_obj_get_info_by_name (obj, "Size"); + if (size_str == NULL) { + errno = ENOENT; + m_err_msg += "Error getting the size of block storage device; "; rc = -1; break; } - if (remap_id - > static_cast (std::numeric_limits::max ())) { - errno = EOVERFLOW; - m_err_msg += "Remapped gpu id too large; "; + long int num_bytes = strtol (size_str, NULL, 10); + if (num_bytes == 0 || num_bytes == LONG_MIN || num_bytes == LONG_MAX) { + // strtol sets errno to ERANGE + m_err_msg += "Error parsing the size of block storage device; "; + rc = -1; + break; + } + size = num_bytes / 1000000; // kBs -> gBs + type = "storage"; + basename = type; + supported_resource = true; + + const char *devID_str = hwloc_obj_get_info_by_name (obj, "LinuxDeviceID"); + if (devID_str == NULL) { + devID_str = "-1"; + } + auto ret = properties.insert ( + std::pair ("LinuxDeviceID", devID_str)); + if (!ret.second) { + errno = EEXIST; + m_err_msg += "Error inserting LinuxDeviceID into properties map; "; rc = -1; break; } - id = static_cast (remap_id); - } - type = "gpu"; - basename = type; - supported_resource = true; - } else if (obj->attr->osdev.type == HWLOC_OBJ_OSDEV_BLOCK) { - if (!in_allowlist ("storage")) { - break; - } - // Size from hwloc is in kBs (base 10) - const char* size_str = hwloc_obj_get_info_by_name (obj, "Size"); - if (size_str == NULL) { - errno = ENOENT; - m_err_msg += "Error getting the size of block storage device; "; - rc = -1; - break; - } - long int num_bytes = strtol (size_str, NULL, 10); - if (num_bytes == 0 || num_bytes == LONG_MIN || num_bytes == LONG_MAX) { - // strtol sets errno to ERANGE - m_err_msg += "Error parsing the size of block storage device; "; - rc = -1; - break; - } - size = num_bytes / 1000000; // kBs -> gBs - type = "storage"; - basename = type; - supported_resource = true; - - const char* devID_str = hwloc_obj_get_info_by_name (obj, "LinuxDeviceID"); - if (devID_str == NULL) { - devID_str = "-1"; - } - auto ret = properties.insert (std::pair("LinuxDeviceID", devID_str)); - if (!ret.second) { - errno = EEXIST; - m_err_msg += "Error inserting LinuxDeviceID into properties map; "; - rc = -1; - break; } + break; + } + default: { + supported_resource = false; + break; } - break; - } - default: { - supported_resource = false; - break; - } } // A valid ancestor vertex to pass to the recursive call @@ -357,26 +358,24 @@ int resource_reader_hwloc_t::walk_hwloc (resource_graph_t &g, valid_ancestor = parent; } else { const std::string subsys = "containment"; - vtx_t v = add_new_vertex (g, m, parent, - id, subsys, type, basename, - name, properties, size, rank); + vtx_t v = + add_new_vertex (g, m, parent, id, subsys, type, basename, name, properties, size, rank); valid_ancestor = v; std::string relation = "contains"; edg_t e; - bool inserted; // set to false when we try and insert a parallel edge + bool inserted; // set to false when we try and insert a parallel edge tie (e, inserted) = add_edge (parent, v, g); if (!inserted) { errno = ENOMEM; - m_err_msg += "error inserting a new edge: " - + g[parent].name + " -> " + g[v].name + "; "; + m_err_msg += + "error inserting a new edge: " + g[parent].name + " -> " + g[v].name + "; "; return -1; } g[e].idata.member_of[subsys] = relation; g[e].name[subsys] = relation; if (add_metadata (m, e, parent, v, g) < 0) return -1; - } hwloc_obj_t curr_child = NULL; @@ -390,53 +389,48 @@ int resource_reader_hwloc_t::walk_hwloc (resource_graph_t &g, int resource_reader_hwloc_t::unpack_internal (resource_graph_t &g, resource_graph_metadata_t &m, vtx_t &vtx, - const std::string &str, int rank) + const std::string &str, + int rank) { int rc = -1; size_t len = str.length (); hwloc_topology_t topo; hwloc_obj_t hwloc_root; - if ( hwloc_topology_init (&topo) != 0 ) { + if (hwloc_topology_init (&topo) != 0) { errno = ENOMEM; m_err_msg += "Error initializing hwloc topology; "; goto done; } #if HWLOC_API_VERSION < 0x20000 - if ( hwloc_topology_set_flags (topo, HWLOC_TOPOLOGY_FLAG_IO_DEVICES) != 0) { + if (hwloc_topology_set_flags (topo, HWLOC_TOPOLOGY_FLAG_IO_DEVICES) != 0) { errno = EINVAL; m_err_msg += "Error setting hwloc topology flag; "; goto done; } #else - if (hwloc_topology_set_io_types_filter (topo, - HWLOC_TYPE_FILTER_KEEP_IMPORTANT) - < 0) { + if (hwloc_topology_set_io_types_filter (topo, HWLOC_TYPE_FILTER_KEEP_IMPORTANT) < 0) { errno = EINVAL; m_err_msg += "hwloc_topology_set_io_types_filter; "; goto done; } - if (hwloc_topology_set_cache_types_filter (topo, - HWLOC_TYPE_FILTER_KEEP_STRUCTURE) - < 0) { + if (hwloc_topology_set_cache_types_filter (topo, HWLOC_TYPE_FILTER_KEEP_STRUCTURE) < 0) { errno = EINVAL; m_err_msg += "hwloc_topology_set_cache_types_filter; "; goto done; } - if (hwloc_topology_set_icache_types_filter (topo, - HWLOC_TYPE_FILTER_KEEP_STRUCTURE) - < 0) { + if (hwloc_topology_set_icache_types_filter (topo, HWLOC_TYPE_FILTER_KEEP_STRUCTURE) < 0) { errno = EINVAL; m_err_msg += "hwloc_topology_set_icache_types_filter; "; goto done; } #endif - if ( hwloc_topology_set_xmlbuffer (topo, str.c_str (), len) != 0) { + if (hwloc_topology_set_xmlbuffer (topo, str.c_str (), len) != 0) { errno = EINVAL; m_err_msg += "Error setting xmlbuffer; "; goto done; } - if ( hwloc_topology_load (topo) != 0) { + if (hwloc_topology_load (topo) != 0) { hwloc_topology_destroy (topo); m_err_msg += "Error hwloc load: rank " + std::to_string (rank) + "; "; goto done; @@ -455,20 +449,18 @@ int resource_reader_hwloc_t::unpack_internal (resource_graph_t &g, return rc; } - - //////////////////////////////////////////////////////////////////////////////// // Public HWLOC Reader API //////////////////////////////////////////////////////////////////////////////// resource_reader_hwloc_t::~resource_reader_hwloc_t () { - } int resource_reader_hwloc_t::unpack (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &str, int rank) + const std::string &str, + int rank) { int rc = 0; vtx_t cluster_vertex; @@ -486,7 +478,8 @@ int resource_reader_hwloc_t::unpack (resource_graph_t &g, int resource_reader_hwloc_t::unpack_at (resource_graph_t &g, resource_graph_metadata_t &m, vtx_t &vtx, - const std::string &str, int rank) + const std::string &str, + int rank) { if (check_hwloc_version (m_err_msg) < 0) { return -1; @@ -498,26 +491,30 @@ int resource_reader_hwloc_t::remove_subgraph (resource_graph_t &g, resource_graph_metadata_t &m, const std::string &path) { - errno = ENOTSUP; // hwloc reader does not support remove - return -1; + errno = ENOTSUP; // hwloc reader does not support remove + return -1; } int resource_reader_hwloc_t::update (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &str, int64_t jobid, - int64_t at, uint64_t dur, bool rsv, + const std::string &str, + int64_t jobid, + int64_t at, + uint64_t dur, + bool rsv, uint64_t token) { - errno = ENOTSUP; // GRUG reader currently does not support update + errno = ENOTSUP; // GRUG reader currently does not support update return -1; } int resource_reader_hwloc_t::partial_cancel (resource_graph_t &g, - resource_graph_metadata_t &m, - modify_data_t &mod_data, - const std::string &R, int64_t jobid) + resource_graph_metadata_t &m, + modify_data_t &mod_data, + const std::string &R, + int64_t jobid) { - errno = ENOTSUP; // hwloc reader does not support partial cancel - return -1; + errno = ENOTSUP; // hwloc reader does not support partial cancel + return -1; } bool resource_reader_hwloc_t::is_allowlist_supported () diff --git a/resource/readers/resource_reader_hwloc.hpp b/resource/readers/resource_reader_hwloc.hpp index 3e315e562..4dcef6759 100644 --- a/resource/readers/resource_reader_hwloc.hpp +++ b/resource/readers/resource_reader_hwloc.hpp @@ -22,8 +22,7 @@ namespace resource_model { /*! Hwloc resource reader class. */ class resource_reader_hwloc_t : public resource_reader_base_t { -public: - + public: virtual ~resource_reader_hwloc_t (); /*! Unpack str into a resource graph. @@ -37,8 +36,10 @@ class resource_reader_hwloc_t : public resource_reader_base_t { * EINVAL: invalid input or operation (e.g. malformed str, * hwloc version or operation error) */ - virtual int unpack (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &str, int rank = -1); + virtual int unpack (resource_graph_t &g, + resource_graph_metadata_t &m, + const std::string &str, + int rank = -1); /*! Unpack str into a resource graph and graft * the top-level vertices to vtx. @@ -53,14 +54,17 @@ class resource_reader_hwloc_t : public resource_reader_base_t { * EINVAL: invalid input or operation (e.g. malformed str, * hwloc version or operation error) */ - virtual int unpack_at (resource_graph_t &g, resource_graph_metadata_t &m, - vtx_t &vtx, const std::string &str, int rank = -1); + virtual int unpack_at (resource_graph_t &g, + resource_graph_metadata_t &m, + vtx_t &vtx, + const std::string &str, + int rank = -1); virtual int remove_subgraph (resource_graph_t &g, resource_graph_metadata_t &m, const std::string &path); - /*! Update resource graph g with str. + /*! Update resource graph g with str. * * \param g resource graph * \param m resource graph meta data @@ -73,9 +77,14 @@ class resource_reader_hwloc_t : public resource_reader_base_t { * token to be used by traverser * \return 0 on success; non-zero integer on an error */ - virtual int update (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &str, int64_t jobid, int64_t at, - uint64_t dur, bool rsv, uint64_t trav_token); + virtual int update (resource_graph_t &g, + resource_graph_metadata_t &m, + const std::string &str, + int64_t jobid, + int64_t at, + uint64_t dur, + bool rsv, + uint64_t trav_token); /*! Partial cancellation of jobid based on R. * @@ -88,9 +97,10 @@ class resource_reader_hwloc_t : public resource_reader_base_t { * \return 0 on success; non-zero integer on an error */ virtual int partial_cancel (resource_graph_t &g, - resource_graph_metadata_t &m, - modify_data_t &mod_data, - const std::string &R, int64_t jobid); + resource_graph_metadata_t &m, + modify_data_t &mod_data, + const std::string &R, + int64_t jobid); /*! Is the hwloc reader format support allowlist * @@ -98,29 +108,42 @@ class resource_reader_hwloc_t : public resource_reader_base_t { */ virtual bool is_allowlist_supported (); -private: + private: int check_hwloc_version (std::string &m_err_msg); - vtx_t create_cluster_vertex (resource_graph_t &g, - resource_graph_metadata_t &m); - vtx_t add_new_vertex (resource_graph_t &g, resource_graph_metadata_t &m, - const vtx_t &parent, int64_t id, - const std::string &subsys, const std::string &type, - const std::string &basename, const std::string &name, + vtx_t create_cluster_vertex (resource_graph_t &g, resource_graph_metadata_t &m); + vtx_t add_new_vertex (resource_graph_t &g, + resource_graph_metadata_t &m, + const vtx_t &parent, + int64_t id, + const std::string &subsys, + const std::string &type, + const std::string &basename, + const std::string &name, const std::map &properties, - int size, int rank = -1); + int size, + int rank = -1); int add_metadata (resource_graph_metadata_t &m, - edg_t e, vtx_t src, vtx_t tgt, resource_graph_t &g); - int walk_hwloc (resource_graph_t &g, resource_graph_metadata_t &m, - const hwloc_topology_t topo, const hwloc_obj_t obj, - const vtx_t parent, int rank); - int unpack_internal (resource_graph_t &g, resource_graph_metadata_t &m, - vtx_t &vtx, const std::string &str, int rank = -1); + edg_t e, + vtx_t src, + vtx_t tgt, + resource_graph_t &g); + int walk_hwloc (resource_graph_t &g, + resource_graph_metadata_t &m, + const hwloc_topology_t topo, + const hwloc_obj_t obj, + const vtx_t parent, + int rank); + int unpack_internal (resource_graph_t &g, + resource_graph_metadata_t &m, + vtx_t &vtx, + const std::string &str, + int rank = -1); }; -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // RESOURCE_READER_HWLOC_HPP +#endif // RESOURCE_READER_HWLOC_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/readers/resource_reader_jgf.cpp b/resource/readers/resource_reader_jgf.cpp index 42b1b2679..d36dad10d 100644 --- a/resource/readers/resource_reader_jgf.cpp +++ b/resource/readers/resource_reader_jgf.cpp @@ -26,7 +26,7 @@ using namespace Flux; using namespace Flux::resource_model; class fetch_remap_support_t { -public: + public: int64_t get_remapped_id () const; int64_t get_remapped_rank () const; const std::string &get_remapped_name () const; @@ -38,7 +38,7 @@ class fetch_remap_support_t { bool is_rank_remapped () const; void clear (); -private: + private: int64_t m_remapped_id = -1; int64_t m_remapped_rank = -1; std::string m_remapped_name = ""; @@ -60,7 +60,7 @@ struct fetch_helper_t : public fetch_remap_support_t { const char *name = NULL; const char *unit = NULL; const char *basename = NULL; - const char *vertex_id= NULL; + const char *vertex_id = NULL; std::map properties; std::map paths; }; @@ -119,17 +119,17 @@ void fetch_remap_support_t::clear () const char *fetch_helper_t::get_proper_name () const { - return (is_name_remapped ())? get_remapped_name ().c_str () : name; + return (is_name_remapped ()) ? get_remapped_name ().c_str () : name; } int64_t fetch_helper_t::get_proper_id () const { - return (is_id_remapped ())? get_remapped_id () : id; + return (is_id_remapped ()) ? get_remapped_id () : id; } int64_t fetch_helper_t::get_proper_rank () const { - return (is_rank_remapped ())? get_remapped_rank () : rank; + return (is_rank_remapped ()) ? get_remapped_rank () : rank; } void fetch_helper_t::scrub () @@ -150,7 +150,6 @@ void fetch_helper_t::scrub () clear (); } - struct vmap_val_t { vtx_t v; std::map is_roots; @@ -161,19 +160,14 @@ struct vmap_val_t { bool operator== (const std::map lhs, const std::map rhs) { - return (lhs.size () == rhs.size ()) - && (std::equal (lhs.begin (), lhs.end (), rhs.begin ())); + return (lhs.size () == rhs.size ()) && (std::equal (lhs.begin (), lhs.end (), rhs.begin ())); } bool operator== (const resource_pool_t &r, const fetch_helper_t &f) { - return (r.type == f.type - && r.basename == f.basename - && r.size == static_cast (f.size) - && r.rank == static_cast (f.rank) - && r.id == f.id - && r.name == f.name - && r.properties == f.properties + return (r.type == f.type && r.basename == f.basename + && r.size == static_cast (f.size) && r.rank == static_cast (f.rank) + && r.id == f.id && r.name == f.name && r.properties == f.properties && r.paths == f.paths); } @@ -216,19 +210,20 @@ std::string diff (const resource_pool_t &r, const fetch_helper_t &f) return sstream.str (); } - //////////////////////////////////////////////////////////////////////////////// // Private JGF Resource Reader //////////////////////////////////////////////////////////////////////////////// -int resource_reader_jgf_t::fetch_jgf (const std::string &str, json_t **jgf_p, - json_t **nodes_p, json_t **edges_p) +int resource_reader_jgf_t::fetch_jgf (const std::string &str, + json_t **jgf_p, + json_t **nodes_p, + json_t **edges_p) { int rc = -1; json_t *graph = NULL; json_error_t json_err; - if ( (*jgf_p = json_loads (str.c_str (), 0, &json_err)) == NULL) { + if ((*jgf_p = json_loads (str.c_str (), 0, &json_err)) == NULL) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": json_loads returned an error: "; @@ -238,19 +233,19 @@ int resource_reader_jgf_t::fetch_jgf (const std::string &str, json_t **jgf_p, + std::to_string (json_err.column) + ".\n"; goto done; } - if ( (graph = json_object_get (*jgf_p, "graph" )) == NULL) { + if ((graph = json_object_get (*jgf_p, "graph")) == NULL) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": JGF does not contain a required key (graph).\n"; goto done; } - if ( (*nodes_p = json_object_get (graph, "nodes" )) == NULL) { + if ((*nodes_p = json_object_get (graph, "nodes")) == NULL) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": JGF does not contain a required key (nodes).\n"; goto done; } - if ( (*edges_p = json_object_get (graph, "edges" )) == NULL) { + if ((*edges_p = json_object_get (graph, "edges")) == NULL) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": JGF does not contain a required key (edges).\n"; @@ -274,16 +269,13 @@ int resource_reader_jgf_t::unpack_and_remap_vtx (fetch_helper_t &f, uint64_t remap_rank; uint64_t remap_id; - if (namespace_remapper.query_exec_target ( - static_cast (f.rank), - remap_rank) < 0) { + if (namespace_remapper.query_exec_target (static_cast (f.rank), remap_rank) < 0) { m_err_msg += __FUNCTION__; m_err_msg += ": error remapping rank id="; m_err_msg += std::to_string (f.rank) + ".\n"; goto error; } - if (remap_rank - > static_cast (std::numeric_limits::max ())) { + if (remap_rank > static_cast (std::numeric_limits::max ())) { errno = EOVERFLOW; m_err_msg += __FUNCTION__; m_err_msg += ": remapped rank too large.\n"; @@ -298,8 +290,7 @@ int resource_reader_jgf_t::unpack_and_remap_vtx (fetch_helper_t &f, m_err_msg += " rank=" + std::to_string (f.rank) + ".\n"; goto error; } - if (remap_id - > static_cast (std::numeric_limits::max ())) { + if (remap_id > static_cast (std::numeric_limits::max ())) { errno = EOVERFLOW; m_err_msg += __FUNCTION__; m_err_msg += ": remapped id too large.\n"; @@ -311,16 +302,15 @@ int resource_reader_jgf_t::unpack_and_remap_vtx (fetch_helper_t &f, json_object_foreach (paths, key, value) { std::string path = json_string_value (value); std::size_t sl = path.find_last_of ("/"); - if (sl == std::string::npos || path.substr (sl+1, 4) != "core") { + if (sl == std::string::npos || path.substr (sl + 1, 4) != "core") { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": malformed path for core id="; m_err_msg += std::to_string (f.id) + ".\n"; goto error; } - f.paths[std::string (key)] = path.substr (0, sl+1) - + f.basename - + std::to_string (remap_id); + f.paths[std::string (key)] = + path.substr (0, sl + 1) + f.basename + std::to_string (remap_id); } } else { json_object_foreach (paths, key, value) { @@ -329,8 +319,7 @@ int resource_reader_jgf_t::unpack_and_remap_vtx (fetch_helper_t &f, } json_object_foreach (properties, key, value) { - f.properties[std::string (key)] - = std::string (json_string_value (value)); + f.properties[std::string (key)] = std::string (json_string_value (value)); } return 0; error: @@ -352,46 +341,64 @@ int resource_reader_jgf_t::remap_aware_unpack_vtx (fetch_helper_t &f, f.paths[std::string (key)] = std::string (json_string_value (value)); } json_object_foreach (properties, key, value) { - f.properties[std::string (key)] - = std::string (json_string_value (value)); + f.properties[std::string (key)] = std::string (json_string_value (value)); } } return 0; } -int resource_reader_jgf_t::fill_fetcher (json_t *element, fetch_helper_t &f, - json_t **paths, json_t **properties) +int resource_reader_jgf_t::fill_fetcher (json_t *element, + fetch_helper_t &f, + json_t **paths, + json_t **properties) { int rc = -1; json_t *p = NULL; json_t *metadata = NULL; - if ( (json_unpack (element, "{ s:s }", "id", &f.vertex_id) < 0)) { + if ((json_unpack (element, "{ s:s }", "id", &f.vertex_id) < 0)) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": JGF vertex id key is not found in a node.\n"; goto done; } - if ( (metadata = json_object_get (element, "metadata")) == NULL) { + if ((metadata = json_object_get (element, "metadata")) == NULL) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": key (metadata) is not found in an JGF node for "; m_err_msg += std::string (f.vertex_id) + ".\n"; goto done; } - if ( (json_unpack (metadata, "{ s:s s:s s:s s:I s:I s:I s?:i s:b s:s s:I }", - "type", &f.type, "basename", &f.basename, - "name", &f.name, "id", &f.id, - "uniq_id", &f.uniq_id, "rank", &f.rank, - "status", &f.status, "exclusive", &f.exclusive, - "unit", &f.unit, "size", &f.size)) < 0) { + if ((json_unpack (metadata, + "{ s:s s:s s:s s:I s:I s:I s?:i s:b s:s s:I }", + "type", + &f.type, + "basename", + &f.basename, + "name", + &f.name, + "id", + &f.id, + "uniq_id", + &f.uniq_id, + "rank", + &f.rank, + "status", + &f.status, + "exclusive", + &f.exclusive, + "unit", + &f.unit, + "size", + &f.size)) + < 0) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": malformed metadata in an JGF node for "; m_err_msg += std::string (f.vertex_id) + "\n"; goto done; } - if ( (p = json_object_get (metadata, "paths")) == NULL) { + if ((p = json_object_get (metadata, "paths")) == NULL) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": key (paths) does not exist in an JGF node for "; @@ -423,20 +430,18 @@ int resource_reader_jgf_t::unpack_vtx (json_t *element, fetch_helper_t &f) return 0; } -vtx_t resource_reader_jgf_t::create_vtx (resource_graph_t &g, - const fetch_helper_t &fetcher) +vtx_t resource_reader_jgf_t::create_vtx (resource_graph_t &g, const fetch_helper_t &fetcher) { planner_t *plans = NULL; planner_t *x_checker = NULL; vtx_t v = boost::graph_traits::null_vertex (); - if ( !(plans = planner_new (0, INT64_MAX, fetcher.size, fetcher.type))) { + if (!(plans = planner_new (0, INT64_MAX, fetcher.size, fetcher.type))) { m_err_msg += __FUNCTION__; m_err_msg += ": planner_new returned NULL.\n"; goto done; } - if ( !(x_checker = planner_new (0, INT64_MAX, - X_CHECKER_NJOBS, X_CHECKER_JOBS_STR))) { + if (!(x_checker = planner_new (0, INT64_MAX, X_CHECKER_NJOBS, X_CHECKER_JOBS_STR))) { m_err_msg += __FUNCTION__; m_err_msg += "planner_new for x_checker returned NULL.\n"; goto done; @@ -464,8 +469,7 @@ vtx_t resource_reader_jgf_t::create_vtx (resource_graph_t &g, vtx_t resource_reader_jgf_t::vtx_in_graph (const resource_graph_t &g, const resource_graph_metadata_t &m, - const std::map &paths, + const std::map &paths, int rank) { for (const auto &paths_it : paths) { @@ -487,7 +491,8 @@ bool resource_reader_jgf_t::is_root (const std::string &path) return (std::count (path.begin (), path.end (), '/') == 1); } -int resource_reader_jgf_t::check_root (vtx_t v, resource_graph_t &g, +int resource_reader_jgf_t::check_root (vtx_t v, + resource_graph_t &g, std::map &is_roots) { int rc = -1; @@ -543,27 +548,24 @@ int resource_reader_jgf_t::remove_graph_metadata (vtx_t v, for (auto &kv : g[v].paths) { m.by_path.erase (kv.second); } - + m.by_outedges.erase (v); - for (auto it = m.by_type[g[v].type].begin (); - it != m.by_type[g[v].type].end (); ++it) { + for (auto it = m.by_type[g[v].type].begin (); it != m.by_type[g[v].type].end (); ++it) { if (*it == v) { m.by_type[g[v].type].erase (it); break; } } - for (auto it = m.by_name[g[v].name].begin (); - it != m.by_name[g[v].name].end (); ++it) { + for (auto it = m.by_name[g[v].name].begin (); it != m.by_name[g[v].name].end (); ++it) { if (*it == v) { m.by_name[g[v].name].erase (it); break; } } - for (auto it = m.by_rank[g[v].rank].begin (); - it != m.by_rank[g[v].rank].end (); ++it) { + for (auto it = m.by_rank[g[v].rank].begin (); it != m.by_rank[g[v].rank].end (); ++it) { if (*it == v) { m.by_rank[g[v].rank].erase (it); break; @@ -587,8 +589,8 @@ int resource_reader_jgf_t::remove_metadata_outedges (vtx_t source_vertex, auto &outedges = iter->second; for (auto kv = outedges.begin (); kv != outedges.end (); ++kv) { if (boost::target (kv->second, g) == dest_vertex) { - kv = outedges.erase (kv); - // TODO: Consider adding break here + kv = outedges.erase (kv); + // TODO: Consider adding break here } } @@ -596,19 +598,18 @@ int resource_reader_jgf_t::remove_metadata_outedges (vtx_t source_vertex, return rc; } -int resource_reader_jgf_t::update_vmap (std::map &vmap, +int resource_reader_jgf_t::update_vmap (std::map &vmap, vtx_t v, - const std::map &root_checks, + const std::map &root_checks, const fetch_helper_t &fetcher) { int rc = -1; std::pair::iterator, bool> ptr; ptr = vmap.emplace (std::string (fetcher.vertex_id), - vmap_val_t{v, root_checks, - static_cast (fetcher.size), - static_cast (fetcher.exclusive)}); + vmap_val_t{v, + root_checks, + static_cast (fetcher.size), + static_cast (fetcher.exclusive)}); if (!ptr.second) { m_err_msg += __FUNCTION__; m_err_msg += ": can't insert into vmap for "; @@ -639,13 +640,13 @@ int resource_reader_jgf_t::add_vtx (resource_graph_t &g, m_err_msg += std::string (fetcher.vertex_id) + ".\n"; goto done; } - if ( (v = create_vtx (g, fetcher)) == nullvtx) + if ((v = create_vtx (g, fetcher)) == nullvtx) goto done; - if ( (rc = check_root (v, g, root_checks)) == -1) + if ((rc = check_root (v, g, root_checks)) == -1) goto done; - if ( (rc = add_graph_metadata (v, g, m)) == -1) + if ((rc = add_graph_metadata (v, g, m)) == -1) goto done; - if ( (rc = update_vmap (vmap, v, root_checks, fetcher)) != 0) + if ((rc = update_vmap (vmap, v, root_checks, fetcher)) != 0) goto done; rc = 0; @@ -655,8 +656,10 @@ int resource_reader_jgf_t::add_vtx (resource_graph_t &g, int resource_reader_jgf_t::exist (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &path, int rank, - const std::string &vid, vtx_t &v) + const std::string &path, + int rank, + const std::string &vid, + vtx_t &v) { try { auto &vect = m.by_path.at (path); @@ -726,7 +729,8 @@ int resource_reader_jgf_t::find_vtx (resource_graph_t &g, return rc; } -int resource_reader_jgf_t::update_vtx_plan (vtx_t v, resource_graph_t &g, +int resource_reader_jgf_t::update_vtx_plan (vtx_t v, + resource_graph_t &g, const fetch_helper_t &fetcher, jgf_updater_data &update_data) { @@ -735,15 +739,14 @@ int resource_reader_jgf_t::update_vtx_plan (vtx_t v, resource_graph_t &g, int64_t avail = -1; planner_t *plans = NULL; - if ( (plans = g[v].schedule.plans) == NULL) { + if ((plans = g[v].schedule.plans) == NULL) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": plan for " + g[v].name + " is null.\n"; goto done; } - if ( (avail = planner_avail_resources_during (plans, - update_data.at, - update_data.duration)) == -1) { + if ((avail = planner_avail_resources_during (plans, update_data.at, update_data.duration)) + == -1) { m_err_msg += __FUNCTION__; m_err_msg += ": planner_avail_resource_during return -1 for "; m_err_msg += g[v].name + ".\n"; @@ -753,9 +756,11 @@ int resource_reader_jgf_t::update_vtx_plan (vtx_t v, resource_graph_t &g, if (fetcher.exclusive) { // Update the vertex plan here (not in traverser code) so vertices // that the traverser won't walk still get their plans updated. - if ( (span = planner_add_span (plans, update_data.at, - update_data.duration, - static_cast (g[v].size))) == -1) { + if ((span = planner_add_span (plans, + update_data.at, + update_data.duration, + static_cast (g[v].size))) + == -1) { m_err_msg += __FUNCTION__; m_err_msg += ": can't add span into " + g[v].name + ".\n"; goto done; @@ -778,7 +783,8 @@ int resource_reader_jgf_t::update_vtx_plan (vtx_t v, resource_graph_t &g, return rc; } -int resource_reader_jgf_t::cancel_vtx (vtx_t vtx, resource_graph_t &g, +int resource_reader_jgf_t::cancel_vtx (vtx_t vtx, + resource_graph_t &g, resource_graph_metadata_t &m, const fetch_helper_t &fetcher, jgf_updater_data &update_data) @@ -838,8 +844,8 @@ int resource_reader_jgf_t::cancel_vtx (vtx_t vtx, resource_graph_t &g, goto ret; } // Add the newly freed counts, Can't assume it freed everything. - update_data.type_to_count[g[vtx].type.c_str ()] - += (planner_avail_resources_at (plans, 0) - prev_avail); + update_data.type_to_count[g[vtx].type.c_str ()] += + (planner_avail_resources_at (plans, 0) - prev_avail); update_data.ranks.insert (g[vtx].rank); rc = 0; @@ -859,17 +865,17 @@ int resource_reader_jgf_t::update_vtx (resource_graph_t &g, vtx_t v = boost::graph_traits::null_vertex (); std::pair::iterator, bool> ptr; - if ( (rc = find_vtx (g, m, vmap, fetcher, v)) != 0) + if ((rc = find_vtx (g, m, vmap, fetcher, v)) != 0) goto done; - if ( (rc = check_root (v, g, root_checks)) != 0) + if ((rc = check_root (v, g, root_checks)) != 0) goto done; - if ( (rc = update_vmap (vmap, v, root_checks, fetcher)) != 0) + if ((rc = update_vmap (vmap, v, root_checks, fetcher)) != 0) goto done; if (update_data.update) { - if ( (rc = update_vtx_plan (v, g, fetcher, update_data)) != 0) + if ((rc = update_vtx_plan (v, g, fetcher, update_data)) != 0) goto done; } else { - if ( (rc = cancel_vtx (v, g, m, fetcher, update_data)) != 0) + if ((rc = cancel_vtx (v, g, m, fetcher, update_data)) != 0) goto done; } @@ -901,7 +907,7 @@ int resource_reader_jgf_t::undo_vertices (resource_graph_t &g, } plans = g[v].schedule.plans; - if ( (rc2 = planner_rem_span (plans, span)) == -1) { + if ((rc2 = planner_rem_span (plans, span)) == -1) { m_err_msg += __FUNCTION__; m_err_msg += ": can't remove span from " + g[v].name + "\n."; m_err_msg += "resource graph state is likely corrupted.\n"; @@ -913,16 +919,14 @@ int resource_reader_jgf_t::undo_vertices (resource_graph_t &g, } } - return (!rc)? 0 : -1; + return (!rc) ? 0 : -1; } int resource_reader_jgf_t::unpack_vertices (resource_graph_t &g, resource_graph_metadata_t &m, - std::map &vmap, + std::map &vmap, json_t *nodes, - std::unordered_set - &added_vtcs) + std::unordered_set &added_vtcs) { int rc = -1; unsigned int i = 0; @@ -938,8 +942,7 @@ int resource_reader_jgf_t::unpack_vertices (resource_graph_t &g, // If the vertex isn't in the graph, add it vtx_t v = boost::graph_traits::null_vertex (); - if ( (v = vtx_in_graph (g, m, - fetcher.paths, fetcher.rank)) == null_vtx) { + if ((v = vtx_in_graph (g, m, fetcher.paths, fetcher.rank)) == null_vtx) { if (add_vtx (g, m, vmap, fetcher) != 0) goto done; auto res = added_vtcs.insert (std::string (fetcher.vertex_id)); @@ -951,7 +954,7 @@ int resource_reader_jgf_t::unpack_vertices (resource_graph_t &g, goto done; } } else { - if ( (rc = update_vmap (vmap, v, root_checks, fetcher)) != 0) + if ((rc = update_vmap (vmap, v, root_checks, fetcher)) != 0) goto done; } } @@ -963,8 +966,7 @@ int resource_reader_jgf_t::unpack_vertices (resource_graph_t &g, int resource_reader_jgf_t::update_vertices (resource_graph_t &g, resource_graph_metadata_t &m, - std::map &vmap, + std::map &vmap, json_t *nodes, jgf_updater_data &update_data) { @@ -974,9 +976,9 @@ int resource_reader_jgf_t::update_vertices (resource_graph_t &g, for (i = 0; i < json_array_size (nodes); i++) { fetcher.scrub (); - if ( (rc = unpack_vtx (json_array_get (nodes, i), fetcher)) != 0) + if ((rc = unpack_vtx (json_array_get (nodes, i), fetcher)) != 0) goto done; - if ( (rc = update_vtx (g, m, vmap, fetcher, update_data)) != 0) + if ((rc = update_vtx (g, m, vmap, fetcher, update_data)) != 0) goto done; } rc = 0; @@ -986,8 +988,7 @@ int resource_reader_jgf_t::update_vertices (resource_graph_t &g, } int resource_reader_jgf_t::unpack_edge (json_t *element, - std::map &vmap, + std::map &vmap, std::string &source, std::string &target, json_t **name) @@ -997,8 +998,7 @@ int resource_reader_jgf_t::unpack_edge (json_t *element, const char *src = NULL; const char *tgt = NULL; - if ( (json_unpack (element, "{ s:s s:s }", "source", &src, - "target", &tgt)) < 0) { + if ((json_unpack (element, "{ s:s s:s }", "source", &src, "target", &tgt)) < 0) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": encountered a malformed edge.\n"; @@ -1006,22 +1006,21 @@ int resource_reader_jgf_t::unpack_edge (json_t *element, } source = src; target = tgt; - if (vmap.find (source) == vmap.end () - || vmap.find (target) == vmap.end ()) { + if (vmap.find (source) == vmap.end () || vmap.find (target) == vmap.end ()) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": source and/or target vertex not found"; m_err_msg += source + std::string (" -> ") + target + ".\n"; goto done; } - if ( (metadata = json_object_get (element, "metadata")) == NULL) { + if ((metadata = json_object_get (element, "metadata")) == NULL) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": metadata key not found in an edge for "; m_err_msg += source + std::string (" -> ") + target + ".\n"; goto done; } - if ( (*name = json_object_get (metadata, "name")) == NULL) { + if ((*name = json_object_get (metadata, "name")) == NULL) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": name key not found in edge metadata.\n"; @@ -1035,11 +1034,9 @@ int resource_reader_jgf_t::unpack_edge (json_t *element, int resource_reader_jgf_t::unpack_edges (resource_graph_t &g, resource_graph_metadata_t &m, - std::map &vmap, + std::map &vmap, json_t *edges, - const std::unordered_set - &added_vtcs) + const std::unordered_set &added_vtcs) { edg_t e; int rc = -1; @@ -1054,11 +1051,10 @@ int resource_reader_jgf_t::unpack_edges (resource_graph_t &g, for (i = 0; i < json_array_size (edges); i++) { element = json_array_get (edges, i); - if ( (unpack_edge (element, vmap, source, target, &name)) != 0) + if ((unpack_edge (element, vmap, source, target, &name)) != 0) goto done; // We only add the edge when it connects at least one newly added vertex - if ( (added_vtcs.count (source) == 1) - || (added_vtcs.count (target) == 1)) { + if ((added_vtcs.count (source) == 1) || (added_vtcs.count (target) == 1)) { tie (e, inserted) = add_edge (vmap[source].v, vmap[target].v, g); if (inserted == false) { errno = EINVAL; @@ -1079,30 +1075,25 @@ int resource_reader_jgf_t::unpack_edges (resource_graph_t &g, auto iter = m.by_outedges.find (vmap[source].v); if (iter == m.by_outedges.end ()) { auto ret = m.by_outedges.insert ( - std::make_pair ( - vmap[source].v, - std::map, edg_t, - std::greater< - std::pair>> ())); + std::make_pair (vmap[source].v, + std::map, + edg_t, + std::greater>> ())); if (!ret.second) { errno = ENOMEM; - m_err_msg += "error creating out-edge metadata map: " - + g[vmap[source].v].name + " -> " - + g[vmap[target].v].name + "; "; + m_err_msg += "error creating out-edge metadata map: " + g[vmap[source].v].name + + " -> " + g[vmap[target].v].name + "; "; goto done; } iter = m.by_outedges.find (vmap[source].v); } - std::pair key = std::make_pair ( - g[e].idata.get_weight (), - g[vmap[target].v].uniq_id); + std::pair key = + std::make_pair (g[e].idata.get_weight (), g[vmap[target].v].uniq_id); auto ret = iter->second.insert (std::make_pair (key, e)); if (!ret.second) { errno = EEXIST; m_err_msg += "error inserting an edge to outedge metadata map: " - + g[vmap[source].v].name + " -> " - + g[vmap[target].v].name + "; "; + + g[vmap[source].v].name + " -> " + g[vmap[target].v].name + "; "; goto done; } } @@ -1115,8 +1106,7 @@ int resource_reader_jgf_t::unpack_edges (resource_graph_t &g, int resource_reader_jgf_t::update_src_edge (resource_graph_t &g, resource_graph_metadata_t &m, - std::map &vmap, + std::map &vmap, std::string &source, uint64_t token) { @@ -1136,8 +1126,7 @@ int resource_reader_jgf_t::update_src_edge (resource_graph_t &g, int resource_reader_jgf_t::update_tgt_edge (resource_graph_t &g, resource_graph_metadata_t &m, - std::map &vmap, + std::map &vmap, std::string &source, std::string &target, uint64_t token) @@ -1161,8 +1150,7 @@ int resource_reader_jgf_t::update_tgt_edge (resource_graph_t &g, m_err_msg += ": JGF edge not found in resource graph.\n"; goto done; } - g[e].idata.set_for_trav_update (vmap[target].needs, - vmap[target].exclusive, token); + g[e].idata.set_for_trav_update (vmap[target].needs, vmap[target].exclusive, token); rc = 0; done: @@ -1171,9 +1159,9 @@ int resource_reader_jgf_t::update_tgt_edge (resource_graph_t &g, int resource_reader_jgf_t::update_edges (resource_graph_t &g, resource_graph_metadata_t &m, - std::map &vmap, - json_t *edges, uint64_t token) + std::map &vmap, + json_t *edges, + uint64_t token) { edg_t e; int rc = -1; @@ -1186,11 +1174,11 @@ int resource_reader_jgf_t::update_edges (resource_graph_t &g, for (i = 0; i < json_array_size (edges); i++) { element = json_array_get (edges, i); // We only check protocol errors in JGF edges in the following... - if ( (rc = unpack_edge (element, vmap, source, target, &name)) != 0) + if ((rc = unpack_edge (element, vmap, source, target, &name)) != 0) goto done; - if ( (rc = update_src_edge (g, m, vmap, source, token)) != 0) + if ((rc = update_src_edge (g, m, vmap, source, token)) != 0) goto done; - if ( (rc = update_tgt_edge (g, m, vmap, source, target, token)) != 0) + if ((rc = update_tgt_edge (g, m, vmap, source, target, token)) != 0) goto done; } @@ -1207,25 +1195,23 @@ int resource_reader_jgf_t::get_subgraph_vertices (resource_graph_t &g, boost::tie (ei, ei_end) = boost::out_edges (vtx, g); for (; ei != ei_end; ++ei) { - next_vtx = boost::target (*ei, g); - + next_vtx = boost::target (*ei, g); + for (const auto &paths_it : g[next_vtx].paths) { - // check that we don't recurse on parent edges - if (paths_it.second.find (g[vtx].name) != std::string::npos && - paths_it.second.find (g[vtx].name) < paths_it.second.find (g[next_vtx].name)) { + // check that we don't recurse on parent edges + if (paths_it.second.find (g[vtx].name) != std::string::npos + && paths_it.second.find (g[vtx].name) < paths_it.second.find (g[next_vtx].name)) { vtx_list.push_back (next_vtx); get_subgraph_vertices (g, next_vtx, vtx_list); break; } - } - } + } + } - return 0; + return 0; } -int resource_reader_jgf_t::get_parent_vtx (resource_graph_t &g, - vtx_t vtx, - vtx_t &parent_vtx) +int resource_reader_jgf_t::get_parent_vtx (resource_graph_t &g, vtx_t vtx, vtx_t &parent_vtx) { vtx_t next_vtx; boost::graph_traits::in_edge_iterator ei, ei_end; @@ -1233,7 +1219,7 @@ int resource_reader_jgf_t::get_parent_vtx (resource_graph_t &g, int rc = -1; for (; ei != ei_end; ++ei) { - next_vtx = boost::source (*ei, g); + next_vtx = boost::source (*ei, g); if (g[*ei].name.contains ("containment")) { parent_vtx = next_vtx; rc = 0; @@ -1244,20 +1230,18 @@ int resource_reader_jgf_t::get_parent_vtx (resource_graph_t &g, return rc; } - - //////////////////////////////////////////////////////////////////////////////// // Public JGF Resource Reader Interface //////////////////////////////////////////////////////////////////////////////// resource_reader_jgf_t::~resource_reader_jgf_t () { - } int resource_reader_jgf_t::unpack (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &str, int rank) + const std::string &str, + int rank) { int rc = -1; @@ -1273,11 +1257,11 @@ int resource_reader_jgf_t::unpack (resource_graph_t &g, m_err_msg += "rank != -1 unsupported for JGF unpack.\n"; goto done; } - if ( (rc = fetch_jgf (str, &jgf, &nodes, &edges)) != 0) + if ((rc = fetch_jgf (str, &jgf, &nodes, &edges)) != 0) goto done; - if ( (rc = unpack_vertices (g, m, vmap, nodes, added_vtcs)) != 0) + if ((rc = unpack_vertices (g, m, vmap, nodes, added_vtcs)) != 0) goto done; - if ( (rc = unpack_edges (g, m, vmap, edges, added_vtcs)) != 0) + if ((rc = unpack_edges (g, m, vmap, edges, added_vtcs)) != 0) goto done; done: @@ -1286,8 +1270,10 @@ int resource_reader_jgf_t::unpack (resource_graph_t &g, } int resource_reader_jgf_t::unpack_at (resource_graph_t &g, - resource_graph_metadata_t &m, vtx_t &vtx, - const std::string &str, int rank) + resource_graph_metadata_t &m, + vtx_t &vtx, + const std::string &str, + int rank) { /* This functionality is currently experimental, as resource graph * growth causes a resize of the boost vecS vertex container type. @@ -1302,8 +1288,11 @@ int resource_reader_jgf_t::unpack_at (resource_graph_t &g, int resource_reader_jgf_t::update (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &str, int64_t jobid, - int64_t at, uint64_t dur, bool rsv, + const std::string &str, + int64_t jobid, + int64_t at, + uint64_t dur, + bool rsv, uint64_t token) { int rc = -1; @@ -1316,9 +1305,8 @@ int resource_reader_jgf_t::update (resource_graph_t &g, if (at < 0 || dur == 0) { errno = EINVAL; m_err_msg += __FUNCTION__; - m_err_msg += ": invalid time (" - + std::to_string (at) + ", " - + std::to_string (dur) + ").\n"; + m_err_msg += + ": invalid time (" + std::to_string (at) + ", " + std::to_string (dur) + ").\n"; goto done; } @@ -1329,13 +1317,13 @@ int resource_reader_jgf_t::update (resource_graph_t &g, update_data.reserved = rsv; update_data.update = true; - if ( (rc = fetch_jgf (str, &jgf, &nodes, &edges)) != 0) + if ((rc = fetch_jgf (str, &jgf, &nodes, &edges)) != 0) goto done; - if ( (rc = update_vertices (g, m, vmap, nodes, update_data)) != 0) { + if ((rc = update_vertices (g, m, vmap, nodes, update_data)) != 0) { undo_vertices (g, vmap, update_data); goto done; } - if ( (rc = update_edges (g, m, vmap, edges, token)) != 0) + if ((rc = update_edges (g, m, vmap, edges, token)) != 0) goto done; done: @@ -1363,10 +1351,10 @@ int resource_reader_jgf_t::remove_subgraph (resource_graph_t &g, vtx_list.push_back (subgraph_root_vtx); get_subgraph_vertices (g, subgraph_root_vtx, vtx_list); - + if (get_parent_vtx (g, subgraph_root_vtx, parent_vtx) != 0) return -1; - + if (remove_metadata_outedges (parent_vtx, subgraph_root_vtx, g, m) != 0) return -1; @@ -1377,13 +1365,13 @@ int resource_reader_jgf_t::remove_subgraph (resource_graph_t &g, } return 0; - } int resource_reader_jgf_t::partial_cancel (resource_graph_t &g, - resource_graph_metadata_t &m, - modify_data_t &mod_data, - const std::string &R, int64_t jobid) + resource_graph_metadata_t &m, + modify_data_t &mod_data, + const std::string &R, + int64_t jobid) { int rc = -1; json_t *jgf = NULL; @@ -1403,9 +1391,9 @@ int resource_reader_jgf_t::partial_cancel (resource_graph_t &g, p_cancel_data.jobid = jobid; p_cancel_data.update = false; - if ( (rc = fetch_jgf (R, &jgf, &nodes, &edges)) != 0) + if ((rc = fetch_jgf (R, &jgf, &nodes, &edges)) != 0) goto done; - if ( (rc = update_vertices (g, m, vmap, nodes, p_cancel_data)) != 0) + if ((rc = update_vertices (g, m, vmap, nodes, p_cancel_data)) != 0) goto done; mod_data.type_to_count = p_cancel_data.type_to_count; diff --git a/resource/readers/resource_reader_jgf.hpp b/resource/readers/resource_reader_jgf.hpp index 7de01f29f..d392b87c3 100644 --- a/resource/readers/resource_reader_jgf.hpp +++ b/resource/readers/resource_reader_jgf.hpp @@ -34,14 +34,13 @@ struct jgf_updater_data { // track count of rank vertices to determine if rank // should be removed from by_rank map std::unordered_set ranks; - bool update = true; // Updating or partial cancel + bool update = true; // Updating or partial cancel }; /*! JGF resource reader class. */ class resource_reader_jgf_t : public resource_reader_base_t { -public: - + public: virtual ~resource_reader_jgf_t (); /*! Unpack str into a resource graph. @@ -54,8 +53,10 @@ class resource_reader_jgf_t : public resource_reader_base_t { * ENOMEM: out of memory * EINVAL: invalid input or operation */ - virtual int unpack (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &str, int rank = -1); + virtual int unpack (resource_graph_t &g, + resource_graph_metadata_t &m, + const std::string &str, + int rank = -1); /*! Unpack str into a resource graph and graft * the top-level vertices to vtx. @@ -67,8 +68,11 @@ class resource_reader_jgf_t : public resource_reader_base_t { * \param rank assign this rank to all the newly created resource vertices * \return -1 with errno=ENOTSUP (Not supported yet) */ - virtual int unpack_at (resource_graph_t &g, resource_graph_metadata_t &m, - vtx_t &vtx, const std::string &str, int rank = -1); + virtual int unpack_at (resource_graph_t &g, + resource_graph_metadata_t &m, + vtx_t &vtx, + const std::string &str, + int rank = -1); /*! Update resource graph g with str. * @@ -83,9 +87,14 @@ class resource_reader_jgf_t : public resource_reader_base_t { * token to be used by traverser * \return 0 on success; non-zero integer on an error */ - virtual int update (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &str, int64_t jobid, int64_t at, - uint64_t dur, bool rsv, uint64_t trav_token); + virtual int update (resource_graph_t &g, + resource_graph_metadata_t &m, + const std::string &str, + int64_t jobid, + int64_t at, + uint64_t dur, + bool rsv, + uint64_t trav_token); virtual int remove_subgraph (resource_graph_t &g, resource_graph_metadata_t &m, @@ -102,9 +111,10 @@ class resource_reader_jgf_t : public resource_reader_base_t { * \return 0 on success; non-zero integer on an error */ virtual int partial_cancel (resource_graph_t &g, - resource_graph_metadata_t &m, - modify_data_t &mod_data, - const std::string &R, int64_t jobid); + resource_graph_metadata_t &m, + modify_data_t &mod_data, + const std::string &R, + int64_t jobid); /*! Is the selected reader format support allowlist * @@ -112,94 +122,105 @@ class resource_reader_jgf_t : public resource_reader_base_t { */ virtual bool is_allowlist_supported (); -private: - int fetch_jgf (const std::string &str, - json_t **jgf_p, json_t **nodes_p, json_t **edges_p); - int unpack_and_remap_vtx (fetch_helper_t &f, - json_t *paths, json_t *properties); - int remap_aware_unpack_vtx (fetch_helper_t &f, - json_t *paths, json_t *properties); - int fill_fetcher (json_t *element, fetch_helper_t &f, - json_t **path, json_t **properties); + private: + int fetch_jgf (const std::string &str, json_t **jgf_p, json_t **nodes_p, json_t **edges_p); + int unpack_and_remap_vtx (fetch_helper_t &f, json_t *paths, json_t *properties); + int remap_aware_unpack_vtx (fetch_helper_t &f, json_t *paths, json_t *properties); + int fill_fetcher (json_t *element, fetch_helper_t &f, json_t **path, json_t **properties); int unpack_vtx (json_t *element, fetch_helper_t &f); vtx_t create_vtx (resource_graph_t &g, const fetch_helper_t &fetcher); vtx_t vtx_in_graph (const resource_graph_t &g, const resource_graph_metadata_t &m, - const std::map &paths, int rank); + const std::map &paths, + int rank); bool is_root (const std::string &path); - int check_root (vtx_t v, resource_graph_t &g, - std::map &is_roots); - int add_graph_metadata (vtx_t v, resource_graph_t &g, - resource_graph_metadata_t &m); - int remove_graph_metadata (vtx_t v, resource_graph_t &g, - resource_graph_metadata_t &m); + int check_root (vtx_t v, resource_graph_t &g, std::map &is_roots); + int add_graph_metadata (vtx_t v, resource_graph_t &g, resource_graph_metadata_t &m); + int remove_graph_metadata (vtx_t v, resource_graph_t &g, resource_graph_metadata_t &m); int remove_metadata_outedges (vtx_t source_vertex, vtx_t dest_vertex, resource_graph_t &g, resource_graph_metadata_t &m); - int update_vmap (std::map &vmap, vtx_t v, + int update_vmap (std::map &vmap, + vtx_t v, const std::map &root_checks, const fetch_helper_t &fetcher); - int add_vtx (resource_graph_t &g, resource_graph_metadata_t &m, + int add_vtx (resource_graph_t &g, + resource_graph_metadata_t &m, std::map &vmap, const fetch_helper_t &fetcher); int exist (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &path, int rank, - const std::string &vid, vtx_t &v); - int find_vtx (resource_graph_t &g, resource_graph_metadata_t &m, + const std::string &path, + int rank, + const std::string &vid, + vtx_t &v); + int find_vtx (resource_graph_t &g, + resource_graph_metadata_t &m, std::map &vmap, - const fetch_helper_t &fetcher, vtx_t &ret_v); - int update_vtx_plan (vtx_t v, resource_graph_t &g, + const fetch_helper_t &fetcher, + vtx_t &ret_v); + int update_vtx_plan (vtx_t v, + resource_graph_t &g, const fetch_helper_t &fetcher, jgf_updater_data &update_data); - int cancel_vtx (vtx_t v, resource_graph_t &g, + int cancel_vtx (vtx_t v, + resource_graph_t &g, resource_graph_metadata_t &m, const fetch_helper_t &fetcher, jgf_updater_data &update_data); - int update_vtx (resource_graph_t &g, resource_graph_metadata_t &m, + int update_vtx (resource_graph_t &g, + resource_graph_metadata_t &m, std::map &vmap, const fetch_helper_t &fetcher, jgf_updater_data &updater_data); - int unpack_vertices (resource_graph_t &g, resource_graph_metadata_t &m, + int unpack_vertices (resource_graph_t &g, + resource_graph_metadata_t &m, std::map &vmap, json_t *nodes, std::unordered_set &added_vtcs); int undo_vertices (resource_graph_t &g, std::map &vmap, jgf_updater_data &updater_data); - int update_vertices (resource_graph_t &g, resource_graph_metadata_t &m, + int update_vertices (resource_graph_t &g, + resource_graph_metadata_t &m, std::map &vmap, - json_t *nodes, jgf_updater_data &updater_data); - int unpack_edge (json_t *element, std::map &vmap, - std::string &source, std::string &target, json_t **name); - int update_src_edge (resource_graph_t &g, resource_graph_metadata_t &m, + json_t *nodes, + jgf_updater_data &updater_data); + int unpack_edge (json_t *element, + std::map &vmap, + std::string &source, + std::string &target, + json_t **name); + int update_src_edge (resource_graph_t &g, + resource_graph_metadata_t &m, std::map &vmap, - std::string &source, uint64_t token); - int update_tgt_edge (resource_graph_t &g, resource_graph_metadata_t &m, + std::string &source, + uint64_t token); + int update_tgt_edge (resource_graph_t &g, + resource_graph_metadata_t &m, std::map &vmap, - std::string &source, std::string &target, + std::string &source, + std::string &target, uint64_t token); - int unpack_edges (resource_graph_t &g, resource_graph_metadata_t &m, + int unpack_edges (resource_graph_t &g, + resource_graph_metadata_t &m, std::map &vmap, json_t *edges, const std::unordered_set &added_vtcs); - int update_edges (resource_graph_t &g, resource_graph_metadata_t &m, + int update_edges (resource_graph_t &g, + resource_graph_metadata_t &m, std::map &vmap, - json_t *edges, uint64_t token); - int get_subgraph_vertices (resource_graph_t &g, - vtx_t node, - std::vector &node_list); - int get_parent_vtx (resource_graph_t &g, - vtx_t node, - vtx_t &parent_node); + json_t *edges, + uint64_t token); + int get_subgraph_vertices (resource_graph_t &g, vtx_t node, std::vector &node_list); + int get_parent_vtx (resource_graph_t &g, vtx_t node, vtx_t &parent_node); }; -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // RESOURCE_READER_GRUG_HPP +#endif // RESOURCE_READER_GRUG_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/readers/resource_reader_rv1exec.cpp b/resource/readers/resource_reader_rv1exec.cpp index efcb606ba..8f059b3dd 100644 --- a/resource/readers/resource_reader_rv1exec.cpp +++ b/resource/readers/resource_reader_rv1exec.cpp @@ -25,32 +25,24 @@ extern "C" { using namespace Flux; using namespace Flux::resource_model; - - //////////////////////////////////////////////////////////////////////////////// // Public RV1EXEC Resource Reader Interface //////////////////////////////////////////////////////////////////////////////// -int resource_reader_rv1exec_t::properties_t::insert ( - const std::string &res_type, - const std::string &property) +int resource_reader_rv1exec_t::properties_t::insert (const std::string &res_type, + const std::string &property) { if (m_properties.find (res_type) == m_properties.end ()) { auto res = m_properties.insert ( - std::pair> ( - res_type, - std::map ())); + std::pair> (res_type, + std::map ())); if (!res.second) { errno = ENOMEM; return -1; } } - auto res2 = m_properties[res_type].insert (std::pair (property, - "")); + auto res2 = m_properties[res_type].insert (std::pair (property, "")); if (!res2.second) { errno = ENOMEM; return -1; @@ -58,17 +50,13 @@ int resource_reader_rv1exec_t::properties_t::insert ( return 0; } -bool resource_reader_rv1exec_t::properties_t::exist ( - const std::string &res_type) +bool resource_reader_rv1exec_t::properties_t::exist (const std::string &res_type) { - return (m_properties.find (res_type) != m_properties.end ())? true : false; + return (m_properties.find (res_type) != m_properties.end ()) ? true : false; } - -int resource_reader_rv1exec_t::properties_t::copy ( - const std::string &res_type, - std::map &properties) +int resource_reader_rv1exec_t::properties_t::copy (const std::string &res_type, + std::map &properties) { int rc = -1; if (m_properties.find (res_type) != m_properties.end ()) { @@ -80,23 +68,23 @@ int resource_reader_rv1exec_t::properties_t::copy ( vtx_t resource_reader_rv1exec_t::add_vertex (resource_graph_t &g, resource_graph_metadata_t &m, - vtx_t parent, int64_t id, + vtx_t parent, + int64_t id, const std::string &subsys, const std::string &type, const std::string &basename, const std::string &name, - const std::map &props, - int size, int rank) + const std::map &props, + int size, + int rank) { planner_t *plan = nullptr; planner_t *x_checker = nullptr; - if ( !(plan = planner_new (0, INT64_MAX, size, type.c_str ()))) + if (!(plan = planner_new (0, INT64_MAX, size, type.c_str ()))) return boost::graph_traits::null_vertex (); - if ( !(x_checker = planner_new (0, INT64_MAX, - X_CHECKER_NJOBS, X_CHECKER_JOBS_STR))) + if (!(x_checker = planner_new (0, INT64_MAX, X_CHECKER_NJOBS, X_CHECKER_JOBS_STR))) return boost::graph_traits::null_vertex (); vtx_t v = boost::add_vertex (g); @@ -106,8 +94,8 @@ vtx_t resource_reader_rv1exec_t::add_vertex (resource_graph_t &g, if (parent == boost::graph_traits::null_vertex ()) is_root = true; - std::string istr = (id != -1)? std::to_string (id) : ""; - std::string prefix = is_root ? "" : g[parent].paths[subsys]; + std::string istr = (id != -1) ? std::to_string (id) : ""; + std::string prefix = is_root ? "" : g[parent].paths[subsys]; g[v].type = type; g[v].basename = basename; @@ -117,7 +105,7 @@ vtx_t resource_reader_rv1exec_t::add_vertex (resource_graph_t &g, g[v].schedule.plans = plan; g[v].idata.x_checker = x_checker; g[v].id = id; - g[v].name = (name != "")? name : basename + istr; + g[v].name = (name != "") ? name : basename + istr; g[v].paths[subsys] = prefix + "/" + g[v].name; g[v].idata.member_of[subsys] = "*"; g[v].status = resource_pool_t::status_t::UP; @@ -134,36 +122,34 @@ vtx_t resource_reader_rv1exec_t::add_vertex (resource_graph_t &g, int resource_reader_rv1exec_t::add_metadata (resource_graph_t &g, resource_graph_metadata_t &m, - edg_t e, vtx_t src, vtx_t dst) + edg_t e, + vtx_t src, + vtx_t dst) { // add this edge to by_outedges metadata auto iter = m.by_outedges.find (src); if (iter == m.by_outedges.end ()) { auto ret = m.by_outedges.insert ( - std::make_pair ( - src, - std::map, edg_t, - std::greater< - std::pair>> ())); + std::make_pair (src, + std::map, + edg_t, + std::greater>> ())); if (!ret.second) { errno = ENOMEM; m_err_msg += __FUNCTION__; - m_err_msg += "error creating out-edge metadata map: " - + g[src].name + " -> " + g[dst].name + "; "; + m_err_msg += "error creating out-edge metadata map: " + g[src].name + " -> " + + g[dst].name + "; "; return -1; } iter = m.by_outedges.find (src); } - std::pair key = std::make_pair ( - g[e].idata.get_weight (), - g[dst].uniq_id); + std::pair key = std::make_pair (g[e].idata.get_weight (), g[dst].uniq_id); auto ret = iter->second.insert (std::make_pair (key, e)); if (!ret.second) { errno = ENOMEM; m_err_msg += __FUNCTION__; - m_err_msg += "error inserting an edge to out-edge metadata map: " - + g[src].name + " -> " + g[dst].name + "; "; + m_err_msg += "error inserting an edge to out-edge metadata map: " + g[src].name + " -> " + + g[dst].name + "; "; return -1; } return 0; @@ -171,7 +157,8 @@ int resource_reader_rv1exec_t::add_metadata (resource_graph_t &g, int resource_reader_rv1exec_t::add_edges (resource_graph_t &g, resource_graph_metadata_t &m, - vtx_t src, vtx_t dst, + vtx_t src, + vtx_t dst, const std::string &subsys, const std::string &relation, const std::string &rev_relation) @@ -187,7 +174,7 @@ int resource_reader_rv1exec_t::add_edges (resource_graph_t &g, g[e].idata.member_of[subsys] = relation; g[e].name[subsys] = relation; if (add_metadata (g, m, e, src, dst) < 0) - goto error; + goto error; return 0; @@ -200,10 +187,18 @@ int resource_reader_rv1exec_t::add_cluster_vertex (resource_graph_t &g, { vtx_t v; const std::map p; - if ( (v = add_vertex (g, m, - boost::graph_traits::null_vertex (), - 0, "containment", "cluster", "cluster", "", p, 1, -1)) - == boost::graph_traits::null_vertex ()) + if ((v = add_vertex (g, + m, + boost::graph_traits::null_vertex (), + 0, + "containment", + "cluster", + "cluster", + "", + p, + 1, + -1)) + == boost::graph_traits::null_vertex ()) return -1; m.roots.emplace ("containment", v); @@ -213,12 +208,14 @@ int resource_reader_rv1exec_t::add_cluster_vertex (resource_graph_t &g, vtx_t resource_reader_rv1exec_t::find_vertex (resource_graph_t &g, resource_graph_metadata_t &m, - vtx_t parent, int64_t id, + vtx_t parent, + int64_t id, const std::string &subsys, const std::string &type, const std::string &basename, const std::string &name, - int size, int rank) + int size, + int rank) { bool is_root = false; std::string path = ""; @@ -229,9 +226,9 @@ vtx_t resource_reader_rv1exec_t::find_vertex (resource_graph_t &g, if (parent == boost::graph_traits::null_vertex ()) is_root = true; - std::string idstr = (id != -1)? std::to_string (id) : ""; - std::string prefix = is_root ? "" : g[parent].paths[subsys]; - vtx_name = (name != "")? name : basename + idstr; + std::string idstr = (id != -1) ? std::to_string (id) : ""; + std::string prefix = is_root ? "" : g[parent].paths[subsys]; + vtx_name = (name != "") ? name : basename + idstr; path = prefix + "/" + vtx_name; // Search graph metadata for vertex @@ -241,10 +238,7 @@ vtx_t resource_reader_rv1exec_t::find_vertex (resource_graph_t &g, return null_vtx; // Found in by_path for (const vtx_t &v : vtx_iter->second) { - if (g[v].rank == rank - && g[v].id == id - && g[v].size == size - && g[v].type == type) { + if (g[v].rank == rank && g[v].id == id && g[v].size == size && g[v].type == type) { return v; } } @@ -256,22 +250,20 @@ int resource_reader_rv1exec_t::update_vertex (resource_graph_t &g, vtx_t vtx, updater_data &update_data) { - int rc = -1; int64_t span = -1; int64_t avail = -1; planner_t *plans = NULL; // Check and update plan - if ( (plans = g[vtx].schedule.plans) == NULL) { + if ((plans = g[vtx].schedule.plans) == NULL) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": plan for " + g[vtx].name + " is null.\n"; goto error; } - if ( (avail = planner_avail_resources_during (plans, - update_data.at, - update_data.duration)) == -1) { + if ((avail = planner_avail_resources_during (plans, update_data.at, update_data.duration)) + == -1) { m_err_msg += __FUNCTION__; m_err_msg += ": planner_avail_resource_during return -1 for "; m_err_msg += g[vtx].name + ".\n"; @@ -293,10 +285,11 @@ int resource_reader_rv1exec_t::update_vertex (resource_graph_t &g, if (g[vtx].type == "node") return 0; // Name is anything besides node - if ( (span = planner_add_span (plans, - update_data.at, - update_data.duration, - static_cast (g[vtx].size))) == -1) { + if ((span = planner_add_span (plans, + update_data.at, + update_data.duration, + static_cast (g[vtx].size))) + == -1) { m_err_msg += __FUNCTION__; m_err_msg += ": can't add span into " + g[vtx].name + ".\n"; goto error; @@ -308,17 +301,15 @@ int resource_reader_rv1exec_t::update_vertex (resource_graph_t &g, g[vtx].schedule.allocations[update_data.jobid] = span; update_data.updated_vertices[g[vtx].rank].push_back (vtx); - + rc = 0; error: return rc; } -int resource_reader_rv1exec_t::undo_vertices (resource_graph_t &g, - updater_data &update_data) +int resource_reader_rv1exec_t::undo_vertices (resource_graph_t &g, updater_data &update_data) { - int rc = -1; int64_t span = -1; planner_t *plans = NULL; @@ -326,7 +317,7 @@ int resource_reader_rv1exec_t::undo_vertices (resource_graph_t &g, for (auto &[rank, vertices] : update_data.updated_vertices) { for (const vtx_t &vtx : vertices) { // Check plan - if ( (plans = g[vtx].schedule.plans) == NULL) { + if ((plans = g[vtx].schedule.plans) == NULL) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": plan for " + g[vtx].name + " is null.\n"; @@ -356,9 +347,10 @@ int resource_reader_rv1exec_t::undo_vertices (resource_graph_t &g, } int resource_reader_rv1exec_t::update_edges (resource_graph_t &g, - resource_graph_metadata_t &m, - vtx_t src, vtx_t dst, - updater_data &update_data) + resource_graph_metadata_t &m, + vtx_t src, + vtx_t dst, + updater_data &update_data) { edg_t e; int rc = -1; @@ -379,8 +371,7 @@ int resource_reader_rv1exec_t::update_edges (resource_graph_t &g, m_err_msg += ": rv1exec edge not found in resource graph.\n"; goto error; } - g[e].idata.set_for_trav_update (g[dst].size, - true, update_data.token); + g[e].idata.set_for_trav_update (g[dst].size, true, update_data.token); return 0; @@ -389,9 +380,9 @@ int resource_reader_rv1exec_t::update_edges (resource_graph_t &g, } int resource_reader_rv1exec_t::update_exclusivity (resource_graph_t &g, - resource_graph_metadata_t &m, - vtx_t vtx, - updater_data &update_data) + resource_graph_metadata_t &m, + vtx_t vtx, + updater_data &update_data) { // idata tag and exclusive checker update int64_t span = -1; @@ -418,7 +409,7 @@ int resource_reader_rv1exec_t::update_exclusivity (resource_graph_t &g, if (rank_ex->second.size () != (by_rank->second.size () - 1)) return 0; // Counts indicate exclusive - if ( (plans = g[vtx].schedule.plans) == NULL) { + if ((plans = g[vtx].schedule.plans) == NULL) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": plan for " + g[vtx].name + " is null.\n"; @@ -427,8 +418,11 @@ int resource_reader_rv1exec_t::update_exclusivity (resource_graph_t &g, // Update the vertex plan here (not in traverser code). // Traverser update () will handle aggregate filters and // exclusivity checking filter. - if ( (span = planner_add_span (plans, update_data.at, update_data.duration, - static_cast (g[vtx].size))) == -1) { + if ((span = planner_add_span (plans, + update_data.at, + update_data.duration, + static_cast (g[vtx].size))) + == -1) { m_err_msg += __FUNCTION__; m_err_msg += ": can't add span into " + g[vtx].name + ".\n"; return -1; @@ -446,22 +440,22 @@ int resource_reader_rv1exec_t::update_exclusivity (resource_graph_t &g, vtx_t resource_reader_rv1exec_t::add_or_update (resource_graph_t &g, resource_graph_metadata_t &m, - vtx_t parent, int64_t id, + vtx_t parent, + int64_t id, const std::string &subsys, const std::string &type, const std::string &basename, const std::string &name, - int size, int rank, - std::map &properties, + int size, + int rank, + std::map &properties, updater_data &update_data) { vtx_t vtx; vtx_t null_vtx = boost::graph_traits::null_vertex (); if (!update_data.update) { - vtx = find_vertex (g, m, parent, id, subsys, type, basename, - name, size, rank); + vtx = find_vertex (g, m, parent, id, subsys, type, basename, name, size, rank); // Shouldn't be found if (vtx != boost::graph_traits::null_vertex ()) { m_err_msg += __FUNCTION__; @@ -470,16 +464,14 @@ vtx_t resource_reader_rv1exec_t::add_or_update (resource_graph_t &g, return null_vtx; } // Add resources - vtx = add_vertex (g, m, parent, id, subsys, type, basename, - name, properties, size, rank); + vtx = add_vertex (g, m, parent, id, subsys, type, basename, name, properties, size, rank); if (vtx == boost::graph_traits::null_vertex ()) { m_err_msg += __FUNCTION__; m_err_msg += ": failed to add vertex for "; m_err_msg += name + ".\n"; return null_vtx; } - if (add_edges (g, m, parent, vtx, subsys, - "contains", "in") < 0) { + if (add_edges (g, m, parent, vtx, subsys, "contains", "in") < 0) { m_err_msg += __FUNCTION__; m_err_msg += ": failed to add edges for "; m_err_msg += name + ".\n"; @@ -487,8 +479,7 @@ vtx_t resource_reader_rv1exec_t::add_or_update (resource_graph_t &g, } } else { // Update resources - vtx = find_vertex (g, m, parent, id, subsys, type, basename, - name, size, rank); + vtx = find_vertex (g, m, parent, id, subsys, type, basename, name, size, rank); // Not found if (vtx == boost::graph_traits::null_vertex ()) { m_err_msg += __FUNCTION__; @@ -506,8 +497,7 @@ vtx_t resource_reader_rv1exec_t::add_or_update (resource_graph_t &g, return vtx; } -int resource_reader_rv1exec_t::build_rmap (json_t *rlite, - std::map &rmap) +int resource_reader_rv1exec_t::build_rmap (json_t *rlite, std::map &rmap) { int i; size_t index; @@ -521,7 +511,7 @@ int resource_reader_rv1exec_t::build_rmap (json_t *rlite, errno = EINVAL; goto error; } - if ( !(ids = idset_create (0, IDSET_FLAG_AUTOGROW))) + if (!(ids = idset_create (0, IDSET_FLAG_AUTOGROW))) goto error; // Create a global rank set that combines all ranks from R_lite array @@ -530,7 +520,7 @@ int resource_reader_rv1exec_t::build_rmap (json_t *rlite, errno = EINVAL; goto error; } - if ( !(r_ids = idset_decode (ranks))) + if (!(r_ids = idset_decode (ranks))) goto error; rank = idset_first (r_ids); @@ -573,8 +563,7 @@ int resource_reader_rv1exec_t::build_rmap (json_t *rlite, } int resource_reader_rv1exec_t::build_pmap (json_t *properties, - std::map &pmap) + std::map &pmap) { const char *key = nullptr; json_t *val = nullptr; @@ -587,7 +576,7 @@ int resource_reader_rv1exec_t::build_pmap (json_t *properties, errno = EINVAL; goto error; } - if ( !(ranks = idset_decode (json_string_value (val)))) { + if (!(ranks = idset_decode (json_string_value (val)))) { errno = ENOMEM; goto error; } @@ -604,10 +593,7 @@ int resource_reader_rv1exec_t::build_pmap (json_t *properties, if (pmap[rank].insert ("node", key) < 0) goto error; } else { - auto res = pmap.insert ( - std::pair (rank, - properties_t ())); + auto res = pmap.insert (std::pair (rank, properties_t ())); if (!res.second) { errno = ENOMEM; goto error; @@ -633,8 +619,7 @@ int resource_reader_rv1exec_t::unpack_child (resource_graph_t &g, const char *resource_type, const char *resource_ids, unsigned rank, - std::map &pmap, + std::map &pmap, updater_data &update_data) { int rc = -1; @@ -645,7 +630,7 @@ int resource_reader_rv1exec_t::unpack_child (resource_graph_t &g, errno = EINVAL; goto error; } - if ( !(ids = idset_decode (resource_ids))) + if (!(ids = idset_decode (resource_ids))) goto error; id = idset_first (ids); @@ -661,8 +646,17 @@ int resource_reader_rv1exec_t::unpack_child (resource_graph_t &g, } } // Returns the added or updated vertex; null_vertex on error. - vtx = add_or_update (g, m, parent, id, "containment", resource_type, - resource_type, name, 1, rank, properties, + vtx = add_or_update (g, + m, + parent, + id, + "containment", + resource_type, + resource_type, + name, + 1, + rank, + properties, update_data); if (vtx == boost::graph_traits::null_vertex ()) { m_err_msg += __FUNCTION__; @@ -680,14 +674,12 @@ int resource_reader_rv1exec_t::unpack_child (resource_graph_t &g, return rc; } - int resource_reader_rv1exec_t::unpack_children (resource_graph_t &g, resource_graph_metadata_t &m, vtx_t parent, json_t *children, unsigned rank, - std::map &pmap, + std::map &pmap, updater_data &update_data) { json_t *res_ids = nullptr; @@ -704,8 +696,7 @@ int resource_reader_rv1exec_t::unpack_children (resource_graph_t &g, goto error; } const char *ids_str = json_string_value (res_ids); - if (unpack_child (g, m, parent, res_type, ids_str, rank, pmap, - update_data) < 0) + if (unpack_child (g, m, parent, res_type, ids_str, rank, pmap, update_data) < 0) goto error; } return 0; @@ -721,8 +712,7 @@ int resource_reader_rv1exec_t::unpack_rank (resource_graph_t &g, json_t *children, struct hostlist *hlist, std::map &rmap, - std::map &pmap, + std::map &pmap, updater_data &update_data) { edg_t e; @@ -741,10 +731,9 @@ int resource_reader_rv1exec_t::unpack_rank (resource_graph_t &g, goto error; } - if ( !(hostname = hostlist_nth (hlist, static_cast (rmap[rank])))) + if (!(hostname = hostlist_nth (hlist, static_cast (rmap[rank])))) goto error; - if (get_hostname_suffix (hostname, id) < 0 - || get_host_basename (hostname, basename) < 0) { + if (get_hostname_suffix (hostname, id) < 0 || get_host_basename (hostname, basename) < 0) { m_err_msg += __FUNCTION__; m_err_msg += ": error splitting hostname="; m_err_msg += hostname + std::string ("; "); @@ -757,8 +746,18 @@ int resource_reader_rv1exec_t::unpack_rank (resource_graph_t &g, } } // Returns the added or updated vertex; null_vtertex on error. - vtx = add_or_update (g, m, parent, id, "containment", "node", basename, - hostname, 1, rank, properties, update_data); + vtx = add_or_update (g, + m, + parent, + id, + "containment", + "node", + basename, + hostname, + 1, + rank, + properties, + update_data); if (vtx == boost::graph_traits::null_vertex ()) { m_err_msg += __FUNCTION__; m_err_msg += ": failed unpacking rank for "; @@ -790,10 +789,8 @@ int resource_reader_rv1exec_t::unpack_rlite_entry (resource_graph_t &g, vtx_t parent, json_t *entry, struct hostlist *hlist, - std::map &rmap, - std::map &pmap, + std::map &rmap, + std::map &pmap, updater_data &update_data) { int rc = -1; @@ -807,20 +804,17 @@ int resource_reader_rv1exec_t::unpack_rlite_entry (resource_graph_t &g, goto error; } - if (json_unpack (entry, "{s:s s:o}", - "rank", &ranks, - "children", &children) < 0) { + if (json_unpack (entry, "{s:s s:o}", "rank", &ranks, "children", &children) < 0) { errno = EINVAL; goto error; } - if ( !(r_ids = idset_decode (ranks))) + if (!(r_ids = idset_decode (ranks))) goto error; rank = idset_first (r_ids); while (rank != IDSET_INVALID_ID) { - if (unpack_rank (g, m, parent, rank, children, hlist, rmap, pmap, - update_data) < 0) + if (unpack_rank (g, m, parent, rank, children, hlist, rmap, pmap, update_data) < 0) goto error; rank = idset_next (r_ids, rank); @@ -837,8 +831,7 @@ int resource_reader_rv1exec_t::unpack_rlite (resource_graph_t &g, json_t *rlite, struct hostlist *hlist, std::map &rmap, - std::map &pmap, + std::map &pmap, updater_data &update_data) { size_t index; @@ -857,11 +850,9 @@ int resource_reader_rv1exec_t::unpack_rlite (resource_graph_t &g, cluster_vtx = m.roots["containment"]; // Set the cluster "needs" and make the update shared access to the cluster - m.v_rt_edges["containment"].set_for_trav_update (g[cluster_vtx].size, - false, update_data.token); + m.v_rt_edges["containment"].set_for_trav_update (g[cluster_vtx].size, false, update_data.token); json_array_foreach (rlite, index, entry) { - if (unpack_rlite_entry (g, m, cluster_vtx, - entry, hlist, rmap, pmap, update_data) < 0) + if (unpack_rlite_entry (g, m, cluster_vtx, entry, hlist, rmap, pmap, update_data) < 0) goto error; } return 0; @@ -886,12 +877,18 @@ int resource_reader_rv1exec_t::unpack_internal (resource_graph_t &g, std::map rmap; std::map pmap; - if (json_unpack (rv1, "{s:i s:{s:o s:o s?o}}", - "version", &version, - "execution", - "R_lite", &rlite, - "nodelist", &nodelist, - "properties", &properties) < 0) { + if (json_unpack (rv1, + "{s:i s:{s:o s:o s?o}}", + "version", + &version, + "execution", + "R_lite", + &rlite, + "nodelist", + &nodelist, + "properties", + &properties) + < 0) { errno = EINVAL; goto ret; } @@ -904,7 +901,7 @@ int resource_reader_rv1exec_t::unpack_internal (resource_graph_t &g, goto ret; if (build_pmap (properties, pmap) < 0) goto ret; - if ( !(hlist = hostlist_create ())) + if (!(hlist = hostlist_create ())) goto ret; // Encode all nodes in nodelist array into a hostlist object. @@ -914,7 +911,7 @@ int resource_reader_rv1exec_t::unpack_internal (resource_graph_t &g, errno = EINVAL; goto ret; } - if ( !(hlist_str = json_string_value (val))) { + if (!(hlist_str = json_string_value (val))) { errno = EINVAL; goto ret; } @@ -932,9 +929,9 @@ int resource_reader_rv1exec_t::unpack_internal (resource_graph_t &g, } int resource_reader_rv1exec_t::partial_cancel_internal (resource_graph_t &g, - resource_graph_metadata_t &m, - modify_data_t &mod_data, - json_t *rv1) + resource_graph_metadata_t &m, + modify_data_t &mod_data, + json_t *rv1) { int rc = -1; int version; @@ -948,10 +945,8 @@ int resource_reader_rv1exec_t::partial_cancel_internal (resource_graph_t &g, // Implementing cancellation of rank subgraph // will require further parsing of nodelist, // children, and rank - if (json_unpack (rv1, "{s:i s:{s:o}}", - "version", &version, - "execution", - "R_lite", &rlite) < 0) { + if (json_unpack (rv1, "{s:i s:{s:o}}", "version", &version, "execution", "R_lite", &rlite) + < 0) { errno = EINVAL; goto error; } @@ -960,13 +955,12 @@ int resource_reader_rv1exec_t::partial_cancel_internal (resource_graph_t &g, goto error; } json_array_foreach (rlite, index, entry) { - if (json_unpack (entry, "{s:s}", - "rank", &ranks) < 0) { + if (json_unpack (entry, "{s:s}", "rank", &ranks) < 0) { errno = EINVAL; goto error; } } - if ( !(r_ids = idset_decode (ranks))) + if (!(r_ids = idset_decode (ranks))) goto error; rank = idset_first (r_ids); while (rank != IDSET_INVALID_ID) { @@ -980,20 +974,18 @@ int resource_reader_rv1exec_t::partial_cancel_internal (resource_graph_t &g, return rc; } - - //////////////////////////////////////////////////////////////////////////////// // Public RV1EXEC Resource Reader Interface //////////////////////////////////////////////////////////////////////////////// resource_reader_rv1exec_t::~resource_reader_rv1exec_t () { - } int resource_reader_rv1exec_t::unpack (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &str, int rank) + const std::string &str, + int rank) { int rc = -1; json_error_t error; @@ -1010,7 +1002,7 @@ int resource_reader_rv1exec_t::unpack (resource_graph_t &g, if (add_cluster_vertex (g, m) < 0) goto ret; - if ( !(rv1 = json_loads (str.c_str (), 0, &error))) { + if (!(rv1 = json_loads (str.c_str (), 0, &error))) { errno = ENOMEM; goto ret; } @@ -1027,7 +1019,8 @@ int resource_reader_rv1exec_t::unpack (resource_graph_t &g, int resource_reader_rv1exec_t::unpack_at (resource_graph_t &g, resource_graph_metadata_t &m, vtx_t &vtx, - const std::string &str, int rank) + const std::string &str, + int rank) { errno = ENOTSUP; return -1; @@ -1037,14 +1030,17 @@ int resource_reader_rv1exec_t::remove_subgraph (resource_graph_t &g, resource_graph_metadata_t &m, const std::string &path) { - errno = ENOTSUP; // RV1Exec reader does not support remove - return -1; + errno = ENOTSUP; // RV1Exec reader does not support remove + return -1; } int resource_reader_rv1exec_t::update (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &R, int64_t jobid, - int64_t at, uint64_t dur, bool rsv, + const std::string &R, + int64_t jobid, + int64_t at, + uint64_t dur, + bool rsv, uint64_t token) { int rc = -1; @@ -1058,7 +1054,7 @@ int resource_reader_rv1exec_t::update (resource_graph_t &g, goto ret; } - if ( !(rv1 = json_loads (R.c_str (), 0, &error))) { + if (!(rv1 = json_loads (R.c_str (), 0, &error))) { errno = ENOMEM; goto ret; } @@ -1070,7 +1066,7 @@ int resource_reader_rv1exec_t::update (resource_graph_t &g, update_data.reserved = rsv; update_data.token = token; - if ( (rc = unpack_internal (g, m, rv1, update_data)) == -1) { + if ((rc = unpack_internal (g, m, rv1, update_data)) == -1) { undo_vertices (g, update_data); } @@ -1087,9 +1083,10 @@ bool resource_reader_rv1exec_t::is_allowlist_supported () } int resource_reader_rv1exec_t::partial_cancel (resource_graph_t &g, - resource_graph_metadata_t &m, - modify_data_t &mod_data, - const std::string &R, int64_t jobid) + resource_graph_metadata_t &m, + modify_data_t &mod_data, + const std::string &R, + int64_t jobid) { int rc = -1; json_error_t error; @@ -1101,7 +1098,7 @@ int resource_reader_rv1exec_t::partial_cancel (resource_graph_t &g, goto ret; } - if ( !(rv1 = json_loads (R.c_str (), 0, &error))) { + if (!(rv1 = json_loads (R.c_str (), 0, &error))) { errno = ENOMEM; goto ret; } diff --git a/resource/readers/resource_reader_rv1exec.hpp b/resource/readers/resource_reader_rv1exec.hpp index e0a5184b0..a2b9e2951 100644 --- a/resource/readers/resource_reader_rv1exec.hpp +++ b/resource/readers/resource_reader_rv1exec.hpp @@ -30,14 +30,13 @@ struct updater_data { uint64_t token = 0; // track updated vertices to undo upon error std::map> updated_vertices; - bool update = true; // Updating or adding vertex + bool update = true; // Updating or adding vertex }; /*! RV1EXEC resource reader class. */ class resource_reader_rv1exec_t : public resource_reader_base_t { -public: - + public: virtual ~resource_reader_rv1exec_t (); /*! Unpack str into a resource graph. @@ -52,8 +51,10 @@ class resource_reader_rv1exec_t : public resource_reader_base_t { * ENOMEM: out of memory * EINVAL: invalid input or operation */ - virtual int unpack (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &str, int rank = -1); + virtual int unpack (resource_graph_t &g, + resource_graph_metadata_t &m, + const std::string &str, + int rank = -1); /*! Unpack str into a resource graph and graft * the top-level vertices to vtx. @@ -65,8 +66,11 @@ class resource_reader_rv1exec_t : public resource_reader_base_t { * \param rank assign this rank to all the newly created resource vertices * \return -1 with ENOTSUP (Not supported yet) */ - virtual int unpack_at (resource_graph_t &g, resource_graph_metadata_t &m, - vtx_t &vtx, const std::string &str, int rank = -1); + virtual int unpack_at (resource_graph_t &g, + resource_graph_metadata_t &m, + vtx_t &vtx, + const std::string &str, + int rank = -1); virtual int remove_subgraph (resource_graph_t &g, resource_graph_metadata_t &m, @@ -85,9 +89,14 @@ class resource_reader_rv1exec_t : public resource_reader_base_t { * token to be used by traverser * \return -1 with ENOTSUP (Not supported yet) */ - virtual int update (resource_graph_t &g, resource_graph_metadata_t &m, - const std::string &str, int64_t jobid, int64_t at, - uint64_t dur, bool rsv, uint64_t trav_token); + virtual int update (resource_graph_t &g, + resource_graph_metadata_t &m, + const std::string &str, + int64_t jobid, + int64_t at, + uint64_t dur, + bool rsv, + uint64_t trav_token); /*! Partial cancellation of jobid based on R. * @@ -100,9 +109,10 @@ class resource_reader_rv1exec_t : public resource_reader_base_t { * \return 0 on success; non-zero integer on an error */ virtual int partial_cancel (resource_graph_t &g, - resource_graph_metadata_t &m, - modify_data_t &mod_data, - const std::string &R, int64_t jobid); + resource_graph_metadata_t &m, + modify_data_t &mod_data, + const std::string &R, + int64_t jobid); /*! Is the selected reader format support allowlist * @@ -110,61 +120,65 @@ class resource_reader_rv1exec_t : public resource_reader_base_t { */ virtual bool is_allowlist_supported (); -private: - + private: class properties_t { - public: - int insert (const std::string &res_type, const std::string &property); - bool exist (const std::string &res_type); - int copy (const std::string &res_type, - std::map &properties); + public: + int insert (const std::string &res_type, const std::string &property); + bool exist (const std::string &res_type); + int copy (const std::string &res_type, std::map &properties); - private: + private: std::map> m_properties; }; vtx_t add_vertex (resource_graph_t &g, resource_graph_metadata_t &m, - vtx_t parent, int64_t id, + vtx_t parent, + int64_t id, const std::string &subsys, const std::string &type, const std::string &basename, const std::string &name, - const std::map &props, int size, int rank); + const std::map &props, + int size, + int rank); int add_metadata (resource_graph_t &g, resource_graph_metadata_t &m, - edg_t e, vtx_t src, vtx_t dst); + edg_t e, + vtx_t src, + vtx_t dst); int add_edges (resource_graph_t &g, resource_graph_metadata_t &m, - vtx_t src, vtx_t dst, + vtx_t src, + vtx_t dst, const std::string &subsys, const std::string &relation, const std::string &rev_relation); int add_cluster_vertex (resource_graph_t &g, resource_graph_metadata_t &m); - - vtx_t find_vertex (resource_graph_t &g, resource_graph_metadata_t &m, - vtx_t parent, int64_t id, + vtx_t find_vertex (resource_graph_t &g, + resource_graph_metadata_t &m, + vtx_t parent, + int64_t id, const std::string &subsys, const std::string &type, const std::string &basename, const std::string &name, - int size, int rank); + int size, + int rank); // Update functions - int update_vertex (resource_graph_t &g, - vtx_t vtx, - updater_data &update_data); + int update_vertex (resource_graph_t &g, vtx_t vtx, updater_data &update_data); int undo_vertices (resource_graph_t &g, updater_data &update_data); int update_edges (resource_graph_t &g, resource_graph_metadata_t &m, - vtx_t src, vtx_t dst, + vtx_t src, + vtx_t dst, updater_data &update_data); int update_exclusivity (resource_graph_t &g, @@ -175,37 +189,43 @@ class resource_reader_rv1exec_t : public resource_reader_base_t { // Returns the added or updated vertex; null_vertex on error. vtx_t add_or_update (resource_graph_t &g, resource_graph_metadata_t &m, - vtx_t parent, int64_t id, + vtx_t parent, + int64_t id, const std::string &subsys, const std::string &type, const std::string &basename, const std::string &name, - int size, int rank, - std::map &properties, + int size, + int rank, + std::map &properties, updater_data &update_data); int build_rmap (json_t *rlite, std::map &rmap); - int build_pmap (json_t *properties, - std::map &pmap); + int build_pmap (json_t *properties, std::map &pmap); int unpack_child (resource_graph_t &g, - resource_graph_metadata_t &m, vtx_t parent, + resource_graph_metadata_t &m, + vtx_t parent, const char *resource_type, - const char *resource_ids, unsigned rank, + const char *resource_ids, + unsigned rank, std::map &pmap, updater_data &update_data); int unpack_children (resource_graph_t &g, resource_graph_metadata_t &m, - vtx_t parent, json_t *children, unsigned rank, + vtx_t parent, + json_t *children, + unsigned rank, std::map &pmap, updater_data &update_data); int unpack_rank (resource_graph_t &g, resource_graph_metadata_t &m, - vtx_t parent, unsigned rank, json_t *children, + vtx_t parent, + unsigned rank, + json_t *children, struct hostlist *hlist, std::map &rmap, std::map &pmap, @@ -213,34 +233,36 @@ class resource_reader_rv1exec_t : public resource_reader_base_t { int unpack_rlite_entry (resource_graph_t &g, resource_graph_metadata_t &m, - vtx_t parent, json_t *entry, + vtx_t parent, + json_t *entry, struct hostlist *hlist, std::map &rmap, std::map &pmap, updater_data &update_data); int unpack_rlite (resource_graph_t &g, - resource_graph_metadata_t &m, json_t *rlite, + resource_graph_metadata_t &m, + json_t *rlite, struct hostlist *hlist, std::map &rmap, std::map &pmap, updater_data &update_data); int unpack_internal (resource_graph_t &g, - resource_graph_metadata_t &m, json_t *rv1, + resource_graph_metadata_t &m, + json_t *rv1, updater_data &update_data); int partial_cancel_internal (resource_graph_t &g, - resource_graph_metadata_t &m, - modify_data_t &mod_data, - json_t *rv1); - + resource_graph_metadata_t &m, + modify_data_t &mod_data, + json_t *rv1); }; -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // RESOURCE_READER_RV1EXEC_HPP +#endif // RESOURCE_READER_RV1EXEC_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/readers/resource_spec_grug.cpp b/resource/readers/resource_spec_grug.cpp index db7d3633f..0f113c1d8 100644 --- a/resource/readers/resource_spec_grug.cpp +++ b/resource/readers/resource_spec_grug.cpp @@ -17,7 +17,7 @@ extern "C" { #include #include -#if defined (__clang__) || (__GNUC__ <= 11) +#if defined(__clang__) || (__GNUC__ <= 11) #include #include #elif (__GNUC__ > 11) @@ -34,29 +34,29 @@ extern "C" { using namespace Flux::resource_model; -struct str2enum_t -{ +struct str2enum_t { std::string str; int e; }; -str2enum_t str2genmeth[] = { - {"MULTIPLY", MULTIPLY}, - {"ASSOCIATE_IN", ASSOCIATE_IN}, - {"ASSOCIATE_BY_PATH_IN", ASSOCIATE_BY_PATH_IN}, - {"", GEN_UNKNOWN} -}; +str2enum_t str2genmeth[] = {{"MULTIPLY", MULTIPLY}, + {"ASSOCIATE_IN", ASSOCIATE_IN}, + {"ASSOCIATE_BY_PATH_IN", ASSOCIATE_BY_PATH_IN}, + {"", GEN_UNKNOWN}}; template class gg_label_writer_t { -public: - gg_label_writer_t (m1 _n1, m2 _n2, m3 _n3) - : n1 (_n1), n2 (_n2), n3 (_n3) { } - template - void operator()(std::ostream &out, const v_or_e &i) const { + public: + gg_label_writer_t (m1 _n1, m2 _n2, m3 _n3) : n1 (_n1), n2 (_n2), n3 (_n3) + { + } + template + void operator() (std::ostream &out, const v_or_e &i) const + { out << "[label=\"" << n1[i] << ":" << n2[i] << ":" << n3[i] << "\"]"; } -private: + + private: m1 n1; m2 n2; m3 n3; @@ -64,46 +64,45 @@ class gg_label_writer_t { template class gg_label_writer_sim_t { -public: - gg_label_writer_sim_t (m1 _n1) - : n1 (_n1) { } - template - void operator()(std::ostream &out, const VertexOrEdge& i) const { + public: + gg_label_writer_sim_t (m1 _n1) : n1 (_n1) + { + } + template + void operator() (std::ostream &out, const VertexOrEdge &i) const + { out << "[label=\"" << n1[i] << "\"]"; } -private: + + private: m1 n1; }; - - //////////////////////////////////////////////////////////////////////////////// // Private Resource Generator Spec API //////////////////////////////////////////////////////////////////////////////// void resource_gen_spec_t::setup_dynamic_property (boost::dynamic_properties &dp, gg_t &g) { - dp.property("root", get(&resource_pool_gen_t::root, g)); - dp.property("type", get(&resource_pool_gen_t::type, g)); - dp.property("basename", get(&resource_pool_gen_t::basename, g)); - dp.property("size", get(&resource_pool_gen_t::size, g)); - dp.property("unit", get(&resource_pool_gen_t::unit, g)); - dp.property("subsystem", get(&resource_pool_gen_t::subsystem, g)); - dp.property("e_subsystem", get(&relation_gen_t::e_subsystem, g)); - dp.property("relation", get(&relation_gen_t::relation, g)); - dp.property("rrelation", get(&relation_gen_t::rrelation, g)); - dp.property("gen_method", get(&relation_gen_t::gen_method, g)); - dp.property("id_scope", get(&relation_gen_t::id_scope, g)); - dp.property("id_start", get(&relation_gen_t::id_start, g)); - dp.property("id_stride", get(&relation_gen_t::id_stride, g)); - dp.property("multi_scale", get(&relation_gen_t::multi_scale, g)); - dp.property("as_tgt_subsystem", get(&relation_gen_t::as_tgt_subsystem, g)); - dp.property("as_tgt_uplvl", get(&relation_gen_t::as_tgt_uplvl, g)); - dp.property("as_src_uplvl", get(&relation_gen_t::as_src_uplvl, g)); + dp.property ("root", get (&resource_pool_gen_t::root, g)); + dp.property ("type", get (&resource_pool_gen_t::type, g)); + dp.property ("basename", get (&resource_pool_gen_t::basename, g)); + dp.property ("size", get (&resource_pool_gen_t::size, g)); + dp.property ("unit", get (&resource_pool_gen_t::unit, g)); + dp.property ("subsystem", get (&resource_pool_gen_t::subsystem, g)); + dp.property ("e_subsystem", get (&relation_gen_t::e_subsystem, g)); + dp.property ("relation", get (&relation_gen_t::relation, g)); + dp.property ("rrelation", get (&relation_gen_t::rrelation, g)); + dp.property ("gen_method", get (&relation_gen_t::gen_method, g)); + dp.property ("id_scope", get (&relation_gen_t::id_scope, g)); + dp.property ("id_start", get (&relation_gen_t::id_start, g)); + dp.property ("id_stride", get (&relation_gen_t::id_stride, g)); + dp.property ("multi_scale", get (&relation_gen_t::multi_scale, g)); + dp.property ("as_tgt_subsystem", get (&relation_gen_t::as_tgt_subsystem, g)); + dp.property ("as_tgt_uplvl", get (&relation_gen_t::as_tgt_uplvl, g)); + dp.property ("as_src_uplvl", get (&relation_gen_t::as_src_uplvl, g)); } - - //////////////////////////////////////////////////////////////////////////////// // Public Resource Generator Spec API //////////////////////////////////////////////////////////////////////////////// @@ -129,11 +128,10 @@ const gg_t &resource_gen_spec_t::gen_graph () * \param s gen_method string from graphml spec * \return 0 on success; -1 otherwise */ -const gen_meth_t resource_gen_spec_t::to_gen_method_t ( - const std::string &s) const +const gen_meth_t resource_gen_spec_t::to_gen_method_t (const std::string &s) const { int i; - for (i=0; str2genmeth[i].str != ""; ++i) + for (i = 0; str2genmeth[i].str != ""; ++i) if (str2genmeth[i].str == s) return (gen_meth_t)str2genmeth[i].e; return (gen_meth_t)str2genmeth[i].e; @@ -185,18 +183,16 @@ int resource_gen_spec_t::write_graphviz (const std::string &ofn, bool simple) try { vtx_basename_map_t v_bn_map = get (&resource_pool_gen_t::basename, g); vtx_size_map_t v_sz_map = get (&resource_pool_gen_t::size, g); - //vtx_unit_map_t v_ut_map = get (&resource_pool_gen_t::unit, g); + // vtx_unit_map_t v_ut_map = get (&resource_pool_gen_t::unit, g); vtx_subsystem_map_t v_ss_map = get (&resource_pool_gen_t::subsystem, g); edg_relation_map_t e_rel_map = get (&relation_gen_t::relation, g); edg_gen_method_map_t e_gen_map = get (&relation_gen_t::gen_method, g); edg_multi_scale_map_t e_ms_map = get (&relation_gen_t::multi_scale, g); if (!simple) { - gg_label_writer_t vwr ( - v_ss_map, v_bn_map, v_sz_map); - gg_label_writer_t ewr ( - e_rel_map, e_gen_map, e_ms_map); + gg_label_writer_t + vwr (v_ss_map, v_bn_map, v_sz_map); + gg_label_writer_t + ewr (e_rel_map, e_gen_map, e_ms_map); boost::write_graphviz (out_file, g, vwr, ewr); } else { gg_label_writer_sim_t vwr (v_bn_map); diff --git a/resource/readers/resource_spec_grug.hpp b/resource/readers/resource_spec_grug.hpp index ebbf55a05..f7c6fd3e6 100644 --- a/resource/readers/resource_spec_grug.hpp +++ b/resource/readers/resource_spec_grug.hpp @@ -20,12 +20,7 @@ namespace Flux { namespace resource_model { -enum gen_meth_t { - MULTIPLY, - ASSOCIATE_IN, - ASSOCIATE_BY_PATH_IN, - GEN_UNKNOWN -}; +enum gen_meth_t { MULTIPLY, ASSOCIATE_IN, ASSOCIATE_BY_PATH_IN, GEN_UNKNOWN }; struct resource_pool_gen_t { int root; @@ -51,11 +46,8 @@ struct relation_gen_t { int as_src_uplvl; }; -using gg_t = boost::adjacency_list; +using gg_t = boost:: + adjacency_list; using pgen_t = std::string resource_pool_gen_t::*; using rgen_t = std::string relation_gen_t::*; using ggv_t = boost::graph_traits::vertex_descriptor; @@ -63,7 +55,7 @@ using gge_t = boost::graph_traits::edge_descriptor; using vtx_type_map_t = boost::property_map::type; using vtx_basename_map_t = boost::property_map::type; -using vtx_size_map_t = boost::property_map::type; +using vtx_size_map_t = boost::property_map::type; using vtx_unit_map_t = boost::property_map::type; using vtx_subsystem_map_t = boost::property_map::type; using edg_e_subsystem_map_t = boost::property_map::type; @@ -71,28 +63,28 @@ using edg_relation_map_t = boost::property_map::type; using edg_rrelation_map_t = boost::property_map::type; using edg_gen_method_map_t = boost::property_map::type; using edg_id_method_map_t = boost::property_map::type; -using edg_multi_scale_map_t = boost::property_map::type; +using edg_multi_scale_map_t = boost::property_map::type; class resource_gen_spec_t { -public: + public: resource_gen_spec_t (); resource_gen_spec_t (const resource_gen_spec_t &o); const gg_t &gen_graph (); const gen_meth_t to_gen_method_t (const std::string &s) const; int read_graphml (const std::string &ifn); int read_graphml (std::istream &in); - int write_graphviz (const std::string &ofn, bool simple=false); + int write_graphviz (const std::string &ofn, bool simple = false); -private: + private: void setup_dynamic_property (boost::dynamic_properties &dp, gg_t &g); gg_t g; boost::dynamic_properties dp; }; -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // RESOURCE_SPEC_GRUG_HPP +#endif // RESOURCE_SPEC_GRUG_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/reapi/bindings/c++/reapi.hpp b/resource/reapi/bindings/c++/reapi.hpp index 7c5823169..cf5eec3e9 100644 --- a/resource/reapi/bindings/c++/reapi.hpp +++ b/resource/reapi/bindings/c++/reapi.hpp @@ -25,13 +25,12 @@ extern "C" { namespace Flux { namespace resource_model { - /*! Queue adapter base API class: define a set of methods a queue * policy class (a subclass of this API class) must implement * to be able to work with reapi_t under asynchronous execution. */ class queue_adapter_base_t { -public: + public: /*! When a match succeeds, this method is called back * by reapi_t with the matched resource information. * The implementor (e.g., queue policy class) of this method @@ -48,8 +47,11 @@ class queue_adapter_base_t { * of the elapse time to complete the match operation. * \return 0 on success; -1 on error. */ - virtual int handle_match_success (flux_jobid_t jobid, const char *status, - const char *R, int64_t at, double ov) = 0; + virtual int handle_match_success (flux_jobid_t jobid, + const char *status, + const char *R, + int64_t at, + double ov) = 0; /*! When a match failed (e.g., unsatisfiable jobspec, resource * unavailable, no more jobspec to process), this method is @@ -86,12 +88,11 @@ class queue_adapter_base_t { virtual int set_sched_loop_active (bool active) = 0; }; - /*! High-level resource API base class. Derived classes must implement * the methods. */ class reapi_t { -public: + public: /*! Match a jobspec to the "best" resources and either allocate * orelse reserve them. The best resources are determined by * the selected match policy. @@ -102,13 +103,13 @@ class reapi_t { * to a flux_t object. * \param match_op match_op_t: set to specify the specific match option * from 1 of 4 choices: - * MATCH_ALLOCATE: try to allocate now and fail if resources - * aren't available. + * MATCH_ALLOCATE: try to allocate now and fail if resources + * aren't available. * MATCH_ALLOCATE_ORELSE_RESERVE : Try to allocate and reseve * if resources aren't available now. - * MATCH_SATISFIABILITY: Do a satisfiablity check and do not + * MATCH_SATISFIABILITY: Do a satisfiablity check and do not * allocate. - * MATCH_ALLOCATE_W_SATISFIABILITY: try to allocate and run + * MATCH_ALLOCATE_W_SATISFIABILITY: try to allocate and run * satisfiability check if resources are not available. * \param jobspec jobspec string. * \param jobid jobid of the uint64_t type. @@ -123,10 +124,14 @@ class reapi_t { * the match operation. * \return 0 on success; -1 on error. */ - static int match_allocate (void *h, bool orelse_reserve, + static int match_allocate (void *h, + bool orelse_reserve, const std::string &jobspec, - const uint64_t jobid, bool &reserved, - std::string &R, int64_t &at, double &ov) + const uint64_t jobid, + bool &reserved, + std::string &R, + int64_t &at, + double &ov) { return -1; } @@ -141,13 +146,13 @@ class reapi_t { * to a flux_t object. * \param match_op match_op_t: set to specify the specific match option * from 1 of 4 choices: - * MATCH_ALLOCATE: try to allocate now and fail if resources - * aren't available. + * MATCH_ALLOCATE: try to allocate now and fail if resources + * aren't available. * MATCH_ALLOCATE_ORELSE_RESERVE : Try to allocate and reseve * if resources aren't available now. - * MATCH_SATISFIABILITY: Do a satisfiablity check and do not + * MATCH_SATISFIABILITY: Do a satisfiablity check and do not * allocate. - * MATCH_ALLOCATE_W_SATISFIABILITY: try to allocate and run + * MATCH_ALLOCATE_W_SATISFIABILITY: try to allocate and run * \param jobs JSON array of jobspecs. * \param adapter queue_adapter_base_t object that provides * a set of callback methods to be called each time @@ -155,7 +160,8 @@ class reapi_t { * resource match service. * \return 0 on success; -1 on error. */ - static int match_allocate_multi (void *h, bool orelse_reserve, + static int match_allocate_multi (void *h, + bool orelse_reserve, const char *jobs, queue_adapter_base_t *adapter); @@ -174,8 +180,11 @@ class reapi_t { * \param R_out return the updated R string. * \return 0 on success; -1 on error. */ - static int update_allocate (void *h, const uint64_t jobid, - const std::string &R, int64_t &at, double &ov, + static int update_allocate (void *h, + const uint64_t jobid, + const std::string &R, + int64_t &at, + double &ov, std::string &R_out) { return -1; @@ -197,16 +206,19 @@ class reapi_t { } /*! Cancel the allocation or reservation corresponding to jobid. - * - * \param ctx reapi_module_ctx_t context object - * \param jobid jobid of the uint64_t type. - * \param R R string to remove - * \param noent_ok don't return an error on nonexistent jobid - * \param full_removal bool indictating whether the job is fully canceled - * \return 0 on success; -1 on error. - */ - static int cancel (void *h, const uint64_t jobid, - const char *R, bool noent_ok, bool &full_removal) + * + * \param ctx reapi_module_ctx_t context object + * \param jobid jobid of the uint64_t type. + * \param R R string to remove + * \param noent_ok don't return an error on nonexistent jobid + * \param full_removal bool indictating whether the job is fully canceled + * \return 0 on success; -1 on error. + */ + static int cancel (void *h, + const uint64_t jobid, + const char *R, + bool noent_ok, + bool &full_removal) { return -1; } @@ -229,8 +241,11 @@ class reapi_t { * the match operation. * \return 0 on success; -1 on error. */ - static int info (void *h, const uint64_t jobid, - std::string &mode, bool &reserved, int64_t &at, + static int info (void *h, + const uint64_t jobid, + std::string &mode, + bool &reserved, + int64_t &at, double &ov) { return -1; @@ -251,17 +266,23 @@ class reapi_t { * \param avg Avg match time * \return 0 on success; -1 on error. */ - static int stat (void *h, int64_t &V, int64_t &E,int64_t &J, - double &load, double &min, double &max, double &avg) + static int stat (void *h, + int64_t &V, + int64_t &E, + int64_t &J, + double &load, + double &min, + double &max, + double &avg) { return -1; } }; -} // namespace Flux::resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // REAPI_HPP +#endif // REAPI_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/reapi/bindings/c++/reapi_cli.hpp b/resource/reapi/bindings/c++/reapi_cli.hpp index c81252e8b..916d4a0fc 100644 --- a/resource/reapi/bindings/c++/reapi_cli.hpp +++ b/resource/reapi/bindings/c++/reapi_cli.hpp @@ -32,12 +32,15 @@ namespace Flux { namespace resource_model { namespace detail { -enum class emit_format_t { GRAPHVIZ_DOT, GRAPH_ML, }; +enum class emit_format_t { + GRAPHVIZ_DOT, + GRAPH_ML, +}; struct match_perf_t { - double min; /* Min match time */ - double max; /* Max match time */ - double accum; /* Total match time accumulated */ + double min; /* Min match time */ + double max; /* Max match time */ + double accum; /* Total match time accumulated */ }; struct resource_params_t { @@ -53,14 +56,14 @@ struct resource_params_t { std::string prune_filters; /* Raw prune-filter specification */ std::string match_format; /* Format to emit a matched resources */ emit_format_t o_format; - bool elapse_time; /* Print elapse time */ - bool disable_prompt; /* Disable resource-query> prompt */ - bool flux_hwloc; /* get hwloc info from flux instance */ - size_t reserve_vtx_vec; /* Allow for reserving vertex vector size */ + bool elapse_time; /* Print elapse time */ + bool disable_prompt; /* Disable resource-query> prompt */ + bool flux_hwloc; /* get hwloc info from flux instance */ + size_t reserve_vtx_vec; /* Allow for reserving vertex vector size */ }; class resource_query_t { -public: + public: resource_query_t (); resource_query_t (const std::string &rgraph, const std::string &options); ~resource_query_t (); @@ -83,39 +86,36 @@ class resource_query_t { void erase_reservation (const uint64_t jobid); void set_allocation (const uint64_t jobid); void erase_allocation (const uint64_t jobid); - void set_job (const uint64_t jobid, - const std::shared_ptr &job); + void set_job (const uint64_t jobid, const std::shared_ptr &job); int remove_job (const uint64_t jobid); - int remove_job (const uint64_t jobid, const std::string &R, - bool &full_removal); + int remove_job (const uint64_t jobid, const std::string &R, bool &full_removal); void incr_job_counter (); /* Run the traverser to match the jobspec */ - int traverser_run (Flux::Jobspec::Jobspec &job, match_op_t op, - int64_t jobid, int64_t &at); + int traverser_run (Flux::Jobspec::Jobspec &job, match_op_t op, int64_t jobid, int64_t &at); int traverser_find (std::string criteria); - // must be public; results in a deleted stringstream if converted to + // must be public; results in a deleted stringstream if converted to // a private member function - std::shared_ptr writers; /* Vertex/Edge writers */ + std::shared_ptr writers; /* Vertex/Edge writers */ -private: + private: /************************************************************************ * * * Private Member Data * * * ************************************************************************/ - std::string m_err_msg; /* class error message */ - resource_params_t params; /* Parameters for resource graph context */ - uint64_t jobid_counter; /* Hold the current jobid value */ - std::shared_ptr matcher; /* Match callback object */ + std::string m_err_msg; /* class error message */ + resource_params_t params; /* Parameters for resource graph context */ + uint64_t jobid_counter; /* Hold the current jobid value */ + std::shared_ptr matcher; /* Match callback object */ std::shared_ptr traverser; /* Graph traverser object */ std::shared_ptr db; /* Resource graph data store */ - match_perf_t perf; /* Match performance stats */ + match_perf_t perf; /* Match performance stats */ std::map> jobs; /* Jobs table */ - std::map allocations; /* Allocation table */ - std::map reservations; /* Reservation table */ + std::map allocations; /* Allocation table */ + std::map reservations; /* Reservation table */ /************************************************************************ * * @@ -129,42 +129,61 @@ class resource_query_t { }; class reapi_cli_t : public reapi_t { -public: - static int match_allocate (void *h, match_op_t match_op, + public: + static int match_allocate (void *h, + match_op_t match_op, const std::string &jobspec, - const uint64_t jobid, bool &reserved, - std::string &R, int64_t &at, double &ov); - static int match_allocate_multi (void *h, bool orelse_reserve, + const uint64_t jobid, + bool &reserved, + std::string &R, + int64_t &at, + double &ov); + static int match_allocate_multi (void *h, + bool orelse_reserve, const char *jobs, queue_adapter_base_t *adapter); - static int update_allocate (void *h, const uint64_t jobid, - const std::string &R, int64_t &at, double &ov, + static int update_allocate (void *h, + const uint64_t jobid, + const std::string &R, + int64_t &at, + double &ov, std::string &R_out); static int cancel (void *h, const uint64_t jobid, bool noent_ok); - static int cancel (void *h, const uint64_t jobid, const std::string &R, - bool noent_ok, bool &full_removal); - static int find (void *h, std::string criteria, json_t *&o ); - static int info (void *h, const uint64_t jobid, std::string &mode, - bool &reserved, int64_t &at, double &ov); - static int info (void *h, const uint64_t jobid, - std::shared_ptr &job); + static int cancel (void *h, + const uint64_t jobid, + const std::string &R, + bool noent_ok, + bool &full_removal); + static int find (void *h, std::string criteria, json_t *&o); + static int info (void *h, + const uint64_t jobid, + std::string &mode, + bool &reserved, + int64_t &at, + double &ov); + static int info (void *h, const uint64_t jobid, std::shared_ptr &job); static unsigned int preorder_count (void *h); static unsigned int postorder_count (void *h); - static int stat (void *h, int64_t &V, int64_t &E,int64_t &J, - double &load, double &min, double &max, double &avg); + static int stat (void *h, + int64_t &V, + int64_t &E, + int64_t &J, + double &load, + double &min, + double &max, + double &avg); static const std::string &get_err_message (); static void clear_err_message (); -private: + private: static std::string m_err_msg; }; +} // namespace detail +} // namespace resource_model +} // namespace Flux -} // namespace Flux::resource_model::detail -} // namespace Flux::resource_model -} // namespace Flux - -#endif // REAPI_MODULE_HPP +#endif // REAPI_MODULE_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/reapi/bindings/c++/reapi_cli_impl.hpp b/resource/reapi/bindings/c++/reapi_cli_impl.hpp index 0a5c860c5..801641e3d 100644 --- a/resource/reapi/bindings/c++/reapi_cli_impl.hpp +++ b/resource/reapi/bindings/c++/reapi_cli_impl.hpp @@ -32,27 +32,29 @@ const int NOT_YET_IMPLEMENTED = -1; static double get_elapsed_time (timeval &st, timeval &et) { - double ts1 = (double)st.tv_sec + (double)st.tv_usec/1000000.0f; - double ts2 = (double)et.tv_sec + (double)et.tv_usec/1000000.0f; + double ts1 = (double)st.tv_sec + (double)st.tv_usec / 1000000.0f; + double ts2 = (double)et.tv_sec + (double)et.tv_usec / 1000000.0f; return ts2 - ts1; } - //////////////////////////////////////////////////////////////////////////////// // REAPI CLI Class Private Definitions //////////////////////////////////////////////////////////////////////////////// std::string reapi_cli_t::m_err_msg = ""; - //////////////////////////////////////////////////////////////////////////////// // REAPI CLI Class Public API Definitions //////////////////////////////////////////////////////////////////////////////// -int reapi_cli_t::match_allocate (void *h, match_op_t match_op, +int reapi_cli_t::match_allocate (void *h, + match_op_t match_op, const std::string &jobspec, - const uint64_t jobid, bool &reserved, - std::string &R, int64_t &at, double &ov) + const uint64_t jobid, + bool &reserved, + std::string &R, + int64_t &at, + double &ov) { resource_query_t *rq = static_cast (h); int rc = -1; @@ -64,21 +66,20 @@ int reapi_cli_t::match_allocate (void *h, match_op_t match_op, std::stringstream o; bool matched = false; - if (!match_op_valid (match_op) ) { - m_err_msg += __FUNCTION__; - m_err_msg += ": ERROR: Invalid Match Option: " - + std::string (match_op_to_string (match_op)) + "\n"; - rc = -1; - goto out; - } + if (!match_op_valid (match_op)) { + m_err_msg += __FUNCTION__; + m_err_msg += + ": ERROR: Invalid Match Option: " + std::string (match_op_to_string (match_op)) + "\n"; + rc = -1; + goto out; + } try { - Flux::Jobspec::Jobspec job {jobspec}; + Flux::Jobspec::Jobspec job{jobspec}; - if ( (rc = gettimeofday (&start_time, NULL)) < 0) { + if ((rc = gettimeofday (&start_time, NULL)) < 0) { m_err_msg += __FUNCTION__; - m_err_msg += ": ERROR: gettimeofday: " - + std::string (strerror (errno)) + "\n"; + m_err_msg += ": ERROR: gettimeofday: " + std::string (strerror (errno)) + "\n"; goto out; } @@ -91,69 +92,61 @@ int reapi_cli_t::match_allocate (void *h, match_op_t match_op, rc = -1; goto out; } - } - catch (Flux::Jobspec::parse_error &e) { + } catch (Flux::Jobspec::parse_error &e) { m_err_msg += __FUNCTION__; - m_err_msg += ": ERROR: Jobspec error for " - + std::to_string (rq->get_job_counter ()) - + ": " + std::string (e.what ()) + "\n"; + m_err_msg += ": ERROR: Jobspec error for " + std::to_string (rq->get_job_counter ()) + ": " + + std::string (e.what ()) + "\n"; rc = -1; goto out; } - if ( (rc != 0) && (errno == ENOMEM)) { + if ((rc != 0) && (errno == ENOMEM)) { m_err_msg += __FUNCTION__; - m_err_msg += ": ERROR: Memory error for " - + std::to_string (rq->get_job_counter ()); + m_err_msg += ": ERROR: Memory error for " + std::to_string (rq->get_job_counter ()); rc = -1; goto out; } - // Check for an unsuccessful match - if ( (rc == 0) && (match_op != match_op_t::MATCH_SATISFIABILITY)) { + // Check for an unsuccessful match + if ((rc == 0) && (match_op != match_op_t::MATCH_SATISFIABILITY)) { matched = true; } - - if ( (rc = rq->writers->emit (o)) < 0) { + + if ((rc = rq->writers->emit (o)) < 0) { m_err_msg += __FUNCTION__; - m_err_msg += ": ERROR: match writer emit: " - + std::string (strerror (errno)) + "\n"; + m_err_msg += ": ERROR: match writer emit: " + std::string (strerror (errno)) + "\n"; goto out; } R = o.str (); - if ( (rc = gettimeofday (&end_time, NULL)) < 0) { + if ((rc = gettimeofday (&end_time, NULL)) < 0) { m_err_msg += __FUNCTION__; - m_err_msg += ": ERROR: gettimeofday: " - + std::string (strerror (errno)) + "\n"; + m_err_msg += ": ERROR: gettimeofday: " + std::string (strerror (errno)) + "\n"; goto out; } ov = get_elapsed_time (start_time, end_time); if (matched) { - reserved = (at != 0)? true : false; - st = (reserved)? - job_lifecycle_t::RESERVED : job_lifecycle_t::ALLOCATED; - if (reserved) - rq->set_reservation (jobid); + reserved = (at != 0) ? true : false; + st = (reserved) ? job_lifecycle_t::RESERVED : job_lifecycle_t::ALLOCATED; + if (reserved) + rq->set_reservation (jobid); else rq->set_allocation (jobid); - - job_info = std::make_shared (jobid, st, at, "", "", ov); + + job_info = std::make_shared (jobid, st, at, "", "", ov); if (job_info == nullptr) { - errno = ENOMEM; - m_err_msg += __FUNCTION__; - m_err_msg += ": ERROR: can't allocate memory: " - + std::string (strerror (errno))+ "\n"; - rc = -1; - goto out; + errno = ENOMEM; + m_err_msg += __FUNCTION__; + m_err_msg += ": ERROR: can't allocate memory: " + std::string (strerror (errno)) + "\n"; + rc = -1; + goto out; } rq->set_job (jobid, job_info); - } - + if (match_op != match_op_t::MATCH_SATISFIABILITY) rq->incr_job_counter (); @@ -161,14 +154,18 @@ int reapi_cli_t::match_allocate (void *h, match_op_t match_op, return rc; } -int reapi_cli_t::update_allocate (void *h, const uint64_t jobid, - const std::string &R, int64_t &at, double &ov, +int reapi_cli_t::update_allocate (void *h, + const uint64_t jobid, + const std::string &R, + int64_t &at, + double &ov, std::string &R_out) { return NOT_YET_IMPLEMENTED; } -int reapi_cli_t::match_allocate_multi (void *h, bool orelse_reserve, +int reapi_cli_t::match_allocate_multi (void *h, + bool orelse_reserve, const char *jobs, queue_adapter_base_t *adapter) { @@ -181,115 +178,114 @@ int reapi_cli_t::cancel (void *h, const uint64_t jobid, bool noent_ok) int rc = -1; if (rq->allocation_exists (jobid)) { - if ( (rc = rq->remove_job (jobid)) == 0) + if ((rc = rq->remove_job (jobid)) == 0) rq->erase_allocation (jobid); } else if (rq->reservation_exists (jobid)) { - if ( (rc = rq->remove_job (jobid)) == 0) + if ((rc = rq->remove_job (jobid)) == 0) rq->erase_reservation (jobid); } else { m_err_msg += __FUNCTION__; - m_err_msg += ": ERROR: nonexistent job " - + std::to_string (jobid) + "\n"; + m_err_msg += ": ERROR: nonexistent job " + std::to_string (jobid) + "\n"; goto out; } if (rc != 0) { m_err_msg += __FUNCTION__; - m_err_msg += ": ERROR: error encountered while removing job " - + std::to_string (jobid) + "\n"; + m_err_msg += + ": ERROR: error encountered while removing job " + std::to_string (jobid) + "\n"; } out: return rc; } -int reapi_cli_t::cancel (void *h, const uint64_t jobid, const std::string &R, - bool noent_ok, bool &full_removal) +int reapi_cli_t::cancel (void *h, + const uint64_t jobid, + const std::string &R, + bool noent_ok, + bool &full_removal) { resource_query_t *rq = static_cast (h); int rc = -1; if (rq->allocation_exists (jobid)) { - if ( (rc = rq->remove_job (jobid, R, full_removal)) == 0) { + if ((rc = rq->remove_job (jobid, R, full_removal)) == 0) { if (full_removal) rq->erase_allocation (jobid); } } else { m_err_msg += __FUNCTION__; - m_err_msg += ": WARNING: can't find allocation for jobid: " - + std::to_string (jobid) + "\n"; + m_err_msg += ": WARNING: can't find allocation for jobid: " + std::to_string (jobid) + "\n"; rc = 0; goto out; } if (rc != 0) { m_err_msg += __FUNCTION__; - m_err_msg += ": ERROR: error encountered while removing job " - + std::to_string (jobid) + "\n"; + m_err_msg += + ": ERROR: error encountered while removing job " + std::to_string (jobid) + "\n"; } out: return rc; } -int reapi_cli_t::find (void *h, std::string criteria, - json_t *&o ) +int reapi_cli_t::find (void *h, std::string criteria, json_t *&o) { int rc = -1; resource_query_t *rq = static_cast (h); - - if ( (rc = rq->traverser_find (criteria)) < 0) { + + if ((rc = rq->traverser_find (criteria)) < 0) { if (rq->get_traverser_err_msg () != "") { - m_err_msg += __FUNCTION__; - m_err_msg += rq->get_traverser_err_msg (); + m_err_msg += __FUNCTION__; + m_err_msg += rq->get_traverser_err_msg (); rq->clear_traverser_err_msg (); } return rc; } - - if ( (rc = rq->writers->emit_json (&o)) < 0) { + if ((rc = rq->writers->emit_json (&o)) < 0) { m_err_msg += __FUNCTION__; - m_err_msg += ": ERROR: find writer emit: " - + std::string (strerror (errno)) + "\n"; - return rc; + m_err_msg += ": ERROR: find writer emit: " + std::string (strerror (errno)) + "\n"; + return rc; } return rc; } -int reapi_cli_t::info (void *h, const uint64_t jobid, std::string &mode, - bool &reserved, int64_t &at, double &ov) +int reapi_cli_t::info (void *h, + const uint64_t jobid, + std::string &mode, + bool &reserved, + int64_t &at, + double &ov) { resource_query_t *rq = static_cast (h); std::shared_ptr info = nullptr; - if ( !(rq->job_exists (jobid))) { - m_err_msg += __FUNCTION__; - m_err_msg += ": ERROR: nonexistent job " - + std::to_string (jobid) + "\n"; - return -1; + if (!(rq->job_exists (jobid))) { + m_err_msg += __FUNCTION__; + m_err_msg += ": ERROR: nonexistent job " + std::to_string (jobid) + "\n"; + return -1; } info = rq->get_job (jobid); get_jobstate_str (info->state, mode); - reserved = (info->state == job_lifecycle_t::RESERVED)? true : false; + reserved = (info->state == job_lifecycle_t::RESERVED) ? true : false; at = info->scheduled_at; ov = info->overhead; return 0; } -int reapi_cli_t::info (void *h, const uint64_t jobid, - std::shared_ptr &job) +int reapi_cli_t::info (void *h, const uint64_t jobid, std::shared_ptr &job) { resource_query_t *rq = static_cast (h); - if ( !(rq->job_exists (jobid))) { - m_err_msg += __FUNCTION__; - m_err_msg += ": ERROR: nonexistent job " - + std::to_string (jobid) + "\n"; - return -1; + if (!(rq->job_exists (jobid))) { + m_err_msg += __FUNCTION__; + m_err_msg += ": ERROR: nonexistent job " + std::to_string (jobid) + "\n"; + return -1; } job = rq->get_job (jobid); @@ -310,8 +306,14 @@ unsigned int reapi_cli_t::postorder_count (void *h) return rq->postorder_count (); } -int reapi_cli_t::stat (void *h, int64_t &V, int64_t &E,int64_t &J, - double &load, double &min, double &max, double &avg) +int reapi_cli_t::stat (void *h, + int64_t &V, + int64_t &E, + int64_t &J, + double &load, + double &min, + double &max, + double &avg) { return NOT_YET_IMPLEMENTED; } @@ -326,7 +328,6 @@ void reapi_cli_t::clear_err_message () m_err_msg = ""; } - //////////////////////////////////////////////////////////////////////////////// // Resource Query Class Private API Definitions //////////////////////////////////////////////////////////////////////////////// @@ -346,65 +347,65 @@ int resource_query_t::set_subsystems_use (const std::string &n) const std::string &matcher_type = matcher->matcher_name (); if (boost::iequals (matcher_type, std::string ("CA"))) { - if ( (rc = subsystem_exist ("containment")) == 0) + if ((rc = subsystem_exist ("containment")) == 0) matcher->add_subsystem ("containment", "*"); } else if (boost::iequals (matcher_type, std::string ("IBA"))) { - if ( (rc = subsystem_exist ("ibnet")) == 0) + if ((rc = subsystem_exist ("ibnet")) == 0) matcher->add_subsystem ("ibnet", "*"); } else if (boost::iequals (matcher_type, std::string ("IBBA"))) { - if ( (rc = subsystem_exist ("ibnetbw")) == 0) + if ((rc = subsystem_exist ("ibnetbw")) == 0) matcher->add_subsystem ("ibnetbw", "*"); } else if (boost::iequals (matcher_type, std::string ("PFS1BA"))) { - if ( (rc = subsystem_exist ("pfs1bw")) == 0) + if ((rc = subsystem_exist ("pfs1bw")) == 0) matcher->add_subsystem ("pfs1bw", "*"); } else if (boost::iequals (matcher_type, std::string ("PA"))) { - if ( (rc = subsystem_exist ("power")) == 0) + if ((rc = subsystem_exist ("power")) == 0) matcher->add_subsystem ("power", "*"); } else if (boost::iequals (matcher_type, std::string ("C+PFS1BA"))) { - if ( (rc = subsystem_exist ("containment")) == 0) + if ((rc = subsystem_exist ("containment")) == 0) matcher->add_subsystem ("containment", "contains"); - if ( !rc && (rc = subsystem_exist ("pfs1bw")) == 0) + if (!rc && (rc = subsystem_exist ("pfs1bw")) == 0) matcher->add_subsystem ("pfs1bw", "*"); } else if (boost::iequals (matcher_type, std::string ("C+IBA"))) { - if ( (rc = subsystem_exist ("containment")) == 0) + if ((rc = subsystem_exist ("containment")) == 0) matcher->add_subsystem ("containment", "contains"); - if ( !rc && (rc = subsystem_exist ("ibnet")) == 0) + if (!rc && (rc = subsystem_exist ("ibnet")) == 0) matcher->add_subsystem ("ibnet", "connected_up"); } else if (boost::iequals (matcher_type, std::string ("C+PA"))) { - if ( (rc = subsystem_exist ("containment")) == 0) + if ((rc = subsystem_exist ("containment")) == 0) matcher->add_subsystem ("containment", "*"); - if ( !rc && (rc = subsystem_exist ("power")) == 0) + if (!rc && (rc = subsystem_exist ("power")) == 0) matcher->add_subsystem ("power", "draws_from"); } else if (boost::iequals (matcher_type, std::string ("IB+IBBA"))) { - if ( (rc = subsystem_exist ("ibnet")) == 0) + if ((rc = subsystem_exist ("ibnet")) == 0) matcher->add_subsystem ("ibnet", "connected_down"); - if ( !rc && (rc = subsystem_exist ("ibnetbw")) == 0) + if (!rc && (rc = subsystem_exist ("ibnetbw")) == 0) matcher->add_subsystem ("ibnetbw", "*"); } else if (boost::iequals (matcher_type, std::string ("C+P+IBA"))) { - if ( (rc = subsystem_exist ("containment")) == 0) + if ((rc = subsystem_exist ("containment")) == 0) matcher->add_subsystem ("containment", "contains"); - if ( (rc = subsystem_exist ("power")) == 0) + if ((rc = subsystem_exist ("power")) == 0) matcher->add_subsystem ("power", "draws_from"); - if ( !rc && (rc = subsystem_exist ("ibnet")) == 0) + if (!rc && (rc = subsystem_exist ("ibnet")) == 0) matcher->add_subsystem ("ibnet", "connected_up"); } else if (boost::iequals (matcher_type, std::string ("V+PFS1BA"))) { - if ( (rc = subsystem_exist ("virtual1")) == 0) + if ((rc = subsystem_exist ("virtual1")) == 0) matcher->add_subsystem ("virtual1", "*"); - if ( !rc && (rc = subsystem_exist ("pfs1bw")) == 0) + if (!rc && (rc = subsystem_exist ("pfs1bw")) == 0) matcher->add_subsystem ("pfs1bw", "*"); } else if (boost::iequals (matcher_type, std::string ("VA"))) { - if ( (rc = subsystem_exist ("virtual1")) == 0) + if ((rc = subsystem_exist ("virtual1")) == 0) matcher->add_subsystem ("virtual1", "*"); } else if (boost::iequals (matcher_type, std::string ("ALL"))) { - if ( (rc = subsystem_exist ("containment")) == 0) + if ((rc = subsystem_exist ("containment")) == 0) matcher->add_subsystem ("containment", "*"); - if ( !rc && (rc = subsystem_exist ("ibnet")) == 0) + if (!rc && (rc = subsystem_exist ("ibnet")) == 0) matcher->add_subsystem ("ibnet", "*"); - if ( !rc && (rc = subsystem_exist ("ibnetbw")) == 0) + if (!rc && (rc = subsystem_exist ("ibnetbw")) == 0) matcher->add_subsystem ("ibnetbw", "*"); - if ( !rc && (rc = subsystem_exist ("pfs1bw")) == 0) + if (!rc && (rc = subsystem_exist ("pfs1bw")) == 0) matcher->add_subsystem ("pfs1bw", "*"); - if ( (rc = subsystem_exist ("power")) == 0) + if ((rc = subsystem_exist ("power")) == 0) matcher->add_subsystem ("power", "*"); } else { rc = -1; @@ -419,7 +420,7 @@ int resource_query_t::set_resource_ctx_params (const std::string &options) json_t *tmp_json = NULL, *opt_json = NULL; // Set default values - perf.min = std::numeric_limits::max(); + perf.min = std::numeric_limits::max (); perf.max = 0.0f; perf.accum = 0.0f; params.load_file = "conf/default"; @@ -437,7 +438,7 @@ int resource_query_t::set_resource_ctx_params (const std::string &options) params.elapse_time = false; params.disable_prompt = false; - if ( !(opt_json = json_loads (options.c_str (), JSON_DECODE_ANY, NULL))) { + if (!(opt_json = json_loads (options.c_str (), JSON_DECODE_ANY, NULL))) { errno = ENOMEM; m_err_msg += __FUNCTION__; m_err_msg += ": Error loading options\n"; @@ -445,9 +446,9 @@ int resource_query_t::set_resource_ctx_params (const std::string &options) } // Override defaults if present in options argument - if ( (tmp_json = json_object_get (opt_json, "load_format"))) { + if ((tmp_json = json_object_get (opt_json, "load_format"))) { params.load_format = json_string_value (tmp_json); - if (!params.load_format.c_str ()) { + if (!params.load_format.c_str ()) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": Error loading load_format\n"; @@ -455,9 +456,9 @@ int resource_query_t::set_resource_ctx_params (const std::string &options) goto out; } } - if ( (tmp_json = json_object_get (opt_json, "load_allowlist"))) { + if ((tmp_json = json_object_get (opt_json, "load_allowlist"))) { params.load_allowlist = json_string_value (tmp_json); - if (!params.load_allowlist.c_str ()) { + if (!params.load_allowlist.c_str ()) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": Error loading load_allowlist\n"; @@ -465,9 +466,9 @@ int resource_query_t::set_resource_ctx_params (const std::string &options) goto out; } } - if ( (tmp_json = json_object_get (opt_json, "matcher_name"))) { + if ((tmp_json = json_object_get (opt_json, "matcher_name"))) { params.matcher_name = json_string_value (tmp_json); - if (!params.matcher_name.c_str ()) { + if (!params.matcher_name.c_str ()) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": Error loading matcher_name\n"; @@ -475,9 +476,9 @@ int resource_query_t::set_resource_ctx_params (const std::string &options) goto out; } } - if ( (tmp_json = json_object_get (opt_json, "matcher_policy"))) { + if ((tmp_json = json_object_get (opt_json, "matcher_policy"))) { params.matcher_policy = json_string_value (tmp_json); - if (!params.matcher_policy.c_str ()) { + if (!params.matcher_policy.c_str ()) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": Error loading matcher_policy\n"; @@ -485,9 +486,9 @@ int resource_query_t::set_resource_ctx_params (const std::string &options) goto out; } } - if ( (tmp_json = json_object_get (opt_json, "match_format"))) { + if ((tmp_json = json_object_get (opt_json, "match_format"))) { params.match_format = json_string_value (tmp_json); - if (!params.match_format.c_str ()) { + if (!params.match_format.c_str ()) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": Error loading match_format\n"; @@ -495,9 +496,9 @@ int resource_query_t::set_resource_ctx_params (const std::string &options) goto out; } } - if ( (tmp_json = json_object_get (opt_json, "prune_filters"))) { + if ((tmp_json = json_object_get (opt_json, "prune_filters"))) { params.prune_filters = json_string_value (tmp_json); - if (!params.prune_filters.c_str ()) { + if (!params.prune_filters.c_str ()) { errno = EINVAL; m_err_msg += __FUNCTION__; m_err_msg += ": Error loading prune_filters\n"; @@ -505,7 +506,7 @@ int resource_query_t::set_resource_ctx_params (const std::string &options) goto out; } } - if ( (tmp_json = json_object_get (opt_json, "reserve_vtx_vec"))) + if ((tmp_json = json_object_get (opt_json, "reserve_vtx_vec"))) // No need for check here; returns 0 on failure params.reserve_vtx_vec = json_integer_value (tmp_json); @@ -515,23 +516,19 @@ int resource_query_t::set_resource_ctx_params (const std::string &options) return rc; } - //////////////////////////////////////////////////////////////////////////////// // Resource Query Class Public API Definitions //////////////////////////////////////////////////////////////////////////////// -resource_query_t::resource_query_t () +resource_query_t::resource_query_t () { - } -resource_query_t::~resource_query_t () +resource_query_t::~resource_query_t () { - } -resource_query_t::resource_query_t (const std::string &rgraph, - const std::string &options) +resource_query_t::resource_query_t (const std::string &rgraph, const std::string &options) { m_err_msg = ""; std::string tmp_err = ""; @@ -549,7 +546,7 @@ resource_query_t::resource_query_t (const std::string &rgraph, throw std::runtime_error (tmp_err); } - if ( !(matcher = create_match_cb (params.matcher_policy))) { + if (!(matcher = create_match_cb (params.matcher_policy))) { tmp_err = __FUNCTION__; tmp_err += ": ERROR: can't create matcher\n"; throw std::runtime_error (tmp_err); @@ -558,9 +555,9 @@ resource_query_t::resource_query_t (const std::string &rgraph, if (params.reserve_vtx_vec != 0) db->resource_graph.m_vertices.reserve (params.reserve_vtx_vec); - if ( (rd = create_resource_reader (params.load_format)) == nullptr) { + if ((rd = create_resource_reader (params.load_format)) == nullptr) { tmp_err = __FUNCTION__; - tmp_err += ": ERROR: can't create reader\n"; + tmp_err += ": ERROR: can't create reader\n"; throw std::runtime_error (tmp_err); } @@ -575,38 +572,36 @@ resource_query_t::resource_query_t (const std::string &rgraph, if (db->load (rgraph, rd) != 0) { tmp_err = __FUNCTION__; - tmp_err += ": ERROR: " + rd->err_message () + "\n"; + tmp_err += ": ERROR: " + rd->err_message () + "\n"; tmp_err += "ERROR: error generating resources\n"; throw std::runtime_error (tmp_err); } if (set_subsystems_use (params.matcher_name) != 0) { tmp_err = __FUNCTION__; - tmp_err += ": ERROR: can't set subsystem\n"; + tmp_err += ": ERROR: can't set subsystem\n"; throw std::runtime_error (tmp_err); } jobid_counter = 1; if (params.prune_filters != "" - && matcher->set_pruning_types_w_spec ( - matcher->dom_subsystem (), - params.prune_filters) - < 0) { + && matcher->set_pruning_types_w_spec (matcher->dom_subsystem (), params.prune_filters) + < 0) { tmp_err = __FUNCTION__; - tmp_err += ": ERROR: can't initialize pruning filters\n"; + tmp_err += ": ERROR: can't initialize pruning filters\n"; throw std::runtime_error (tmp_err); } if (traverser->initialize (db, matcher) != 0) { tmp_err = __FUNCTION__; - tmp_err += ": ERROR: can't initialize traverser\n"; + tmp_err += ": ERROR: can't initialize traverser\n"; throw std::runtime_error (tmp_err); } format = match_writers_factory_t::get_writers_type (params.match_format); - if ( !(writers = match_writers_factory_t::create (format))) { + if (!(writers = match_writers_factory_t::create (format))) { tmp_err = __FUNCTION__; - tmp_err += ": ERROR: can't create match writer\n"; + tmp_err += ": ERROR: can't create match writer\n"; throw std::runtime_error (tmp_err); } @@ -688,8 +683,7 @@ void resource_query_t::erase_allocation (const uint64_t jobid) allocations.erase (jobid); } -void resource_query_t::set_job (const uint64_t jobid, - const std::shared_ptr &job) +void resource_query_t::set_job (const uint64_t jobid, const std::shared_ptr &job) { jobs[jobid] = job; } @@ -698,7 +692,7 @@ int resource_query_t::remove_job (const uint64_t jobid) { int rc = -1; - if (jobid > (uint64_t) std::numeric_limits::max ()) { + if (jobid > (uint64_t)std::numeric_limits::max ()) { errno = EOVERFLOW; return rc; } @@ -716,13 +710,12 @@ int resource_query_t::remove_job (const uint64_t jobid) return rc; } -int resource_query_t::remove_job (const uint64_t jobid, const std::string &R, - bool &full_removal) +int resource_query_t::remove_job (const uint64_t jobid, const std::string &R, bool &full_removal) { int rc = -1; std::shared_ptr reader; - if (jobid > (uint64_t) std::numeric_limits::max ()) { + if (jobid > (uint64_t)std::numeric_limits::max ()) { errno = EOVERFLOW; return rc; } @@ -730,14 +723,13 @@ int resource_query_t::remove_job (const uint64_t jobid, const std::string &R, errno = EINVAL; return rc; } - if ( (reader = create_resource_reader (params.load_format)) == nullptr) { + if ((reader = create_resource_reader (params.load_format)) == nullptr) { m_err_msg = __FUNCTION__; - m_err_msg += ": ERROR: can't create reader\n"; + m_err_msg += ": ERROR: can't create reader\n"; return rc; } - rc = traverser->remove (R, reader, static_cast (jobid), - full_removal); + rc = traverser->remove (R, reader, static_cast (jobid), full_removal); if (rc == 0) { if (full_removal) { auto job_info_it = jobs.find (jobid); @@ -758,8 +750,10 @@ void resource_query_t::incr_job_counter () jobid_counter++; } -int resource_query_t::traverser_run (Flux::Jobspec::Jobspec &job, match_op_t op, - int64_t jobid, int64_t &at) +int resource_query_t::traverser_run (Flux::Jobspec::Jobspec &job, + match_op_t op, + int64_t jobid, + int64_t &at) { return traverser->run (job, writers, op, jobid, &at); } @@ -769,12 +763,11 @@ int resource_query_t::traverser_find (std::string criteria) return traverser->find (writers, criteria); } +} // namespace detail +} // namespace resource_model +} // namespace Flux -} // namespace Flux::resource_model::detail -} // namespace Flux::resource_model -} // namespace Flux - -#endif // REAPI_CLI_IMPL_HPP +#endif // REAPI_CLI_IMPL_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/reapi/bindings/c++/reapi_module.hpp b/resource/reapi/bindings/c++/reapi_module.hpp index f3b14504e..45c6f9a27 100644 --- a/resource/reapi/bindings/c++/reapi_module.hpp +++ b/resource/reapi/bindings/c++/reapi_module.hpp @@ -28,39 +28,59 @@ namespace resource_model { namespace detail { class reapi_module_t : public reapi_t { -public: - static int match_allocate (void *h, match_op_t match_op, + public: + static int match_allocate (void *h, + match_op_t match_op, const std::string &jobspec, - const uint64_t jobid, bool &reserved, - std::string &R, int64_t &at, double &ov); - static int match_allocate (void *h, bool orelse_reserve, + const uint64_t jobid, + bool &reserved, + std::string &R, + int64_t &at, + double &ov); + static int match_allocate (void *h, + bool orelse_reserve, const std::string &jobspec, - const uint64_t jobid, bool &reserved, - std::string &R, int64_t &at, double &ov); - static int match_allocate_multi (void *h, bool orelse_reserve, + const uint64_t jobid, + bool &reserved, + std::string &R, + int64_t &at, + double &ov); + static int match_allocate_multi (void *h, + bool orelse_reserve, const char *jobs, queue_adapter_base_t *adapter); - static int match_allocate_multi (void *h, match_op_t match_op, + static int match_allocate_multi (void *h, + match_op_t match_op, const char *jobs, queue_adapter_base_t *adapter); - static int update_allocate (void *h, const uint64_t jobid, - const std::string &R, int64_t &at, double &ov, + static int update_allocate (void *h, + const uint64_t jobid, + const std::string &R, + int64_t &at, + double &ov, std::string &R_out); static int cancel (void *h, const uint64_t jobid, bool noent_ok); - static int cancel (void *h, const uint64_t jobid, const std::string &R, - bool noent_ok, bool &full_removal); - static int info (void *h, const uint64_t jobid, - bool &reserved, int64_t &at, double &ov); - static int stat (void *h, int64_t &V, int64_t &E,int64_t &J, - double &load, double &min, double &max, double &avg); + static int cancel (void *h, + const uint64_t jobid, + const std::string &R, + bool noent_ok, + bool &full_removal); + static int info (void *h, const uint64_t jobid, bool &reserved, int64_t &at, double &ov); + static int stat (void *h, + int64_t &V, + int64_t &E, + int64_t &J, + double &load, + double &min, + double &max, + double &avg); }; +} // namespace detail +} // namespace resource_model +} // namespace Flux -} // namespace Flux::resource_model::detail -} // namespace Flux::resource_model -} // namespace Flux - -#endif // REAPI_MODULE_HPP +#endif // REAPI_MODULE_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/reapi/bindings/c++/reapi_module_impl.hpp b/resource/reapi/bindings/c++/reapi_module_impl.hpp index 20308e3ad..ecef5d000 100644 --- a/resource/reapi/bindings/c++/reapi_module_impl.hpp +++ b/resource/reapi/bindings/c++/reapi_module_impl.hpp @@ -25,10 +25,14 @@ namespace Flux { namespace resource_model { namespace detail { -int reapi_module_t::match_allocate (void *h, match_op_t match_op, +int reapi_module_t::match_allocate (void *h, + match_op_t match_op, const std::string &jobspec, - const uint64_t jobid, bool &reserved, - std::string &R, int64_t &at, double &ov) + const uint64_t jobid, + bool &reserved, + std::string &R, + int64_t &at, + double &ov) { int rc = -1; int64_t rj = -1; @@ -43,20 +47,36 @@ int reapi_module_t::match_allocate (void *h, match_op_t match_op, goto out; } - if (!(f = flux_rpc_pack (fh, "sched-fluxion-resource.match", - FLUX_NODEID_ANY, 0, + if (!(f = flux_rpc_pack (fh, + "sched-fluxion-resource.match", + FLUX_NODEID_ANY, + 0, "{s:s s:I s:s}", - "cmd", cmd, "jobid", (const int64_t)jobid, - "jobspec", jobspec.c_str ()))) { + "cmd", + cmd, + "jobid", + (const int64_t)jobid, + "jobspec", + jobspec.c_str ()))) { goto out; } - if (flux_rpc_get_unpack (f, "{s:I s:s s:f s:s s:I}", - "jobid", &rj, "status", &status, - "overhead", &ov, "R", &rset, "at", &at) < 0) { + if (flux_rpc_get_unpack (f, + "{s:I s:s s:f s:s s:I}", + "jobid", + &rj, + "status", + &status, + "overhead", + &ov, + "R", + &rset, + "at", + &at) + < 0) { goto out; } - reserved = (std::string ("RESERVED") == status)? true : false; + reserved = (std::string ("RESERVED") == status) ? true : false; R = rset; if (rj != (int64_t)jobid) { errno = EINVAL; @@ -69,16 +89,19 @@ int reapi_module_t::match_allocate (void *h, match_op_t match_op, return rc; } -int reapi_module_t::match_allocate (void *h, bool orelse_reserve, +int reapi_module_t::match_allocate (void *h, + bool orelse_reserve, const std::string &jobspec, - const uint64_t jobid, bool &reserved, - std::string &R, int64_t &at, double &ov) + const uint64_t jobid, + bool &reserved, + std::string &R, + int64_t &at, + double &ov) { - match_op_t match_op = (orelse_reserve)? match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE - : match_op_t::MATCH_ALLOCATE_W_SATISFIABILITY; - - return match_allocate (h, match_op, jobspec, jobid, reserved, R, at, ov); + match_op_t match_op = (orelse_reserve) ? match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE + : match_op_t::MATCH_ALLOCATE_W_SATISFIABILITY; + return match_allocate (h, match_op, jobspec, jobid, reserved, R, at, ov); } void match_allocate_multi_cont (flux_future_t *f, void *arg) @@ -90,12 +113,19 @@ void match_allocate_multi_cont (flux_future_t *f, void *arg) const char *status = nullptr; queue_adapter_base_t *adapter = static_cast (arg); - if (flux_rpc_get_unpack (f, "{s:I s:s s:f s:s s:I}", - "jobid", &jobid, - "status", &status, - "overhead", &ov, - "R", &rset, - "at", &at) == 0) { + if (flux_rpc_get_unpack (f, + "{s:I s:s s:f s:s s:I}", + "jobid", + &jobid, + "status", + &status, + "overhead", + &ov, + "R", + &rset, + "at", + &at) + == 0) { if (adapter->handle_match_success (jobid, status, rset, at, ov) < 0) { adapter->set_sched_loop_active (false); flux_future_destroy (f); @@ -124,17 +154,17 @@ int reapi_module_t::match_allocate_multi (void *h, errno = EINVAL; goto error; } - if ( !(f = flux_rpc_pack (fh, - "sched-fluxion-resource.match_multi", - FLUX_NODEID_ANY, FLUX_RPC_STREAMING, - "{s:s s:s}", - "cmd", cmd, - "jobs", jobs))) + if (!(f = flux_rpc_pack (fh, + "sched-fluxion-resource.match_multi", + FLUX_NODEID_ANY, + FLUX_RPC_STREAMING, + "{s:s s:s}", + "cmd", + cmd, + "jobs", + jobs))) goto error; - if (flux_future_then (f, - -1.0f, - match_allocate_multi_cont, - static_cast (adapter)) < 0) + if (flux_future_then (f, -1.0f, match_allocate_multi_cont, static_cast (adapter)) < 0) goto error; return 0; @@ -148,15 +178,18 @@ int reapi_module_t::match_allocate_multi (void *h, const char *jobs, queue_adapter_base_t *adapter) { - match_op_t match_op = (orelse_reserve)? match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE - : match_op_t::MATCH_ALLOCATE_W_SATISFIABILITY; + match_op_t match_op = (orelse_reserve) ? match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE + : match_op_t::MATCH_ALLOCATE_W_SATISFIABILITY; return match_allocate_multi (h, match_op, jobs, adapter); } -int reapi_module_t::update_allocate (void *h, const uint64_t jobid, - const std::string &R, int64_t &at, - double &ov, std::string &R_out) +int reapi_module_t::update_allocate (void *h, + const uint64_t jobid, + const std::string &R, + int64_t &at, + double &ov, + std::string &R_out) { int rc = -1; int64_t res_jobid = -1; @@ -171,22 +204,31 @@ int reapi_module_t::update_allocate (void *h, const uint64_t jobid, errno = EINVAL; goto out; } - if ( !(f = flux_rpc_pack (fh, "sched-fluxion-resource.update", - FLUX_NODEID_ANY, 0, - "{s:I s:s}", - "jobid", jobid, - "R", R.c_str ()))) + if (!(f = flux_rpc_pack (fh, + "sched-fluxion-resource.update", + FLUX_NODEID_ANY, + 0, + "{s:I s:s}", + "jobid", + jobid, + "R", + R.c_str ()))) goto out; - if ( (rc = flux_rpc_get_unpack (f, "{s:I s:s s:f s:s s:I}", - "jobid", &res_jobid, - "status", &status, - "overhead", &overhead, - "R", &rset, - "at", &scheduled_at)) < 0) + if ((rc = flux_rpc_get_unpack (f, + "{s:I s:s s:f s:s s:I}", + "jobid", + &res_jobid, + "status", + &status, + "overhead", + &overhead, + "R", + &rset, + "at", + &scheduled_at)) + < 0) goto out; - if (res_jobid != static_cast (jobid) - || rset == NULL - || status == NULL + if (res_jobid != static_cast (jobid) || rset == NULL || status == NULL || std::string ("ALLOCATED") != status) { rc = -1; errno = EPROTO; @@ -212,9 +254,13 @@ int reapi_module_t::cancel (void *h, const uint64_t jobid, bool noent_ok) errno = EINVAL; goto out; } - if (!(f = flux_rpc_pack (fh, "sched-fluxion-resource.cancel", - FLUX_NODEID_ANY, 0, - "{s:I}", "jobid", (const int64_t)jobid))) { + if (!(f = flux_rpc_pack (fh, + "sched-fluxion-resource.cancel", + FLUX_NODEID_ANY, + 0, + "{s:I}", + "jobid", + (const int64_t)jobid))) { goto out; } saved_errno = errno; @@ -232,8 +278,10 @@ int reapi_module_t::cancel (void *h, const uint64_t jobid, bool noent_ok) return rc; } -int reapi_module_t::cancel (void *h, const uint64_t jobid, - const std::string &R, bool noent_ok, +int reapi_module_t::cancel (void *h, + const uint64_t jobid, + const std::string &R, + bool noent_ok, bool &full_removal) { int rc = -1; @@ -246,20 +294,23 @@ int reapi_module_t::cancel (void *h, const uint64_t jobid, errno = EINVAL; goto out; } - if (!(f = flux_rpc_pack (fh, "sched-fluxion-resource.partial-cancel", - FLUX_NODEID_ANY, 0, - "{s:I s:s}", - "jobid", (const int64_t)jobid, - "R", R.c_str ()))) { + if (!(f = flux_rpc_pack (fh, + "sched-fluxion-resource.partial-cancel", + FLUX_NODEID_ANY, + 0, + "{s:I s:s}", + "jobid", + (const int64_t)jobid, + "R", + R.c_str ()))) { goto out; } saved_errno = errno; - if ( (rc = flux_rpc_get_unpack (f, "{s:i}", - "full-removal", &ret_removal)) < 0) { + if ((rc = flux_rpc_get_unpack (f, "{s:i}", "full-removal", &ret_removal)) < 0) { if (noent_ok && (errno == ENOENT)) { errno = saved_errno; rc = 0; - } + } goto out; } rc = 0; @@ -270,8 +321,7 @@ int reapi_module_t::cancel (void *h, const uint64_t jobid, return rc; } -int reapi_module_t::info (void *h, const uint64_t jobid, - bool &reserved, int64_t &at, double &ov) +int reapi_module_t::info (void *h, const uint64_t jobid, bool &reserved, int64_t &at, double &ov) { int rc = -1; int64_t rj = -1; @@ -283,17 +333,29 @@ int reapi_module_t::info (void *h, const uint64_t jobid, errno = EINVAL; goto out; } - if (!(f = flux_rpc_pack (fh, "sched-fluxion-resource.info", - FLUX_NODEID_ANY, 0, - "{s:I}", "jobid", (const int64_t)jobid))) { + if (!(f = flux_rpc_pack (fh, + "sched-fluxion-resource.info", + FLUX_NODEID_ANY, + 0, + "{s:I}", + "jobid", + (const int64_t)jobid))) { goto out; } - if (flux_rpc_get_unpack (f, "{s:I s:s s:I s:f}", - "jobid", &rj, "status", &status, - "at", &at, "overhead", &ov) < 0) { + if (flux_rpc_get_unpack (f, + "{s:I s:s s:I s:f}", + "jobid", + &rj, + "status", + &status, + "at", + &at, + "overhead", + &ov) + < 0) { goto out; } - reserved = (std::string ("RESERVED") == status)? true : false; + reserved = (std::string ("RESERVED") == status) ? true : false; if (rj != (int64_t)jobid) { errno = EINVAL; goto out; @@ -305,8 +367,14 @@ int reapi_module_t::info (void *h, const uint64_t jobid, return rc; } -int reapi_module_t::stat (void *h, int64_t &V, int64_t &E,int64_t &J, - double &load, double &min, double &max, double &avg) +int reapi_module_t::stat (void *h, + int64_t &V, + int64_t &E, + int64_t &J, + double &load, + double &min, + double &max, + double &avg) { int rc = -1; flux_t *fh = (flux_t *)h; @@ -317,14 +385,26 @@ int reapi_module_t::stat (void *h, int64_t &V, int64_t &E,int64_t &J, goto out; } - if (!(f = flux_rpc (fh, "sched-fluxion-resource.stats-get", - NULL, FLUX_NODEID_ANY, 0))) { + if (!(f = flux_rpc (fh, "sched-fluxion-resource.stats-get", NULL, FLUX_NODEID_ANY, 0))) { goto out; } - if ((rc = flux_rpc_get_unpack (f, "{s:I s:I s:f s:I s:f s:f s:f}", - "V", &V, "E", &E, "load-time", &load, - "njobs", &J, "min-match", &min, - "max-match", &max, "avg-match", &avg)) < 0) { + if ((rc = flux_rpc_get_unpack (f, + "{s:I s:I s:f s:I s:f s:f s:f}", + "V", + &V, + "E", + &E, + "load-time", + &load, + "njobs", + &J, + "min-match", + &min, + "max-match", + &max, + "avg-match", + &avg)) + < 0) { goto out; } @@ -333,11 +413,11 @@ int reapi_module_t::stat (void *h, int64_t &V, int64_t &E,int64_t &J, return rc; } -} // namespace Flux::resource_model::detail -} // namespace Flux::resource_model -} // namespace Flux +} // namespace detail +} // namespace resource_model +} // namespace Flux -#endif // REAPI_MODULE_IMPL_HPP +#endif // REAPI_MODULE_IMPL_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/reapi/bindings/c/reapi_cli.cpp b/resource/reapi/bindings/c/reapi_cli.cpp index 09d99fde0..6bec44ca9 100644 --- a/resource/reapi/bindings/c/reapi_cli.cpp +++ b/resource/reapi/bindings/c/reapi_cli.cpp @@ -37,11 +37,9 @@ extern "C" reapi_cli_ctx_t *reapi_cli_new () try { ctx = new reapi_cli_ctx_t; - } - catch (const std::bad_alloc &e) { + } catch (const std::bad_alloc &e) { ctx->err_msg = __FUNCTION__; - ctx->err_msg += ": ERROR: can't allocate memory: " - + std::string (e.what ()) + "\n"; + ctx->err_msg += ": ERROR: can't allocate memory: " + std::string (e.what ()) + "\n"; errno = ENOMEM; goto out; } @@ -62,8 +60,7 @@ extern "C" void reapi_cli_destroy (reapi_cli_ctx_t *ctx) errno = saved_errno; } -extern "C" int reapi_cli_initialize (reapi_cli_ctx_t *ctx, const char *rgraph, - const char *options) +extern "C" int reapi_cli_initialize (reapi_cli_ctx_t *ctx, const char *rgraph, const char *options) { int rc = -1; ctx->rqt = nullptr; @@ -72,14 +69,12 @@ extern "C" int reapi_cli_initialize (reapi_cli_ctx_t *ctx, const char *rgraph, ctx->rqt = new resource_query_t (rgraph, options); } catch (std::bad_alloc &e) { ctx->err_msg += __FUNCTION__; - ctx->err_msg += ": ERROR: can't allocate memory: " - + std::string (e.what ()) + "\n"; + ctx->err_msg += ": ERROR: can't allocate memory: " + std::string (e.what ()) + "\n"; errno = ENOMEM; goto out; } catch (std::runtime_error &e) { ctx->err_msg += __FUNCTION__; - ctx->err_msg += ": Runtime error: " - + std::string (e.what ()) + "\n"; + ctx->err_msg += ": Runtime error: " + std::string (e.what ()) + "\n"; errno = EPROTO; goto out; } @@ -87,13 +82,17 @@ extern "C" int reapi_cli_initialize (reapi_cli_ctx_t *ctx, const char *rgraph, rc = 0; out: - return rc; + return rc; } extern "C" int reapi_cli_match (reapi_cli_ctx_t *ctx, - match_op_t match_op, const char *jobspec, - uint64_t *jobid, bool *reserved, - char **R, int64_t *at, double *ov) + match_op_t match_op, + const char *jobspec, + uint64_t *jobid, + bool *reserved, + char **R, + int64_t *at, + double *ov) { int rc = -1; std::string R_buf = ""; @@ -105,13 +104,13 @@ extern "C" int reapi_cli_match (reapi_cli_ctx_t *ctx, } *jobid = ctx->rqt->get_job_counter (); - if ((rc = reapi_cli_t::match_allocate (ctx->rqt, match_op, - jobspec, *jobid, *reserved, - R_buf, *at, *ov)) < 0) { + if ((rc = reapi_cli_t:: + match_allocate (ctx->rqt, match_op, jobspec, *jobid, *reserved, R_buf, *at, *ov)) + < 0) { goto out; } - if ( !(R_buf_c = strdup (R_buf.c_str ()))) { + if (!(R_buf_c = strdup (R_buf.c_str ()))) { ctx->err_msg = __FUNCTION__; ctx->err_msg += ": ERROR: can't allocate memory\n"; errno = ENOMEM; @@ -125,43 +124,48 @@ extern "C" int reapi_cli_match (reapi_cli_ctx_t *ctx, } extern "C" int reapi_cli_match_allocate (reapi_cli_ctx_t *ctx, - bool orelse_reserve, const char *jobspec, - uint64_t *jobid, bool *reserved, - char **R, int64_t *at, double *ov) + bool orelse_reserve, + const char *jobspec, + uint64_t *jobid, + bool *reserved, + char **R, + int64_t *at, + double *ov) { - match_op_t match_op = orelse_reserve ? match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE : - match_op_t::MATCH_ALLOCATE; + match_op_t match_op = + orelse_reserve ? match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE : match_op_t::MATCH_ALLOCATE; - return reapi_cli_match (ctx, match_op, jobspec, jobid, reserved, - R, at, ov); + return reapi_cli_match (ctx, match_op, jobspec, jobid, reserved, R, at, ov); } extern "C" int reapi_cli_match_satisfy (reapi_cli_ctx_t *ctx, - const char *jobspec, - bool *sat, double *ov) + const char *jobspec, + bool *sat, + double *ov) { match_op_t match_op = match_op_t::MATCH_SATISFIABILITY; uint64_t jobid; bool reserved; - char *R; - int64_t at; + char *R; + int64_t at; int ret; *sat = true; - ret = reapi_cli_match (ctx, match_op, jobspec, &jobid, - &reserved, &R, &at, ov); + ret = reapi_cli_match (ctx, match_op, jobspec, &jobid, &reserved, &R, &at, ov); // check for satisfiability if (errno == ENODEV) *sat = false; - return ret; + return ret; } extern "C" int reapi_cli_update_allocate (reapi_cli_ctx_t *ctx, - const uint64_t jobid, - const char *R, int64_t *at, - double *ov, const char **R_out) + const uint64_t jobid, + const char *R, + int64_t *at, + double *ov, + const char **R_out) { int rc = -1; std::string R_buf = ""; @@ -170,11 +174,10 @@ extern "C" int reapi_cli_update_allocate (reapi_cli_ctx_t *ctx, errno = EINVAL; goto out; } - if ( (rc = reapi_cli_t::update_allocate (ctx->rqt, - jobid, R, *at, *ov, R_buf)) < 0) { + if ((rc = reapi_cli_t::update_allocate (ctx->rqt, jobid, R, *at, *ov, R_buf)) < 0) { goto out; } - if ( !(R_buf_c = strdup (R_buf.c_str ()))) { + if (!(R_buf_c = strdup (R_buf.c_str ()))) { rc = -1; goto out; } @@ -183,8 +186,7 @@ extern "C" int reapi_cli_update_allocate (reapi_cli_ctx_t *ctx, return rc; } -extern "C" int reapi_cli_cancel (reapi_cli_ctx_t *ctx, - const uint64_t jobid, bool noent_ok) +extern "C" int reapi_cli_cancel (reapi_cli_ctx_t *ctx, const uint64_t jobid, bool noent_ok) { if (!ctx || !ctx->rqt) { errno = EINVAL; @@ -195,7 +197,8 @@ extern "C" int reapi_cli_cancel (reapi_cli_ctx_t *ctx, extern "C" int reapi_cli_partial_cancel (reapi_cli_ctx_t *ctx, const uint64_t jobid, - const char *R, bool noent_ok, + const char *R, + bool noent_ok, bool *full_removal) { if (!ctx || !ctx->rqt || !R) { @@ -205,8 +208,11 @@ extern "C" int reapi_cli_partial_cancel (reapi_cli_ctx_t *ctx, return reapi_cli_t::cancel (ctx->rqt, jobid, R, noent_ok, *full_removal); } -extern "C" int reapi_cli_info (reapi_cli_ctx_t *ctx, const uint64_t jobid, - char **mode, bool *reserved, int64_t *at, +extern "C" int reapi_cli_info (reapi_cli_ctx_t *ctx, + const uint64_t jobid, + char **mode, + bool *reserved, + int64_t *at, double *ov) { int rc = -1; @@ -217,10 +223,9 @@ extern "C" int reapi_cli_info (reapi_cli_ctx_t *ctx, const uint64_t jobid, errno = EINVAL; return -1; } - if ((rc = reapi_cli_t::info (ctx->rqt, jobid, mode_buf, - *reserved, *at, *ov)) < 0) + if ((rc = reapi_cli_t::info (ctx->rqt, jobid, mode_buf, *reserved, *at, *ov)) < 0) goto out; - if ( !(mode_buf_c = strdup (mode_buf.c_str ()))) { + if (!(mode_buf_c = strdup (mode_buf.c_str ()))) { ctx->err_msg = __FUNCTION__; ctx->err_msg += ": ERROR: can't allocate memory\n"; errno = ENOMEM; @@ -234,9 +239,14 @@ extern "C" int reapi_cli_info (reapi_cli_ctx_t *ctx, const uint64_t jobid, return rc; } -extern "C" int reapi_cli_stat (reapi_cli_ctx_t *ctx, int64_t *V, - int64_t *E, int64_t *J, double *load, - double *min, double *max, double *avg) +extern "C" int reapi_cli_stat (reapi_cli_ctx_t *ctx, + int64_t *V, + int64_t *E, + int64_t *J, + double *load, + double *min, + double *max, + double *avg) { if (!ctx || !ctx->rqt) { errno = EINVAL; @@ -250,8 +260,8 @@ extern "C" const char *reapi_cli_get_err_msg (reapi_cli_ctx_t *ctx) std::string err_buf = ""; if (ctx->rqt) - err_buf = ctx->rqt->get_resource_query_err_msg () - + reapi_cli_t::get_err_message () + ctx->err_msg; + err_buf = ctx->rqt->get_resource_query_err_msg () + reapi_cli_t::get_err_message () + + ctx->err_msg; else err_buf = reapi_cli_t::get_err_message () + ctx->err_msg; diff --git a/resource/reapi/bindings/c/reapi_cli.h b/resource/reapi/bindings/c/reapi_cli.h index a41ca3103..eeca639dd 100644 --- a/resource/reapi/bindings/c/reapi_cli.h +++ b/resource/reapi/bindings/c/reapi_cli.h @@ -39,8 +39,7 @@ void reapi_cli_destroy (reapi_cli_ctx_t *ctx); * \param rgraph string encoding the resource graph * \param options json string initialization options */ -int reapi_cli_initialize (reapi_cli_ctx_t *ctx, const char *rgraph, - const char *options); +int reapi_cli_initialize (reapi_cli_ctx_t *ctx, const char *rgraph, const char *options); /*! Match a jobspec to the "best" resources and either allocate * orelse reserve them. The best resources are determined by @@ -49,13 +48,13 @@ int reapi_cli_initialize (reapi_cli_ctx_t *ctx, const char *rgraph, * \param ctx reapi_cli_ctx_t context object * \param match_op match_op_t: set to specify the specific match option * from 1 of 4 choices: - * MATCH_ALLOCATE: try to allocate now and fail if resources - * aren't available. + * MATCH_ALLOCATE: try to allocate now and fail if resources + * aren't available. * MATCH_ALLOCATE_ORELSE_RESERVE : Try to allocate and reserve * if resources aren't available now. - * MATCH_SATISFIABILITY: Do a satisfiablity check and do not + * MATCH_SATISFIABILITY: Do a satisfiablity check and do not * allocate. - * MATCH_ALLOCATE_W_SATISFIABILITY: try to allocate and run + * MATCH_ALLOCATE_W_SATISFIABILITY: try to allocate and run * satisfiability check if resources are not available. * \param jobspec jobspec string. * \param jobid jobid of the uint64_t type. @@ -70,10 +69,14 @@ int reapi_cli_initialize (reapi_cli_ctx_t *ctx, const char *rgraph, * the match operation. * \return 0 on success; -1 on error. */ -int reapi_cli_match (reapi_cli_ctx_t *ctx, match_op_t match_op, - const char *jobspec, uint64_t *jobid, +int reapi_cli_match (reapi_cli_ctx_t *ctx, + match_op_t match_op, + const char *jobspec, + uint64_t *jobid, bool *reserved, - char **R, int64_t *at, double *ov); + char **R, + int64_t *at, + double *ov); /*! Match a jobspec to the "best" resources and either allocate * orelse reserve them. The best resources are determined by @@ -96,24 +99,27 @@ int reapi_cli_match (reapi_cli_ctx_t *ctx, match_op_t match_op, * the match operation. * \return 0 on success; -1 on error. */ -int reapi_cli_match_allocate (reapi_cli_ctx_t *ctx, bool orelse_reserve, - const char *jobspec, uint64_t *jobid, +int reapi_cli_match_allocate (reapi_cli_ctx_t *ctx, + bool orelse_reserve, + const char *jobspec, + uint64_t *jobid, bool *reserved, - char **R, int64_t *at, double *ov); + char **R, + int64_t *at, + double *ov); /*! Run Satisfiability check for jobspec. * * \param ctx reapi_cli_ctx_t context object * \param jobspec jobspec string. - * \param sat bool sat into which to return if jobspec is - * satisfiable. + * \param sat bool sat into which to return if jobspec is + * satisfiable. * \param ov Double into which to return performance overhead * in terms of elapse time needed to complete * the match operation. * \return 0 on success; -1 on error. */ -int reapi_cli_match_satisfy (reapi_cli_ctx_t *ctx, - const char *jobspec, bool *sat, double *ov); +int reapi_cli_match_satisfy (reapi_cli_ctx_t *ctx, const char *jobspec, bool *sat, double *ov); /*! Update the resource state with R. * @@ -128,8 +134,11 @@ int reapi_cli_match_satisfy (reapi_cli_ctx_t *ctx, * \return 0 on success; -1 on error. */ int reapi_cli_update_allocate (reapi_cli_ctx_t *ctx, - const uint64_t jobid, const char *R, int64_t *at, - double *ov, const char **R_out); + const uint64_t jobid, + const char *R, + int64_t *at, + double *ov, + const char **R_out); /*! Cancel the allocation or reservation corresponding to jobid. * @@ -138,8 +147,7 @@ int reapi_cli_update_allocate (reapi_cli_ctx_t *ctx, * \param noent_ok don't return an error on nonexistent jobid * \return 0 on success; -1 on error. */ -int reapi_cli_cancel (reapi_cli_ctx_t *ctx, - const uint64_t jobid, bool noent_ok); +int reapi_cli_cancel (reapi_cli_ctx_t *ctx, const uint64_t jobid, bool noent_ok); /*! Cancel the allocation or reservation corresponding to jobid. * @@ -153,7 +161,8 @@ int reapi_cli_cancel (reapi_cli_ctx_t *ctx, int reapi_cli_partial_cancel (reapi_cli_ctx_t *ctx, const uint64_t jobid, const char *R, - bool noent_ok, bool *full_removal); + bool noent_ok, + bool *full_removal); /*! Get the information on the allocation or reservation corresponding * to jobid. @@ -170,8 +179,11 @@ int reapi_cli_partial_cancel (reapi_cli_ctx_t *ctx, * the match operation. * \return 0 on success; -1 on error. */ -int reapi_cli_info (reapi_cli_ctx_t *ctx, const uint64_t jobid, - char **mode, bool *reserved, int64_t *at, +int reapi_cli_info (reapi_cli_ctx_t *ctx, + const uint64_t jobid, + char **mode, + bool *reserved, + int64_t *at, double *ov); /*! Get the performance information about the resource infrastructure. @@ -186,9 +198,14 @@ int reapi_cli_info (reapi_cli_ctx_t *ctx, const uint64_t jobid, * \param avg Avg match time * \return 0 on success; -1 on error. */ -int reapi_cli_stat (reapi_cli_ctx_t *ctx, int64_t *V, int64_t *E, - int64_t *J, double *load, - double *min, double *max, double *avg); +int reapi_cli_stat (reapi_cli_ctx_t *ctx, + int64_t *V, + int64_t *E, + int64_t *J, + double *load, + double *min, + double *max, + double *avg); /*! Get the reapi cli error message. * @@ -207,7 +224,7 @@ void reapi_cli_clear_err_msg (reapi_cli_ctx_t *ctx); } #endif -#endif // REAPI_CLI_H +#endif // REAPI_CLI_H /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/reapi/bindings/c/reapi_module.cpp b/resource/reapi/bindings/c/reapi_module.cpp index ccfb5c4b4..ea1064c03 100644 --- a/resource/reapi/bindings/c/reapi_module.cpp +++ b/resource/reapi/bindings/c/reapi_module.cpp @@ -48,9 +48,13 @@ extern "C" void reapi_module_destroy (reapi_module_ctx_t *ctx) } extern "C" int reapi_module_match (reapi_module_ctx_t *ctx, - match_op_t match_op, const char *jobspec, - const uint64_t jobid, bool *reserved, - char **R, int64_t *at, double *ov) + match_op_t match_op, + const char *jobspec, + const uint64_t jobid, + bool *reserved, + char **R, + int64_t *at, + double *ov) { int rc = -1; std::string R_buf = ""; @@ -60,12 +64,12 @@ extern "C" int reapi_module_match (reapi_module_ctx_t *ctx, errno = EINVAL; goto out; } - if ((rc = reapi_module_t::match_allocate (ctx->h, match_op, jobspec, - jobid, *reserved, - R_buf, *at, *ov)) < 0) { + if ((rc = reapi_module_t:: + match_allocate (ctx->h, match_op, jobspec, jobid, *reserved, R_buf, *at, *ov)) + < 0) { goto out; } - if ( !(R_buf_c = strdup (R_buf.c_str ()))) { + if (!(R_buf_c = strdup (R_buf.c_str ()))) { rc = -1; goto out; } @@ -76,33 +80,36 @@ extern "C" int reapi_module_match (reapi_module_ctx_t *ctx, } extern "C" int reapi_module_match_allocate (reapi_module_ctx_t *ctx, - bool orelse_reserve, const char *jobspec, - const uint64_t jobid, bool *reserved, - char **R, int64_t *at, double *ov) + bool orelse_reserve, + const char *jobspec, + const uint64_t jobid, + bool *reserved, + char **R, + int64_t *at, + double *ov) { - match_op_t match_op = orelse_reserve ? match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE - : match_op_t::MATCH_ALLOCATE; + match_op_t match_op = + orelse_reserve ? match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE : match_op_t::MATCH_ALLOCATE; - return reapi_module_match (ctx, match_op, jobspec, jobid, reserved, - R, at, ov); + return reapi_module_match (ctx, match_op, jobspec, jobid, reserved, R, at, ov); } -extern "C" int reapi_module_match_satisfy (reapi_module_ctx_t *ctx, - const char *jobspec, double *ov) +extern "C" int reapi_module_match_satisfy (reapi_module_ctx_t *ctx, const char *jobspec, double *ov) { match_op_t match_op = match_op_t::MATCH_SATISFIABILITY; - const uint64_t jobid =0; + const uint64_t jobid = 0; bool *reserved; - char **R; - int64_t *at; + char **R; + int64_t *at; - return reapi_module_match (ctx, match_op, jobspec, jobid, - reserved, R, at, ov); + return reapi_module_match (ctx, match_op, jobspec, jobid, reserved, R, at, ov); } extern "C" int reapi_module_update_allocate (reapi_module_ctx_t *ctx, - const uint64_t jobid, const char *R, - int64_t *at, double *ov, + const uint64_t jobid, + const char *R, + int64_t *at, + double *ov, const char **R_out) { int rc = -1; @@ -113,22 +120,19 @@ extern "C" int reapi_module_update_allocate (reapi_module_ctx_t *ctx, errno = EINVAL; goto out; } - if ( (rc = reapi_module_t::update_allocate (ctx->h, jobid, R, - *at, *ov, R_buf)) < 0) { + if ((rc = reapi_module_t::update_allocate (ctx->h, jobid, R, *at, *ov, R_buf)) < 0) { goto out; } - if ( !(R_buf_c = strdup (R_buf.c_str ()))) { + if (!(R_buf_c = strdup (R_buf.c_str ()))) { rc = -1; goto out; } *R_out = R_buf_c; out: return rc; - } -extern "C" int reapi_module_cancel (reapi_module_ctx_t *ctx, - const uint64_t jobid, bool noent_ok) +extern "C" int reapi_module_cancel (reapi_module_ctx_t *ctx, const uint64_t jobid, bool noent_ok) { if (!ctx || !ctx->h) { errno = EINVAL; @@ -139,7 +143,8 @@ extern "C" int reapi_module_cancel (reapi_module_ctx_t *ctx, extern "C" int reapi_module_partial_cancel (reapi_module_ctx_t *ctx, const uint64_t jobid, - const char *R, bool noent_ok, + const char *R, + bool noent_ok, bool &full_removal) { if (!ctx || !ctx->h || !R) { @@ -149,8 +154,11 @@ extern "C" int reapi_module_partial_cancel (reapi_module_ctx_t *ctx, return reapi_module_t::cancel (ctx->h, jobid, R, noent_ok, full_removal); } -extern "C" int reapi_module_info (reapi_module_ctx_t *ctx, const uint64_t jobid, - bool *reserved, int64_t *at, double *ov) +extern "C" int reapi_module_info (reapi_module_ctx_t *ctx, + const uint64_t jobid, + bool *reserved, + int64_t *at, + double *ov) { if (!ctx || !ctx->h) { errno = EINVAL; @@ -159,9 +167,14 @@ extern "C" int reapi_module_info (reapi_module_ctx_t *ctx, const uint64_t jobid, return reapi_module_t::info (ctx->h, jobid, *reserved, *at, *ov); } -extern "C" int reapi_module_stat (reapi_module_ctx_t *ctx, int64_t *V, - int64_t *E, int64_t *J, double *load, - double *min, double *max, double *avg) +extern "C" int reapi_module_stat (reapi_module_ctx_t *ctx, + int64_t *V, + int64_t *E, + int64_t *J, + double *load, + double *min, + double *max, + double *avg) { if (!ctx || !ctx->h) { errno = EINVAL; diff --git a/resource/reapi/bindings/c/reapi_module.h b/resource/reapi/bindings/c/reapi_module.h index 2e6737354..84fa2f0bc 100644 --- a/resource/reapi/bindings/c/reapi_module.h +++ b/resource/reapi/bindings/c/reapi_module.h @@ -40,13 +40,13 @@ void reapi_module_destroy (reapi_module_ctx_t *ctx); * \param ctx reapi_module_ctx_t context object * \param match_op match_op_t: set to specify the specific match option * from 1 of 4 choices: - * MATCH_ALLOCATE: try to allocate now and fail if resources - * aren't available. + * MATCH_ALLOCATE: try to allocate now and fail if resources + * aren't available. * MATCH_ALLOCATE_ORELSE_RESERVE : Try to allocate and reserve * if resources aren't available now. - * MATCH_SATISFIABILITY: Do a satisfiablity check and do not + * MATCH_SATISFIABILITY: Do a satisfiablity check and do not * allocate. - * MATCH_ALLOCATE_W_SATISFIABILITY: try to allocate and run + * MATCH_ALLOCATE_W_SATISFIABILITY: try to allocate and run * satisfiability check if resources are not available. * \param jobspec jobspec string. * \param jobid jobid of the uint64_t type. @@ -61,9 +61,14 @@ void reapi_module_destroy (reapi_module_ctx_t *ctx); * the match operation. * \return 0 on success; -1 on error. */ -int reapi_module_match (reapi_module_ctx_t *ctx, match_op_t match_op, - const char *jobspec, const uint64_t jobid, - bool *reserved, char **R, int64_t *at, double *ov); +int reapi_module_match (reapi_module_ctx_t *ctx, + match_op_t match_op, + const char *jobspec, + const uint64_t jobid, + bool *reserved, + char **R, + int64_t *at, + double *ov); /*! Match a jobspec to the "best" resources and either allocate * orelse reserve them. The best resources are determined by @@ -86,12 +91,16 @@ int reapi_module_match (reapi_module_ctx_t *ctx, match_op_t match_op, * the match operation. * \return 0 on success; -1 on error. */ -int reapi_module_match_allocate (reapi_module_ctx_t *ctx, bool orelse_reserve, - const char *jobspec, const uint64_t jobid, +int reapi_module_match_allocate (reapi_module_ctx_t *ctx, + bool orelse_reserve, + const char *jobspec, + const uint64_t jobid, bool *reserved, - char **R, int64_t *at, double *ov); + char **R, + int64_t *at, + double *ov); -/*! Run Satisfiability check for jobspec. +/*! Run Satisfiability check for jobspec. * * \param ctx reapi_module_ctx_t context object * \param jobspec jobspec string. @@ -100,8 +109,7 @@ int reapi_module_match_allocate (reapi_module_ctx_t *ctx, bool orelse_reserve, * the match operation. * \return 0 on success; -1 on error. */ -int reapi_module_match_satisfy (reapi_module_ctx_t *ctx, - const char *jobspec, double *ov); +int reapi_module_match_satisfy (reapi_module_ctx_t *ctx, const char *jobspec, double *ov); /*! Update the resource state with R. * @@ -116,8 +124,11 @@ int reapi_module_match_satisfy (reapi_module_ctx_t *ctx, * \return 0 on success; -1 on error. */ int reapi_module_update_allocate (reapi_module_ctx_t *ctx, - const uint64_t jobid, const char *R, - int64_t *at, double *ov, const char **R_out); + const uint64_t jobid, + const char *R, + int64_t *at, + double *ov, + const char **R_out); /*! Cancel the allocation or reservation corresponding to jobid. * @@ -126,8 +137,7 @@ int reapi_module_update_allocate (reapi_module_ctx_t *ctx, * \param noent_ok don't return an error on nonexistent jobid * \return 0 on success; -1 on error. */ -int reapi_module_cancel (reapi_module_ctx_t *ctx, - const uint64_t jobid, bool noent_ok); +int reapi_module_cancel (reapi_module_ctx_t *ctx, const uint64_t jobid, bool noent_ok); /*! Cancel the allocation or reservation corresponding to jobid. * @@ -141,7 +151,8 @@ int reapi_module_cancel (reapi_module_ctx_t *ctx, int reapi_module_partial_cancel (reapi_module_ctx_t *ctx, const uint64_t jobid, const char *R, - bool noent_ok, bool &full_removal); + bool noent_ok, + bool &full_removal); /*! Get the information on the allocation or reservation corresponding * to jobid. @@ -157,8 +168,11 @@ int reapi_module_partial_cancel (reapi_module_ctx_t *ctx, * the match operation. * \return 0 on success; -1 on error. */ -int reapi_module_info (reapi_module_ctx_t *ctx, const uint64_t jobid, - bool *reserved, int64_t *at, double *ov); +int reapi_module_info (reapi_module_ctx_t *ctx, + const uint64_t jobid, + bool *reserved, + int64_t *at, + double *ov); /*! Get the performance information about the resource infrastructure. * @@ -172,9 +186,14 @@ int reapi_module_info (reapi_module_ctx_t *ctx, const uint64_t jobid, * \param avg Avg match time * \return 0 on success; -1 on error. */ -int reapi_module_stat (reapi_module_ctx_t *ctx, int64_t *V, int64_t *E, - int64_t *J, double *load, - double *min, double *max, double *avg); +int reapi_module_stat (reapi_module_ctx_t *ctx, + int64_t *V, + int64_t *E, + int64_t *J, + double *load, + double *min, + double *max, + double *avg); /*! Set the opaque handle to the reapi module context. * @@ -198,7 +217,7 @@ void *reapi_module_get_handle (reapi_module_ctx_t *ctx); } #endif -#endif // REAPI_MODULE_H +#endif // REAPI_MODULE_H /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/schema/color.cpp b/resource/schema/color.cpp index 97b9adfc2..644e60e8e 100644 --- a/resource/schema/color.cpp +++ b/resource/schema/color.cpp @@ -21,47 +21,41 @@ namespace resource_model { void color_t::reset () { - m_color_base += static_cast(color_offset_t::NEW_BASE); + m_color_base += static_cast (color_offset_t::NEW_BASE); } bool color_t::is_white (uint64_t c) const { - return c <= (m_color_base - + static_cast(color_offset_t::WHITE_OFFSET)); + return c <= (m_color_base + static_cast (color_offset_t::WHITE_OFFSET)); } bool color_t::is_gray (uint64_t c) const { - return c == (m_color_base - + static_cast(color_offset_t::GRAY_OFFSET)); + return c == (m_color_base + static_cast (color_offset_t::GRAY_OFFSET)); } bool color_t::is_black (uint64_t c) const { - return c == (m_color_base - + static_cast(color_offset_t::BLACK_OFFSET)); + return c == (m_color_base + static_cast (color_offset_t::BLACK_OFFSET)); } uint64_t color_t::white () const { - return m_color_base - + static_cast(color_offset_t::WHITE_OFFSET); + return m_color_base + static_cast (color_offset_t::WHITE_OFFSET); } uint64_t color_t::gray () const { - return m_color_base - + static_cast(color_offset_t::GRAY_OFFSET); + return m_color_base + static_cast (color_offset_t::GRAY_OFFSET); } uint64_t color_t::black () const { - return m_color_base - + static_cast(color_offset_t::BLACK_OFFSET); + return m_color_base + static_cast (color_offset_t::BLACK_OFFSET); } -} // resource_model -} // Flux +} // namespace resource_model +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/schema/color.hpp b/resource/schema/color.hpp index 3f14972cc..545f24599 100644 --- a/resource/schema/color.hpp +++ b/resource/schema/color.hpp @@ -17,7 +17,7 @@ namespace Flux { namespace resource_model { class color_t { -public: + public: enum class color_offset_t : uint64_t { WHITE_OFFSET = 0, GRAY_OFFSET = 1, @@ -37,14 +37,14 @@ class color_t { uint64_t gray () const; uint64_t black () const; -private: + private: uint64_t m_color_base = 0; }; -} // resource_model -} // Flux +} // namespace resource_model +} // namespace Flux -#endif // COLOR_H +#endif // COLOR_H /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/schema/data_std.hpp b/resource/schema/data_std.hpp index c0bc32b07..53a248ea7 100644 --- a/resource/schema/data_std.hpp +++ b/resource/schema/data_std.hpp @@ -23,17 +23,17 @@ namespace resource_model { // job allocation/reservation -- subtract 1 from x_checker planner for the // scheduled span. Any vertex with less than X_CHECKER_NJOBS available in its // x_checker cannot be exclusively allocated or reserved. -const char * const X_CHECKER_JOBS_STR = "jobs"; +const char *const X_CHECKER_JOBS_STR = "jobs"; const int64_t X_CHECKER_NJOBS = 0x40000000; using subsystem_t = std::string; using multi_subsystems_t = std::map; using multi_subsystemsS = std::map>; -} // Flux -} // Flux::resource_model +} // namespace resource_model +} // namespace Flux -#endif // DATA_STD_H +#endif // DATA_STD_H /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/schema/ephemeral.cpp b/resource/schema/ephemeral.cpp index 0b25e90ea..c1eed64ec 100644 --- a/resource/schema/ephemeral.cpp +++ b/resource/schema/ephemeral.cpp @@ -19,16 +19,14 @@ extern "C" { namespace Flux { namespace resource_model { -int ephemeral_t::insert (uint64_t epoch, - const std::string &key, - const std::string &value) +int ephemeral_t::insert (uint64_t epoch, const std::string &key, const std::string &value) { int rc = 0; try { check_and_clear_if_stale (epoch); m_epoch = epoch; - auto ret = m_store.insert(std::make_pair (key, value)); + auto ret = m_store.insert (std::make_pair (key, value)); if (!ret.second) { errno = EEXIST; rc = -1; @@ -55,20 +53,18 @@ boost::optional ephemeral_t::get (uint64_t epoch, const std::string auto value = (*it).second; return value; - } catch (const std::out_of_range& oor) { + } catch (const std::out_of_range &oor) { return boost::none; } } - - -const std::map& ephemeral_t::to_map (uint64_t epoch) +const std::map &ephemeral_t::to_map (uint64_t epoch) { check_and_clear_if_stale (epoch); return this->to_map (); } -const std::map& ephemeral_t::to_map () const +const std::map &ephemeral_t::to_map () const { return m_store; } @@ -83,15 +79,13 @@ bool ephemeral_t::check_and_clear_if_stale (uint64_t epoch) return false; } - void ephemeral_t::clear () { m_store.clear (); } - -} // resource_model -} // Flux +} // namespace resource_model +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/schema/ephemeral.hpp b/resource/schema/ephemeral.hpp index 7efe9ccac..ccbb59505 100644 --- a/resource/schema/ephemeral.hpp +++ b/resource/schema/ephemeral.hpp @@ -19,26 +19,24 @@ namespace Flux { namespace resource_model { class ephemeral_t { -public: - int insert (uint64_t epoch, - const std::string &key, - const std::string &value); + public: + int insert (uint64_t epoch, const std::string &key, const std::string &value); boost::optional get (uint64_t epoch, const std::string &key); - const std::map& to_map (uint64_t epoch); - const std::map& to_map () const; + const std::map &to_map (uint64_t epoch); + const std::map &to_map () const; bool check_and_clear_if_stale (uint64_t epoch); void clear (); -private: + private: std::map m_store; // Need to initialize; Valgrind reports errors. uint64_t m_epoch = 0; }; -} // resource_model -} // Flux +} // namespace resource_model +} // namespace Flux -#endif // EPHEMERAL_H +#endif // EPHEMERAL_H /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/schema/infra_data.cpp b/resource/schema/infra_data.cpp index 089ac49f5..794cfa807 100644 --- a/resource/schema/infra_data.cpp +++ b/resource/schema/infra_data.cpp @@ -20,8 +20,6 @@ extern "C" { namespace Flux { namespace resource_model { - - //////////////////////////////////////////////////////////////////////////////// // Public Methods on the Data Belonging to the Scheduler Infrastructure //////////////////////////////////////////////////////////////////////////////// @@ -41,18 +39,15 @@ infra_base_t &infra_base_t::operator= (const infra_base_t &o) infra_base_t::~infra_base_t () { - } - - //////////////////////////////////////////////////////////////////////////////// // Public Methods on Infrastructure Data for Resource Pool //////////////////////////////////////////////////////////////////////////////// pool_infra_t::pool_infra_t () = default; -pool_infra_t::pool_infra_t (const pool_infra_t &o): infra_base_t (o) +pool_infra_t::pool_infra_t (const pool_infra_t &o) : infra_base_t (o) { ephemeral = o.ephemeral; colors = o.colors; @@ -156,15 +151,13 @@ void pool_infra_t::scrub () ephemeral.clear (); } - - //////////////////////////////////////////////////////////////////////////////// // Public Methods on Infrastructure Data for Resource Relation //////////////////////////////////////////////////////////////////////////////// relation_infra_t::relation_infra_t () = default; -relation_infra_t::relation_infra_t (const relation_infra_t &o): infra_base_t (o) +relation_infra_t::relation_infra_t (const relation_infra_t &o) : infra_base_t (o) { m_needs = o.m_needs; m_trav_token = o.m_trav_token; @@ -182,7 +175,6 @@ relation_infra_t &relation_infra_t::operator= (const relation_infra_t &o) relation_infra_t::~relation_infra_t () { - } void relation_infra_t::scrub () @@ -192,8 +184,7 @@ void relation_infra_t::scrub () m_exclusive = 0; } -void relation_infra_t::set_for_trav_update (uint64_t needs, int exclusive, - uint64_t trav_token) +void relation_infra_t::set_for_trav_update (uint64_t needs, int exclusive, uint64_t trav_token) { m_needs = needs; m_trav_token = trav_token; @@ -225,8 +216,8 @@ void relation_infra_t::set_weight (uint64_t weight) m_weight = weight; } -} // resource_model -} // Flux +} // namespace resource_model +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/schema/infra_data.hpp b/resource/schema/infra_data.hpp index f61bc7d4b..57d34ce4d 100644 --- a/resource/schema/infra_data.hpp +++ b/resource/schema/infra_data.hpp @@ -52,15 +52,14 @@ struct pool_infra_t : public infra_base_t { }; class relation_infra_t : public infra_base_t { -public: + public: relation_infra_t (); relation_infra_t (const relation_infra_t &o); relation_infra_t &operator= (const relation_infra_t &o); virtual ~relation_infra_t (); virtual void scrub (); - void set_for_trav_update (uint64_t needs, int exclusive, - uint64_t trav_token); + void set_for_trav_update (uint64_t needs, int exclusive, uint64_t trav_token); uint64_t get_needs () const; int get_exclusive () const; @@ -68,17 +67,17 @@ class relation_infra_t : public infra_base_t { uint64_t get_weight () const; void set_weight (uint64_t); -private: + private: uint64_t m_needs = 0; uint64_t m_trav_token = 0; uint64_t m_weight = std::numeric_limits::max (); int m_exclusive = 0; }; -} // Flux::resource_model -} // Flux +} // namespace resource_model +} // namespace Flux -#endif // INFRA_DATA_HPP +#endif // INFRA_DATA_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/schema/perf_data.cpp b/resource/schema/perf_data.cpp index ac14cd1a4..156f55fb6 100644 --- a/resource/schema/perf_data.cpp +++ b/resource/schema/perf_data.cpp @@ -21,8 +21,8 @@ namespace resource_model { struct match_perf_t perf; -} // Flux::resource_model -} // Flux +} // namespace resource_model +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/schema/perf_data.hpp b/resource/schema/perf_data.hpp index 4f8aeab38..b53b44d63 100644 --- a/resource/schema/perf_data.hpp +++ b/resource/schema/perf_data.hpp @@ -17,13 +17,14 @@ namespace Flux { namespace resource_model { struct perf_stats { - void update_stats (double elapsed, int64_t jobid, int64_t match_iter_ct) { + void update_stats (double elapsed, int64_t jobid, int64_t match_iter_ct) + { /* Update using Welford's algorithm */ double delta = 0.0; double delta2 = 0.0; njobs++; njobs_reset++; - min = (min > elapsed)? elapsed : min; + min = (min > elapsed) ? elapsed : min; if (max < elapsed) { max = elapsed; max_match_jobid = jobid; @@ -37,25 +38,25 @@ struct perf_stats { } /* Performance data */ - uint64_t njobs = 0; /* Total match count */ - uint64_t njobs_reset = 0; /* Jobs since match count reset */ - int64_t max_match_jobid = 0; /* jobid corresponding to max match time */ + uint64_t njobs = 0; /* Total match count */ + uint64_t njobs_reset = 0; /* Jobs since match count reset */ + int64_t max_match_jobid = 0; /* jobid corresponding to max match time */ int64_t match_iter_count = 0; double min = std::numeric_limits::max (); /* Min match time */ - double max = 0.0; /* Max match time */ - double accum = 0.0; /* Accumulated match time for resource query */ - double avg = 0.0; /* Average match time */ - double M2 = 0.0; /* Welford's algorithm */ + double max = 0.0; /* Max match time */ + double accum = 0.0; /* Accumulated match time for resource query */ + double avg = 0.0; /* Average match time */ + double M2 = 0.0; /* Welford's algorithm */ }; struct match_perf_t { - double load = 0.0; /* Graph load time */ + double load = 0.0; /* Graph load time */ /* Graph uptime in seconds */ - std::chrono::time_point graph_uptime - = std::chrono::system_clock::now (); + std::chrono::time_point graph_uptime = + std::chrono::system_clock::now (); /* Time since stats were last cleared */ - std::chrono::time_point time_of_last_reset - = std::chrono::system_clock::now (); + std::chrono::time_point time_of_last_reset = + std::chrono::system_clock::now (); perf_stats succeeded; perf_stats failed; int64_t tmp_iter_count = -1; @@ -63,10 +64,10 @@ struct match_perf_t { extern struct match_perf_t perf; -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // PERF_DATA_HPP +#endif // PERF_DATA_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/schema/resource_base.hpp b/resource/schema/resource_base.hpp index 68e0ac7e1..c0b73c79f 100644 --- a/resource/schema/resource_base.hpp +++ b/resource/schema/resource_base.hpp @@ -28,10 +28,10 @@ struct resource_t { int rank = -1; }; -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // RESOURCE_BASE_HPP +#endif // RESOURCE_BASE_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/schema/resource_data.cpp b/resource/schema/resource_data.cpp index 1636231a6..305c206f6 100644 --- a/resource/schema/resource_data.cpp +++ b/resource/schema/resource_data.cpp @@ -19,15 +19,12 @@ extern "C" { namespace Flux { namespace resource_model { - - //////////////////////////////////////////////////////////////////////////////// // Resource Pool Method Definitions //////////////////////////////////////////////////////////////////////////////// resource_pool_t::resource_pool_t () { - } resource_pool_t::resource_pool_t (const resource_pool_t &o) @@ -67,18 +64,14 @@ resource_pool_t &resource_pool_t::operator= (const resource_pool_t &o) resource_pool_t::~resource_pool_t () { - } - - //////////////////////////////////////////////////////////////////////////////// // Resource Relation Method Definitions //////////////////////////////////////////////////////////////////////////////// resource_relation_t::resource_relation_t () { - } resource_relation_t::resource_relation_t (const resource_relation_t &o) @@ -87,8 +80,7 @@ resource_relation_t::resource_relation_t (const resource_relation_t &o) idata = o.idata; } -resource_relation_t &resource_relation_t::operator= ( - const resource_relation_t &o) +resource_relation_t &resource_relation_t::operator= (const resource_relation_t &o) { name = o.name; idata = o.idata; @@ -97,33 +89,31 @@ resource_relation_t &resource_relation_t::operator= ( resource_relation_t::~resource_relation_t () { - } -const resource_pool_t::string_to_status resource_pool_t::str_to_status = - { { "up", resource_pool_t::status_t::UP }, - { "down", resource_pool_t::status_t::DOWN } }; +const resource_pool_t::string_to_status resource_pool_t::str_to_status = + {{"up", resource_pool_t::status_t::UP}, {"down", resource_pool_t::status_t::DOWN}}; const std::string resource_pool_t::status_to_str (status_t s) { std::string str; switch (s) { - case status_t::UP: - str = "UP"; - break; - case status_t::DOWN: - str = "DOWN"; - break; - default: - str = ""; - errno = EINVAL; - break; + case status_t::UP: + str = "UP"; + break; + case status_t::DOWN: + str = "DOWN"; + break; + default: + str = ""; + errno = EINVAL; + break; } return str; } -} // Flux::resource_model -} // Flux +} // namespace resource_model +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/schema/resource_data.hpp b/resource/schema/resource_data.hpp index 5b529c2c1..da68d4552 100644 --- a/resource/schema/resource_data.hpp +++ b/resource/schema/resource_data.hpp @@ -34,10 +34,7 @@ struct resource_pool_t : public resource_t { resource_pool_t &operator= (const resource_pool_t &o); ~resource_pool_t (); - enum class status_t : int { - UP = 0, - DOWN = 1 - }; + enum class status_t : int { UP = 0, DOWN = 1 }; typedef std::unordered_map string_to_status; static const string_to_status str_to_status; @@ -49,8 +46,8 @@ struct resource_pool_t : public resource_t { unsigned int size = 0; std::string unit; - schedule_t schedule; //!< schedule data - pool_infra_t idata; //!< scheduling infrastructure data + schedule_t schedule; //!< schedule data + pool_infra_t idata; //!< scheduling infrastructure data status_t status = status_t::UP; }; @@ -66,14 +63,14 @@ struct resource_relation_t { resource_relation_t &operator= (const resource_relation_t &o); ~resource_relation_t (); - std::map name; //!< subsystem: relationship - relation_infra_t idata; //!< scheduling infrastructure data + std::map name; //!< subsystem: relationship + relation_infra_t idata; //!< scheduling infrastructure data }; -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // RESOURCE_DATA_HPP +#endif // RESOURCE_DATA_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/schema/resource_graph.hpp b/resource/schema/resource_graph.hpp index a8e929b66..4ef9d6b0d 100644 --- a/resource/schema/resource_graph.hpp +++ b/resource/schema/resource_graph.hpp @@ -21,11 +21,14 @@ namespace Flux { namespace resource_model { -enum class emit_format_t { GRAPHVIZ_DOT, GRAPH_ML, }; +enum class emit_format_t { + GRAPHVIZ_DOT, + GRAPH_ML, +}; using pinfra_t = pool_infra_t resource_pool_t::*; -using pname_t = std::string resource_t::*; -using rname_t = std::string resource_relation_t::*; +using pname_t = std::string resource_t::*; +using rname_t = std::string resource_relation_t::*; using rinfra_t = relation_infra_t resource_relation_t::*; using resource_graph_t = boost::adjacency_list::out_edge_ite template class label_writer_t { -public: - label_writer_t (name_map &in_map): m (in_map) { } - void operator()(std::ostream &out, const graph_entity ent) const { + public: + label_writer_t (name_map &in_map) : m (in_map) + { + } + void operator() (std::ostream &out, const graph_entity ent) const + { out << "[label=\"" << m[ent] << "\"]"; } -private: + + private: name_map m; }; class edg_label_writer_t { -public: - edg_label_writer_t (f_edg_infra_map_t &idata, subsystem_t &s) - : m_infra (idata), m_s (s) {} - void operator()(std::ostream& out, const edg_t &e) const { + public: + edg_label_writer_t (f_edg_infra_map_t &idata, subsystem_t &s) : m_infra (idata), m_s (s) + { + } + void operator() (std::ostream &out, const edg_t &e) const + { multi_subsystems_t::iterator i = m_infra[e].member_of.find (m_s); if (i != m_infra[e].member_of.end ()) { out << "[label=\"" << i->second << "\"]"; @@ -74,15 +83,16 @@ class edg_label_writer_t { out << "[label=\"" << i->second << "\"]"; } } -private: + + private: f_edg_infra_map_t m_infra; subsystem_t m_s; }; -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // RESOURCE_GRAPH_HPP +#endif // RESOURCE_GRAPH_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/schema/sched_data.cpp b/resource/schema/sched_data.cpp index bea20482f..e799a0965 100644 --- a/resource/schema/sched_data.cpp +++ b/resource/schema/sched_data.cpp @@ -47,7 +47,7 @@ schedule_t &schedule_t::operator= (const schedule_t &o) reservations.clear (); allocations = o.allocations; reservations = o.reservations; - + if (plans) { if (o.plans) { planner_assign (plans, o.plans); @@ -82,8 +82,8 @@ schedule_t::~schedule_t () planner_destroy (&plans); } -} // resource_model -} // Flux +} // namespace resource_model +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/schema/sched_data.hpp b/resource/schema/sched_data.hpp index 2276316db..3c4ecd0ba 100644 --- a/resource/schema/sched_data.hpp +++ b/resource/schema/sched_data.hpp @@ -32,8 +32,7 @@ struct schedule_t { planner_t *plans = nullptr; }; -} // Flux::resource_model -} // Flux - -#endif // SCHED_DATA_H +} // namespace resource_model +} // namespace Flux +#endif // SCHED_DATA_H diff --git a/resource/schema/test/schema_test01.cpp b/resource/schema/test/schema_test01.cpp index c5bb6d380..6ec6fce49 100644 --- a/resource/schema/test/schema_test01.cpp +++ b/resource/schema/test/schema_test01.cpp @@ -9,7 +9,7 @@ \*****************************************************************************/ #if HAVE_CONFIG_H -# include +#include #endif #include #include @@ -50,7 +50,7 @@ static int test_constructors_and_overload () sched3 = new schedule_t (*sched1); bo = (bo || !(*sched3 == *sched1)); - ok (!bo, "copied schedule_t equal to rhs schedule_t"); + ok (!bo, "copied schedule_t equal to rhs schedule_t"); sched4 = new schedule_t (); *sched4 = *sched1; @@ -81,7 +81,6 @@ static int test_constructors_and_overload () return 0; } - int main (int argc, char *argv[]) { plan (7); diff --git a/resource/schema/test/schema_test02.cpp b/resource/schema/test/schema_test02.cpp index 37f0ec7d6..9bf83ec82 100644 --- a/resource/schema/test/schema_test02.cpp +++ b/resource/schema/test/schema_test02.cpp @@ -9,7 +9,7 @@ \*****************************************************************************/ #if HAVE_CONFIG_H -# include +#include #endif #include #include @@ -43,12 +43,12 @@ static int test_constructors_and_overload () infra1->colors["network"] = 1; infra1->x_checker = planner_new (0, INT64_MAX, resource_total, resource_type); infra1->subplans["containment"] = - planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); + planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); infra1->subplans["network"] = - planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); + planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); infra2 = new pool_infra_t (); - + bo = (bo || (*infra1 == *infra2)); ok (!bo, "initialized pool_infra_t not equal to uninitialized pool_infra_t"); @@ -59,15 +59,15 @@ static int test_constructors_and_overload () infra2->colors["network"] = 1; infra2->x_checker = planner_new (0, INT64_MAX, resource_total, resource_type); infra2->subplans["containment"] = - planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); + planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); infra2->subplans["network"] = - planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); + planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); bo = (bo || !(*infra1 == *infra2)); ok (!bo, "initialized pool_infra_t equal to identically initialized pool_infra_t"); infra3 = new pool_infra_t (*infra1); bo = (bo || !(*infra3 == *infra1)); - ok (!bo, "copied pool_infra_t equal to rhs pool_infra_t"); + ok (!bo, "copied pool_infra_t equal to rhs pool_infra_t"); infra4 = new pool_infra_t (); *infra4 = *infra1; @@ -86,11 +86,12 @@ static int test_constructors_and_overload () infra5->colors["network"] = 1; infra5->x_checker = planner_new (1, INT64_MAX, resource_total, resource_type); infra5->subplans["containment"] = - planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); + planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); infra5->subplans["network"] = - planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); + planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); bo = (bo || (*infra5 == *infra1)); - ok (!bo, "pool_infra_t initialized with different x_checker not equal to original pool_infra_t"); + ok (!bo, + "pool_infra_t initialized with different x_checker not equal to original pool_infra_t"); infra6 = new pool_infra_t (); infra6->tags[0] = 0; @@ -100,9 +101,9 @@ static int test_constructors_and_overload () infra6->colors["storage"] = 1; infra6->x_checker = planner_new (0, INT64_MAX, resource_total, resource_type); infra6->subplans["containment"] = - planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); + planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); infra6->subplans["network"] = - planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); + planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); bo = (bo || (*infra6 == *infra1)); ok (!bo, "pool_infra_t initialized with different colors not equal to original pool_infra_t"); @@ -114,11 +115,13 @@ static int test_constructors_and_overload () infra7->colors["network"] = 1; infra7->x_checker = planner_new (0, INT64_MAX, resource_total, resource_type); infra7->subplans["containment"] = - planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); + planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); infra7->subplans["storage"] = - planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); + planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); bo = (bo || (*infra7 == *infra1)); - ok (!bo, "pool_infra_t initialized with different subplan systems not equal to original pool_infra_t"); + ok (!bo, + "pool_infra_t initialized with different subplan systems not equal to original " + "pool_infra_t"); infra8 = new pool_infra_t (); infra8->tags[0] = 0; @@ -128,11 +131,13 @@ static int test_constructors_and_overload () infra8->colors["network"] = 1; infra8->x_checker = planner_new (0, INT64_MAX, resource_total, resource_type); infra8->subplans["containment"] = - planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); + planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); infra8->subplans["network"] = - planner_multi_new (1, INT64_MAX, resource_totals, resource_types, len); + planner_multi_new (1, INT64_MAX, resource_totals, resource_types, len); bo = (bo || (*infra8 == *infra1)); - ok (!bo, "pool_infra_t initialized with different subplan planner_multis not equal to original pool_infra_t"); + ok (!bo, + "pool_infra_t initialized with different subplan planner_multis not equal to original " + "pool_infra_t"); infra9 = new pool_infra_t (); infra9->tags[0] = 0; @@ -142,9 +147,11 @@ static int test_constructors_and_overload () infra9->colors["network"] = 1; infra9->x_checker = planner_new (0, INT64_MAX, resource_total, resource_type); infra9->subplans["containment"] = - planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); + planner_multi_new (0, INT64_MAX, resource_totals, resource_types, len); bo = (bo || (*infra9 == *infra1)); - ok (!bo, "pool_infra_t initialized with different subplan planner_multis len not equal to original pool_infra_t"); + ok (!bo, + "pool_infra_t initialized with different subplan planner_multis len not equal to original " + "pool_infra_t"); *infra9 = *infra1; bo = (bo || !(*infra9 == *infra1)); @@ -168,7 +175,6 @@ static int test_constructors_and_overload () return 0; } - int main (int argc, char *argv[]) { plan (12); diff --git a/resource/store/resource_graph_store.cpp b/resource/store/resource_graph_store.cpp index c26f92708..fcc23b42d 100644 --- a/resource/store/resource_graph_store.cpp +++ b/resource/store/resource_graph_store.cpp @@ -20,15 +20,13 @@ extern "C" { using namespace Flux; using namespace Flux::resource_model; -void resource_graph_metadata_t::set_graph_duration ( - graph_duration_t &g_duration) +void resource_graph_metadata_t::set_graph_duration (graph_duration_t &g_duration) { - if ( (g_duration.graph_start == std::chrono::system_clock::from_time_t (0)) - && (g_duration.graph_end - == std::chrono::system_clock::from_time_t (0))) { + if ((g_duration.graph_start == std::chrono::system_clock::from_time_t (0)) + && (g_duration.graph_end == std::chrono::system_clock::from_time_t (0))) { graph_duration.graph_start = std::chrono::system_clock::now (); - graph_duration.graph_end = graph_duration.graph_start + - std::chrono::seconds (detail::SYSTEM_MAX_DURATION); + graph_duration.graph_end = + graph_duration.graph_start + std::chrono::seconds (detail::SYSTEM_MAX_DURATION); } else { graph_duration.graph_start = g_duration.graph_start; graph_duration.graph_end = g_duration.graph_end; @@ -57,7 +55,7 @@ void resource_graph_metadata_t::initialize_node_stats (resource_graph_t const &g bool resource_graph_db_t::known_subsystem (const std::string &s) { - return (metadata.roots.find (s) != metadata.roots.end ())? true : false; + return (metadata.roots.find (s) != metadata.roots.end ()) ? true : false; } int resource_graph_db_t::load (const std::string &str, @@ -71,7 +69,8 @@ int resource_graph_db_t::load (const std::string &str, int resource_graph_db_t::load (const std::string &str, std::shared_ptr &reader, - vtx_t &vtx_at, int rank) + vtx_t &vtx_at, + int rank) { int rc = reader->unpack_at (resource_graph, metadata, vtx_at, str, rank); metadata.initialize_node_stats (resource_graph); diff --git a/resource/store/resource_graph_store.hpp b/resource/store/resource_graph_store.hpp index 7caad1418..7e6b5b023 100644 --- a/resource/store/resource_graph_store.hpp +++ b/resource/store/resource_graph_store.hpp @@ -25,7 +25,7 @@ struct resource_graph_db_t; struct graph_duration_t { std::chrono::time_point graph_start = - std::chrono::system_clock::from_time_t (0); + std::chrono::system_clock::from_time_t (0); std::chrono::time_point graph_end = std::chrono::system_clock::from_time_t (detail::SYSTEM_MAX_DURATION); }; @@ -36,15 +36,16 @@ struct graph_duration_t { struct resource_graph_metadata_t { std::map roots; std::map v_rt_edges; - std::map> by_type; - std::map> by_name; - std::map> by_rank; + std::map> by_type; + std::map> by_name; + std::map> by_rank; std::map> by_path; // by_outedges enables graph traversing order to edge "weight" // E.g., the more available resources an edge point to, the heavier - std::map, edg_t, - std::greater>>> by_outedges; + std::map< + vtx_t, + std::map, edg_t, std::greater>>> + by_outedges; graph_duration_t graph_duration; int64_t nodes_up = 0; @@ -76,7 +77,7 @@ struct resource_graph_db_t { * \param rank assign this rank to all the newly created resource vertices * \return 0 on success; non-zero integer on an error * ENOMEM: out of memory - * EINVAL: invalid input or operation (e.g. + * EINVAL: invalid input or operation (e.g. * hwloc version or json string load error) * EPROTO: str violates the schema */ @@ -92,19 +93,20 @@ struct resource_graph_db_t { * \param rank assign this rank to all the newly created resource vertices * \return 0 on success; non-zero integer on an error * ENOMEM: out of memory - * EINVAL: invalid input or operation (e.g. + * EINVAL: invalid input or operation (e.g. * hwloc version or json string load error) * EPROTO: str violates the schema */ int load (const std::string &str, std::shared_ptr &reader, - vtx_t &vtx_at, int rank = -1); + vtx_t &vtx_at, + int rank = -1); }; -} -} +} // namespace resource_model +} // namespace Flux -#endif // RESOURCE_GRAPH_STORE_HPP +#endif // RESOURCE_GRAPH_STORE_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/traversers/dfu.cpp b/resource/traversers/dfu.cpp index 8f9e3a606..1afa34c72 100644 --- a/resource/traversers/dfu.cpp +++ b/resource/traversers/dfu.cpp @@ -26,7 +26,6 @@ using namespace Flux::Jobspec; // Global perf struct from schema extern struct match_perf_t perf; - //////////////////////////////////////////////////////////////////////////////// // DFU Traverser Private API Definitions //////////////////////////////////////////////////////////////////////////////// @@ -136,12 +135,14 @@ int dfu_traverser_t::request_feasible (detail::jobmeta_t const &meta, } int dfu_traverser_t::schedule (Jobspec::Jobspec &jobspec, - detail::jobmeta_t &meta, bool x, match_op_t op, + detail::jobmeta_t &meta, + bool x, + match_op_t op, vtx_t root, std::unordered_map &dfv) { int64_t t = 0; - int64_t sched_iters = 1; // Track the schedule iterations in perf stats + int64_t sched_iters = 1; // Track the schedule iterations in perf stats int rc = -1; size_t len = 0; std::vector agg; @@ -162,70 +163,69 @@ int dfu_traverser_t::schedule (Jobspec::Jobspec &jobspec, /* Currently no resources/devices available... Do more... */ switch (op) { - case match_op_t::MATCH_ALLOCATE_W_SATISFIABILITY: { - /* With satisfiability check */ - errno = EBUSY; - meta.alloc_type = jobmeta_t::alloc_type_t::AT_SATISFIABILITY; - p = (*get_graph ())[root].idata.subplans.at (dom); - meta.at = planner_multi_base_time (p) - + planner_multi_duration (p) - meta.duration - 1; - detail::dfu_impl_t::count_relevant_types (p, dfv, agg); - if (detail::dfu_impl_t::select (jobspec, root, meta, x) < 0) { - errno = (errno == EBUSY)? ENODEV : errno; - detail::dfu_impl_t::update (); - } - m_total_preorder += detail::dfu_impl_t::get_preorder_count (); - m_total_postorder += detail::dfu_impl_t::get_postorder_count (); - // increment match traversal loop count - ++sched_iters; - break; - } - case match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE: { - /* Or else reserve */ - errno = 0; - meta.alloc_type = jobmeta_t::alloc_type_t::AT_ALLOC_ORELSE_RESERVE; - t = meta.at + 1; - p = (*get_graph ())[root].idata.subplans.at (dom); - len = planner_multi_resources_len (p); - duration = meta.duration; - detail::dfu_impl_t::count_relevant_types (p, dfv, agg); - for (t = planner_multi_avail_time_first (p, t, duration, agg.data(), len); - (t != -1 && rc && !errno); t = planner_multi_avail_time_next (p)) { - meta.at = t; - rc = detail::dfu_impl_t::select (jobspec, root, meta, x); - m_total_preorder += detail::dfu_impl_t::get_preorder_count (); - m_total_postorder += detail::dfu_impl_t::get_postorder_count (); - // increment match traversal loop count - ++sched_iters; - } - // The planner layer returns - // ENOENT when no scheduleable point exists - // ERANGE when the total available core count at the root < the request - if (rc < 0 && (errno == ENOENT || errno == ERANGE)) { + case match_op_t::MATCH_ALLOCATE_W_SATISFIABILITY: { + /* With satisfiability check */ errno = EBUSY; meta.alloc_type = jobmeta_t::alloc_type_t::AT_SATISFIABILITY; - meta.at = planner_multi_base_time (p) - + planner_multi_duration (p) - duration - 1; + p = (*get_graph ())[root].idata.subplans.at (dom); + meta.at = planner_multi_base_time (p) + planner_multi_duration (p) - meta.duration - 1; + detail::dfu_impl_t::count_relevant_types (p, dfv, agg); if (detail::dfu_impl_t::select (jobspec, root, meta, x) < 0) { - errno = (errno == EBUSY)? ENODEV : errno; + errno = (errno == EBUSY) ? ENODEV : errno; detail::dfu_impl_t::update (); } m_total_preorder += detail::dfu_impl_t::get_preorder_count (); m_total_postorder += detail::dfu_impl_t::get_postorder_count (); // increment match traversal loop count ++sched_iters; + break; } - break; - } - case match_op_t::MATCH_ALLOCATE: - errno = EBUSY; - break; - default: - break; + case match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE: { + /* Or else reserve */ + errno = 0; + meta.alloc_type = jobmeta_t::alloc_type_t::AT_ALLOC_ORELSE_RESERVE; + t = meta.at + 1; + p = (*get_graph ())[root].idata.subplans.at (dom); + len = planner_multi_resources_len (p); + duration = meta.duration; + detail::dfu_impl_t::count_relevant_types (p, dfv, agg); + for (t = planner_multi_avail_time_first (p, t, duration, agg.data (), len); + (t != -1 && rc && !errno); + t = planner_multi_avail_time_next (p)) { + meta.at = t; + rc = detail::dfu_impl_t::select (jobspec, root, meta, x); + m_total_preorder += detail::dfu_impl_t::get_preorder_count (); + m_total_postorder += detail::dfu_impl_t::get_postorder_count (); + // increment match traversal loop count + ++sched_iters; + } + // The planner layer returns + // ENOENT when no scheduleable point exists + // ERANGE when the total available core count at the root < the request + if (rc < 0 && (errno == ENOENT || errno == ERANGE)) { + errno = EBUSY; + meta.alloc_type = jobmeta_t::alloc_type_t::AT_SATISFIABILITY; + meta.at = planner_multi_base_time (p) + planner_multi_duration (p) - duration - 1; + if (detail::dfu_impl_t::select (jobspec, root, meta, x) < 0) { + errno = (errno == EBUSY) ? ENODEV : errno; + detail::dfu_impl_t::update (); + } + m_total_preorder += detail::dfu_impl_t::get_preorder_count (); + m_total_postorder += detail::dfu_impl_t::get_postorder_count (); + // increment match traversal loop count + ++sched_iters; + } + break; + } + case match_op_t::MATCH_ALLOCATE: + errno = EBUSY; + break; + default: + break; } out: - errno = (!errno)? saved_errno : errno; + errno = (!errno) ? saved_errno : errno; // Update the perf temporary iteration count. If this schedule invocation // corresponds to the max match time this value will be output in the // stats RPC. @@ -233,28 +233,22 @@ int dfu_traverser_t::schedule (Jobspec::Jobspec &jobspec, return rc; } - - //////////////////////////////////////////////////////////////////////////////// // DFU Traverser Public API Definitions //////////////////////////////////////////////////////////////////////////////// dfu_traverser_t::dfu_traverser_t () { - } -dfu_traverser_t::dfu_traverser_t ( std::shared_ptr db, +dfu_traverser_t::dfu_traverser_t (std::shared_ptr db, std::shared_ptr m) : detail::dfu_impl_t (db, m) { - } -dfu_traverser_t::dfu_traverser_t (const dfu_traverser_t &o) - : detail::dfu_impl_t (o) +dfu_traverser_t::dfu_traverser_t (const dfu_traverser_t &o) : detail::dfu_impl_t (o) { - } dfu_traverser_t &dfu_traverser_t::operator= (const dfu_traverser_t &o) @@ -265,22 +259,19 @@ dfu_traverser_t &dfu_traverser_t::operator= (const dfu_traverser_t &o) dfu_traverser_t::~dfu_traverser_t () { - } const resource_graph_t *dfu_traverser_t::get_graph () const { - return detail::dfu_impl_t::get_graph (); + return detail::dfu_impl_t::get_graph (); } -const std::shared_ptr dfu_traverser_t:: - get_graph_db () const +const std::shared_ptr dfu_traverser_t::get_graph_db () const { return detail::dfu_impl_t::get_graph_db (); } -const std::shared_ptr dfu_traverser_t:: - get_match_cb () const +const std::shared_ptr dfu_traverser_t::get_match_cb () const { return detail::dfu_impl_t::get_match_cb (); } @@ -339,11 +330,10 @@ int dfu_traverser_t::initialize () rc = -1; break; } - root = get_graph_db ()->metadata.roots.at(subsystem); - rc += detail::dfu_impl_t::prime_pruning_filter (subsystem, - root, from_dfv); + root = get_graph_db ()->metadata.roots.at (subsystem); + rc += detail::dfu_impl_t::prime_pruning_filter (subsystem, root, from_dfv); } - m_initialized = (rc == 0)? true : false; + m_initialized = (rc == 0) ? true : false; return rc; } @@ -357,59 +347,57 @@ int dfu_traverser_t::initialize (std::shared_ptr db, int dfu_traverser_t::run (Jobspec::Jobspec &jobspec, std::shared_ptr &writers, - match_op_t op, int64_t jobid, int64_t *at) + match_op_t op, + int64_t jobid, + int64_t *at) { const subsystem_t &dom = get_match_cb ()->dom_subsystem (); - graph_duration_t graph_duration = - get_graph_db ()->metadata.graph_duration; + graph_duration_t graph_duration = get_graph_db ()->metadata.graph_duration; if (!get_graph () || !get_graph_db () - || (get_graph_db ()->metadata.roots.find (dom) - == get_graph_db ()->metadata.roots.end ()) + || (get_graph_db ()->metadata.roots.find (dom) == get_graph_db ()->metadata.roots.end ()) || !get_match_cb () || jobspec.resources.empty ()) { errno = EINVAL; return -1; } int rc = -1; - int64_t graph_end = std::chrono::duration_cast - (graph_duration.graph_end - .time_since_epoch ()).count (); + int64_t graph_end = std::chrono::duration_cast ( + graph_duration.graph_end.time_since_epoch ()) + .count (); detail::jobmeta_t meta; vtx_t root = get_graph_db ()->metadata.roots.at (dom); bool x = detail::dfu_impl_t::exclusivity (jobspec.resources, root); const std::set exclusive_types = - detail::dfu_impl_t::get_exclusive_resource_types (); + detail::dfu_impl_t::get_exclusive_resource_types (); std::unordered_map dfv; detail::dfu_impl_t::prime_jobspec (jobspec.resources, dfv); - if (meta.build (jobspec, detail::jobmeta_t::alloc_type_t::AT_ALLOC, jobid, - *at, graph_duration) < 0) + if (meta.build (jobspec, detail::jobmeta_t::alloc_type_t::AT_ALLOC, jobid, *at, graph_duration) + < 0) return -1; - if ( (op == match_op_t::MATCH_SATISFIABILITY) + if ((op == match_op_t::MATCH_SATISFIABILITY) && (rc = is_satisfiable (jobspec, meta, x, root, dfv)) == 0) { detail::dfu_impl_t::update (); - } else if ( (rc = schedule (jobspec, meta, x, op, root, dfv)) == 0) { + } else if ((rc = schedule (jobspec, meta, x, op, root, dfv)) == 0) { *at = meta.at; if (*at == graph_end) { - detail::dfu_impl_t::reset_exclusive_resource_types - (exclusive_types); + detail::dfu_impl_t::reset_exclusive_resource_types (exclusive_types); // no schedulable point found even at the end of the time, return EBUSY errno = EBUSY; return -1; } if (*at < 0 or *at > graph_end) { - detail::dfu_impl_t::reset_exclusive_resource_types - (exclusive_types); + detail::dfu_impl_t::reset_exclusive_resource_types (exclusive_types); errno = EINVAL; return -1; } // If job ends after the resource graph expires, reduce the duration // so it coincides with the graph expiration. Note that we could - // arguably return ENOTSUP/EINVAL instead. Also note that we - // know *at < graph_end from the previous check, and meta.duration + // arguably return ENOTSUP/EINVAL instead. Also note that we + // know *at < graph_end from the previous check, and meta.duration // is < int64_t max from meta.build. - if ( (*at + static_cast (meta.duration)) > graph_end) + if ((*at + static_cast (meta.duration)) > graph_end) meta.duration = graph_end - *at; // returns 0 or -1 rc = detail::dfu_impl_t::update (root, writers, meta); @@ -423,17 +411,17 @@ int dfu_traverser_t::run (Jobspec::Jobspec &jobspec, int dfu_traverser_t::run (const std::string &str, std::shared_ptr &writers, std::shared_ptr &reader, - int64_t id, int64_t at, uint64_t duration) + int64_t id, + int64_t at, + uint64_t duration) { - if (!get_match_cb () || !get_graph () - || !get_graph_db () || !reader || at < 0) { + if (!get_match_cb () || !get_graph () || !get_graph_db () || !reader || at < 0) { errno = EINVAL; return -1; } const subsystem_t &dom = get_match_cb ()->dom_subsystem (); - if (get_graph_db ()->metadata.roots.find (dom) - == get_graph_db ()->metadata.roots.end ()) { + if (get_graph_db ()->metadata.roots.find (dom) == get_graph_db ()->metadata.roots.end ()) { errno = EINVAL; return -1; } @@ -447,8 +435,7 @@ int dfu_traverser_t::run (const std::string &str, return detail::dfu_impl_t::update (root, writers, str, reader, meta); } -int dfu_traverser_t::find (std::shared_ptr &writers, - const std::string &criteria) +int dfu_traverser_t::find (std::shared_ptr &writers, const std::string &criteria) { return detail::dfu_impl_t::find (writers, criteria); } @@ -457,8 +444,7 @@ int dfu_traverser_t::remove (int64_t jobid) { const subsystem_t &dom = get_match_cb ()->dom_subsystem (); if (!get_graph () || !get_graph_db () - || get_graph_db ()->metadata.roots.find (dom) - == get_graph_db ()->metadata.roots.end () + || get_graph_db ()->metadata.roots.find (dom) == get_graph_db ()->metadata.roots.end () || !get_match_cb ()) { errno = EINVAL; return -1; @@ -469,31 +455,28 @@ int dfu_traverser_t::remove (int64_t jobid) } int dfu_traverser_t::remove (const std::string &R_to_cancel, - std::shared_ptr &reader, - int64_t jobid, bool &full_cancel) + std::shared_ptr &reader, + int64_t jobid, + bool &full_cancel) { const subsystem_t &dom = get_match_cb ()->dom_subsystem (); if (!get_graph () || !get_graph_db () - || get_graph_db ()->metadata.roots.find (dom) - == get_graph_db ()->metadata.roots.end () + || get_graph_db ()->metadata.roots.find (dom) == get_graph_db ()->metadata.roots.end () || !get_match_cb ()) { errno = EINVAL; return -1; } vtx_t root = get_graph_db ()->metadata.roots.at (dom); - return detail::dfu_impl_t::remove (root, R_to_cancel, reader, jobid, - full_cancel); + return detail::dfu_impl_t::remove (root, R_to_cancel, reader, jobid, full_cancel); } -int dfu_traverser_t::mark (const std::string &root_path, - resource_pool_t::status_t status) +int dfu_traverser_t::mark (const std::string &root_path, resource_pool_t::status_t status) { return detail::dfu_impl_t::mark (root_path, status); } -int dfu_traverser_t::mark (std::set &ranks, - resource_pool_t::status_t status) +int dfu_traverser_t::mark (std::set &ranks, resource_pool_t::status_t status) { return detail::dfu_impl_t::mark (ranks, status); } diff --git a/resource/traversers/dfu.hpp b/resource/traversers/dfu.hpp index a1a043b81..4c83e21b0 100644 --- a/resource/traversers/dfu.hpp +++ b/resource/traversers/dfu.hpp @@ -23,12 +23,10 @@ namespace resource_model { * by the matcher callback object (dfu_match_cb_t). Corresponding match * callback methods are invoked at various well-defined graph visit events. */ -class dfu_traverser_t : protected detail::dfu_impl_t -{ -public: +class dfu_traverser_t : protected detail::dfu_impl_t { + public: dfu_traverser_t (); - dfu_traverser_t (std::shared_ptr db, - std::shared_ptr m); + dfu_traverser_t (std::shared_ptr db, std::shared_ptr m); dfu_traverser_t (const dfu_traverser_t &o); dfu_traverser_t (dfu_traverser_t &&o) = default; dfu_traverser_t &operator= (const dfu_traverser_t &o); @@ -81,8 +79,7 @@ class dfu_traverser_t : protected detail::dfu_impl_t * ENOTSUP: roots does not contain a subsystem * the match callback uses. */ - int initialize (std::shared_ptr db, - std::shared_ptr m); + int initialize (std::shared_ptr db, std::shared_ptr m); /*! Begin a graph traversal for the jobspec and allocate, * reserve or check its satisfiability on the resources @@ -109,7 +106,9 @@ class dfu_traverser_t : protected detail::dfu_impl_t */ int run (Jobspec::Jobspec &jobspec, std::shared_ptr &writers, - match_op_t op, int64_t id, int64_t *at); + match_op_t op, + int64_t id, + int64_t *at); /*! Read str which is a serialized allocation data (e.g., written in JGF) * with rd, and traverse the resource graph to update it with this data. @@ -126,7 +125,9 @@ class dfu_traverser_t : protected detail::dfu_impl_t int run (const std::string &str, std::shared_ptr &writers, std::shared_ptr &reader, - int64_t id, int64_t at, uint64_t duration); + int64_t id, + int64_t at, + uint64_t duration); /*! Traverse the resource graph and emit those resources whose * status is matched with the matching criteria. @@ -152,8 +153,7 @@ class dfu_traverser_t : protected detail::dfu_impl_t * ignored. * \return 0 on success; -1 on error. */ - int find (std::shared_ptr &writers, - const std::string &criteria); + int find (std::shared_ptr &writers, const std::string &criteria); /*! Remove the allocation/reservation referred to by jobid and update * the resource state. @@ -178,7 +178,8 @@ class dfu_traverser_t : protected detail::dfu_impl_t */ int remove (const std::string &to_cancel, std::shared_ptr &reader, - int64_t jobid, bool &full_cancel); + int64_t jobid, + bool &full_cancel); /*! Mark the resource status up|down|etc starting at subtree_root. * @@ -198,27 +199,32 @@ class dfu_traverser_t : protected detail::dfu_impl_t */ int mark (std::set &ranks, resource_pool_t::status_t status); -private: - int is_satisfiable (Jobspec::Jobspec &jobspec, detail::jobmeta_t &meta, - bool x, vtx_t root, + private: + int is_satisfiable (Jobspec::Jobspec &jobspec, + detail::jobmeta_t &meta, + bool x, + vtx_t root, std::unordered_map &dfv); int request_feasible (detail::jobmeta_t const &meta, match_op_t op, vtx_t root, std::unordered_map &dfv, const subsystem_t &dom); - int schedule (Jobspec::Jobspec &jobspec, detail::jobmeta_t &meta, - bool x, match_op_t op, vtx_t root, + int schedule (Jobspec::Jobspec &jobspec, + detail::jobmeta_t &meta, + bool x, + match_op_t op, + vtx_t root, std::unordered_map &dfv); bool m_initialized = false; unsigned int m_total_preorder = 0; unsigned int m_total_postorder = 0; }; -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // DFU_TRAVERSE_HPP +#endif // DFU_TRAVERSE_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/traversers/dfu_impl.cpp b/resource/traversers/dfu_impl.cpp index 09d9dceb0..00c9ba69e 100644 --- a/resource/traversers/dfu_impl.cpp +++ b/resource/traversers/dfu_impl.cpp @@ -20,7 +20,6 @@ using namespace Flux::Jobspec; using namespace Flux::resource_model; using namespace Flux::resource_model::detail; - //////////////////////////////////////////////////////////////////////////////// // DFU Traverser Implementation Private API Definitions //////////////////////////////////////////////////////////////////////////////// @@ -60,13 +59,12 @@ bool dfu_impl_t::stop_explore (edg_t e, const subsystem_t &subsystem) const || m_color.is_black ((*m_graph)[u].idata.colors[subsystem])); } -bool dfu_impl_t::exclusivity (const std::vector &resources, - vtx_t u) +bool dfu_impl_t::exclusivity (const std::vector &resources, vtx_t u) { // If one of the resources matches with the visiting vertex, u // and it requested exclusive access, return true; bool exclusive = false; - for (auto &resource: resources) { + for (auto &resource : resources) { if (resource.type == (*m_graph)[u].type) if (resource.exclusive == Jobspec::tristate_t::TRUE) exclusive = true; @@ -74,7 +72,9 @@ bool dfu_impl_t::exclusivity (const std::vector &resources, return exclusive; } -int dfu_impl_t::by_avail (const jobmeta_t &meta, const std::string &s, vtx_t u, +int dfu_impl_t::by_avail (const jobmeta_t &meta, + const std::string &s, + vtx_t u, const std::vector &resources) { int rc = -1; @@ -105,8 +105,11 @@ int dfu_impl_t::by_avail (const jobmeta_t &meta, const std::string &s, vtx_t u, return rc; } -int dfu_impl_t::by_excl (const jobmeta_t &meta, const std::string &s, vtx_t u, - bool exclusive_in, const Jobspec::Resource &resource) +int dfu_impl_t::by_excl (const jobmeta_t &meta, + const std::string &s, + vtx_t u, + bool exclusive_in, + const Jobspec::Resource &resource) { int rc = -1; planner_t *p = NULL; @@ -136,8 +139,8 @@ int dfu_impl_t::by_excl (const jobmeta_t &meta, const std::string &s, vtx_t u, // available. Note: if Fluxion needs to support shared // resources at the leaf level this check will not catch // multiple booking. - if (meta.alloc_type == jobmeta_t::alloc_type_t::AT_ALLOC && - !(*m_graph)[u].schedule.allocations.empty ()) + if (meta.alloc_type == jobmeta_t::alloc_type_t::AT_ALLOC + && !(*m_graph)[u].schedule.allocations.empty ()) goto done; errno = 0; p = (*m_graph)[u].idata.x_checker; @@ -163,7 +166,9 @@ int dfu_impl_t::by_excl (const jobmeta_t &meta, const std::string &s, vtx_t u, return rc; } -int dfu_impl_t::by_subplan (const jobmeta_t &meta, const std::string &s, vtx_t u, +int dfu_impl_t::by_subplan (const jobmeta_t &meta, + const std::string &s, + vtx_t u, const Jobspec::Resource &resource) { int rc = -1; @@ -182,7 +187,7 @@ int dfu_impl_t::by_subplan (const jobmeta_t &meta, const std::string &s, vtx_t u count_relevant_types (p, resource.user_data, aggs); errno = 0; len = aggs.size (); - if ((rc = planner_multi_avail_during (p, at, d, aggs.data(), len)) == -1) { + if ((rc = planner_multi_avail_during (p, at, d, aggs.data (), len)) == -1) { if (errno != 0 && errno != ERANGE) { m_err_msg += "by_subplan: planner_multi_avail_during returned -1.\n"; m_err_msg += strerror (errno); @@ -196,8 +201,10 @@ int dfu_impl_t::by_subplan (const jobmeta_t &meta, const std::string &s, vtx_t u return rc; } -int dfu_impl_t::prune (const jobmeta_t &meta, bool exclusive, - const std::string &s, vtx_t u, +int dfu_impl_t::prune (const jobmeta_t &meta, + bool exclusive, + const std::string &s, + vtx_t u, const std::vector &resources) { int rc = 0; @@ -210,24 +217,22 @@ int dfu_impl_t::prune (const jobmeta_t &meta, bool exclusive, } // RFC 31 constraints only match against type == "node" // unspecified constraint matches everything - if (meta.constraint != nullptr - && (*m_graph)[u].type == "node" + if (meta.constraint != nullptr && (*m_graph)[u].type == "node" && !meta.constraint->match ((*m_graph)[u])) { rc = -1; goto done; } // if rack has been allocated exclusively, no reason to descend further. - if ( (rc = by_avail (meta, s, u, resources)) == -1) + if ((rc = by_avail (meta, s, u, resources)) == -1) goto done; for (auto &resource : resources) { if ((*m_graph)[u].type != resource.type && resource.type != "slot") continue; // Prune by exclusivity checker - if (resource.type != "slot" - && (rc = by_excl (meta, s, u, exclusive, resource)) == -1) + if (resource.type != "slot" && (rc = by_excl (meta, s, u, exclusive, resource)) == -1) break; // Prune by the subtree planner quantities - if ( (rc = by_subplan (meta, s, u, resource)) == -1) + if ((rc = by_subplan (meta, s, u, resource)) == -1) break; } @@ -235,7 +240,8 @@ int dfu_impl_t::prune (const jobmeta_t &meta, bool exclusive, return rc; } -planner_multi_t *dfu_impl_t::subtree_plan (vtx_t u, std::vector &av, +planner_multi_t *dfu_impl_t::subtree_plan (vtx_t u, + std::vector &av, std::vector &tp) { size_t len = av.size (); @@ -244,8 +250,10 @@ planner_multi_t *dfu_impl_t::subtree_plan (vtx_t u, std::vector &av, return planner_multi_new (base_time, duration, &av[0], &tp[0], len); } -int dfu_impl_t::match (vtx_t u, const std::vector &resources, - const Resource **slot_resource, unsigned int *nslots, +int dfu_impl_t::match (vtx_t u, + const std::vector &resources, + const Resource **slot_resource, + unsigned int *nslots, const Resource **match_resource) { int rc = -1; @@ -290,7 +298,7 @@ bool dfu_impl_t::slot_match (vtx_t u, const Resource *slot_resources) for (tie (ei, eie) = out_edges (u, *m_graph); ei != eie; ++ei) { vtx_t tgt = target (*ei, *m_graph); if ((*m_graph)[tgt].type == c_resource.type) - break; // found the target resource type of the slot + break; // found the target resource type of the slot } if (ei == eie) { slot_match = false; @@ -304,9 +312,10 @@ bool dfu_impl_t::slot_match (vtx_t u, const Resource *slot_resources) } const std::vector &dfu_impl_t::test (vtx_t u, - const std::vector &resources, - bool &pristine, unsigned int &nslots, - match_kind_t &spec) + const std::vector &resources, + bool &pristine, + unsigned int &nslots, + match_kind_t &spec) { /* Note on the purpose of pristine: we differentiate two similar but * distinct cases with this parameter. @@ -333,7 +342,7 @@ const std::vector &dfu_impl_t::test (vtx_t u, spec = match_kind_t::NONE_MATCH; goto done; } - if ( (slot = slot_match (u, slot_resources))) { + if ((slot = slot_match (u, slot_resources))) { spec = match_kind_t::SLOT_MATCH; pristine = false; ret = &(slot_resources->with); @@ -342,8 +351,7 @@ const std::vector &dfu_impl_t::test (vtx_t u, pristine = false; ret = &(match_resources->with); } else { - spec = pristine? match_kind_t::PRISTINE_NONE_MATCH - : match_kind_t::NONE_MATCH; + spec = pristine ? match_kind_t::PRISTINE_NONE_MATCH : match_kind_t::NONE_MATCH; } done: @@ -353,7 +361,8 @@ const std::vector &dfu_impl_t::test (vtx_t u, /* Accumulate counts into accum[type] if the type is one of the pruning * filter type. */ -int dfu_impl_t::accum_if (const subsystem_t &subsystem, const std::string &type, +int dfu_impl_t::accum_if (const subsystem_t &subsystem, + const std::string &type, unsigned int counts, std::map &accum) { @@ -367,7 +376,8 @@ int dfu_impl_t::accum_if (const subsystem_t &subsystem, const std::string &type, } /* Same as above except that accum is unorder_map */ -int dfu_impl_t::accum_if (const subsystem_t &subsystem, const std::string &type, +int dfu_impl_t::accum_if (const subsystem_t &subsystem, + const std::string &type, unsigned int counts, std::unordered_map &accum) { @@ -382,7 +392,8 @@ int dfu_impl_t::accum_if (const subsystem_t &subsystem, const std::string &type, return rc; } -int dfu_impl_t::prime_exp (const subsystem_t &subsystem, vtx_t u, +int dfu_impl_t::prime_exp (const subsystem_t &subsystem, + vtx_t u, std::map &dfv) { int rc = 0; @@ -390,18 +401,19 @@ int dfu_impl_t::prime_exp (const subsystem_t &subsystem, vtx_t u, for (tie (ei, ei_end) = out_edges (u, *m_graph); ei != ei_end; ++ei) { if (stop_explore (*ei, subsystem) || !in_subsystem (*ei, subsystem)) continue; - if ((rc = prime_pruning_filter (subsystem, - target (*ei, *m_graph), dfv)) != 0) + if ((rc = prime_pruning_filter (subsystem, target (*ei, *m_graph), dfv)) != 0) break; } return rc; } -int dfu_impl_t::explore_statically (const jobmeta_t &meta, vtx_t u, +int dfu_impl_t::explore_statically (const jobmeta_t &meta, + vtx_t u, const subsystem_t &subsystem, const std::vector &resources, bool pristine, - bool *excl, visit_t direction, + bool *excl, + visit_t direction, scoring_api_t &dfu) { int rc = -1; @@ -414,14 +426,13 @@ int dfu_impl_t::explore_statically (const jobmeta_t &meta, vtx_t u, bool x_inout = *excl; vtx_t tgt = target (*ei, *m_graph); switch (direction) { - case visit_t::UPV: - rc = aux_upv (meta, tgt, subsystem, - resources, pristine, &x_inout, dfu); - break; - case visit_t::DFV: - default: - rc = dom_dfv (meta, tgt, resources, pristine, &x_inout, dfu); - break; + case visit_t::UPV: + rc = aux_upv (meta, tgt, subsystem, resources, pristine, &x_inout, dfu); + break; + case visit_t::DFV: + default: + rc = dom_dfv (meta, tgt, resources, pristine, &x_inout, dfu); + break; } if (rc == 0) { unsigned int count = dfu.avail (); @@ -437,30 +448,25 @@ int dfu_impl_t::explore_statically (const jobmeta_t &meta, vtx_t u, bool dfu_impl_t::is_enough (const subsystem_t &subsystem, const std::vector &resources, - scoring_api_t &dfu, unsigned int multiplier) + scoring_api_t &dfu, + unsigned int multiplier) { - return std::all_of ( - resources.begin (), - resources.end (), - [&] (const Resource &resource) { - unsigned int total = dfu.total_count (subsystem, - resource.type); - unsigned int required = multiplier - * m_match->calc_effective_max ( - resource); - return total >= required; - }); + return std::all_of (resources.begin (), resources.end (), [&] (const Resource &resource) { + unsigned int total = dfu.total_count (subsystem, resource.type); + unsigned int required = multiplier * m_match->calc_effective_max (resource); + return total >= required; + }); } int dfu_impl_t::new_sat_types (const subsystem_t &subsystem, - const std::vector &resources, - scoring_api_t &dfu, unsigned int multiplier, - std::set &sat_types) + const std::vector &resources, + scoring_api_t &dfu, + unsigned int multiplier, + std::set &sat_types) { for (auto &resource : resources) { unsigned int total = dfu.total_count (subsystem, resource.type); - unsigned int required = multiplier - * m_match->calc_effective_max (resource); + unsigned int required = multiplier * m_match->calc_effective_max (resource); bool sat = total >= required; if (sat && sat_types.find (resource.type) == sat_types.end ()) { auto ret = sat_types.insert (resource.type); @@ -473,11 +479,15 @@ int dfu_impl_t::new_sat_types (const subsystem_t &subsystem, return 0; } -int dfu_impl_t::explore_dynamically (const jobmeta_t &meta, vtx_t u, +int dfu_impl_t::explore_dynamically (const jobmeta_t &meta, + vtx_t u, const subsystem_t &subsystem, const std::vector &resources, - bool pristine, bool *excl, visit_t direction, - scoring_api_t &dfu, unsigned int multiplier) + bool pristine, + bool *excl, + visit_t direction, + scoring_api_t &dfu, + unsigned int multiplier) { int rc = -1; int rc2 = -1; @@ -499,24 +509,21 @@ int dfu_impl_t::explore_dynamically (const jobmeta_t &meta, vtx_t u, bool x_inout = *excl; switch (direction) { - case visit_t::UPV: - rc = aux_upv (meta, tgt, subsystem, - resources, pristine, &x_inout, dfu); - break; - case visit_t::DFV: - default: - rc = dom_dfv (meta, tgt, resources, pristine, &x_inout, dfu); - break; + case visit_t::UPV: + rc = aux_upv (meta, tgt, subsystem, resources, pristine, &x_inout, dfu); + break; + case visit_t::DFV: + default: + rc = dom_dfv (meta, tgt, resources, pristine, &x_inout, dfu); + break; } if (rc == 0) { unsigned int count = dfu.avail (); eval_edg_t ev_edg (count, count, x_inout, e); - eval_egroup_t egrp (dfu.overall_score (), - dfu.avail (), 0, x_inout, false); + eval_egroup_t egrp (dfu.overall_score (), dfu.avail (), 0, x_inout, false); egrp.edges.push_back (ev_edg); dfu.add (subsystem, (*m_graph)[tgt].type, egrp); - if ( (rc2 = new_sat_types (subsystem, resources, - dfu, multiplier, sat_types)) < 0) + if ((rc2 = new_sat_types (subsystem, resources, dfu, multiplier, sat_types)) < 0) break; rc2 = 0; if (is_enough (subsystem, resources, dfu, multiplier)) @@ -526,22 +533,36 @@ int dfu_impl_t::explore_dynamically (const jobmeta_t &meta, vtx_t u, return rc2; } -int dfu_impl_t::explore (const jobmeta_t &meta, vtx_t u, +int dfu_impl_t::explore (const jobmeta_t &meta, + vtx_t u, const subsystem_t &subsystem, - const std::vector &resources, bool pristine, - bool *excl, visit_t direction, scoring_api_t &dfu, + const std::vector &resources, + bool pristine, + bool *excl, + visit_t direction, + scoring_api_t &dfu, unsigned int multiplier) { return (!m_match->get_stop_on_k_matches ()) - ? explore_statically (meta, u, subsystem, resources, pristine, - excl, direction, dfu) - : explore_dynamically (meta, u, subsystem, resources, pristine, - excl, direction, dfu, multiplier); + ? explore_statically (meta, u, subsystem, resources, pristine, excl, direction, dfu) + : explore_dynamically (meta, + u, + subsystem, + resources, + pristine, + excl, + direction, + dfu, + multiplier); } -int dfu_impl_t::aux_upv (const jobmeta_t &meta, vtx_t u, const subsystem_t &aux, - const std::vector &resources, bool pristine, - bool *excl, scoring_api_t &to_parent) +int dfu_impl_t::aux_upv (const jobmeta_t &meta, + vtx_t u, + const subsystem_t &aux, + const std::vector &resources, + bool pristine, + bool *excl, + scoring_api_t &to_parent) { int rc = -1; scoring_api_t upv; @@ -558,7 +579,7 @@ int dfu_impl_t::aux_upv (const jobmeta_t &meta, vtx_t u, const subsystem_t &aux, explore (meta, u, aux, resources, pristine, excl, visit_t::UPV, upv); p = (*m_graph)[u].schedule.plans; - if ( (avail = planner_avail_resources_during (p, at, duration)) == 0) { + if ((avail = planner_avail_resources_during (p, at, duration)) == 0) { goto done; } else if (avail == -1) { m_err_msg += "aux_upv: planner_avail_resources_during returned -1. "; @@ -574,25 +595,25 @@ int dfu_impl_t::aux_upv (const jobmeta_t &meta, vtx_t u, const subsystem_t &aux, return rc; } -int dfu_impl_t::dom_exp (const jobmeta_t &meta, vtx_t u, - const std::vector &resources, bool pristine, - bool *excl, scoring_api_t &dfu) +int dfu_impl_t::dom_exp (const jobmeta_t &meta, + vtx_t u, + const std::vector &resources, + bool pristine, + bool *excl, + scoring_api_t &dfu) { int rc = -1; const subsystem_t &dom = m_match->dom_subsystem (); for (auto &s : m_match->subsystems ()) { if (s == dom) - rc = explore (meta, u, s, resources, - pristine, excl, visit_t::DFV, dfu); + rc = explore (meta, u, s, resources, pristine, excl, visit_t::DFV, dfu); else - rc = explore (meta, u, s, resources, - pristine, excl, visit_t::UPV, dfu); + rc = explore (meta, u, s, resources, pristine, excl, visit_t::UPV, dfu); } return rc; } -int dfu_impl_t::cnt_slot (const std::vector &slot_shape, - scoring_api_t &dfu_slot) +int dfu_impl_t::cnt_slot (const std::vector &slot_shape, scoring_api_t &dfu_slot) { unsigned int qc = 0; unsigned int qg = 0; @@ -615,19 +636,22 @@ int dfu_impl_t::cnt_slot (const std::vector &slot_shape, qg = dfu_slot.qualified_granules (dom, slot_elem.type); count = m_match->calc_count (slot_elem, qc); // constraint check against qualified amounts - fit = (count == 0)? count : (qc / count); + fit = (count == 0) ? count : (qc / count); // constraint check against qualified granules - fit = (fit > qg)? qg : fit; - qual_num_slots = (qual_num_slots > fit)? fit : qual_num_slots; + fit = (fit > qg) ? qg : fit; + qual_num_slots = (qual_num_slots > fit) ? fit : qual_num_slots; dfu_slot.eval_egroups_iter_reset (dom, slot_elem.type); } return qual_num_slots; } -int dfu_impl_t::dom_slot (const jobmeta_t &meta, vtx_t u, +int dfu_impl_t::dom_slot (const jobmeta_t &meta, + vtx_t u, const std::vector &slot_shape, unsigned int nslots, - bool pristine, bool *excl, scoring_api_t &dfu) + bool pristine, + bool *excl, + scoring_api_t &dfu) { int rc; bool x_inout = true; @@ -636,8 +660,9 @@ int dfu_impl_t::dom_slot (const jobmeta_t &meta, vtx_t u, std::vector edg_group_vector; const subsystem_t &dom = m_match->dom_subsystem (); - if ( (rc = explore (meta, u, dom, slot_shape, pristine, - &x_inout, visit_t::DFV, dfu_slot, nslots)) != 0) + if ((rc = + explore (meta, u, dom, slot_shape, pristine, &x_inout, visit_t::DFV, dfu_slot, nslots)) + != 0) goto done; if ((rc = m_match->dom_finish_slot (dom, dfu_slot)) != 0) goto done; @@ -651,17 +676,16 @@ int dfu_impl_t::dom_slot (const jobmeta_t &meta, vtx_t u, unsigned int qc = dfu_slot.qualified_count (dom, slot_elem.type); unsigned int count = m_match->calc_count (slot_elem, qc); while (j < count) { - auto egroup_i = dfu_slot.eval_egroups_iter_next ( - dom, slot_elem.type); - if (egroup_i == dfu_slot.eval_egroups_end (dom, - slot_elem.type)) { + auto egroup_i = dfu_slot.eval_egroups_iter_next (dom, slot_elem.type); + if (egroup_i == dfu_slot.eval_egroups_end (dom, slot_elem.type)) { m_err_msg += __FUNCTION__; m_err_msg += ": not enough slots.\n"; qual_num_slots = 0; goto done; } eval_edg_t ev_edg ((*egroup_i).edges[0].count, - (*egroup_i).edges[0].count, 1, + (*egroup_i).edges[0].count, + 1, (*egroup_i).edges[0].edge); score += (*egroup_i).score; edg_group.edges.push_back (ev_edg); @@ -677,12 +701,15 @@ int dfu_impl_t::dom_slot (const jobmeta_t &meta, vtx_t u, dfu.add (dom, std::string ("slot"), edg_group); done: - return (qual_num_slots)? 0 : -1; + return (qual_num_slots) ? 0 : -1; } -int dfu_impl_t::dom_dfv (const jobmeta_t &meta, vtx_t u, - const std::vector &resources, bool pristine, - bool *excl, scoring_api_t &to_parent) +int dfu_impl_t::dom_dfv (const jobmeta_t &meta, + vtx_t u, + const std::vector &resources, + bool pristine, + bool *excl, + scoring_api_t &to_parent) { int rc = -1; match_kind_t sm; @@ -695,8 +722,7 @@ int dfu_impl_t::dom_dfv (const jobmeta_t &meta, vtx_t u, scoring_api_t dfu; planner_t *p = NULL; const std::string &dom = m_match->dom_subsystem (); - const std::vector &next = test (u, resources, - check_pres, nslots, sm); + const std::vector &next = test (u, resources, check_pres, nslots, sm); m_preorder++; if (sm == match_kind_t::NONE_MATCH) @@ -713,7 +739,7 @@ int dfu_impl_t::dom_dfv (const jobmeta_t &meta, vtx_t u, (*m_graph)[u].idata.colors[dom] = m_color.black (); p = (*m_graph)[u].schedule.plans; - if ( (avail = planner_avail_resources_during (p, at, duration)) == 0) { + if ((avail = planner_avail_resources_during (p, at, duration)) == 0) { goto done; } else if (avail == -1) { m_err_msg += "dom_dfv: planner_avail_resources_during returned -1.\n"; @@ -728,12 +754,9 @@ int dfu_impl_t::dom_dfv (const jobmeta_t &meta, vtx_t u, to_parent.set_avail (avail); to_parent.set_overall_score (dfu.overall_score ()); - for (auto &resource: resources) { - if ((resource.type == (*m_graph)[u].type) && - (!resource.label.empty())) { - rc = (*m_graph)[u].idata.ephemeral.insert (m_best_k_cnt, - "label", - resource.label); + for (auto &resource : resources) { + if ((resource.type == (*m_graph)[u].type) && (!resource.label.empty ())) { + rc = (*m_graph)[u].idata.ephemeral.insert (m_best_k_cnt, "label", resource.label); if (rc < 0) { m_err_msg += "dom_dfv: inserting label into ephemeral failed.\n"; m_err_msg += strerror (errno); @@ -749,14 +772,16 @@ int dfu_impl_t::dom_dfv (const jobmeta_t &meta, vtx_t u, int dfu_impl_t::aux_find_upv (std::shared_ptr &writers, const std::string &criteria, - vtx_t u, const subsystem_t &aux, + vtx_t u, + const subsystem_t &aux, const vtx_predicates_override_t &p) { return 0; } int dfu_impl_t::dom_find_dfv (std::shared_ptr &w, - const std::string &criteria, vtx_t u, + const std::string &criteria, + vtx_t u, const vtx_predicates_override_t &p) { int rc = -1; @@ -778,8 +803,8 @@ int dfu_impl_t::dom_find_dfv (std::shared_ptr &w, if (stop_explore (*ei, s) || !in_subsystem (*ei, s)) continue; vtx_t tgt = target (*ei, *m_graph); - rc = (s == dom)? dom_find_dfv (w, criteria, tgt, p_overridden) - : aux_find_upv (w, criteria, tgt, s, p_overridden); + rc = (s == dom) ? dom_find_dfv (w, criteria, tgt, p_overridden) + : aux_find_upv (w, criteria, tgt, s, p_overridden); if (rc > 0) { if (w->emit_edg (level (), *m_graph, *ei) < 0) { m_err_msg += __FUNCTION__; @@ -794,7 +819,7 @@ int dfu_impl_t::dom_find_dfv (std::shared_ptr &w, vtx_target.initialize (p_overridden, m_graph, u); (*m_graph)[u].idata.colors[dom] = m_color.black (); - if ( (rc = m_expr_eval.evaluate (criteria, vtx_target, result)) < 0) { + if ((rc = m_expr_eval.evaluate (criteria, vtx_target, result)) < 0) { m_err_msg += __FUNCTION__; m_err_msg += std::string (": error from evaluate: ") + strerror (errno); goto done; @@ -806,8 +831,7 @@ int dfu_impl_t::dom_find_dfv (std::shared_ptr &w, // emitting the vertex, since data could be leftover from previous // traversals where the vertex was matched but not emitted (*m_graph)[u].idata.ephemeral.check_and_clear_if_stale (m_best_k_cnt); - if ( (rc = w->emit_vtx (level (), *m_graph, u, - (*m_graph)[u].size, true)) < 0) { + if ((rc = w->emit_vtx (level (), *m_graph, u, (*m_graph)[u].size, true)) < 0) { m_err_msg += __FUNCTION__; m_err_msg += std::string (": error from emit_vtx: ") + strerror (errno); goto done; @@ -853,11 +877,11 @@ int dfu_impl_t::enforce_dfv (vtx_t u, scoring_api_t &dfu) // Thus, the subtree must be explored to decide if the ancestor // edge should be marked best_k. if (enforce_dfv (tgt, dfu) == 1) { - (*m_graph)[*ei].idata.set_for_trav_update ((*m_graph)[tgt].size, - false, - m_best_k_cnt); - rc = 1; - continue; + (*m_graph)[*ei].idata.set_for_trav_update ((*m_graph)[tgt].size, + false, + m_best_k_cnt); + rc = 1; + continue; } } } @@ -867,13 +891,15 @@ int dfu_impl_t::enforce_dfv (vtx_t u, scoring_api_t &dfu) return rc; } -int dfu_impl_t::has_root (vtx_t root, std::vector &resources, - scoring_api_t &dfu, unsigned int *needs) +int dfu_impl_t::has_root (vtx_t root, + std::vector &resources, + scoring_api_t &dfu, + unsigned int *needs) { int rc = 0; unsigned int qc; unsigned int count; - *needs = 1; // if the root is not specified, assume we need 1 + *needs = 1; // if the root is not specified, assume we need 1 for (auto &resource : resources) { if (resource.type == (*m_graph)[root].type) { qc = dfu.avail (); @@ -881,15 +907,14 @@ int dfu_impl_t::has_root (vtx_t root, std::vector &resources, rc = -1; goto done; } - *needs = count; // if the root is specified, give that much + *needs = count; // if the root is specified, give that much } } done: return rc; } -int dfu_impl_t::has_remaining (vtx_t root, std::vector &resources, - scoring_api_t &dfu) +int dfu_impl_t::has_remaining (vtx_t root, std::vector &resources, scoring_api_t &dfu) { int rc = 0; for (auto &subsystem : m_match->subsystems ()) { @@ -920,12 +945,14 @@ int dfu_impl_t::enforce_remaining (vtx_t root, scoring_api_t &dfu) m_color.reset (); rc = enforce_dfv (root, dfu); m_color.reset (); - return (rc < 0)? -1 : 0; + return (rc < 0) ? -1 : 0; } -int dfu_impl_t::resolve_graph (vtx_t root, std::vector &resources, +int dfu_impl_t::resolve_graph (vtx_t root, + std::vector &resources, scoring_api_t &dfu, - bool excl, unsigned int *needs) + bool excl, + unsigned int *needs) { int rc = -1; const subsystem_t &dom = m_match->dom_subsystem (); @@ -937,7 +964,7 @@ int dfu_impl_t::resolve_graph (vtx_t root, std::vector &resources, goto done; if (enforce_constrained (dfu) != 0) goto done; - if ( (rc = enforce_remaining (root, dfu)) != 0) + if ((rc = enforce_remaining (root, dfu)) != 0) goto done; done: return rc; @@ -950,8 +977,7 @@ int dfu_impl_t::resolve (scoring_api_t &dfu, scoring_api_t &to_parent) if (dfu.hier_constrain_now ()) { for (auto subsystem : m_match->subsystems ()) rc += enforce (subsystem, dfu); - } - else { + } else { to_parent.merge (dfu); } } @@ -987,18 +1013,14 @@ int dfu_impl_t::enforce (const subsystem_t &subsystem, scoring_api_t &dfu) return rc; } - - //////////////////////////////////////////////////////////////////////////////// // DFU Traverser Implementation Public API Definitions //////////////////////////////////////////////////////////////////////////////// dfu_impl_t::dfu_impl_t () = default; -dfu_impl_t::dfu_impl_t (std::shared_ptr db, - std::shared_ptr m) +dfu_impl_t::dfu_impl_t (std::shared_ptr db, std::shared_ptr m) : m_graph_db (db), m_match (m) { - } dfu_impl_t::dfu_impl_t (const dfu_impl_t &o) = default; dfu_impl_t &dfu_impl_t::operator= (const dfu_impl_t &o) = default; @@ -1067,7 +1089,8 @@ int dfu_impl_t::reset_exclusive_resource_types (const std::set &x_t return m_match->reset_exclusive_resource_types (x_types); } -int dfu_impl_t::prime_pruning_filter (const subsystem_t &s, vtx_t u, +int dfu_impl_t::prime_pruning_filter (const subsystem_t &s, + vtx_t u, std::map &to_parent) { int rc = -1; @@ -1086,8 +1109,7 @@ int dfu_impl_t::prime_pruning_filter (const subsystem_t &s, vtx_t u, for (auto &aggr : dfv) accum_if (s, aggr.first, aggr.second, to_parent); - if (m_match->get_my_pruning_types (s, - (*m_graph)[u].type, out_prune_types)) { + if (m_match->get_my_pruning_types (s, (*m_graph)[u].type, out_prune_types)) { for (auto &type : out_prune_types) { types.push_back (type.c_str ()); if (dfv.find (type) != dfv.end ()) @@ -1102,18 +1124,20 @@ int dfu_impl_t::prime_pruning_filter (const subsystem_t &s, vtx_t u, goto done; } - if ( (*m_graph)[u].idata.subplans[s] == NULL) { + if ((*m_graph)[u].idata.subplans[s] == NULL) { errno = 0; planner_multi_t *p = NULL; - if (!(p = subtree_plan (u, avail, types)) ) { + if (!(p = subtree_plan (u, avail, types))) { m_err_msg += "prime: error initializing a multi-planner. "; m_err_msg += strerror (errno); goto done; } (*m_graph)[u].idata.subplans[s] = p; } else { - planner_multi_update ((*m_graph)[u].idata.subplans[s], avail.data(), - types.data(), types.size ()); + planner_multi_update ((*m_graph)[u].idata.subplans[s], + avail.data (), + types.data (), + types.size ()); } rc = 0; done: @@ -1123,14 +1147,13 @@ int dfu_impl_t::prime_pruning_filter (const subsystem_t &s, vtx_t u, } void dfu_impl_t::prime_jobspec (std::vector &resources, - std::unordered_map &to_parent) + std::unordered_map &to_parent) { const subsystem_t &subsystem = m_match->dom_subsystem (); for (auto &resource : resources) { - // If the resource is requested as exclusive in the - // jobspec, add it to the matcher's exclusive resource - // set. This ensures that the full resource set (which + // If the resource is requested as exclusive in the + // jobspec, add it to the matcher's exclusive resource + // set. This ensures that the full resource set (which // includes shadow resources) is emitted. if (resource.exclusive == Jobspec::tristate_t::TRUE) m_match->add_exclusive_resource_type (resource.type); @@ -1139,14 +1162,12 @@ void dfu_impl_t::prime_jobspec (std::vector &resources, accum_if (subsystem, resource.type, resource.count.min, to_parent); prime_jobspec (resource.with, resource.user_data); for (auto &aggregate : resource.user_data) { - accum_if (subsystem, aggregate.first, - resource.count.min * aggregate.second, to_parent); + accum_if (subsystem, aggregate.first, resource.count.min * aggregate.second, to_parent); } } } -int dfu_impl_t::select (Jobspec::Jobspec &j, vtx_t root, jobmeta_t &meta, - bool excl) +int dfu_impl_t::select (Jobspec::Jobspec &j, vtx_t root, jobmeta_t &meta, bool excl) { int rc = -1; scoring_api_t dfu; @@ -1164,14 +1185,12 @@ int dfu_impl_t::select (Jobspec::Jobspec &j, vtx_t root, jobmeta_t &meta, egrp.edges.push_back (ev_edg); dfu.add (dom, (*m_graph)[root].type, egrp); rc = resolve_graph (root, j.resources, dfu, excl, &needs); - m_graph_db->metadata.v_rt_edges[dom].set_for_trav_update (needs, x_in, - m_best_k_cnt); + m_graph_db->metadata.v_rt_edges[dom].set_for_trav_update (needs, x_in, m_best_k_cnt); } return rc; } -int dfu_impl_t::find (std::shared_ptr &writers, - const std::string &criteria) +int dfu_impl_t::find (std::shared_ptr &writers, const std::string &criteria) { int rc = -1; vtx_t root; @@ -1183,14 +1202,13 @@ int dfu_impl_t::find (std::shared_ptr &writers, return rc; } const subsystem_t &dom = m_match->dom_subsystem (); - if (m_graph_db->metadata.roots.find (dom) - == m_graph_db->metadata.roots.end ()) { + if (m_graph_db->metadata.roots.find (dom) == m_graph_db->metadata.roots.end ()) { errno = EINVAL; goto done; } root = m_graph_db->metadata.roots.at (dom); target.initialize (p_overridden, m_graph, root); - if ( (rc = m_expr_eval.validate (criteria, target)) < 0) { + if ((rc = m_expr_eval.validate (criteria, target)) < 0) { m_err_msg += __FUNCTION__; m_err_msg += ": invalid criteria: " + criteria + ".\n"; goto done; @@ -1198,7 +1216,7 @@ int dfu_impl_t::find (std::shared_ptr &writers, tick (); - if ( (rc = dom_find_dfv (writers, criteria, root, p_overridden)) < 0) + if ((rc = dom_find_dfv (writers, criteria, root, p_overridden)) < 0) goto done; if (writers->emit_tm (0, 0) == -1) { @@ -1207,10 +1225,9 @@ int dfu_impl_t::find (std::shared_ptr &writers, } done: - return (rc >= 0)? 0: -1; + return (rc >= 0) ? 0 : -1; } - /* * vi:tabstop=4 shiftwidth=4 expandtab */ diff --git a/resource/traversers/dfu_impl.hpp b/resource/traversers/dfu_impl.hpp index 09b96aa83..7d239a6e1 100644 --- a/resource/traversers/dfu_impl.hpp +++ b/resource/traversers/dfu_impl.hpp @@ -35,13 +35,9 @@ namespace detail { enum class visit_t { DFV, UPV }; -enum class match_kind_t { RESOURCE_MATCH, - SLOT_MATCH, - NONE_MATCH, - PRISTINE_NONE_MATCH }; +enum class match_kind_t { RESOURCE_MATCH, SLOT_MATCH, NONE_MATCH, PRISTINE_NONE_MATCH }; struct jobmeta_t { - enum class alloc_type_t : int { AT_ALLOC = 0, AT_ALLOC_ORELSE_RESERVE = 1, @@ -52,26 +48,32 @@ struct jobmeta_t { int64_t jobid = -1; int64_t at = -1; int64_t now = -1; - uint64_t duration = SYSTEM_DEFAULT_DURATION; // will need config ultimately - std::shared_ptr constraint; + uint64_t duration = SYSTEM_DEFAULT_DURATION; // will need config ultimately + std::shared_ptr constraint; - bool is_queue_set () const { + bool is_queue_set () const + { return m_queue_set; } - const std::string &get_queue () const { + const std::string &get_queue () const + { return m_queue; } - int build (Jobspec::Jobspec &jobspec, alloc_type_t alloc, int64_t id, - int64_t t, graph_duration_t &graph_duration) + int build (Jobspec::Jobspec &jobspec, + alloc_type_t alloc, + int64_t id, + int64_t t, + graph_duration_t &graph_duration) { at = t; now = t; jobid = id; alloc_type = alloc; - int64_t g_duration = std::chrono::duration_cast - (graph_duration.graph_end - graph_duration.graph_start).count (); + int64_t g_duration = std::chrono::duration_cast ( + graph_duration.graph_end - graph_duration.graph_start) + .count (); if (g_duration <= 0) { errno = EINVAL; @@ -79,10 +81,9 @@ struct jobmeta_t { } // Ensure that duration is shorter than expressible // int64_t max () for comparison with at in dfu_traverser_t::run - if ( (jobspec.attributes.system.duration > - static_cast (g_duration)) - || (jobspec.attributes.system.duration > - static_cast (std::numeric_limits::max ()))) { + if ((jobspec.attributes.system.duration > static_cast (g_duration)) + || (jobspec.attributes.system.duration + > static_cast (std::numeric_limits::max ()))) { errno = EINVAL; return -1; } @@ -99,19 +100,17 @@ struct jobmeta_t { return 0; } -private: + private: bool m_queue_set = false; std::string m_queue = ""; }; - /*! implementation class of dfu_traverser_t */ class dfu_impl_t { -public: + public: dfu_impl_t (); - dfu_impl_t (std::shared_ptr db, - std::shared_ptr m); + dfu_impl_t (std::shared_ptr db, std::shared_ptr m); dfu_impl_t (const dfu_impl_t &o); dfu_impl_t (dfu_impl_t &&o); dfu_impl_t &operator= (const dfu_impl_t &o); @@ -159,8 +158,9 @@ class dfu_impl_t { * \return 0 on success; -1 on error -- call err_message () * for detail. */ - int prime_pruning_filter (const subsystem_t &subsystem, vtx_t u, - std::map &to_parent); + int prime_pruning_filter (const subsystem_t &subsystem, + vtx_t u, + std::map &to_parent); /*! Prime the resource section of the jobspec. Aggregate configured * subtree resources into jobspec's user_data. For example, @@ -191,8 +191,9 @@ class dfu_impl_t { * output array. * \return 0 on success; -1 on error. */ - template - int count_relevant_types (planner_multi_t *plan, const lookup_t &lookup, + template + int count_relevant_types (planner_multi_t *plan, + const lookup_t &lookup, std::vector &resource_counts); /*! Entry point for graph matching and scoring depth-first-and-up (DFU) walk. @@ -216,8 +217,7 @@ class dfu_impl_t { * \return 0 on success; -1 on error -- call err_message () * for detail. */ - int select (Jobspec::Jobspec &jobspec, vtx_t root, jobmeta_t &meta, - bool exclusive); + int select (Jobspec::Jobspec &jobspec, vtx_t root, jobmeta_t &meta, bool exclusive); /*! Traverse the resource graph and emit those resources whose * status is matched with the matching criteria. @@ -243,8 +243,7 @@ class dfu_impl_t { * ignored. * \return 0 on success; -1 on error. */ - int find (std::shared_ptr &writers, - const std::string &criteria); + int find (std::shared_ptr &writers, const std::string &criteria); /*! Update the resource state based on the previous select invocation * and emit the allocation/reservation information. @@ -257,8 +256,7 @@ class dfu_impl_t { * \return 0 on success; -1 on error -- call err_message () * for detail. */ - int update (vtx_t root, std::shared_ptr &writers, - jobmeta_t &meta); + int update (vtx_t root, std::shared_ptr &writers, jobmeta_t &meta); /*! Update the resource state based on the allocation data (str) * as deserialized by reader and meta. @@ -271,7 +269,8 @@ class dfu_impl_t { * \return 0 on success; -1 on error -- call err_message () * for detail. */ - int update (vtx_t root, std::shared_ptr &writers, + int update (vtx_t root, + std::shared_ptr &writers, const std::string &str, std::shared_ptr &reader, jobmeta_t &meta); @@ -303,9 +302,11 @@ class dfu_impl_t { * job resources * \return 0 on success; -1 on error. */ - int remove (vtx_t root, const std::string &to_cancel, + int remove (vtx_t root, + const std::string &to_cancel, std::shared_ptr &reader, - int64_t jobid, bool &full_cancel); + int64_t jobid, + bool &full_cancel); /*! Update the resource status to up|down|etc starting at subtree_root. * @@ -316,7 +317,7 @@ class dfu_impl_t { */ int mark (const std::string &root_path, resource_pool_t::status_t status); - /*! Update the resource status to up|down|etc for subgraph + /*! Update the resource status to up|down|etc for subgraph * represented by ranks. * * \param ranks set of ranks representing the subgraphs to update. @@ -326,8 +327,7 @@ class dfu_impl_t { */ int mark (std::set &ranks, resource_pool_t::status_t status); -private: - + private: /************************************************************************ * * * Private Match and Util API * @@ -343,166 +343,240 @@ class dfu_impl_t { bool get_eff_exclusive (bool x, bool mod) const; unsigned get_eff_needs (unsigned needs, unsigned size, bool mod) const; - /*! Various pruning methods */ - int by_avail (const jobmeta_t &meta, const std::string &s, vtx_t u, + int by_avail (const jobmeta_t &meta, + const std::string &s, + vtx_t u, const std::vector &resources); - int by_excl (const jobmeta_t &meta, const std::string &s, vtx_t u, - bool exclusive_in, const Jobspec::Resource &resource); - int by_subplan (const jobmeta_t &meta, const std::string &s, vtx_t u, + int by_excl (const jobmeta_t &meta, + const std::string &s, + vtx_t u, + bool exclusive_in, + const Jobspec::Resource &resource); + int by_subplan (const jobmeta_t &meta, + const std::string &s, + vtx_t u, const Jobspec::Resource &resource); - int prune (const jobmeta_t &meta, bool excl, const std::string &subsystem, - vtx_t u, const std::vector &resources); - - planner_multi_t *subtree_plan (vtx_t u, std::vector &avail, + int prune (const jobmeta_t &meta, + bool excl, + const std::string &subsystem, + vtx_t u, + const std::vector &resources); + + planner_multi_t *subtree_plan (vtx_t u, + std::vector &avail, std::vector &types); /*! Test various matching conditions between jobspec and graph * including slot match */ - int match (vtx_t u, const std::vector &resources, - const Jobspec::Resource **slot_resource, unsigned int *nslots, - const Jobspec::Resource **match_resource); + int match (vtx_t u, + const std::vector &resources, + const Jobspec::Resource **slot_resource, + unsigned int *nslots, + const Jobspec::Resource **match_resource); bool slot_match (vtx_t u, const Jobspec::Resource *slot_resource); const std::vector &test (vtx_t u, - const std::vector &resources, - bool &prestine, unsigned int &nslots, match_kind_t &ko); + const std::vector &resources, + bool &prestine, + unsigned int &nslots, + match_kind_t &ko); bool is_pconstraint_matched (vtx_t u, const std::string &property); - /*! Accumulate count into accum if type matches with one of the resource * types used in the scheduler-driven aggregate update (SDAU) scheme. * dfu_match_cb_t provides an interface to configure what types are used * for SDAU scheme. */ - int accum_if (const subsystem_t &subsystem, const std::string &type, - unsigned int count, std::map &accum); - int accum_if (const subsystem_t &subsystem, const std::string &type, + int accum_if (const subsystem_t &subsystem, + const std::string &type, + unsigned int count, + std::map &accum); + int accum_if (const subsystem_t &subsystem, + const std::string &type, unsigned int count, std::unordered_map &accum); // Explore out-edges for priming the subtree plans - int prime_exp (const subsystem_t &subsystem, - vtx_t u, std::map &dfv); + int prime_exp (const subsystem_t &subsystem, vtx_t u, std::map &dfv); // Explore for resource matching -- only DFV or UPV - int explore (const jobmeta_t &meta, vtx_t u, const subsystem_t &subsystem, - const std::vector &resources, bool prestine, - bool *excl, visit_t direction, scoring_api_t &dfu, - unsigned int multiplier=1); - int explore_statically (const jobmeta_t &meta, vtx_t u, + int explore (const jobmeta_t &meta, + vtx_t u, + const subsystem_t &subsystem, + const std::vector &resources, + bool prestine, + bool *excl, + visit_t direction, + scoring_api_t &dfu, + unsigned int multiplier = 1); + int explore_statically (const jobmeta_t &meta, + vtx_t u, const subsystem_t &subsystem, const std::vector &resources, - bool prestine, bool *excl, visit_t direction, + bool prestine, + bool *excl, + visit_t direction, scoring_api_t &dfu); - int explore_dynamically (const jobmeta_t &meta, vtx_t u, + int explore_dynamically (const jobmeta_t &meta, + vtx_t u, const subsystem_t &subsystem, const std::vector &resources, - bool prestine, bool *excl, visit_t direction, - scoring_api_t &dfu, unsigned int multiplier=1); + bool prestine, + bool *excl, + visit_t direction, + scoring_api_t &dfu, + unsigned int multiplier = 1); bool is_enough (const subsystem_t &subsystem, const std::vector &resources, - scoring_api_t &dfu, unsigned int multiplier); + scoring_api_t &dfu, + unsigned int multiplier); int new_sat_types (const subsystem_t &subsystem, const std::vector &resources, - scoring_api_t &dfu, unsigned int multiplier, + scoring_api_t &dfu, + unsigned int multiplier, std::set &sat_types); - int aux_upv (const jobmeta_t &meta, vtx_t u, const subsystem_t &subsystem, - const std::vector &resources, bool prestine, - bool *excl, scoring_api_t &to_parent); - int cnt_slot (const std::vector &slot_shape, - scoring_api_t &dfu_slot); - int dom_slot (const jobmeta_t &meta, vtx_t u, + int aux_upv (const jobmeta_t &meta, + vtx_t u, + const subsystem_t &subsystem, + const std::vector &resources, + bool prestine, + bool *excl, + scoring_api_t &to_parent); + int cnt_slot (const std::vector &slot_shape, scoring_api_t &dfu_slot); + int dom_slot (const jobmeta_t &meta, + vtx_t u, const std::vector &resources, - unsigned int nslots, bool prestine, - bool *excl, scoring_api_t &dfu); - int dom_exp (const jobmeta_t &meta, vtx_t u, - const std::vector &resources, bool prestine, - bool *excl, scoring_api_t &to_parent); - int dom_dfv (const jobmeta_t &meta, vtx_t u, - const std::vector &resources, bool prestine, - bool *excl, scoring_api_t &to_parent); + unsigned int nslots, + bool prestine, + bool *excl, + scoring_api_t &dfu); + int dom_exp (const jobmeta_t &meta, + vtx_t u, + const std::vector &resources, + bool prestine, + bool *excl, + scoring_api_t &to_parent); + int dom_dfv (const jobmeta_t &meta, + vtx_t u, + const std::vector &resources, + bool prestine, + bool *excl, + scoring_api_t &to_parent); int dom_find_dfv (std::shared_ptr &writers, const std::string &criteria, - vtx_t u, const vtx_predicates_override_t &p); + vtx_t u, + const vtx_predicates_override_t &p); int aux_find_upv (std::shared_ptr &writers, const std::string &criteria, - vtx_t u, const subsystem_t &aux, + vtx_t u, + const subsystem_t &aux, const vtx_predicates_override_t &p); - - int has_root (vtx_t root, std::vector &resources, - scoring_api_t &dfu, unsigned int *needs); - int has_remaining (vtx_t root, std::vector &resources, - scoring_api_t &dfu); + int has_root (vtx_t root, + std::vector &resources, + scoring_api_t &dfu, + unsigned int *needs); + int has_remaining (vtx_t root, std::vector &resources, scoring_api_t &dfu); // Resolve and enforce hierarchical constraints - int resolve_graph (vtx_t root, std::vector &resources, - scoring_api_t &dfu, bool excl, unsigned int *needs); + int resolve_graph (vtx_t root, + std::vector &resources, + scoring_api_t &dfu, + bool excl, + unsigned int *needs); int resolve (scoring_api_t &dfu, scoring_api_t &to_parent); int enforce (const subsystem_t &subsystem, scoring_api_t &dfu); int enforce_constrained (scoring_api_t &dfu); int enforce_dfv (vtx_t u, scoring_api_t &dfu); int enforce_remaining (vtx_t u, scoring_api_t &dfu); - /************************************************************************ * * * Private Update/Emit/Remove API * * * ************************************************************************/ // Emit matched resource set - int emit_vtx (vtx_t u, std::shared_ptr &w, - unsigned int needs, bool exclusive); + int emit_vtx (vtx_t u, std::shared_ptr &w, unsigned int needs, bool exclusive); int emit_edg (edg_t e, std::shared_ptr &w); // Update resource graph data store - int upd_txfilter (vtx_t u, const jobmeta_t &jobmeta, - const std::map &dfu); - int upd_agfilter (vtx_t u, const subsystem_t &s, const jobmeta_t &jobmeta, + int upd_txfilter (vtx_t u, const jobmeta_t &jobmeta, const std::map &dfu); + int upd_agfilter (vtx_t u, + const subsystem_t &s, + const jobmeta_t &jobmeta, const std::map &dfu); - int upd_idata (vtx_t u, const subsystem_t &s, const jobmeta_t &jobmeta, + int upd_idata (vtx_t u, + const subsystem_t &s, + const jobmeta_t &jobmeta, const std::map &dfu); - int upd_by_outedges (const subsystem_t &subsystem, - const jobmeta_t &jobmeta, vtx_t u, edg_t e); - int upd_plan (vtx_t u, const subsystem_t &s, unsigned int needs, - bool excl, const jobmeta_t &jobmeta, bool full, int &n); - int accum_to_parent (vtx_t u, const subsystem_t &s, unsigned int needs, - bool excl, const std::map &dfu, + int upd_by_outedges (const subsystem_t &subsystem, const jobmeta_t &jobmeta, vtx_t u, edg_t e); + int upd_plan (vtx_t u, + const subsystem_t &s, + unsigned int needs, + bool excl, + const jobmeta_t &jobmeta, + bool full, + int &n); + int accum_to_parent (vtx_t u, + const subsystem_t &s, + unsigned int needs, + bool excl, + const std::map &dfu, std::map &to_parent); - int upd_meta (vtx_t u, const subsystem_t &s, unsigned int needs, bool excl, - int n, const jobmeta_t &jobmeta, + int upd_meta (vtx_t u, + const subsystem_t &s, + unsigned int needs, + bool excl, + int n, + const jobmeta_t &jobmeta, const std::map &dfu, std::map &to_parent); - int upd_sched (vtx_t u, std::shared_ptr &writers, - const subsystem_t &s, unsigned int needs, - bool excl, int n, const jobmeta_t &jobmeta, bool full, + int upd_sched (vtx_t u, + std::shared_ptr &writers, + const subsystem_t &s, + unsigned int needs, + bool excl, + int n, + const jobmeta_t &jobmeta, + bool full, const std::map &dfu, std::map &to_parent); - int upd_upv (vtx_t u, std::shared_ptr &writers, - const subsystem_t &subsystem, unsigned int needs, bool excl, - const jobmeta_t &jobmeta, bool full, + int upd_upv (vtx_t u, + std::shared_ptr &writers, + const subsystem_t &subsystem, + unsigned int needs, + bool excl, + const jobmeta_t &jobmeta, + bool full, std::map &to_parent); - int upd_dfv (vtx_t u, std::shared_ptr &writers, - unsigned int needs, bool excl, const jobmeta_t &jobmeta, - bool full, std::map &to_parent, + int upd_dfv (vtx_t u, + std::shared_ptr &writers, + unsigned int needs, + bool excl, + const jobmeta_t &jobmeta, + bool full, + std::map &to_parent, bool emit_shadow); bool rem_tag (vtx_t u, int64_t jobid); - int rem_exclusive_filter (vtx_t u, int64_t jobid, - const modify_data_t &mod_data); - int mod_agfilter (vtx_t u, int64_t jobid, const std::string &s, - const modify_data_t &mod_data, bool &stop); - int mod_idata (vtx_t u, int64_t jobid, const std::string &s, - const modify_data_t &mod_data, bool &stop); + int rem_exclusive_filter (vtx_t u, int64_t jobid, const modify_data_t &mod_data); + int mod_agfilter (vtx_t u, + int64_t jobid, + const std::string &s, + const modify_data_t &mod_data, + bool &stop); + int mod_idata (vtx_t u, + int64_t jobid, + const std::string &s, + const modify_data_t &mod_data, + bool &stop); int mod_plan (vtx_t u, int64_t jobid, modify_data_t &mod_data); int mod_upv (vtx_t u, int64_t jobid, const modify_data_t &mod_data); int mod_dfv (vtx_t u, int64_t jobid, modify_data_t &mod_data); int mod_exv (int64_t jobid, const modify_data_t &mod_data); - int cancel_vertex (vtx_t vtx, modify_data_t &mod_data, - int64_t jobid); - + int cancel_vertex (vtx_t vtx, modify_data_t &mod_data, int64_t jobid); /************************************************************************ * * @@ -520,12 +594,12 @@ class dfu_impl_t { std::shared_ptr m_match = nullptr; expr_eval_api_t m_expr_eval; std::string m_err_msg = ""; -}; // the end of class dfu_impl_t +}; // the end of class dfu_impl_t -template +template int dfu_impl_t::count_relevant_types (planner_multi_t *plan, - const lookup_t &lookup, - std::vector &resource_counts) + const lookup_t &lookup, + std::vector &resource_counts) { int rc = 0; size_t len = planner_multi_resources_len (plan); @@ -542,11 +616,11 @@ int dfu_impl_t::count_relevant_types (planner_multi_t *plan, return rc; } -} // namespace detail -} // namespace resource_model -} // namespace Flux +} // namespace detail +} // namespace resource_model +} // namespace Flux -#endif // DFU_TRAVERSE_HPP +#endif // DFU_TRAVERSE_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/traversers/dfu_impl_update.cpp b/resource/traversers/dfu_impl_update.cpp index 710ee07b4..ce9915144 100644 --- a/resource/traversers/dfu_impl_update.cpp +++ b/resource/traversers/dfu_impl_update.cpp @@ -20,24 +20,25 @@ using namespace Flux::Jobspec; using namespace Flux::resource_model; using namespace Flux::resource_model::detail; - - //////////////////////////////////////////////////////////////////////////////// // DFU Traverser Implementation Private Update API //////////////////////////////////////////////////////////////////////////////// -int dfu_impl_t::emit_vtx (vtx_t u, std::shared_ptr &w, - unsigned int needs, bool exclusive) +int dfu_impl_t::emit_vtx (vtx_t u, + std::shared_ptr &w, + unsigned int needs, + bool exclusive) { return w->emit_vtx (level (), (*m_graph), u, needs, exclusive); } int dfu_impl_t::emit_edg (edg_t e, std::shared_ptr &w) { - return w->emit_edg (level (), (*m_graph), e); + return w->emit_edg (level (), (*m_graph), e); } -int dfu_impl_t::upd_txfilter (vtx_t u, const jobmeta_t &jobmeta, +int dfu_impl_t::upd_txfilter (vtx_t u, + const jobmeta_t &jobmeta, const std::map &dfu) { // idata tag and exclusive checker update @@ -47,13 +48,12 @@ int dfu_impl_t::upd_txfilter (vtx_t u, const jobmeta_t &jobmeta, // Tag on a vertex with exclusive access or all of its ancestors (*m_graph)[u].idata.tags[jobmeta.jobid] = jobmeta.jobid; // Update x_checker used for quick exclusivity check during matching - if ( (x_checker = (*m_graph)[u].idata.x_checker) == NULL) { + if ((x_checker = (*m_graph)[u].idata.x_checker) == NULL) { m_err_msg += __FUNCTION__; m_err_msg += ": x_checker not installed.\n"; return -1; } - if ( (span = planner_add_span (x_checker, jobmeta.at, - jobmeta.duration, 1)) == -1) { + if ((span = planner_add_span (x_checker, jobmeta.at, jobmeta.duration, 1)) == -1) { m_err_msg += __FUNCTION__; m_err_msg += ": planner_add_span returned -1.\n"; m_err_msg += strerror (errno); @@ -64,7 +64,8 @@ int dfu_impl_t::upd_txfilter (vtx_t u, const jobmeta_t &jobmeta, return 0; } -int dfu_impl_t::upd_agfilter (vtx_t u, const subsystem_t &s, +int dfu_impl_t::upd_agfilter (vtx_t u, + const subsystem_t &s, const jobmeta_t &jobmeta, const std::map &dfu) { @@ -77,8 +78,10 @@ int dfu_impl_t::upd_agfilter (vtx_t u, const subsystem_t &s, // using the new aggregates passed by dfu. count_relevant_types (subtree_plan, dfu, aggregate); span = planner_multi_add_span (subtree_plan, - jobmeta.at, jobmeta.duration, - aggregate.data (), aggregate.size ()); + jobmeta.at, + jobmeta.duration, + aggregate.data (), + aggregate.size ()); if (span == -1) { m_err_msg += __FUNCTION__; m_err_msg += ": planner_multi_add_span returned -1.\n"; @@ -91,27 +94,30 @@ int dfu_impl_t::upd_agfilter (vtx_t u, const subsystem_t &s, return 0; } -int dfu_impl_t::upd_idata (vtx_t u, const subsystem_t &s, - const jobmeta_t &jobmeta, - const std::map &dfu) +int dfu_impl_t::upd_idata (vtx_t u, + const subsystem_t &s, + const jobmeta_t &jobmeta, + const std::map &dfu) { int rc = 0; - if ( (rc = upd_txfilter (u, jobmeta, dfu)) != 0) + if ((rc = upd_txfilter (u, jobmeta, dfu)) != 0) goto done; - if ( (rc = upd_agfilter (u, s, jobmeta, dfu)) != 0) + if ((rc = upd_agfilter (u, s, jobmeta, dfu)) != 0) goto done; done: return rc; } int dfu_impl_t::upd_by_outedges (const subsystem_t &subsystem, - const jobmeta_t &jobmeta, vtx_t u, edg_t e) + const jobmeta_t &jobmeta, + vtx_t u, + edg_t e) { size_t len = 0; vtx_t tgt = target (e, *m_graph); planner_multi_t *subplan = (*m_graph)[tgt].idata.subplans[subsystem]; if (subplan) { - if ( (len = planner_multi_resources_len (subplan)) == 0) + if ((len = planner_multi_resources_len (subplan)) == 0) return -1; // Set dynamic traversing order based on the following heuristics: @@ -119,24 +125,20 @@ int dfu_impl_t::upd_by_outedges (const subsystem_t &subsystem, // 2. Last pruning filter resource type (if additional // pruning filter type was given, that's a good // indication that it is the scarcest resource) - int64_t avail = planner_multi_avail_resources_at (subplan, - jobmeta.now, len - 1); + int64_t avail = planner_multi_avail_resources_at (subplan, jobmeta.now, len - 1); // Special case to skip (e.g., leaf resource vertices) if (avail == 0 && planner_multi_span_size (subplan) == 0) return 0; - auto key = std::make_pair ((*m_graph)[e].idata.get_weight (), - (*m_graph)[tgt].uniq_id); + auto key = std::make_pair ((*m_graph)[e].idata.get_weight (), (*m_graph)[tgt].uniq_id); m_graph_db->metadata.by_outedges[u].erase (key); - (*m_graph)[e].idata.set_weight ((avail == -1)? 0 : avail); - key = std::make_pair ((*m_graph)[e].idata.get_weight (), - (*m_graph)[tgt].uniq_id); + (*m_graph)[e].idata.set_weight ((avail == -1) ? 0 : avail); + key = std::make_pair ((*m_graph)[e].idata.get_weight (), (*m_graph)[tgt].uniq_id); // Reinsert so that outedges are maintained according to the current // resource availability state. Leverage the fact that std::map // uses a RedBlack tree keep its elemented in sorted order. - auto ret = m_graph_db->metadata.by_outedges[u].insert ( - std::make_pair (key, e)); + auto ret = m_graph_db->metadata.by_outedges[u].insert (std::make_pair (key, e)); if (!ret.second) { errno = ENOMEM; return -1; @@ -145,8 +147,12 @@ int dfu_impl_t::upd_by_outedges (const subsystem_t &subsystem, return 0; } -int dfu_impl_t::upd_plan (vtx_t u, const subsystem_t &s, unsigned int needs, - bool excl, const jobmeta_t &jobmeta, bool full, +int dfu_impl_t::upd_plan (vtx_t u, + const subsystem_t &s, + unsigned int needs, + bool excl, + const jobmeta_t &jobmeta, + bool full, int &n) { int rc = 0; @@ -160,12 +166,12 @@ int dfu_impl_t::upd_plan (vtx_t u, const subsystem_t &s, unsigned int needs, return 0; } - if ( (plans = (*m_graph)[u].schedule.plans) == NULL) { + if ((plans = (*m_graph)[u].schedule.plans) == NULL) { m_err_msg += __FUNCTION__; m_err_msg += ": plans not installed.\n"; } - if ( (span = planner_add_span (plans, jobmeta.at, jobmeta.duration, - (const uint64_t)needs)) == -1) { + if ((span = planner_add_span (plans, jobmeta.at, jobmeta.duration, (const uint64_t)needs)) + == -1) { m_err_msg += __FUNCTION__; m_err_msg += ": planner_add_span returned -1.\n"; if (errno != 0) { @@ -177,18 +183,18 @@ int dfu_impl_t::upd_plan (vtx_t u, const subsystem_t &s, unsigned int needs, } switch (jobmeta.alloc_type) { - case jobmeta_t::alloc_type_t::AT_ALLOC: - (*m_graph)[u].schedule.allocations[jobmeta.jobid] = span; - break; - case jobmeta_t::alloc_type_t::AT_ALLOC_ORELSE_RESERVE: - (*m_graph)[u].schedule.reservations[jobmeta.jobid] = span; - break; - case jobmeta_t::alloc_type_t::AT_SATISFIABILITY: - break; - default: - rc = -1; - errno = EINVAL; - break; + case jobmeta_t::alloc_type_t::AT_ALLOC: + (*m_graph)[u].schedule.allocations[jobmeta.jobid] = span; + break; + case jobmeta_t::alloc_type_t::AT_ALLOC_ORELSE_RESERVE: + (*m_graph)[u].schedule.reservations[jobmeta.jobid] = span; + break; + case jobmeta_t::alloc_type_t::AT_SATISFIABILITY: + break; + default: + rc = -1; + errno = EINVAL; + break; } } @@ -196,8 +202,10 @@ int dfu_impl_t::upd_plan (vtx_t u, const subsystem_t &s, unsigned int needs, return rc; } -int dfu_impl_t::accum_to_parent (vtx_t u, const subsystem_t &subsystem, - unsigned int needs, bool excl, +int dfu_impl_t::accum_to_parent (vtx_t u, + const subsystem_t &subsystem, + unsigned int needs, + bool excl, const std::map &dfu, std::map &to_parent) { @@ -205,11 +213,9 @@ int dfu_impl_t::accum_to_parent (vtx_t u, const subsystem_t &subsystem, // aggregate pruning filter. If exclusive, none of the vertex's resource // is available (size). If not, all will be available (size - needs). if (excl) - accum_if (subsystem, - (*m_graph)[u].type, (*m_graph)[u].size, to_parent); + accum_if (subsystem, (*m_graph)[u].type, (*m_graph)[u].size, to_parent); else - accum_if (subsystem, - (*m_graph)[u].type, (*m_graph)[u].size - needs, to_parent); + accum_if (subsystem, (*m_graph)[u].type, (*m_graph)[u].size - needs, to_parent); // Pass up the new subtree aggregates collected so far to the parent. for (auto &kv : dfu) @@ -218,36 +224,45 @@ int dfu_impl_t::accum_to_parent (vtx_t u, const subsystem_t &subsystem, return 0; } -int dfu_impl_t::upd_meta (vtx_t u, const subsystem_t &s, unsigned int needs, - bool excl, int n, const jobmeta_t &jobmeta, +int dfu_impl_t::upd_meta (vtx_t u, + const subsystem_t &s, + unsigned int needs, + bool excl, + int n, + const jobmeta_t &jobmeta, const std::map &dfu, std::map &to_parent) { int rc = 0; if (n == 0) goto done; - if ( (rc = upd_idata (u, s, jobmeta, dfu)) == -1) + if ((rc = upd_idata (u, s, jobmeta, dfu)) == -1) goto done; - if ( (rc = accum_to_parent (u, s, needs, excl, dfu, to_parent)) == -1) + if ((rc = accum_to_parent (u, s, needs, excl, dfu, to_parent)) == -1) goto done; done: return rc; } -int dfu_impl_t::upd_sched (vtx_t u, std::shared_ptr &writers, - const subsystem_t &s, unsigned int needs, bool excl, - int n, const jobmeta_t &jobmeta, bool full, +int dfu_impl_t::upd_sched (vtx_t u, + std::shared_ptr &writers, + const subsystem_t &s, + unsigned int needs, + bool excl, + int n, + const jobmeta_t &jobmeta, + bool full, const std::map &dfu, std::map &to_parent) { int rc = -1; - if ( (rc = upd_plan (u, s, needs, excl, jobmeta, full, n)) == -1) + if ((rc = upd_plan (u, s, needs, excl, jobmeta, full, n)) == -1) goto done; - if ( (rc = upd_meta (u, s, needs, excl, n, jobmeta, dfu, to_parent)) == -1) { + if ((rc = upd_meta (u, s, needs, excl, n, jobmeta, dfu, to_parent)) == -1) { goto done; } if (n > 0) { - if ( (rc = emit_vtx (u, writers, needs, excl)) == -1) { + if ((rc = emit_vtx (u, writers, needs, excl)) == -1) { m_err_msg += __FUNCTION__; m_err_msg += ": emit_vtx returned -1.\n"; } @@ -258,13 +273,16 @@ int dfu_impl_t::upd_sched (vtx_t u, std::shared_ptr &writers, return n; } -int dfu_impl_t::upd_upv (vtx_t u, std::shared_ptr &writers, +int dfu_impl_t::upd_upv (vtx_t u, + std::shared_ptr &writers, const subsystem_t &subsystem, - unsigned int needs, bool excl, - const jobmeta_t &jobmeta, bool full, + unsigned int needs, + bool excl, + const jobmeta_t &jobmeta, + bool full, std::map &to_parent) { - //NYI: update resources on the UPV direction + // NYI: update resources on the UPV direction return 0; } @@ -272,8 +290,7 @@ bool dfu_impl_t::modify_traversal (vtx_t u, bool emit_shadow_from_parent) const { // We modify our traversal if the parent says so if the // visiting vertex resource type is exclusive by configuration - return emit_shadow_from_parent - || m_match->is_resource_type_exclusive ((*m_graph)[u].type); + return emit_shadow_from_parent || m_match->is_resource_type_exclusive ((*m_graph)[u].type); } bool dfu_impl_t::stop_explore_best (edg_t e, bool mod_trav) const @@ -286,15 +303,17 @@ bool dfu_impl_t::get_eff_exclusive (bool x, bool mod_trav) const return x || mod_trav; } -unsigned dfu_impl_t::get_eff_needs (unsigned needs, - unsigned size, bool mod_trav) const +unsigned dfu_impl_t::get_eff_needs (unsigned needs, unsigned size, bool mod_trav) const { - return mod_trav? size : needs; + return mod_trav ? size : needs; } -int dfu_impl_t::upd_dfv (vtx_t u, std::shared_ptr &writers, - unsigned int needs, bool excl, - const jobmeta_t &jobmeta, bool full, +int dfu_impl_t::upd_dfv (vtx_t u, + std::shared_ptr &writers, + unsigned int needs, + bool excl, + const jobmeta_t &jobmeta, + bool full, std::map &to_parent, bool emit_shadow) { @@ -315,18 +334,14 @@ int dfu_impl_t::upd_dfv (vtx_t u, std::shared_ptr &writers, vtx_t tgt = target (*ei, *m_graph); int n_plan_sub = 0; - bool x = get_eff_exclusive ( - (*m_graph)[*ei].idata.get_exclusive (), mod); - unsigned needs = get_eff_needs ( - (*m_graph)[*ei].idata.get_needs (), - (*m_graph)[tgt].size, mod); + bool x = get_eff_exclusive ((*m_graph)[*ei].idata.get_exclusive (), mod); + unsigned needs = + get_eff_needs ((*m_graph)[*ei].idata.get_needs (), (*m_graph)[tgt].size, mod); if (subsystem == dom) { - n_plan_sub += upd_dfv (tgt, writers, - needs, x, jobmeta, full, dfu, mod); + n_plan_sub += upd_dfv (tgt, writers, needs, x, jobmeta, full, dfu, mod); } else { - n_plan_sub += upd_upv (tgt, writers, subsystem, - needs, x, jobmeta, full, dfu); + n_plan_sub += upd_upv (tgt, writers, subsystem, needs, x, jobmeta, full, dfu); } if (n_plan_sub > 0) { @@ -344,12 +359,10 @@ int dfu_impl_t::upd_dfv (vtx_t u, std::shared_ptr &writers, } } (*m_graph)[u].idata.colors[dom] = m_color.black (); - return upd_sched (u, writers, dom, needs, - excl, n_plans, jobmeta, full, dfu, to_parent); + return upd_sched (u, writers, dom, needs, excl, n_plans, jobmeta, full, dfu, to_parent); } -int dfu_impl_t::rem_exclusive_filter (vtx_t u, int64_t jobid, - const modify_data_t &mod_data) +int dfu_impl_t::rem_exclusive_filter (vtx_t u, int64_t jobid, const modify_data_t &mod_data) { int rc = -1; int64_t span = -1; @@ -370,7 +383,7 @@ int dfu_impl_t::rem_exclusive_filter (vtx_t u, int64_t jobid, x_checker = (*m_graph)[u].idata.x_checker; span = span_it->second; (*m_graph)[u].idata.x_spans.erase (span_it); - if ( (rc = planner_rem_span (x_checker, span)) == -1) { + if ((rc = planner_rem_span (x_checker, span)) == -1) { m_err_msg += __FUNCTION__; m_err_msg += "planner_rem_span returned -1.\n"; m_err_msg += (*m_graph)[u].name + ".\n"; @@ -394,7 +407,8 @@ bool dfu_impl_t::rem_tag (vtx_t u, int64_t jobid) } } -int dfu_impl_t::mod_agfilter (vtx_t u, int64_t jobid, +int dfu_impl_t::mod_agfilter (vtx_t u, + int64_t jobid, const std::string &subsystem, const modify_data_t &mod_data, bool &stop) @@ -405,7 +419,7 @@ int dfu_impl_t::mod_agfilter (vtx_t u, int64_t jobid, auto &job2span = (*m_graph)[u].idata.job2span; std::map::iterator span_it; - if ( (subtree_plan = (*m_graph)[u].idata.subplans[subsystem]) == NULL) + if ((subtree_plan = (*m_graph)[u].idata.subplans[subsystem]) == NULL) goto done; span_it = job2span.find (jobid); @@ -419,8 +433,7 @@ int dfu_impl_t::mod_agfilter (vtx_t u, int64_t jobid, goto done; } if (mod_data.mod_type != job_modify_t::PARTIAL_CANCEL) { - if ( (rc = planner_multi_rem_span (subtree_plan, - span_it->second)) != 0) { + if ((rc = planner_multi_rem_span (subtree_plan, span_it->second)) != 0) { m_err_msg += __FUNCTION__; m_err_msg += ": planner_multi_rem_span returned -1.\n"; m_err_msg += (*m_graph)[u].name + ".\n"; @@ -429,9 +442,8 @@ int dfu_impl_t::mod_agfilter (vtx_t u, int64_t jobid, goto done; } job2span.erase (span_it); - } else { // PARTIAL_CANCEL - if ( (*m_graph)[u].idata.tags.find (jobid) - == (*m_graph)[u].idata.tags.end ()) { + } else { // PARTIAL_CANCEL + if ((*m_graph)[u].idata.tags.find (jobid) == (*m_graph)[u].idata.tags.end ()) { // stop removal stop = true; goto done; @@ -439,9 +451,8 @@ int dfu_impl_t::mod_agfilter (vtx_t u, int64_t jobid, // If not a default/root rank and the rank is still in the graph // but don't remove exclusive filter as allocation may be exclusive // at the subgraph rooted here. - if ( (mod_data.ranks_removed.find ((*m_graph)[u].rank) - == mod_data.ranks_removed.end ()) - && (*m_graph)[u].rank != -1) { + if ((mod_data.ranks_removed.find ((*m_graph)[u].rank) == mod_data.ranks_removed.end ()) + && (*m_graph)[u].rank != -1) { stop = true; goto done; } @@ -452,12 +463,13 @@ int dfu_impl_t::mod_agfilter (vtx_t u, int64_t jobid, reduced_types.push_back (t2ct_it.first); reduced_counts.push_back (t2ct_it.second); } - if ( (rc = planner_multi_reduce_span (subtree_plan, - span_it->second, - reduced_counts.data (), - reduced_types.data (), - mod_data.type_to_count.size (), - removed)) != 0) { + if ((rc = planner_multi_reduce_span (subtree_plan, + span_it->second, + reduced_counts.data (), + reduced_types.data (), + mod_data.type_to_count.size (), + removed)) + != 0) { m_err_msg += __FUNCTION__; m_err_msg += ": planner_multi_reduce_span returned -1.\n"; m_err_msg += (*m_graph)[u].name + ".\n"; @@ -486,16 +498,17 @@ int dfu_impl_t::mod_agfilter (vtx_t u, int64_t jobid, return rc; } -int dfu_impl_t::mod_idata (vtx_t u, int64_t jobid, - const std::string &subsystem, - const modify_data_t &mod_data, - bool &stop) +int dfu_impl_t::mod_idata (vtx_t u, + int64_t jobid, + const std::string &subsystem, + const modify_data_t &mod_data, + bool &stop) { // Only remove the txfilter span and tag first if we're completely // cancelling the vertex if (mod_data.mod_type != job_modify_t::PARTIAL_CANCEL) { // returns true if stopping - if ( (stop = rem_tag (u, jobid))) + if ((stop = rem_tag (u, jobid))) return 0; if (rem_exclusive_filter (u, jobid, mod_data) != 0) return -1; @@ -506,8 +519,7 @@ int dfu_impl_t::mod_idata (vtx_t u, int64_t jobid, return mod_agfilter (u, jobid, subsystem, mod_data, stop); } -int dfu_impl_t::mod_plan (vtx_t u, int64_t jobid, - modify_data_t &mod_data) +int dfu_impl_t::mod_plan (vtx_t u, int64_t jobid, modify_data_t &mod_data) { int rc = 0; int64_t span = -1; @@ -524,7 +536,7 @@ int dfu_impl_t::mod_plan (vtx_t u, int64_t jobid, if (mod_data.mod_type != job_modify_t::PARTIAL_CANCEL) { (*m_graph)[u].schedule.allocations.erase (alloc_span); } - } else if ( (res_span = (*m_graph)[u].schedule.reservations.find (jobid)) + } else if ((res_span = (*m_graph)[u].schedule.reservations.find (jobid)) != (*m_graph)[u].schedule.reservations.end ()) { span = res_span->second; // Can't be PARTIAL_CANCEL @@ -537,7 +549,7 @@ int dfu_impl_t::mod_plan (vtx_t u, int64_t jobid, if (mod_data.mod_type != job_modify_t::PARTIAL_CANCEL) { if (mod_data.mod_type == job_modify_t::VTX_CANCEL) prev_count = planner_span_resource_count (plans, span); - if ( (rc = planner_rem_span (plans, span)) == -1) { + if ((rc = planner_rem_span (plans, span)) == -1) { m_err_msg += __FUNCTION__; m_err_msg += ": planner_rem_span returned -1.\n"; m_err_msg += (*m_graph)[u].name + ".\n"; @@ -549,7 +561,7 @@ int dfu_impl_t::mod_plan (vtx_t u, int64_t jobid, if (mod_data.mod_type == job_modify_t::VTX_CANCEL) { mod_data.type_to_count[(*m_graph)[u].type.c_str ()] += prev_count; } - } else { // PARTIAL_CANCEL + } else { // PARTIAL_CANCEL m_err_msg += __FUNCTION__; m_err_msg += ": traverser tried to remove schedule and span"; m_err_msg += " after vtx_cancel during partial cancel:\n"; @@ -563,25 +575,22 @@ int dfu_impl_t::mod_plan (vtx_t u, int64_t jobid, return rc; } -int dfu_impl_t::mod_upv (vtx_t u, int64_t jobid, - const modify_data_t &mod_data) +int dfu_impl_t::mod_upv (vtx_t u, int64_t jobid, const modify_data_t &mod_data) { // NYI: remove schedule data for upwalk return 0; } -int dfu_impl_t::mod_dfv (vtx_t u, int64_t jobid, - modify_data_t &mod_data) +int dfu_impl_t::mod_dfv (vtx_t u, int64_t jobid, modify_data_t &mod_data) { int rc = 0; bool stop = false; const std::string &dom = m_match->dom_subsystem (); f_out_edg_iterator_t ei, ei_end; - if ( (rc = mod_idata (u, jobid, dom, mod_data, - stop)) != 0 || stop) + if ((rc = mod_idata (u, jobid, dom, mod_data, stop)) != 0 || stop) goto done; - if ( (rc = mod_plan (u, jobid, mod_data)) != 0) + if ((rc = mod_plan (u, jobid, mod_data)) != 0) goto done; for (auto const &subsystem : m_match->subsystems ()) { for (tie (ei, ei_end) = out_edges (u, *m_graph); ei != ei_end; ++ei) { @@ -615,8 +624,7 @@ int dfu_impl_t::mod_exv (int64_t jobid, const modify_data_t &mod_data) // In this case, you can't find allocated resources from an accelerated // depth first visit (dfv). There won't be no idata for that allocation. for (boost::tie (vi, v_end) = boost::vertices (g); vi != v_end; ++vi) { - if (g[*vi].schedule.allocations.find (jobid) - != g[*vi].schedule.allocations.end ()) { + if (g[*vi].schedule.allocations.find (jobid) != g[*vi].schedule.allocations.end ()) { span = g[*vi].schedule.allocations[jobid]; g[*vi].schedule.allocations.erase (jobid); } else if (g[*vi].schedule.reservations.find (jobid) @@ -627,7 +635,7 @@ int dfu_impl_t::mod_exv (int64_t jobid, const modify_data_t &mod_data) continue; } - if ( (rc += planner_rem_span (g[*vi].schedule.plans, span)) == -1) { + if ((rc += planner_rem_span (g[*vi].schedule.plans, span)) == -1) { m_err_msg += __FUNCTION__; m_err_msg += ": planner_rem_span returned -1.\n"; m_err_msg += "name=" + g[*vi].name + "uniq_id="; @@ -637,68 +645,63 @@ int dfu_impl_t::mod_exv (int64_t jobid, const modify_data_t &mod_data) } } - return (!rc)? 0 : -1; + return (!rc) ? 0 : -1; } -int dfu_impl_t::cancel_vertex (vtx_t vtx, modify_data_t &mod_data, - int64_t jobid) +int dfu_impl_t::cancel_vertex (vtx_t vtx, modify_data_t &mod_data, int64_t jobid) { int rc = -1; bool stop = false; const std::string &dom = m_match->dom_subsystem (); - if ( (rc = mod_idata (vtx, jobid, dom, mod_data, stop)) == -1) { + if ((rc = mod_idata (vtx, jobid, dom, mod_data, stop)) == -1) { errno = EINVAL; return rc; } - if ( (rc = mod_plan (vtx, jobid, mod_data)) == -1) + if ((rc = mod_plan (vtx, jobid, mod_data)) == -1) errno = EINVAL; return rc; - } //////////////////////////////////////////////////////////////////////////////// // DFU Traverser Implementation Update API //////////////////////////////////////////////////////////////////////////////// -int dfu_impl_t::update (vtx_t root, std::shared_ptr &writers, - jobmeta_t &jobmeta) +int dfu_impl_t::update (vtx_t root, std::shared_ptr &writers, jobmeta_t &jobmeta) { int rc = -1; std::map dfu; const std::string &dom = m_match->dom_subsystem (); - if (m_graph_db->metadata.v_rt_edges[dom].get_trav_token () - != m_best_k_cnt) { + if (m_graph_db->metadata.v_rt_edges[dom].get_trav_token () != m_best_k_cnt) { m_err_msg += __FUNCTION__; m_err_msg += ": resource state wasn't properly set up for update.\n"; return -1; } unsigned int excl = m_graph_db->metadata.v_rt_edges[dom].get_exclusive (); - bool x = (excl == 0)? false : true; + bool x = (excl == 0) ? false : true; unsigned int needs = m_graph_db->metadata.v_rt_edges[dom].get_needs (); m_color.reset (); bool emit_shadow = modify_traversal (root, false); - if ((rc = upd_dfv (root, writers, needs, - x, jobmeta, true, dfu, emit_shadow)) > 0) { - uint64_t starttime = jobmeta.at; - uint64_t endtime = jobmeta.at + jobmeta.duration; - if (writers->emit_tm (starttime, endtime) == -1) { - m_err_msg += __FUNCTION__; - m_err_msg += ": emit_tm returned -1.\n"; - } - if (jobmeta.is_queue_set ()) { - if (writers->emit_attrs ("queue", jobmeta.get_queue ()) == -1) { - m_err_msg += __FUNCTION__; - m_err_msg += ": emit_attrs returned -1.\n"; - } - } - } - - return (rc > 0)? 0 : -1; + if ((rc = upd_dfv (root, writers, needs, x, jobmeta, true, dfu, emit_shadow)) > 0) { + uint64_t starttime = jobmeta.at; + uint64_t endtime = jobmeta.at + jobmeta.duration; + if (writers->emit_tm (starttime, endtime) == -1) { + m_err_msg += __FUNCTION__; + m_err_msg += ": emit_tm returned -1.\n"; + } + if (jobmeta.is_queue_set ()) { + if (writers->emit_attrs ("queue", jobmeta.get_queue ()) == -1) { + m_err_msg += __FUNCTION__; + m_err_msg += ": emit_attrs returned -1.\n"; + } + } + } + + return (rc > 0) ? 0 : -1; } int dfu_impl_t::update () @@ -707,7 +710,8 @@ int dfu_impl_t::update () return 0; } -int dfu_impl_t::update (vtx_t root, std::shared_ptr &writers, +int dfu_impl_t::update (vtx_t root, + std::shared_ptr &writers, const std::string &str, std::shared_ptr &reader, jobmeta_t &jobmeta) @@ -718,22 +722,24 @@ int dfu_impl_t::update (vtx_t root, std::shared_ptr &writers, unsigned int needs = 0; std::map dfu; const std::string &dom = m_match->dom_subsystem (); - bool rsv = (jobmeta.alloc_type - == jobmeta_t::alloc_type_t::AT_ALLOC_ORELSE_RESERVE); + bool rsv = (jobmeta.alloc_type == jobmeta_t::alloc_type_t::AT_ALLOC_ORELSE_RESERVE); tick (); - if ( (rc = reader->update (m_graph_db->resource_graph, - m_graph_db->metadata, str, - jobmeta.jobid, jobmeta.at, - jobmeta.duration, - rsv, m_best_k_cnt)) != 0) { + if ((rc = reader->update (m_graph_db->resource_graph, + m_graph_db->metadata, + str, + jobmeta.jobid, + jobmeta.at, + jobmeta.duration, + rsv, + m_best_k_cnt)) + != 0) { m_err_msg += reader->err_message (); reader->clear_err_message (); return rc; } - if (m_graph_db->metadata.v_rt_edges[dom].get_trav_token () - != m_best_k_cnt) { + if (m_graph_db->metadata.v_rt_edges[dom].get_trav_token () != m_best_k_cnt) { // This condition occurs when the subgraph came from a // traverver different from this traverser, for example, // a traverser whose dominant subsystem is different than this. @@ -741,52 +747,50 @@ int dfu_impl_t::update (vtx_t root, std::shared_ptr &writers, } excl = m_graph_db->metadata.v_rt_edges[dom].get_exclusive (); - x = (excl == 0)? false : true; - needs = static_cast(m_graph_db->metadata - .v_rt_edges[dom].get_needs ()); + x = (excl == 0) ? false : true; + needs = static_cast (m_graph_db->metadata.v_rt_edges[dom].get_needs ()); m_color.reset (); bool emit_shadow = modify_traversal (root, false); - if ( (rc = upd_dfv (root, writers, needs, - x, jobmeta, false, dfu, emit_shadow)) > 0) { - uint64_t starttime = jobmeta.at; - uint64_t endtime = jobmeta.at + jobmeta.duration; - if (writers->emit_tm (starttime, endtime) == -1) { - m_err_msg += __FUNCTION__; - m_err_msg += ": emit_tm returned -1.\n"; - } - if (jobmeta.is_queue_set ()) { - if (writers->emit_attrs ("queue", jobmeta.get_queue ()) == -1) { - m_err_msg += __FUNCTION__; - m_err_msg += ": emit_attrs returned -1.\n"; - } - } + if ((rc = upd_dfv (root, writers, needs, x, jobmeta, false, dfu, emit_shadow)) > 0) { + uint64_t starttime = jobmeta.at; + uint64_t endtime = jobmeta.at + jobmeta.duration; + if (writers->emit_tm (starttime, endtime) == -1) { + m_err_msg += __FUNCTION__; + m_err_msg += ": emit_tm returned -1.\n"; + } + if (jobmeta.is_queue_set ()) { + if (writers->emit_attrs ("queue", jobmeta.get_queue ()) == -1) { + m_err_msg += __FUNCTION__; + m_err_msg += ": emit_attrs returned -1.\n"; + } + } } - return (rc > 0)? 0: -1; + return (rc > 0) ? 0 : -1; } int dfu_impl_t::remove (vtx_t root, int64_t jobid) { - bool root_has_jtag = ((*m_graph)[root].idata.tags.find (jobid) - != (*m_graph)[root].idata.tags.end ()); + bool root_has_jtag = + ((*m_graph)[root].idata.tags.find (jobid) != (*m_graph)[root].idata.tags.end ()); modify_data_t mod_data; mod_data.mod_type = job_modify_t::CANCEL; m_color.reset (); - return (root_has_jtag)? mod_dfv (root, jobid, mod_data) - : mod_exv (jobid, mod_data); + return (root_has_jtag) ? mod_dfv (root, jobid, mod_data) : mod_exv (jobid, mod_data); } -int dfu_impl_t::remove (vtx_t root, const std::string &R_to_cancel, +int dfu_impl_t::remove (vtx_t root, + const std::string &R_to_cancel, std::shared_ptr &reader, - int64_t jobid, bool &full_cancel) + int64_t jobid, + bool &full_cancel) { int rc = -1; modify_data_t mod_data; resource_graph_t &g = m_graph_db->resource_graph; resource_graph_metadata_t &m = m_graph_db->metadata; - if (reader->partial_cancel (g, m, mod_data, R_to_cancel, - jobid) != 0) { + if (reader->partial_cancel (g, m, mod_data, R_to_cancel, jobid) != 0) { m_err_msg += __FUNCTION__; m_err_msg += ": partial_cancel returned error.\n"; return -1; @@ -806,27 +810,26 @@ int dfu_impl_t::remove (vtx_t root, const std::string &R_to_cancel, for (const vtx_t &vtx : rank_vector->second) { // Cancel the vertex if it has job tag. Not necessary // but reduces number of checks before function return - if ( (*m_graph)[vtx].idata.tags.find (jobid) - != (*m_graph)[vtx].idata.tags.end ()) { - if ( (rc = cancel_vertex (vtx, mod_data, jobid)) != 0) { - errno = EINVAL; - return rc; + if ((*m_graph)[vtx].idata.tags.find (jobid) != (*m_graph)[vtx].idata.tags.end ()) { + if ((rc = cancel_vertex (vtx, mod_data, jobid)) != 0) { + errno = EINVAL; + return rc; } } } } } - bool root_has_jtag = ((*m_graph)[root].idata.tags.find (jobid) - != (*m_graph)[root].idata.tags.end ()); + bool root_has_jtag = + ((*m_graph)[root].idata.tags.find (jobid) != (*m_graph)[root].idata.tags.end ()); // Now partial cancel DFV from graph root mod_data.mod_type = job_modify_t::PARTIAL_CANCEL; m_color.reset (); if (root_has_jtag) { rc = mod_dfv (root, jobid, mod_data); // Was the root vertex's job tag removed? If so, full_cancel - full_cancel = ((*m_graph)[root].idata.tags.find (jobid) - == (*m_graph)[root].idata.tags.end ()); + full_cancel = + ((*m_graph)[root].idata.tags.find (jobid) == (*m_graph)[root].idata.tags.end ()); } else { rc = mod_exv (jobid, mod_data); } @@ -834,17 +837,15 @@ int dfu_impl_t::remove (vtx_t root, const std::string &R_to_cancel, return rc; } -int dfu_impl_t::mark (const std::string &root_path, - resource_pool_t::status_t status) +int dfu_impl_t::mark (const std::string &root_path, resource_pool_t::status_t status) { std::map>::const_iterator vit_root = m_graph_db->metadata.by_path.find (root_path); if (vit_root == m_graph_db->metadata.by_path.end ()) { errno = EINVAL; - m_err_msg += __FUNCTION__; - m_err_msg += ": could not find subtree path (" - + root_path + ") in resource graph.\n"; + m_err_msg += __FUNCTION__; + m_err_msg += ": could not find subtree path (" + root_path + ") in resource graph.\n"; return -1; } for (auto &v : vit_root->second) @@ -854,11 +855,10 @@ int dfu_impl_t::mark (const std::string &root_path, return 0; } -int dfu_impl_t::mark (std::set &ranks, - resource_pool_t::status_t status) +int dfu_impl_t::mark (std::set &ranks, resource_pool_t::status_t status) { try { - std::map>::iterator vit; + std::map>::iterator vit; std::string subtree_path = "", tmp_path = ""; const std::string &dom = m_match->dom_subsystem (); vtx_t subtree_root; diff --git a/resource/utilities/command.cpp b/resource/utilities/command.cpp index 803cccf5b..07f54ff71 100644 --- a/resource/utilities/command.cpp +++ b/resource/utilities/command.cpp @@ -29,55 +29,88 @@ struct command_t { std::string note; }; -command_t commands[] = { - { "match", "m", cmd_match, "Allocate or reserve matching resources (subcmd: " -"allocate | allocate_with_satisfiability | allocate_orelse_reserve) | " -"satisfiability: " -"resource-query> match allocate jobspec"}, - { "multi-match", "M", cmd_match_multi, "Allocate or reserve for " -"multiple jobspecs (subcmd: allocate | allocate_with_satisfiability | " -"allocate_orelse_reserve): " -"resource-query> multi-match allocate jobspec1 jobspec2 ..."}, - { "update", "u", cmd_update, "Update resources with a JGF subgraph (subcmd: " -"allocate | reserve), (reader: jgf | rv1exec): " -"resource-query> update allocate jgf jgf_file jobid starttime duration" }, - { "attach", "j", cmd_attach, "Attach a JGF subgraph to the " -"resource graph: resource-query> attach jgf_file" }, - { "remove", "j", cmd_remove, "Experimental: remove a subgraph to the " - "resource graph: resource-query> remove path/to/node/" }, - { "find", "f", cmd_find, "Find resources matched with criteria " -"(predicates: status={up|down} sched-now={allocated|free} sched-future={reserved|free}): " -"resource-query> find status=down and sched-now=allocated" }, - { "cancel", "c", cmd_cancel, "Cancel an allocation or reservation: " -"resource-query> cancel jobid" }, - { "partial-cancel", "pc", cmd_partial_cancel, "Partially release an allocation: " -"resource-query> partial-cancel jobid (file format: jgf | rv1exec) R_to_cancel.file" }, - { "set-property", "p", cmd_set_property, "Add a property to a resource: " -"resource-query> set-property resource PROPERTY=VALUE" }, -{ "get-property", "g", cmd_get_property, "Get all properties of a resource: " -"resource-query> get-property resource" }, -{ "set-status", "t", cmd_set_status, "Set resource status on vertex: " -"resource-query> set-status PATH_TO_VERTEX {up|down}" }, -{ "get-status", "e", cmd_get_status, "Get the graph resource vertex status: " -"resource-query> get-status PATH_TO_VERTEX" }, - { "list", "l", cmd_list, "List all jobs: resource-query> list" }, - { "info", "i", cmd_info, -"Print info on a jobid: resource-query> info jobid" }, - { "stat", "s", cmd_stat, - "Print overall stats: resource-query> stat jobid" }, - { "cat", "a", cmd_cat, "Print jobspec file: resource-query> cat jobspec" }, - { "help", "h", cmd_help, "Print help message: resource-query> help" }, - { "quit", "q", cmd_quit, "Quit the session: resource-query> quit" }, - { "NA", "NA", (cmd_func_f *)NULL, "NA" } -}; +command_t commands[] = + {{"match", + "m", + cmd_match, + "Allocate or reserve matching resources (subcmd: " + "allocate | allocate_with_satisfiability | allocate_orelse_reserve) | " + "satisfiability: " + "resource-query> match allocate jobspec"}, + {"multi-match", + "M", + cmd_match_multi, + "Allocate or reserve for " + "multiple jobspecs (subcmd: allocate | allocate_with_satisfiability | " + "allocate_orelse_reserve): " + "resource-query> multi-match allocate jobspec1 jobspec2 ..."}, + {"update", + "u", + cmd_update, + "Update resources with a JGF subgraph (subcmd: " + "allocate | reserve), (reader: jgf | rv1exec): " + "resource-query> update allocate jgf jgf_file jobid starttime duration"}, + {"attach", + "j", + cmd_attach, + "Attach a JGF subgraph to the " + "resource graph: resource-query> attach jgf_file"}, + {"remove", + "j", + cmd_remove, + "Experimental: remove a subgraph to the " + "resource graph: resource-query> remove path/to/node/"}, + {"find", + "f", + cmd_find, + "Find resources matched with criteria " + "(predicates: status={up|down} sched-now={allocated|free} sched-future={reserved|free}): " + "resource-query> find status=down and sched-now=allocated"}, + {"cancel", + "c", + cmd_cancel, + "Cancel an allocation or reservation: " + "resource-query> cancel jobid"}, + {"partial-cancel", + "pc", + cmd_partial_cancel, + "Partially release an allocation: " + "resource-query> partial-cancel jobid (file format: jgf | rv1exec) R_to_cancel.file"}, + {"set-property", + "p", + cmd_set_property, + "Add a property to a resource: " + "resource-query> set-property resource PROPERTY=VALUE"}, + {"get-property", + "g", + cmd_get_property, + "Get all properties of a resource: " + "resource-query> get-property resource"}, + {"set-status", + "t", + cmd_set_status, + "Set resource status on vertex: " + "resource-query> set-status PATH_TO_VERTEX {up|down}"}, + {"get-status", + "e", + cmd_get_status, + "Get the graph resource vertex status: " + "resource-query> get-status PATH_TO_VERTEX"}, + {"list", "l", cmd_list, "List all jobs: resource-query> list"}, + {"info", "i", cmd_info, "Print info on a jobid: resource-query> info jobid"}, + {"stat", "s", cmd_stat, "Print overall stats: resource-query> stat jobid"}, + {"cat", "a", cmd_cat, "Print jobspec file: resource-query> cat jobspec"}, + {"help", "h", cmd_help, "Print help message: resource-query> help"}, + {"quit", "q", cmd_quit, "Quit the session: resource-query> quit"}, + {"NA", "NA", (cmd_func_f *)NULL, "NA"}}; static int do_remove (std::shared_ptr &ctx, int64_t jobid) { int rc = -1; if ((rc = ctx->traverser->remove ((int64_t)jobid)) == 0) { if (ctx->jobs.find (jobid) != ctx->jobs.end ()) { - std::shared_ptr info = ctx->jobs[jobid]; - info->state = job_lifecycle_t::CANCELED; + std::shared_ptr info = ctx->jobs[jobid]; + info->state = job_lifecycle_t::CANCELED; } } else { std::cout << ctx->traverser->err_message (); @@ -88,16 +121,16 @@ static int do_remove (std::shared_ptr &ctx, int64_t jobid) static int do_partial_remove (std::shared_ptr &ctx, std::shared_ptr &reader, - int64_t jobid, const std::string &R_cancel, + int64_t jobid, + const std::string &R_cancel, bool &full_cancel) { int rc = -1; - if ( (rc = ctx->traverser->remove (R_cancel, reader, (int64_t)jobid, - full_cancel)) == 0) { + if ((rc = ctx->traverser->remove (R_cancel, reader, (int64_t)jobid, full_cancel)) == 0) { if (full_cancel && (ctx->jobs.find (jobid) != ctx->jobs.end ())) { - std::shared_ptr info = ctx->jobs[jobid]; - info->state = job_lifecycle_t::CANCELED; + std::shared_ptr info = ctx->jobs[jobid]; + info->state = job_lifecycle_t::CANCELED; } } else { std::cout << ctx->traverser->err_message (); @@ -107,91 +140,110 @@ static int do_partial_remove (std::shared_ptr &ctx, } static void print_sat_info (std::shared_ptr &ctx, - std::ostream &out, bool sat, double elapse, - unsigned int pre, unsigned int post) + std::ostream &out, + bool sat, + double elapse, + unsigned int pre, + unsigned int post) { - std::string satstr = sat? "Satisfiable" : "Unsatisfiable"; - out << "INFO:" << " =============================" << std::endl; + std::string satstr = sat ? "Satisfiable" : "Unsatisfiable"; + out << "INFO:" + << " =============================" << std::endl; out << "INFO: " << satstr << " request" << std::endl; - out << "INFO:" << " =============================" << std::endl; + out << "INFO:" + << " =============================" << std::endl; if (ctx->params.elapse_time) { - std::cout << "INFO:" << " ELAPSE=" << std::to_string (elapse) - << std::endl; - std::cout << "INFO:" << " PREORDER VISIT COUNT=" << pre - << std::endl; - std::cout << "INFO:" << " POSTORDER VISIT COUNT=" << post - << std::endl; + std::cout << "INFO:" + << " ELAPSE=" << std::to_string (elapse) << std::endl; + std::cout << "INFO:" + << " PREORDER VISIT COUNT=" << pre << std::endl; + std::cout << "INFO:" + << " POSTORDER VISIT COUNT=" << post << std::endl; } } static void print_schedule_info (std::shared_ptr &ctx, - std::ostream &out, uint64_t jobid, - const std::string &jobspec_fn, bool matched, - int64_t at, bool sat, double elapse, - unsigned int pre, unsigned int post) + std::ostream &out, + uint64_t jobid, + const std::string &jobspec_fn, + bool matched, + int64_t at, + bool sat, + double elapse, + unsigned int pre, + unsigned int post) { if (matched) { job_lifecycle_t st; - std::string mode = (at == 0)? "ALLOCATED" : "RESERVED"; - std::string scheduled_at = (at == 0)? "Now" : std::to_string (at); - out << "INFO:" << " =============================" << std::endl; - out << "INFO:" << " JOBID=" << jobid << std::endl; - out << "INFO:" << " RESOURCES=" << mode << std::endl; - out << "INFO:" << " SCHEDULED AT=" << scheduled_at << std::endl; + std::string mode = (at == 0) ? "ALLOCATED" : "RESERVED"; + std::string scheduled_at = (at == 0) ? "Now" : std::to_string (at); + out << "INFO:" + << " =============================" << std::endl; + out << "INFO:" + << " JOBID=" << jobid << std::endl; + out << "INFO:" + << " RESOURCES=" << mode << std::endl; + out << "INFO:" + << " SCHEDULED AT=" << scheduled_at << std::endl; if (ctx->params.elapse_time) { - std::cout << "INFO:" << " ELAPSE=" << std::to_string (elapse) - << std::endl; - std::cout << "INFO:" << " PREORDER VISIT COUNT=" << pre - << std::endl; - std::cout << "INFO:" << " POSTORDER VISIT COUNT=" << post - << std::endl; + std::cout << "INFO:" + << " ELAPSE=" << std::to_string (elapse) << std::endl; + std::cout << "INFO:" + << " PREORDER VISIT COUNT=" << pre << std::endl; + std::cout << "INFO:" + << " POSTORDER VISIT COUNT=" << post << std::endl; } - out << "INFO:" << " =============================" << std::endl; - st = (at == 0)? job_lifecycle_t::ALLOCATED : job_lifecycle_t::RESERVED; - ctx->jobs[jobid] = std::make_shared (jobid, st, at, - jobspec_fn, - "", elapse); + out << "INFO:" + << " =============================" << std::endl; + st = (at == 0) ? job_lifecycle_t::ALLOCATED : job_lifecycle_t::RESERVED; + ctx->jobs[jobid] = std::make_shared (jobid, st, at, jobspec_fn, "", elapse); if (at == 0) ctx->allocations[jobid] = jobid; else ctx->reservations[jobid] = jobid; } else { - out << "INFO:" << " =============================" << std::endl; - out << "INFO: " << "No matching resources found" << std::endl; + out << "INFO:" + << " =============================" << std::endl; + out << "INFO: " + << "No matching resources found" << std::endl; if (!sat) - out << "INFO: " << "Unsatisfiable request" << std::endl; - out << "INFO:" << " JOBID=" << jobid << std::endl; + out << "INFO: " + << "Unsatisfiable request" << std::endl; + out << "INFO:" + << " JOBID=" << jobid << std::endl; if (ctx->params.elapse_time) { - out << "INFO:" << " ELAPSE=" << std::to_string (elapse) - << std::endl; - std::cout << "INFO:" << " PREORDER VISIT COUNT=" << pre - << std::endl; - std::cout << "INFO:" << " POSTORDER VISIT COUNT=" << post - << std::endl; + out << "INFO:" + << " ELAPSE=" << std::to_string (elapse) << std::endl; + std::cout << "INFO:" + << " PREORDER VISIT COUNT=" << pre << std::endl; + std::cout << "INFO:" + << " POSTORDER VISIT COUNT=" << post << std::endl; } - out << "INFO:" << " =============================" << std::endl; + out << "INFO:" + << " =============================" << std::endl; } ctx->jobid_counter++; } -static void update_match_perf (std::shared_ptr &ctx, - double elapse) +static void update_match_perf (std::shared_ptr &ctx, double elapse) { - ctx->perf.min = (ctx->perf.min > elapse)? elapse : ctx->perf.min; - ctx->perf.max = (ctx->perf.max < elapse)? elapse : ctx->perf.max; + ctx->perf.min = (ctx->perf.min > elapse) ? elapse : ctx->perf.min; + ctx->perf.max = (ctx->perf.max < elapse) ? elapse : ctx->perf.max; ctx->perf.accum += elapse; } double get_elapse_time (timeval &st, timeval &et) { - double ts1 = (double)st.tv_sec + (double)st.tv_usec/1000000.0f; - double ts2 = (double)et.tv_sec + (double)et.tv_usec/1000000.0f; + double ts1 = (double)st.tv_sec + (double)st.tv_usec / 1000000.0f; + double ts2 = (double)et.tv_sec + (double)et.tv_usec / 1000000.0f; return ts2 - ts1; } -static int run_match (std::shared_ptr &ctx, int64_t jobid, - const std::string cmd, const std::string &jobspec_fn, +static int run_match (std::shared_ptr &ctx, + int64_t jobid, + const std::string cmd, + const std::string &jobspec_fn, Flux::Jobspec::Jobspec &job) { int rc = 0; @@ -203,29 +255,37 @@ static int run_match (std::shared_ptr &ctx, int64_t jobid, unsigned int preorder_count = 0; unsigned int postorder_count = 0; struct timeval st, et; - std::ostream &out = (ctx->params.r_fname != "")? ctx->params.r_out - : std::cout; + std::ostream &out = (ctx->params.r_fname != "") ? ctx->params.r_out : std::cout; - if ( (rc = gettimeofday (&st, NULL)) < 0) { + if ((rc = gettimeofday (&st, NULL)) < 0) { std::cerr << "ERROR: gettimeofday: " << strerror (errno) << std::endl; goto done; } if (cmd == "allocate") - rc2 = ctx->traverser->run (job, ctx->writers, match_op_t:: - MATCH_ALLOCATE, (int64_t)jobid, &at); + rc2 = ctx->traverser->run (job, + ctx->writers, + match_op_t::MATCH_ALLOCATE, + (int64_t)jobid, + &at); else if (cmd == "allocate_with_satisfiability") - rc2 = ctx->traverser->run (job, ctx->writers, match_op_t:: - MATCH_ALLOCATE_W_SATISFIABILITY, - (int64_t)jobid, &at); + rc2 = ctx->traverser->run (job, + ctx->writers, + match_op_t::MATCH_ALLOCATE_W_SATISFIABILITY, + (int64_t)jobid, + &at); else if (cmd == "allocate_orelse_reserve") - rc2 = ctx->traverser->run (job, ctx->writers, match_op_t:: - MATCH_ALLOCATE_ORELSE_RESERVE, - (int64_t)jobid, &at); + rc2 = ctx->traverser->run (job, + ctx->writers, + match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE, + (int64_t)jobid, + &at); else if (cmd == "satisfiability") - rc2 = ctx->traverser->run (job, ctx->writers, match_op_t:: - MATCH_SATISFIABILITY, - (int64_t)jobid, &at); + rc2 = ctx->traverser->run (job, + ctx->writers, + match_op_t::MATCH_SATISFIABILITY, + (int64_t)jobid, + &at); else goto done; @@ -236,15 +296,14 @@ static int run_match (std::shared_ptr &ctx, int64_t jobid, std::cerr << "ERROR: " << ctx->traverser->err_message (); ctx->traverser->clear_err_message (); } - if ( (rc = ctx->writers->emit (o)) < 0) { - std::cerr << "ERROR: match writer emit: " - << strerror (errno) << std::endl; + if ((rc = ctx->writers->emit (o)) < 0) { + std::cerr << "ERROR: match writer emit: " << strerror (errno) << std::endl; goto done; } out << o.str (); - if ( (rc = gettimeofday (&et, NULL)) < 0) { + if ((rc = gettimeofday (&et, NULL)) < 0) { std::cerr << "ERROR: gettimeofday: " << strerror (errno) << std::endl; goto done; } @@ -255,9 +314,16 @@ static int run_match (std::shared_ptr &ctx, int64_t jobid, update_match_perf (ctx, elapse); if (cmd != "satisfiability") - print_schedule_info (ctx, out, jobid, - jobspec_fn, rc2 == 0, at, sat, - elapse, preorder_count, postorder_count); + print_schedule_info (ctx, + out, + jobid, + jobspec_fn, + rc2 == 0, + at, + sat, + elapse, + preorder_count, + postorder_count); else print_sat_info (ctx, out, sat, elapse, preorder_count, postorder_count); @@ -265,8 +331,7 @@ static int run_match (std::shared_ptr &ctx, int64_t jobid, return rc + rc2; } -int cmd_match (std::shared_ptr &ctx, - std::vector &args) +int cmd_match (std::shared_ptr &ctx, std::vector &args) { if (args.size () != 3) { std::cerr << "ERROR: malformed command" << std::endl; @@ -274,8 +339,7 @@ int cmd_match (std::shared_ptr &ctx, } std::string subcmd = args[1]; if (!(subcmd == "allocate" || subcmd == "allocate_orelse_reserve" - || subcmd == "allocate_with_satisfiability" - || subcmd == "satisfiability")) { + || subcmd == "allocate_with_satisfiability" || subcmd == "satisfiability")) { std::cerr << "ERROR: unknown subcmd " << args[1] << std::endl; return 0; } @@ -288,20 +352,19 @@ int cmd_match (std::shared_ptr &ctx, std::cerr << "ERROR: can't open " << jobspec_fn << std::endl; return 0; } - Flux::Jobspec::Jobspec job {jobspec_in}; + Flux::Jobspec::Jobspec job{jobspec_in}; jobspec_in.close (); run_match (ctx, jobid, subcmd, jobspec_fn, job); } catch (parse_error &e) { - std::cerr << "ERROR: Jobspec error for " << ctx->jobid_counter <<": " - << e.what () << std::endl; + std::cerr << "ERROR: Jobspec error for " << ctx->jobid_counter << ": " << e.what () + << std::endl; } return 0; } -int cmd_match_multi (std::shared_ptr &ctx, - std::vector &args) +int cmd_match_multi (std::shared_ptr &ctx, std::vector &args) { size_t i; @@ -325,22 +388,25 @@ int cmd_match_multi (std::shared_ptr &ctx, std::cerr << "ERROR: can't open " << jobspec_fn << std::endl; return 0; } - Flux::Jobspec::Jobspec job {jobspec_in}; + Flux::Jobspec::Jobspec job{jobspec_in}; jobspec_in.close (); if (run_match (ctx, jobid, subcmd, jobspec_fn, job) < 0) return 0; } } catch (parse_error &e) { - std::cerr << "ERROR: Jobspec error for " << ctx->jobid_counter <<": " - << e.what () << std::endl; + std::cerr << "ERROR: Jobspec error for " << ctx->jobid_counter << ": " << e.what () + << std::endl; } return 0; } static int update_run (std::shared_ptr &ctx, - const std::string &fn, const std::string &str, - int64_t id, int64_t at, uint64_t d, + const std::string &fn, + const std::string &str, + int64_t id, + int64_t at, + uint64_t d, const std::string &reader) { int rc = -1; @@ -350,19 +416,19 @@ static int update_run (std::shared_ptr &ctx, std::shared_ptr rd; if (reader == "jgf") { - if ( (rd = create_resource_reader ("jgf")) == nullptr) { + if ((rd = create_resource_reader ("jgf")) == nullptr) { std::cerr << "ERROR: can't create JGF reader " << std::endl; return -1; } } else { - if ( (rd = create_resource_reader ("rv1exec")) == nullptr) { + if ((rd = create_resource_reader ("rv1exec")) == nullptr) { std::cerr << "ERROR: can't create rv1exec reader " << std::endl; return -1; } } gettimeofday (&st, NULL); - if ( (rc = ctx->traverser->run (str, ctx->writers, rd, id, at, d)) != 0) { + if ((rc = ctx->traverser->run (str, ctx->writers, rd, id, at, d)) != 0) { std::cerr << "ERROR: traverser run () returned error " << std::endl; if (ctx->traverser->err_message () != "") { std::cerr << "ERROR: " << ctx->traverser->err_message (); @@ -370,8 +436,7 @@ static int update_run (std::shared_ptr &ctx, } } ctx->writers->emit (o); - std::ostream &out = (ctx->params.r_fname != "")? ctx->params.r_out - : std::cout; + std::ostream &out = (ctx->params.r_fname != "") ? ctx->params.r_out : std::cout; out << o.str (); gettimeofday (&et, NULL); @@ -383,8 +448,7 @@ static int update_run (std::shared_ptr &ctx, return 0; } -static int update (std::shared_ptr &ctx, - std::vector &args) +static int update (std::shared_ptr &ctx, std::vector &args) { uint64_t d = 0; int64_t at = 0; @@ -416,8 +480,7 @@ static int update (std::shared_ptr &ctx, at = static_cast (std::strtoll (args[5].c_str (), NULL, 10)); d = static_cast (std::strtoll (args[6].c_str (), NULL, 10)); if (at < 0 || d == 0) { - std::cerr << "ERROR: invalid time (" - << at << ", " << d << ")" << std::endl; + std::cerr << "ERROR: invalid time (" << at << ", " << d << ")" << std::endl; return -1; } @@ -427,8 +490,7 @@ static int update (std::shared_ptr &ctx, return update_run (ctx, args[3], buffer.str (), jobid, at, d, reader); } -int cmd_update (std::shared_ptr &ctx, - std::vector &args) +int cmd_update (std::shared_ptr &ctx, std::vector &args) { try { if (args.size () != 7) { @@ -445,8 +507,7 @@ int cmd_update (std::shared_ptr &ctx, return 0; } -static int attach (std::shared_ptr &ctx, - std::vector &args) +static int attach (std::shared_ptr &ctx, std::vector &args) { std::stringstream buffer{}; std::shared_ptr rd; @@ -459,7 +520,7 @@ static int attach (std::shared_ptr &ctx, buffer << jgf_file.rdbuf (); jgf_file.close (); - if ( (rd = create_resource_reader ("jgf")) == nullptr) { + if ((rd = create_resource_reader ("jgf")) == nullptr) { std::cerr << "ERROR: can't create JGF reader " << std::endl; return -1; } @@ -467,34 +528,30 @@ static int attach (std::shared_ptr &ctx, // Unpack_at currently does not use the vertex attachment point. // This functionality is currently experimental. vtx_t v = boost::graph_traits::null_vertex (); - if ( (rd->unpack_at (ctx->db->resource_graph, ctx->db->metadata, - v, buffer.str (), -1)) != 0) { + if ((rd->unpack_at (ctx->db->resource_graph, ctx->db->metadata, v, buffer.str (), -1)) != 0) { std::cerr << "ERROR: can't attach JGF subgraph " << std::endl; std::cerr << "ERROR: " << rd->err_message (); return -1; } if (ctx->traverser->initialize (ctx->db, ctx->matcher) != 0) { - std::cerr << "ERROR: can't reinitialize traverser after attach" - << std::endl; + std::cerr << "ERROR: can't reinitialize traverser after attach" << std::endl; return -1; } return 0; } -static int remove (std::shared_ptr &ctx, - std::vector &args) +static int remove (std::shared_ptr &ctx, std::vector &args) { const std::string node_path = args[1]; std::shared_ptr rd; - if ( (rd = create_resource_reader ("jgf")) == nullptr) { + if ((rd = create_resource_reader ("jgf")) == nullptr) { std::cerr << "ERROR: can't create JGF reader " << std::endl; return -1; } - if ( (rd->remove_subgraph (ctx->db->resource_graph, ctx->db->metadata, - node_path)) != 0) { + if ((rd->remove_subgraph (ctx->db->resource_graph, ctx->db->metadata, node_path)) != 0) { std::cerr << "ERROR: can't remove subgraph " << std::endl; std::cerr << "ERROR: " << rd->err_message (); return -1; @@ -504,8 +561,7 @@ static int remove (std::shared_ptr &ctx, return 0; } -int cmd_attach (std::shared_ptr &ctx, - std::vector &args) +int cmd_attach (std::shared_ptr &ctx, std::vector &args) { try { if (args.size () != 2) { @@ -522,8 +578,7 @@ int cmd_attach (std::shared_ptr &ctx, return 0; } -int cmd_remove (std::shared_ptr &ctx, - std::vector &args) +int cmd_remove (std::shared_ptr &ctx, std::vector &args) { try { if (args.size () != 2) { @@ -540,8 +595,7 @@ int cmd_remove (std::shared_ptr &ctx, return 0; } -int cmd_find (std::shared_ptr &ctx, - std::vector &args) +int cmd_find (std::shared_ptr &ctx, std::vector &args) { int rc = -1; int i = 0; @@ -552,12 +606,11 @@ int cmd_find (std::shared_ptr &ctx, std::cerr << "ERROR: malformed command: " << std::endl; return 0; } - std::ostream &out = (ctx->params.r_fname != "")? ctx->params.r_out - : std::cout; + std::ostream &out = (ctx->params.r_fname != "") ? ctx->params.r_out : std::cout; std::string criteria = args[1]; - for (int i = 2; i < static_cast (args.size()); ++i) + for (int i = 2; i < static_cast (args.size ()); ++i) criteria += " " + args[i]; - if ( (rc = ctx->traverser->find (ctx->writers, criteria)) < 0) { + if ((rc = ctx->traverser->find (ctx->writers, criteria)) < 0) { if (ctx->traverser->err_message () != "") { std::cerr << "ERROR: " << ctx->traverser->err_message (); ctx->traverser->clear_err_message (); @@ -582,16 +635,18 @@ int cmd_find (std::shared_ptr &ctx, } json_decref (o); } - out << "INFO:" << " =============================" << std::endl; - out << "INFO:" << " EXPRESSION=\"" << criteria << "\"" << std::endl; - out << "INFO:" << " =============================" << std::endl; + out << "INFO:" + << " =============================" << std::endl; + out << "INFO:" + << " EXPRESSION=\"" << criteria << "\"" << std::endl; + out << "INFO:" + << " =============================" << std::endl; done: return 0; } -int cmd_cancel (std::shared_ptr &ctx, - std::vector &args) +int cmd_cancel (std::shared_ptr &ctx, std::vector &args) { if (args.size () != 2) { std::cerr << "ERROR: malformed command" << std::endl; @@ -603,10 +658,10 @@ int cmd_cancel (std::shared_ptr &ctx, uint64_t jobid = (uint64_t)std::strtoll (jobid_str.c_str (), NULL, 10); if (ctx->allocations.find (jobid) != ctx->allocations.end ()) { - if ( (rc = do_remove (ctx, jobid)) == 0) + if ((rc = do_remove (ctx, jobid)) == 0) ctx->allocations.erase (jobid); } else if (ctx->reservations.find (jobid) != ctx->reservations.end ()) { - if ( (rc = do_remove (ctx, jobid)) == 0) + if ((rc = do_remove (ctx, jobid)) == 0) ctx->reservations.erase (jobid); } else { std::cerr << "ERROR: nonexistent job " << jobid << std::endl; @@ -614,16 +669,14 @@ int cmd_cancel (std::shared_ptr &ctx, } if (rc != 0) { - std::cerr << "ERROR: error encountered while removing job " - << jobid << std::endl; + std::cerr << "ERROR: error encountered while removing job " << jobid << std::endl; } done: return 0; } -int cmd_partial_cancel (std::shared_ptr &ctx, - std::vector &args) +int cmd_partial_cancel (std::shared_ptr &ctx, std::vector &args) { int rc = -1; std::stringstream buffer{}; @@ -653,26 +706,24 @@ int cmd_partial_cancel (std::shared_ptr &ctx, cancel_file.close (); if (reader == "rv1exec") { - if ( (rd = create_resource_reader ("rv1exec")) == nullptr) { + if ((rd = create_resource_reader ("rv1exec")) == nullptr) { std::cerr << "ERROR: can't create rv1exec reader " << std::endl; goto done; } - } else { // must be JGF - if ( (rd = create_resource_reader ("jgf")) == nullptr) { + } else { // must be JGF + if ((rd = create_resource_reader ("jgf")) == nullptr) { std::cerr << "ERROR: can't create rv1exec reader " << std::endl; goto done; } } if (ctx->allocations.find (jobid) != ctx->allocations.end ()) { - if ( (rc = do_partial_remove (ctx, rd, jobid, buffer.str (), - full_cancel)) == 0) { + if ((rc = do_partial_remove (ctx, rd, jobid, buffer.str (), full_cancel)) == 0) { if (full_cancel) ctx->allocations.erase (jobid); } } else if (ctx->reservations.find (jobid) != ctx->reservations.end ()) { - std::cerr << "ERROR: reservations not currently supported by partial cancel" - << std::endl; + std::cerr << "ERROR: reservations not currently supported by partial cancel" << std::endl; goto done; } else { std::cerr << "ERROR: nonexistent job " << jobid << std::endl; @@ -680,16 +731,14 @@ int cmd_partial_cancel (std::shared_ptr &ctx, } if (rc != 0) { - std::cerr << "ERROR: error encountered while removing job " - << jobid << std::endl; + std::cerr << "ERROR: error encountered while removing job " << jobid << std::endl; } done: return 0; } -int cmd_set_property (std::shared_ptr &ctx, - std::vector &args) +int cmd_set_property (std::shared_ptr &ctx, std::vector &args) { if (args.size () != 3) { std::cerr << "ERROR: malformed command" << std::endl; @@ -698,17 +747,14 @@ int cmd_set_property (std::shared_ptr &ctx, std::string resource_path = args[1]; std::string property_key, property_value; - std::ostream &out = (ctx->params.r_fname != "") ? ctx->params.r_out - : std::cout; + std::ostream &out = (ctx->params.r_fname != "") ? ctx->params.r_out : std::cout; size_t pos = args[2].find ('='); if (pos == 0 || (pos == args[2].size () - 1) || pos == std::string::npos) { out << "Incorrect input format. " << std::endl - << "Please use `set-property PROPERTY=VALUE`." - << std::endl; + << "Please use `set-property PROPERTY=VALUE`." << std::endl; return 0; - } - else { + } else { property_key = args[2].substr (0, pos); property_value = args[2].substr (pos + 1); } @@ -717,29 +763,25 @@ int cmd_set_property (std::shared_ptr &ctx, ctx->db->metadata.by_path.find (resource_path); if (it == ctx->db->metadata.by_path.end ()) { - out << "Couldn't find path " << resource_path - << " in resource graph." << std::endl; - } - else { + out << "Couldn't find path " << resource_path << " in resource graph." << std::endl; + } else { for (auto &v : it->second) { /* Note that map.insert () does not insert if the key exists. * Assuming we want to update the value though, we do an erase * before we insert. */ if (ctx->db->resource_graph[v].properties.find (property_key) - != ctx->db->resource_graph[v].properties.end ()) { + != ctx->db->resource_graph[v].properties.end ()) { ctx->db->resource_graph[v].properties.erase (property_key); } ctx->db->resource_graph[v].properties.insert ( - std::pair (property_key, - property_value)); + std::pair (property_key, property_value)); } } return 0; } -int cmd_get_property (std::shared_ptr &ctx, - std::vector &args) +int cmd_get_property (std::shared_ptr &ctx, std::vector &args) { if (args.size () != 2) { std::cerr << "ERROR: malformed command" << std::endl; @@ -747,36 +789,32 @@ int cmd_get_property (std::shared_ptr &ctx, } std::string resource_path = args[1]; - std::ostream &out = (ctx->params.r_fname != "") ? ctx->params.r_out - : std::cout; + std::ostream &out = (ctx->params.r_fname != "") ? ctx->params.r_out : std::cout; std::map>::const_iterator it = ctx->db->metadata.by_path.find (resource_path); if (it == ctx->db->metadata.by_path.end ()) { - out << "Could not find path " << resource_path - << " in resource graph." << std::endl; - } - else { + out << "Could not find path " << resource_path << " in resource graph." << std::endl; + } else { for (auto &v : it->second) { if (ctx->db->resource_graph[v].properties.size () == 0) { out << "No properties were found for " << resource_path - << " (vtx's uniq_id=" << ctx->db->resource_graph[v].uniq_id - << ")." << std::endl; - } - else { + << " (vtx's uniq_id=" << ctx->db->resource_graph[v].uniq_id << ")." + << std::endl; + } else { std::map::const_iterator p_it; for (p_it = ctx->db->resource_graph[v].properties.begin (); - p_it != ctx->db->resource_graph[v].properties.end (); p_it++) - out << p_it->first << "=" << p_it->second << std::endl; + p_it != ctx->db->resource_graph[v].properties.end (); + p_it++) + out << p_it->first << "=" << p_it->second << std::endl; } } } return 0; } -int cmd_set_status (std::shared_ptr &ctx, - std::vector &args) +int cmd_set_status (std::shared_ptr &ctx, std::vector &args) { if (args.size () != 3) { std::cerr << "ERROR: malformed command" << std::endl; @@ -788,12 +826,10 @@ int cmd_set_status (std::shared_ptr &ctx, ctx->db->metadata.by_path.find (vtx_path); resource_pool_t::string_to_status sts = resource_pool_t::str_to_status; - std::ostream &out = (ctx->params.r_fname != "") ? ctx->params.r_out - : std::cout; + std::ostream &out = (ctx->params.r_fname != "") ? ctx->params.r_out : std::cout; if (it == ctx->db->metadata.by_path.end ()) { - out << "Could not find path " << vtx_path - << " in resource graph." << std::endl; + out << "Could not find path " << vtx_path << " in resource graph." << std::endl; return 0; } @@ -806,8 +842,7 @@ int cmd_set_status (std::shared_ptr &ctx, return ctx->traverser->mark (vtx_path, status_it->second); } -int cmd_get_status (std::shared_ptr &ctx, - std::vector &args) +int cmd_get_status (std::shared_ptr &ctx, std::vector &args) { if (args.size () != 2) { std::cerr << "ERROR: malformed command" << std::endl; @@ -819,13 +854,10 @@ int cmd_get_status (std::shared_ptr &ctx, resource_pool_t::string_to_status sts = resource_pool_t::str_to_status; std::string status = ""; - std::ostream &out = (ctx->params.r_fname != "") ? ctx->params.r_out - : std::cout; - + std::ostream &out = (ctx->params.r_fname != "") ? ctx->params.r_out : std::cout; if (it == ctx->db->metadata.by_path.end ()) { - out << "Could not find path " << vtx_path - << " in resource graph." << std::endl; + out << "Could not find path " << vtx_path << " in resource graph." << std::endl; return 0; } @@ -838,8 +870,8 @@ int cmd_get_status (std::shared_ptr &ctx, } if (status == "") { - std::cerr << "ERROR: vertex " << vtx_path << "(vtx's uniq_id=" - << ctx->db->resource_graph[v].uniq_id + std::cerr << "ERROR: vertex " << vtx_path + << "(vtx's uniq_id=" << ctx->db->resource_graph[v].uniq_id << ") has unknown status." << std::endl; return 0; } @@ -850,43 +882,38 @@ int cmd_get_status (std::shared_ptr &ctx, return 0; } -int cmd_list (std::shared_ptr &ctx, - std::vector &args) +int cmd_list (std::shared_ptr &ctx, std::vector &args) { - for (auto &kv: ctx->jobs) { + for (auto &kv : ctx->jobs) { std::shared_ptr info = kv.second; std::string mode; get_jobstate_str (info->state, mode); - std::cout << "INFO: " << info->jobid << ", " << mode << ", " - << info->scheduled_at << ", " << info->jobspec_fn << ", " - << info->overhead << std::endl; + std::cout << "INFO: " << info->jobid << ", " << mode << ", " << info->scheduled_at << ", " + << info->jobspec_fn << ", " << info->overhead << std::endl; } return 0; } -int cmd_info (std::shared_ptr &ctx, - std::vector &args) +int cmd_info (std::shared_ptr &ctx, std::vector &args) { if (args.size () != 2) { std::cerr << "ERROR: malformed command" << std::endl; return 0; } - uint64_t jobid = (uint64_t)std::atoll(args[1].c_str ()); + uint64_t jobid = (uint64_t)std::atoll (args[1].c_str ()); if (ctx->jobs.find (jobid) == ctx->jobs.end ()) { - std::cout << "ERROR: jobid doesn't exist: " << args[1] << std::endl; - return 0; + std::cout << "ERROR: jobid doesn't exist: " << args[1] << std::endl; + return 0; } std::string mode; std::shared_ptr info = ctx->jobs[jobid]; get_jobstate_str (info->state, mode); - std::cout << "INFO: " << info->jobid << ", " << mode << ", " - << info->scheduled_at << ", " << info->jobspec_fn << ", " - << info->overhead << std::endl; + std::cout << "INFO: " << info->jobid << ", " << mode << ", " << info->scheduled_at << ", " + << info->jobspec_fn << ", " << info->overhead << std::endl; return 0; } -int cmd_stat (std::shared_ptr &ctx, - std::vector &args) +int cmd_stat (std::shared_ptr &ctx, std::vector &args) { if (args.size () != 1) { std::cerr << "ERROR: malformed command" << std::endl; @@ -899,16 +926,14 @@ int cmd_stat (std::shared_ptr &ctx, avg = ctx->perf.accum / (double)ctx->jobs.size (); min = ctx->perf.min; } - std::cout << "INFO: Num. of Jobs Matched: " << ctx->jobs.size () - << std::endl; + std::cout << "INFO: Num. of Jobs Matched: " << ctx->jobs.size () << std::endl; std::cout << "INFO: Min. Match Time: " << min << std::endl; std::cout << "INFO: Max. Match Time: " << ctx->perf.max << std::endl; std::cout << "INFO: Avg. Match Time: " << avg << std::endl; return 0; } -int cmd_cat (std::shared_ptr &ctx, - std::vector &args) +int cmd_cat (std::shared_ptr &ctx, std::vector &args) { std::string &jspec_filename = args[1]; std::ifstream jspec_in; @@ -916,14 +941,13 @@ int cmd_cat (std::shared_ptr &ctx, std::string line; while (getline (jspec_in, line)) std::cout << line << std::endl; - std::cout << "INFO: " << "Jobspec in " << jspec_filename - << std::endl; + std::cout << "INFO: " + << "Jobspec in " << jspec_filename << std::endl; jspec_in.close (); return 0; } -int cmd_help (std::shared_ptr &ctx, - std::vector &args) +int cmd_help (std::shared_ptr &ctx, std::vector &args) { bool multi = true; bool found = false; @@ -936,9 +960,8 @@ int cmd_help (std::shared_ptr &ctx, for (int i = 0; commands[i].name != "NA"; ++i) { if (multi || cmd == commands[i].name || cmd == commands[i].abbr) { - std::cout << "INFO: " << commands[i].name << " (" - << commands[i].abbr << ")" << " -- " - << commands[i].note << std::endl; + std::cout << "INFO: " << commands[i].name << " (" << commands[i].abbr << ")" + << " -- " << commands[i].note << std::endl; found = true; } } @@ -948,8 +971,7 @@ int cmd_help (std::shared_ptr &ctx, return 0; } -int cmd_quit (std::shared_ptr &ctx, - std::vector &args) +int cmd_quit (std::shared_ptr &ctx, std::vector &args) { return -1; } @@ -965,8 +987,8 @@ cmd_func_f *find_cmd (const std::string &cmd_str) return (cmd_func_f *)NULL; } -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/utilities/command.hpp b/resource/utilities/command.hpp index e083d6fe0..38e1c43f3 100644 --- a/resource/utilities/command.hpp +++ b/resource/utilities/command.hpp @@ -37,78 +37,59 @@ struct test_params_t { std::string prune_filters; /* Raw prune-filter specification */ std::string match_format; /* Format to emit a matched resources */ emit_format_t o_format; - bool elapse_time; /* Print elapse time */ - bool disable_prompt; /* Disable resource-query> prompt */ - bool flux_hwloc; /* get hwloc info from flux instance */ - size_t reserve_vtx_vec; /* Allow for reserving vertex vector size */ + bool elapse_time; /* Print elapse time */ + bool disable_prompt; /* Disable resource-query> prompt */ + bool flux_hwloc; /* get hwloc info from flux instance */ + size_t reserve_vtx_vec; /* Allow for reserving vertex vector size */ }; struct match_perf_t { - double min; /* Min match time */ - double max; /* Max match time */ - double accum; /* Total match time accumulated */ + double min; /* Min match time */ + double max; /* Max match time */ + double accum; /* Total match time accumulated */ }; struct resource_context_t { - test_params_t params; /* Parameters for resource-query */ - uint64_t jobid_counter; /* Hold the current jobid value */ - std::shared_ptr matcher; /* Match callback object */ - std::shared_ptr traverser; /* Graph traverser object */ - std::shared_ptr db; /* Resource graph data store */ - std::shared_ptr fgraph; /* Filtered graph */ - std::shared_ptr writers; /* Vertex/Edge writers */ - match_perf_t perf; /* Match performance stats */ + test_params_t params; /* Parameters for resource-query */ + uint64_t jobid_counter; /* Hold the current jobid value */ + std::shared_ptr matcher; /* Match callback object */ + std::shared_ptr traverser; /* Graph traverser object */ + std::shared_ptr db; /* Resource graph data store */ + std::shared_ptr fgraph; /* Filtered graph */ + std::shared_ptr writers; /* Vertex/Edge writers */ + match_perf_t perf; /* Match performance stats */ std::map> jobs; /* Jobs table */ - std::map allocations; /* Allocation table */ - std::map reservations; /* Reservation table */ + std::map allocations; /* Allocation table */ + std::map reservations; /* Reservation table */ }; -typedef int cmd_func_f (std::shared_ptr &, - std::vector &); +typedef int cmd_func_f (std::shared_ptr &, std::vector &); cmd_func_f *find_cmd (const std::string &cmd_str); -int cmd_match (std::shared_ptr &ctx, - std::vector &args); -int cmd_match_multi (std::shared_ptr &ctx, - std::vector &args); -int cmd_update (std::shared_ptr &ctx, - std::vector &args); -int cmd_attach (std::shared_ptr &ctx, - std::vector &args); -int cmd_remove (std::shared_ptr &ctx, - std::vector &args); -int cmd_find (std::shared_ptr &ctx, - std::vector &args); -int cmd_cancel (std::shared_ptr &ctx, - std::vector &args); -int cmd_partial_cancel (std::shared_ptr &ctx, - std::vector &args); -int cmd_set_property (std::shared_ptr &ctx, - std::vector &args); -int cmd_get_property (std::shared_ptr &ctx, - std::vector &args); -int cmd_set_status (std::shared_ptr &ctx, - std::vector &args); -int cmd_get_status (std::shared_ptr &ctx, - std::vector &args); -int cmd_list (std::shared_ptr &ctx, - std::vector &args); -int cmd_info (std::shared_ptr &ctx, - std::vector &args); -int cmd_stat (std::shared_ptr &ctx, - std::vector &args); -int cmd_cat (std::shared_ptr &ctx, - std::vector &args); -int cmd_quit (std::shared_ptr &ctx, - std::vector &args); -int cmd_help (std::shared_ptr &ctx, - std::vector &args); +int cmd_match (std::shared_ptr &ctx, std::vector &args); +int cmd_match_multi (std::shared_ptr &ctx, std::vector &args); +int cmd_update (std::shared_ptr &ctx, std::vector &args); +int cmd_attach (std::shared_ptr &ctx, std::vector &args); +int cmd_remove (std::shared_ptr &ctx, std::vector &args); +int cmd_find (std::shared_ptr &ctx, std::vector &args); +int cmd_cancel (std::shared_ptr &ctx, std::vector &args); +int cmd_partial_cancel (std::shared_ptr &ctx, std::vector &args); +int cmd_set_property (std::shared_ptr &ctx, std::vector &args); +int cmd_get_property (std::shared_ptr &ctx, std::vector &args); +int cmd_set_status (std::shared_ptr &ctx, std::vector &args); +int cmd_get_status (std::shared_ptr &ctx, std::vector &args); +int cmd_list (std::shared_ptr &ctx, std::vector &args); +int cmd_info (std::shared_ptr &ctx, std::vector &args); +int cmd_stat (std::shared_ptr &ctx, std::vector &args); +int cmd_cat (std::shared_ptr &ctx, std::vector &args); +int cmd_quit (std::shared_ptr &ctx, std::vector &args); +int cmd_help (std::shared_ptr &ctx, std::vector &args); double get_elapse_time (timeval &st, timeval &et); -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // COMMAND_HPP +#endif // COMMAND_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/utilities/grug2dot.cpp b/resource/utilities/grug2dot.cpp index c1875a1b4..95d5d7437 100644 --- a/resource/utilities/grug2dot.cpp +++ b/resource/utilities/grug2dot.cpp @@ -22,26 +22,25 @@ using namespace Flux::resource_model; #define OPTIONS "hm" static const struct option longopts[] = { - {"more", no_argument, 0, 'm'}, - {"help", no_argument, 0, 'h'}, - { 0, 0, 0, 0 }, + {"more", no_argument, 0, 'm'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0}, }; void usage (int code) { - std::cerr << -"Usage: grug2dot .graphml\n" -" Convert a resource-graph generator spec (.graphml)\n" -" to AT&T GraphViz format (.dot). The output\n" -" file only contains the basic information unless --more is given.\n" -"\n" -" OPTIONS:\n" -" -h, --help\n" -" Display this usage information\n" -"\n" -" -m, --more\n" -" More information in the output file\n" -"\n"; + std::cerr << "Usage: grug2dot .graphml\n" + " Convert a resource-graph generator spec (.graphml)\n" + " to AT&T GraphViz format (.dot). The output\n" + " file only contains the basic information unless --more is given.\n" + "\n" + " OPTIONS:\n" + " -h, --help\n" + " Display this usage information\n" + "\n" + " -m, --more\n" + " More information in the output file\n" + "\n"; exit (code); } diff --git a/resource/utilities/resource-query.cpp b/resource/utilities/resource-query.cpp index b64f61c45..51ee42c21 100644 --- a/resource/utilities/resource-query.cpp +++ b/resource/utilities/resource-query.cpp @@ -36,21 +36,21 @@ using boost::tie; #define OPTIONS "L:f:W:S:P:F:g:o:p:t:r:edh" static const struct option longopts[] = { - {"load-file", required_argument, 0, 'L'}, - {"load-format", required_argument, 0, 'f'}, - {"load-allowlist", required_argument, 0, 'W'}, - {"match-subsystems", required_argument, 0, 'S'}, - {"match-policy", required_argument, 0, 'P'}, - {"match-format", required_argument, 0, 'F'}, - {"graph-format", required_argument, 0, 'g'}, - {"graph-output", required_argument, 0, 'o'}, - {"prune-filters", required_argument, 0, 'p'}, - {"test-output", required_argument, 0, 't'}, - {"reserve-vtx-vec", required_argument, 0, 'r'}, - {"elapse-time", no_argument, 0, 'e'}, - {"disable-prompt", no_argument, 0, 'd'}, - {"help", no_argument, 0, 'h'}, - { 0, 0, 0, 0 }, + {"load-file", required_argument, 0, 'L'}, + {"load-format", required_argument, 0, 'f'}, + {"load-allowlist", required_argument, 0, 'W'}, + {"match-subsystems", required_argument, 0, 'S'}, + {"match-policy", required_argument, 0, 'P'}, + {"match-format", required_argument, 0, 'F'}, + {"graph-format", required_argument, 0, 'g'}, + {"graph-output", required_argument, 0, 'o'}, + {"prune-filters", required_argument, 0, 'p'}, + {"test-output", required_argument, 0, 't'}, + {"reserve-vtx-vec", required_argument, 0, 'r'}, + {"elapse-time", no_argument, 0, 'e'}, + {"disable-prompt", no_argument, 0, 'd'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0}, }; static void usage (int code) @@ -68,11 +68,11 @@ and populate the resource-graph data store representing the compute and other HPC resources and their relationships (RFC 4). Provide a simple command-line interface (cli) to allow users to allocate -or reserve the resource set in this resource-graph data store +or reserve the resource set in this resource-graph data store using a jobspec as an input. Traverse the resource graph in a predefined order for resource selection. Currently only support one traversal type: depth-first traversal on the -dominant subsystem and up-walk traversal on one or more auxiliary +dominant subsystem and up-walk traversal on one or more auxiliary subsystems. OPTIONS allow for using a predefined matcher that is configured @@ -118,7 +118,7 @@ To see cli commands, type in "help" in the cli: i.e., IB+IBBA: InfiniBand connection and Bandwidth-Aware C+P+IBA: Containment-, Power- and InfiniBand connection-Aware VA: Virtual Hierarchy-Aware - V+PFS1BA: Virtual Hierarchy and PFS1 Bandwidth-Aware + V+PFS1BA: Virtual Hierarchy and PFS1 Bandwidth-Aware ALL: Aware of everything. (default=CA). @@ -126,14 +126,14 @@ To see cli commands, type in "help" in the cli: i.e., Set the resource match selection policy. Available policies are: low: Select resources with low ID first high: Select resources with high ID first - lonode: Select resources with lowest node ID first, - low ID first otherwise (e.g., node-local resource types) - hinode: Select resources with highest node ID first, - high ID first otherwise (e.g., node-local resource types) - lonodex: Same as lonode except each node is exclusively allocated - hinodex: Same as hinode except each node is exclusively allocated + lonode: Select resources with lowest node ID first, + low ID first otherwise (e.g., node-local resource types) + hinode: Select resources with highest node ID first, + high ID first otherwise (e.g., node-local resource types) + lonodex: Same as lonode except each node is exclusively allocated + hinodex: Same as hinode except each node is exclusively allocated first: Select the first matching resources and stop the search - firstnodex: Select the first matching resources, node exclusive, + firstnodex: Select the first matching resources, node exclusive, and stop the search locality: Select contiguous resources first in their ID space variation: Allocate resources based on performance classes. @@ -219,20 +219,19 @@ static int graph_format_to_ext (emit_format_t format, std::string &st) { int rc = 0; switch (format) { - case emit_format_t::GRAPHVIZ_DOT: - st = "dot"; - break; - case emit_format_t::GRAPH_ML: - st = "graphml"; - break; - default: - rc = -1; + case emit_format_t::GRAPHVIZ_DOT: + st = "dot"; + break; + case emit_format_t::GRAPH_ML: + st = "graphml"; + break; + default: + rc = -1; } return rc; } -static int subsystem_exist (std::shared_ptr &ctx, - std::string n) +static int subsystem_exist (std::shared_ptr &ctx, std::string n) { int rc = 0; if (ctx->db->metadata.roots.find (n) == ctx->db->metadata.roots.end ()) @@ -240,8 +239,7 @@ static int subsystem_exist (std::shared_ptr &ctx, return rc; } -static int set_subsystems_use (std::shared_ptr &ctx, - std::string n) +static int set_subsystems_use (std::shared_ptr &ctx, std::string n) { int rc = 0; ctx->matcher->set_matcher_name (n); @@ -249,65 +247,65 @@ static int set_subsystems_use (std::shared_ptr &ctx, const std::string &matcher_type = matcher.matcher_name (); if (boost::iequals (matcher_type, std::string ("CA"))) { - if ( (rc = subsystem_exist (ctx, "containment")) == 0) + if ((rc = subsystem_exist (ctx, "containment")) == 0) matcher.add_subsystem ("containment", "*"); } else if (boost::iequals (matcher_type, std::string ("IBA"))) { - if ( (rc = subsystem_exist (ctx, "ibnet")) == 0) + if ((rc = subsystem_exist (ctx, "ibnet")) == 0) matcher.add_subsystem ("ibnet", "*"); } else if (boost::iequals (matcher_type, std::string ("IBBA"))) { - if ( (rc = subsystem_exist (ctx, "ibnetbw")) == 0) + if ((rc = subsystem_exist (ctx, "ibnetbw")) == 0) matcher.add_subsystem ("ibnetbw", "*"); } else if (boost::iequals (matcher_type, std::string ("PFS1BA"))) { - if ( (rc = subsystem_exist (ctx, "pfs1bw")) == 0) + if ((rc = subsystem_exist (ctx, "pfs1bw")) == 0) matcher.add_subsystem ("pfs1bw", "*"); } else if (boost::iequals (matcher_type, std::string ("PA"))) { - if ( (rc = subsystem_exist (ctx, "power")) == 0) + if ((rc = subsystem_exist (ctx, "power")) == 0) matcher.add_subsystem ("power", "*"); } else if (boost::iequals (matcher_type, std::string ("C+PFS1BA"))) { - if ( (rc = subsystem_exist (ctx, "containment")) == 0) + if ((rc = subsystem_exist (ctx, "containment")) == 0) matcher.add_subsystem ("containment", "contains"); - if ( !rc && (rc = subsystem_exist (ctx, "pfs1bw")) == 0) + if (!rc && (rc = subsystem_exist (ctx, "pfs1bw")) == 0) matcher.add_subsystem ("pfs1bw", "*"); } else if (boost::iequals (matcher_type, std::string ("C+IBA"))) { - if ( (rc = subsystem_exist (ctx, "containment")) == 0) + if ((rc = subsystem_exist (ctx, "containment")) == 0) matcher.add_subsystem ("containment", "contains"); - if ( !rc && (rc = subsystem_exist (ctx, "ibnet")) == 0) + if (!rc && (rc = subsystem_exist (ctx, "ibnet")) == 0) matcher.add_subsystem ("ibnet", "connected_up"); } else if (boost::iequals (matcher_type, std::string ("C+PA"))) { - if ( (rc = subsystem_exist (ctx, "containment")) == 0) + if ((rc = subsystem_exist (ctx, "containment")) == 0) matcher.add_subsystem ("containment", "*"); - if ( !rc && (rc = subsystem_exist (ctx, "power")) == 0) + if (!rc && (rc = subsystem_exist (ctx, "power")) == 0) matcher.add_subsystem ("power", "draws_from"); } else if (boost::iequals (matcher_type, std::string ("IB+IBBA"))) { - if ( (rc = subsystem_exist (ctx, "ibnet")) == 0) + if ((rc = subsystem_exist (ctx, "ibnet")) == 0) matcher.add_subsystem ("ibnet", "connected_down"); - if ( !rc && (rc = subsystem_exist (ctx, "ibnetbw")) == 0) + if (!rc && (rc = subsystem_exist (ctx, "ibnetbw")) == 0) matcher.add_subsystem ("ibnetbw", "*"); } else if (boost::iequals (matcher_type, std::string ("C+P+IBA"))) { - if ( (rc = subsystem_exist (ctx, "containment")) == 0) + if ((rc = subsystem_exist (ctx, "containment")) == 0) matcher.add_subsystem ("containment", "contains"); - if ( (rc = subsystem_exist (ctx, "power")) == 0) + if ((rc = subsystem_exist (ctx, "power")) == 0) matcher.add_subsystem ("power", "draws_from"); - if ( !rc && (rc = subsystem_exist (ctx, "ibnet")) == 0) + if (!rc && (rc = subsystem_exist (ctx, "ibnet")) == 0) matcher.add_subsystem ("ibnet", "connected_up"); } else if (boost::iequals (matcher_type, std::string ("V+PFS1BA"))) { - if ( (rc = subsystem_exist (ctx, "virtual1")) == 0) + if ((rc = subsystem_exist (ctx, "virtual1")) == 0) matcher.add_subsystem ("virtual1", "*"); - if ( !rc && (rc = subsystem_exist (ctx, "pfs1bw")) == 0) + if (!rc && (rc = subsystem_exist (ctx, "pfs1bw")) == 0) matcher.add_subsystem ("pfs1bw", "*"); } else if (boost::iequals (matcher_type, std::string ("VA"))) { - if ( (rc = subsystem_exist (ctx, "virtual1")) == 0) + if ((rc = subsystem_exist (ctx, "virtual1")) == 0) matcher.add_subsystem ("virtual1", "*"); } else if (boost::iequals (matcher_type, std::string ("ALL"))) { - if ( (rc = subsystem_exist (ctx, "containment")) == 0) + if ((rc = subsystem_exist (ctx, "containment")) == 0) matcher.add_subsystem ("containment", "*"); - if ( !rc && (rc = subsystem_exist (ctx, "ibnet")) == 0) + if (!rc && (rc = subsystem_exist (ctx, "ibnet")) == 0) matcher.add_subsystem ("ibnet", "*"); - if ( !rc && (rc = subsystem_exist (ctx, "ibnetbw")) == 0) + if (!rc && (rc = subsystem_exist (ctx, "ibnetbw")) == 0) matcher.add_subsystem ("ibnetbw", "*"); - if ( !rc && (rc = subsystem_exist (ctx, "pfs1bw")) == 0) + if (!rc && (rc = subsystem_exist (ctx, "pfs1bw")) == 0) matcher.add_subsystem ("pfs1bw", "*"); - if ( (rc = subsystem_exist (ctx, "power")) == 0) + if ((rc = subsystem_exist (ctx, "power")) == 0) matcher.add_subsystem ("power", "*"); } else { rc = -1; @@ -315,8 +313,7 @@ static int set_subsystems_use (std::shared_ptr &ctx, return rc; } -static void write_to_graphviz (resource_graph_t &fg, subsystem_t ss, - std::fstream &o) +static void write_to_graphviz (resource_graph_t &fg, subsystem_t ss, std::fstream &o) { f_res_name_map_t vmap = get (&resource_t::name, fg); f_edg_infra_map_t emap = get (&resource_relation_t::idata, fg); @@ -373,14 +370,10 @@ static void write_to_graphml (resource_graph_t &fg, std::fstream &o) boost::dynamic_properties dp; std::map esubsystems; std::map subsystems, properties, paths; - boost::associative_property_map< - std::map> subsystems_map (subsystems); - boost::associative_property_map< - std::map> esubsystems_map (esubsystems); - boost::associative_property_map< - std::map> props_map (properties); - boost::associative_property_map< - std::map> paths_map (paths); + boost::associative_property_map> subsystems_map (subsystems); + boost::associative_property_map> esubsystems_map (esubsystems); + boost::associative_property_map> props_map (properties); + boost::associative_property_map> paths_map (paths); flatten (fg, paths, subsystems, esubsystems, properties); @@ -408,20 +401,19 @@ static void write_to_graph (std::shared_ptr &ctx) mn = ctx->matcher->matcher_name (); fn = ctx->params.o_fname + "." + ctx->params.o_fext; - std::cout << "INFO: Write the target graph of the matcher..." - << std::endl; + std::cout << "INFO: Write the target graph of the matcher..." << std::endl; o.open (fn, std::fstream::out); switch (ctx->params.o_format) { - case emit_format_t::GRAPHVIZ_DOT: - write_to_graphviz (ctx->db->resource_graph, ctx->matcher->dom_subsystem (), o); - break; - case emit_format_t::GRAPH_ML: - write_to_graphml (ctx->db->resource_graph, o); - break; - default: - std::cout << "ERROR: Unknown graph format" << std::endl; - break; + case emit_format_t::GRAPHVIZ_DOT: + write_to_graphviz (ctx->db->resource_graph, ctx->matcher->dom_subsystem (), o); + break; + case emit_format_t::GRAPH_ML: + write_to_graphml (ctx->db->resource_graph, o); + break; + default: + std::cout << "ERROR: Unknown graph format" << std::endl; + break; } if (o.bad ()) { std::cerr << "ERROR: Failure encountered in writing" << std::endl; @@ -434,8 +426,7 @@ static void control_loop (std::shared_ptr &ctx) { cmd_func_f *cmd = NULL; while (1) { - char *line = ctx->params.disable_prompt? readline ("") - : readline ("resource-query> "); + char *line = ctx->params.disable_prompt ? readline ("") : readline ("resource-query> "); if (line == NULL) continue; else if (*line) @@ -445,8 +436,8 @@ static void control_loop (std::shared_ptr &ctx) std::istringstream iss (line); std::copy (std::istream_iterator (iss), std::istream_iterator (), - back_inserter (tokens)); - free(line); + back_inserter (tokens)); + free (line); if (tokens.empty ()) continue; @@ -468,9 +459,8 @@ static int populate_resource_db (std::shared_ptr &ctx) std::shared_ptr rd; if (ctx->params.reserve_vtx_vec != 0) - ctx->db->resource_graph.m_vertices.reserve ( - ctx->params.reserve_vtx_vec); - if ( (rd = create_resource_reader (ctx->params.load_format)) == nullptr) { + ctx->db->resource_graph.m_vertices.reserve (ctx->params.reserve_vtx_vec); + if ((rd = create_resource_reader (ctx->params.load_format)) == nullptr) { std::cerr << "ERROR: Can't create load reader " << std::endl; goto done; } @@ -490,7 +480,7 @@ static int populate_resource_db (std::shared_ptr &ctx) in_file.close (); gettimeofday (&st, NULL); - if ( (rc = ctx->db->load (buffer.str (), rd)) != 0) { + if ((rc = ctx->db->load (buffer.str (), rd)) != 0) { std::cerr << "ERROR: " << rd->err_message () << std::endl; std::cerr << "ERROR: error in generating resources" << std::endl; goto done; @@ -503,16 +493,16 @@ static int populate_resource_db (std::shared_ptr &ctx) std::cout << "INFO: Graph Load Time: " << elapse << std::endl; std::cout << "INFO: Vertex Count: " << num_vertices (g) << std::endl; std::cout << "INFO: Edge Count: " << num_edges (g) << std::endl; - std::cout << "INFO: by_type Key-Value Pairs: " << - ctx->db->metadata.by_type.size () << std::endl; - std::cout << "INFO: by_name Key-Value Pairs: " << - ctx->db->metadata.by_name.size () << std::endl; - std::cout << "INFO: by_path Key-Value Pairs: " << - ctx->db->metadata.by_path.size () << std::endl; - for (auto it = ctx->db->metadata.by_rank.begin (); - it != ctx->db->metadata.by_rank.end (); ++it) { - std::cout << "INFO: number of vertices with rank " - << it->first << ": " << it->second.size () << "\n"; + std::cout << "INFO: by_type Key-Value Pairs: " << ctx->db->metadata.by_type.size () + << std::endl; + std::cout << "INFO: by_name Key-Value Pairs: " << ctx->db->metadata.by_name.size () + << std::endl; + std::cout << "INFO: by_path Key-Value Pairs: " << ctx->db->metadata.by_path.size () + << std::endl; + for (auto it = ctx->db->metadata.by_rank.begin (); it != ctx->db->metadata.by_rank.end (); + ++it) { + std::cout << "INFO: number of vertices with rank " << it->first << ": " + << it->second.size () << "\n"; } } @@ -524,17 +514,15 @@ static int init_resource_graph (std::shared_ptr &ctx) { int rc = 0; - if ( (rc = populate_resource_db (ctx)) != 0) { - std::cerr << "ERROR: can't populate graph resource database" - << std::endl; + if ((rc = populate_resource_db (ctx)) != 0) { + std::cerr << "ERROR: can't populate graph resource database" << std::endl; return rc; } resource_graph_t &g = ctx->db->resource_graph; // Configure the matcher and its subsystem selector - std::cout << "INFO: Loading a matcher: " << ctx->params.matcher_name - << std::endl; - if ( (rc = set_subsystems_use (ctx, ctx->params.matcher_name)) != 0) { + std::cout << "INFO: Loading a matcher: " << ctx->params.matcher_name << std::endl; + if ((rc = set_subsystems_use (ctx, ctx->params.matcher_name)) != 0) { std::cerr << "ERROR: Not all subsystems found" << std::endl; return rc; } @@ -543,16 +531,14 @@ static int init_resource_graph (std::shared_ptr &ctx) if (ctx->params.prune_filters != "" && ctx->matcher->set_pruning_types_w_spec (ctx->matcher->dom_subsystem (), ctx->params.prune_filters) - < 0) { - std::cerr - << "ERROR: setting pruning filters with ctx->params.prune_filters: " - << ctx->params.prune_filters << std::endl; + < 0) { + std::cerr << "ERROR: setting pruning filters with ctx->params.prune_filters: " + << ctx->params.prune_filters << std::endl; return -1; } if (ctx->params.r_fname != "") { - ctx->params.r_out.exceptions (std::ofstream::failbit - | std::ofstream::badbit); + ctx->params.r_out.exceptions (std::ofstream::failbit | std::ofstream::badbit); ctx->params.r_out.open (ctx->params.r_fname); } @@ -564,23 +550,20 @@ static int init_resource_graph (std::shared_ptr &ctx) return -1; } - if ( (rc = ctx->traverser->initialize (ctx->db, ctx->matcher)) != 0) { + if ((rc = ctx->traverser->initialize (ctx->db, ctx->matcher)) != 0) { std::cerr << "ERROR: initializing traverser" << std::endl; return -1; } - match_format_t format = match_writers_factory_t:: - get_writers_type (ctx->params.match_format); - if ( !(ctx->writers = match_writers_factory_t::create (format))) { - std::cerr << "ERROR: out of memory allocating traverser" - << std::endl; + match_format_t format = match_writers_factory_t::get_writers_type (ctx->params.match_format); + if (!(ctx->writers = match_writers_factory_t::create (format))) { + std::cerr << "ERROR: out of memory allocating traverser" << std::endl; return -1; } return rc; } -static void process_args (std::shared_ptr &ctx, - int argc, char *argv[]) +static void process_args (std::shared_ptr &ctx, int argc, char *argv[]) { int rc = 0; int ch = 0; @@ -593,11 +576,11 @@ static void process_args (std::shared_ptr &ctx, break; case 'L': /* --load-file */ ctx->params.load_file = optarg; - if (!fs::exists(ctx->params.load_file)) { + if (!fs::exists (ctx->params.load_file)) { std::cerr << "[ERROR] file does not exist for --load-file: "; std::cerr << optarg << std::endl; usage (1); - } else if (fs::is_directory(ctx->params.load_file)) { + } else if (fs::is_directory (ctx->params.load_file)) { std::cerr << "[ERROR] path passed to --load-file is a directory: "; std::cerr << optarg << std::endl; usage (1); @@ -613,7 +596,7 @@ static void process_args (std::shared_ptr &ctx, break; case 'W': /* --hwloc-allowlist */ token = optarg; - if(token.find_first_not_of(' ') != std::string::npos) { + if (token.find_first_not_of (' ') != std::string::npos) { ctx->params.load_allowlist += "cluster,"; ctx->params.load_allowlist += token; } @@ -634,7 +617,7 @@ static void process_args (std::shared_ptr &ctx, break; case 'g': /* --graph-format */ rc = string_to_graph_format (optarg, ctx->params.o_format); - if ( rc != 0) { + if (rc != 0) { std::cerr << "[ERROR] unknown format for --graph-format: "; std::cerr << optarg << std::endl; usage (1); @@ -646,7 +629,7 @@ static void process_args (std::shared_ptr &ctx, break; case 'p': /* --prune-filters */ token = optarg; - if(token.find_first_not_of(' ') != std::string::npos) { + if (token.find_first_not_of (' ') != std::string::npos) { ctx->params.prune_filters += ","; ctx->params.prune_filters += token; } @@ -657,11 +640,9 @@ static void process_args (std::shared_ptr &ctx, case 'r': /* --reserve-vtx-vec */ // If atoi fails, it defaults to 0, which is fine for us ctx->params.reserve_vtx_vec = atoi (optarg); - if ( (ctx->params.reserve_vtx_vec < 0) - || (ctx->params.reserve_vtx_vec > 2000000)) { + if ((ctx->params.reserve_vtx_vec < 0) || (ctx->params.reserve_vtx_vec > 2000000)) { ctx->params.reserve_vtx_vec = 0; - std::cerr - << "WARN: out of range specified for --reserve-vtx-vec: "; + std::cerr << "WARN: out of range specified for --reserve-vtx-vec: "; std::cerr << optarg << std::endl; } break; @@ -681,27 +662,25 @@ static void process_args (std::shared_ptr &ctx, usage (1); } -static std::shared_ptr init_resource_query (int c, - char *v[]) +static std::shared_ptr init_resource_query (int c, char *v[]) { std::shared_ptr ctx = nullptr; try { ctx = std::make_shared (); - ctx->db = std::make_shared (); + ctx->db = std::make_shared (); } catch (std::bad_alloc &e) { - std::cerr << "ERROR: out of memory allocating resource context" - << std::endl; + std::cerr << "ERROR: out of memory allocating resource context" << std::endl; errno = ENOMEM; goto done; } set_default_params (ctx); process_args (ctx, c, v); - ctx->perf.min = std::numeric_limits::max(); + ctx->perf.min = std::numeric_limits::max (); ctx->perf.max = 0.0f; ctx->perf.accum = 0.0f; - if ( !(ctx->matcher = create_match_cb (ctx->params.matcher_policy))) { + if (!(ctx->matcher = create_match_cb (ctx->params.matcher_policy))) { std::cerr << "ERROR: unknown match policy " << std::endl; std::cerr << "ERROR: " << ctx->params.matcher_policy << std::endl; ctx = nullptr; @@ -726,7 +705,7 @@ static void fini_resource_query (std::shared_ptr &ctx) int main (int argc, char *argv[]) { std::shared_ptr ctx = nullptr; - if ( !(ctx = init_resource_query (argc, argv))) { + if (!(ctx = init_resource_query (argc, argv))) { std::cerr << "ERROR: resource query initialization" << std::endl; return EXIT_FAILURE; } diff --git a/resource/utilities/rq2.cpp b/resource/utilities/rq2.cpp index 2193d984f..47e30c473 100644 --- a/resource/utilities/rq2.cpp +++ b/resource/utilities/rq2.cpp @@ -23,27 +23,25 @@ using namespace Flux; using namespace Flux::resource_model; using namespace Flux::resource_model::detail; -typedef int cmd_func_f (resource_query_t &, - std::vector &, - json_t *, std::ostream &); +typedef int cmd_func_f (resource_query_t &, std::vector &, json_t *, std::ostream &); #define OPTIONS "L:f:W:S:P:F:g:o:p:t:r:edh" static const struct option longopts[] = { - {"load-file", required_argument, 0, 'L'}, - {"load-format", required_argument, 0, 'f'}, - {"load-allowlist", required_argument, 0, 'W'}, - {"match-subsystems", required_argument, 0, 'S'}, - {"match-policy", required_argument, 0, 'P'}, - {"match-format", required_argument, 0, 'F'}, - {"graph-format", required_argument, 0, 'g'}, - {"graph-output", required_argument, 0, 'o'}, - {"prune-filters", required_argument, 0, 'p'}, - {"test-output", required_argument, 0, 't'}, - {"reserve-vtx-vec", required_argument, 0, 'r'}, - {"elapse-time", no_argument, 0, 'e'}, - {"disable-prompt", no_argument, 0, 'd'}, - {"help", no_argument, 0, 'h'}, - { 0, 0, 0, 0 }, + {"load-file", required_argument, 0, 'L'}, + {"load-format", required_argument, 0, 'f'}, + {"load-allowlist", required_argument, 0, 'W'}, + {"match-subsystems", required_argument, 0, 'S'}, + {"match-policy", required_argument, 0, 'P'}, + {"match-format", required_argument, 0, 'F'}, + {"graph-format", required_argument, 0, 'g'}, + {"graph-output", required_argument, 0, 'o'}, + {"prune-filters", required_argument, 0, 'p'}, + {"test-output", required_argument, 0, 't'}, + {"reserve-vtx-vec", required_argument, 0, 'r'}, + {"elapse-time", no_argument, 0, 'e'}, + {"disable-prompt", no_argument, 0, 'd'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0}, }; struct command_t { @@ -53,145 +51,153 @@ struct command_t { std::string note; }; -command_t commands[] = { - { "match", "m", match, "Allocate or reserve matching resources (subcmd: " -"allocate | allocate_with_satisfiability | allocate_orelse_reserve) | " -"satisfiability: " -"resource-query> match allocate jobspec"}, - { "help", "h", help, "Print help message: resource-query> help" }, - { "quit", "q", quit, "Quit the session: resource-query> quit" }, - { "NA", "NA", (cmd_func_f *)NULL, "NA" } -}; - +command_t commands[] = {{"match", + "m", + match, + "Allocate or reserve matching resources (subcmd: " + "allocate | allocate_with_satisfiability | allocate_orelse_reserve) | " + "satisfiability: " + "resource-query> match allocate jobspec"}, + {"help", "h", help, "Print help message: resource-query> help"}, + {"quit", "q", quit, "Quit the session: resource-query> quit"}, + {"NA", "NA", (cmd_func_f *)NULL, "NA"}}; static void usage (int code) { - std::cerr << -"usage: resource-query [OPTIONS...]\n" -"\n" -"Command-line utility that takes in an HPC resource request written in\n" -"Flux's Canonical Job Specification (or simply a jobspec) (RFC 14) and\n" -"selects the best-matching compute and other resources in accordance\n" -"with a selection policy.\n" -"\n" -"Read in a resource-graph generation recipe written in the GRUG format\n" -"and populate the resource-graph data store representing the compute and\n" -"other HPC resources and their relationships (RFC 4).\n" -"\n" -"Provide a simple command-line interface (cli) to allow users to allocate\n" -"or reserve the resource set in this resource-graph data store \n" -"using a jobspec as an input.\n" -"Traverse the resource graph in a predefined order for resource selection.\n" -"Currently only support one traversal type: depth-first traversal on the\n" -"dominant subsystem and up-walk traversal on one or more auxiliary \n" -"subsystems.\n" -"\n" -"OPTIONS allow for using a predefined matcher that is configured\n" -"to use a different set of subsystems as its dominant and/or auxiliary\n" -"ones to perform the matches on.\n" -"\n" -"OPTIONS also allow for instantiating a different resource-matching\n" -"selection policy--e.g., select resources with high or low IDs first.\n" -"\n" -"OPTIONS allow for exporting the filtered graph of the used matcher\n" -"in a selected graph format at the end of the cli session.\n" -"\n" -"To see cli commands, type in \"help\" in the cli: i.e.,\n" -" % resource-query> help\n" -"\n" -"\n" -"\n" -"OPTIONS:\n" -" -h, --help\n" -" Display this usage information\n" -"\n" -" -L, --load-file=filepath\n" -" Input file from which to load the resource graph data store\n" -" (default=conf/default)\n" -"\n" -" -f, --load-format=\n" -" Format of the load file (default=grug)\n" -"\n" -" -W, --load-allowlist=\n" -" Allowlist of resource types to be loaded\n" -" Resources that are not included in this list will be filtered out\n" -"\n" -" -S, --match-subsystems=" - "\n" -" Set the predefined matcher to use. Available matchers are:\n" -" CA: Containment Aware\n" -" IBA: InfiniBand connection-Aware\n" -" IBBA: InfiniBand Bandwidth-Aware\n" -" PFS1BA: Parallel File System 1 Bandwidth-aware\n" -" PA: Power-Aware\n" -" C+IBA: Containment- and InfiniBand connection-Aware\n" -" C+PFS1BA: Containment- and PFS1 Bandwidth-Aware\n" -" C+PA: Containment- and Power-Aware\n" -" IB+IBBA: InfiniBand connection and Bandwidth-Aware\n" -" C+P+IBA: Containment-, Power- and InfiniBand connection-Aware\n" -" VA: Virtual Hierarchy-Aware\n" -" V+PFS1BA: Virtual Hierarchy and PFS1 Bandwidth-Aware \n" -" ALL: Aware of everything.\n" -" (default=CA).\n" -"\n" -" -P, --match-policy=\n" -" Set the resource match selection policy. Available policies are:\n" -" low: Select resources with low ID first\n" -" high: Select resources with high ID first\n" -" lonode: Select resources with lowest node ID first, \n" -" low ID first otherwise (e.g., node-local resource types) \n" -" hinode: Select resources with highest node ID first, \n" -" high ID first otherwise (e.g., node-local resource types) \n" -" lonodex: Same as lonode except each node is exclusively allocated \n" -" hinodex: Same as hinode except each node is exclusively allocated \n" -" first: Select the first matching resources and stop the search\n" -" locality: Select contiguous resources first in their ID space\n" -" variation: Allocate resources based on performance classes.\n" -" (perf_class must be set using set-property).\n" -" (default=first).\n" -"\n" -" -F, --match-format=\n" -" Specify the emit format of the matched resource set.\n" -" (default=simple).\n" -"\n" -" -p, --prune-filters=\n" -" Install a planner-based filter at each High-Level (HL) resource\n" -" vertex which tracks the state of the Low-Level (LL) resources\n" -" in aggregate, residing under its subtree. If a jobspec requests\n" -" 1 node with 4 cores, and the visiting compute-node vertex has\n" -" only a total of 2 available cores in aggregate at its\n" -" subtree, this filter allows the traverser to prune a further descent\n" -" to accelerate the search.\n" -" Use the ALL keyword for HL-resource if you want LL-resource to be\n" -" tracked at all of the HL-resource vertices. Examples:\n" -" rack:node,node:core\n" -" ALL:core,cluster:node,rack:node\n" -" (default=ALL:core).\n" -"\n" -" -g, --graph-format=\n" -" Specify the graph format of the output file\n" -" (default=dot).\n" -"\n" -" -r, --reserve-vtx-vec=\n" -" Reserve the graph vertex size to optimize resource graph loading.\n" -" The size value must be a non-zero integer up to 2000000.\n" -"\n" -" -e, --elapse-time\n" -" Print the elapse time per scheduling operation.\n" -"\n" -" -d, --disable-prompt\n" -" Don't print the prompt.\n" -"\n" -" -o, --graph-output=\n" -" Set the basename of the graph output file\n" -" For AT&T Graphviz dot, .dot\n" -" For GraphML, .graphml.\n" -"\n" -" -t, --test-output=\n" -" Set the output filename where allocated or reserved resource\n" -" information is stored into.\n" -"\n"; + std::cerr << "usage: resource-query [OPTIONS...]\n" + "\n" + "Command-line utility that takes in an HPC resource request written in\n" + "Flux's Canonical Job Specification (or simply a jobspec) (RFC 14) and\n" + "selects the best-matching compute and other resources in accordance\n" + "with a selection policy.\n" + "\n" + "Read in a resource-graph generation recipe written in the GRUG format\n" + "and populate the resource-graph data store representing the compute and\n" + "other HPC resources and their relationships (RFC 4).\n" + "\n" + "Provide a simple command-line interface (cli) to allow users to allocate\n" + "or reserve the resource set in this resource-graph data store \n" + "using a jobspec as an input.\n" + "Traverse the resource graph in a predefined order for resource selection.\n" + "Currently only support one traversal type: depth-first traversal on the\n" + "dominant subsystem and up-walk traversal on one or more auxiliary \n" + "subsystems.\n" + "\n" + "OPTIONS allow for using a predefined matcher that is configured\n" + "to use a different set of subsystems as its dominant and/or auxiliary\n" + "ones to perform the matches on.\n" + "\n" + "OPTIONS also allow for instantiating a different resource-matching\n" + "selection policy--e.g., select resources with high or low IDs first.\n" + "\n" + "OPTIONS allow for exporting the filtered graph of the used matcher\n" + "in a selected graph format at the end of the cli session.\n" + "\n" + "To see cli commands, type in \"help\" in the cli: i.e.,\n" + " % resource-query> help\n" + "\n" + "\n" + "\n" + "OPTIONS:\n" + " -h, --help\n" + " Display this usage information\n" + "\n" + " -L, --load-file=filepath\n" + " Input file from which to load the resource graph data store\n" + " (default=conf/default)\n" + "\n" + " -f, --load-format=\n" + " Format of the load file (default=grug)\n" + "\n" + " -W, --load-allowlist=\n" + " Allowlist of resource types to be loaded\n" + " Resources that are not included in this list will be filtered out\n" + "\n" + " -S, --match-subsystems=" + "\n" + " Set the predefined matcher to use. Available matchers are:\n" + " CA: Containment Aware\n" + " IBA: InfiniBand connection-Aware\n" + " IBBA: InfiniBand Bandwidth-Aware\n" + " PFS1BA: Parallel File System 1 Bandwidth-aware\n" + " PA: Power-Aware\n" + " C+IBA: Containment- and InfiniBand connection-Aware\n" + " C+PFS1BA: Containment- and PFS1 Bandwidth-Aware\n" + " C+PA: Containment- and Power-Aware\n" + " IB+IBBA: InfiniBand connection and Bandwidth-Aware\n" + " C+P+IBA: Containment-, Power- and InfiniBand connection-Aware\n" + " VA: Virtual Hierarchy-Aware\n" + " V+PFS1BA: Virtual Hierarchy and PFS1 Bandwidth-Aware \n" + " ALL: Aware of everything.\n" + " (default=CA).\n" + "\n" + " -P, " + "--match-policy=" + "\n" + " Set the resource match selection policy. Available policies are:\n" + " low: Select resources with low ID first\n" + " high: Select resources with high ID first\n" + " lonode: Select resources with lowest node ID first, \n" + " low ID first otherwise (e.g., node-local resource types) " + "\n" + " hinode: Select resources with highest node ID first, \n" + " high ID first otherwise (e.g., node-local resource " + "types) \n" + " lonodex: Same as lonode except each node is exclusively " + "allocated \n" + " hinodex: Same as hinode except each node is exclusively " + "allocated \n" + " first: Select the first matching resources and stop the search\n" + " locality: Select contiguous resources first in their ID space\n" + " variation: Allocate resources based on performance classes.\n" + " (perf_class must be set using set-property).\n" + " (default=first).\n" + "\n" + " -F, --match-format=\n" + " Specify the emit format of the matched resource set.\n" + " (default=simple).\n" + "\n" + " -p, " + "--prune-filters=\n" + " Install a planner-based filter at each High-Level (HL) resource\n" + " vertex which tracks the state of the Low-Level (LL) resources\n" + " in aggregate, residing under its subtree. If a jobspec requests\n" + " 1 node with 4 cores, and the visiting compute-node vertex has\n" + " only a total of 2 available cores in aggregate at its\n" + " subtree, this filter allows the traverser to prune a further " + "descent\n" + " to accelerate the search.\n" + " Use the ALL keyword for HL-resource if you want LL-resource to " + "be\n" + " tracked at all of the HL-resource vertices. Examples:\n" + " rack:node,node:core\n" + " ALL:core,cluster:node,rack:node\n" + " (default=ALL:core).\n" + "\n" + " -g, --graph-format=\n" + " Specify the graph format of the output file\n" + " (default=dot).\n" + "\n" + " -r, --reserve-vtx-vec=\n" + " Reserve the graph vertex size to optimize resource graph loading.\n" + " The size value must be a non-zero integer up to 2000000.\n" + "\n" + " -e, --elapse-time\n" + " Print the elapse time per scheduling operation.\n" + "\n" + " -d, --disable-prompt\n" + " Don't print the prompt.\n" + "\n" + " -o, --graph-output=\n" + " Set the basename of the graph output file\n" + " For AT&T Graphviz dot, .dot\n" + " For GraphML, .graphml.\n" + "\n" + " -t, --test-output=\n" + " Set the output filename where allocated or reserved resource\n" + " information is stored into.\n" + "\n"; exit (code); } @@ -211,42 +217,50 @@ static int graph_format_to_ext (Flux::resource_model::emit_format_t format, std: { int rc = 0; switch (format) { - case Flux::resource_model::emit_format_t::GRAPHVIZ_DOT: - st = "dot"; - break; - case Flux::resource_model::emit_format_t::GRAPH_ML: - st = "graphml"; - break; - default: - rc = -1; + case Flux::resource_model::emit_format_t::GRAPHVIZ_DOT: + st = "dot"; + break; + case Flux::resource_model::emit_format_t::GRAPH_ML: + st = "graphml"; + break; + default: + rc = -1; } return rc; } static void print_sat_info (resource_query_t &ctx, - std::ostream &out, bool sat, double elapse, + std::ostream &out, + bool sat, + double elapse, bool print_elapse) { unsigned int pre = reapi_cli_t::preorder_count (&ctx); unsigned int post = reapi_cli_t::postorder_count (&ctx); - std::string satstr = sat? "Satisfiable" : "Unsatisfiable"; - out << "INFO:" << " =============================" << std::endl; + std::string satstr = sat ? "Satisfiable" : "Unsatisfiable"; + out << "INFO:" + << " =============================" << std::endl; out << "INFO: " << satstr << " request" << std::endl; - out << "INFO:" << " =============================" << std::endl; + out << "INFO:" + << " =============================" << std::endl; if (print_elapse) { - std::cout << "INFO:" << " ELAPSE=" << std::to_string (elapse) - << std::endl; - std::cout << "INFO:" << " PREORDER VISIT COUNT=" << pre - << std::endl; - std::cout << "INFO:" << " POSTORDER VISIT COUNT=" << post - << std::endl; + std::cout << "INFO:" + << " ELAPSE=" << std::to_string (elapse) << std::endl; + std::cout << "INFO:" + << " PREORDER VISIT COUNT=" << pre << std::endl; + std::cout << "INFO:" + << " POSTORDER VISIT COUNT=" << post << std::endl; } } static void print_schedule_info (resource_query_t &ctx, - std::ostream &out, uint64_t jobid, - const std::string &jobspec_fn, bool matched, - int64_t at, bool sat, double elapse, + std::ostream &out, + uint64_t jobid, + const std::string &jobspec_fn, + bool matched, + int64_t at, + bool sat, + double elapse, bool print_elapse) { unsigned int pre = reapi_cli_t::preorder_count (&ctx); @@ -254,39 +268,49 @@ static void print_schedule_info (resource_query_t &ctx, if (matched) { job_lifecycle_t st; std::shared_ptr job = nullptr; - std::string mode = (at == 0)? "ALLOCATED" : "RESERVED"; - std::string scheduled_at = (at == 0)? "Now" : std::to_string (at); - out << "INFO:" << " =============================" << std::endl; - out << "INFO:" << " JOBID=" << jobid << std::endl; - out << "INFO:" << " RESOURCES=" << mode << std::endl; - out << "INFO:" << " SCHEDULED AT=" << scheduled_at << std::endl; + std::string mode = (at == 0) ? "ALLOCATED" : "RESERVED"; + std::string scheduled_at = (at == 0) ? "Now" : std::to_string (at); + out << "INFO:" + << " =============================" << std::endl; + out << "INFO:" + << " JOBID=" << jobid << std::endl; + out << "INFO:" + << " RESOURCES=" << mode << std::endl; + out << "INFO:" + << " SCHEDULED AT=" << scheduled_at << std::endl; if (print_elapse) { - std::cout << "INFO:" << " ELAPSE=" << std::to_string (elapse) - << std::endl; - std::cout << "INFO:" << " PREORDER VISIT COUNT=" << pre - << std::endl; - std::cout << "INFO:" << " POSTORDER VISIT COUNT=" << post - << std::endl; + std::cout << "INFO:" + << " ELAPSE=" << std::to_string (elapse) << std::endl; + std::cout << "INFO:" + << " PREORDER VISIT COUNT=" << pre << std::endl; + std::cout << "INFO:" + << " POSTORDER VISIT COUNT=" << post << std::endl; } - out << "INFO:" << " =============================" << std::endl; - st = (at == 0)? job_lifecycle_t::ALLOCATED : job_lifecycle_t::RESERVED; + out << "INFO:" + << " =============================" << std::endl; + st = (at == 0) ? job_lifecycle_t::ALLOCATED : job_lifecycle_t::RESERVED; if (reapi_cli_t::info (&ctx, jobid, job) == 0) job->jobspec_fn = jobspec_fn; } else { - out << "INFO:" << " =============================" << std::endl; - out << "INFO: " << "No matching resources found" << std::endl; + out << "INFO:" + << " =============================" << std::endl; + out << "INFO: " + << "No matching resources found" << std::endl; if (!sat) - out << "INFO: " << "Unsatisfiable request" << std::endl; - out << "INFO:" << " JOBID=" << jobid << std::endl; + out << "INFO: " + << "Unsatisfiable request" << std::endl; + out << "INFO:" + << " JOBID=" << jobid << std::endl; if (print_elapse) { - out << "INFO:" << " ELAPSE=" << std::to_string (elapse) - << std::endl; - std::cout << "INFO:" << " PREORDER VISIT COUNT=" << pre - << std::endl; - std::cout << "INFO:" << " POSTORDER VISIT COUNT=" << post - << std::endl; + out << "INFO:" + << " ELAPSE=" << std::to_string (elapse) << std::endl; + std::cout << "INFO:" + << " PREORDER VISIT COUNT=" << pre << std::endl; + std::cout << "INFO:" + << " POSTORDER VISIT COUNT=" << post << std::endl; } - out << "INFO:" << " =============================" << std::endl; + out << "INFO:" + << " =============================" << std::endl; } } @@ -295,19 +319,18 @@ bool r_fname_set (json_t *params) return (json_object_get (params, "r_fname") != NULL); } -std::ofstream open_fs (json_t *params) { +std::ofstream open_fs (json_t *params) +{ std::string r_fname = json_string_value (json_object_get (params, "r_fname")); - std::ofstream r_out; + std::ofstream r_out; + + r_out.exceptions (std::ofstream::failbit | std::ofstream::badbit); - r_out.exceptions (std::ofstream::failbit | - std::ofstream::badbit); - r_out.open (r_fname); return r_out; } -int match (resource_query_t &ctx, std::vector &args, - json_t *params, std::ostream &out) +int match (resource_query_t &ctx, std::vector &args, json_t *params, std::ostream &out) { int rc = 0; int64_t at = 0; @@ -318,9 +341,9 @@ int match (resource_query_t &ctx, std::vector &args, std::string R = ""; double ov = 0.0; std::stringstream o; - struct timeval st, et; - - if ( (gettimeofday (&st, NULL)) < 0) { + struct timeval st, et; + + if ((gettimeofday (&st, NULL)) < 0) { std::cerr << "ERROR: gettimeofday: " << strerror (errno) << std::endl; return 0; } @@ -342,7 +365,7 @@ int match (resource_query_t &ctx, std::vector &args, std::cerr << "ERROR: unknown subcmd " << args[1] << std::endl; return 0; } - + uint64_t jobid = ctx.get_job_counter (); std::string &jobspec_fn = args[2]; std::ifstream jobspec_in (jobspec_fn); @@ -350,19 +373,19 @@ int match (resource_query_t &ctx, std::vector &args, std::cerr << "ERROR: can't open " << jobspec_fn << std::endl; return 0; } - std::string jobspec ( (std::istreambuf_iterator (jobspec_in) ), - (std::istreambuf_iterator () ) ); + std::string jobspec ((std::istreambuf_iterator (jobspec_in)), + (std::istreambuf_iterator ())); rc = reapi_cli_t::match_allocate (&ctx, match_op, jobspec, jobid, reserved, R, at, ov); - // check for match success - if ( (errno == ENODEV) || (errno == EBUSY) || (errno == EINVAL)) + // check for match success + if ((errno == ENODEV) || (errno == EBUSY) || (errno == EINVAL)) matched = false; - + // check for satisfiability if (errno == ENODEV) sat = false; - + if (reapi_cli_t::get_err_message () != "") { std::cerr << reapi_cli_t::get_err_message () << std::endl; reapi_cli_t::clear_err_message (); @@ -370,32 +393,35 @@ int match (resource_query_t &ctx, std::vector &args, out << R; - if ( (gettimeofday (&et, NULL)) < 0) { + if ((gettimeofday (&et, NULL)) < 0) { std::cerr << "ERROR: gettimeofday: " << strerror (errno) << std::endl; return 0; } if (subcmd != "satisfiability") - print_schedule_info (ctx, out, jobid, - jobspec_fn, matched, at, sat, - ov, json_object_get (params, "elapse_time")); + print_schedule_info (ctx, + out, + jobid, + jobspec_fn, + matched, + at, + sat, + ov, + json_object_get (params, "elapse_time")); else - print_sat_info (ctx, out, sat, ov, - json_object_get (params, "elapse_time")); + print_sat_info (ctx, out, sat, ov, json_object_get (params, "elapse_time")); jobspec_in.close (); return 0; } -int quit (resource_query_t &ctx, std::vector &args, - json_t *params, std::ostream &out) +int quit (resource_query_t &ctx, std::vector &args, json_t *params, std::ostream &out) { return -1; } -int help (resource_query_t &ctx, std::vector &args, - json_t *params, std::ostream &out) +int help (resource_query_t &ctx, std::vector &args, json_t *params, std::ostream &out) { bool multi = true; bool found = false; @@ -408,9 +434,8 @@ int help (resource_query_t &ctx, std::vector &args, for (int i = 0; commands[i].name != "NA"; ++i) { if (multi || cmd == commands[i].name || cmd == commands[i].abbr) { - std::cout << "INFO: " << commands[i].name << " (" - << commands[i].abbr << ")" << " -- " - << commands[i].note << std::endl; + std::cout << "INFO: " << commands[i].name << " (" << commands[i].abbr << ")" + << " -- " << commands[i].note << std::endl; found = true; } } @@ -431,19 +456,17 @@ cmd_func_f *find_cmd (const std::string &cmd_str) return (cmd_func_f *)NULL; } -static void process_args (json_t *options, - int argc, char *argv[]) +static void process_args (json_t *options, int argc, char *argv[]) { int rc = 0; int ch = 0; std::string token; Flux::resource_model::emit_format_t format; - /* set defaults specific for resource query */ json_object_set_new (options, "match_format", json_string ("simple")); - while ( (ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) { + while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) { switch (ch) { case 'h': /* --help */ usage (0); @@ -471,13 +494,15 @@ static void process_args (json_t *options, case 'W': /* --hwloc-allowlist */ token = optarg; if (token.find_first_not_of (' ') != std::string::npos) { - if (!json_object_get (options,"load_allowlist")) { + if (!json_object_get (options, "load_allowlist")) { json_object_set_new (options, "load_allowlist", json_string ("")); } - json_object_set_new (options, "load_allowlist", - json_pack ("s++", - json_object_get (options,"load_allowlist"), - "cluster,", token.c_str ())); + json_object_set_new (options, + "load_allowlist", + json_pack ("s++", + json_object_get (options, "load_allowlist"), + "cluster,", + token.c_str ())); } break; case 'S': /* --match-subsystems */ @@ -496,7 +521,7 @@ static void process_args (json_t *options, break; case 'g': /* --graph-format */ rc = string_to_graph_format (optarg, format); - if ( rc != 0) { + if (rc != 0) { std::cerr << "[ERROR] unknown format for --graph-format: "; std::cerr << optarg << std::endl; usage (1); @@ -510,15 +535,18 @@ static void process_args (json_t *options, case 'p': /* --prune-filters */ token = optarg; if (token.find_first_not_of (' ') != std::string::npos) { - if (!json_object_get (options,"prune_filters")) { - json_object_set_new (options, "prune_filters", json_string (token.c_str ())); + if (!json_object_get (options, "prune_filters")) { + json_object_set_new (options, + "prune_filters", + json_string (token.c_str ())); } else { - json_object_set_new (options, "prune_filters", - json_pack ("s++", - json_object_get (options,"prune_filters"), - ",", token.c_str ())); + json_object_set_new (options, + "prune_filters", + json_pack ("s++", + json_object_get (options, "prune_filters"), + ",", + token.c_str ())); } - } break; case 't': /* --test-output */ @@ -527,11 +555,9 @@ static void process_args (json_t *options, case 'r': /* --reserve-vtx-vec */ // If atoi fails, it defaults to 0, which is fine for us json_object_set_new (options, "match_format", json_integer (atoi (optarg))); - if ( (atoi (optarg) < 0) - || (atoi (optarg) > 2000000)) { + if ((atoi (optarg) < 0) || (atoi (optarg) > 2000000)) { json_object_set_new (options, "match_format", json_integer (0)); - std::cerr - << "WARN: out of range specified for --reserve-vtx-vec: "; + std::cerr << "WARN: out of range specified for --reserve-vtx-vec: "; std::cerr << optarg << std::endl; } break; @@ -551,25 +577,24 @@ static void process_args (json_t *options, usage (1); } -void get_rgraph (std::string &rgraph, json_t* options) +void get_rgraph (std::string &rgraph, json_t *options) { const char *load_file = json_string_value (json_object_get (options, "load_file")); if (load_file == NULL) { - load_file = "conf/default"; + load_file = "conf/default"; } std::ifstream ifs (load_file); - rgraph = std::string( (std::istreambuf_iterator (ifs) ), - (std::istreambuf_iterator () ) ); - ifs.close(); + rgraph = + std::string ((std::istreambuf_iterator (ifs)), (std::istreambuf_iterator ())); + ifs.close (); } -static void control_loop (resource_query_t &ctx, json_t *params, - std::ostream &out) +static void control_loop (resource_query_t &ctx, json_t *params, std::ostream &out) { cmd_func_f *cmd = NULL; while (1) { - char *line = json_object_get (params, "disable_prompt")? readline ("") - : readline ("resource-query> "); + char *line = json_object_get (params, "disable_prompt") ? readline ("") + : readline ("resource-query> "); if (line == NULL) continue; else if (*line) @@ -579,8 +604,8 @@ static void control_loop (resource_query_t &ctx, json_t *params, std::istringstream iss (line); std::copy (std::istream_iterator (iss), std::istream_iterator (), - back_inserter (tokens)); - free(line); + back_inserter (tokens)); + free (line); if (tokens.empty ()) continue; @@ -612,20 +637,17 @@ int main (int argc, char *argv[]) return EXIT_FAILURE; } catch (std::runtime_error &e) { errno = EPROTO; - std::cerr << ": Runtime error: " - + std::string (e.what ()) + "\n"; + std::cerr << ": Runtime error: " + std::string (e.what ()) + "\n"; return EXIT_FAILURE; } std::ofstream out_file; - if (r_fname_set (json_options)) - { + if (r_fname_set (json_options)) { out_file = open_fs (json_options); } - std::ostream &out = (r_fname_set (json_options))? out_file - : std::cout; + std::ostream &out = (r_fname_set (json_options)) ? out_file : std::cout; control_loop (*ctx, json_options, out); diff --git a/resource/utilities/rq2.hpp b/resource/utilities/rq2.hpp index f22326121..0ca796b79 100644 --- a/resource/utilities/rq2.hpp +++ b/resource/utilities/rq2.hpp @@ -19,10 +19,9 @@ using namespace Flux; using namespace Flux::resource_model; using namespace Flux::resource_model::detail; -int match (resource_query_t &ctx, std::vector &args, json_t *params, +int match (resource_query_t &ctx, + std::vector &args, + json_t *params, std::ostream &out); -int help (resource_query_t &ctx, std::vector &args, json_t *params, - std::ostream &out); -int quit (resource_query_t &ctx, std::vector &args, json_t *params, - std::ostream &out); - +int help (resource_query_t &ctx, std::vector &args, json_t *params, std::ostream &out); +int quit (resource_query_t &ctx, std::vector &args, json_t *params, std::ostream &out); diff --git a/resource/writers/match_writers.cpp b/resource/writers/match_writers.cpp index 24315b09d..9c82b0bf4 100644 --- a/resource/writers/match_writers.cpp +++ b/resource/writers/match_writers.cpp @@ -27,14 +27,11 @@ extern "C" { namespace Flux { namespace resource_model { - - //////////////////////////////////////////////////////////////////////////////// // Base Writers Class Public Method Definitions //////////////////////////////////////////////////////////////////////////////// -int match_writers_t::compress_ids (std::stringstream &o, - const std::vector &ids) +int match_writers_t::compress_ids (std::stringstream &o, const std::vector &ids) { int rc = 0; try { @@ -76,22 +73,22 @@ int match_writers_t::compress_hosts (const std::vector &hosts, goto ret; } if (hostlist_init) { - if ( !(hl = hostlist_decode (hostlist_init))) { + if (!(hl = hostlist_decode (hostlist_init))) { rc = -1; goto ret; } } else { - if ( !(hl = hostlist_create ())) { + if (!(hl = hostlist_create ())) { rc = -1; goto ret; } } for (auto &hn : hosts) { - if ( (rc = hostlist_append (hl, hn.c_str ())) < 0) + if ((rc = hostlist_append (hl, hn.c_str ())) < 0) goto ret; } - if ( !(*hostlist_out = hostlist_encode (hl))) { + if (!(*hostlist_out = hostlist_encode (hl))) { rc = -1; goto ret; } @@ -101,8 +98,6 @@ int match_writers_t::compress_hosts (const std::vector &hosts, return rc; } - - //////////////////////////////////////////////////////////////////////////////// // Simple Writers Class Public Method Definitions //////////////////////////////////////////////////////////////////////////////// @@ -119,7 +114,7 @@ int sim_match_writers_t::emit_json (json_t **j_o, json_t **aux) std::string str = m_out.str (); if (!str.empty ()) { - if ( !(o = json_string (str.c_str ()))) { + if (!(o = json_string (str.c_str ()))) { errno = ENOMEM; rc = -1; goto done; @@ -142,17 +137,16 @@ int sim_match_writers_t::emit (std::stringstream &out) } int sim_match_writers_t::emit_vtx (const std::string &prefix, - const resource_graph_t &g, const vtx_t &u, - unsigned int needs, bool exclusive) + const resource_graph_t &g, + const vtx_t &u, + unsigned int needs, + bool exclusive) { - std::string mode = (exclusive)? "x" : "s"; - m_out << prefix << g[u].name << "[" << needs << ":" << mode << "]" - << std::endl; + std::string mode = (exclusive) ? "x" : "s"; + m_out << prefix << g[u].name << "[" << needs << ":" << mode << "]" << std::endl; return 0; } - - //////////////////////////////////////////////////////////////////////////////// // JSON Graph Format (JGF) Writers Class Public Definitions //////////////////////////////////////////////////////////////////////////////// @@ -179,8 +173,7 @@ jgf_match_writers_t::jgf_match_writers_t (const jgf_match_writers_t &w) } } -jgf_match_writers_t &jgf_match_writers_t::operator=( - const jgf_match_writers_t &w) +jgf_match_writers_t &jgf_match_writers_t::operator= (const jgf_match_writers_t &w) { if (!(m_vout = json_deep_copy (w.m_vout))) throw std::bad_alloc (); @@ -211,10 +204,7 @@ int jgf_match_writers_t::emit_json (json_t **o, json_t **aux) if ((rc = check_array_sizes ()) <= 0) goto ret; - if (!(*o = json_pack ("{s:{s:o s:o}}", - "graph", - "nodes", m_vout, - "edges", m_eout))) { + if (!(*o = json_pack ("{s:{s:o s:o}}", "graph", "nodes", m_vout, "edges", m_eout))) { json_decref (m_vout); json_decref (m_eout); m_vout = NULL; @@ -254,12 +244,14 @@ int jgf_match_writers_t::emit (std::stringstream &out) json_decref (o); } ret: - return (rc == -1)? -1 : 0; + return (rc == -1) ? -1 : 0; } int jgf_match_writers_t::emit_vtx (const std::string &prefix, - const resource_graph_t &g, const vtx_t &u, - unsigned int needs, bool exclusive) + const resource_graph_t &g, + const vtx_t &u, + unsigned int needs, + bool exclusive) { int rc = 0; json_t *o = NULL; @@ -288,9 +280,8 @@ int jgf_match_writers_t::emit_vtx (const std::string &prefix, json_decref (b); goto out; } - if ((o = json_pack ("{s:s s:o}", - "id", std::to_string (g[u].uniq_id).c_str (), - "metadata", b)) == NULL) { + if ((o = json_pack ("{s:s s:o}", "id", std::to_string (g[u].uniq_id).c_str (), "metadata", b)) + == NULL) { json_decref (b); rc = -1; errno = ENOMEM; @@ -306,7 +297,8 @@ int jgf_match_writers_t::emit_vtx (const std::string &prefix, } int jgf_match_writers_t::emit_edg (const std::string &prefix, - const resource_graph_t &g, const edg_t &e) + const resource_graph_t &g, + const edg_t &e) { int rc = 0; json_t *o = NULL; @@ -327,9 +319,12 @@ int jgf_match_writers_t::emit_edg (const std::string &prefix, goto out; } if (!(o = json_pack ("{s:s s:s s:o}", - "source", std::to_string (g[source (e, g)].uniq_id).c_str (), - "target", std::to_string (g[target (e, g)].uniq_id).c_str (), - "metadata", m))) { + "source", + std::to_string (g[source (e, g)].uniq_id).c_str (), + "target", + std::to_string (g[target (e, g)].uniq_id).c_str (), + "metadata", + m))) { json_decref (m); rc = -1; errno = ENOMEM; @@ -344,8 +339,6 @@ int jgf_match_writers_t::emit_edg (const std::string &prefix, return rc; } - - //////////////////////////////////////////////////////////////////////////////// // JSON Graph Format (JGF) Writers Class Private Definitions //////////////////////////////////////////////////////////////////////////////// @@ -398,19 +391,20 @@ int jgf_match_writers_t::check_array_sizes () json_t *jgf_match_writers_t::emit_vtx_base (const resource_graph_t &g, const vtx_t &u, - unsigned int needs, bool exclusive) + unsigned int needs, + bool exclusive) { json_t *o = NULL; json_t *prop = nullptr; if (!g[u].properties.empty ()) { - if ( !(prop = json_object ())) { + if (!(prop = json_object ())) { errno = ENOMEM; return nullptr; } for (auto &kv : g[u].properties) { json_t *value = nullptr; - if ( !(value = json_string (kv.second.c_str ()))) { + if (!(value = json_string (kv.second.c_str ()))) { json_decref (prop); errno = EINVAL; return nullptr; @@ -425,29 +419,48 @@ json_t *jgf_match_writers_t::emit_vtx_base (const resource_graph_t &g, if (prop) { if (!(o = json_pack ("{s:s s:s s:s s:I s:I s:i s:o s:b s:s s:I}", - "type", g[u].type.c_str (), - "basename", g[u].basename.c_str (), - "name", g[u].name.c_str (), - "id", g[u].id, - "uniq_id", g[u].uniq_id, - "rank", g[u].rank, - "properties", prop, - "exclusive", (exclusive)? 1 : 0, - "unit", g[u].unit.c_str (), - "size", static_cast (needs)))) { + "type", + g[u].type.c_str (), + "basename", + g[u].basename.c_str (), + "name", + g[u].name.c_str (), + "id", + g[u].id, + "uniq_id", + g[u].uniq_id, + "rank", + g[u].rank, + "properties", + prop, + "exclusive", + (exclusive) ? 1 : 0, + "unit", + g[u].unit.c_str (), + "size", + static_cast (needs)))) { errno = EINVAL; } } else { if (!(o = json_pack ("{s:s s:s s:s s:I s:I s:i s:b s:s s:I}", - "type", g[u].type.c_str (), - "basename", g[u].basename.c_str (), - "name", g[u].name.c_str (), - "id", g[u].id, - "uniq_id", g[u].uniq_id, - "rank", g[u].rank, - "exclusive", (exclusive)? 1 : 0, - "unit", g[u].unit.c_str (), - "size", static_cast (needs)))) { + "type", + g[u].type.c_str (), + "basename", + g[u].basename.c_str (), + "name", + g[u].name.c_str (), + "id", + g[u].id, + "uniq_id", + g[u].uniq_id, + "rank", + g[u].rank, + "exclusive", + (exclusive) ? 1 : 0, + "unit", + g[u].unit.c_str (), + "size", + static_cast (needs)))) { errno = EINVAL; } } @@ -479,7 +492,7 @@ int jgf_match_writers_t::map2json (json_t *o, errno = ENOMEM; goto out; } - } + } if ((rc = json_object_set_new (o, key, p)) == -1) { errno = ENOMEM; goto out; @@ -490,8 +503,7 @@ int jgf_match_writers_t::map2json (json_t *o, return rc; } -int jgf_match_writers_t::emit_edg_meta (json_t *o, const resource_graph_t &g, - const edg_t &e) +int jgf_match_writers_t::emit_edg_meta (json_t *o, const resource_graph_t &g, const edg_t &e) { int rc = 0; if (!o) { @@ -530,8 +542,6 @@ int jgf_match_writers_t::emit_edg_meta (json_t *o, const resource_graph_t &g, return rc; } - - //////////////////////////////////////////////////////////////////////////////// // RLITE Writers Class Public Method Definitions //////////////////////////////////////////////////////////////////////////////// @@ -550,8 +560,7 @@ rlite_match_writers_t::rlite_match_writers_t (const rlite_match_writers_t &w) m_gl_gatherer = w.m_gl_gatherer; } -rlite_match_writers_t &rlite_match_writers_t::operator=( - const rlite_match_writers_t &w) +rlite_match_writers_t &rlite_match_writers_t::operator= (const rlite_match_writers_t &w) { m_reducer = w.m_reducer; m_gatherer = w.m_gatherer; @@ -581,12 +590,12 @@ int rlite_match_writers_t::emit_json (json_t **o, json_t **aux) rc = -1; goto ret; } - if ( !(rlite_array = json_array ())) { + if (!(rlite_array = json_array ())) { rc = -1; errno = ENOMEM; goto ret; } - if ( aux && !(host_array = json_array ())) { + if (aux && !(host_array = json_array ())) { json_decref (rlite_array); rc = -1; errno = ENOMEM; @@ -599,7 +608,7 @@ int rlite_match_writers_t::emit_json (json_t **o, json_t **aux) errno = ENOMEM; goto ret; } - if ( (rc = fill (rlite_array, host_array, props)) < 0) { + if ((rc = fill (rlite_array, host_array, props)) < 0) { saved_errno = errno; json_decref (rlite_array); if (host_array) @@ -614,15 +623,14 @@ int rlite_match_writers_t::emit_json (json_t **o, json_t **aux) m_gl_prop_gatherer.clear (); - if ( (rc = json_array_size (rlite_array)) != 0) { + if ((rc = json_array_size (rlite_array)) != 0) { *o = rlite_array; if (aux) { - if ( !(*aux = json_pack ("{ s:o }", - "nodelist", host_array))) { - rc = -1; - errno = EINVAL; - goto ret; - } + if (!(*aux = json_pack ("{ s:o }", "nodelist", host_array))) { + rc = -1; + errno = EINVAL; + goto ret; + } if (props) { if (json_object_set_new (*aux, "properties", props)) { rc = -1; @@ -653,9 +661,9 @@ int rlite_match_writers_t::emit (std::stringstream &out, bool newline) out << std::endl; free (json_str); json_decref (o); - } + } ret: - return (rc == -1)? -1 : 0; + return (rc == -1) ? -1 : 0; } int rlite_match_writers_t::emit (std::stringstream &out) @@ -687,8 +695,6 @@ int rlite_match_writers_t::emit_vtx (const std::string &prefix, return rc; } - - //////////////////////////////////////////////////////////////////////////////// // RLITE Writers Class Private Method Definitions //////////////////////////////////////////////////////////////////////////////// @@ -724,14 +730,14 @@ int rlite_match_writers_t::get_gatherer_children (std::string &children) continue; std::sort (kv.second.begin (), kv.second.end ()); - if ( (rc = compress_ids (s, kv.second)) < 0) + if ((rc = compress_ids (s, kv.second)) < 0) goto memfree_ret; - if ( !(vo = json_string (s.str ().c_str ()))) { + if (!(vo = json_string (s.str ().c_str ()))) { rc = -1; errno = ENOMEM; goto memfree_ret; } - if ( (rc = json_object_set_new (co, kv.first.c_str (), vo)) < 0) { + if ((rc = json_object_set_new (co, kv.first.c_str (), vo)) < 0) { errno = ENOMEM; goto memfree_ret; } @@ -754,8 +760,7 @@ int rlite_match_writers_t::get_gatherer_children (std::string &children) return rc; } -int rlite_match_writers_t::emit_gatherer (const resource_graph_t &g, - const vtx_t &u) +int rlite_match_writers_t::emit_gatherer (const resource_graph_t &g, const vtx_t &u) { int rc = 0; std::string children; @@ -764,7 +769,7 @@ int rlite_match_writers_t::emit_gatherer (const resource_graph_t &g, if (!m_reducer_set ()) goto ret; - if ( (rc = get_gatherer_children (children)) < 0) + if ((rc = get_gatherer_children (children)) < 0) goto ret; if (m_gl_gatherer.find (children) == m_gl_gatherer.end ()) @@ -777,12 +782,9 @@ int rlite_match_writers_t::emit_gatherer (const resource_graph_t &g, std::string prop = kv.first; if (kv.second != "") prop = prop + "=" + kv.second; - if (m_gl_prop_gatherer.find (prop) - == m_gl_prop_gatherer.end ()) { + if (m_gl_prop_gatherer.find (prop) == m_gl_prop_gatherer.end ()) { auto ret = m_gl_prop_gatherer.insert ( - std::pair> ( - prop, std::vector ())); + std::pair> (prop, std::vector ())); if (!ret.second) { errno = ENOMEM; rc = -1; @@ -800,15 +802,13 @@ int rlite_match_writers_t::emit_gatherer (const resource_graph_t &g, return rc; } -int rlite_match_writers_t::fill (json_t *rlite_array, - json_t *host_array, json_t *props) +int rlite_match_writers_t::fill (json_t *rlite_array, json_t *host_array, json_t *props) { int rc = 0; int saved_errno; char *hl_out = nullptr; std::vector rankhosts_vec; - // m_gl_gatherer is keyed by the "children" signature of each node // the value is the set of ranks that have the same signature. for (auto &kv : m_gl_gatherer) { @@ -818,48 +818,45 @@ int rlite_match_writers_t::fill (json_t *rlite_array, json_t *robj, *ranks, *cobj = NULL; // The primary sorting order for compression is rank - std::sort (kv.second.begin (), kv.second.end (), - [] (const rank_host_t &a, const rank_host_t &b) { - return a.rank < b.rank; - }); - std::transform (kv.second.begin (), kv.second.end (), + std::sort (kv.second.begin (), + kv.second.end (), + [] (const rank_host_t &a, const rank_host_t &b) { return a.rank < b.rank; }); + std::transform (kv.second.begin (), + kv.second.end (), std::back_inserter (ranks_vec), - [] (rank_host_t &o) { - return o.rank; - }); - if ( (rc = compress_ids (s, ranks_vec)) < 0) + [] (rank_host_t &o) { return o.rank; }); + if ((rc = compress_ids (s, ranks_vec)) < 0) goto ret; if (host_array) - std::copy (kv.second.begin (), - kv.second.end (), std::back_inserter (rankhosts_vec)); - if ( !(robj = json_object ())) { + std::copy (kv.second.begin (), kv.second.end (), std::back_inserter (rankhosts_vec)); + if (!(robj = json_object ())) { rc = -1; errno = ENOMEM; goto ret; } - if ( !(ranks = json_string (s.str ().c_str ()))) { + if (!(ranks = json_string (s.str ().c_str ()))) { json_decref (robj); rc = -1; errno = EINVAL; goto ret; } - if ( (rc = json_object_set_new (robj, "rank", ranks)) < 0) { + if ((rc = json_object_set_new (robj, "rank", ranks)) < 0) { json_decref (robj); errno = EINVAL; goto ret; } - if ( !(cobj = json_loads (kv.first.c_str (), 0, &err))) { + if (!(cobj = json_loads (kv.first.c_str (), 0, &err))) { json_decref (robj); rc = -1; errno = ENOMEM; goto ret; } - if ( (rc = json_object_set_new (robj, "children", cobj)) < 0) { + if ((rc = json_object_set_new (robj, "children", cobj)) < 0) { json_decref (robj); errno = EINVAL; goto ret; } - if ( (rc = json_array_append_new (rlite_array, robj)) < 0) { + if ((rc = json_array_append_new (rlite_array, robj)) < 0) { json_decref (robj); errno = EINVAL; goto ret; @@ -873,9 +870,9 @@ int rlite_match_writers_t::fill (json_t *rlite_array, // kv.second is a std::vector with ranks std::sort (kv.second.begin (), kv.second.end ()); - if ( (rc = compress_ids (s, kv.second)) < 0) + if ((rc = compress_ids (s, kv.second)) < 0) goto ret; - if ( !(ranks = json_string (s.str ().c_str ()))) { + if (!(ranks = json_string (s.str ().c_str ()))) { rc = -1; errno = EINVAL; goto ret; @@ -891,21 +888,18 @@ int rlite_match_writers_t::fill (json_t *rlite_array, if (host_array) { // The primary sorting order for compression is rank - std::sort (rankhosts_vec.begin (), rankhosts_vec.end (), - [] (const rank_host_t &a, const rank_host_t &b) { - return a.rank < b.rank; - }); + std::sort (rankhosts_vec.begin (), + rankhosts_vec.end (), + [] (const rank_host_t &a, const rank_host_t &b) { return a.rank < b.rank; }); std::vector hosts_vec; - std::transform (rankhosts_vec.begin (), rankhosts_vec.end (), + std::transform (rankhosts_vec.begin (), + rankhosts_vec.end (), std::back_inserter (hosts_vec), - [] (rank_host_t &o) { - return o.host; - }); - if ( (rc = compress_hosts (hosts_vec, nullptr, &hl_out)) < 0) + [] (rank_host_t &o) { return o.host; }); + if ((rc = compress_hosts (hosts_vec, nullptr, &hl_out)) < 0) goto ret; if (hl_out) { - if ( (rc = json_array_append_new (host_array, - json_string (hl_out))) < 0) { + if ((rc = json_array_append_new (host_array, json_string (hl_out))) < 0) { json_decref (rlite_array); errno = EINVAL; goto ret; @@ -920,8 +914,6 @@ int rlite_match_writers_t::fill (json_t *rlite_array, return rc; } - - //////////////////////////////////////////////////////////////////////////////// // RV1 Writers Class Method Definitions //////////////////////////////////////////////////////////////////////////////// @@ -931,7 +923,8 @@ bool rv1_match_writers_t::empty () return (rlite.empty () && jgf.empty ()); } -int rv1_match_writers_t::attrs_json (json_t **o) { +int rv1_match_writers_t::attrs_json (json_t **o) +{ int rc = 0; json_t *sys = NULL; json_t *attrs = json_object (); @@ -950,9 +943,7 @@ int rv1_match_writers_t::attrs_json (json_t **o) { goto ret; } } - if (!(sys = json_pack ("{s:{s:o}}", - "system", - "scheduler", attrs))) { + if (!(sys = json_pack ("{s:{s:o}}", "system", "scheduler", attrs))) { json_decref (attrs); rc = -1; errno = ENOMEM; @@ -976,28 +967,31 @@ int rv1_match_writers_t::emit_json (json_t **j_o, json_t **aux) if (rlite.empty () || jgf.empty ()) goto ret; - if ( (rc = rlite.emit_json (&rlite_o, &rlite_aux_o)) < 0) + if ((rc = rlite.emit_json (&rlite_o, &rlite_aux_o)) < 0) goto ret; - if ( (rc = jgf.emit_json (&jgf_o)) < 0) { + if ((rc = jgf.emit_json (&jgf_o)) < 0) { saved_errno = errno; json_decref (rlite_aux_o); errno = saved_errno; goto ret; } if (json_object_get (rlite_aux_o, "properties")) { - if ( !(o = json_pack ("{s:i s:{s:o s:O s:O s:I s:I} s:o}", - "version", 1, - "execution", - "R_lite", rlite_o, - "nodelist", json_object_get ( - rlite_aux_o, - "nodelist"), - "properties", json_object_get ( - rlite_aux_o, - "properties"), - "starttime", m_starttime, - "expiration", m_expiration, - "scheduling", jgf_o))) { + if (!(o = json_pack ("{s:i s:{s:o s:O s:O s:I s:I} s:o}", + "version", + 1, + "execution", + "R_lite", + rlite_o, + "nodelist", + json_object_get (rlite_aux_o, "nodelist"), + "properties", + json_object_get (rlite_aux_o, "properties"), + "starttime", + m_starttime, + "expiration", + m_expiration, + "scheduling", + jgf_o))) { json_decref (rlite_o); json_decref (jgf_o); json_decref (rlite_aux_o); @@ -1006,16 +1000,20 @@ int rv1_match_writers_t::emit_json (json_t **j_o, json_t **aux) goto ret; } } else { - if ( !(o = json_pack ("{s:i s:{s:o s:O s:I s:I} s:o}", - "version", 1, - "execution", - "R_lite", rlite_o, - "nodelist", json_object_get ( - rlite_aux_o, - "nodelist"), - "starttime", m_starttime, - "expiration", m_expiration, - "scheduling", jgf_o))) { + if (!(o = json_pack ("{s:i s:{s:o s:O s:I s:I} s:o}", + "version", + 1, + "execution", + "R_lite", + rlite_o, + "nodelist", + json_object_get (rlite_aux_o, "nodelist"), + "starttime", + m_starttime, + "expiration", + m_expiration, + "scheduling", + jgf_o))) { json_decref (rlite_o); json_decref (jgf_o); json_decref (rlite_aux_o); @@ -1034,7 +1032,7 @@ int rv1_match_writers_t::emit_json (json_t **j_o, json_t **aux) errno = saved_errno; goto ret; } - if ( (rc = json_object_set_new (o, "attributes", attrs_o)) == -1) { + if ((rc = json_object_set_new (o, "attributes", attrs_o)) == -1) { json_decref (o); errno = EINVAL; goto ret; @@ -1054,9 +1052,9 @@ int rv1_match_writers_t::emit (std::stringstream &out) if (rlite.empty () || jgf.empty ()) goto ret; - if ( (rc = emit_json (&o)) < 0) + if ((rc = emit_json (&o)) < 0) goto ret; - if ( !(json_str = json_dumps (o, JSON_INDENT (0)))) { + if (!(json_str = json_dumps (o, JSON_INDENT (0)))) { json_decref (o); o = NULL; rc = -1; @@ -1106,8 +1104,6 @@ int rv1_match_writers_t::emit_attrs (const std::string &k, const std::string &v) return 0; } - - //////////////////////////////////////////////////////////////////////////////// // RV1 Nosched Writers Class Method Definitions //////////////////////////////////////////////////////////////////////////////// @@ -1125,21 +1121,23 @@ int rv1_nosched_match_writers_t::emit_json (json_t **j_o, json_t **aux) if (rlite.empty ()) goto ret; - if ( (rc = rlite.emit_json (&rlite_o, &rlite_aux_o)) < 0) + if ((rc = rlite.emit_json (&rlite_o, &rlite_aux_o)) < 0) goto ret; if (json_object_get (rlite_aux_o, "properties")) { - if ( !(*j_o = json_pack ("{s:i s:{s:o s:O s:O s:I s:I}}", - "version", 1, - "execution", - "R_lite", rlite_o, - "nodelist", json_object_get ( - rlite_aux_o, - "nodelist"), - "properties", json_object_get ( - rlite_aux_o, - "properties"), - "starttime", m_starttime, - "expiration", m_expiration))) { + if (!(*j_o = json_pack ("{s:i s:{s:o s:O s:O s:I s:I}}", + "version", + 1, + "execution", + "R_lite", + rlite_o, + "nodelist", + json_object_get (rlite_aux_o, "nodelist"), + "properties", + json_object_get (rlite_aux_o, "properties"), + "starttime", + m_starttime, + "expiration", + m_expiration))) { json_decref (rlite_o); json_decref (rlite_aux_o); rc = -1; @@ -1147,15 +1145,18 @@ int rv1_nosched_match_writers_t::emit_json (json_t **j_o, json_t **aux) goto ret; } } else { - if ( !(*j_o = json_pack ("{s:i s:{s:o s:O s:I s:I}}", - "version", 1, - "execution", - "R_lite", rlite_o, - "nodelist", json_object_get ( - rlite_aux_o, - "nodelist"), - "starttime", m_starttime, - "expiration", m_expiration))) { + if (!(*j_o = json_pack ("{s:i s:{s:o s:O s:I s:I}}", + "version", + 1, + "execution", + "R_lite", + rlite_o, + "nodelist", + json_object_get (rlite_aux_o, "nodelist"), + "starttime", + m_starttime, + "expiration", + m_expiration))) { json_decref (rlite_o); json_decref (rlite_aux_o); rc = -1; @@ -1178,9 +1179,9 @@ int rv1_nosched_match_writers_t::emit (std::stringstream &out) if (rlite.empty ()) goto ret; - if ( (rc = emit_json (&o)) < 0) + if ((rc = emit_json (&o)) < 0) goto ret; - if ( !(json_str = json_dumps (o, JSON_INDENT (0)))) { + if (!(json_str = json_dumps (o, JSON_INDENT (0)))) { json_decref (o); o = NULL; rc = -1; @@ -1211,8 +1212,6 @@ int rv1_nosched_match_writers_t::emit_tm (uint64_t start_tm, uint64_t end_tm) return 0; } - - //////////////////////////////////////////////////////////////////////////////// // PRETTY Simple Writers Class Public Method Definitions //////////////////////////////////////////////////////////////////////////////// @@ -1220,7 +1219,7 @@ int rv1_nosched_match_writers_t::emit_tm (uint64_t start_tm, uint64_t end_tm) bool pretty_sim_match_writers_t::empty () { bool empty = true; - for (auto &s: m_out) { + for (auto &s : m_out) { if (!s.empty ()) { empty = false; break; @@ -1234,11 +1233,11 @@ int pretty_sim_match_writers_t::emit_json (json_t **j_o, json_t **aux) json_t *o = NULL; std::string str = ""; - for (auto &s: m_out) + for (auto &s : m_out) str += s; m_out.clear (); if (!str.empty ()) { - if ( !(o = json_string (str.c_str ()))) { + if (!(o = json_string (str.c_str ()))) { errno = ENOMEM; return -1; } @@ -1249,7 +1248,7 @@ int pretty_sim_match_writers_t::emit_json (json_t **j_o, json_t **aux) int pretty_sim_match_writers_t::emit (std::stringstream &out) { - for (auto &s: m_out) + for (auto &s : m_out) out << s; m_out.clear (); return 0; @@ -1258,48 +1257,45 @@ int pretty_sim_match_writers_t::emit (std::stringstream &out) int pretty_sim_match_writers_t::emit_vtx (const std::string &prefix, const resource_graph_t &g, const vtx_t &u, - unsigned int needs, bool exclusive) + unsigned int needs, + bool exclusive) { std::stringstream out; - std::string mode = (exclusive)? "exclusive" : "shared"; - out << prefix << g[u].name << "[" << needs << ":" << mode << "]" - << std::endl; + std::string mode = (exclusive) ? "exclusive" : "shared"; + out << prefix << g[u].name << "[" << needs << ":" << mode << "]" << std::endl; m_out.push_front (out.str ()); return 0; } - - //////////////////////////////////////////////////////////////////////////////// // Match Writers Factory Class Method Definitions //////////////////////////////////////////////////////////////////////////////// -std::shared_ptr match_writers_factory_t:: - create (match_format_t f) +std::shared_ptr match_writers_factory_t::create (match_format_t f) { std::shared_ptr w = nullptr; try { switch (f) { - case match_format_t::SIMPLE: - w = std::make_shared (); - break; - case match_format_t::JGF: - w = std::make_shared (); - break; - case match_format_t::RLITE: - w = std::make_shared (); - break; - case match_format_t::RV1_NOSCHED: - w = std::make_shared (); - break; - case match_format_t::PRETTY_SIMPLE: - w = std::make_shared (); - break; - case match_format_t::RV1: - default: - w = std::make_shared (); - break; + case match_format_t::SIMPLE: + w = std::make_shared (); + break; + case match_format_t::JGF: + w = std::make_shared (); + break; + case match_format_t::RLITE: + w = std::make_shared (); + break; + case match_format_t::RV1_NOSCHED: + w = std::make_shared (); + break; + case match_format_t::PRETTY_SIMPLE: + w = std::make_shared (); + break; + case match_format_t::RV1: + default: + w = std::make_shared (); + break; } } catch (std::bad_alloc &e) { errno = ENOMEM; @@ -1327,16 +1323,12 @@ match_format_t match_writers_factory_t::get_writers_type (const std::string &n) bool known_match_format (const std::string &format) { - return (format == "simple" - || format == "jgf" - || format == "rlite" - || format == "rv1" - || format == "rv1_nosched" - || format == "pretty_simple"); + return (format == "simple" || format == "jgf" || format == "rlite" || format == "rv1" + || format == "rv1_nosched" || format == "pretty_simple"); } -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/resource/writers/match_writers.hpp b/resource/writers/match_writers.hpp index 85415000b..ecd84da23 100644 --- a/resource/writers/match_writers.hpp +++ b/resource/writers/match_writers.hpp @@ -23,85 +23,96 @@ extern "C" { namespace Flux { namespace resource_model { -enum class match_format_t { SIMPLE, - JGF, - RLITE, - RV1, - RV1_NOSCHED, - PRETTY_SIMPLE }; - +enum class match_format_t { SIMPLE, JGF, RLITE, RV1, RV1_NOSCHED, PRETTY_SIMPLE }; /*! Base match writers class for a matched resource set */ class match_writers_t { -public: - virtual ~match_writers_t () {} + public: + virtual ~match_writers_t () + { + } virtual bool empty () = 0; virtual int emit_json (json_t **o, json_t **aux = nullptr) = 0; virtual int emit (std::stringstream &out) = 0; virtual int emit_vtx (const std::string &prefix, - const resource_graph_t &g, const vtx_t &u, - unsigned int needs, bool exclusive) = 0; - virtual int emit_edg (const std::string &prefix, - const resource_graph_t &g, const edg_t &e) { + const resource_graph_t &g, + const vtx_t &u, + unsigned int needs, + bool exclusive) = 0; + virtual int emit_edg (const std::string &prefix, const resource_graph_t &g, const edg_t &e) + { return 0; } - virtual int emit_tm (uint64_t starttime, uint64_t expiration) { + virtual int emit_tm (uint64_t starttime, uint64_t expiration) + { return 0; } - virtual int emit_attrs (const std::string &k, const std::string &v) { + virtual int emit_attrs (const std::string &k, const std::string &v) + { return 0; } int compress_ids (std::stringstream &o, const std::vector &ids); int compress_hosts (const std::vector &hosts, - const char *hostlist_init, char **hostlist); + const char *hostlist_init, + char **hostlist); }; - /*! Simple match writers class for a matched resource set */ -class sim_match_writers_t : public match_writers_t -{ -public: - virtual ~sim_match_writers_t () {} +class sim_match_writers_t : public match_writers_t { + public: + virtual ~sim_match_writers_t () + { + } virtual bool empty (); virtual int emit_json (json_t **o, json_t **aux = nullptr); virtual int emit (std::stringstream &out); virtual int emit_vtx (const std::string &prefix, - const resource_graph_t &g, const vtx_t &u, - unsigned int needs, bool exclusive); -private: + const resource_graph_t &g, + const vtx_t &u, + unsigned int needs, + bool exclusive); + + private: std::stringstream m_out; }; - /*! JGF match writers class for a matched resource set */ -class jgf_match_writers_t : public match_writers_t -{ -public: +class jgf_match_writers_t : public match_writers_t { + public: jgf_match_writers_t (); jgf_match_writers_t (const jgf_match_writers_t &w); - jgf_match_writers_t &operator=(const jgf_match_writers_t &w); + jgf_match_writers_t &operator= (const jgf_match_writers_t &w); virtual ~jgf_match_writers_t (); virtual bool empty (); virtual int emit_json (json_t **o, json_t **aux = nullptr); virtual int emit (std::stringstream &out); virtual int emit_vtx (const std::string &prefix, - const resource_graph_t &g, const vtx_t &u, - unsigned int needs, bool exclusive); - virtual int emit_edg (const std::string &prefix, - const resource_graph_t &g, const edg_t &e); -private: - json_t *emit_vtx_base (const resource_graph_t &g, const vtx_t &u, - unsigned int needs, bool exclusive); - int emit_vtx_prop (json_t *o, const resource_graph_t &g, - const vtx_t &u, unsigned int needs, bool exclusive); - int emit_vtx_path (json_t *o, const resource_graph_t &g, - const vtx_t &u, unsigned int needs, bool exclusive); - int map2json (json_t *o, const std::map &mp, - const char *key); + const resource_graph_t &g, + const vtx_t &u, + unsigned int needs, + bool exclusive); + virtual int emit_edg (const std::string &prefix, const resource_graph_t &g, const edg_t &e); + + private: + json_t *emit_vtx_base (const resource_graph_t &g, + const vtx_t &u, + unsigned int needs, + bool exclusive); + int emit_vtx_prop (json_t *o, + const resource_graph_t &g, + const vtx_t &u, + unsigned int needs, + bool exclusive); + int emit_vtx_path (json_t *o, + const resource_graph_t &g, + const vtx_t &u, + unsigned int needs, + bool exclusive); + int map2json (json_t *o, const std::map &mp, const char *key); int emit_edg_meta (json_t *o, const resource_graph_t &g, const edg_t &e); int alloc_json_arrays (); int check_array_sizes (); @@ -110,15 +121,13 @@ class jgf_match_writers_t : public match_writers_t json_t *m_eout = NULL; }; - /*! RLITE match writers class for a matched resource set */ -class rlite_match_writers_t : public match_writers_t -{ -public: +class rlite_match_writers_t : public match_writers_t { + public: rlite_match_writers_t (); rlite_match_writers_t (const rlite_match_writers_t &w); - rlite_match_writers_t &operator=(const rlite_match_writers_t &w); + rlite_match_writers_t &operator= (const rlite_match_writers_t &w); virtual ~rlite_match_writers_t (); virtual bool empty (); @@ -126,11 +135,14 @@ class rlite_match_writers_t : public match_writers_t virtual int emit (std::stringstream &out, bool newline); virtual int emit (std::stringstream &out); virtual int emit_vtx (const std::string &prefix, - const resource_graph_t &g, const vtx_t &u, - unsigned int needs, bool exclusive); -private: + const resource_graph_t &g, + const vtx_t &u, + unsigned int needs, + bool exclusive); + + private: class rank_host_t { - public: + public: int64_t rank; std::string host; }; @@ -144,26 +156,25 @@ class rlite_match_writers_t : public match_writers_t std::map> m_gl_gatherer; std::map> m_gl_prop_gatherer; std::set m_gatherer; - }; - /*! R Version 1 match writers class for a matched resource set */ -class rv1_match_writers_t : public match_writers_t -{ -public: +class rv1_match_writers_t : public match_writers_t { + public: virtual bool empty (); virtual int emit_json (json_t **o, json_t **aux = nullptr); virtual int emit (std::stringstream &out); virtual int emit_vtx (const std::string &prefix, - const resource_graph_t &g, const vtx_t &u, - unsigned int needs, bool exclusive); - virtual int emit_edg (const std::string &prefix, - const resource_graph_t &g, const edg_t &e); + const resource_graph_t &g, + const vtx_t &u, + unsigned int needs, + bool exclusive); + virtual int emit_edg (const std::string &prefix, const resource_graph_t &g, const edg_t &e); virtual int emit_tm (uint64_t start_tm, uint64_t end_tm); virtual int emit_attrs (const std::string &k, const std::string &v); -private: + + private: int attrs_json (json_t **o); rlite_match_writers_t rlite; @@ -173,56 +184,57 @@ class rv1_match_writers_t : public match_writers_t jgf_match_writers_t jgf; }; - /*! R Version 1 with no "scheduling" key match writers class */ -class rv1_nosched_match_writers_t : public match_writers_t -{ -public: +class rv1_nosched_match_writers_t : public match_writers_t { + public: virtual bool empty (); virtual int emit_json (json_t **o, json_t **aux = nullptr); virtual int emit (std::stringstream &out); virtual int emit_vtx (const std::string &prefix, - const resource_graph_t &g, const vtx_t &u, - unsigned int needs, bool exclusive); + const resource_graph_t &g, + const vtx_t &u, + unsigned int needs, + bool exclusive); virtual int emit_tm (uint64_t start_tm, uint64_t end_tm); -private: + + private: rlite_match_writers_t rlite; int64_t m_starttime = 0; int64_t m_expiration = 0; }; - /*! Human-friendly simple match writers class for a matched resource set */ -class pretty_sim_match_writers_t : public match_writers_t -{ -public: +class pretty_sim_match_writers_t : public match_writers_t { + public: virtual bool empty (); virtual int emit_json (json_t **o, json_t **aux = nullptr); virtual int emit (std::stringstream &out); virtual int emit_vtx (const std::string &prefix, - const resource_graph_t &g, const vtx_t &u, - unsigned int needs, bool exclusive); -private: + const resource_graph_t &g, + const vtx_t &u, + unsigned int needs, + bool exclusive); + + private: std::list m_out; }; - /*! Match writer factory-method class */ class match_writers_factory_t { -public: + public: static match_format_t get_writers_type (const std::string &n); static std::shared_ptr create (match_format_t f); }; bool known_match_format (const std::string &format); -} // namespace resource_model -} // namespace Flux +} // namespace resource_model +} // namespace Flux -#endif // MATCH_WRITERS_HPP +#endif // MATCH_WRITERS_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/src/common/c++wrappers/eh_wrapper.hpp b/src/common/c++wrappers/eh_wrapper.hpp index dbad9064c..e51998b76 100644 --- a/src/common/c++wrappers/eh_wrapper.hpp +++ b/src/common/c++wrappers/eh_wrapper.hpp @@ -23,7 +23,7 @@ namespace cplusplus_wrappers { * exception classes to errnos as they are caught. */ class eh_wrapper_t { -public: + public: /*! Templated operator() method: An object of eh_wrapper_t *can invoke * its wrapping function using the function invocation convention. * "functor_object()". Different numbers and types of function parameters @@ -38,69 +38,68 @@ class eh_wrapper_t { * \param args variadic arguments list that is transparently * forwarded to f. */ - template - auto operator() (Functor f, Args && ... args) - -> decltype(f (std::forward (args) ... )) { + template + auto operator() (Functor f, Args &&...args) -> decltype (f (std::forward (args)...)) + { int rc = -1; exception_raised = false; memset (err_message, '\0', 4096); try { - return f (std::forward (args) ... ); - } - catch (std::bad_alloc &e) { + return f (std::forward (args)...); + } catch (std::bad_alloc &e) { errno = ENOMEM; snprintf (err_message, 4096, "ENOMEM: %s", e.what ()); - } - catch (std::length_error &e) { + } catch (std::length_error &e) { errno = ERANGE; snprintf (err_message, 4096, "ERANGE: %s", e.what ()); - } - catch (std::out_of_range &e) { + } catch (std::out_of_range &e) { errno = ENOENT; snprintf (err_message, 4096, "ENOENT: %s", e.what ()); - } - catch (std::exception &e) { + } catch (std::exception &e) { errno = ENOSYS; snprintf (err_message, 4096, "ENOSYS: %s", e.what ()); - } - catch (...) { + } catch (...) { errno = ENOSYS; snprintf (err_message, 4096, "ENOSYS: Caught unknown exception"); } exception_raised = true; - return return_ (args) ...))> (rc); + return return_ (args)...))> (rc); } /*! Has a C++ exception been raised from the last invocation of operator()? */ - bool bad () { + bool bad () + { return exception_raised; } /*! Return the exception error message associated from the last invocation * of operator(). */ - const char *get_err_message () { + const char *get_err_message () + { return exception_raised ? err_message : NULL; } -private: - template - T return_ (int i) { - return T(i); + private: + template + T return_ (int i) + { + return T (i); } bool exception_raised = false; - char err_message[4096]; // to avoid a bad_alloc exception with std::string + char err_message[4096]; // to avoid a bad_alloc exception with std::string }; -template <> -inline void eh_wrapper_t::return_ (int i) { +template<> +inline void eh_wrapper_t::return_ (int i) +{ return; } -} // namespace c++wrappers -} // namespace Flux +} // namespace cplusplus_wrappers +} // namespace Flux /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/src/common/c++wrappers/test/exception_safe_wrapper_test01.cpp b/src/common/c++wrappers/test/exception_safe_wrapper_test01.cpp index b441282fd..e0a358a4e 100644 --- a/src/common/c++wrappers/test/exception_safe_wrapper_test01.cpp +++ b/src/common/c++wrappers/test/exception_safe_wrapper_test01.cpp @@ -10,7 +10,7 @@ extern "C" { #if HAVE_CONFIG_H -# include +#include #endif } @@ -25,37 +25,38 @@ extern "C" { using namespace Flux::cplusplus_wrappers; - static void throw_exception (int en) { switch (en) { - case ENOMEM: - throw std::bad_alloc (); - break; - case ERANGE: - throw std::length_error (__FUNCTION__); - break; - case ENOENT: - throw std::out_of_range (__FUNCTION__); - break; - case ENOSYS: - throw std::exception (); - break; - case ENOTSUP: - throw "Unknown exception"; - break; + case ENOMEM: + throw std::bad_alloc (); + break; + case ERANGE: + throw std::length_error (__FUNCTION__); + break; + case ENOENT: + throw std::out_of_range (__FUNCTION__); + break; + case ENOSYS: + throw std::exception (); + break; + case ENOTSUP: + throw "Unknown exception"; + break; } } struct foo_functor_t { - int operator() (int en) { + int operator() (int en) + { throw_exception (en); return 0; } }; struct foo_functor_eh_wrapper_t { - int operator() (int en) { + int operator() (int en) + { eh_wrapper_t exception_safe_wrapper; foo_functor_t functor; return exception_safe_wrapper (functor, en); @@ -70,14 +71,14 @@ int foo1 (int en) int foo2 (int en, double p1, float p2, long p3, long long p4) { - int rc = (int) (p1 + p2 + p3 + p4); + int rc = (int)(p1 + p2 + p3 + p4); p1 = p2 = p3 = p4 = 0; return rc; } int foo3 (int en, double &p1, float &p2, long &p3, long long &p4) { - int rc = (int) (p1 + p2 + p3 + p4); + int rc = (int)(p1 + p2 + p3 + p4); p1 = p2 = p3 = p4 = 0; return rc; } @@ -87,7 +88,6 @@ void foo4 (int en) throw_exception (en); } - static void test_functor_wrapper () { int rc = 0; @@ -95,33 +95,27 @@ static void test_functor_wrapper () errno = 0; rc = func (-1); - ok (rc == 0 && errno == 0, - "eh_wrapper_t works with functor (no exception)"); + ok (rc == 0 && errno == 0, "eh_wrapper_t works with functor (no exception)"); errno = 0; rc = func (ENOMEM); - ok (rc == -1 && errno == ENOMEM, - "eh_wrapper_t works with functor (bad_alloc exception)"); + ok (rc == -1 && errno == ENOMEM, "eh_wrapper_t works with functor (bad_alloc exception)"); errno = 0; rc = func (ERANGE); - ok (rc == -1 && errno == ERANGE, - "eh_wrapper_t works with functor (length_error exception)"); + ok (rc == -1 && errno == ERANGE, "eh_wrapper_t works with functor (length_error exception)"); errno = 0; rc = func (ENOENT); - ok (rc == -1 && errno == ENOENT, - "eh_wrapper_t works with functor (out_of_range exception)"); + ok (rc == -1 && errno == ENOENT, "eh_wrapper_t works with functor (out_of_range exception)"); errno = 0; rc = func (ENOSYS); - ok (rc == -1 && errno == ENOSYS, - "eh_wrapper_t works with functor (std::exception)"); + ok (rc == -1 && errno == ENOSYS, "eh_wrapper_t works with functor (std::exception)"); errno = 0; rc = func (ENOTSUP); - ok (rc == -1 && errno == ENOSYS, - "eh_wrapper_t works with functor (unknown exception)"); + ok (rc == -1 && errno == ENOSYS, "eh_wrapper_t works with functor (unknown exception)"); } static void test_function_wrapper () @@ -132,8 +126,7 @@ static void test_function_wrapper () errno = 0; rc = exception_safe_wrapper (foo1, -1); - ok (rc == 0 && errno == 0, - "eh_wrapper_t works with simple function (no exception)"); + ok (rc == 0 && errno == 0, "eh_wrapper_t works with simple function (no exception)"); ok (!exception_safe_wrapper.bad (), "eh_wrapper_t::bad() works with simple function (no exception)"); msg = exception_safe_wrapper.get_err_message (); @@ -141,8 +134,7 @@ static void test_function_wrapper () errno = 0; rc = exception_safe_wrapper (foo1, ENOENT); - ok (rc == -1 && errno == ENOENT, - "eh_wrapper_t works with simple function (out_of_range)"); + ok (rc == -1 && errno == ENOENT, "eh_wrapper_t works with simple function (out_of_range)"); ok (exception_safe_wrapper.bad (), "eh_wrapper_t::bad() works with simple function (out_of_range)"); msg = exception_safe_wrapper.get_err_message (); @@ -162,8 +154,7 @@ static void test_function_wrapper2 () int sum1 = static_cast (p1 + p2 + p3 + p4); rc = exception_safe_wrapper (foo2, -1, p1, p2, p3, p4); int sum2 = static_cast (p1 + p2 + p3 + p4); - ok (rc == sum1 && sum1 == sum2 && errno == 0, - "eh_wrapper_t forwards args by value works"); + ok (rc == sum1 && sum1 == sum2 && errno == 0, "eh_wrapper_t forwards args by value works"); } static void test_function_wrapper3 () @@ -179,8 +170,7 @@ static void test_function_wrapper3 () int sum1 = static_cast (p1 + p2 + p3 + p4); rc = exception_safe_wrapper (foo3, -1, p1, p2, p3, p4); int sum2 = static_cast (p1 + p2 + p3 + p4); - ok (rc == sum1 && sum2 == 0 && errno == 0, - "eh_wrapper_t forwards args by reference works"); + ok (rc == sum1 && sum2 == 0 && errno == 0, "eh_wrapper_t forwards args by reference works"); } static void test_lambda_wrapper () @@ -190,25 +180,27 @@ static void test_lambda_wrapper () eh_wrapper_t exception_safe_wrapper; errno = 0; - rc = exception_safe_wrapper ([](int en) { - throw_exception (en); - return 0; }, - -1); - - ok (rc == 0 && errno == 0, - "eh_wrapper_t works with lambda function (no exception)"); + rc = exception_safe_wrapper ( + [] (int en) { + throw_exception (en); + return 0; + }, + -1); + + ok (rc == 0 && errno == 0, "eh_wrapper_t works with lambda function (no exception)"); ok (!exception_safe_wrapper.bad (), "eh_wrapper_t::bad() works with simple function (no exception)"); msg = exception_safe_wrapper.get_err_message (); ok (msg == NULL, "eh_wrapper_t::get_err_message () works (no exception)"); errno = 0; - rc = exception_safe_wrapper ([](int en) { - throw_exception (en); - return 0; }, - ENOENT); - ok (rc == -1 && errno == ENOENT, - "eh_wrapper_t works with simple function (out_of_range)"); + rc = exception_safe_wrapper ( + [] (int en) { + throw_exception (en); + return 0; + }, + ENOENT); + ok (rc == -1 && errno == ENOENT, "eh_wrapper_t works with simple function (out_of_range)"); ok (exception_safe_wrapper.bad (), "eh_wrapper_t::bad() works with simple function (out_of_range)"); msg = exception_safe_wrapper.get_err_message (); @@ -222,8 +214,7 @@ static void test_function_wrapper4 () errno = 0; exception_safe_wrapper (foo4, -1); - ok (errno == 0, - "eh_wrapper_t works with void function (no exception)"); + ok (errno == 0, "eh_wrapper_t works with void function (no exception)"); ok (!exception_safe_wrapper.bad (), "eh_wrapper_t::bad() works with void function (no exception)"); msg = exception_safe_wrapper.get_err_message (); @@ -231,8 +222,7 @@ static void test_function_wrapper4 () errno = 0; exception_safe_wrapper (foo4, ENOENT); - ok (errno == ENOENT, - "eh_wrapper_t works with void function (out_of_range)"); + ok (errno == ENOENT, "eh_wrapper_t works with void function (out_of_range)"); ok (exception_safe_wrapper.bad (), "eh_wrapper_t::bad() works with void function (out_of_range)"); msg = exception_safe_wrapper.get_err_message (); diff --git a/src/common/liboptmgr/optmgr.hpp b/src/common/liboptmgr/optmgr.hpp index 5d5a8f545..01bb56800 100644 --- a/src/common/liboptmgr/optmgr.hpp +++ b/src/common/liboptmgr/optmgr.hpp @@ -18,7 +18,6 @@ namespace Flux { namespace opts_manager { - /*! Flux module option composer class: Module options can come * from multiple sources (e.g., through compile-time default, * configuration file and module load options). This simple templated @@ -35,10 +34,9 @@ namespace opts_manager { * have it; otherwise override it. However, this wrapper class simply * delegates the composition rule down to the template T class. */ -template +template class optmgr_composer_t { -public: - + public: /*! * Compose the option-set state managed by "this" object * with the option-set state from another object with @@ -46,11 +44,12 @@ class optmgr_composer_t { * If T doesn't have operator+=(), a compilation error * will ensue. * - * \param o option-set object of T type + * \param o option-set object of T type * \return the option set object of type T of "this" * after composed with o. */ - T &operator+= (const T &o) { + T &operator+= (const T &o) + { return m_opt += o; } @@ -59,7 +58,8 @@ class optmgr_composer_t { * of the object of the option set class T which canonicalizes * its internal state after all the composition completes. */ - T &canonicalize () { + T &canonicalize () + { return m_opt.canonicalize (); } @@ -68,7 +68,8 @@ class optmgr_composer_t { * * \return Option set object of type T */ - const T &get_opt () const { + const T &get_opt () const + { return m_opt; } @@ -78,15 +79,15 @@ class optmgr_composer_t { * \param json_out output JSON string * \return 0 on success; -1 on error. */ - int jsonify (std::string &json_out) const { + int jsonify (std::string &json_out) const + { return m_opt.jsonify (json_out); } -private: + private: T m_opt; }; - /*! A key value store class that helps parsing and holding * the option set from a single source (e.g., an option set passed from * module-load time). @@ -96,14 +97,14 @@ class optmgr_composer_t { * In addition, T must provide "operator()" method to give specific * iteration order on the option set. */ -template +template struct optmgr_kv_t { - /*! Getter * * \return Option set object of type T of "this" object. */ - const T &get_opt () const { + const T &get_opt () const + { return m_opt; } @@ -114,7 +115,8 @@ struct optmgr_kv_t { * * \return 0 on success; -1 on error. */ - int put (const std::string &k, const std::string &v) { + int put (const std::string &k, const std::string &v) + { int rc = 0; try { auto ret = m_kv.insert (std::pair (k, v)); @@ -122,8 +124,7 @@ struct optmgr_kv_t { errno = EEXIST; rc = -1; } - } - catch (std::bad_alloc &) { + } catch (std::bad_alloc &) { errno = ENOMEM; rc = -1; } @@ -136,9 +137,10 @@ struct optmgr_kv_t { * * \return 0 on success; -1 on error. */ - int put (const std::string &kv) { + int put (const std::string &kv) + { size_t found = std::string::npos; - if ( (found = kv.find_first_of ("=")) == std::string::npos) { + if ((found = kv.find_first_of ("=")) == std::string::npos) { errno = EPROTO; return -1; } @@ -152,16 +154,15 @@ struct optmgr_kv_t { * * \return 0 on success; -1 on error. */ - int get (const std::string &k, std::string &v) const { + int get (const std::string &k, std::string &v) const + { int rc = 0; try { v = m_kv.at (k); - } - catch (std::bad_alloc &) { + } catch (std::bad_alloc &) { errno = ENOMEM; rc = -1; - } - catch (std::out_of_range &) { + } catch (std::out_of_range &) { errno = ENOENT; rc = -1; } @@ -175,28 +176,27 @@ struct optmgr_kv_t { * \param info parse warning or error string. * \return 0 on success; -1 on error. */ - int parse (std::string &info) { + int parse (std::string &info) + { int rc = 0; for (const auto &kv : m_kv) { // If T doesn't have parse method, this produces an compiler error - if ( (rc = m_opt.parse (kv.first, kv.second, info)) < 0) { + if ((rc = m_opt.parse (kv.first, kv.second, info)) < 0) { return rc; } } return rc; } -private: + private: T m_opt; std::map m_kv; }; - /*! Parsing utilities. * */ -struct optmgr_parse_t { - +struct optmgr_parse_t { /*! Parse a string that contains key and value delimited with token. * The parsed key and value are passed through k and v respectively. * @@ -208,14 +208,17 @@ struct optmgr_parse_t { * \return 0 on success; -1 on error. * errno: EINVAL and EPROTO */ - int parse_single (const std::string &str, const std::string &token, - std::string &k, std::string &v) { + int parse_single (const std::string &str, + const std::string &token, + std::string &k, + std::string &v) + { size_t found; if (str == "" || token == "") { errno = EINVAL; return -1; } - if ( (found = str.find_first_of (token)) == std::string::npos) { + if ((found = str.find_first_of (token)) == std::string::npos) { errno = EPROTO; return -1; } @@ -237,8 +240,10 @@ struct optmgr_parse_t { * \return 0 on success; -1 on error. * errno: ENOMEM */ - int parse_multi (const std::string multi_value, const char delim, - std::vector &entries) { + int parse_multi (const std::string multi_value, + const char delim, + std::vector &entries) + { int rc = 0; try { std::stringstream ss; @@ -246,8 +251,7 @@ struct optmgr_parse_t { ss << multi_value; while (getline (ss, entry, delim)) entries.push_back (entry); - } - catch (std::bad_alloc &) { + } catch (std::bad_alloc &) { errno = ENOMEM; rc = -1; } @@ -268,29 +272,29 @@ struct optmgr_parse_t { * \return 0 on success; -1 on error. * errno: ENOMEM, EEXIST, EINVAL and EPROTO. */ - int parse_multi_options (const std::string &m_opts, const char odelim, - const char kdelim, std::map &opt_mp) { + int parse_multi_options (const std::string &m_opts, + const char odelim, + const char kdelim, + std::map &opt_mp) + { int rc = 0; try { std::vector entries; - if ( (rc = parse_multi (m_opts, odelim, entries)) < 0) + if ((rc = parse_multi (m_opts, odelim, entries)) < 0) goto done; for (const auto &entry : entries) { std::string n = ""; std::string v = ""; - if ( (rc = parse_single (entry, std::string (1, kdelim), n, v)) < 0) + if ((rc = parse_single (entry, std::string (1, kdelim), n, v)) < 0) goto done; - auto ret = opt_mp.insert (std::pair (n, v)); + auto ret = opt_mp.insert (std::pair (n, v)); if (!ret.second) { errno = EEXIST; rc = -1; goto done; } } - } - catch (std::bad_alloc &) { + } catch (std::bad_alloc &) { errno = ENOMEM; rc = -1; } @@ -299,10 +303,10 @@ struct optmgr_parse_t { } }; -} // namespace Flux::opts_manager -} // namespace Flux +} // namespace opts_manager +} // namespace Flux -#endif // OPTMGR_HPP +#endif // OPTMGR_HPP /* * vi:tabstop=4 shiftwidth=4 expandtab diff --git a/src/python/fluxion/resourcegraph/V1.py b/src/python/fluxion/resourcegraph/V1.py index b8f3ea2d7..cda90a197 100644 --- a/src/python/fluxion/resourcegraph/V1.py +++ b/src/python/fluxion/resourcegraph/V1.py @@ -16,7 +16,6 @@ class FluxionResourcePoolV1(Node): - """ Fluxion Resource Pool Vertex Class: extend jsongraph's Node class """ diff --git a/t/scripts/flux-jsonschemalint.py b/t/scripts/flux-jsonschemalint.py index 87131a02b..d0f29df05 100755 --- a/t/scripts/flux-jsonschemalint.py +++ b/t/scripts/flux-jsonschemalint.py @@ -10,12 +10,12 @@ import json import jsonschema -""" - Print json document and schema as a verbose option -""" - def print_verbose(doc, schema): + """ + Print json document and schema as a verbose option + """ + print("==============================================") print(" Jsonschema ") print("==============================================") @@ -28,12 +28,11 @@ def print_verbose(doc, schema): print("") -""" +def main(): + """ Main entry point -""" - + """ -def main(): desc = "Validate an JSON document against an JSON scheme." parser = argparse.ArgumentParser(description=desc) parser.add_argument("schema", help="JSON schema file name") diff --git a/t/scripts/y2j.py b/t/scripts/y2j.py index 969715af4..0af43e4f3 100755 --- a/t/scripts/y2j.py +++ b/t/scripts/y2j.py @@ -7,7 +7,7 @@ obj = yaml.safe_load(sys.stdin) except (OSError, IOError) as e: sys.exit("y2j: " + e.strerror) -except (yaml.YAMLError) as e: +except yaml.YAMLError as e: sys.exit("y2j: " + e.problem) json.dump(obj, sys.stdout, separators=(",", ":"))