# \[CTest\] best practice for running tests on a cluster

**URL:** https://discourse.cmake.org/t/ctest-best-practice-for-running-tests-on-a-cluster/7202
**Category:** Usage
**Created:** [January 5, 2023, 7:54am UTC](https://discourse.cmake.org/t/ctest-best-practice-for-running-tests-on-a-cluster/7202 "2023-01-05T07:54:09Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![menno](https://discourse.cmake.org/user_avatar/discourse.cmake.org/menno/32/2928_2.png) [@menno](https://discourse.cmake.org/u/menno)
#### Post date: [January 5, 2023, 7:54am UTC](https://discourse.cmake.org/t/ctest-best-practice-for-running-tests-on-a-cluster/7202/1 "2023-01-05T07:54:09Z")

</div>

I’m wondering what the best way to run tests on a cluster would be when I use CTest. The objective is to run a number of tests on the compute nodes of a cluster that has the SLURM resource aanager. Any tips are welcome 🙂

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [January 5, 2023, 1:06pm UTC](https://discourse.cmake.org/t/ctest-best-practice-for-running-tests-on-a-cluster/7202/2 "2023-01-05T13:06:36Z")

</div>

@chuckatkins? My gut says that the test commands would need to use `slrum`, but maybe there’s some other trick available.

---

<div class="post-metadata">

### Author: ![menno](https://discourse.cmake.org/user_avatar/discourse.cmake.org/menno/32/2928_2.png) [@menno](https://discourse.cmake.org/u/menno)
#### Post date: [January 5, 2023, 2:58pm UTC](https://discourse.cmake.org/t/ctest-best-practice-for-running-tests-on-a-cluster/7202/3 "2023-01-05T14:58:09Z")

</div>

Ok, I suspected as much as googling did not turn up much.

Some testing shows that it is easy to do with an interactive job, e.g. to run an 8-core “test\_command” on a single node:

```auto
add_test(NAME test_srun 
         COMMAND srun --nodes 1 --output test_output-%A.out 
                 mpirun -n 8 <test_command> <test_options>)

```

---

<div class="post-metadata">

### Author: ![fsimonis](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fsimonis/32/1712_2.png) [@fsimonis](https://discourse.cmake.org/u/fsimonis)
#### Post date: [June 16, 2023, 1:05pm UTC](https://discourse.cmake.org/t/ctest-best-practice-for-running-tests-on-a-cluster/7202/4 "2023-06-16T13:05:22Z")

</div>

Hi @menno,

If you run individual tests on a cluster using slurm, be careful about waiting times, timeouts and other problems.  
Also some clusters have different environments on compute nodes, so you may need to load modules etc. This can be tedious to get right and maintain in single commands.

At preCICE, we found that it’s way easier to run the entirety of ctest in a single job script. This also simplifies getting the setup working before moving to more involved setups.

Best  
Frédéric
