static void freectx (void *arg) { ctx_t *ctx = arg; free_simstate (ctx->sim_state); free (ctx->rdl_string); free (ctx); }
// Recevied a reply to a trigger ("sim.reply") static void reply_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { const char *json_str = NULL; json_t *request = NULL; ctx_t *ctx = arg; sim_state_t *curr_sim_state = ctx->sim_state; sim_state_t *reply_sim_state; if (flux_msg_get_json (msg, &json_str) < 0 || json_str == NULL || !(request = Jfromstr (json_str))) { flux_log (h, LOG_ERR, "%s: bad reply message", __FUNCTION__); Jput (request); return; } // De-serialize and get new info reply_sim_state = json_to_sim_state (request); copy_new_state_data (ctx, curr_sim_state, reply_sim_state); if (handle_next_event (ctx) < 0) { flux_log (h, LOG_DEBUG, "No events remaining"); if (ctx->exit_on_complete) { log_msg_exit ("exit_on_complete is set. Exiting now."); } else { send_complete_event (h); } } free_simstate (reply_sim_state); Jput (request); }
static void freectx (void *arg) { ctx_t *ctx = arg; free_simstate (ctx->sim_state); while (zlist_size (ctx->queued_events) > 0) free (zlist_pop (ctx->queued_events)); zlist_destroy (&ctx->queued_events); while (zlist_size (ctx->running_jobs) > 0) free_job (zlist_pop (ctx->running_jobs)); zlist_destroy (&ctx->running_jobs); rdllib_close (ctx->rdllib); free (ctx->rdl); free (ctx); }
// Handle trigger requests from the sim module ("sim_exec.trigger") static void trigger_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { json_t *o = NULL; const char *json_str = NULL; double next_termination = -1; zhash_t *job_hash = NULL; ctx_t *ctx = (ctx_t *)arg; if (flux_msg_get_string (msg, &json_str) < 0 || json_str == NULL || !(o = Jfromstr (json_str))) { flux_log (h, LOG_ERR, "%s: bad message", __FUNCTION__); return; } // Logging flux_log (h, LOG_DEBUG, "received a trigger (sim_exec.trigger: %s", json_str); // Handle the trigger ctx->sim_state = json_to_sim_state (o); handle_queued_events (ctx); #if SIMEXEC_IO job_hash = determine_all_min_bandwidth (ctx->rdl, ctx->running_jobs); #endif advance_time (ctx, job_hash); handle_completed_jobs (ctx); next_termination = determine_next_termination (ctx, ctx->sim_state->sim_time, job_hash); set_event_timer (ctx, "sim_exec", next_termination); send_reply_request (h, module_name, ctx->sim_state); // Cleanup free_simstate (ctx->sim_state); ctx->sim_state = NULL; Jput (o); zhash_destroy (&job_hash); }