From 445f1a2b8f96ad1410b6b97be7d584ea7f8c8d24 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Thu, 21 Nov 2024 21:08:18 +0100 Subject: [PATCH 01/26] Adding cleanup logic. --- Project.toml | 2 +- src/T8code.jl | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index c524d5c..f445c98 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "T8code" uuid = "d0cc0030-9a40-4274-8435-baadcfd54fa1" authors = ["Johannes Markert "] -version = "0.7.0" +version = "0.8.0" [deps] CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82" diff --git a/src/T8code.jl b/src/T8code.jl index 1edce31..10df10b 100644 --- a/src/T8code.jl +++ b/src/T8code.jl @@ -1,5 +1,7 @@ module T8code +using MPI + using Reexport: @reexport using Libdl: Libdl @@ -157,6 +159,84 @@ not a system-provided `t8code` installation. In this case, T8code.jl is not usab preferences_set_correctly() = !(_PREFERENCE_LIBT8 == "t8code_jll" && MPIPreferences.binary == "system") +# Minimal reference tracker holding active t8code related objects +# created throughout the life time of a Julia session. t8code objects +# should remove themselves from the tracker when they get finalized. +if !@isdefined(T8CODE_OBJECT_TRACKER) + T8CODE_OBJECT_TRACKER = Dict() +end + +""" + T8codeForestWrapper + +Lightweight `t8_forest_t` pointer wrapper which helps to free +resources allocated by t8code in an orderly fashion. + +When initialized with a t8code forest pointer the wrapper +registers itself with a t8code object tracker called `__T8CODE_OBJECT_TRACKER`. + +In serial mode the wrapper and in consequence the t8code forest +can be finalized immediately whenever Julia's garbage collector sees fit. + +In (MPI) parallel mode the wrapper (and the t8code forest) is kept till the end +of the session or when finalized explicitly. At the end of the session (resp. +when the program shuts down) the object tracker finalizes all registered t8code +objects in sync with all MPI ranks. This is necessary since t8code internally +allocates MPI shared arrays. See `src/auxiliary/t8code.jl` for the finalization +code when Trixi is shutting down. +""" +mutable struct ForestWrapper + pointer::Ptr{t8_forest} # cpointer to t8code forest + unique_id::UInt + + function ForestWrapper(pointer::Ptr{t8_forest}) + wrapper = new(pointer) + + # Compute the unique id from the T8codeForestWrapper object. + wrapper.unique_id = pointer_from_objref(wrapper) + + if MPI.Comm_size(MPI.Comm(t8_forest_get_mpicomm(pointer))) > 1 + # Make sure the unique id is identical for each MPI rank. + wrapper.unique_id = MPI.bcast(wrapper.unique_id, MPI.Comm(t8_forest_get_mpicomm(pointer))) + end + + finalizer(wrapper) do wrapper + # When finalizing, `forest`, `scheme`, `cmesh`, and `geometry` are + # also cleaned up from within `t8code`. The cleanup code for + # `cmesh` does some MPI calls for deallocating shared memory + # arrays. Due to garbage collection in Julia the order of shutdown + # is not deterministic. Hence, deterministic finalization is necessary in + # order to avoid MPI-related error output when closing the Julia + # program/session. + t8_forest_unref(Ref(wrapper.pointer)) + + # Deregister from the object tracker. + delete!(T8CODE_OBJECT_TRACKER, wrapper.unique_id) + end + + # Register the T8codeForestWrapper with the object tracker. + T8CODE_OBJECT_TRACKER[wrapper.unique_id] = wrapper + end +end + +function clean_up() + # Finalize all registered t8code objects before MPI shuts down. + while length(T8CODE_OBJECT_TRACKER) > 0 + unique_id = first(T8CODE_OBJECT_TRACKER).first + + forest_wrapper = T8CODE_OBJECT_TRACKER[unique_id] + + # Make sure all MPI ranks finalize the same object. + if MPI.Comm_size(MPI.Comm(t8_forest_get_mpicomm(forest_wrapper.pointer))) > 1 + unique_id = MPI.bcast(unique_id, MPI.Comm(t8_forest_get_mpicomm(forest_wrapper.pointer))) + end + + # Finalize the object. The object deregisters itself from the + # object tracker automatically. + finalize(forest_wrapper) + end +end + const T8_QUAD_MAXLEVEL = 30 const T8_HEX_MAXLEVEL = 19 From 20e01d9722636c42c5a87bfe74085865f521822f Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 22 Nov 2024 13:29:50 +0100 Subject: [PATCH 02/26] Applying review comments and adding a test. --- src/T8code.jl | 18 ++++++++---------- test/test_all.jl | 4 ++++ test/test_forestwrapper.jl | 26 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 test/test_forestwrapper.jl diff --git a/src/T8code.jl b/src/T8code.jl index 10df10b..bb91359 100644 --- a/src/T8code.jl +++ b/src/T8code.jl @@ -167,13 +167,13 @@ if !@isdefined(T8CODE_OBJECT_TRACKER) end """ - T8codeForestWrapper + ForestWrapper Lightweight `t8_forest_t` pointer wrapper which helps to free resources allocated by t8code in an orderly fashion. When initialized with a t8code forest pointer the wrapper -registers itself with a t8code object tracker called `__T8CODE_OBJECT_TRACKER`. +registers itself with a t8code object tracker called `T8CODE_OBJECT_TRACKER`. In serial mode the wrapper and in consequence the t8code forest can be finalized immediately whenever Julia's garbage collector sees fit. @@ -182,22 +182,20 @@ In (MPI) parallel mode the wrapper (and the t8code forest) is kept till the end of the session or when finalized explicitly. At the end of the session (resp. when the program shuts down) the object tracker finalizes all registered t8code objects in sync with all MPI ranks. This is necessary since t8code internally -allocates MPI shared arrays. See `src/auxiliary/t8code.jl` for the finalization -code when Trixi is shutting down. +allocates MPI shared arrays. """ mutable struct ForestWrapper pointer::Ptr{t8_forest} # cpointer to t8code forest - unique_id::UInt function ForestWrapper(pointer::Ptr{t8_forest}) wrapper = new(pointer) - # Compute the unique id from the T8codeForestWrapper object. - wrapper.unique_id = pointer_from_objref(wrapper) + # Compute a unique id from the ForestWrapper object. + unique_id = UInt64(pointer_from_objref(wrapper)) if MPI.Comm_size(MPI.Comm(t8_forest_get_mpicomm(pointer))) > 1 # Make sure the unique id is identical for each MPI rank. - wrapper.unique_id = MPI.bcast(wrapper.unique_id, MPI.Comm(t8_forest_get_mpicomm(pointer))) + unique_id = MPI.bcast(unique_id, MPI.Comm(t8_forest_get_mpicomm(pointer))) end finalizer(wrapper) do wrapper @@ -211,11 +209,11 @@ mutable struct ForestWrapper t8_forest_unref(Ref(wrapper.pointer)) # Deregister from the object tracker. - delete!(T8CODE_OBJECT_TRACKER, wrapper.unique_id) + delete!(T8CODE_OBJECT_TRACKER, unique_id) end # Register the T8codeForestWrapper with the object tracker. - T8CODE_OBJECT_TRACKER[wrapper.unique_id] = wrapper + T8CODE_OBJECT_TRACKER[unique_id] = wrapper end end diff --git a/test/test_all.jl b/test/test_all.jl index 88f6f7e..c093ac3 100644 --- a/test/test_all.jl +++ b/test/test_all.jl @@ -23,6 +23,10 @@ end end end +@testset "forestwrapper" begin + include("test_forestwrapper.jl") +end + @testset "cmesh" begin include("cmesh/test_readmshfile.jl") end diff --git a/test/test_forestwrapper.jl b/test/test_forestwrapper.jl new file mode 100644 index 0000000..8e7a221 --- /dev/null +++ b/test/test_forestwrapper.jl @@ -0,0 +1,26 @@ +@testset "test forestwrapper" begin + + # Clean up t8code before MPI shuts down. + MPI.add_finalize_hook!() do + T8code.clean_up() + T8code.Libt8.sc_finalize() + end + + # Create a forest and wrap by `ForestWrapper` + scheme = t8_scheme_new_default_cxx() + cmesh = t8_cmesh_new_hypercube(T8_ECLASS_QUAD, comm, 0, 0, 0) + forest = t8_forest_new_uniform(cmesh, scheme, 0, 0, comm) + wrapper_A = T8code.ForestWrapper(forest) + + # Create another forest and wrap by `ForestWrapper` + scheme = t8_scheme_new_default_cxx() + cmesh = t8_cmesh_new_hypercube(T8_ECLASS_TRIANGLE, comm, 0, 0, 0) + forest = t8_forest_new_uniform(cmesh, scheme, 0, 0, comm) + wrapper_B = T8code.ForestWrapper(forest) + + # Finalize the first wrapper. + finalize(wrapper_A) + + # The second wrapper should be finalized automatically when Julia shuts down. + # ... finalize(wrapper_B) ... +end From 602954a327ed99e309dd05aa81b132eb88b6a2db Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 22 Nov 2024 13:36:22 +0100 Subject: [PATCH 03/26] Applied review suggestions. --- src/T8code.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/T8code.jl b/src/T8code.jl index bb91359..d316e5e 100644 --- a/src/T8code.jl +++ b/src/T8code.jl @@ -163,7 +163,7 @@ preferences_set_correctly() = !(_PREFERENCE_LIBT8 == "t8code_jll" && # created throughout the life time of a Julia session. t8code objects # should remove themselves from the tracker when they get finalized. if !@isdefined(T8CODE_OBJECT_TRACKER) - T8CODE_OBJECT_TRACKER = Dict() + T8CODE_OBJECT_TRACKER = Dict{UInt64, ForestWrapper}() end """ @@ -214,6 +214,8 @@ mutable struct ForestWrapper # Register the T8codeForestWrapper with the object tracker. T8CODE_OBJECT_TRACKER[unique_id] = wrapper + + return wrapper end end From 487fbc3e9c655e05406b9f2b99b86d5f185f8363 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 22 Nov 2024 13:39:42 +0100 Subject: [PATCH 04/26] Adding format utility. --- utils/trixi-format.jl | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 utils/trixi-format.jl diff --git a/utils/trixi-format.jl b/utils/trixi-format.jl new file mode 100755 index 0000000..59021c2 --- /dev/null +++ b/utils/trixi-format.jl @@ -0,0 +1,31 @@ +#!/usr/bin/env julia + +using Pkg +Pkg.activate(; temp = true, io = devnull) +Pkg.add(PackageSpec(name = "JuliaFormatter", version = "1.0.60"); preserve = PRESERVE_ALL, + io = devnull) + +using JuliaFormatter: format + +function main() + # Show help + if "-h" in ARGS || "--help" in ARGS + println("usage: trixi-format.jl PATH [PATH...]") + println() + println("positional arguments:") + println() + println(" PATH One or more paths (directories or files) to format. Default: '.'") + return nothing + end + + # Set default path if none is given on command line + if isempty(ARGS) + paths = String["."] + else + paths = ARGS + end + + return format(paths) +end + +main() From ba5ab1021bd685f0e5b97f092efcab7e262d0ea0 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 22 Nov 2024 13:41:24 +0100 Subject: [PATCH 05/26] Renamed formatter. --- utils/format.jl | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 utils/format.jl diff --git a/utils/format.jl b/utils/format.jl new file mode 100755 index 0000000..59021c2 --- /dev/null +++ b/utils/format.jl @@ -0,0 +1,31 @@ +#!/usr/bin/env julia + +using Pkg +Pkg.activate(; temp = true, io = devnull) +Pkg.add(PackageSpec(name = "JuliaFormatter", version = "1.0.60"); preserve = PRESERVE_ALL, + io = devnull) + +using JuliaFormatter: format + +function main() + # Show help + if "-h" in ARGS || "--help" in ARGS + println("usage: trixi-format.jl PATH [PATH...]") + println() + println("positional arguments:") + println() + println(" PATH One or more paths (directories or files) to format. Default: '.'") + return nothing + end + + # Set default path if none is given on command line + if isempty(ARGS) + paths = String["."] + else + paths = ARGS + end + + return format(paths) +end + +main() From 0888b79aeca3af9c78e87a4ae05aaa79484372e6 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 22 Nov 2024 13:41:39 +0100 Subject: [PATCH 06/26] Removed trixi formatter. --- utils/trixi-format.jl | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100755 utils/trixi-format.jl diff --git a/utils/trixi-format.jl b/utils/trixi-format.jl deleted file mode 100755 index 59021c2..0000000 --- a/utils/trixi-format.jl +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env julia - -using Pkg -Pkg.activate(; temp = true, io = devnull) -Pkg.add(PackageSpec(name = "JuliaFormatter", version = "1.0.60"); preserve = PRESERVE_ALL, - io = devnull) - -using JuliaFormatter: format - -function main() - # Show help - if "-h" in ARGS || "--help" in ARGS - println("usage: trixi-format.jl PATH [PATH...]") - println() - println("positional arguments:") - println() - println(" PATH One or more paths (directories or files) to format. Default: '.'") - return nothing - end - - # Set default path if none is given on command line - if isempty(ARGS) - paths = String["."] - else - paths = ARGS - end - - return format(paths) -end - -main() From e4450685aff87296d6bc4c60299bd898ec40b5d4 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 22 Nov 2024 13:44:15 +0100 Subject: [PATCH 07/26] Limited folders to format. --- utils/format.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/format.jl b/utils/format.jl index 59021c2..ddebbed 100755 --- a/utils/format.jl +++ b/utils/format.jl @@ -20,7 +20,7 @@ function main() # Set default path if none is given on command line if isempty(ARGS) - paths = String["."] + paths = String["./src/T8code.jl", "./test"] else paths = ARGS end From e07ceeb394a2cef4b8e18f926a12191ceed5f084 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 22 Nov 2024 13:44:23 +0100 Subject: [PATCH 08/26] Applie formatter. --- src/T8code.jl | 5 +++-- test/cmesh/test_readmshfile.jl | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/T8code.jl b/src/T8code.jl index d316e5e..eee1b4f 100644 --- a/src/T8code.jl +++ b/src/T8code.jl @@ -214,7 +214,7 @@ mutable struct ForestWrapper # Register the T8codeForestWrapper with the object tracker. T8CODE_OBJECT_TRACKER[unique_id] = wrapper - + return wrapper end end @@ -228,7 +228,8 @@ function clean_up() # Make sure all MPI ranks finalize the same object. if MPI.Comm_size(MPI.Comm(t8_forest_get_mpicomm(forest_wrapper.pointer))) > 1 - unique_id = MPI.bcast(unique_id, MPI.Comm(t8_forest_get_mpicomm(forest_wrapper.pointer))) + unique_id = MPI.bcast(unique_id, + MPI.Comm(t8_forest_get_mpicomm(forest_wrapper.pointer))) end # Finalize the object. The object deregisters itself from the diff --git a/test/cmesh/test_readmshfile.jl b/test/cmesh/test_readmshfile.jl index 373f8de..94d6729 100644 --- a/test/cmesh/test_readmshfile.jl +++ b/test/cmesh/test_readmshfile.jl @@ -10,7 +10,7 @@ function t8_supported_msh_file(cmesh) [4, 0], [1, 2], [3, 2], - [2, 4], + [2, 4] ] # 0-based indexing @@ -18,14 +18,14 @@ function t8_supported_msh_file(cmesh) [0, 1, 3], [1, 4, 3], [1, 2, 4], - [3, 4, 5], + [3, 4, 5] ] face_neigh_elem = [ [1, -1, -1], [3, 0, 2], [-1, 1, -1], - [-1, -1, 1], + [-1, -1, 1] ] @assert cmesh != C_NULL From 0e629e2b5049d48c8467f21ec1c0c56bbc3723ed Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 22 Nov 2024 13:48:20 +0100 Subject: [PATCH 09/26] Fixed error in code. --- src/T8code.jl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/T8code.jl b/src/T8code.jl index eee1b4f..0ca7245 100644 --- a/src/T8code.jl +++ b/src/T8code.jl @@ -159,13 +159,6 @@ not a system-provided `t8code` installation. In this case, T8code.jl is not usab preferences_set_correctly() = !(_PREFERENCE_LIBT8 == "t8code_jll" && MPIPreferences.binary == "system") -# Minimal reference tracker holding active t8code related objects -# created throughout the life time of a Julia session. t8code objects -# should remove themselves from the tracker when they get finalized. -if !@isdefined(T8CODE_OBJECT_TRACKER) - T8CODE_OBJECT_TRACKER = Dict{UInt64, ForestWrapper}() -end - """ ForestWrapper @@ -238,6 +231,13 @@ function clean_up() end end +# Minimal reference tracker holding active t8code related objects +# created throughout the life time of a Julia session. t8code objects +# should remove themselves from the tracker when they get finalized. +if !@isdefined(T8CODE_OBJECT_TRACKER) + T8CODE_OBJECT_TRACKER = Dict{UInt64, ForestWrapper}() +end + const T8_QUAD_MAXLEVEL = 30 const T8_HEX_MAXLEVEL = 19 From 5e52f481c961e50aefafe764eab667854c87882f Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 22 Nov 2024 13:53:51 +0100 Subject: [PATCH 10/26] Updated formatter. --- .github/workflows/FormatCheck.yml | 2 +- utils/format.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/FormatCheck.yml b/.github/workflows/FormatCheck.yml index e9f32c1..36673c0 100644 --- a/.github/workflows/FormatCheck.yml +++ b/.github/workflows/FormatCheck.yml @@ -23,7 +23,7 @@ jobs: - uses: julia-actions/cache@v2 - name: Install JuliaFormatter and format run: | - julia -e 'using Pkg; Pkg.add(PackageSpec(name = "JuliaFormatter", version="1.0.45"))' + julia -e 'using Pkg; Pkg.add(PackageSpec(name = "JuliaFormatter", version="1.0.6"))' julia -e 'using JuliaFormatter; format(["examples", "src/T8code.jl", "test"])' - name: Format check run: | diff --git a/utils/format.jl b/utils/format.jl index ddebbed..ae02dc7 100755 --- a/utils/format.jl +++ b/utils/format.jl @@ -20,7 +20,7 @@ function main() # Set default path if none is given on command line if isempty(ARGS) - paths = String["./src/T8code.jl", "./test"] + paths = String["./src/T8code.jl", "./test", "./examples"] else paths = ARGS end From bf3493c89c2bbe0ba0d84ceca0c7142a1d65aa74 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 22 Nov 2024 13:54:09 +0100 Subject: [PATCH 11/26] Formatted examples. --- examples/t8_step6_stencil.jl | 2 +- examples/t8_tutorial_build_cmesh.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/t8_step6_stencil.jl b/examples/t8_step6_stencil.jl index 265a62d..c47e6f3 100644 --- a/examples/t8_step6_stencil.jl +++ b/examples/t8_step6_stencil.jl @@ -348,7 +348,7 @@ function t8_step6_output_data_to_vtu(forest, element_data, prefix) pointer(schlieren)), t8_vtk_data_field_t(T8_VTK_SCALAR, NTuple{8192, Cchar}(rpad("curvature\0", 8192, ' ')), - pointer(curvature)), + pointer(curvature)) ] # The number of user defined data fields to write. diff --git a/examples/t8_tutorial_build_cmesh.jl b/examples/t8_tutorial_build_cmesh.jl index 25fad15..d886970 100644 --- a/examples/t8_tutorial_build_cmesh.jl +++ b/examples/t8_tutorial_build_cmesh.jl @@ -154,7 +154,7 @@ function t8_cmesh_new_periodic_hybrid_2d(comm) 1, 1, 0, 0.5, 0.5, 0, # tree 5, triangle 1, 1, 0, - 0.5, 1, 0, + 0.5, 1, 0 ] # 2. Initialization of the mesh. From 29a8439be3fc96b54d2bab5c1602f971f6776cd9 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 22 Nov 2024 13:55:55 +0100 Subject: [PATCH 12/26] Revised package version. --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index f445c98..80896a3 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "T8code" uuid = "d0cc0030-9a40-4274-8435-baadcfd54fa1" authors = ["Johannes Markert "] -version = "0.8.0" +version = "0.7.1" [deps] CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82" From 58f629a519053b4ba9d510031d208a2ae237a7da Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 22 Nov 2024 15:09:02 +0100 Subject: [PATCH 13/26] Downgraded formatter. --- examples/t8_step6_stencil.jl | 2 +- examples/t8_tutorial_build_cmesh.jl | 2 +- test/cmesh/test_readmshfile.jl | 6 +++--- utils/format.jl | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/t8_step6_stencil.jl b/examples/t8_step6_stencil.jl index c47e6f3..265a62d 100644 --- a/examples/t8_step6_stencil.jl +++ b/examples/t8_step6_stencil.jl @@ -348,7 +348,7 @@ function t8_step6_output_data_to_vtu(forest, element_data, prefix) pointer(schlieren)), t8_vtk_data_field_t(T8_VTK_SCALAR, NTuple{8192, Cchar}(rpad("curvature\0", 8192, ' ')), - pointer(curvature)) + pointer(curvature)), ] # The number of user defined data fields to write. diff --git a/examples/t8_tutorial_build_cmesh.jl b/examples/t8_tutorial_build_cmesh.jl index d886970..25fad15 100644 --- a/examples/t8_tutorial_build_cmesh.jl +++ b/examples/t8_tutorial_build_cmesh.jl @@ -154,7 +154,7 @@ function t8_cmesh_new_periodic_hybrid_2d(comm) 1, 1, 0, 0.5, 0.5, 0, # tree 5, triangle 1, 1, 0, - 0.5, 1, 0 + 0.5, 1, 0, ] # 2. Initialization of the mesh. diff --git a/test/cmesh/test_readmshfile.jl b/test/cmesh/test_readmshfile.jl index 94d6729..373f8de 100644 --- a/test/cmesh/test_readmshfile.jl +++ b/test/cmesh/test_readmshfile.jl @@ -10,7 +10,7 @@ function t8_supported_msh_file(cmesh) [4, 0], [1, 2], [3, 2], - [2, 4] + [2, 4], ] # 0-based indexing @@ -18,14 +18,14 @@ function t8_supported_msh_file(cmesh) [0, 1, 3], [1, 4, 3], [1, 2, 4], - [3, 4, 5] + [3, 4, 5], ] face_neigh_elem = [ [1, -1, -1], [3, 0, 2], [-1, 1, -1], - [-1, -1, 1] + [-1, -1, 1], ] @assert cmesh != C_NULL diff --git a/utils/format.jl b/utils/format.jl index ae02dc7..e58d332 100755 --- a/utils/format.jl +++ b/utils/format.jl @@ -2,7 +2,7 @@ using Pkg Pkg.activate(; temp = true, io = devnull) -Pkg.add(PackageSpec(name = "JuliaFormatter", version = "1.0.60"); preserve = PRESERVE_ALL, +Pkg.add(PackageSpec(name = "JuliaFormatter", version = "1.0.45"); preserve = PRESERVE_ALL, io = devnull) using JuliaFormatter: format From 04b7066ad7ceb7b92bb7d51fef2013024c2ebf39 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 22 Nov 2024 15:14:44 +0100 Subject: [PATCH 14/26] Fixed version number of formatter. --- .github/workflows/FormatCheck.yml | 2 +- utils/format.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/FormatCheck.yml b/.github/workflows/FormatCheck.yml index 36673c0..c019cfd 100644 --- a/.github/workflows/FormatCheck.yml +++ b/.github/workflows/FormatCheck.yml @@ -23,7 +23,7 @@ jobs: - uses: julia-actions/cache@v2 - name: Install JuliaFormatter and format run: | - julia -e 'using Pkg; Pkg.add(PackageSpec(name = "JuliaFormatter", version="1.0.6"))' + julia -e 'using Pkg; Pkg.add(PackageSpec(name = "JuliaFormatter", version="1.0.60"))' julia -e 'using JuliaFormatter; format(["examples", "src/T8code.jl", "test"])' - name: Format check run: | diff --git a/utils/format.jl b/utils/format.jl index e58d332..ae02dc7 100755 --- a/utils/format.jl +++ b/utils/format.jl @@ -2,7 +2,7 @@ using Pkg Pkg.activate(; temp = true, io = devnull) -Pkg.add(PackageSpec(name = "JuliaFormatter", version = "1.0.45"); preserve = PRESERVE_ALL, +Pkg.add(PackageSpec(name = "JuliaFormatter", version = "1.0.60"); preserve = PRESERVE_ALL, io = devnull) using JuliaFormatter: format From 37f2524418815111111c0701656e55fc9aa327b7 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 22 Nov 2024 15:15:23 +0100 Subject: [PATCH 15/26] Applied formater with version x.x.60. --- examples/t8_step6_stencil.jl | 2 +- examples/t8_tutorial_build_cmesh.jl | 2 +- test/cmesh/test_readmshfile.jl | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/t8_step6_stencil.jl b/examples/t8_step6_stencil.jl index 265a62d..c47e6f3 100644 --- a/examples/t8_step6_stencil.jl +++ b/examples/t8_step6_stencil.jl @@ -348,7 +348,7 @@ function t8_step6_output_data_to_vtu(forest, element_data, prefix) pointer(schlieren)), t8_vtk_data_field_t(T8_VTK_SCALAR, NTuple{8192, Cchar}(rpad("curvature\0", 8192, ' ')), - pointer(curvature)), + pointer(curvature)) ] # The number of user defined data fields to write. diff --git a/examples/t8_tutorial_build_cmesh.jl b/examples/t8_tutorial_build_cmesh.jl index 25fad15..d886970 100644 --- a/examples/t8_tutorial_build_cmesh.jl +++ b/examples/t8_tutorial_build_cmesh.jl @@ -154,7 +154,7 @@ function t8_cmesh_new_periodic_hybrid_2d(comm) 1, 1, 0, 0.5, 0.5, 0, # tree 5, triangle 1, 1, 0, - 0.5, 1, 0, + 0.5, 1, 0 ] # 2. Initialization of the mesh. diff --git a/test/cmesh/test_readmshfile.jl b/test/cmesh/test_readmshfile.jl index 373f8de..94d6729 100644 --- a/test/cmesh/test_readmshfile.jl +++ b/test/cmesh/test_readmshfile.jl @@ -10,7 +10,7 @@ function t8_supported_msh_file(cmesh) [4, 0], [1, 2], [3, 2], - [2, 4], + [2, 4] ] # 0-based indexing @@ -18,14 +18,14 @@ function t8_supported_msh_file(cmesh) [0, 1, 3], [1, 4, 3], [1, 2, 4], - [3, 4, 5], + [3, 4, 5] ] face_neigh_elem = [ [1, -1, -1], [3, 0, 2], [-1, 1, -1], - [-1, -1, 1], + [-1, -1, 1] ] @assert cmesh != C_NULL From 0b16ec8fa68cdbe46fb2597f2829e6e0cbcbc0d3 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 22 Nov 2024 15:20:29 +0100 Subject: [PATCH 16/26] Fixing compats. --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 80896a3..d2c4ffe 100644 --- a/Project.toml +++ b/Project.toml @@ -16,7 +16,7 @@ t8code_jll = "4ee9bed8-4011-53f7-90c2-22363c2f500d" [compat] CEnum = "0.4, 0.5" Libdl = "1" -MPI = "0.20" +MPI = "0.20.6" MPIPreferences = "0.1.3" Preferences = "1.2" Reexport = "0.2, 1.0" From 19579bab33c2f8c2646e5b922c39a86c8acf6bcd Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 22 Nov 2024 15:31:36 +0100 Subject: [PATCH 17/26] Bumped MPIPreferences. --- Project.toml | 2 +- test/Project.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index d2c4ffe..af39d89 100644 --- a/Project.toml +++ b/Project.toml @@ -17,7 +17,7 @@ t8code_jll = "4ee9bed8-4011-53f7-90c2-22363c2f500d" CEnum = "0.4, 0.5" Libdl = "1" MPI = "0.20.6" -MPIPreferences = "0.1.3" +MPIPreferences = "0.1.4" Preferences = "1.2" Reexport = "0.2, 1.0" UUIDs = "1" diff --git a/test/Project.toml b/test/Project.toml index b3d2bde..b736c9d 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -6,6 +6,6 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] Aqua = "0.7, 0.8" -MPI = "0.20" -MPIPreferences = "0.1.3" +MPI = "0.20.6" +MPIPreferences = "0.1.4" Test = "1" From 89c95c627f6f7e55ff4e7e40cd42681169e93fb6 Mon Sep 17 00:00:00 2001 From: Johannes Markert <10619309+jmark@users.noreply.github.com> Date: Fri, 22 Nov 2024 15:36:45 +0100 Subject: [PATCH 18/26] Update Project.toml Co-authored-by: Joshua Lampert <51029046+JoshuaLampert@users.noreply.github.com> --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index af39d89..7f6cc42 100644 --- a/Project.toml +++ b/Project.toml @@ -17,7 +17,7 @@ t8code_jll = "4ee9bed8-4011-53f7-90c2-22363c2f500d" CEnum = "0.4, 0.5" Libdl = "1" MPI = "0.20.6" -MPIPreferences = "0.1.4" +MPIPreferences = "0.1.6" Preferences = "1.2" Reexport = "0.2, 1.0" UUIDs = "1" From b186ba1cce8f8edcfd11bc01a6fa75d5b31c4ae0 Mon Sep 17 00:00:00 2001 From: Johannes Markert <10619309+jmark@users.noreply.github.com> Date: Fri, 22 Nov 2024 15:36:56 +0100 Subject: [PATCH 19/26] Update test/Project.toml Co-authored-by: Joshua Lampert <51029046+JoshuaLampert@users.noreply.github.com> --- test/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Project.toml b/test/Project.toml index b736c9d..8cdd8fe 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -7,5 +7,5 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] Aqua = "0.7, 0.8" MPI = "0.20.6" -MPIPreferences = "0.1.4" +MPIPreferences = "0.1.6" Test = "1" From 6e4e7266fd5f67f2e1eeb1d2b4f42b8cacce8a9a Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 22 Nov 2024 16:12:59 +0100 Subject: [PATCH 20/26] Refining test. --- test/test_forestwrapper.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/test_forestwrapper.jl b/test/test_forestwrapper.jl index 8e7a221..c8f5e31 100644 --- a/test/test_forestwrapper.jl +++ b/test/test_forestwrapper.jl @@ -3,7 +3,10 @@ # Clean up t8code before MPI shuts down. MPI.add_finalize_hook!() do T8code.clean_up() - T8code.Libt8.sc_finalize() + status = T8code.Libt8.sc_finalize_noabort() + # If the following test fails the allocated objects were not cleaned up + # properly before shutting down. + @test status == 0 end # Create a forest and wrap by `ForestWrapper` From f1f1e7b4bcb193909c1483704eed4a63584f5ed3 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 22 Nov 2024 16:18:58 +0100 Subject: [PATCH 21/26] Added test evals. --- test/test_forestwrapper.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/test_forestwrapper.jl b/test/test_forestwrapper.jl index c8f5e31..3ebd2c4 100644 --- a/test/test_forestwrapper.jl +++ b/test/test_forestwrapper.jl @@ -9,21 +9,29 @@ @test status == 0 end + @test length(T8code.T8CODE_OBJECT_TRACKER) == 0 + # Create a forest and wrap by `ForestWrapper` scheme = t8_scheme_new_default_cxx() cmesh = t8_cmesh_new_hypercube(T8_ECLASS_QUAD, comm, 0, 0, 0) forest = t8_forest_new_uniform(cmesh, scheme, 0, 0, comm) wrapper_A = T8code.ForestWrapper(forest) + @test length(T8code.T8CODE_OBJECT_TRACKER) == 1 + # Create another forest and wrap by `ForestWrapper` scheme = t8_scheme_new_default_cxx() cmesh = t8_cmesh_new_hypercube(T8_ECLASS_TRIANGLE, comm, 0, 0, 0) forest = t8_forest_new_uniform(cmesh, scheme, 0, 0, comm) wrapper_B = T8code.ForestWrapper(forest) + @test length(T8code.T8CODE_OBJECT_TRACKER) == 2 + # Finalize the first wrapper. finalize(wrapper_A) + @test length(T8code.T8CODE_OBJECT_TRACKER) == 1 + # The second wrapper should be finalized automatically when Julia shuts down. # ... finalize(wrapper_B) ... end From 76d5295e62acea39d0f0510122cdb4db9c2c8eca Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 22 Nov 2024 16:21:09 +0100 Subject: [PATCH 22/26] Added further test eval. --- test/test_forestwrapper.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_forestwrapper.jl b/test/test_forestwrapper.jl index 3ebd2c4..2c4b0fd 100644 --- a/test/test_forestwrapper.jl +++ b/test/test_forestwrapper.jl @@ -3,6 +3,7 @@ # Clean up t8code before MPI shuts down. MPI.add_finalize_hook!() do T8code.clean_up() + @test length(T8code.T8CODE_OBJECT_TRACKER) == 0 status = T8code.Libt8.sc_finalize_noabort() # If the following test fails the allocated objects were not cleaned up # properly before shutting down. From e4f0cb5148cce4c7df0c0a66eebb7218c5061b5d Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Mon, 25 Nov 2024 17:49:13 +0100 Subject: [PATCH 23/26] Adding convenient dispatch on type conversion. --- src/T8code.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/T8code.jl b/src/T8code.jl index 0ca7245..83963cd 100644 --- a/src/T8code.jl +++ b/src/T8code.jl @@ -212,6 +212,13 @@ mutable struct ForestWrapper end end +Base.pointer(fw::ForestWrapper) = fw.pointer +# This dispatched conversion allows to directly pass a ForestWrapper object to, +# for example, `t8_forest_...` call. The following link leads to a lengthy +# discussion about if this is a valid way to do achieve this: +# https://discourse.julialang.org/t/how-to-use-ccall-cconvert-and-unsafe-convert-in-a-convenient-and-memory-safe-way/41932/18 +Base.unsafe_convert(::Type{Ptr{T8code.Libt8.t8_forest}}, fw::ForestWrapper) = fw.pointer + function clean_up() # Finalize all registered t8code objects before MPI shuts down. while length(T8CODE_OBJECT_TRACKER) > 0 From 0df2f517e097510e8c68559717153d347150a146 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Mon, 25 Nov 2024 17:50:17 +0100 Subject: [PATCH 24/26] Version bump. --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 7f6cc42..c9b261a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "T8code" uuid = "d0cc0030-9a40-4274-8435-baadcfd54fa1" authors = ["Johannes Markert "] -version = "0.7.1" +version = "0.7.2" [deps] CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82" From 9ce1f779f5fc45f5d575d6acfe12c1353bba5096 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Mon, 25 Nov 2024 17:52:56 +0100 Subject: [PATCH 25/26] Refined comment. --- src/T8code.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/T8code.jl b/src/T8code.jl index 83963cd..b5da677 100644 --- a/src/T8code.jl +++ b/src/T8code.jl @@ -213,9 +213,9 @@ mutable struct ForestWrapper end Base.pointer(fw::ForestWrapper) = fw.pointer -# This dispatched conversion allows to directly pass a ForestWrapper object to, -# for example, `t8_forest_...` call. The following link leads to a lengthy -# discussion about if this is a valid way to do achieve this: +# This dispatched conversion allows to conveniently pass a ForestWrapper object +# to `t8_forest_...` calls. The following link leads to a lengthy discussion +# about if this is a valid way to achieve this: # https://discourse.julialang.org/t/how-to-use-ccall-cconvert-and-unsafe-convert-in-a-convenient-and-memory-safe-way/41932/18 Base.unsafe_convert(::Type{Ptr{T8code.Libt8.t8_forest}}, fw::ForestWrapper) = fw.pointer From 0b1a938bfc3efcd82d423270a524a2fab7b461f6 Mon Sep 17 00:00:00 2001 From: Johannes Markert <10619309+jmark@users.noreply.github.com> Date: Tue, 26 Nov 2024 09:10:13 +0100 Subject: [PATCH 26/26] Update src/T8code.jl Co-authored-by: Joshua Lampert <51029046+JoshuaLampert@users.noreply.github.com> --- src/T8code.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/T8code.jl b/src/T8code.jl index b5da677..87a8148 100644 --- a/src/T8code.jl +++ b/src/T8code.jl @@ -217,7 +217,7 @@ Base.pointer(fw::ForestWrapper) = fw.pointer # to `t8_forest_...` calls. The following link leads to a lengthy discussion # about if this is a valid way to achieve this: # https://discourse.julialang.org/t/how-to-use-ccall-cconvert-and-unsafe-convert-in-a-convenient-and-memory-safe-way/41932/18 -Base.unsafe_convert(::Type{Ptr{T8code.Libt8.t8_forest}}, fw::ForestWrapper) = fw.pointer +Base.unsafe_convert(::Type{Ptr{t8_forest}}, fw::ForestWrapper) = fw.pointer function clean_up() # Finalize all registered t8code objects before MPI shuts down.