Exemplo n.º 1
0
void test_filename() {
  runpath_list_type * list = runpath_list_alloc("DefaultFile");
  test_assert_string_equal( "DefaultFile" , runpath_list_get_export_file(list));
  runpath_list_set_export_file( list , "/tmp/file.txt");
  test_assert_string_equal( "/tmp/file.txt" , runpath_list_get_export_file(list));
  runpath_list_free( list );
}
Exemplo n.º 2
0
hook_manager_type * hook_manager_alloc( ert_workflow_list_type * workflow_list , const char * path ) {
  hook_manager_type * hook_manager = util_malloc( sizeof * hook_manager );
  hook_manager->hook_workflow = hook_workflow_alloc(path);
  hook_manager->runpath_list = runpath_list_alloc( NULL );
  hook_manager->workflow_list = workflow_list;
  hook_manager_set_runpath_list_file( hook_manager, NULL, RUNPATH_LIST_FILE );

  /* Deprecated stuff */
  hook_manager->post_hook_workflow = hook_workflow_alloc(path);
  hook_manager->path = NULL;
  hook_manager_set_path( hook_manager , path );
  return hook_manager;
}
Exemplo n.º 3
0
qc_module_type * qc_module_alloc( ert_workflow_list_type * workflow_list , const char * qc_path ) {
  qc_module_type * qc_module = util_malloc( sizeof * qc_module );
  qc_module->qc_workflow = NULL;
  qc_module->qc_path = NULL;
  qc_module->workflow_list = workflow_list;
  qc_module->runpath_list = runpath_list_alloc();
  qc_module->runpath_list_file = NULL;
  qc_module_set_path( qc_module , qc_path );
  {
    char * cwd = util_alloc_cwd();
    char * runpath_list_file = util_alloc_filename( cwd , RUNPATH_LIST_FILE , NULL);

    qc_module_set_runpath_list_file( qc_module , runpath_list_file );

    free( runpath_list_file );
    free( cwd );
  }
  return qc_module;
}
Exemplo n.º 4
0
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);
}
Exemplo n.º 5
0
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 );
}