Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "T8code"
uuid = "d0cc0030-9a40-4274-8435-baadcfd54fa1"
authors = ["Johannes Markert <johannes.markert@dlr.de>"]
version = "0.9.1"
version = "0.9.2-DEV"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
Expand Down
17 changes: 8 additions & 9 deletions examples/t8_step5_element_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@ function t8_step5_output_data_to_vtu(forest, element_data, prefix)

# WARNING: This code hangs for Julia v1.8.* or older. Use at least Julia v1.9.
# For each user defined data field we need one t8_vtk_data_field_t variable.
vtk_data = t8_vtk_data_field_t(T8_VTK_SCALAR, # Set the type of this variable. Since we have one value per element, we pick T8_VTK_SCALAR.
NTuple{8192, Cchar}(rpad("Element volume\0", 8192, ' ')), # The name of the field as should be written to the file.
pointer(element_volumes))
# We set the type of this variable. Since we have one value per element, we pick
# T8_VTK_SCALAR.
# We also set the name of the field as should be written to the file.
vtk_data = [t8_vtk_data_field_t(T8_VTK_SCALAR, "Element volume", element_volumes)]

# To write user defined data, we need to extended output function
# t8_forest_vtk_write_file from t8_forest_vtk.h. Despite writin user data,
Expand All @@ -208,7 +209,7 @@ function t8_step5_output_data_to_vtu(forest, element_data, prefix)
write_ghosts = 0
t8_forest_write_vtk_ext(forest, prefix, write_treeid, write_mpirank,
write_level, write_element_id, write_ghosts,
0, 0, num_data, Ref(vtk_data))
0, 0, num_data, pointer(vtk_data))
end

# The prefix for our output files.
Expand Down Expand Up @@ -277,11 +278,9 @@ if t8_forest_get_num_ghosts(forest) > 0
end

# Output the volume data to vtu.
if !(CI_ON_WINDOWS || CI_ON_MACOS)
t8_step5_output_data_to_vtu(forest, element_data, prefix_forest_with_data)
t8_global_productionf(" [step5] Wrote forest and volume data to %s*.\n",
prefix_forest_with_data)
end
t8_step5_output_data_to_vtu(forest, element_data, prefix_forest_with_data)
t8_global_productionf(" [step5] Wrote forest and volume data to %s*.\n",
prefix_forest_with_data)

#
# Clean-up.
Expand Down
18 changes: 5 additions & 13 deletions examples/t8_step6_stencil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,9 @@ function t8_step6_output_data_to_vtu(forest, element_data, prefix)

# WARNING: This code hangs for Julia v1.8.* or older. Use at least Julia v1.9.
vtk_data = [
t8_vtk_data_field_t(T8_VTK_SCALAR,
NTuple{8192, Cchar}(rpad("height\0", 8192, ' ')),
pointer(heights)),
t8_vtk_data_field_t(T8_VTK_SCALAR,
NTuple{8192, Cchar}(rpad("schlieren\0", 8192, ' ')),
pointer(schlieren)),
t8_vtk_data_field_t(T8_VTK_SCALAR,
NTuple{8192, Cchar}(rpad("curvature\0", 8192, ' ')),
pointer(curvature))
t8_vtk_data_field_t(T8_VTK_SCALAR, "height", heights),
t8_vtk_data_field_t(T8_VTK_SCALAR, "schlieren", schlieren),
t8_vtk_data_field_t(T8_VTK_SCALAR, "curvature", curvature)
]

# The number of user defined data fields to write.
Expand Down Expand Up @@ -402,10 +396,8 @@ t8_step6_exchange_ghost_data(forest, element_data)
t8_step6_compute_stencil(forest, element_data)

# Output the data to vtu files.
if !(CI_ON_WINDOWS || CI_ON_MACOS)
t8_step6_output_data_to_vtu(forest, element_data, prefix_forest_with_data)
t8_global_productionf(" Wrote forest and data to %s*.\n", prefix_forest_with_data)
end
t8_step6_output_data_to_vtu(forest, element_data, prefix_forest_with_data)
t8_global_productionf(" Wrote forest and data to %s*.\n", prefix_forest_with_data)

#
# Clean-up
Expand Down
8 changes: 4 additions & 4 deletions src/Libt8.jl

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manually changing Libt8.jl means that following the steps in dev/ produces another Libt8.jl, which is not ideal. Could we instead apply the fixes in dev/fixes.sh?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @JoshuaLampert! Marking as "ready for review" was a mistake!

Yes, this has to go to fixes.sh, but I wanted to discuss first if there are better options.

