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

Using H5Z-ZFP static library #92

Open
houjun opened this issue Sep 28, 2022 · 10 comments
Open

Using H5Z-ZFP static library #92

houjun opened this issue Sep 28, 2022 · 10 comments

Comments

@houjun
Copy link

houjun commented Sep 28, 2022

Hi, I'm trying to include H5Z_ZFP static library to SW4. I'm able to compile ZFP (v1.0.0) and H5Z-ZFP (v1.1.0).

I added the following to SW4's CMakeList:

CMAKE_POLICY(SET CMP0028 NEW)
...
OPTION(USE_ZFP "Use ZFP compression." OFF)
IF(USE_ZFP)
    SET(H5Z_ZFP_USE_STATIC_LIBS ON)
    FIND_PACKAGE(H5Z_ZFP 1.1.0 CONFIG)
    ADD_DEFINITIONS(-DUSE_ZFP)
ENDIF (USE_ZFP)
...
IF(USE_ZFP)
    TARGET_LINK_LIBRARIES(sw4 PRIVATE h5z_zfp::h5z_zfp)
ENDIF (USE_ZFP)

But when I run the cmake command in SW4:

export H5Z_ZFP_DIR=/global/cfs/cdirs/m3354/tang/H5Z-ZFP-1.1.0/build/
cmake -DUSE_HDF5=ON -DUSE_ZFP=ON ..

I got the following error message:

-- Could NOT find H5Z_ZFP: missing: H5Z_ZFP_LIBRARY H5Z_ZFP_INCLUDE_DIR (found /global/cfs/cdirs/m3354/tang/H5Z-ZFP-1.1.0/build/install/lib/cmake/h5z_zfp/h5z_zfp-config.cmake (found suitable version "1.1.0", minimum required is "1.1.0"))
CMake Warning at CMakeLists.txt:78 (FIND_PACKAGE):
  Found package configuration file:

    /global/cfs/cdirs/m3354/tang/H5Z-ZFP-1.1.0/build/install/lib/cmake/h5z_zfp/h5z_zfp-config.cmake

  but it set H5Z_ZFP_FOUND to FALSE so package "H5Z_ZFP" is considered to be
  NOT FOUND.

-- Configuring done
CMake Error at CMakeLists.txt:167 (ADD_EXECUTABLE):
  Target "sw4" links to target "h5z_zfp::h5z_zfp" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

Any idea what is going on?

@markcmiller86
Copy link
Member

@houjun my CMake expertise is not that great...particularly CMake's FIND_PACKAGE functionality and behavior. I suspect its correct operation depends on H5Z-ZFP's CMake's logic having done the right thing when installing. If practical, can you attach here the h5z-zfp-config.cmake (you can either compress it or give it a fake extension that GitHub accepts). Likewise, can you run ls -Rl on /global/cfs/cdirs/m3354/tang/H5Z-ZFP-1.1.0/build/install and report the results for that here?

@houjun
Copy link
Author

houjun commented Sep 29, 2022

@markcmiller86 Here it is:

# h5z_zfp-config.cmake
# --------------------
#
# Finds the H5Z_ZFP library, specify the starting search path in H5Z_ZFP_ROOT
#
# Static vs. shared
# -----------------
# To make use of the static library instead of the shared one, one needs
# to set the variable H5Z_ZFP_USE_STATIC_LIBS to ON before calling find_package.
# Example:
#   set(H5Z_ZFP_USE_STATIC_LIBS ON)
#   find_package(H5Z_ZFP REQUIRED CONFIG)
#
# This will define the following variables:
#
#   H5Z_ZFP_FOUND       - True if the system has the H5Z_ZFP library.
#   H5Z_ZFP_WITH_OPENMP - True if the zfp library has been built with OpenMP support.
#
# and the following imported targets:
#
#   h5z_zfp::h5z_zfp - The H5Z_ZFP library.

find_path(H5Z_ZFP_INCLUDE_DIR NAMES H5Zzfp.h DOC "H5Z_ZFP include directory")
if(H5Z_ZFP_USE_STATIC_LIBS)
  find_library(H5Z_ZFP_LIBRARY NAMES libh5zzfp.a DOC "H5Z_ZFP library")
else()
  find_library(H5Z_ZFP_LIBRARY NAMES libh5zzfp.so HINTS $ENV{H5Z_ZFP_ROOT}/plugin DOC "H5Z_ZFP library")
endif()

