Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance mode #1014

Merged
merged 4 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.code-workspace
.DS_Store
docs/build/
LocalPreferences.toml
Manifest.toml
tmp/
.vscode/
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
NearestNeighbors = "b8a86587-4115-5ab1-83bc-aa920d37bbce"
PolynomialBases = "c74db56a-226d-5e98-8bb0-a6049094aeea"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Expand Down
7 changes: 7 additions & 0 deletions src/Helpers/Helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ $(EXPORTS)
module Helpers
using DocStringExtensions

@static if VERSION >= v"1.6"
using Preferences
end

import Base: +, -, *, /, transpose, adjoint
import LinearAlgebra: cross, tr, dot

Expand All @@ -21,8 +25,11 @@ export tfill
export get_val_parameter
export first_and_tail
export GridapType
export set_execution_mode
#export operate

include("Preferences.jl")

include("Macros.jl")

include("HelperFunctions.jl")
Expand Down
13 changes: 9 additions & 4 deletions src/Helpers/Macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@ end
@check condition "Error message"

Macro used to make sure that condition is fulfilled, like `@assert`
but the check gets deactivated when running Julia with --boundscheck=no
but the check gets deactivated when running Gridap in performance mode.
"""
macro check(test,msg="A check failed")
quote
@boundscheck @assert $(esc(test)) $(esc(msg))
@static if execution_mode == "debug"
quote
@assert $(esc(test)) $(esc(msg))
end
else
quote
nothing
end
end
end

22 changes: 22 additions & 0 deletions src/Helpers/Preferences.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

"""
set_execution_mode(new_mode::String)

Sets the execution mode to either "debug" or "performance", which controls
the behavior of the @check macro within the Gridap package.
"""
function set_execution_mode(new_mode::String)
if !(new_mode in ("debug", "performance"))
throw(ArgumentError("Invalid execution mode: \"$(new_mode)\""))

Check warning on line 10 in src/Helpers/Preferences.jl

View check run for this annotation

Codecov / codecov/patch

src/Helpers/Preferences.jl#L8-L10

Added lines #L8 - L10 were not covered by tests
end

# Set it in our runtime values, as well as saving it to disk
@set_preferences!("execution_mode" => new_mode)
@info("New execution mode set; restart your Julia session for this change to take effect!")

Check warning on line 15 in src/Helpers/Preferences.jl

View check run for this annotation

Codecov / codecov/patch

src/Helpers/Preferences.jl#L14-L15

Added lines #L14 - L15 were not covered by tests
end

@static if VERSION >= v"1.6"
const execution_mode = @load_preference("execution_mode", "debug")
else
const execution_mode = "debug"
end
Loading