Skip to content

Enabling multi-threading? #12

Closed
Closed
@giordano

Description

These days I'm pushing a few changes to slightly improve performance of the conversions, and others will come in the next days ;-)

In addition, there is a one-line change that can boost performance: enabling multi-threading

diff --git a/src/SkyCoords.jl b/src/SkyCoords.jl
index 5aa77d2..a092321 100644
--- a/src/SkyCoords.jl
+++ b/src/SkyCoords.jl
@@ -258,7 +258,7 @@ function convert{T<:AbstractSkyCoords, n, S<:AbstractSkyCoords}(
     ::Type{Array{T,n}}, c::Array{S, n})
     m = Matrix33{_eltype(S)}(rotmat(T, S))
     result = similar(c, T)
-    for i in 1:length(c)
+    Threads.@threads for i in 1:length(c)
         r = m * coords2cart(c[i])
         lon, lat = cart2coords(r)
         result[i] = T(lon, lat)

Running the benchmark script at https://github.com/kbarbary/SkyCoords.jl/pull/9#issuecomment-336395556 I get this new plot by using 4 threads:

bench

With 1 million coordinates SkyCoords.jl is still one order of magnitude faster than Astropy :-) The change was applied on top of current master, so there is still room for some minor improvement.

The problem of multi-threading in Julia is that it's still experimental. However, when running Julia with just one thread there is zero overhead and no issues. Thus, the change I propose should be safe enough (doesn't break single-thread systems) and we would only need to warn people that multi-threading may not work.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions