{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/17972","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/17972/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/17972/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/17972/events","html_url":"https://github.com/JuliaLang/julia/issues/17972","id":170687027,"number":17972,"title":"FFTW planner is not thread safe.","user":{"login":"DrTodd13","id":2584128,"avatar_url":"https://avatars.githubusercontent.com/u/2584128?v=3","gravatar_id":"","url":"https://api.github.com/users/DrTodd13","html_url":"https://github.com/DrTodd13","followers_url":"https://api.github.com/users/DrTodd13/followers","following_url":"https://api.github.com/users/DrTodd13/following{/other_user}","gists_url":"https://api.github.com/users/DrTodd13/gists{/gist_id}","starred_url":"https://api.github.com/users/DrTodd13/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DrTodd13/subscriptions","organizations_url":"https://api.github.com/users/DrTodd13/orgs","repos_url":"https://api.github.com/users/DrTodd13/repos","events_url":"https://api.github.com/users/DrTodd13/events{/privacy}","received_events_url":"https://api.github.com/users/DrTodd13/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/JuliaLang/julia/labels/multi-threading","name":"multi-threading","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-08-11T16:22:17Z","updated_at":"2016-08-11T18:08:51Z","closed_at":null,"body":"Having fft/bfft/ifft/etc. calls in a threaded region exposes the fact that the planning portion of the fft call is not thread-safe in fftw.  Below is a potential patch to dft.jl if you just want to lock the planner.\r\n\r\n```\r\nglobal planner_mutex = nothing\r\n\r\nfunction __init__()\r\n    global planner_mutex = Base.Threads.Mutex()\r\nend\r\n\r\n# implementations only need to provide plan_X(x, region)\r\n# for X in (:fft, :bfft, ...):\r\nfor f in (:fft, :bfft, :ifft, :fft!, :bfft!, :ifft!, :rfft)\r\n    pf = Symbol(\"plan_\", f)\r\n    @eval begin\r\n        function $f(x::AbstractArray)\r\n            Base.Threads.lock!(planner_mutex)\r\n            the_plan = $pf(x)\r\n            Base.Threads.unlock!(planner_mutex)\r\n            the_plan * x\r\n        end\r\n        function $f(x::AbstractArray, region)\r\n            Base.Threads.lock!(planner_mutex)\r\n            the_plan = $pf(x, region)\r\n            Base.Threads.unlock!(planner_mutex)\r\n            the_plan * x\r\n        end\r\n        function $pf(x::AbstractArray; kws...)\r\n            Base.Threads.lock!(planner_mutex)\r\n            the_plan = $pf(x, 1:ndims(x); kws...)\r\n            Base.Threads.unlock!(planner_mutex)\r\n            the_plan\r\n        end\r\n    end\r\nend\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/239242857","html_url":"https://github.com/JuliaLang/julia/issues/17972#issuecomment-239242857","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/17972","id":239242857,"user":{"login":"DrTodd13","id":2584128,"avatar_url":"https://avatars.githubusercontent.com/u/2584128?v=3","gravatar_id":"","url":"https://api.github.com/users/DrTodd13","html_url":"https://github.com/DrTodd13","followers_url":"https://api.github.com/users/DrTodd13/followers","following_url":"https://api.github.com/users/DrTodd13/following{/other_user}","gists_url":"https://api.github.com/users/DrTodd13/gists{/gist_id}","starred_url":"https://api.github.com/users/DrTodd13/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DrTodd13/subscriptions","organizations_url":"https://api.github.com/users/DrTodd13/orgs","repos_url":"https://api.github.com/users/DrTodd13/repos","events_url":"https://api.github.com/users/DrTodd13/events{/privacy}","received_events_url":"https://api.github.com/users/DrTodd13/received_events","type":"User","site_admin":false},"created_at":"2016-08-11T18:08:50Z","updated_at":"2016-08-11T18:08:50Z","body":"Yes, that is probably better.  Just those 4 ccalls in the for block on fft/FFTW.jl line 454."}}
{"actor":{"display_login":"DrTodd13"}}