Skip to content

Commit 17e4612

Browse files
author
Maximilian Reißmann
committed
changes threads
1 parent 4dd0195 commit 17e4612

4 files changed

Lines changed: 13 additions & 10 deletions

File tree

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "GeneExpressionProgramming"
22
uuid = "2f0a5bb0-5f4f-4f7f-b515-93a1e67611af"
3-
authors = ["Max Reissmann <reissmannm@student.unimelb.edu.au>"]
43
version = "0.5.1"
4+
authors = ["Max Reissmann <reissmannm@student.unimelb.edu.au>"]
55

66
[deps]
77
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
@@ -37,6 +37,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
3737
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
3838
Tensors = "48a634ad-e948-5137-8d70-aa71f2a747f4"
3939
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
40+
ThreadsX = "ac1d9e8a-700a-412c-b207-f0111f4b6c0d"
4041
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
4142

4243
[compat]
@@ -72,5 +73,6 @@ Statistics = "1"
7273
StatsBase = "0.34 - 0.37"
7374
Tensors = "1"
7475
Test = "1"
76+
ThreadsX = "0.1"
7577
Zygote = "0.6"
7678
julia = "1"

src/Gep.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ using Printf
8181
using LRUCache
8282
using Base.Threads: SpinLock
8383
using .Threads
84+
using ThreadsX
8485
export runGep
8586

8687

@@ -213,7 +214,7 @@ Applies correction operations to ensure dimensional homogeneity in chromosomes.
213214

214215
if !isnothing(correction_callback) && epoch % correction_epochs == 0
215216
pop_amount = Int(ceil(length(population) * correction_amount))
216-
Threads.@threads for i in 1:pop_amount
217+
ThreadsX.foreach(1:pop_amount) do i
217218
if !(population[i].dimension_homogene) && population[i].compiled && isnan(mean(population[i].fitness))
218219
distance, correction = correction_callback(population[i].genes, population[i].toolbox.gen_start_indices,
219220
population[i].expression_raw, epoch)
@@ -315,7 +316,7 @@ The evolution process stops when either:
315316
same = Atomic{Int}(0)
316317
perform_correction_callback!(population[1:population_size], epoch, correction_epochs, correction_amount, correction_callback)
317318

318-
Threads.@threads for i in eachindex(population[1:population_size])
319+
ThreadsX.foreach(eachindex(population[1:population_size])) do i
319320
if isnan(mean(population[i].fitness))
320321
key = join(population[i].expression_raw, ",")
321322
cache_value = key in keys(fit_cache)

src/RegressionWrapper.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ mutable struct GepRegressor
473473
function GepRegressor(feature_amount::Int;
474474
entered_features::Vector{Symbol}=Vector{Symbol}(),
475475
entered_non_terminals::Vector{Symbol}=[:+, :-, :*, :/],
476-
entered_terminal_nums::Vector{Symbol}=[Symbol(0.0), Symbol(0.5)],
476+
entered_terminal_nums::Vector{Symbol}=[Symbol(0.5),Symbol(0.0)],
477477
gene_connections::Vector{Symbol}=[:+, :-, :*, :/],
478478
considered_dimensions::Dict{Symbol,Vector{Float16}}=Dict{Symbol,Vector{Float16}}(),
479479
rnd_count::Int=1,

src/Sbp.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -881,9 +881,9 @@ function create_lib(tokenLib::TokenLib, features::Vector{Int8},
881881
end
882882

883883
lib_array = collect(lib)
884-
Threads.@threads for i in eachindex(lib_array)
884+
Threads.@threads :static for i in eachindex(lib_array)
885885
entry = lib_array[i]
886-
local_entries = new_entries_local[Threads.threadid()]
886+
local_entries = new_entries_local[mod1(Threads.threadid(), Threads.nthreads())]
887887
for item in search_space
888888
new_entry = copy(entry)
889889
append!(new_entry, item)
@@ -917,11 +917,11 @@ function reorganize_lib(old_lib::Set{LibEntry})
917917
local_libs = [OrderedDict{Tuple{Vector{Float16},Int},Vector{Vector{Int8}}}() for _ in 1:Threads.nthreads()]
918918

919919
old_lib_array = collect(old_lib) # Convert Set to Array
920-
Threads.@threads for i in eachindex(old_lib_array)
920+
Threads.@threads :static for i in eachindex(old_lib_array)
921921
entry = old_lib_array[i]
922922
clean!(entry)
923923
key = (entry.physical_dimension, length(entry.elements))
924-
local_lib = local_libs[Threads.threadid()]
924+
local_lib = local_libs[mod1(Threads.threadid(), Threads.nthreads())]
925925

926926
if haskey(local_lib, key)
927927
push!(local_lib[key], entry.elements)
@@ -1174,7 +1174,7 @@ function calculate_contribution(tree::TempComputeTree, expected_dim::Vector{Floa
11741174
end
11751175

11761176
function check_crit_up!(len_rest::Int, expected_dim::Vector{Float16}, tree::TempComputeTree)
1177-
@inbounds for elem in len_rest:-1:SMALLEST_TREE_SEGMENT
1177+
@inbounds for elem in len_rest:-1:max(SMALLEST_TREE_SEGMENT,len_rest-SMALLEST_TREE_SEGMENT*2)
11781178
if haskey(tree.tokenDto.lib[], (expected_dim, elem))
11791179
tree.exchange_len = elem
11801180
return true
@@ -1448,7 +1448,7 @@ function propagate_necessary_changes!(
14481448
return true
14491449
end
14501450

1451-
if check_crit_up!(tree.depend_on_total_number + 1, expected_dim, tree) && distance_to_change <= 0 && rand() > 0.01
1451+
if check_crit_up!(tree.depend_on_total_number + 1, expected_dim, tree) && distance_to_change <= 0 && rand() > 0.05
14521452
return enforce_changes!(tree, expected_dim)
14531453
end
14541454

0 commit comments

Comments
 (0)