Skip to content

Commit

Permalink
save Particle<T> object in HDF5
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouyan committed Feb 2, 2015
1 parent 3923074 commit 7875908
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 15 deletions.
8 changes: 6 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Changes since v1.0.0

* Add support for [jemalloc][jemalloc] in `utility/aligned_memory.hpp`
## New features

* Support for [jemalloc][jemalloc] in `utility/aligned_memory.hpp`
* `AlignedMemory` and `AlignedAllocator` default to [jemalloc][jemalloc] if it
is available.
is available
* Store `Particle<T>` object in [HDF5][HDF5] format

[HDF5]: http://www.hdfgroup.org/HDF5/
[jemalloc]: http://www.canonware.com/jemalloc/
6 changes: 2 additions & 4 deletions example/pf/include/pf_cl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,13 @@ inline void cv_do (vsmc::Sampler<cv> &sampler, vsmc::ResampleScheme res,

#if VSMC_HAS_HDF5
sampler.initialize(argv[1]);
vsmc::hdf5store<vsmc::RowMajor, cl_float>(
sampler.particle().value(),
vsmc::hdf5store<vsmc::RowMajor, cl_float>(sampler.particle(),
argv[2] + rname + ".trace.h5", "Trace.0");
for (std::size_t i = 0; i != DataNum - 1; ++i) {
std::stringstream tss;
tss << "Trace." << (i + 1);
sampler.iterate();
vsmc::hdf5store<vsmc::RowMajor, cl_float>(
sampler.particle().value(),
vsmc::hdf5store<vsmc::RowMajor, cl_float>(sampler.particle(),
argv[2] + rname + ".trace.h5", tss.str(), true);
}
#else
Expand Down
8 changes: 4 additions & 4 deletions example/pf/include/pf_mpi_do.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ inline void cv_do (vsmc::ResampleScheme res, char **argv,

#if VSMC_HAS_HDF5
sampler.initialize(argv[1]);
vsmc::hdf5store(sampler.particle().value(),
argv[2] + rname + ".trace.h5", "Trace.0");
vsmc::hdf5store(sampler.particle(), argv[2] + rname + ".trace.h5",
"Trace.0");
for (std::size_t i = 0; i != DataNum - 1; ++i) {
std::stringstream tss;
tss << "Trace." << (i + 1);
sampler.iterate();
vsmc::hdf5store(sampler.particle().value(),
argv[2] + rname + ".trace.h5", tss.str(), true);
vsmc::hdf5store(sampler.particle(), argv[2] + rname + ".trace.h5",
tss.str(), true);
}
#else
sampler.initialize(argv[1]);
Expand Down
8 changes: 4 additions & 4 deletions example/pf/include/pf_smp_do.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ inline void cv_do (vsmc::ResampleScheme res, char **argv,
sampler.monitor("pos").name(1) = "pos.y";
#if VSMC_HAS_HDF5
sampler.initialize(argv[1]);
vsmc::hdf5store(sampler.particle().value(),
argv[2] + name + ".trace.h5", "Trace.0");
vsmc::hdf5store(sampler.particle(), argv[2] + name + ".trace.h5",
"Trace.0");
for (std::size_t i = 0; i != DataNum - 1; ++i) {
std::stringstream ss;
ss << "Trace." << (i + 1);
sampler.iterate();
vsmc::hdf5store(sampler.particle().value(),
argv[2] + name + ".trace.h5", ss.str(), true);
vsmc::hdf5store(sampler.particle(), argv[2] + name + ".trace.h5",
ss.str(), true);
}
#else
sampler.initialize(argv[1]);
Expand Down
29 changes: 28 additions & 1 deletion include/vsmc/utility/hdf5io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,33 @@ inline void hdf5store (const Sampler<T> &sampler,
&resampled[0], "Resampled");
}

/// \brief Store a Particle in the HDF5 format
/// \ingroup HDF5IO
template <typename T>
inline void hdf5store (const Particle<T> &particle,
const std::string &file_name, const std::string &data_name,
bool append = false)
{
hdf5store_list_empty(file_name, data_name, append);
hdf5store(particle.value(), file_name, data_name + "/value", true);
hdf5store_matrix<ColMajor, double>(particle.size(), 1, file_name,
data_name + "/weight", particle.weight_set().weight_data(), true);
}

/// \brief Store a Particle with StateCL value type in the HDF5 format
/// \ingroup HDF5IO
template <MatrixOrder Order, typename T, typename U>
inline void hdf5store (const Particle<U> &particle,
const std::string &file_name, const std::string &data_name,
bool append = false)
{
hdf5store_list_empty(file_name, data_name, append);
hdf5store<Order, T>(particle.value(), file_name, data_name + "/value",
append);
hdf5store_matrix<ColMajor, double>(particle.size(), 1, file_name,
data_name + "/weight", particle.weight_set().weight_data(), true);
}

/// \brief Store a StateMatrix in the HDF5 format
/// \ingroup HDF5IO
template <MatrixOrder Order, std::size_t Dim, typename T>
Expand Down Expand Up @@ -689,7 +716,7 @@ inline void hdf5store (const StateTuple<ColMajor, T, Types...> &state,
/// \brief Store a StateCL in the HDF5 format
/// \ingroup HDF5IO
template <MatrixOrder Order, typename T,
std::size_t StateSize, typename FPType, typename ID>
std::size_t StateSize, typename FPType, typename ID>
inline void hdf5store (const StateCL<StateSize, FPType, ID> &state,
const std::string &file_name, const std::string &data_name,
bool append = false)
Expand Down

0 comments on commit 7875908

Please sign in to comment.