HDF5 tutorialNUG2010
HDF5 tutorialNUG2010
Intro to HDF5
Katie Antypas
NERSC
Tutorial in part from HDF Group
NUG 2010
Berkeley, CA
Oct 18th, 2010
2010
NUG 2010
www.hdfgroup.org
Serial I/O
processors
Advantages ?
File
Disadvantages ?
File
File
File
File
File
File
File
Each processor writes its own data to the same file using
MPI-IO mapping
Advantages ?
Disadvantages ?
ASCII:
Slow
Takes more space!
Inaccurate
Binary
Non-portable (eg. byte ordering and types sizes)
Not future proof
Parallel I/O using MPI-IO
Self-Describing formats
Experiment Notes:
Serial Number: 99378920
Date: 3/13/09
Configuration: Standard 3
Viz
SimOut
www.hdfgroup.org
HDF5 Dataset
Metadata
Data
Dataspace
3
Dim_1 = 4
Dim_2 = 5
Dim_3 = 7
Integer
Time = 32.4
Chunked
Pressure = 987
Compressed
Temp = 56
www.hdfgroup.org
HDF5 Dataset
3
Datatype:
Dataspace:
16-byte integer
Rank = 2
Dimensions = 5 x 3
10
www.hdfgroup.org
HDF5 Datatypes
The HDF5 datatype describes how to interpret
individual data elements.
HDF5 datatypes include:
integer, float, unsigned, bitfield,
user-definable (e.g., 13-bit integer)
variable length types (e.g., strings)
references to objects/dataset regions
enumerations - names mapped to integers
opaque
compound (similar to C structs)
11
www.hdfgroup.org
int
H5T_STD_I32BE
H5T_STD_I32LE
H5T_NATIVE_INT
float
H5T_IEEE_F32BE
H5T_IEEE_F32LE
H5T_NATIVE_FLOAT
double
H5T_IEEE_F64BE
H5T_IEEE_F64LE
H5T_NATIVE_DOUBLE
12
www.hdfgroup.org
13
www.hdfgroup.org
Basic Functions
H5Fcreate (H5Fopen)
H5Dread, H5Dwrite
access Dataset
H5Dclose
H5Sclose
H5Fclose
close Dataset
close fileSpace
close File
NOTE: Order not strictly specified.
14
www.hdfgroup.org
Logistics
Log into franklin or carver
ssh franklin.nersc.gov or ssh carver.nersc.gov
cp /project/projectdirs/training/pHDF5_examples.tar
$SCRATCH
cd $SCRATCH
tar xvf pHDF5_examples.tar
Here you will find the code examples, submission
scripts and detailed instructions in
instructions_carver.txt or instructions_franklin.txt
15
www.hdfgroup.org
Example :
write_grid_rows.c
(or fortran90 version if you prefer)
16
www.hdfgroup.org
File
P2
P3
NX
NY
17
www.hdfgroup.org
www.hdfgroup.org
www.hdfgroup.org
www.hdfgroup.org
21
www.hdfgroup.org
Calculate Offsets
P0
P1
File
P2
NX
P3
NY
Every processor has a 2d array, which holds the number of
blocks to write and the starting offset
count[0], count[1]
offet[0][offset[1]
22
www.hdfgroup.org
Memory
offset[1]
count[1]
count[0]
offset[0]
count[0] = dimsf[0]/num_procs
count[1] = dimsf[1];
offset[0] = my_proc * count[0];
offset[1] = 0;
/* = 2 */
23
www.hdfgroup.org
24
www.hdfgroup.org
25
www.hdfgroup.org
Write Data
Identifier for dataset
dataset1
Datatype
Data buffer
Then close every dataspace and file space that was opened
26
www.hdfgroup.org
To compile:
% h5pcc h5prog.c
% h5pfc h5prog.f90
27
www.hdfgroup.org
P0
File
P1
28
www.hdfgroup.org
29
www.hdfgroup.org
NY
www.hdfgroup.org
Process 0
File
P0 offset[1]
block[0]
dimsm[0]
dimsm[1]
Process 1
block[1]
P1 offset[1]
stride[1]
31
www.hdfgroup.org
www.hdfgroup.org
File
Process 0
Process 1
NX
Process 2
Process 3
NY
33
www.hdfgroup.org
www.hdfgroup.org
File
Process 0
Process 1
NX
Process 2
Process 3
NY
www.hdfgroup.org
File
stride[1]
Process 2
stride[0]
offset[0]
offset[1]
count[0]
count[1]
stride[0]
stride[1]
=
=
=
=
=
=
0;
1;
4;
2;
2;
2;
count[1]
offset[1]
36
www.hdfgroup.org
www.hdfgroup.org
P0
P1
P2
File
P3
NX
NY
38
www.hdfgroup.org
P1
P2
P3
NX
NY
More complicated pattern, describe data layout with 4 arrays
offset[] - starting position
stride[] - spacing to the next element
count[] - how many times to write a contiguous block
block[] - how many contiguous elements to write
39
www.hdfgroup.org
www.hdfgroup.org
Process 2: Memory
offset[1]
chunk_dims[1]
offset[0]
chunk_dims[0]
block[0]
block[0]
block[1]
offset[0]
offset[1]
=
=
=
=
chunk_dims[0];
chunk_dims[1];
chunk_dims[0];
0;
block[1]
41
www.hdfgroup.org
count[0] = 1;
count[1] = 1 ;
stride[0] = 1;
stride[1] = 1;
block[0] = chunk_dims[0];
block[1] = chunk_dims[1];
if(mpi_rank == 0) {
offset[0] = 0;
offset[1] = 0;
}
if(mpi_rank == 1) {
offset[0] = 0;
offset[1] = chunk_dims[1];
}
if(mpi_rank == 2) {
offset[0] = chunk_dims[0];
offset[1] = 0;
}
if(mpi_rank == 3) {
offset[0] = chunk_dims[0];
offset[1] = chunk_dims[1];
}
42
www.hdfgroup.org
www.hdfgroup.org
P0
P1
File
P2
P3
44
www.hdfgroup.org
P0
File
P1
45
www.hdfgroup.org
46
www.hdfgroup.org
47
www.hdfgroup.org
49 www.hdfgroup.org
50
www.hdfgroup.org
51
www.hdfgroup.org
Process2
call A(); call B(); **right**
call B(); call A(); **wrong**
52
www.hdfgroup.org
Programming Restrictions
Most PHDF5 APIs are collective
PHDF5 opens a parallel file with a
communicator
Returns a file-handle
Future access to the file via the file-handle
All processes must participate in collective
PHDF5 APIs
Different files can be opened via different
communicators
53
www.hdfgroup.org
54
www.hdfgroup.org
F90:
h5pset_fapl_mpio_f(plist_id, comm, info)
integer(hid_t) :: plist_id
integer
:: comm, info
plist_id is a file access property list identifier
55
www.hdfgroup.org
comm = MPI_COMM_WORLD;
info = MPI_INFO_NULL;
/*
* Initialize MPI
*/
MPI_Init(&argc, &argv);
/*
* Set up file access property list for MPI-IO access
*/
plist_id = H5Pcreate(H5P_FILE_ACCESS);
H5Pset_fapl_mpio(plist_id, comm, info);
file_id = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC,
H5P_DEFAULT, plist_id);
/*
* Close the file.
*/
H5Fclose(file_id);
MPI_Finalize();
56
www.hdfgroup.org
comm = MPI_COMM_WORLD
info = MPI_INFO_NULL
CALL MPI_INIT(mpierror)
!
! Initialize FORTRAN predefined datatypes
CALL h5open_f(error)
!
! Setup file access property list for MPI-IO access.
CALL h5pcreate_f(H5P_FILE_ACCESS_F, plist_id, error)
CALL h5pset_fapl_mpio_f(plist_id, comm, info, error)
!
! Create the file collectively.
CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id,
error, access_prp = plist_id)
!
! Close the file.
CALL h5fclose_f(file_id, error)
!
! Close FORTRAN interface
CALL h5close_f(error)
CALL MPI_FINALIZE(mpierror)
57
www.hdfgroup.org
58
www.hdfgroup.org
file_id = H5Fcreate();
/*
* Create the dataspace for the dataset.
*/
dimsf[0] = NX;
dimsf[1] = NY;
filespace = H5Screate_simple(RANK, dimsf, NULL);
/*
* Create the dataset with default properties collective.
*/
dset_id = H5Dcreate(file_id, dataset1, H5T_NATIVE_INT,
filespace, H5P_DEFAULT);
H5Dclose(dset_id);
/*
* Close the file.
*/
H5Fclose(file_id);
59
www.hdfgroup.org
60
www.hdfgroup.org
Accessing a Dataset
All processes that have opened dataset may
do collective I/O
Each process may do independent and
arbitrary number of data I/O access calls
C: H5Dwrite and H5Dread
F90: h5dwrite_f and h5dread_f
61
www.hdfgroup.org
F90: h5pset_dxpl_mpio_f
H5FD_MPIO_COLLECTIVE_F
H5FD_MPIO_INDEPENDENT_F (default)
62
www.hdfgroup.org
95
96
97
98
->99
100
/*
* Create property list for collective dataset write.
*/
plist_id = H5Pcreate(H5P_DATASET_XFER);
H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
63
www.hdfgroup.org
64
www.hdfgroup.org
65
www.hdfgroup.org
HDF5 Properties
Properties (also known as Property Lists)
are characteristics of HDF5 objects that can
be modified
Default properties handle most needs
By changing properties one can take
advantage of the more powerful features in
HDF5
66
www.hdfgroup.org
Storage Properties
Data elements
stored physically
adjacent to each
other
Improves storage
efficiency,
transmission speed
67
www.hdfgroup.org
www.hdfgroup.org
Improves storage
efficiency,
transmission speed
H5P_DEFAULT: contiguous
Dataset creation property list: information on how to
organize data in storage.
69
www.hdfgroup.org
70
www.hdfgroup.org
4x6 array of
integers
file.h5
71
www.hdfgroup.org
www.hdfgroup.org
73
www.hdfgroup.org
Outline
Performance
Parallel tools
74
www.hdfgroup.org
75
www.hdfgroup.org
MB/Sec
HDF5 Write
MPIO Write
16
32
User reported
Independent data
transfer mode was much
slower than the
Collective data transfer
mode
Data array was tall and
thin: 230,000 rows by 6
columns
:
:
:
230,000 rows
:
:
:
77
www.hdfgroup.org
Data Size
(MB)
Independent
(Sec.)
Collective
(Sec.)
16384
0.25
8.26
1.72
32768
0.50
65.12
1.80
65536
1.00
108.20
2.68
122918
1.88
276.57
3.11
150000
2.29
528.15
3.63
180300
2.75
881.39
4.12
78
www.hdfgroup.org
Time (s)
700
600
Independent
500
Collective
400
300
200
100
0
0.00
0.50
1.00
1.50
2.00
2.50
3.00
79
www.hdfgroup.org
4 nodes, 16 tasks
Total data size 1024MB
I/O buffer size 1MB
Tasks
16
16
IBM_largeblock_io=false IBM_largeblock_io=true
MPI-IO
PHDF5
MPI-IO
PHDF5
write (MB/S)
60
48
354
294
read (MB/S)
44
39
256
248
80
www.hdfgroup.org
16 write
16 read
100
50
0
MPI-IO
PHDF5
MPI-IO
PHDF5
IBM_largeblock_io=false IBM_largeblock_io=true
81
www.hdfgroup.org
Parallel Tools
ph5diff
Parallel version of the h5diff tool
h5perf
Performance measuring tools showing I/
O performance for different I/O API
82
www.hdfgroup.org
ph5diff
An parallel version of the h5diff tool
Supports all features of h5diff
An MPI parallel tool
Manager process (proc 0)
coordinates each the remaining processes
(workers) to diff one dataset at a time;
collects any output from each worker and
prints them out.
Works best if there are many datasets in the
files with few differences.
Available in v1.8.
83
www.hdfgroup.org
h5perf
An I/O performance measurement tool
Test 3 File I/O API
POSIX I/O (open/write/read/close)
MPIO (MPI_File_{open,write,read,close})
PHDF5
H5Pset_fapl_mpio (using MPI-IO)
H5Pset_fapl_mpiposix (using POSIX I/O)
84
www.hdfgroup.org
85
www.hdfgroup.org
IO API = MPIO
Write (1 iteration(s)):
Maximum Throughput: 611.95 MB/s
Average Throughput: 611.95 MB/s
Minimum Throughput: 611.95 MB/s
Write Open-Close (1 iteration(s)):
Maximum Throughput: 16.89 MB/s
Average Throughput: 16.89 MB/s
Minimum Throughput: 16.89 MB/s
Read (1 iteration(s)):
Maximum Throughput: 421.75 MB/s
Average Throughput: 421.75 MB/s
Minimum Throughput: 421.75 MB/s
Read Open-Close (1 iteration(s)):
Maximum Throughput: 109.22 MB/s
Average Throughput: 109.22 MB/s
Minimum Throughput: 109.22 MB/s
87 www.hdfgroup.org
89
www.hdfgroup.org
Questions?
End of Part IV
90
www.hdfgroup.org
HDF5 Groups
Used to organize collections
Every file starts with a root group
Similar to UNIX directories
Path to object defines it
Objects can be shared:
/A/k and /B/l are the same temp
A
k
B
l
temp
= Group
= Dataset
91
www.hdfgroup.org
int8
int4
V V V
V V V
int16
Compound
Datatype:
Dataspace: Rank = 2
Dimensions = 5 x 3
92
www.hdfgroup.org
Dataset Access:
Retrieve the raw data chunk cache parameters
93
www.hdfgroup.org
Group Properties
Link Creation
Creating intermediate groups
Group Creation
Creation order tracking and indexing for links in
a group.
Set Number of links and length of link names in
a group.
www.hdfgroup.org
95
www.hdfgroup.org
96
www.hdfgroup.org
Help
http://hdfgroup.org/
http://hdfgroup.org/HDF5/
[email protected]
http://hdfgroup.org/services/support.html
97
www.hdfgroup.org
HDF5 is designed
for high volume and/or complex data
for every size and type of system (portable)
for flexible, efficient storage and I/O
to enable applications to evolve in their use of
HDF5 and to accommodate new models
to support long-term data preservation
98
www.hdfgroup.org
99
www.hdfgroup.org
HDF5 Technology
HDF5 (Abstract) Data Model
Defines the building blocks for data organization and
specification
Files, Groups, Datasets, Attributes, Datatypes, Dataspaces,
www.hdfgroup.org
HDF5 File
An HDF5 file is a
container that
holds data
objects.
lat|lon|temp
||
12|23|3.1
15|24|4.2
17|21|3.6
101
www.hdfgroup.org
HDF5 Datasets
HDF5 Datasets organize and contain your
raw data values. They consist of:
Your raw data
Metadata describing the data:
- The information to interpret the data (Datatype)
- The information to describe the logical layout of the
data elements (Dataspace)
- Characteristics of the data (Properties)
- Additional optional information that describes the
data (Attributes)
102
www.hdfgroup.org
103
www.hdfgroup.org
HDF5 Library
Tools
Language
Interfaces
C, Fortran, C++
Internals
Virtual File
Layer
h5repack HDFview
tool
tool
Java Interface
Tunable Properties
Memory
Mgmt
Datatype
Conversion
Filters
Split
Files
Posix
I/O
Chunked
Storage
Version
Compatibility
and so
on
Custom
MPI I/O
Storage
I/O Drivers
HDF5 File
Format
File
Split
Files
File on
Parallel
Filesystem
104
Other
www.hdfgroup.org
105
www.hdfgroup.org
HDF5 is like
106
www.hdfgroup.org
h5dump Utility
h5dump [options] [file]
-H, --header
-d <names>
-g <names>
-p
107
www.hdfgroup.org
www.hdfgroup.org
(int)
(float )
(unsigned int)
(long )
(char )
109
www.hdfgroup.org
H5Sselect_hyperslab
H5Sselect_elements
H5Dget_space
Groups:
Attributes:
H5Acreate, H5Aopen_name,
H5Aclose, H5Aread, H5Awrite
Property lists:
H5Pcreate, H5Pclose
H5Pset_chunk, H5Pset_deflate
110
www.hdfgroup.org
111
www.hdfgroup.org
HDF5 Dataspaces
Two roles:
Dataspace contains spatial information (logical
layout) about a dataset
stored in a file
Rank and dimensions
Permanent part of dataset
definition
112
www.hdfgroup.org