include(FindPackageHandleStandardArgs)
set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG "${CMAKE_CURRENT_LIST_FILE}")
find_package_handle_standard_args(H5Z_ZFP
  FOUND_VAR H5Z_ZFP_FOUND
  REQUIRED_VARS H5Z_ZFP_LIBRARY H5Z_ZFP_INCLUDE_DIR
  CONFIG_MODE
)

if(H5Z_ZFP_FOUND)
  set(HDF5_USE_STATIC_LIBRARIES ${H5Z_ZFP_USE_STATIC_LIBS})
  find_package(HDF5 MODULE REQUIRED COMPONENTS C)
  find_package(ZFP REQUIRED CONFIG)
  if(H5Z_ZFP_USE_STATIC_LIBS)
    add_library(h5z_zfp::h5z_zfp STATIC IMPORTED)
  else()
    add_library(h5z_zfp::h5z_zfp SHARED IMPORTED)
  endif()
  set_target_properties(h5z_zfp::h5z_zfp PROPERTIES
    IMPORTED_LOCATION "${H5Z_ZFP_LIBRARY}"
    INTERFACE_INCLUDE_DIRECTORIES "${H5Z_ZFP_INCLUDE_DIR}"
    INTERFACE_LINK_LIBRARIES "zfp::zfp;${HDF5_LIBRARIES}"
    LINK_LIBRARIES "zfp::zfp;${HDF5_LIBRARIES}"
  )
  set(H5Z_ZFP_WITH_OPENMP ${ZFP_WITH_OPENMP})
endif()

mark_as_advanced(
  H5Z_ZFP_INCLUDE_DIR
  H5Z_ZFP_LIBRARY
)

and for the files:

cori04:h5z_zfp$ ls -Rl  /global/cfs/cdirs/m3354/tang/H5Z-ZFP-1.1.0/build/install
/global/cfs/cdirs/m3354/tang/H5Z-ZFP-1.1.0/build/install:
total 3
drwxrws--- 2 houhun m3354 4096 Sep 28 10:45 include
drwxrws--- 3 houhun m3354 4096 Sep 28 10:45 lib
drwxrws--- 2 houhun m3354 4096 Sep 28 10:45 plugin

/global/cfs/cdirs/m3354/tang/H5Z-ZFP-1.1.0/build/install/include:
total 34
-rw-r--r-- 1 houhun m3354   122 Aug 18 11:36 H5Zzfp.h
-rw-r--r-- 1 houhun m3354   222 Aug 18 11:36 H5Zzfp_lib.h
-rw-r--r-- 1 houhun m3354  2884 Aug 18 11:36 H5Zzfp_plugin.h
-rw-r--r-- 1 houhun m3354  1077 Aug 18 11:36 H5Zzfp_props.h
-rw-r--r-- 1 houhun m3354 23265 Sep 28 10:21 h5zzfp_props_f.mod

/global/cfs/cdirs/m3354/tang/H5Z-ZFP-1.1.0/build/install/lib:
total 49
drwxrws--- 3 houhun m3354  4096 Sep 28 10:45 cmake
-rw-r--r-- 1 houhun m3354 41096 Sep 28 10:21 libh5zzfp.a

/global/cfs/cdirs/m3354/tang/H5Z-ZFP-1.1.0/build/install/lib/cmake:
total 1
drwxrws--- 2 houhun m3354 4096 Sep 28 10:45 h5z_zfp

/global/cfs/cdirs/m3354/tang/H5Z-ZFP-1.1.0/build/install/lib/cmake/h5z_zfp:
total 1
-rw-r--r-- 1 houhun m3354  494 Sep 28 10:21 h5z_zfp-config-version.cmake
-rw-r--r-- 1 houhun m3354 1938 Sep 28 10:21 h5z_zfp-config.cmake

/global/cfs/cdirs/m3354/tang/H5Z-ZFP-1.1.0/build/install/plugin:
total 560
-rwxr-xr-x 1 houhun m3354 567368 Sep 28 10:45 libh5zzfp.so

@jwsblokland
Copy link
Contributor

@houjun In the past, I made the initial implementation of the h5z_zfp-config.cmake file. I have a few questions for you.

  • Which cmake version are you using?
  • Maybe I see what the problem is. Could you set H5Z_ZFP_DIR=/global/cfs/cdirs/m3354/tang/H5Z-ZFP-1.1.0/build/install and run cmake again. Personally, I always use the policy CMP0074 and set the environment variable H5Z_ZFP_ROOT.

@houjun
Copy link
Author

houjun commented Sep 29, 2022

@jwsblokland I added CMAKE_POLICY(SET CMP0074 NEW) and set the H5Z_ZFP_DIR, but got the same issue:

