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 enkf_main_export_runpath_file(enkf_main_type * enkf_main, const int_vector_type * realizations, const int_vector_type * iterations) { ecl_config_type * ecl_config = enkf_main_get_ecl_config(enkf_main); const model_config_type * model_config = enkf_main_get_model_config(enkf_main); const char * basename_fmt = ecl_config_get_eclbase(ecl_config); const char * runpath_fmt = model_config_get_runpath_as_char(model_config); const qc_module_type * qc_module = enkf_main_get_qc_module( enkf_main ); runpath_list_type * runpath_list = runpath_list_alloc( qc_module_get_runpath_list_file( qc_module )); for (int iter = 0; iter < int_vector_size(iterations); ++iter) { for (int iens = 0; iens < int_vector_size(realizations); ++iens) { int iter_value = int_vector_iget(iterations, iter); int iens_value = int_vector_iget(realizations, iens); char * basename; char * runpath; if (basename_fmt) basename = util_alloc_sprintf(basename_fmt, iens_value); else basename = util_alloc_sprintf("--%d", iens_value); if (model_config_runpath_requires_iter(model_config)) runpath = util_alloc_sprintf(runpath_fmt, iens_value, iter_value); else runpath = util_alloc_sprintf(runpath_fmt, iens_value); runpath_list_add(runpath_list, iens_value, iter_value, runpath, basename); free(basename); free(runpath); } } runpath_list_fprintf(runpath_list); runpath_list_free(runpath_list); }
void test_runpath_list() { runpath_list_type * list = runpath_list_alloc(); test_assert_int_equal( runpath_list_size( list ) , 0 ); runpath_list_add( list , 3 , 0, "path" , "base"); runpath_list_add( list , 2 , 0, "path" , "base"); runpath_list_add( list , 1 , 0, "path" , "base"); runpath_list_add( list , 3 , 1, "path" , "base"); runpath_list_add( list , 2 , 1, "path" , "base"); runpath_list_add( list , 1 , 1, "path" , "base"); test_assert_int_equal( runpath_list_size( list ) , 6 ); test_assert_int_equal( runpath_list_iget_iens( list , 0 ) , 3 ); test_assert_int_equal( runpath_list_iget_iens( list , 2 ) , 1 ); test_assert_int_equal( runpath_list_iget_iter( list , 3 ) , 1 ); runpath_list_sort( list ); test_assert_int_equal( runpath_list_iget_iens( list , 0 ) , 1 ); test_assert_int_equal( runpath_list_iget_iens( list , 4 ) , 3 ); runpath_list_clear( list ); test_assert_int_equal( runpath_list_size( list ) , 0 ); test_assert_string_equal( runpath_list_get_line_fmt( list ) , RUNPATH_LIST_DEFAULT_LINE_FMT ); { const char * other_line = "%d %s %s"; runpath_list_set_line_fmt( list , other_line ); test_assert_string_equal( runpath_list_get_line_fmt( list ) , other_line ); } runpath_list_set_line_fmt( list , NULL ); test_assert_string_equal( runpath_list_get_line_fmt( list ) , RUNPATH_LIST_DEFAULT_LINE_FMT ); { const int block_size = 100; const int threads = 100; thread_pool_type * tp = thread_pool_alloc( threads , true ); int it; for (it = 0; it < threads; it++) { int iens_offset = it * block_size; arg_pack_type * arg_pack = arg_pack_alloc(); arg_pack_append_ptr( arg_pack , list ); arg_pack_append_int( arg_pack , iens_offset ); arg_pack_append_int( arg_pack , block_size ); thread_pool_add_job( tp , add_pathlist , arg_pack ); } thread_pool_join( tp ); test_assert_int_equal( runpath_list_size( list ) , block_size * threads ); runpath_list_sort( list ); { int iens; for (iens = 0; iens < block_size * threads; iens++) test_assert_int_equal( runpath_list_iget_iens( list , iens ) , iens ); } { test_work_area_type * work_area = test_work_area_alloc("enkf_runpath_list" ); const char *filename = "runpath_list.txt"; { FILE * stream = util_fopen( filename, "w"); runpath_list_fprintf( list , stream ); fclose( stream ); } { int file_iens; int file_iter; char file_path[256]; char file_base[256]; int iens; FILE * stream = util_fopen( filename, "r"); for (iens = 0; iens < threads * block_size; iens++) { int fscanf_return = fscanf( stream , "%d %s %s %d" , &file_iens , file_path , file_base, &file_iter); test_assert_int_equal(fscanf_return, 4 ); test_assert_int_equal( file_iens , iens ); test_assert_int_equal( file_iter , 0 ); } fclose( stream ); } test_work_area_free( work_area ); } } runpath_list_free( list ); }
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 ); }
void enkf_tui_run_manual_load__( void * arg ) { enkf_main_type * enkf_main = enkf_main_safe_cast( arg ); const int ens_size = enkf_main_get_ensemble_size( enkf_main ); bool_vector_type * iactive = bool_vector_alloc( 0 , false ); run_mode_type run_mode = ENSEMBLE_EXPERIMENT; int iter = 0; enkf_main_init_run(enkf_main , iactive , run_mode , INIT_NONE); /* This is ugly */ { 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 ); } { const model_config_type * model_config = enkf_main_get_model_config( enkf_main ); if (model_config_runpath_requires_iter( model_config )) { const char * prompt = "Which iteration to load from [0...?) : "; char * input; bool OK; util_printf_prompt(prompt , PROMPT_LEN , '=' , "=> "); input = util_alloc_stdin_line(); if (input == NULL) return; OK = util_sscanf_int( input , &iter ); free( input ); if (!OK) return; } } if (bool_vector_count_equal( iactive , true )) { stringlist_type ** realizations_msg_list = util_calloc( ens_size , sizeof * realizations_msg_list ); int iens = 0; for (; iens < ens_size; ++iens) { realizations_msg_list[iens] = stringlist_alloc_new(); } enkf_main_load_from_forward_model(enkf_main, iter , iactive, realizations_msg_list); { 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) { stringlist_type * msg_list = realizations_msg_list[iens]; if (bool_vector_iget(iactive, iens)) { if (stringlist_get_size( msg_list )) { enkf_tui_display_load_msg( iens , msg_list ); } } stringlist_free(msg_list); } free(realizations_msg_list); } bool_vector_free( iactive ); }