ADIOS2.jl
ADIOS2.jl is a Julia interface to the ADIOS2, the Adaptable Input Output System version 2.
Installation
julia>]
pkg> add ADIOS2ADIOS2 binaries are downloaded by default using the ADIOS2_jll package
Using a custom or system provided ADIOS2 library
Set the environment variable JULIA_ADIOS2_PATH to the top-level installation directory for ADIOS2, i.e. the libadios2_c and libadios2_c_mpi (if using MPI-enabled ADIOS2) libraries should be located under $JULIA_ADIOS2_PATH/lib or $JULIA_ADIOS2_PATH/lib64. Then run import Pkg; Pkg.build("ADIOS2"). This is preferred in high-performance computing (HPC) systems for system-wide installations for libraries built against vendor MPI implementations. It is highly recommended that MPIPreferences points at the system MPI implementation used to build ADIOS2.
Example:
$ export JULIA_ADIOS2_PATH=/opt/adios2/2.8.3Then in Julia, run:
pkg> buildBasic API
Types
ADIOS2.Error — Type
@enum Error begin
error_none
error_invalid_argument
error_system_error
error_runtime_error
error_exception
endError return types for all ADIOS2 functions
Based on the library C++ standardized exceptions. Each error will issue a more detailed description in the standard error output, stderr
ADIOS2.AdiosType — Type
const AdiosType = Union{AbstractString,
Float32,Float64,
Complex{Float32},Complex{Float64},
Int8,Int16,Int32,Int64,
UInt8,UInt16,UInt32,UInt64}A Union of all scalar types supported in ADIOS files.
ADIOS2.Mode — Type
@enum Mode begin
mode_undefined
mode_write
mode_read
mode_append
mode_readRandomAccess
mode_deferred
mode_sync
endMode specifies for various functions. write, read, append, and readRandomAccess are used for file operations. deferred and sync are used for get and put operations.
ADIOS2.StepMode — Type
@enum StepMode begin
step_mode_append
step_mode_update
step_mode_read
endADIOS2.StepStatus — Type
@enum StepStatus begin
step_status_other_error
step_status_ok
step_status_not_ready
step_status_end_of_stream
endADIOS2.ShapeId — Type
@enum ShapeId begin
shapeid_unknown
shapeid_global_value
shapeid_global_array
shapeid_joined_array
shapeid_local_value
shapeid_local_array
endAdios functions
ADIOS2.Adios — Type
mutable struct AdiosHolds a C pointer adios2_adios *.
This value is finalized automatically. It can also be explicitly finalized by calling finalize(adios).
ADIOS2.adios_init_mpi — Function
adios = adios_init_mpi(comm::MPI.Comm)
adios = adios_init_mpi(config_file::AbstractString, comm::MPI.Comm)
adios::Union{Adios,Nothing}Starting point for MPI apps. Creates an ADIOS handler. MPI collective and it calls MPI_Comm_dup.
ADIOS2.adios_init_serial — Function
adios = adios_init_serial()
adios = adios_init_serial(config_file::AbstractString)
adios::Union{Adios,Nothing}Initialize an Adios struct in a serial, non-MPI application. Doesn’t require a runtime config file.
See also the ADIOS2 documentation.
ADIOS2.declare_io — Function
io = declare_io(adios::Adios, name::AbstractString)
io::Union{AIO,Nothing}Declare a new IO handler.
See also the ADIOS2 documentation.
ADIOS2.adios_finalize — Function
err = adios_finalize(adios::Adios)
err::ErrorFinalize the ADIOS context adios. It is usually not necessary to call this function.
Instead of calling this function, one can also call the finalizer via finalize(adios). This finalizer is also called automatically when the Adios object is garbage collected.
See also the ADIOS2 documentation
IO functions
ADIOS2.AIO — Type
struct AIOHolds a C pointer adios2_io *.
ADIOS2.set_engine — Function
err = set_engine(io::AIO, engine_type::AbstractString)
err::ErrorSet the engine type for current io handler.
Arguments
io: handlerengine_type: predefined engine type, default is bpfile
ADIOS2.define_variable — Function
variable = define_variable(io::AIO, name::AbstractString, type::Type,
shape::Union{Nothing,NTuple{N,Int} where N,CartesianIndex}=nothing,
start::Union{Nothing,NTuple{N,Int} where N,CartesianIndex}=nothing,
count::Union{Nothing,NTuple{N,Int} where N,CartesianIndex}=nothing,
constant_dims::Bool=false; global_value=false)
variable::Union{Nothing,Variable}Define a variable within io.
Arguments
io: handler that owns the variablename: unique variable identifiertype: primitive typendims: number of dimensionsshape: global dimensionstart: local offsetcount: local dimensionconstant_dims:true: shape, start, count won't change;false: shape, start, count will change after definition
Keywords
global_value: for scalar variables (shape=nothing),global_value=truecan be passed to indicate that the variable will be a 'global' variable, written once per step, as opposed to a 'local' variable written once per MPI rank per step.
ADIOS2.inquire_variable — Function
variable = inquire_variable(io::AIO, name::AbstractString)
variable::Union{Nothing,Variable}Retrieve a variable handler within current io handler.
Arguments
io: handler to variableioownername: unique variable identifier withiniohandler
ADIOS2.inquire_all_variables — Function
variables = inquire_all_variables(io::AIO)
variables::Union{Nothing,Vector{Variable}}Returns an array of variable handlers for all variable present in the io group.
Arguments
io: handler to variables io owner
ADIOS2.inquire_group_variables — Function
vars = inquire_group_variables(io::AIO, full_prefix::AbstractString)
vars::Vector{String}List all variables in the group full_prefix.
ADIOS2.define_attribute — Function
attribute = define_attribute(io::AIO, name::AbstractString, value)
attribute::Union{Nothing,Attribute}Define an attribute value inside io.
ADIOS2.define_attribute_array — Function
attribute = define_attribute_array(io::AIO, name::AbstractString,
values::AbstractVector)
attribute::Union{Nothing,Attribute}Define an attribute array inside io.
ADIOS2.define_variable_attribute — Function
attribute = define_variable_attribute(io::AIO, name::AbstractString, value,
variable_name::AbstractString,
separator::AbstractString="/")
attribute::Union{Nothing,Attribute}Define an attribute single value associated to an existing variable by its name.
ADIOS2.define_variable_attribute_array — Function
attribute = define_variable_attribute_array(io::AIO, name::AbstractString,
values::AbstractVector,
variable_name::AbstractString,
separator::AbstractString="/")
attribute::Union{Nothing,Attribute}Define an attribute array associated to an existing variable by its name.
ADIOS2.inquire_attribute — Function
attribute = inquire_attribute(io::AIO, name::AbstractString)
attribute::Union{Nothing,Attribute}Return a handler to a previously defined attribute by name.
ADIOS2.inquire_variable_attribute — Function
attribute = inquire_variable_attribute(io::AIO, name::AbstractString,
variable_name::AbstractString,
separator::AbstractString="/")
attribute::Union{Nothing,Attribute}Return a handler to a previously defined attribute by name.
ADIOS2.inquire_all_attributes — Function
attributes = inquire_all_attributes(io::AIO)
attributes::Union{Nothing,Vector{Attribute}}Return an array of attribute handlers for all attribute present in the io group.
ADIOS2.inquire_group_attributes — Function
vars = inquire_group_attributes(io::AIO, full_prefix::AbstractString)
vars::Vector{String}List all attributes in the group full_prefix.
ADIOS2.inquire_subgroups — Function
groups = inquire_subgroups(io::AIO, full_prefix::AbstractString)
groups::Vector{String}List all subgroups in the group full_prefix.
Base.open — Function
engine = open(io::AIO, name::AbstractString, mode::Mode)
engine::Union{Nothing,Engine}Open an Engine to start heavy-weight input/output operations.
In MPI version reuses the communicator from adios_init_mpi. MPI Collective function as it calls MPI_Comm_dup.
Arguments
io: engine ownername: unique engine identifiermode:mode_write,mode_read,mode_append(not yet supported)
ADIOS2.engine_type — Function
type = engine_type(io::AIO)
type::Union{Nothing,String}Return engine type string. See set_engine.
ADIOS2.get_engine — Function
engine = get_engine(io::AIO, name::AbstractString)
engine::Union{Nothing,Engine}Variable functions
ADIOS2.Variable — Type
struct VariableHolds a C pointer adios2_variable *.
ADIOS2.set_block_selection — Function
set_block_selection(variable::Variable, block_id::Int)ADIOS2.set_selection — Function
set_selection(variable::Variable, start::Union{Nothing,NTuple{N,Int} where N,
CartesianIndex}, count::Union{Nothing,NTuple{N,Int} where N,
CartesianIndex})ADIOS2.set_step_selection — Function
set_step_selection(variable::Variable, step_start::Int, step_count::Int)
Only works with file-based engines, not streaming engines (e.g. does not work with SST)ADIOS2.name — Method
var_name = name(variable::Variable)
var_name::Union{Nothing,String}Retrieve variable name.
ADIOS2.type — Method
var_type = type(variable::Variable)
var_type::Union{Nothing,Type}Retrieve variable type.
ADIOS2.shapeid — Method
var_shapeid = shapeid(variable::Variable)
var_shapeid::Union{Nothing,ShapeId}Retrieve variable shapeid.
Base.ndims — Method
var_ndims = ndims(variable::Variable)
var_ndims::Union{Nothing,Int}Retrieve current variable number of dimensions.
ADIOS2.shape — Method
var_shape = shape(variable::Variable)
var_shape::Union{Nothing,NTuple{N,Int} where N}Retrieve current variable shape.
ADIOS2.start — Method
var_start = start(variable::Variable)
var_start::Union{Nothing,NTuple{N,Int} where N}Retrieve current variable start.
Base.count — Method
var_count = count(variable::Variable)
var_count::Union{Nothing,NTuple{N,Int} where N}Retrieve current variable count.
ADIOS2.steps_start — Method
var_steps_start = steps_start(variable::Variable)
var_steps_start::Union{Nothing,Int}Read API, get available steps start from available steps count (e.g. in a file for a variable).
This returns the absolute first available step, don't use with adios2_set_step_selection as inputs are relative, use 0 instead.
ADIOS2.steps — Method
var_steps = steps(variable::Variable)
var_steps::Union{Nothing,Int}Read API, get available steps count from available steps count (e.g. in a file for a variable). Not necessarily contiguous.
ADIOS2.selection_size — Method
var_selection_size = selection_size(variable::Variable)
var_selection_size::Union{Nothing,Int}Return the minimum required allocation (in number of elements of a certain type, not bytes) for the current selection.
Base.minimum — Method
var_min = minimum(variable::Variable)
var_min::Union{Nothing,T}Read mode only: return the absolute minimum for variable.
Base.maximum — Method
var_max = maximum(variable::Variable)
var_max::Union{Nothing,T}Read mode only: return the absolute maximum for variable.
Attribute functions
ADIOS2.Attribute — Type
struct AttributeHolds a C pointer adios2_attribute *.
ADIOS2.name — Method
attr_name = name(attribute::Attribute)
attr_name::Union{Nothing,String}Retrieve attribute name.
ADIOS2.type — Method
attr_type = type(attribute::Attribute)
attr_type::Union{Nothing,Type}Retrieve attribute type.
ADIOS2.is_value — Method
attr_is_value = is_value(attribute::Attribute)
attr_is_value::Union{Nothing,Bool}Retrieve attribute type.
ADIOS2.data — Method
attr_data = data(attribute::Attribute)
attr_data::Union{Nothing,AdiosType,Vector{<:AdiosType}}Retrieve attribute Data.
Engine functions
ADIOS2.Engine — Type
struct EngineHolds a C pointer adios2_engine *.
ADIOS2.name — Function
var_name = name(variable::Variable)
var_name::Union{Nothing,String}Retrieve variable name.
attr_name = name(attribute::Attribute)
attr_name::Union{Nothing,String}Retrieve attribute name.
engine_name = name(engine::Engine)
engine_name::Union{Nothing,String}Retrieve engine name.
ADIOS2.type — Function
var_type = type(variable::Variable)
var_type::Union{Nothing,Type}Retrieve variable type.
attr_type = type(attribute::Attribute)
attr_type::Union{Nothing,Type}Retrieve attribute type.
engine_type = type(engine::Engine)
engine_type::Union{Nothing,String}Retrieve engine type.
ADIOS2.openmode — Function
engine_openmode = openmode(engine::Engine)
engine_openmode::Union{Nothing,Mode}Retrieve engine openmode.
ADIOS2.begin_step — Function
status = begin_step(engine::Engine, mode::StepMode,
timeout_seconds::Union{Integer,AbstractFloat})
status = begin_step(engine::Engine)
status::Union{Noting,StepStatus}Begin a logical adios2 step stream.
ADIOS2.current_step — Function
step = current_step(engine::Engine)
step::Union{Noting,Int}Inspect current logical step.
ADIOS2.steps — Function
var_steps = steps(variable::Variable)
var_steps::Union{Nothing,Int}Read API, get available steps count from available steps count (e.g. in a file for a variable). Not necessarily contiguous.
step = steps(engine::Engine)
step::Union{Noting,Int}Inspect total number of available steps.
Base.put! — Function
err = Base.put!(engine::Engine, variable::Variable,
data::Union{Ref,DenseArray,SubArray,Ptr},
launch::Mode=mode_deferred)
err = Base.put!(engine::Engine, variable::Variable, data::AdiosType,
launch::Mode=mode_deferred)
err::ErrorSchedule writing a variable to file. The buffer data must be contiguous in memory.
Call perform_puts! to perform the actual write operations.
The reference/array/pointer target must not be modified before perform_puts! is called. It is most efficient to schedule multiple put! operations before calling perform_puts!.
ADIOS2.perform_puts! — Function
perform_puts!(engine::Engine)Execute all currently scheduled write operations.
Base.get — Function
err = Base.get(engine::Engine, variable::Variable,
data::Union{Ref,DenseArray,SubArray,Ptr},
launch::Mode=mode_deferred)
err::ErrorSchedule reading a variable from file into the provided buffer data. data must be contiguous in memory.
Call perform_gets to perform the actual read operations.
The reference/array/pointer target must not be modified before perform_gets is called. It is most efficient to schedule multiple get operations before calling perform_gets.
ADIOS2.perform_gets — Function
perform_gets(engine::Engine)Execute all currently scheduled read operations.
ADIOS2.end_step — Function
end_step(engine::Engine)Terminate interaction with current step.
Base.flush — Method
flush(engine::Engine)Flush all buffered data to file. Call this after perform_puts! to ensure data are actually written to file.
Base.close — Method
close(engine::Engine)Close a file. This implicitly also flushed all buffered data.
High-Level API
ADIOS2.AdiosFile — Type
struct AdiosFileContext for the high-level API for an ADIOS file
ADIOS2.adios_open_serial — Function
adios = adios_open_serial(filename::AbstractString, mode::Mode)
adios::AdiosFileOpen an ADIOS file. Use mode = mode_write for writing and mode = mode_read for reading.
ADIOS2.adios_open_mpi — Function
adios = adios_open_mpi(comm::MPI.Comm, filename::AbstractString, mode::Mode)
adios::AdiosFileOpen an ADIOS file for parallel I/O. Use mode = mode_write for writing and mode = mode_read for reading.
Base.flush — Method
flush(file::AdiosFile)Flush an ADIOS file. When writing, flushing or closing a file is necesssary to ensure that data are actually written to the file.
Base.close — Method
close(file::AdiosFile)Close an ADIOS file. When writing, flushing or closing a file is necesssary to ensure that data are actually written to the file.
ADIOS2.adios_subgroup_names — Function
groups = adios_subgroup_names(file::AdiosFile, groupname::AbstractString)
vars::Vector{String}List (non-recursively) all subgroups in the group groupname in the file.
ADIOS2.adios_define_attribute — Function
adiosdefineattribute(file::AdiosFile, name::AbstractString, value::AdiosType)
Write a scalar attribute.
adios_define_attribute(file::AdiosFile, name::AbstractString,
value::AbstractArray{<:AdiosType})Write an array-valued attribute.
adios_define_attribute(file::AdiosFile, path::AbstractString,
name::AbstractString, value::AdiosType)Write a scalar attribute into the path path in the file.
adios_define_attribute(file::AdiosFile, path::AbstractString,
name::AbstractString,
value::AbstractArray{<:AdiosType})Write an array-valued attribute into the path path in the file.
ADIOS2.adios_all_attribute_names — Function
attrs = adios_all_attribute_names(file::AdiosFile)
attrs::Vector{String}List (recursively) all attributes in the file.
ADIOS2.adios_group_attribute_names — Function
vars = adios_group_attribute_names(file::AdiosFile, groupname::AbstractString)
vars::Vector{String}List (non-recursively) all attributes in the group groupname in the file.
ADIOS2.adios_attribute_data — Function
attr_data = adios_attribute_data(file::AdiosFile, name::AbstractString)
attr_data::Union{Nothing,AdiosType}Read an attribute from a file. Return nothing if the attribute is not found.
attr_data = adios_attribute_data(file::AdiosFile, path::AbstractString,
name::AbstractString)
attr_data::Union{Nothing,AdiosType}Read an attribute from a file in path path. Return nothing if the attribute is not found.
ADIOS2.adios_put! — Function
adios_put!(file::AdiosFile, name::AbstractString, scalar::AdiosType)
Schedule writing a scalar variable to a file.
The variable is not written until adios_perform_puts! is called and the file is flushed or closed.
Keywords
global_value: for scalar variables (shape=nothing),global_value=truecan be passed to indicate that the variable will be a 'global' value, written once per step, as opposed to a 'local' value written once per MPI rank per step.
adios_put!(file::AdiosFile, name::AbstractString,
array::AbstractArray{<:AdiosType}; make_copy::Bool=false)Schedule writing an array-valued variable to a file.
make_copy determines whether to make a copy of the array, which is expensive for large arrays. When no copy is made, then the array must not be modified before adios_perform_puts! is called.
The variable is not written until adios_perform_puts! is called and the file is flushed or closed.
ADIOS2.adios_perform_puts! — Function
adios_perform_puts!(file::AdiosFile)Execute all scheduled adios_put! operations.
The data might not be in the file yet; they might be buffered. Call adios_flush or adios_close to ensure all data are written to file.
ADIOS2.adios_all_variable_names — Function
vars = adios_all_variable_names(file::AdiosFile)
vars::Vector{String}List (recursively) all variables in the file.
ADIOS2.adios_group_variable_names — Function
vars = adios_group_variable_names(file::AdiosFile, groupname::AbstractString)
vars::Vector{String}List (non-recursively) all variables in the group groupname in the file.
ADIOS2.IORef — Type
mutable struct IORef{T,D}A reference to the value of a variable that has been scheduled to be read from disk. This value cannot be accessed bofre the read operations have actually been executed.
Use fetch(ioref::IORef) to access the value. fetch will trigger the actual reading from file if necessary. It is most efficient to schedule multiple read operations at once.
Use adios_perform_gets to trigger reading all currently scheduled variables.
Base.isready — Method
isready(ioref::IORef)::BoolCheck whether an IORef has already been read from file.
Base.fetch — Method
value = fetch(ioref::IORef{T,D}) where {T,D}
value::Array{T,D}Access an IORef. If necessary, the variable is read from file and then cached. (Each IORef is read at most once.)
Scalars are handled as zero-dimensional arrays. To access the value of a zero-dimensional array, write array[] (i.e. use array indexing, but without any indices).
ADIOS2.adios_get — Function
ioref = adios_get(file::AdiosFile, name::AbstractString; start=nothing, count=nothing)
ioref::Union{Nothing,IORef}Schedule reading a variable from a file.
The variable is not read until adios_perform_gets is called. This happens automatically when the IORef is accessed (via fetch). It is most efficient to first schedule multiple variables for reading, and then executing the reads together.
start and counts can be used to select a subset of the data, as defined by set_selection.
ADIOS2.adios_perform_gets — Function
adios_perform_gets(file::AdiosFile)Execute all currently scheduled read opertions. This makes all pending IORefs ready.
Extended High-Level API
ADIOS2.adios_load — Function
adios_load(file::AdiosFile, [varName(s)], [step(s)]; start=nothing, count=nothing)Read variable data from ADIOS file with optional variable name(s) and step selection(s).
Arguments
- First:
file(::AdiosFile): ADIOS file (opened withmode_readRandomAccess)
- Second (Optional):
varName(::AbstractString): Single variable name or nothing (reads all)varNames(::AbstractArray{<:AbstractString}`): Array of variable namesname_pattern(::Regex): To find variables whose name contains the pattern (e.g., r"temp.*")
- Third (Optional):
step(::Integer): Single step index (0-based)step_list(::AbstractArray{<:Integer}): Array of step indices
Keywords
start: when loading a single variable, can be passed a length-N Tuple giving the positions to start reading data in each dimension. Note thanstartshould be given in standard Julian 1-based indexing.count: when loading a single variable, can be passed a length-N Tuple giving the number of entries to read in each dimension.
Returns
For a variable of N-D data, returns an (N+1)-D array with the last dimension being the steps.
- Single variable:
- Single step: original dimensionality preserved (N-D array)
- Multiple steps: returns (N+1)-D array with shape (dim1, dim2, ..., dimN, N_steps)
- Multiple variables:
- Dictionary with variable names as keys and their data arrays as values
Examples
# Open file in random access mode
file = adios_open_serial("simulation.bp", mode_readRandomAccess)
# Read all steps of all variables in the file
data_dict = adios_load(file)
# Read all steps of a variable
data = adios_load(file, "temperature")
data = adios_load(file, "temperature"; start=[3,4], count=[10,20])
# Read of a variable at a specific step
data = adios_load(file, "temperature", 5)
data = adios_load(file, "temperature", 5; start=[3,4], count=[10,20])
# Read specific steps at multiple steps (order is not sorted)
data = adios_load(file, "temperature", [1,3,6])
data = adios_load(file, "temperature", [6,3,1]) # reverse of previous example
data = adios_load(file, "temperature", 50:100)
data = adios_load(file, "temperature", 50:100; start=[3,4], count=[10,20])
# Read multiple variables at a specific step
data_dict = adios_load(file, ["temperature", "pressure"], 5)
# Read multiple variables at multiple steps (order is not sorted)
data_dict = adios_load(file, ["temperature", "pressure"], [1,3,6])
data_dict = adios_load(file, ["temperature", "pressure"], [6,3,1]) # reverse of previous example
data_dict = adios_load(file, ["temperature", "pressure"], 50:100)
# Read multiple variables contain the given name pattern at multiple steps
data_dict = adios_load(file, r"temper", 50:100) # will read (electron_temperature, ion_temperature, abc_temper_abc, etc.)
data_dict = adios_load(file, r"ion.*temper", 50:100) # will read (ion_temperature)
data_dict = adios_load(file, r"temper|pres", 50:100) # will read (temperature, temperature, pressure, ion_pressure, electron_pressure, etc.)
close(file)adios_load(bpPath::AbstractString)
adios_load(bpPath::AbstractString, args...; kwargs...)Convenient highest-level API to read variable data directly from ADIOS's BP file path.
This is a convenience wrapper that automatically opens the file in mode_readRandomAccess, reads the data, and closes the file. All the functionality of adios_load(file::AdiosFile, ...) is available through the same argument patterns.
Arguments
bpPath(AbstractString): Path to ADIOS's BP file/directory ending with.bpextensionargs...: Same arguments asadios_load(file::AdiosFile, ...)- variable names, steps, etc.
Keywords
kwargs...: Same keyword arguments asadios_load(file::AdiosFile, ...).
Returns
Same return types as adios_load(file::AdiosFile, ...):
- Single variable, single step: N-D array
- Single variable, multiple steps: (N+1)-D array with steps as last dimension
- Multiple variables: Dictionary with variable names as keys
Examples
# Read all variables and all steps
data_dict = adios_load("simulation.bp")
# Read specific variable, all steps
temperature = adios_load("simulation.bp", "temperature")
# Read specific variable at specific step
temp_step5 = adios_load("simulation.bp", "temperature", 5)
# Read multiple variables at multiple steps
data = adios_load("simulation.bp", ["temperature", "pressure"], [1,3,5])
# Read variables matching pattern
temps = adios_load("simulation.bp", r".*temperature.*", 10:20)Notes
- File is automatically opened with
mode_readRandomAccessand closed after reading - Throws
ErrorExceptionif the file path does not exist or is invalid - More efficient to use
adios_load(file::AdiosFile, ...)directly if reading multiple times from the same file to avoid repeated open/close operations
See also: adios_load(::AdiosFile), adios_open_serial