cori04:build$ cmake --version
cmake version 3.22.2

cori04:build$ export H5Z_ZFP_DIR=/global/cfs/cdirs/m3354/tang/H5Z-ZFP-1.1.0/build/install
cori04:build$ cmake -DUSE_HDF5=ON  -DUSE_ZFP=ON  ..
-- The C compiler identification is Intel 19.1.2.20200623
-- The CXX compiler identification is Intel 19.1.2.20200623
-- The Fortran compiler identification is Intel 19.1.2.20200623
-- Cray Programming Environment 2.7.10 C
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/cray/pe/craype/2.6.2/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Cray Programming Environment 2.7.10 CXX
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/cray/pe/craype/2.6.2/bin/CC - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Cray Programming Environment 2.7.10 Fortran
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Check for working Fortran compiler: /opt/cray/pe/craype/2.6.2/bin/ftn - skipped
-- Found MPI_C: /opt/cray/pe/craype/2.6.2/bin/cc (found version "3.1")
-- Found MPI_CXX: /opt/cray/pe/craype/2.6.2/bin/CC (found version "3.1")
-- Found MPI_Fortran: /opt/cray/pe/craype/2.6.2/bin/ftn (found version "3.1")
-- Found MPI: TRUE (found version "3.1")
-- Found HDF5: Included by compiler wrappers (found version "1.12.1")
-- Could NOT find H5Z_ZFP: missing: H5Z_ZFP_LIBRARY H5Z_ZFP_INCLUDE_DIR (found /global/cfs/cdirs/m3354/tang/H5Z-ZFP-1.1.0/build/install/lib/cmake/h5z_zfp/h5z_zfp-config.cmake (found suitable version "1.1.0", minimum required is "1.1.0"))
CMake Warning at CMakeLists.txt:79 (FIND_PACKAGE):
  Found package configuration file:

    /global/cfs/cdirs/m3354/tang/H5Z-ZFP-1.1.0/build/install/lib/cmake/h5z_zfp/h5z_zfp-config.cmake

  but it set H5Z_ZFP_FOUND to FALSE so package "H5Z_ZFP" is considered to be
  NOT FOUND.


-- Looking for Fortran sgemm
...

@jwsblokland
Copy link
Contributor

jwsblokland commented Sep 29, 2022

Could you try setting the environment variable H5Z_ZFP_ROOT=/global/cfs/cdirs/m3354/tang/H5Z-ZFP-1.1.0/build/install in combination with using CMP0074 policy.

@markcmiller86
Copy link
Member

@houjun sorry but I hadn't realized h5z_zfp-config.cmake was already part of H5Z-ZFP. Shows how much I understand about CMake. I will try a similar exercise on my macOS system with that CMake find logic and see if it either needs some adjustment or most recent recommendation from @jwsblokland resolves it.

@houjun
Copy link
Author

houjun commented Sep 29, 2022

@jwsblokland That works, but I also have to set ZFP_DIR so that cmake can find ZFP correctly. Now the cmake process completes without errors.

But when I compile the application code, I'm getting the following error:

In file included from /global/cfs/cdirs/m3354/tang/H5Z-ZFP-1.1.0/build/install/include/H5Zzfp_lib.h(4),
                 from /global/u1/h/houhun/sw4/src/main.C(49):
/global/cfs/cdirs/m3354/tang/H5Z-ZFP-1.1.0/build/install/include/H5Zzfp_plugin.h(4): catastrophic error: cannot open source file "H5Zzfp_version.h"
  #include "H5Zzfp_version.h"
                             ^

It seems that file is not installed with H5Z_ZFP's cmake (see my previous post with the file list)

@markcmiller86
Copy link
Member

It seems that file is not installed with H5Z_ZFP's cmake (see my previous post with the file list)

@jwsblokland this I think is my fault. I can fix (along with some other issues reported by @lindstro in email to me) and cut a new release...will have to wait 'til next week though. @houjun in meantime, can you manually copy that header to the install point to correct your build?

@houjun
Copy link
Author

houjun commented Sep 29, 2022

@markcmiller86 Yes, I just tried copying that file and now the code compiles successfully, thanks for the help!

@markcmiller86 markcmiller86 self-assigned this Sep 29, 2022
@jwsblokland
Copy link
Contributor

@houjun Good to hear that now everything works.

@markcmiller86 The fix of the missing header file has been already implemented. The only thing that is missing creating a proper release of it. I would suggest for example 1.1.1 if you want to honor the semantic version scheme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants