int main( int argc , char ** argv) { const char * ptr1 = "Pointer1"; const char * ptr2 = "Pointer2"; arg_pack_type * arg_pack = arg_pack_alloc(); arg_pack_append_const_ptr( arg_pack , ptr1 ); arg_pack_append_const_ptr( arg_pack , ptr2 ); test_assert_ptr_equal( ptr1 , arg_pack_iget_const_ptr( arg_pack , 0 )); test_assert_ptr_equal( ptr2 , arg_pack_iget_const_ptr( arg_pack , 1 )); exit(0); }
void enkf_main_initialize_from_scratch_with_bool_vector(enkf_main_type * enkf_main , const stringlist_type * param_list ,const bool_vector_type * iens_mask , init_mode_type init_mode) { int num_cpu = 4; int ens_size = enkf_main_get_ensemble_size( enkf_main ); thread_pool_type * tp = thread_pool_alloc( num_cpu , true ); arg_pack_type ** arg_list = util_calloc( ens_size , sizeof * arg_list ); int i; int iens; for (iens = 0; iens < ens_size; iens++) { arg_list[iens] = arg_pack_alloc(); if (bool_vector_safe_iget(iens_mask , iens)) { arg_pack_append_ptr( arg_list[iens] , enkf_main ); arg_pack_append_const_ptr( arg_list[iens] , param_list ); arg_pack_append_int( arg_list[iens] , iens ); arg_pack_append_int( arg_list[iens] , init_mode ); thread_pool_add_job( tp , enkf_main_initialize_from_scratch_mt , arg_list[iens]); } } thread_pool_join( tp ); for (i = 0; i < ens_size; i++) { arg_pack_free( arg_list[i] ); } free( arg_list ); thread_pool_free( tp ); }
void matrix_inplace_matmul_mt2(matrix_type * A, const matrix_type * B , thread_pool_type * thread_pool){ int num_threads = thread_pool_get_max_running( thread_pool ); arg_pack_type ** arglist = util_malloc( num_threads * sizeof * arglist ); int it; thread_pool_restart( thread_pool ); { int rows = matrix_get_rows( A ) / num_threads; int rows_mod = matrix_get_rows( A ) % num_threads; int row_offset = 0; for (it = 0; it < num_threads; it++) { int row_size; arglist[it] = arg_pack_alloc(); row_size = rows; if (it < rows_mod) row_size += 1; arg_pack_append_int(arglist[it] , row_offset ); arg_pack_append_int(arglist[it] , row_size ); arg_pack_append_ptr(arglist[it] , A ); arg_pack_append_const_ptr(arglist[it] , B ); thread_pool_add_job( thread_pool , matrix_inplace_matmul_mt__ , arglist[it]); row_offset += row_size; } } thread_pool_join( thread_pool ); for (it = 0; it < num_threads; it++) arg_pack_free( arglist[it] ); free( arglist ); }
void enkf_main_initialize_from_scratch(enkf_main_type * enkf_main , const stringlist_type * param_list , int iens1 , int iens2, init_mode_enum init_mode) { int num_cpu = 4; thread_pool_type * tp = thread_pool_alloc( num_cpu , true ); int ens_sub_size = (iens2 - iens1 + 1) / num_cpu; arg_pack_type ** arg_list = util_calloc( num_cpu , sizeof * arg_list ); int i; printf("Setting up ensemble members from %d to %d", iens1, iens2); if (init_mode == INIT_CONDITIONAL) { printf(" using conditional initialization (keep existing parameter values).\n"); } else if (init_mode == INIT_FORCE) { printf(" using forced initialization (initialize from scratch).\n"); } else if (init_mode == INIT_NONE) { printf(" not initializing at all.\n"); } fflush( stdout ); for (i = 0; i < num_cpu; i++) { arg_list[i] = arg_pack_alloc(); arg_pack_append_ptr( arg_list[i] , enkf_main ); arg_pack_append_const_ptr( arg_list[i] , param_list ); { int start_iens = i * ens_sub_size; int end_iens = start_iens + ens_sub_size; if (i == (num_cpu - 1)){ end_iens = iens2 + 1; /* Input is upper limit inclusive. */ if(ens_sub_size == 0) start_iens = iens1; /* Don't necessarily want to start from zero when ens_sub_size = 0*/ } arg_pack_append_int( arg_list[i] , start_iens ); arg_pack_append_int( arg_list[i] , end_iens ); } arg_pack_append_int( arg_list[i] , init_mode ); thread_pool_add_job( tp , enkf_main_initialize_from_scratch_mt , arg_list[i]); } thread_pool_join( tp ); for (i = 0; i < num_cpu; i++) arg_pack_free( arg_list[i] ); free( arg_list ); thread_pool_free( tp ); printf("Done setting up ensemble.\n"); }