Original file line number Diff line number Diff line change
Expand Up @@ -12866,9 +12866,9 @@ A data field for VTK output. This struct is used to store data that is written t
| type | Describes of which type the data array is |
| description | String that describes the data. |
"""
struct t8_vtk_data_field_t
struct t8_vtk_data_field_t{BUFSIZ}
type::t8_vtk_data_type_t
description::NTuple{8192, Cchar}
description::NTuple{BUFSIZ, Cchar}
data::Ptr{Cdouble}
end

Expand All @@ -12880,8 +12880,8 @@ end
int t8_forest_write_vtk_ext (t8_forest_t forest, const char *fileprefix, const int write_treeid, const int write_mpirank, const int write_level, const int write_element_id, const int write_ghosts, const int write_curved, int do_not_use_API, const int num_data, t8_vtk_data_field_t *data);
```
"""
function t8_forest_write_vtk_ext(forest, fileprefix, write_treeid, write_mpirank, write_level, write_element_id, write_ghosts, write_curved, do_not_use_API, num_data, data)
@ccall libt8.t8_forest_write_vtk_ext(forest::t8_forest_t, fileprefix::Cstring, write_treeid::Cint, write_mpirank::Cint, write_level::Cint, write_element_id::Cint, write_ghosts::Cint, write_curved::Cint, do_not_use_API::Cint, num_data::Cint, data::Ptr{t8_vtk_data_field_t})::Cint
function t8_forest_write_vtk_ext(forest, fileprefix, write_treeid, write_mpirank, write_level, write_element_id, write_ghosts, write_curved, do_not_use_API, num_data, data::Ptr{DataFieldType}) where DataFieldType
@ccall libt8.t8_forest_write_vtk_ext(forest::t8_forest_t, fileprefix::Cstring, write_treeid::Cint, write_mpirank::Cint, write_level::Cint, write_element_id::Cint, write_ghosts::Cint, write_curved::Cint, do_not_use_API::Cint, num_data::Cint, data::Ptr{DataFieldType})::Cint
end

"""
Expand Down
20 changes: 20 additions & 0 deletions src/T8code.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,26 @@ macro T8_ASSERT(q)
:($(esc(q)) ? nothing : throw(AssertionError($(string(q)))))
end

# platform specific BUFSIZ used in t8_vtk_data_field_t
# TODO: Just a guess!
if Sys.isapple()
const T8_BUFSIZ = 1024
elseif Sys.iswindows()
const T8_BUFSIZ = 512
else
const T8_BUFSIZ = 8192
end
Comment on lines +261 to +269

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual problem.

t8code defines a t8_vtk_data_field_t struct, whose member description has fixed width BUFSIZ, which is platform dependent.
https://github.com/DLR-AMR/t8code/blob/077b6414c3a0c4b0d0f4b38f3118a0f5f2c142e2/src/t8_vtk/t8_vtk.h#L69

The value of BUFSIZ is determined during compilation. I checked the BinaryBuilder build for Windows and mac and got 512 and 1024, respectively.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all: Thanks A LOT @benegee for identifying and fixing this issue! 👍 I can imagine this was not that much fun to find out 🙈

The CI seems to confirm you found the correct root of the crashing vtk output. That being said, I am not sure this is the correct way to fix it. Do you happen to have an idea why we overwrite the BUFSIZ like this in t8code? Seems like bad style to me, maybe we should replace it in t8code by some custom macro like T8_BUFSIZ?

And admittedly, I don't fully understand yet why the lines above fix the issue 🤔 because t8code seems to always set BUFSIZ to 8192m but you now define a T8_BUFSIZ which is platform-dependent. How does that solve anything? 😄

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @spenke91 !

The displayed code is a bit misleading. This is just a local variable with "guessed" values for different platforms. I use it here

T8code.jl/src/T8code.jl

Lines 274 to 280 in cf650db

function Libt8.t8_vtk_data_field_t(type, description::String, data)
@info "external ctor", T8_BUFSIZ
return t8_vtk_data_field_t(type,
NTuple{T8_BUFSIZ, Cchar}(rpad(description * "\0", T8_BUFSIZ,
' ')),
pointer(data))
end
to create t8_vtk_data_field_t structs, which should hopefully match the size in den underlying t8code library.

This is a fix because we used a hard-coded value of 8192 before

NTuple{8192, Cchar}(rpad("Element volume\0", 8192, ' ')), # The name of the field as should be written to the file.
, which is only correct for Linux.

In fact, if t8code would use a custom value instead of BUFSIZ from stdio.h, and make this value accessible, it would be more portable.


# convenience constructor
# - adds 0 termination and padding to description string
# - takes pointer of data
function Libt8.t8_vtk_data_field_t(type, description::String, data)
return t8_vtk_data_field_t(type,
NTuple{T8_BUFSIZ, Cchar}(rpad(description * "\0", T8_BUFSIZ,
' ')),
pointer(data))
end

function t8_free(ptr)
Libt8.sc_free(t8_get_package_id(), ptr)
end
Expand Down
5 changes: 0 additions & 5 deletions test/test_all.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ MPI.Init()

comm = MPI.COMM_WORLD

# Check whether we run CI in the cloud with Windows or Mac, see also
# https://docs.github.com/en/actions/learn-github-actions/environment-variables
CI_ON_WINDOWS = (get(ENV, "GITHUB_ACTIONS", false) == "true") && Sys.iswindows()
CI_ON_MACOS = (get(ENV, "GITHUB_ACTIONS", false) == "true") && Sys.isapple()

@testset "init" begin
include("test_init.jl")
end
Expand Down
7 changes: 2 additions & 5 deletions test/test_examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ end
include("../examples/t8_step4_partition_balance_ghost.jl")
end

# Unfortunately, step 5 and step 6 currently crash (1.) in Windows, (2.) in MacOS,
# and (3.) with Julia older than 1.9, see related issues
# https://github.com/DLR-AMR/T8code.jl/issues/26,
# https://github.com/DLR-AMR/T8code.jl/issues/30,
# https://github.com/DLR-AMR/T8code.jl/issues/104.
# Step 5 and step 6 crash with Julia older than 1.9, see related issue
# https://github.com/DLR-AMR/T8code.jl/issues/26

@testset "t8_step5_element_data" begin
include("../examples/t8_step5_element_data.jl")
Expand Down
Loading