# Difference between nprocs and nthreads

**URL:** <https://discourse.julialang.org/t/difference-between-nprocs-and-nthreads/87361>\
**Category:** Julia at Scale\
**Tags:** distributed\
**Created:** [September 16, 2022, 11:24am UTC](https://discourse.julialang.org/t/difference-between-nprocs-and-nthreads/87361 "2022-09-16T11:24:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)\
**Post date:** [September 16, 2022, 11:24am UTC](https://discourse.julialang.org/t/difference-between-nprocs-and-nthreads/87361/1 "2022-09-16T11:24:23Z")

</div>

Hello,

I’m trying to get my head around distributed programming to execute a script on a cluster.  
My code works well on my workstation with one CPU. It internally uses `@threads` to parallelize some stuff within the main task, using the threads of my one CPU. So I start as follows: `$ julia -t 12`.

On the cluster, I would like to launch several of this task (each will use `@threads` occasionally).  
Now I’m reading the documentation of [distributed programming](https://docs.julialang.org/en/v1/manual/distributed-computing/) and I read

> Starting with `julia -p n` provides `n` worker processes on the local machine. Generally it makes sense for `n` to equal the number of CPU threads (logical cores) on the machine. Note that the `-p` argument implicitly loads module [`Distributed`](https://docs.julialang.org/en/v1/stdlib/Distributed/#man-distributed).

Say I have 4 CPUs on my cluster node. Should I start with

1. `$ julia -p 4 -t 12` (assuming 12 cores per cpu) or
2. `$ julia -p 48` ? The latter takes the above quote literally.

I tried 2) on my local machine and I see that `nthreads() == 1`. 1) gives `nprocs() == 4 && nthreads == 12`.

Am I correct to think that with 1) I can start 4 parallel “main” tasks" that will each use 12 threads for multithreading or will it be 3 because the 12 threads are divided between the workers ? Meaning I should use `$ julia -p 4 -t 48` instead.

and

Am I correct to think that with 2) I will launch 48 “main” tasks that will not be able to multithread my `@threads` calls because `nthreads() == 1` then?

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [September 16, 2022, 12:25pm UTC](https://discourse.julialang.org/t/difference-between-nprocs-and-nthreads/87361/2 "2022-09-16T12:25:45Z")

</div>

Do `@everywhere @show Threads.nthreads()`.

This runs the code on every process, so you’ll see how many threads they each have.  
They do not share with one another.

---

<div class="post-metadata">

**Author:** ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)\
**Post date:** [September 17, 2022, 5:35pm UTC](https://discourse.julialang.org/t/difference-between-nprocs-and-nthreads/87361/3 "2022-09-17T17:35:58Z")

</div>

Thank you 🙂
