Skip to content

Instantly share code, notes, and snippets.

@lyon-fnal
Created August 12, 2022 23:30
Show Gist options
  • Save lyon-fnal/c615d5edc8dceb34d2283f576f35a327 to your computer and use it in GitHub Desktop.
Save lyon-fnal/c615d5edc8dceb34d2283f576f35a327 to your computer and use it in GitHub Desktop.
using ADIOS2
function main()
adios = adios_init_serial()
# --- Write a file with two steps with a global array `anArray`
# For step 0, `anArray` will have 200 rows
# For step 1, `anArray` will have 100 rows
iow = declare_io(adios, "Write_MWE")
initialSize = 200
anArray_io = define_variable(iow, "anArray", Float64, (initialSize,), (0,), (initialSize,);
constant_dims=false)
engine = open(iow, "mwe.bp4", mode_write)
for step in 0:1
begin_step(engine, step_mode_update, 100)
arraySize = initialSize - step*100 # Step 0 has 200 rows; step 1 has 100 rows
anArray = collect(1:arraySize) # Fill the array with values from 1 to its size
# Note that ADIOS2.jl doesn't have set_shape - I added it and it will be part of a pull request
set_shape(anArray_io, (arraySize,))
# Note that ADIOS2.jl doesn't have set_selection - I added it and it will be part of a pull request
set_selection(anArray_io, (0,), (arraySize,))
put!(engine, anArray_io, anArray)
end_step(engine)
end
close(engine)
## --- Read the file
ior = declare_io(adios, "Read_MWE")
engine = open(ior, "mwe.bp4", mode_read)
theArray_io = inquire_variable(ior, "anArray")
for step in 0:1
begin_step(engine, step_mode_read, 100)
theStep = current_step(engine) ## Note that ADIOS2.jl has a bug for this function
## I fixed it and it will be part of a pull request
println("Step $theStep: Shape is $(shape(theArray_io)[1]), Start is $(start(theArray_io)[1]), "*
"Count is $(count(theArray_io)[1]), selection_size is $(selection_size(theArray_io)[1])")
# The line below solves the problem - why isn't the count set correctly by default?
#set_selection(theArray_io, (0,), shape(theArray_io))
# Make an empty array of size given by selection_size
theArray = Array{Float64}(undef, selection_size(theArray_io))
get(engine,theArray_io, theArray)
end_step(engine)
end
end
main()
@lyon-fnal
Copy link
Author

Output is

Step 0: Shape is 200, Start is 0, Count is 200, selection_size is 200
Step 1: Shape is 100, Start is 0, Count is 200, selection_size is 200
[Fri Aug 12 18:38:28 2022] [ADIOS2 ERROR] <Helper> <adiosSystem> <ExceptionToError> : adios2_end_step: [Fri Aug 12 18:38:28 2022] [ADIOS2 EXCEPTION] <Toolkit> <format::bp::BP4Deserializer> <SetVariableBlockInfo> : selection Start Dims(1):[0] and Count Dims(1):[200] (requested) is out of bounds of (available) Shape Dims(1):[100] , when reading global array variable anArray in step 2, in call to Get

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment