Skip to content

Commit

Permalink
thdat: Fix OpenMP threading.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lymia committed Aug 15, 2017
1 parent cab79f2 commit 189daa5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 6 additions & 0 deletions thdat/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
include_directories(${CMAKE_SOURCE_DIR})
add_executable(thdat thdat.c)
find_package(OpenMP)
if (OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
target_link_libraries(thdat thtk util)
link_setargv(thdat)
install(TARGETS thdat DESTINATION bin)
Expand Down
15 changes: 9 additions & 6 deletions thdat/thdat.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,9 @@ thdat_create_wrapper(

k = 0;
/* TODO: Properly indicate when insertion fails. */
#pragma omp parallel for
for (size_t i = 0; i < real_entry_count; ++i) {
ssize_t i;
#pragma omp parallel for schedule(dynamic)
for (i = 0; i < real_entry_count; ++i) {
thtk_error_t* error = NULL;
thtk_io_t* entry_stream;
off_t entry_size;
Expand Down Expand Up @@ -373,8 +374,9 @@ main(
}

if (argc > 3) {
#pragma omp parallel for
for (int a = 3; a < argc; ++a) {
ssize_t a;
#pragma omp parallel for schedule(dynamic)
for (a = 3; a < argc; ++a) {
thtk_error_t* error = NULL;
int entry_index;

Expand All @@ -398,8 +400,9 @@ main(
exit(1);
}

#pragma omp parallel for
for (ssize_t entry_index = 0; entry_index < entry_count; ++entry_index) {
ssize_t entry_index;
#pragma omp parallel for schedule(dynamic)
for (entry_index = 0; entry_index < entry_count; ++entry_index) {
thtk_error_t* error = NULL;
if (!thdat_extract_file(state, entry_index, &error)) {
print_error(error);
Expand Down

0 comments on commit 189daa5

Please sign in to comment.