<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.anunna.wur.nl/index.php?action=history&amp;feed=atom&amp;title=Performance_Optimization%2FMultiple_CPUs</id>
	<title>Performance Optimization/Multiple CPUs - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.anunna.wur.nl/index.php?action=history&amp;feed=atom&amp;title=Performance_Optimization%2FMultiple_CPUs"/>
	<link rel="alternate" type="text/html" href="https://wiki.anunna.wur.nl/index.php?title=Performance_Optimization/Multiple_CPUs&amp;action=history"/>
	<updated>2026-06-19T05:02:32Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.anunna.wur.nl/index.php?title=Performance_Optimization/Multiple_CPUs&amp;diff=2860&amp;oldid=prev</id>
		<title>Haars0011: IA migration §8: new Performance Optimization/Multiple CPUs (threads/OpenMP within one node) (via create-page on MediaWiki MCP Server)</title>
		<link rel="alternate" type="text/html" href="https://wiki.anunna.wur.nl/index.php?title=Performance_Optimization/Multiple_CPUs&amp;diff=2860&amp;oldid=prev"/>
		<updated>2026-06-18T13:03:37Z</updated>

		<summary type="html">&lt;p&gt;IA migration §8: new Performance Optimization/Multiple CPUs (threads/OpenMP within one node) (via create-page on MediaWiki MCP Server)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Many programs can use more than one CPU core at once — through threads, OpenMP, or built-in multiprocessing. To use several cores on a single node, request them from the scheduler and tell your program how many to use. To scale beyond one node, see [[Performance Optimization/Multiple nodes (MPI)|MPI]] or [[Performance Optimization/Multiple nodes (arrayjobs)|job arrays]].&lt;br /&gt;
&lt;br /&gt;
== Requesting cores ==&lt;br /&gt;
&lt;br /&gt;
For a threaded program, ask SLURM for cores on one node with &amp;lt;code&amp;gt;--cpus-per-task&amp;lt;/code&amp;gt; — for example, 8 cores:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#SBATCH --job-name=threads&lt;br /&gt;
#SBATCH --nodes=1&lt;br /&gt;
#SBATCH --ntasks=1&lt;br /&gt;
#SBATCH --cpus-per-task=8&lt;br /&gt;
#SBATCH --time=01:00:00&lt;br /&gt;
&lt;br /&gt;
# many tools read this to decide how many threads to use&lt;br /&gt;
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK&lt;br /&gt;
&lt;br /&gt;
./my_threaded_program&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Requesting more cores than your program can actually use wastes the allocation and makes your job wait longer in the queue, so match the request to what the program will use.&lt;br /&gt;
&lt;br /&gt;
== Telling your program how many cores to use ==&lt;br /&gt;
&lt;br /&gt;
Most programs need to be told how many cores to use; they do not pick it up automatically. Common ways:&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;OpenMP&amp;#039;&amp;#039;&amp;#039; programs read the &amp;lt;code&amp;gt;OMP_NUM_THREADS&amp;lt;/code&amp;gt; environment variable — set it from &amp;lt;code&amp;gt;$SLURM_CPUS_PER_TASK&amp;lt;/code&amp;gt;, as above.&lt;br /&gt;
* Many tools take a flag, for example &amp;lt;code&amp;gt;-t&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;--threads&amp;lt;/code&amp;gt;, or &amp;lt;code&amp;gt;-p&amp;lt;/code&amp;gt; — check the program&amp;#039;s documentation.&lt;br /&gt;
* In Python, R, and similar, use the language&amp;#039;s multiprocessing or parallel facilities and pass the core count explicitly.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Performance Optimization/Multiple nodes (MPI)]]&lt;br /&gt;
* [[Performance Optimization/Multiple nodes (arrayjobs)]]&lt;br /&gt;
* [[Batch Jobs]]&lt;br /&gt;
* [[Scheduler Overview (Slurm)]]&lt;/div&gt;</summary>
		<author><name>Haars0011</name></author>
	</entry>
</feed>