From a2375a5d110819e4a082d023adace32574f5445e Mon Sep 17 00:00:00 2001 From: Adriano Meligrana <68152031+Tortar@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:41:56 +0100 Subject: [PATCH 1/5] Use ChunkSplitters for multithreading --- src/BeforeIT.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/BeforeIT.jl b/src/BeforeIT.jl index 77420b4..4fadf55 100644 --- a/src/BeforeIT.jl +++ b/src/BeforeIT.jl @@ -2,6 +2,7 @@ module BeforeIT import Base: length +using ChunkSplitters using DynamicSampling using LazyArrays using LinearAlgebra From 0adb6f572b0456ab7dcb975ebc0bc9b43005fdae Mon Sep 17 00:00:00 2001 From: Adriano Meligrana <68152031+Tortar@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:47:07 +0100 Subject: [PATCH 2/5] Update search_and_matching.jl --- src/markets/search_and_matching.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/markets/search_and_matching.jl b/src/markets/search_and_matching.jl index f5c14c4..d20b75a 100644 --- a/src/markets/search_and_matching.jl +++ b/src/markets/search_and_matching.jl @@ -108,8 +108,10 @@ function search_and_matching!(model, multi_threading = false) if multi_threading - Threads.@threads :static for g in 1:G - loopBody(Threads.threadid(), g) + Threads.@sync for (i, gs) in enumerate(chunks(1:G; n=Threads.nthreads(), split=RoundRobin())) + for g in gs + Threads.@spawn loopBody(i, g) + end end else for g in 1:G From 79720bdd1451efa02c41a608c850816840d816a4 Mon Sep 17 00:00:00 2001 From: Adriano Meligrana <68152031+Tortar@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:48:15 +0100 Subject: [PATCH 3/5] Update Project.toml --- Project.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Project.toml b/Project.toml index 09eb14a..afdb295 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,7 @@ authors = ["Aldo Glielmo ", "Mitja Devetak Date: Tue, 3 Dec 2024 14:56:03 +0100 Subject: [PATCH 4/5] Update search_and_matching.jl --- src/markets/search_and_matching.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/markets/search_and_matching.jl b/src/markets/search_and_matching.jl index d20b75a..2242243 100644 --- a/src/markets/search_and_matching.jl +++ b/src/markets/search_and_matching.jl @@ -108,9 +108,9 @@ function search_and_matching!(model, multi_threading = false) if multi_threading - Threads.@sync for (i, gs) in enumerate(chunks(1:G; n=Threads.nthreads(), split=RoundRobin())) + Threads.@threads for (i, gs) in enumerate(chunks(1:G; n=Threads.nthreads(), split=RoundRobin())) for g in gs - Threads.@spawn loopBody(i, g) + loopBody(i, g) end end else From a966f5048dd012f33063fcc13a29bb017df063a4 Mon Sep 17 00:00:00 2001 From: Adriano Meligrana <68152031+Tortar@users.noreply.github.com> Date: Wed, 4 Dec 2024 12:56:49 +0100 Subject: [PATCH 5/5] Update search_and_matching.jl --- src/markets/search_and_matching.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/markets/search_and_matching.jl b/src/markets/search_and_matching.jl index 2242243..7dc63a0 100644 --- a/src/markets/search_and_matching.jl +++ b/src/markets/search_and_matching.jl @@ -106,9 +106,8 @@ function search_and_matching!(model, multi_threading = false) ) end - if multi_threading - Threads.@threads for (i, gs) in enumerate(chunks(1:G; n=Threads.nthreads(), split=RoundRobin())) + Threads.@threads for (i, gs) in enumerate(chunks(shuffle(1:G); n=Threads.nthreads())) for g in gs loopBody(i, g) end