Skip to content
Snippets Groups Projects

HDF5 minimal example

Merged Tobias Meisel requested to merge without_odds into main
1 file
+ 9
9
Compare changes
  • Side-by-side
  • Inline
+ 9
9
@@ -13,11 +13,15 @@
#include <iostream>
#include <vector>
const hsize_t CHUNK_SIZE = 314;
int main(int argc, char** argv)
{
MPI_Init(&argc, &argv);
for (int i = 0; i < argc; ++i)
std::cout << argv[i] << "\n";
int data_length=std::atoi(argv[1]);
int comm_size, comm_rank;
assert(MPI_SUCCESS == MPI_Comm_size(MPI_COMM_WORLD, &comm_size));
assert(MPI_SUCCESS == MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank));
@@ -30,21 +34,21 @@ int main(int argc, char** argv)
// Let's create some sample data!
// MPI ranks have (100 + rank) integers worth of data
std::vector<int> v(100 + comm_rank, comm_rank);
std::vector<int> v(data_length, comm_rank+1);
// The extent of the dataspace in the file can be computed accordingly.
hsize_t size = 100*comm_size+ comm_size*(comm_size-1)/2 ;
hsize_t size = data_length*comm_size; //+ comm_size*(comm_size-1)/2;
printf("Size %d", size);
// Make a dataset!
// I can't believe that takes 10 lines of code :-(
hsize_t infty = 406;
hsize_t infty = H5S_UNLIMITED;;
hid_t fspace = H5Screate_simple(1, &size, &infty);
assert(fspace >= 0);
hid_t dcpl = H5Pcreate(H5P_DATASET_CREATE);
assert(dcpl >= 0);
//assert(H5Pset_chunk(dcpl, 1, &CHUNK_SIZE) >= 0);
assert(H5Pset_chunk(dcpl, 1, &CHUNK_SIZE) >= 0);
hid_t dset = H5Dcreate(file, "1D", H5T_STD_I32LE, fspace, H5P_DEFAULT, dcpl,
H5P_DEFAULT);
assert(dset >= 0);
@@ -55,17 +59,13 @@ int main(int argc, char** argv)
hid_t mspace = H5Screate_simple(1, &blk, NULL);
assert(H5Sselect_all(mspace) >= 0);
offset =
comm_rank / 2 * 100 + (comm_rank - 1) / 2 * ((comm_rank - 1) / 2 + 1);
offset = comm_rank*100; //+(comm_rank)*(comm_rank-1)/2;
offset = (comm_rank)*data_length; //+comm_rank;
printf("offset %d of rank %d \n", offset, comm_rank);
assert(H5Sselect_hyperslab(fspace, H5S_SELECT_SET, &offset, NULL, &one,
&blk) >= 0);
assert(H5Sselect_all(mspace) >= 0);
offset = comm_rank * 100;
assert(H5Sselect_hyperslab(fspace, H5S_SELECT_SET, &offset, NULL, &one,
&blk) >= 0);
Loading