Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add THREADS check to configuration file #4746

Merged
merged 5 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 21 additions & 34 deletions HDF5Examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,53 +99,40 @@ if (H5_HAVE_PARALLEL)
INCLUDE_DIRECTORIES (${MPI_C_INCLUDE_DIRS})
endif ()

# Determine if a threading package is available on this system
option (HDF5_ENABLE_THREADS "Enable thread support" ON)
set (THREADS_PREFER_PTHREAD_FLAG ON)
find_package (Threads)
if (Threads_FOUND)
set (H5_HAVE_THREADS 1)
set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})

# Determine which threading package to use
# Comment out check for C11 threads for now, since it conflicts with the
# current --std=c99 compile flags at configuration time. When we switch to
# --std=c11, this can be uncommented.
#CHECK_INCLUDE_FILE("threads.h" HAVE_THREADS_H)
if (WIN32)
# When Win32 is available, we use those threads
set (H5_HAVE_WIN_THREADS 1)
elseif (HAVE_THREADS_H)
# When C11 threads are available, those are the top choice
set (H5_HAVE_C11_THREADS 1)
elseif (CMAKE_USE_PTHREADS_INIT)
set (H5_HAVE_PTHREAD_H 1)
else ()
message (FATAL_ERROR " **** thread support requires C11 threads, Win32 threads or Pthreads **** ")
#-----------------------------------------------------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This piece seems wrong, as it's eliminating all the macros that were previously set that show what kind of threads are found.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No that section is not needed for Examples. These changes only affect the Examples when using the library binary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see.

Then this entire section of the CMake file should be removed, since the examples don't use threading.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until we add examples that test such feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the library requires the THREADS library it still needs to be checked.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Applications that link to a threadsafe version of HDF5 don't need to make this check in their CMake builds, correct?

# Option to use threads
#-----------------------------------------------------------------------------
option (HDF_ENABLE_THREADS "Enable Threads" OFF)
# Note that HDF_ENABLE_THREADS is the CMake option for determining
# whether to enable threads in the examples. HDF5_ENABLE_THREADS
# is the CMake option determining whether HDF5 was configured with
# threads enabled.
if (HDF_ENABLE_THREADS AND HDF5_ENABLE_THREADS)
# Check for threading package
if (NOT Threads_FOUND)
set (THREADS_PREFER_PTHREAD_FLAG ON)
find_package (Threads)
if (NOT Threads_FOUND)
message (FATAL_ERROR " **** threads option requires a threading package and none was found **** ")
endif ()
endif ()

# Check for compiler support for atomic variables
CHECK_INCLUDE_FILE("stdatomic.h" HAVE_STDATOMIC_H)
if (HAVE_STDATOMIC_H)
set (H5_HAVE_STDATOMIC_H 1)
endif()
endif ()

#-----------------------------------------------------------------------------
# Option to use threadsafe
#-----------------------------------------------------------------------------
option (HDF_ENABLE_THREADSAFE "Enable Threadsafety" OFF)
option (HDF_ENABLE_THREADSAFE "Enable Thread-safety" OFF)
# Note that HDF_ENABLE_THREADSAFE is the CMake option for determining
# whether to enable thread-safety in the examples. HDF5_ENABLE_THREADSAFE
# is the CMake option determining whether HDF5 was configured with
# thread-safety enabled.
if (HDF_ENABLE_THREADSAFE AND HDF5_ENABLE_THREADSAFE)
# thread-safety enabled. HDF5_ENABLE_THREADS
# is the CMake option determining whether HDF5 was configured with
# threads enabled.
if (HDF_ENABLE_THREADSAFE AND HDF5_ENABLE_THREADSAFE AND HDF5_ENABLE_THREADS)
# Check for threading package
if (NOT Threads_FOUND)
message (FATAL_ERROR " **** thread-safety option requires a threading package and none was found **** ")
endif ()

set (H5_HAVE_THREADSAFE 1)
endif ()

set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES
Expand Down
2 changes: 1 addition & 1 deletion config/cmake/hdf5-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ if (${HDF5_PACKAGE_NAME}_ENABLE_PARALLEL)
find_package(MPI QUIET REQUIRED)
endif ()

if (${HDF5_PACKAGE_NAME}_ENABLE_THREADSAFE OR ${HDF5_PACKAGE_NAME}_ENABLE_SUBFILING_VFD)
if (${HDF5_PACKAGE_NAME}_ENABLE_THREADSAFE OR ${HDF5_PACKAGE_NAME}_ENABLE_THREADS OR ${HDF5_PACKAGE_NAME}_ENABLE_SUBFILING_VFD)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "${HDF5_PACKAGE_NAME}_ENABLE_THREADSAFE" and "${HDF5_PACKAGE_NAME}_ENABLE_SUBFILING_VFD)" components are no longer correct and should be removed.

(Leaving just ${HDF5_PACKAGE_NAME}_ENABLE_THREADS)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are they no longer correct, if they are set in the library? This file is the status of the options used to build the library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that since they require threads that is why we only need to check threads?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is only about threads, not threadsafety or subfiling.

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads QUIET REQUIRED)
endif ()
Expand Down
Loading