tests_high_five_parallel.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c), 2017, Adrien Devresse <adrien.devresse@epfl.ch>
3  *
4  * Distributed under the Boost Software License, Version 1.0.
5  * (See accompanying file LICENSE_1_0.txt or copy at
6  * http://www.boost.org/LICENSE_1_0.txt)
7  *
8  */
9 
10 #include <cstdlib>
11 #include <iostream>
12 #include <string>
13 #include <typeinfo>
14 #include <vector>
15 
16 #include <highfive/H5File.hpp>
17 #include <highfive/H5DataSet.hpp>
18 #include <highfive/H5DataSpace.hpp>
19 #include <highfive/H5Group.hpp>
20 
21 #define BOOST_TEST_MAIN HighFiveTest
22 #include <boost/mpl/list.hpp>
23 #include <boost/test/included/unit_test.hpp>
24 
25 using namespace HighFive;
26 
27 int argc = boost::unit_test::framework::master_test_suite().argc;
28 char** argv = boost::unit_test::framework::master_test_suite().argv;
29 
30 struct MpiFixture {
31  MpiFixture() { MPI_Init(&argc, &argv); }
32 
33  ~MpiFixture() { MPI_Finalize(); }
34 };
35 
37 
38 typedef boost::mpl::list<int, unsigned int, long, unsigned long, unsigned char,
39  char, float, double, long long, unsigned long long>
41 
42 template <typename T>
43 struct ContentGenerate {
44  ContentGenerate(T init_val = T(0), T inc_val = T(1) + T(1) / T(10))
45  : _init(init_val), _inc(inc_val) {}
46 
47  T operator()() {
48  T ret = _init;
49  _init += _inc;
50  return ret;
51  }
52 
53  T _init, _inc;
54 };
55 
56 template <>
57 struct ContentGenerate<char> {
58  ContentGenerate() : _init('a') {}
59 
60  char operator()() {
61  char ret = _init;
62  if (++_init >= ('a' + 26))
63  _init = 'a';
64  return ret;
65  }
66 
67  char _init;
68 };
69 
70 template <>
71 struct ContentGenerate<std::string> {
73 
74  std::string operator()() {
76  std::string random_string;
77  const size_t size_string = std::rand() % 1000;
78  random_string.resize(size_string);
79  std::generate(random_string.begin(), random_string.end(), gen);
80  return random_string;
81  }
82 };
83 
84 template <typename T>
86 
87  int mpi_rank, mpi_size;
88  MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
89  MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
90 
91  typedef typename std::vector<T> Vector;
92 
93  std::ostringstream filename;
94  filename << "h5_rw_select_parallel_test_" << typeid(T).name() << "_test.h5";
95 
96  const size_t size_x = mpi_size;
97  const size_t offset_x = mpi_rank, count_x = mpi_size - mpi_rank;
98 
99  const std::string DATASET_NAME("dset");
100 
101  Vector values(size_x);
102 
103  ContentGenerate<T> generator;
104  std::generate(values.begin(), values.end(), generator);
105 
106  // Create a new file using the default property lists.
108  MPIOFileDriver(MPI_COMM_WORLD, MPI_INFO_NULL));
109 
110  DataSet dataset =
111  file.createDataSet<T>(DATASET_NAME, DataSpace::From(values));
112 
113  dataset.write(values);
114 
115  file.flush();
116 
117  // read it back
118  Vector result;
119  std::vector<size_t> offset;
120  offset.push_back(offset_x);
121  std::vector<size_t> size;
122  size.push_back(count_x);
123 
124  Selection slice = dataset.select(offset, size);
125 
126  BOOST_CHECK_EQUAL(slice.getSpace().getDimensions()[0], size_x);
127  BOOST_CHECK_EQUAL(slice.getMemSpace().getDimensions()[0], count_x);
128 
129  slice.read(result);
130 
131  BOOST_CHECK_EQUAL(result.size(), count_x);
132 
133  for (size_t i = offset_x; i < count_x; ++i) {
134  // std::cout << result[i] << " ";
135  BOOST_CHECK_EQUAL(values[i + offset_x], result[i]);
136  }
137 }
138 
140 
141  selectionArraySimpleTestParallel<T>();
142 }
size_x
const size_t size_x
Definition: boost_multi_array_2D.cpp:21
ContentGenerate< std::string >::ContentGenerate
ContentGenerate()
Definition: tests_high_five_parallel.cpp:72
HighFive::Selection
Selection: represent a view on a slice/part of a dataset.
Definition: H5Selection.hpp:27
ContentGenerate< char >
Definition: tests_high_five_base.cpp:91
HighFive::DataSpace::getDimensions
std::vector< size_t > getDimensions() const
getDimensions
Definition: H5Dataspace_misc.hpp:104
H5File.hpp
numerical_test_types
boost::mpl::list< int, unsigned int, long, unsigned long, unsigned char, char, float, double, long long, unsigned long long, complex > numerical_test_types
Definition: tests_high_five_base.cpp:45
HighFive::SliceTraits::read
void read(T &array) const
Definition: H5Slice_traits_misc.hpp:149
ContentGenerate< char >::ContentGenerate
ContentGenerate()
Definition: tests_high_five_parallel.cpp:58
HighFive::DataSpace::From
static DataSpace From(const ScalarValue &scalar_value)
Definition: H5Dataspace_misc.hpp:130
H5DataSet.hpp
H5DataSpace.hpp
HighFive::SliceTraits::select
Selection select(const std::vector< size_t > &offset, const std::vector< size_t > &count, const std::vector< size_t > &stride=std::vector< size_t >()) const
Definition: H5Slice_traits_misc.hpp:66
HighFive::SliceTraits::write
void write(const T &buffer)
Definition: H5Slice_traits_misc.hpp:210
H5Group.hpp
ContentGenerate
Definition: tests_high_five_base.cpp:72
MpiFixture::MpiFixture
MpiFixture()
Definition: tests_high_five_parallel.cpp:31
ContentGenerate< char >::operator()
char operator()()
Definition: tests_high_five_parallel.cpp:60
ContentGenerate< std::string >::operator()
std::string operator()()
Definition: tests_high_five_parallel.cpp:74
HighFive::File::Create
static const int Create
Open flag: Create non existing file.
Definition: H5File.hpp:40
scripts.normalize_multiple.filename
filename
Definition: normalize_multiple.py:60
scripts.create_png.values
values
Definition: create_png.py:26
BOOST_GLOBAL_FIXTURE
BOOST_GLOBAL_FIXTURE(MpiFixture)
HighFive::File
File class.
Definition: H5File.hpp:25
HighFive::Selection::getMemSpace
DataSpace getMemSpace() const
getMemSpace
Definition: H5Selection_misc.hpp:23
BOOST_AUTO_TEST_CASE_TEMPLATE
BOOST_AUTO_TEST_CASE_TEMPLATE(selectionArraySimple, T, numerical_test_types)
Definition: tests_high_five_parallel.cpp:139
argc
int argc
Definition: tests_high_five_parallel.cpp:27
file
FILE * file
Definition: arithmeticencoder.cpp:77
MpiFixture
Definition: tests_high_five_parallel.cpp:30
ContentGenerate::operator()
T operator()()
Definition: tests_high_five_parallel.cpp:47
ContentGenerate::ContentGenerate
ContentGenerate(T init_val=T(0), T inc_val=T(1)+T(1)/T(10))
Definition: tests_high_five_parallel.cpp:44
std
Definition: HalfEdge.hpp:124
MpiFixture::~MpiFixture
~MpiFixture()
Definition: tests_high_five_parallel.cpp:33
HighFive::Selection::getSpace
DataSpace getSpace() const
getSpace
Definition: H5Selection_misc.hpp:21
numerical_test_types
boost::mpl::list< int, unsigned int, long, unsigned long, unsigned char, char, float, double, long long, unsigned long long > numerical_test_types
Definition: tests_high_five_parallel.cpp:40
HighFive::File::ReadWrite
static const int ReadWrite
Open flag: Read Write access.
Definition: H5File.hpp:32
HighFive::MPIOFileDriver
MPIIO Driver for Parallel HDF5.
Definition: H5FileDriver.hpp:29
selectionArraySimpleTestParallel
void selectionArraySimpleTestParallel()
Definition: tests_high_five_parallel.cpp:85
argv
char ** argv
Definition: tests_high_five_parallel.cpp:28
HighFive::DataSet
Definition: H5DataSet.hpp:27
HighFive::File::Truncate
static const int Truncate
Open flag: Truncate a file if already existing.
Definition: H5File.hpp:34
HighFive
Definition: H5Annotate_traits.hpp:14
DATASET_NAME
const std::string DATASET_NAME("dset")


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:25