Skip to content

Commit 189daa5

Browse files
committed
thdat: Fix OpenMP threading.
1 parent cab79f2 commit 189daa5

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

thdat/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
include_directories(${CMAKE_SOURCE_DIR})
22
add_executable(thdat thdat.c)
3+
find_package(OpenMP)
4+
if (OPENMP_FOUND)
5+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
6+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
7+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
8+
endif()
39
target_link_libraries(thdat thtk util)
410
link_setargv(thdat)
511
install(TARGETS thdat DESTINATION bin)

thdat/thdat.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,9 @@ thdat_create_wrapper(
263263

264264
k = 0;
265265
/* TODO: Properly indicate when insertion fails. */
266-
#pragma omp parallel for
267-
for (size_t i = 0; i < real_entry_count; ++i) {
266+
ssize_t i;
267+
#pragma omp parallel for schedule(dynamic)
268+
for (i = 0; i < real_entry_count; ++i) {
268269
thtk_error_t* error = NULL;
269270
thtk_io_t* entry_stream;
270271
off_t entry_size;
@@ -373,8 +374,9 @@ main(
373374
}
374375

375376
if (argc > 3) {
376-
#pragma omp parallel for
377-
for (int a = 3; a < argc; ++a) {
377+
ssize_t a;
378+
#pragma omp parallel for schedule(dynamic)
379+
for (a = 3; a < argc; ++a) {
378380
thtk_error_t* error = NULL;
379381
int entry_index;
380382

@@ -398,8 +400,9 @@ main(
398400
exit(1);
399401
}
400402

401-
#pragma omp parallel for
402-
for (ssize_t entry_index = 0; entry_index < entry_count; ++entry_index) {
403+
ssize_t entry_index;
404+
#pragma omp parallel for schedule(dynamic)
405+
for (entry_index = 0; entry_index < entry_count; ++entry_index) {
403406
thtk_error_t* error = NULL;
404407
if (!thdat_extract_file(state, entry_index, &error)) {
405408
print_error(error);

0 commit comments

Comments
 (0)