47 throw FLANNException(
"Unsupported type for IO operations");
51 hid_t get_hdf5_type<char>() {
return H5T_NATIVE_CHAR; }
53 hid_t get_hdf5_type<unsigned char>() {
return H5T_NATIVE_UCHAR; }
55 hid_t get_hdf5_type<short int>() {
return H5T_NATIVE_SHORT; }
57 hid_t get_hdf5_type<unsigned short int>() {
return H5T_NATIVE_USHORT; }
59 hid_t get_hdf5_type<int>() {
return H5T_NATIVE_INT; }
61 hid_t get_hdf5_type<unsigned int>() {
return H5T_NATIVE_UINT; }
63 hid_t get_hdf5_type<long>() {
return H5T_NATIVE_LONG; }
65 hid_t get_hdf5_type<unsigned long>() {
return H5T_NATIVE_ULONG; }
67 hid_t get_hdf5_type<float>() {
return H5T_NATIVE_FLOAT; }
69 hid_t get_hdf5_type<double>() {
return H5T_NATIVE_DOUBLE; }
71 hid_t get_hdf5_type<long double>() {
return H5T_NATIVE_LDOUBLE; }
75 #define CHECK_ERROR(x,y) if ((x)<0) throw FLANNException((y));
81 #if H5Eset_auto_vers == 2
82 H5Eset_auto( H5E_DEFAULT,
NULL,
NULL );
89 file_id = H5Fopen(
filename.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
91 file_id = H5Fcreate(
filename.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
96 dimsf[0] = dataset.
rows;
97 dimsf[1] = dataset.
cols;
99 hid_t space_id = H5Screate_simple(2, dimsf,
NULL);
100 hid_t memspace_id = H5Screate_simple(2, dimsf,
NULL);
103 #if H5Dcreate_vers == 2
104 dataset_id = H5Dcreate2(file_id,
name.c_str(), get_hdf5_type<T>(), space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
106 dataset_id = H5Dcreate(file_id,
name.c_str(), get_hdf5_type<T>(), space_id, H5P_DEFAULT);
110 #if H5Dopen_vers == 2
111 dataset_id = H5Dopen2(file_id,
name.c_str(), H5P_DEFAULT);
113 dataset_id = H5Dopen(file_id,
name.c_str());
116 CHECK_ERROR(dataset_id,
"Error creating or opening dataset in file.");
118 status = H5Dwrite(dataset_id, get_hdf5_type<T>(), memspace_id, space_id, H5P_DEFAULT, dataset.
ptr() );
121 H5Sclose(memspace_id);
123 H5Dclose(dataset_id);
133 hid_t file_id = H5Fopen(
filename.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
137 #if H5Dopen_vers == 2
138 dataset_id = H5Dopen2(file_id,
name.c_str(), H5P_DEFAULT);
140 dataset_id = H5Dopen(file_id,
name.c_str());
142 CHECK_ERROR(dataset_id,
"Error opening dataset in file.");
144 hid_t space_id = H5Dget_space(dataset_id);
147 H5Sget_simple_extent_dims(space_id, dims_out,
NULL);
149 dataset =
flann::Matrix<T>(
new T[dims_out[0]*dims_out[1]], dims_out[0], dims_out[1]);
151 status = H5Dread(dataset_id, get_hdf5_type<T>(), H5S_ALL, H5S_ALL, H5P_DEFAULT, dataset[0]);
155 H5Dclose(dataset_id);
173 MPI_Comm comm = MPI_COMM_WORLD;
174 MPI_Info info = MPI_INFO_NULL;
176 int mpi_size, mpi_rank;
177 MPI_Comm_size(comm, &mpi_size);
178 MPI_Comm_rank(comm, &mpi_rank);
182 hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS);
183 H5Pset_fapl_mpio(plist_id, comm, info);
184 hid_t file_id = H5Fopen(
filename.c_str(), H5F_ACC_RDWR, plist_id);
188 #if H5Dopen_vers == 2
189 dataset_id = H5Dopen2(file_id,
name.c_str(), H5P_DEFAULT);
191 dataset_id = H5Dopen(file_id,
name.c_str());
193 CHECK_ERROR(dataset_id,
"Error opening dataset in file.");
195 hid_t space_id = H5Dget_space(dataset_id);
197 H5Sget_simple_extent_dims(space_id, dims,
NULL);
202 hsize_t item_cnt = dims[0]/mpi_size+(dims[0]%mpi_size==0 ? 0 : 1);
203 hsize_t cnt = (mpi_rank<mpi_size-1 ? item_cnt : dims[0]-item_cnt*(mpi_size-1));
207 offset[0] = mpi_rank*item_cnt;
210 hid_t memspace_id = H5Screate_simple(2,
count,
NULL);
216 plist_id = H5Pcreate(H5P_DATASET_XFER);
218 status = H5Dread(dataset_id, get_hdf5_type<T>(), memspace_id, space_id, plist_id, dataset[0]);
223 H5Sclose(memspace_id);
224 H5Dclose(dataset_id);
#define CHECK_ERROR(x, y)
void save_to_file(const flann::Matrix< T > &dataset, const std::string &filename, const std::string &name)
void load_from_file(flann::Matrix< T > &dataset, const std::string &filename, const std::string &name)