tatami_hdf5
tatami bindings for HDF5-backed matrices
Loading...
Searching...
No Matches
serialize.hpp
Go to the documentation of this file.
1#ifndef TATAMI_HDF5_SERIALIZE_HPP
2#define TATAMI_HDF5_SERIALIZE_HPP
3
9#ifndef TATAMI_HDF5_PARALLEL_LOCK
10#include "subpar/subpar.hpp"
11#ifndef SUBPAR_USES_OPENMP_RANGE
12#include <mutex>
13#include <thread>
14namespace tatami_hdf5 {
15// We put this in a separate function instead of a static function variable
16// inside serialize(), as we would get a different mutex for each instance
17// of serialize() created with a different Function_.
18inline auto& get_default_hdf5_lock() {
19 static std::mutex hdf5_lock;
20 return hdf5_lock;
21}
22}
23#endif
24#endif
25
26namespace tatami_hdf5 {
27
44template<class Function_>
45void serialize(Function_ f) {
46#ifdef TATAMI_HDF5_PARALLEL_LOCK
47 TATAMI_HDF5_PARALLEL_LOCK(f);
48#else
49#ifdef SUBPAR_USES_OPENMP_RANGE
50 #pragma omp critical(hdf5)
51 {
52 f();
53 }
54#else
55 auto& h5lock = get_default_hdf5_lock();
56 std::lock_guard<std::mutex> thing(h5lock);
57 f();
58#endif
59#endif
60}
61
62}
63
64#endif
Representations for matrix data in HDF5 files.
Definition CompressedSparseMatrix.hpp:23
void serialize(Function_ f)
Definition serialize.hpp:45