Skip to content

Commit d673175

Browse files
authored
v0.1.4: Multithreading (#26)
* doc up * Added multihreading in optimize! (#25) * Added multihreading in optimize! * Updated CI for multithreading * Bump new version for multithreading
1 parent 820d3af commit d673175

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
arch:
1919
- x64
2020
- x86
21+
threads:
22+
- "2"
2123
exclude:
2224
- os: macOS-latest
2325
arch: x86
@@ -41,6 +43,8 @@ jobs:
4143
${{ runner.os }}-
4244
- uses: julia-actions/julia-buildpkg@v1
4345
- uses: julia-actions/julia-runtest@v1
46+
env:
47+
JULIA_NUM_THREADS: ${{ matrix.threads }}
4448
- uses: julia-actions/julia-processcoverage@v1
4549
- uses: codecov/codecov-action@v1
4650
with:

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CompositionalNetworks"
22
uuid = "4b67e4b5-442d-4ef5-b760-3f5df3a57537"
33
authors = ["Jean-François Baffier"]
4-
version = "0.1.3"
4+
version = "0.1.4"
55

66
[deps]
77
ConstraintDomains = "5800fd60-8556-4464-8d61-84ebf7a0bedb"
@@ -11,7 +11,7 @@ OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
1111
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1212

1313
[compat]
14-
ConstraintDomains = "0.1.2"
14+
ConstraintDomains = "0.1"
1515
Dictionaries = "0.3"
1616
Evolutionary = "0.7, 0.8"
1717
OrderedCollections = "1.3"

src/CompositionalNetworks.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import Evolutionary: GA, tournament, singlepoint, flip, optimize, minimizer, Opt
55
import Random: bitrand, falses
66
import OrderedCollections: LittleDict
77
import Dictionaries: Dictionary, set!
8-
import Base.Iterators: product
8+
import Base.Iterators: product, flatten
99
import ConstraintDomains: _get_domain, _length
10+
import Base.Threads: @threads, threadid, nthreads
1011

1112
# Exports utilities
1213
export lazy, lazy_param, csv2space

src/genetic.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,17 @@ Optimize and set the weigths of an ICN with a given set of configuration `X` and
4646

4747
function optimize!(icn, X, X_sols, global_iter, local_iter, dom_size, param=nothing; metric=hamming, popSize=100)
4848
results = Dictionary{BitVector,Int}()
49-
@info "Starting optimization of weights"
50-
for i in 1:global_iter
49+
aux_results = Vector{BitVector}(undef, global_iter)
50+
@info """Starting optimization of weights$(nthreads() > 1 ? " (multithreaded)" : "")"""
51+
@threads for i in 1:global_iter
5152
@info "Iteration $i"
52-
_optimize!(icn, X, X_sols, dom_size, param;
53+
aux_icn = deepcopy(icn)
54+
_optimize!(aux_icn, X, X_sols, dom_size, param;
5355
iter=local_iter, metric=metric, pop_size=popSize
5456
)
55-
_incsert!(results, _weigths(icn))
57+
aux_results[i] = _weigths(aux_icn)
5658
end
59+
foreach(bv -> _incsert!(results, bv), aux_results)
5760
best = rand(findall(x -> x == maximum(results), results))
5861
_weigths!(icn, best)
5962
@info show_composition(icn) best results

0 commit comments

Comments
 (0)