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
10#ifndef TATAMI_HDF5_PARALLEL_LOCK
11#include "subpar/subpar.hpp"
12#ifndef SUBPAR_USES_OPENMP_RANGE
13#include <mutex>
14#include <thread>
15
19namespace tatami_hdf5 {
20// We put this in a separate function instead of a static function variable
21// inside serialize(), as we would get a different mutex for each instance
22// of serialize() created with a different Function_.
23inline auto& get_default_hdf5_lock() {
24 static std::mutex hdf5_lock;
25 return hdf5_lock;
26}
27}
31#endif
32#endif
33
34namespace tatami_hdf5 {
35
52template<class Function_>
53void serialize(Function_ f) {
54#ifdef TATAMI_HDF5_PARALLEL_LOCK
55 TATAMI_HDF5_PARALLEL_LOCK(f);
56#else
57#ifdef SUBPAR_USES_OPENMP_RANGE
58 #pragma omp critical(hdf5)
59 {
60 f();
61 }
62#else
63 auto& h5lock = get_default_hdf5_lock();
64 std::lock_guard<std::mutex> thing(h5lock);
65 f();
66#endif
67#endif
68}
69
70}
71
72#endif
Representations for matrix data in HDF5 files.
Definition CompressedSparseMatrix.hpp:24
void serialize(Function_ f)
Definition serialize.hpp:53