<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://necluster.ne.utk.edu/wiki/index.php?action=history&amp;feed=atom&amp;title=Setting_thread_count_in_standard_Python_libraries</id>
	<title>Setting thread count in standard Python libraries - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://necluster.ne.utk.edu/wiki/index.php?action=history&amp;feed=atom&amp;title=Setting_thread_count_in_standard_Python_libraries"/>
	<link rel="alternate" type="text/html" href="https://necluster.ne.utk.edu/wiki/index.php?title=Setting_thread_count_in_standard_Python_libraries&amp;action=history"/>
	<updated>2026-05-08T08:38:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.2</generator>
	<entry>
		<id>https://necluster.ne.utk.edu/wiki/index.php?title=Setting_thread_count_in_standard_Python_libraries&amp;diff=460&amp;oldid=prev</id>
		<title>Ondrejch at 13:05, 25 July 2024</title>
		<link rel="alternate" type="text/html" href="https://necluster.ne.utk.edu/wiki/index.php?title=Setting_thread_count_in_standard_Python_libraries&amp;diff=460&amp;oldid=prev"/>
		<updated>2024-07-25T13:05:49Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 13:05, 25 July 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;All, the issue I had came from under-the-hood python packages automatically starting several processes, even though I was only requesting a single core in my job submission script. I’ve attached a function that will force the number of threads to a specific value, as it is important that the number of threads your program is trying to use aligns with the requested resources. On local machines, python should only use what is available and does pretty well playing nicely with other programs, but this is not the case with how torque distributes jobs.  &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;All, the issue I had came from under-the-hood python packages automatically starting several processes, even though I was only requesting a single core in my job submission script. I’ve attached a function that will force the number of threads to a specific value, as it is important that the number of threads your program is trying to use aligns with the requested resources. On local machines, python should only use what is available and does pretty well playing nicely with other programs, but this is not the case with how torque distributes jobs.  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l22&quot; &gt;Line 22:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 23:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     print(&amp;quot;Threading limits unset&amp;quot;)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     print(&amp;quot;Threading limits unset&amp;quot;)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[From Noah W.]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ondrejch</name></author>
		
	</entry>
	<entry>
		<id>https://necluster.ne.utk.edu/wiki/index.php?title=Setting_thread_count_in_standard_Python_libraries&amp;diff=459&amp;oldid=prev</id>
		<title>Ondrejch: Created page with &quot;All, the issue I had came from under-the-hood python packages automatically starting several processes, even though I was only requesting a single core in my job submission sc...&quot;</title>
		<link rel="alternate" type="text/html" href="https://necluster.ne.utk.edu/wiki/index.php?title=Setting_thread_count_in_standard_Python_libraries&amp;diff=459&amp;oldid=prev"/>
		<updated>2024-07-25T13:05:14Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;All, the issue I had came from under-the-hood python packages automatically starting several processes, even though I was only requesting a single core in my job submission sc...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;All, the issue I had came from under-the-hood python packages automatically starting several processes, even though I was only requesting a single core in my job submission script. I’ve attached a function that will force the number of threads to a specific value, as it is important that the number of threads your program is trying to use aligns with the requested resources. On local machines, python should only use what is available and does pretty well playing nicely with other programs, but this is not the case with how torque distributes jobs. &lt;br /&gt;
&lt;br /&gt;
These should work for most python applications, as I’m using many of the standard python packages (numpy, spicy, pandas, etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=Python&amp;gt;&lt;br /&gt;
# Function to set threading limits&lt;br /&gt;
def set_threading_limits(num_threads):&lt;br /&gt;
    os.environ['OMP_NUM_THREADS'] = str(num_threads)&lt;br /&gt;
    os.environ['OPENBLAS_NUM_THREADS'] = str(num_threads)&lt;br /&gt;
    os.environ['MKL_NUM_THREADS'] = str(num_threads)&lt;br /&gt;
    os.environ['VECLIB_MAXIMUM_THREADS'] = str(num_threads)&lt;br /&gt;
    os.environ['NUMEXPR_NUM_THREADS'] = str(num_threads)&lt;br /&gt;
    print(f&amp;quot;Threading limits set to {num_threads}”)&lt;br /&gt;
&lt;br /&gt;
# Function to restore defaults&lt;br /&gt;
def unset_threading_limits():&lt;br /&gt;
    os.environ.pop('OMP_NUM_THREADS', None)&lt;br /&gt;
    os.environ.pop('OPENBLAS_NUM_THREADS', None)&lt;br /&gt;
    os.environ.pop('MKL_NUM_THREADS', None)&lt;br /&gt;
    os.environ.pop('VECLIB_MAXIMUM_THREADS', None)&lt;br /&gt;
    os.environ.pop('NUMEXPR_NUM_THREADS', None)&lt;br /&gt;
    print(&amp;quot;Threading limits unset&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ondrejch</name></author>
		
	</entry>
</feed>