steven-varga / h5cpp

C++17 templates between [stl::vector | armadillo | eigen3 | ublas | blitz++] and HDF5 datasets
http://h5cpp.org
Other
140 stars 32 forks source link

Eigen example results in HDF5 errors #75

Open Svalorzen opened 2 years ago

Svalorzen commented 2 years ago

I've just finished setting up h5cpp and I'm trying the examples on this page.

The basics.cpp example seems to work fine, but I cannot get the eigen3.cpp example to work. I get HDF5 errors unfortunately.

This is what happens if I run the example as-is:

HDF5-DIAG: Error detected in HDF5 (1.10.4) thread 140505354843968:
  #000: ../../../src/H5Dio.c line 336 in H5Dwrite(): can't write data
    major: Dataset
    minor: Write failed
  #001: ../../../src/H5Dio.c line 683 in H5D__write(): unable to set up type info
    major: Dataset
    minor: Unable to initialize object
  #002: ../../../src/H5Dio.c line 968 in H5D__typeinfo_init(): not a datatype
    major: Invalid arguments to routine
    minor: Inappropriate type
terminate called after throwing an instance of 'h5::error::io::dataset::write'
  what():  /home/svalorzen/Tests/cpp/h5/h5cpp/h5cpp/H5Dwrite.hpp line#  27 : couldn't write dataset...
Aborted (core dumped)

After this the linalg.h5 file is created, but cannot be opened with another tool.

If instead I comment most of the file, and I simply try to run the fixed/compile time examples (replacing H5F_ACC_RDWR with H5F_ACC_TRUNC, I get this:

HDF5-DIAG: Error detected in HDF5 (1.10.4) thread 140167186298688:
  #000: ../../../src/H5F.c line 495 in H5Fopen(): invalid file open flags
    major: Invalid arguments to routine
    minor: Bad value
terminate called after throwing an instance of 'h5::error::io::file::open'
  what():  /home/svalorzen/Tests/cpp/h5/h5cpp/h5cpp/H5Fopen.hpp line#  29 : opening hdf5 container failed...
Aborted (core dumped)

This is my CMake setup:

cmake_minimum_required(VERSION 3.1.0) 
PROJECT (main)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(EIGEN_VERSION_REQUIRED 3.2.92)

find_package(HDF5 REQUIRED)
include_directories(${HDF5_INCLUDE_DIRS})

find_package(Eigen3 ${EIGEN_VERSION_REQUIRED} REQUIRED)
include_directories(SYSTEM ${EIGEN3_INCLUDE_DIR})

add_subdirectory(./h5cpp)
include_directories(SYSTEM ./h5cpp/)

add_executable( main main.cpp )

target_link_libraries( main ${HDF5_CXX_LIBRARIES} ${HDF5_LIBRARIES})

and CMake output:

-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- HDF5: Using hdf5 compiler wrapper to determine C configuration
-- Found HDF5: /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so;/usr/lib/x86_64-linux-gnu/libpthread.so;/usr/lib/x86_64-linux-gnu/libsz.so;/usr/lib/x86_64-linux-gnu/libz.so;/usr/lib/x86_64-linux-gnu/libdl.so;/usr/lib/x86_64-linux-gnu/libm.so (found version "1.10.4")  
-- H5CPP 1.10.4.6 matches with minimum required HDF5 v1.10.4
-- Found MPI_C: /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi.so (found version "3.1") 
-- Found MPI_CXX: /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi_cxx.so (found version "3.1") 
-- Found MPI: TRUE (found version "3.1")  
-- Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY) 
-- Install directory: /usr/local/include
-- Configuring done
-- Generating done
-- Build files have been written to: /home/svalorzen/Tests/cpp/h5/build

Any ideas what I'm doing wrong?

steven-varga commented 2 years ago

Thanks for the report: I could replicate the issue.

My suggestion is to clone this repository then git checkout v1.10.4-6; I also installed eigen 3.3.7-2 with sudo apt install libeigen3-dev on an ubuntu 20.04LTS based linux mint. The Unix makefile expects Eigen3 in /usr/include/eigen3 which can be adjusted to your system. Running make eigen3 from examples/linalg did the right thing.

Alternatively from the h5cpp/examples directory run cmake . && make to compile the examples, then run ./examples-eigen3 Let me know either here or on the HDF5 C++ forum if the above solved the problem. best: steve

Svalorzen commented 2 years ago

Thanks, this fixed it :)