Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

Commit

Permalink
ERT-749: Relaxed ecl_util_get_num_cpu()
Browse files Browse the repository at this point in the history
  • Loading branch information
joakim-hove committed Sep 9, 2014
1 parent e699060 commit 7564398
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
20 changes: 8 additions & 12 deletions devel/libecl/src/ecl_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1267,18 +1267,14 @@ static int ecl_util_get_num_parallel_cpu__(parser_type* parser, FILE* stream, co

{
stringlist_type * tokens = parser_tokenize_buffer( parser , buffer , true );
int i;
char * item = NULL;
for (i=0; i < stringlist_get_size( tokens ); i++) {
item = util_realloc_string_copy( item , stringlist_iget( tokens , i ));
util_strupr( item );
if (( util_string_equal( item , "DISTRIBUTED" )) ||
( util_string_equal( item , "DIST" ))) {
num_cpu = atoi( stringlist_iget( tokens , i - 1));
break;
}
}
free( item );

if (stringlist_get_size( tokens ) > 0) {
const char * num_cpu_string = stringlist_iget( tokens , 0 );
if (!util_sscanf_int( num_cpu_string , &num_cpu))
fprintf(stderr,"** Warning: failed to interpret:%s as integer - assuming one CPU\n",num_cpu_string);
} else
fprintf(stderr,"** Warning: failed to load data for PARALLEL keyword - assuming one CPU\n");

stringlist_free( tokens );
}
free( buffer );
Expand Down
3 changes: 3 additions & 0 deletions devel/libecl/tests/data/num_cpu4
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PARALLEL
4 /

4 changes: 4 additions & 0 deletions devel/libecl/tests/ecl_get_num_cpu_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ int main(int argc , char ** argv) {
const char * filename1 = argv[1];
const char * filename2 = argv[2];
const char * filename3 = argv[3];
const char * filename4 = argv[4];

int num_cpu = 4;
test_assert_int_equal(ecl_util_get_num_cpu(filename1), num_cpu);
test_assert_int_equal(ecl_util_get_num_cpu(filename2), num_cpu);
test_assert_int_equal(ecl_util_get_num_cpu(filename3), num_cpu);
test_assert_int_equal(ecl_util_get_num_cpu(filename4), num_cpu);
exit(0);

}

7 changes: 5 additions & 2 deletions devel/libecl/tests/tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,11 @@ add_test( ecl_rft_cell ${EXECUTABLE_OUTPUT_PATH}/ecl_rft_cell )

add_executable( ecl_get_num_cpu ecl_get_num_cpu_test.c )
target_link_libraries( ecl_get_num_cpu ecl test_util )
add_test( ecl_get_num_cpu ${EXECUTABLE_OUTPUT_PATH}/ecl_get_num_cpu ${PROJECT_SOURCE_DIR}/libecl/tests/data/num_cpu1 ${PROJECT_SOURCE_DIR}/libecl/tests/data/num_cpu2 ${PROJECT_SOURCE_DIR}/libecl/tests/data/num_cpu3)

add_test( ecl_get_num_cpu ${EXECUTABLE_OUTPUT_PATH}/ecl_get_num_cpu
${PROJECT_SOURCE_DIR}/libecl/tests/data/num_cpu1
${PROJECT_SOURCE_DIR}/libecl/tests/data/num_cpu2
${PROJECT_SOURCE_DIR}/libecl/tests/data/num_cpu3
${PROJECT_SOURCE_DIR}/libecl/tests/data/num_cpu4 )

add_executable( ecl_fault_block ecl_fault_block.c )
target_link_libraries( ecl_fault_block ecl test_util )
Expand Down

0 comments on commit 7564398

Please sign in to comment.