Created
August 12, 2022 23:30
-
-
Save lyon-fnal/c615d5edc8dceb34d2283f576f35a327 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output is