void * status_job__( void * arg ) { const int usleep_time = 10000; arg_pack_type * arg_pack = arg_pack_safe_cast( arg ); job_type * job = job_safe_cast( arg_pack_iget_ptr( arg_pack , 0 ) ); job_queue_type * queue = arg_pack_iget_ptr( arg_pack , 1 ); char * run_file = util_alloc_filename( job->run_path , "RUNNING" , NULL); while (true) { if (job->queue_index >= 0) { job_status_type status; if (util_is_file(run_file)) { status = job_queue_iget_job_status(queue, job->queue_index); if (util_is_file(run_file)) test_assert_true( (status == JOB_QUEUE_RUNNING) || (status == JOB_QUEUE_SUBMITTED) ); } status = job_queue_iget_job_status(queue, job->queue_index); if (status == JOB_QUEUE_SUCCESS) break; } usleep( usleep_time ); } free( run_file ); return NULL; }
static void * gravity_response_mt( void * arg ) { arg_pack_type * arg_pack = arg_pack_safe_cast( arg ); vector_type * grav_stations = arg_pack_iget_ptr( arg_pack , 0 ); const ecl_grid_type * ecl_grid = arg_pack_iget_ptr( arg_pack , 1 ); const ecl_file_type * init_file = arg_pack_iget_ptr( arg_pack , 2 ); ecl_file_type ** restart_files = arg_pack_iget_ptr( arg_pack , 3 ); int station1 = arg_pack_iget_int( arg_pack , 4 ); int station2 = arg_pack_iget_int( arg_pack , 5 ); int model_phases = arg_pack_iget_int( arg_pack , 6 ); int file_phases = arg_pack_iget_int( arg_pack , 7 ); int station_nr; for (station_nr = station1; station_nr < station2; station_nr++) { grav_station_type * gs = vector_iget( grav_stations , station_nr ); gs->grav_diff = gravity_response( ecl_grid , init_file , restart_files[0] , restart_files[1] , gs , model_phases , file_phases); } return NULL; }
void * ensemble_add_case__( void * arg ) { arg_pack_type * arg_pack = arg_pack_safe_cast( arg ); ensemble_type * ensemble = arg_pack_iget_ptr( arg , 0 ); const char * data_file = arg_pack_iget_ptr( arg , 1 ); ensemble_add_case( ensemble , data_file ); arg_pack_free( arg_pack ); return NULL; }
void * submit_job__( void * arg ) { arg_pack_type * arg_pack = arg_pack_safe_cast( arg ); job_type * job = job_safe_cast( arg_pack_iget_ptr( arg_pack , 0 ) ); job_queue_type * queue = arg_pack_iget_ptr( arg_pack , 1 ); job->queue_index = job_queue_add_job( queue , job->cmd , callback , NULL , NULL , job , 1 , job->run_path , job->run_path , job->argc , (const char **) job->argv ); usleep( job->submit_usleep ); return NULL; }
static void * enkf_main_initialize_from_scratch_mt(void * void_arg) { arg_pack_type * arg_pack = arg_pack_safe_cast( void_arg ); enkf_main_type * enkf_main = arg_pack_iget_ptr( arg_pack , 0); enkf_fs_type * init_fs = arg_pack_iget_ptr( arg_pack , 1); const stringlist_type * param_list = arg_pack_iget_const_ptr( arg_pack , 2 ); int iens = arg_pack_iget_int( arg_pack , 3 ); init_mode_type init_mode = arg_pack_iget_int( arg_pack , 4 ); enkf_state_type * state = enkf_main_iget_state( enkf_main , iens); enkf_state_initialize( state , init_fs , param_list , init_mode); return NULL; }
void enkf_tui_analysis_select_module__(void * arg) { int prompt_len = 50; arg_pack_type * arg_pack = arg_pack_safe_cast( arg ); enkf_main_type * enkf_main = arg_pack_iget_ptr( arg_pack , 0 ); menu_type * menu = arg_pack_iget_ptr( arg_pack , 1 ); const analysis_config_type * analysis_config = enkf_main_get_analysis_config(enkf_main); char module_name[256]; util_printf_prompt("Name module to select" , prompt_len , '=' , "=> "); scanf("%s", module_name); if (analysis_config_select_module( analysis_config , module_name )) enkf_tui_analysis_update_title( enkf_main , menu ); }
static void * job_queue_run_EXIT_callback( void * arg ) { arg_pack_type * arg_pack = arg_pack_safe_cast( arg ); job_queue_type * job_queue = arg_pack_iget_ptr( arg_pack , 0 ); int queue_index = arg_pack_iget_int( arg_pack , 1 ); job_list_get_rdlock( job_queue->job_list ); { job_queue_node_type * node = job_list_iget_job( job_queue->job_list , queue_index ); if (job_queue_node_get_submit_attempt( node ) < job_queue->max_submit) job_queue_change_node_status( job_queue , node , JOB_QUEUE_WAITING ); /* The job will be picked up for antother go. */ else { bool retry = job_queue_node_run_RETRY_callback( node ); if (retry) { /* OK - we have invoked the retry_callback() - and that has returned true; giving this job a brand new start. */ job_queue_node_reset_submit_attempt( node ); job_queue_change_node_status(job_queue , node , JOB_QUEUE_WAITING); } else { // It's time to call it a day job_queue_node_run_EXIT_callback( node ); job_queue_change_node_status(job_queue , node , JOB_QUEUE_FAILED); } } job_queue_node_free_driver_data( node , job_queue->driver ); } job_list_unlock(job_queue->job_list ); arg_pack_free( arg_pack ); return NULL; }
static void enkf_tui_ranking_make_misfit_ensemble( void * arg) { arg_pack_type * arg_pack = arg_pack_safe_cast( arg ); enkf_main_type * enkf_main = arg_pack_iget_ptr( arg_pack , 0 ); enkf_fs_type * fs = enkf_main_get_fs(enkf_main); enkf_obs_type * enkf_obs = enkf_main_get_obs( enkf_main ); const ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config(enkf_main); const int history_length = enkf_main_get_history_length( enkf_main ); const int ens_size = enkf_main_get_ensemble_size( enkf_main ); misfit_ensemble_type * misfit_ensemble = enkf_fs_get_misfit_ensemble( fs ); misfit_ensemble_update( misfit_ensemble , ensemble_config , enkf_obs , fs , ens_size , history_length ); { menu_item_type * obs_item = arg_pack_iget_ptr( arg_pack , 1 ); menu_item_enable( obs_item ); } }
void enkf_tui_fs_select_case(void * arg) { int prompt_len = 40; char * new_case; char * menu_title; arg_pack_type * arg_pack = arg_pack_safe_cast( arg ); enkf_main_type * enkf_main = enkf_main_safe_cast( arg_pack_iget_ptr(arg_pack, 0) ); menu_type * menu = arg_pack_iget_ptr(arg_pack, 1); new_case = enkf_tui_fs_alloc_existing_case( enkf_main , "Name of case" , prompt_len); if (new_case != NULL) { enkf_main_select_fs( enkf_main , new_case ); menu_title = util_alloc_sprintf("Manage cases. Current: %s", enkf_main_get_current_fs( enkf_main )); menu_set_title(menu, menu_title); free(menu_title); free(new_case); } }
void * job_queue_run_jobs__(void * __arg_pack) { arg_pack_type * arg_pack = arg_pack_safe_cast(__arg_pack); job_queue_type * queue = arg_pack_iget_ptr(arg_pack , 0); int num_total_run = arg_pack_iget_int(arg_pack , 1); bool verbose = arg_pack_iget_bool(arg_pack , 2); job_queue_run_jobs(queue , num_total_run , verbose); arg_pack_free( arg_pack ); return NULL; }
void * add_pathlist( void * arg ) { arg_pack_type * arg_pack = arg_pack_safe_cast( arg ); runpath_list_type * list = arg_pack_iget_ptr( arg_pack , 0 ); int offset = arg_pack_iget_int( arg_pack , 1 ); int bs = arg_pack_iget_int( arg_pack , 2 ); int i; for (i=0; i < bs; i++) runpath_list_add( list , i + offset , 0, "Path" , "Basename"); return NULL; }
static void * matrix_inplace_matmul_mt__(void * arg) { arg_pack_type * arg_pack = arg_pack_safe_cast( arg ); int row_offset = arg_pack_iget_int( arg_pack , 0 ); int rows = arg_pack_iget_int( arg_pack , 1 ); matrix_type * A = arg_pack_iget_ptr( arg_pack , 2 ); const matrix_type * B = arg_pack_iget_const_ptr( arg_pack , 3 ); matrix_type * A_view = matrix_alloc_shared( A , row_offset , 0 , rows , matrix_get_columns( A )); matrix_inplace_matmul( A_view , B ); matrix_free( A_view ); return NULL; }
void enkf_tui_fs_create_case(void * arg) { int prompt_len = 50; char new_case[256]; char * menu_title; arg_pack_type * arg_pack = arg_pack_safe_cast( arg ); enkf_main_type * enkf_main = enkf_main_safe_cast( arg_pack_iget_ptr(arg_pack, 0) ); menu_type * menu = arg_pack_iget_ptr(arg_pack, 1); util_printf_prompt("Name of new case" , prompt_len , '=' , "=> "); if (fgets(new_case, prompt_len, stdin) != NULL){ char *newline = strchr(new_case, '\n'); if (newline) *newline = 0; if(strlen(new_case) != 0) enkf_main_select_fs( enkf_main , new_case ); } menu_title = util_alloc_sprintf("Manage cases. Current: %s", enkf_main_get_current_fs(enkf_main)); menu_set_title(menu, menu_title); free(menu_title); }
static void * enkf_main_initialize_from_scratch_mt(void * void_arg) { arg_pack_type * arg_pack = arg_pack_safe_cast( void_arg ); enkf_main_type * enkf_main = arg_pack_iget_ptr( arg_pack , 0); const stringlist_type * param_list = arg_pack_iget_const_ptr( arg_pack , 1 ); int iens1 = arg_pack_iget_int( arg_pack , 2 ); int iens2 = arg_pack_iget_int( arg_pack , 3 ); init_mode_enum init_mode = arg_pack_iget_int( arg_pack , 4 ); int iens; for (iens = iens1; iens < iens2; iens++) { enkf_state_type * state = enkf_main_iget_state( enkf_main , iens); enkf_state_initialize( state , enkf_main_get_fs( enkf_main ) , param_list , init_mode); } return NULL; }
static void * job_queue_run_DO_KILL_callback( void * arg ) { arg_pack_type * arg_pack = arg_pack_safe_cast( arg ); job_queue_type * job_queue = arg_pack_iget_ptr( arg_pack , 0 ); int queue_index = arg_pack_iget_int( arg_pack , 1 ); job_list_get_rdlock( job_queue->job_list ); { job_queue_node_type * node = job_list_iget_job( job_queue->job_list , queue_index ); job_queue_node_free_driver_data( node , job_queue->driver ); // It's time to call it a day job_queue_node_run_EXIT_callback( node ); job_queue_change_node_status(job_queue, node, JOB_QUEUE_IS_KILLED); } job_list_unlock(job_queue->job_list ); arg_pack_free( arg_pack ); return NULL; }
static void * job_queue_run_DONE_callback( void * arg ) { arg_pack_type * arg_pack = arg_pack_safe_cast( arg ); job_queue_type * job_queue = arg_pack_iget_ptr( arg_pack , 0 ); int queue_index = arg_pack_iget_int( arg_pack , 1 ); job_list_get_rdlock( job_queue->job_list ); { job_queue_node_type * node = job_list_iget_job( job_queue->job_list , queue_index ); bool OK = job_queue_check_node_status_files( job_queue , node ); if (OK) OK = job_queue_node_run_DONE_callback( node ); if (OK) job_queue_change_node_status( job_queue , node , JOB_QUEUE_SUCCESS ); else job_queue_change_node_status( job_queue , node , JOB_QUEUE_EXIT ); job_queue_node_free_driver_data( node , job_queue->driver ); } job_list_unlock(job_queue->job_list ); arg_pack_free( arg_pack ); return NULL; }
void * test_argpack_is_stringlist( void * arg ) { arg_pack_type * arg_pack = arg_pack_safe_cast( arg ); void * arg0 = arg_pack_iget_ptr( arg_pack , 0 ); test_assert_true( stringlist_is_instance( arg0 ) ); return NULL; }
void call_add_job( void * arg ) { arg_pack_type * arg_pack = arg_pack_safe_cast( arg ); job_list_type * job_list = arg_pack_iget_ptr( arg_pack , 0 ); job_queue_node_type * node = arg_pack_iget_ptr( arg_pack , 1 ); job_list_add_job( job_list , node ); }
void enkf_tui_run_manual_load__( void * arg ) { enkf_main_type * enkf_main = enkf_main_safe_cast( arg ); enkf_fs_type * fs = enkf_main_get_fs( enkf_main ); const int last_report = -1; const int ens_size = enkf_main_get_ensemble_size( enkf_main ); int step1,step2; bool_vector_type * iactive = bool_vector_alloc( 0 , false ); run_mode_type run_mode = ENSEMBLE_EXPERIMENT; enkf_main_init_run(enkf_main , run_mode); /* This is ugly */ step1 = 0; step2 = last_report; /** Observe that for the summary data it will load all the available data anyway. */ { char * prompt = util_alloc_sprintf("Which realizations to load (Ex: 1,3-5) <Enter for all> [M to return to menu] : [ensemble size:%d] : " , ens_size); char * select_string; util_printf_prompt(prompt , PROMPT_LEN , '=' , "=> "); select_string = util_alloc_stdin_line(); enkf_tui_util_sscanf_active_list( iactive , select_string , ens_size ); util_safe_free( select_string ); free( prompt ); } if (bool_vector_count_equal( iactive , true )) { int iens; arg_pack_type ** arg_list = util_calloc( ens_size , sizeof * arg_list ); thread_pool_type * tp = thread_pool_alloc( 4 , true ); /* num_cpu - HARD coded. */ for (iens = 0; iens < ens_size; iens++) { arg_pack_type * arg_pack = arg_pack_alloc(); arg_list[iens] = arg_pack; if (bool_vector_iget(iactive , iens)) { enkf_state_type * enkf_state = enkf_main_iget_state( enkf_main , iens ); arg_pack_append_ptr( arg_pack , enkf_state); /* 0: */ arg_pack_append_ptr( arg_pack , fs ); /* 1: */ arg_pack_append_int( arg_pack , step1 ); /* 2: This will be the load start parameter for the run_info struct. */ arg_pack_append_int( arg_pack , step1 ); /* 3: Step1 */ arg_pack_append_int( arg_pack , step2 ); /* 4: Step2 For summary data it will load the whole goddamn thing anyway.*/ arg_pack_append_bool( arg_pack , true ); /* 5: Interactive */ arg_pack_append_owned_ptr( arg_pack , stringlist_alloc_new() , stringlist_free__); /* 6: List of interactive mode messages. */ thread_pool_add_job( tp , enkf_state_load_from_forward_model_mt , arg_pack); } } thread_pool_join( tp ); thread_pool_free( tp ); printf("\n"); { qc_module_type * qc_module = enkf_main_get_qc_module( enkf_main ); runpath_list_type * runpath_list = qc_module_get_runpath_list( qc_module ); for (iens = 0; iens < ens_size; iens++) { if (bool_vector_iget(iactive , iens)) { const enkf_state_type * state = enkf_main_iget_state( enkf_main , iens ); runpath_list_add( runpath_list , iens , enkf_state_get_run_path( state ) , enkf_state_get_eclbase( state )); } } qc_module_export_runpath_list( qc_module ); } for (iens = 0; iens < ens_size; iens++) { if (bool_vector_iget(iactive , iens)) { stringlist_type * msg_list = arg_pack_iget_ptr( arg_list[iens] , 6 ); if (stringlist_get_size( msg_list )) enkf_tui_display_load_msg( iens , msg_list ); } } for (iens = 0; iens < ens_size; iens++) arg_pack_free( arg_list[iens]); free( arg_list ); } bool_vector_free( iactive ); }