{"id":256,"date":"2009-04-17T13:39:12","date_gmt":"2009-04-17T17:39:12","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/2009\/04\/17\/multithreaded-fft-functions-in-matlab-r2009a\/"},"modified":"2019-10-28T15:29:44","modified_gmt":"2019-10-28T19:29:44","slug":"multithreaded-fft-functions-in-matlab-r2009a","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2009\/04\/17\/multithreaded-fft-functions-in-matlab-r2009a\/","title":{"rendered":"Multithreaded FFT functions in MATLAB R2009a"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <p>For the past several releases, we have been incrementally making more of the computational routines in MATLAB multithreaded.\r\n      (More recently, we've also started doing this in the Image Processing Toolbox.)\r\n   <\/p>\r\n   <p>For the R2009a release, readers of this blog might be particularly interested in the improvements made to the FFT functions\r\n      (<tt>fft<\/tt>, <tt>ifft<\/tt>, <tt>fft2<\/tt>, <tt>ifft2<\/tt>, <tt>fftn<\/tt>, and <tt>ifftn<\/tt>).\r\n   <\/p>\r\n   <p>Multithreading for the FFT functions works for two- and higher-dimensional cases, and it works for one-dimensional FFTs when\r\n      multiple columns are being transformed at the same time.\r\n   <\/p>\r\n   <p>In this example I time a 2048-by-2048 two-dimensional FFT using a two-core 32-bit Windows laptop. \r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">x = rand(2048, 2048);\r\ntimeit(@() fft2(x))<\/pre><pre style=\"font-style:oblique\">\r\nans =\r\n\r\n    0.5443\r\n\r\n<\/pre><p>The computation runs almost twice as fast (on my two-core machine) as it does when using the R2008b release.<\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_acd985709d7c40a997750bc1c1c69ab1() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='acd985709d7c40a997750bc1c1c69ab1 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' acd985709d7c40a997750bc1c1c69ab1';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Steve Eddins';\r\n        copyright = '';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_acd985709d7c40a997750bc1c1c69ab1()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.8<br><\/p>\r\n<\/div>\r\n<!--\r\nacd985709d7c40a997750bc1c1c69ab1 ##### SOURCE BEGIN #####\r\n%%\r\n% For the past several releases, we have been incrementally making more of the\r\n% computational routines in MATLAB multithreaded. (More recently, we've also started doing this in\r\n% the Image Processing Toolbox.)\r\n%\r\n% For the R2009a release, readers of this blog might be particularly interested\r\n% in the improvements made to the FFT functions (|fft|, |ifft|, |fft2|, |ifft2|,\r\n% |fftn|, and |ifftn|).\r\n%\r\n% Multithreading for the FFT functions works for two- and higher-dimensional\r\n% cases, and it works for one-dimensional FFTs when multiple columns are being\r\n% transformed at the same time.\r\n%\r\n% In this example I time a 2048-by-2048 two-dimensional FFT using a two-core 32-bit \r\n% Windows laptop. (You can get the |timeit| function from the \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/18798 MATLAB Central\r\n% File Exchange>.)\r\n\r\nx = rand(2048, 2048);\r\ntimeit(@() fft2(x))\r\n\r\n%%\r\n% The computation runs almost twice as fast (on my two-core machine) as it does\r\n% when using the R2008b release.\r\n\r\n##### SOURCE END ##### acd985709d7c40a997750bc1c1c69ab1\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   For the past several releases, we have been incrementally making more of the computational routines in MATLAB multithreaded.\r\n      (More recently, we've also started doing this in the Image... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2009\/04\/17\/multithreaded-fft-functions-in-matlab-r2009a\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[392,460,474],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/256"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/comments?post=256"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/256\/revisions"}],"predecessor-version":[{"id":2645,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/256\/revisions\/2645"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}