# Multiple Ray Head Nodes

**URL:** <https://discuss.ray.io/t/multiple-ray-head-nodes/9003>\
**Category:** Ray Core\
**Created:** [January 18, 2023, 3:56am UTC](https://discuss.ray.io/t/multiple-ray-head-nodes/9003 "2023-01-18T03:56:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xzf0kgb0bqr.cev2RWU](https://avatars.discourse-cdn.com/v4/letter/x/65b543/32.png) [@xzf0kgb0bqr.cev2RWU](https://discuss.ray.io/u/xzf0kgb0bqr.cev2RWU)\
**Post date:** [January 18, 2023, 3:56am UTC](https://discuss.ray.io/t/multiple-ray-head-nodes/9003/1 "2023-01-18T03:56:02Z")

</div>

Low: It annoys or frustrates me for a moment.

* * *

I am using 2 nodes and 2 folders. I want to create 2 processes with Slurm, one to go into each folder. So something like:

```auto
srun [run python script using one node] &
srun [run same python script using other node] &
wait

```

So far so good.

**Question**

Each process I want to further parallelize using Ray. So I want to create two Ray head nodes that do not communicate with each other, since the folders are independent from each other.

How can I do this?

Presumably something like:

```auto
srun [run a python script that starts a Ray head node with no worker nodes since just one node] &
srun [run the same python script that creates a Ray head node that does not talk with the Ray head node from first line, since two folders are independent] &
wait

```

---

<div class="post-metadata">

**Author:** ![Stephanie\_Wang](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/stephanie_wang/32/18_2.png) [@Stephanie\_Wang](https://discuss.ray.io/u/Stephanie_Wang)\
**Post date:** [January 19, 2023, 3:45pm UTC](https://discuss.ray.io/t/multiple-ray-head-nodes/9003/2 "2023-01-19T15:45:30Z")

</div>

Ray nodes are usually meant to be deployed one per VM/physical machine, which is why we strongly recommend against running multiple head nodes (or even worker nodes) on the same machine. For your use case, it should be okay to run both Python scripts on the same Ray head node, since Ray will internally run the Python scripts in different Ray jobs, parallelize them with separate processes, etc.

---

<div class="post-metadata">

**Author:** ![xzf0kgb0bqr.cev2RWU](https://avatars.discourse-cdn.com/v4/letter/x/65b543/32.png) [@xzf0kgb0bqr.cev2RWU](https://discuss.ray.io/u/xzf0kgb0bqr.cev2RWU)\
**Post date:** [January 20, 2023, 3:42am UTC](https://discuss.ray.io/t/multiple-ray-head-nodes/9003/3 "2023-01-20T03:42:42Z")

</div>

I’m a bit confused now. If I have two nodes (each with 20 CPUs), would that be one head node (with 20 CPUs) and one worker node (with 20 CPUs), or would that just be one head node with 40 CPUs (that somehow connects the two nodes I have)?

Thanks!

---

<div class="post-metadata">

**Author:** ![Stephanie\_Wang](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/stephanie_wang/32/18_2.png) [@Stephanie\_Wang](https://discuss.ray.io/u/Stephanie_Wang)\
**Post date:** [January 23, 2023, 5:16pm UTC](https://discuss.ray.io/t/multiple-ray-head-nodes/9003/4 "2023-01-23T17:16:59Z")

</div>

A Ray node must fit entirely in one machine, so the recommendation would be the former (start a head node one node and a worker node on the other). Then if you want to make sure that a certain task or group of tasks is only scheduled to one node, you could use something like the [NodeAffinitySchedulingStrategy](https://docs.ray.io/en/latest/ray-core/scheduling/index.html#nodeaffinityschedulingstrategy).

The other way to do it is to start separate Ray “clusters” by launching one head node per physical node. But this is a bit more complicated than what you need because then you’ll need to manage multiple “clusters”.
