{"id":175,"date":"2017-04-19T15:39:55","date_gmt":"2017-04-19T19:39:55","guid":{"rendered":"https:\/\/carleton.ca\/rcs\/?page_id=175"},"modified":"2021-07-29T10:25:09","modified_gmt":"2021-07-29T14:25:09","slug":"matlab-tips","status":"publish","type":"page","link":"https:\/\/carleton.ca\/rcs\/rcdc\/matlab-tips\/","title":{"rendered":"Matlab on Linux Servers"},"content":{"rendered":"<h2>Using Parallelism in Matlab<\/h2>\n<p>One way to improve MATLAB code performance is using parallelism.\u00a0 In MATLAB, the most common way to do this is to replace a slow\u00a0<strong>for\u00a0<\/strong>loop with a\u00a0<strong>parfor<\/strong> loop.<\/p>\n<p>However, there are some restrictions on what loops can be converted to\u00a0parfor.\u00a0 Loops must be independent.\u00a0 That is, the loop iterations should be executable in any order, where the results of one iteration do not rely on previous iterations.<\/p>\n<p>More information on converting loops to parfor can be found at:\u00a0\u00a0<a href=\"https:\/\/www.mathworks.com\/help\/distcomp\/troubleshoot-variables-in-parfor-loops.html\">https:\/\/www.mathworks.com\/help\/distcomp\/troubleshoot-variables-in-parfor-loops.html<\/a><\/p>\n<h2>Using the Console<\/h2>\n<p>It is possible to use MATLAB without its graphical interface.\u00a0 In particular, on remote Linux servers it is often best to run MATLAB from the command-line and not interactively.<\/p>\n<p>Once your MATLAB code is finished and tested, you can run it from the Linux server&#8217;s shell:<\/p>\n<ol>\n<li>SSH to remote server<\/li>\n<li>Change directory to your MATLAB script&#8217;s location\u00a0<em>(let&#8217;s assume your script is called myexample.m)<\/em><\/li>\n<li>Run this command: <code>matlab -nodisplay -r 'myexample; quit'<\/code><\/li>\n<\/ol>\n<p>You can even put this MATLAB command in the background using techniques found at either:<\/p>\n<ul>\n<li><span class=\"s1\"><a href=\"https:\/\/carleton.ca\/rcs\/linux-basics\/\">https:\/\/carleton.ca\/rcs\/linux-basics\/<\/a><\/span><\/li>\n<li><span class=\"s1\"><a href=\"https:\/\/carleton.ca\/rcs\/background-terminal-sessions\/\">https:\/\/carleton.ca\/rcs\/background-terminal-sessions\/<\/a>.<\/span><\/li>\n<\/ul>\n<h2>Forcing Single-Threaded Execution<\/h2>\n<p>MATLAB has commands that operate on entire matrices or vectors at once.\u00a0 These are called vectorized operations.\u00a0 MATLAB automatically runs many vectorized operations in parallel.<\/p>\n<p>Sometimes you don&#8217;t want MATLAB to automatically use multiple processor cores.\u00a0 Perhaps you want to evaluate how effective MATLAB&#8217;s core use is, or perhaps you need to share the cores with other programs.\u00a0 You can disable MATLAB&#8217;s automatic parallelism by invoking matlab from the command line with this option: <code>matlab\u00a0-singleCompThread<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using Parallelism in Matlab One way to improve MATLAB code performance is using parallelism.\u00a0 In MATLAB, the most common way to do this is to replace a slow\u00a0for\u00a0loop with a\u00a0parfor loop. However, there are some restrictions on what loops can be converted to\u00a0parfor.\u00a0 Loops must be independent.\u00a0 That is, the loop iterations should be executable [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"parent":96,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_relevanssi_hide_post":"","_relevanssi_hide_content":"","_relevanssi_pin_for_all":"","_relevanssi_pin_keywords":"","_relevanssi_unpin_keywords":"","_relevanssi_related_keywords":"","_relevanssi_related_include_ids":"","_relevanssi_related_exclude_ids":"","_relevanssi_related_no_append":"","_relevanssi_related_not_related":"","_relevanssi_related_posts":"","_relevanssi_noindex_reason":"","_mi_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":"","_links_to":"","_links_to_target":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Matlab on Linux Servers - Research Computing Services<\/title>\n<meta name=\"description\" content=\"Using Parallelism in Matlab One way to improve MATLAB code performance is using parallelism.\u00a0 In MATLAB, the most common way to do this is to replace a\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/carleton.ca\/rcs\/rcdc\/matlab-tips\/\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/carleton.ca\/rcs\/rcdc\/matlab-tips\/\",\"url\":\"https:\/\/carleton.ca\/rcs\/rcdc\/matlab-tips\/\",\"name\":\"Matlab on Linux Servers - Research Computing Services\",\"isPartOf\":{\"@id\":\"https:\/\/carleton.ca\/rcs\/#website\"},\"datePublished\":\"2017-04-19T19:39:55+00:00\",\"dateModified\":\"2021-07-29T14:25:09+00:00\",\"description\":\"Using Parallelism in Matlab One way to improve MATLAB code performance is using parallelism.\u00a0 In MATLAB, the most common way to do this is to replace a\",\"breadcrumb\":{\"@id\":\"https:\/\/carleton.ca\/rcs\/rcdc\/matlab-tips\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/carleton.ca\/rcs\/rcdc\/matlab-tips\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/carleton.ca\/rcs\/rcdc\/matlab-tips\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/carleton.ca\/rcs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Research Computing and Development Cloud (RCDC)\",\"item\":\"https:\/\/carleton.ca\/rcs\/rcdc\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Matlab on Linux Servers\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/carleton.ca\/rcs\/#website\",\"url\":\"https:\/\/carleton.ca\/rcs\/\",\"name\":\"Research Computing Services\",\"description\":\"Carleton University\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/carleton.ca\/rcs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Matlab on Linux Servers - Research Computing Services","description":"Using Parallelism in Matlab One way to improve MATLAB code performance is using parallelism.\u00a0 In MATLAB, the most common way to do this is to replace a","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/carleton.ca\/rcs\/rcdc\/matlab-tips\/","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/carleton.ca\/rcs\/rcdc\/matlab-tips\/","url":"https:\/\/carleton.ca\/rcs\/rcdc\/matlab-tips\/","name":"Matlab on Linux Servers - Research Computing Services","isPartOf":{"@id":"https:\/\/carleton.ca\/rcs\/#website"},"datePublished":"2017-04-19T19:39:55+00:00","dateModified":"2021-07-29T14:25:09+00:00","description":"Using Parallelism in Matlab One way to improve MATLAB code performance is using parallelism.\u00a0 In MATLAB, the most common way to do this is to replace a","breadcrumb":{"@id":"https:\/\/carleton.ca\/rcs\/rcdc\/matlab-tips\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/carleton.ca\/rcs\/rcdc\/matlab-tips\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/carleton.ca\/rcs\/rcdc\/matlab-tips\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/carleton.ca\/rcs\/"},{"@type":"ListItem","position":2,"name":"Research Computing and Development Cloud (RCDC)","item":"https:\/\/carleton.ca\/rcs\/rcdc\/"},{"@type":"ListItem","position":3,"name":"Matlab on Linux Servers"}]},{"@type":"WebSite","@id":"https:\/\/carleton.ca\/rcs\/#website","url":"https:\/\/carleton.ca\/rcs\/","name":"Research Computing Services","description":"Carleton University","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/carleton.ca\/rcs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"}]}},"acf":{"banner_image_type":"none","banner_button":"no"},"_links":{"self":[{"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/pages\/175"}],"collection":[{"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/comments?post=175"}],"version-history":[{"count":3,"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/pages\/175\/revisions"}],"predecessor-version":[{"id":454,"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/pages\/175\/revisions\/454"}],"up":[{"embeddable":true,"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/pages\/96"}],"wp:attachment":[{"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/media?parent=175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}