# Multithreading on a Linux HPC cluster

**URL:** <https://discourse.julialang.org/t/multithreading-on-a-linux-hpc-cluster/43780>\
**Category:** General Usage\
**Tags:** question, hpc, multithreading, cluster\
**Created:** [July 27, 2020, 5:32pm UTC](https://discourse.julialang.org/t/multithreading-on-a-linux-hpc-cluster/43780 "2020-07-27T17:32:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [July 27, 2020, 5:32pm UTC](https://discourse.julialang.org/t/multithreading-on-a-linux-hpc-cluster/43780/1 "2020-07-27T17:32:30Z")

</div>

I’m running some machine learning code on a linux HPC cluster that is managed by a PBS scheduler. The code consists mostly of training a bunch of random forests using MLJ.jl and DecisionTree.jl. DecisionTree.jl [uses multithreading](https://github.com/bensadeghi/DecisionTree.jl/blob/a7a6316dfafa3056d53408fe2013465936c39db7/src/classification/main.jl#L222) to train random forests. However, I’m not confident that the multithreading is happening when I run my code on the cluster. I ran some jobs that seem to be taking a lot longer than they took on my laptop (where the multithreading seems to work as expected).

I don’t really know how PBS works under the hood, but I would imagine that it provides some kind of virtual machine for your code to run on. So I would hope that multithreading works about the same as it would on my laptop.

So far the only test I’ve come up with is the following. I created the following test PBS script:

```julia
#!/bin/bash -l

export JULIA_NUM_THREADS=12
julia test.jl

```

Where “test.jl” contains the following:

```julia
println("Number of Julia threads: $(Threads.nthreads())")

```

Then I submit the PBS job with this:

```julia
qsub -l nodes=1:ppn=16,mem=2gb,walltime=01:00:00 -q mangi test.pbs

```

And the output of the job is this:

```nohighlight
Number of Julia threads: 12

```

So, setting `JULIA_NUM_THREADS` in the PBS script seems to work as expected. Besides setting `export JULIA_NUM_THREADS=12` in the PBS script, is there anything else I need to do to ensure that multithreading will work correctly on a PBS controlled HPC cluster?
