forked from BlueBrain/HighFive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparallel_hdf5_write_dataset.cpp
More file actions
69 lines (56 loc) · 1.89 KB
/
Copy pathparallel_hdf5_write_dataset.cpp
File metadata and controls
69 lines (56 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Copyright (c), 2017, Adrien Devresse
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
*/
#include <iostream>
#include <string>
#include <vector>
#include <mpi.h>
#include <highfive/H5DataSet.hpp>
#include <highfive/H5DataSpace.hpp>
#include <highfive/H5File.hpp>
const std::string FILE_NAME("parallel_dataset_example.h5");
const std::string DATASET_NAME("dset");
//
// simple example to write a dataset with Parallel HDF5 with MPI-IO
//
// The dataset is written from several MPI node in parallel
//
//
int main(int argc, char** argv) {
int mpi_rank, mpi_size;
// initialize MPI
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
using namespace HighFive;
try {
// open a new file with the MPI IO driver for parallel Read/Write
File file(FILE_NAME, File::ReadWrite | File::Create | File::Truncate,
MPIOFileDriver(MPI_COMM_WORLD, MPI_INFO_NULL));
// we define the size of our dataset to
// lines : total number of mpi_rank
// columns : 2
std::vector<size_t> dims(2);
dims[0] = std::size_t(mpi_size);
dims[1] = 2;
// Create the dataset
DataSet dataset =
file.createDataSet<double>(DATASET_NAME, DataSpace(dims));
// Each node want to write its own rank two time in
// its associated row
int data[1][2] = {{mpi_rank, mpi_rank}};
// write it to the associated mpi_rank
dataset.select({std::size_t(mpi_rank), 0}, {1, 2}).write(data);
} catch (Exception& err) {
// catch and print any HDF5 error
std::cerr << err.what() << std::endl;
MPI_Abort(MPI_COMM_WORLD, 1);
}
MPI_Finalize();
return 0; // successfully terminated
}