示例#1
0
int IntegLoopSimObject::call_function ( Trick::JobData * curr_job ) {

    int trick_ret = 0 ;
    if ( curr_job->disabled ) return (trick_ret) ;

    switch ( curr_job->id ) {
        case 0:
            integ_sched.rebuild_jobs() ;
            break ;
        case 1:
            integ_sched.get_first_step_deriv_from_integrator() ;
            break ;
        case 2:
            integ_sched.call_deriv_jobs() ;
            break ;
        case 3:
            integ_sched.integrate() ;
            break ;
        case 4:
            checkpoint_stl(integ_sched.sim_objects, name + std::string("_") + std::string("integ_sched.sim_objects"), std::string("")) ;
            break ;
        case 5:
            delete_stl (integ_sched.sim_objects, name + std::string("_") + std::string("integ_sched.sim_objects"), std::string("")) ;
            break ;
        case 6:
            restore_stl (integ_sched.sim_objects, name + std::string("_") + std::string("integ_sched.sim_objects"), std::string("")) ;
            break ;
        case 7:
            integ_sched.restart_checkpoint() ;
            break ;
        case 8:
            integ_sched.rebuild_jobs() ;
            break ;
        case 9:
            integ_sched.get_first_step_deriv_from_integrator() ;
            break ;
        default:
            trick_ret = -1 ;
            break ;
    }

    return(trick_ret) ;
}
示例#2
0
/* All STLs are restored through the same templated function restore_stl.  The 
   second and third arguments give the unique name to delete.  In
   this example the unique name is the concatenation of the object instance and the variable name.
   retore_stl will delete the memory manager arrays. 
 */
