/* PURPOSE: (CheckPointRestart) */ #ifndef MMWRAPPER_HH #define MMWRAPPER_HH #include #include #include #include "sim_services/Scheduler/include/Scheduler.hh" namespace Trick { /** * * This class wraps the MemoryManager class for use in Trick simulations * @author Alexander S. Lin * */ class CheckPointRestart : public Trick::Scheduler { protected: /** queue to hold jobs to be called before a checkpoint is dumped. */ Trick::ScheduledJobQueue checkpoint_queue ; /* ** */ /** queue to hold jobs to be called before a checkpoint is dumped. */ Trick::ScheduledJobQueue post_checkpoint_queue ; /* ** */ /** queue to hold jobs to be called before a checkpoint is reloaded. */ Trick::ScheduledJobQueue preload_checkpoint_queue ; /* ** */ /** queue to hold jobs to be called after a checkpoint is reloaded. */ Trick::ScheduledJobQueue restart_queue ; /* ** */ /** The specified sim objs for checkpoint, if it's null, checkpoint everything */ std::vector obj_list; /* ** */ /** The specified sim objs for checkpoint, if it's null, checkpoint everything */ Trick::JobData * write_checkpoint_job ; /* ** */ /** The specified sim objs for checkpoint, if it's null, checkpoint everything */ Trick::JobData * safestore_checkpoint_job ; /* ** */ /** * Internal call the MemoryManager checkpoint method with the string argument file_name * @param file_name - file name to write checkpoint * @param print_status - print a message when checkpoint is written * @return always 0 */ int do_checkpoint( std::string file_name , bool print_status) ; public: /** Times to dump a checkpoint. Saved as simulation tics.\n */ std::priority_queue< long long, std::vector< long long >, std::greater< long long > > checkpoint_times ; /**< trick_units(--) */ /** Times to dump a dmtcp_checkpoint. Saved as simulation tics.\n */ std::priority_queue< long long, std::vector< long long >, std::greater< long long > > dmtcp_checkpoint_times ; /**< trick_units(--) */ /** Period to dump a recurring checkpoint. Saved as simulation tics.\n */ long long safestore_period ; /**< trick_units(--) */ /** Period to dump a recurring dmtcp checkpoint. Saved as simulation tics.\n */ long long dmtcp_safestore_period ; /**< trick_units(--) */ /** Next time to dump a recurring checkpoint. Saved as simulation tics.\n */ long long safestore_time ; /**< trick_units(--) */ /** Next time to dump a recurring dmtcp checkpoint. Saved as simulation tics.\n */ long long dmtcp_safestore_time ; /**< trick_units(--) */ /** If true take a pre_init_checkpoint\n */ bool pre_init_checkpoint ; /**< trick_units(--) */ /** If true take a post_init_checkpoint\n */ bool post_init_checkpoint ; /**< trick_units(--) */ /** If true take a end_checkpoint\n */ bool end_checkpoint ; /**< trick_units(--) */ /** If true enable taking safestore checkpoints\n */ bool safestore_enabled ; /**< trick_units(--) */ /** If true enable taking safestore checkpoints\n */ bool dmtcp_safestore_enabled ; /**< trick_units(--) */ /** output_directory/checkpoint_file_name to dump for a checkpoint\n */ std::string output_file ; /**< ** */ /** output_directory/checkpoint_file_name to load for a restore\n */ std::string load_checkpoint_file_name ; /**< ** */ /** CPU to use for checkpoints\n */ int cpu_num ; /**< trick_units(--) */ /** * This is the constructor of the CheckPointRestart class. It initializes * the checkpoint, pre_load_checkpoint, and the restart_queues */ CheckPointRestart() ; /** @brief @userdesc Command to set the pre_init_checkpoint flag. If pre_init_checkpoint is set a checkpoint will be done before Initialization class jobs are run (at beginning of P1 phase). The checkpointed file name is @e chkpnt_pre_init. @par Python Usage: @code trick.checkpoint_pre_init() @endcode @param yes_no - boolean yes (C integer 1) = dump checkpoint, no (C integer 0) = do not dump @return always 0 */ int set_pre_init_checkpoint(bool yes_no) ; /** @brief @userdesc Command to set the post_init_checkpoint flag. If post_init_checkpoint is set a checkpoint will be done after Initialization class jobs are run (at beginning of the P65535 phase). The checkpointed file name is @e chkpnt_post_init. @par Python Usage: @code trick.checkpoint_post_init() @endcode @param yes_no - boolean yes (C integer 1) = dump checkpoint, no (C integer 0) = do not dump @return always 0 */ int set_post_init_checkpoint(bool yes_no) ; /** @brief @userdesc Command to set the end_checkpoint flag. If end_checkpoint is set a checkpoint will be done at simulation termination before any other Shutdown class jobs are run. The checkpointed file name is @e chkpnt_end. @par Python Usage: @code trick.checkpoint_end() @endcode @param yes_no - boolean yes (C integer 1) = dump checkpoint, no (C integer 0) = do not dump @return always 0 */ int set_end_checkpoint(bool yes_no) ; /** @brief @userdesc Command to set the safestore_enabled flag. If safestore_enabled is set periodic checkpoints will be done according to safestore_period that was set in checkpoint_safestore(). The checkpointed file name is @e chkpnt_safestore. @par Python Usage: @code trick.checkpoint_safestore_set_enabled() @endcode @param yes_no - boolean yes (C integer 1) = dump periodic checkpoint, no (C integer 0) = do not dump @return always 0 */ int set_safestore_enabled(bool yes_no) ; /** @brief @userdesc Command to set the dmtcp_safestore_enabled flag. If dmtcp_safestore_enabled is set periodic checkpoints will be done according to dmtcp_safestore_period that was set in dmtcp_checkpoint_safestore(). The checkpointed file name is @e dmtcp_chkpnt_safestore. @par Python Usage: @code trick.dmtcp_checkpoint_safestore_set_enabled() @endcode @param yes_no - boolean yes (C integer 1) = dump periodic checkpoint, no (C integer 0) = do not dump @return always 0 */ int dmtcp_set_safestore_enabled(bool yes_no) ; /** @brief @userdesc Command to get the name of the checkpoint dump file. @par Python Usage: @code trick.checkpoint_get_output_file() @endcode @return string representing / */ const char * get_output_file() ; /** @brief @userdesc Command to get the name of the checkpoint load file. @par Python Usage: @code trick.checkpoint_get_load_file() @endcode @return string representing / */ const char * get_load_file() ; /** @brief @userdesc Command to set the CPU to use for checkpoints. The default is to use the same CPU as the main thread. If the main thread of the simulation is running at high real-time priority, it is recommended to choose a different CPU to use for checkpointing. @par Python Usage: @code trick.checkpoint_cpu() @endcode @param in_cpu_num - CPU number that Trick will use to perform checkpoints @return always 0 */ int set_cpu_num(int in_cpu_num) ; /** * Get the write_checkpoint_job and safestore_checkpoint jobs. * @return always 0 */ int find_write_checkpoint_jobs(std::string sim_object_name) ; /** @brief @userdesc Command to set the desired period that safestore checkpoints will be dumped. (Sets safestore_period to the integral time tic value corresponding to the incoming in_time so that checkpoint occurs periodically.) @par Python Usage: @code trick.checkpoint_safestore() @endcode @param in_time - desired safestore checkpoint time period in seconds. @return always 0 */ int set_safestore_time(double in_time) ; /** @brief @userdesc Command to set the desired period that dmtcp safestore checkpoints will be dumped. (Sets dmtcp_safestore_period to the integral time tic value corresponding to the incoming in_time so that checkpoint occurs periodically.) @par Python Usage: @code trick.dmtcp_checkpoint_safestore() @endcode @param in_time - desired dmtcp safestore checkpoint time period in seconds. @return always 0 */ int dmtcp_set_safestore_time(double in_time) ; /** @brief @userdesc Command to dump a checkpoint now to the specified file. Calls the MemoryManager checkpoint method with the string argument file_name and sim objects list string separated by "," to specify which sim objects need checkpointing. If sim objects are not specified, all will be checkpointed. @par Python Usage: @code trick.checkpoint() @endcode @param file_name - optional: name of checkpoint file to dump (default is "chkpnt_