int STLCompanion::restart(STLCheckpoint * stlc, std::string object_name ) {

    restore_stl(stlc->my_double_map , object_name , std::string("my_double_map")) ;
    restore_stl(stlc->my_string_key_map , object_name , std::string("my_string_key_map")) ;
    restore_stl(stlc->my_string_data_map , object_name , std::string("my_string_data_map")) ;
    restore_stl(stlc->my_string_map , object_name , std::string("my_string_map")) ;

    restore_stl(stlc->my_int_multimap , object_name , std::string("my_int_multimap")) ;
    restore_stl(stlc->my_string_key_multimap , object_name , std::string("my_string_key_multimap")) ;
    restore_stl(stlc->my_string_data_multimap , object_name , std::string("my_string_data_multimap")) ;
    restore_stl(stlc->my_string_multimap , object_name , std::string("my_string_multimap")) ;

    restore_stl(stlc->my_double_vector , object_name , std::string("my_double_vector")) ;
    restore_stl(stlc->my_string_vector , object_name , std::string("my_string_vector")) ;

    restore_stl(stlc->my_short_list , object_name , std::string("my_short_list")) ;
    restore_stl(stlc->my_string_list , object_name , std::string("my_string_list")) ;

    restore_stl(stlc->my_float_deque , object_name , std::string("my_float_deque")) ;
    restore_stl(stlc->my_string_deque , object_name , std::string("my_string_deque")) ;

    restore_stl(stlc->my_int_set , object_name , std::string("my_int_set")) ;
    restore_stl(stlc->my_string_set , object_name , std::string("my_string_set")) ;

    restore_stl(stlc->my_long_multiset , object_name , std::string("my_long_multiset")) ;
    restore_stl(stlc->my_string_multiset , object_name , std::string("my_string_multiset")) ;

    restore_stl(stlc->my_uint_stack , object_name , std::string("my_uint_stack")) ;
    restore_stl(stlc->my_string_stack , object_name , std::string("my_string_stack")) ;

    restore_stl(stlc->my_int_queue , object_name , std::string("my_int_queue")) ;
    restore_stl(stlc->my_string_queue , object_name , std::string("my_string_queue")) ;

    restore_stl(stlc->my_int_priority_queue , object_name , std::string("my_int_priority_queue")) ;
    restore_stl(stlc->my_string_priority_queue , object_name , std::string("my_string_priority_queue")) ;

    restore_stl(stlc->my_int_pair , object_name , std::string("my_int_pair")) ;
    restore_stl(stlc->my_string_first_pair , object_name , std::string("my_string_first_pair")) ;
    restore_stl(stlc->my_string_second_pair , object_name , std::string("my_string_second_pair")) ;
    restore_stl(stlc->my_string_pair , object_name , std::string("my_stringpair")) ;

    return 0 ;
}
示例#3
0
/**
@details
-# verify that all jobs in the checkpoint are present in the current simulation
-# Clear all current job information in scheduler
-# Clear all current sim_object information in scheduler
-# Add the sim_objects in checkpoint to the scheduler
-# Call post_checkpoint to delete memory for checkpoint
*/
int Trick::Executive::restart() {

    unsigned int ii ;
    std::multimap<std::string, Trick::JobData *>::iterator it ;
    std::pair<std::multimap<std::string, Trick::JobData *>::iterator, std::multimap<std::string, Trick::JobData *>::iterator> ret ;
    std::vector <Trick::SimObject *>::iterator sit ;
    std::vector <Trick::JobData *>::iterator jit ;
    std::multimap<std::string, Trick::JobData *> all_jobs_from_checkpointed_objects ;

    /*
       Save the current job index position of the input processor queue. This queue position is special
       because of the possibility of restarting from a checkpoint read in from the input file.  When
       we restart from a checkpoint we reset the queues.  If we reset the input_processor queue we'll
       call the input_processor again... and we can end up in recursive hell.  Save the current position
       and replace the queue position after the queues have been rebuilt.  This ensures that we don't
       call the input file twice, or more!
     */
    unsigned int current_ip_index = input_processor_queue.get_curr_index() ;

    /* clear all current job information in scheduler.  These will be repopulated when we call add_job_to_queue */
    clear_scheduled_queues() ;
    all_jobs.clear() ;
    all_jobs_vector.clear() ;
    all_tagged_jobs.clear() ;

    /* clear all sim_object information in scheduler */
    num_sim_objects = 0 ;
    sim_objects.clear() ;

    /* restore the list of sim_objects from the checkpoint. */
    restore_stl(sim_objects , std::string("trick_sys") , std::string("sim_objects")) ;

    /* Create a temporary all_jobs map to use to restore job data from all_jobs_for_checkpoint */
    for ( sit = sim_objects.begin() ; sit != sim_objects.end() ; sit++ ) {
        for ( jit = (*sit)->jobs.begin() ; jit != (*sit)->jobs.end() ; jit++ ) {
            /* Dynamically created sim_objects, like data_recording objects, require that
               some of the job class data be repopulated before we start
               copying job data back into the sim. */
            (*jit)->sim_object_id = (*sit)->id ;
            (*jit)->parent_object = (*sit) ;
            (*jit)->frame_id = (*jit)->sim_object_id + ((double)(*jit)->id / 100.0);
            std::string so_name_and_period = (*sit)->name + "." ;
            if ( strncmp( (*jit)->name.c_str() , so_name_and_period.c_str(), so_name_and_period.length())) {
                (*jit)->name = (*sit)->name + "." + (*jit)->name ;
            }
            all_jobs_from_checkpointed_objects.insert(std::pair<std::string, JobData *>((*jit)->name,(*jit))) ;
        }
    }

    /* verify that all jobs in the checkpoint are present in the current simulation */
    for ( ii = 0 ; ii < num_all_jobs ; ii++ ) {
        ret = all_jobs_from_checkpointed_objects.equal_range(all_jobs_for_checkpoint[ii].name) ;
        if ( ret.first == all_jobs_from_checkpointed_objects.end() ) {
            message_publish(MSG_ERROR, "Could not find job %s\n", all_jobs_for_checkpoint[ii].name.c_str()) ;
            exec_terminate_with_return( -1 , __FILE__ , __LINE__ , "Job in checkpoint file does not exist in current sim." ) ;
        } else {
            for ( it = ret.first ; it != ret.second ; it++ ) {
                // The JobData::id and JobData::sim_object_id together uniquely identify a job.
                if (( it->second->id            == all_jobs_for_checkpoint[ii].id ) &&
                    ( it->second->sim_object_id == all_jobs_for_checkpoint[ii].sim_object_id )) {
                    // copy the job information from the checkpoint back to the job.
                    it->second->copy_from_checkpoint(&all_jobs_for_checkpoint[ii]) ;
                }
            }
        }
    }

    /* restore the executive sim_objects vector from the checkpoint and add back all of
       the jobs to the schedulers */
    for ( sit = sim_objects.begin() ; sit != sim_objects.end() ; sit++ ) {
        add_jobs_to_queue(*sit, true) ;
        for ( ii = 0 ; ii < other_schedulers.size() ; ii++ ) {
            other_schedulers[ii]->add_sim_object(*sit) ;
        }
    }
    num_sim_objects = sim_objects.size() ;

    // The queues have been rebuilt, restore the current position of the input processor queue.
    input_processor_queue.set_curr_index(current_ip_index) ;

    // set the restart_called flag to true.  This flag is checked during Executive::init.  If
    // we have restarted from a checkpoint, we will be skipping initialization jobs.
    restart_called = true ;

    /* Delete temporary memory used to restore jobs */
    TMM_delete_var_a(all_jobs_for_checkpoint) ;
    all_jobs_for_checkpoint = NULL ;

    // restore the vector of freeze times
    restore_stl(freeze_times , std::string("trick_sys") , std::string("freeze_times")) ;

    /* Set the main thread current time to the simulation time tics value, used with Executive::get_sim_time() */

    threads[0]->curr_time_tics = time_tics ;

    // if we restarted from scratch without calling init jobs, need to create child threads
    create_threads() ;

    // make sure asynchronous must finish jobs restart at correct time
    for (ii = 1; ii < threads.size() ; ii++) {
        Threads * curr_thread = threads[ii] ;
        if ( (curr_thread->process_type == PROCESS_TYPE_AMF_CHILD) ||
             (curr_thread->process_type == PROCESS_TYPE_ASYNC_CHILD) ) {
            if ( curr_thread->amf_cycle_tics > 0 and time_tics % curr_thread->amf_cycle_tics ) {
                curr_thread->amf_next_tics = time_tics + curr_thread->amf_cycle_tics - (time_tics % curr_thread->amf_cycle_tics) ;
            } else {
                curr_thread->amf_next_tics = time_tics ;
            }
        }
    }

    // If we are in freeze, reset the freeze_scheduled queue, we'll restart freeze time at 0
    if ( mode == Freeze ) {
        init_freeze_scheduled() ;
    }


    return(0) ;
}