# Running openmc from python

**URL:** <https://openmc.discourse.group/t/running-openmc-from-python/1358>\
**Category:** User Support\
**Created:** [August 4, 2021, 5:26am UTC](https://openmc.discourse.group/t/running-openmc-from-python/1358 "2021-08-04T05:26:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TimeLard](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@TimeLard](https://openmc.discourse.group/u/TimeLard)\
**Post date:** [August 4, 2021, 5:26am UTC](https://openmc.discourse.group/t/running-openmc-from-python/1358/1 "2021-08-04T05:26:49Z")

</div>

Heiyas,

I’m very new to openmc and want to it from python. How should I do this? Is this something I type in the .py script, and if so, how do I execute it?

To be clear, I don’t want to run openmc in my terminal since I want to be able to set the number of threads it will use.

---

<div class="post-metadata">

**Author:** ![Pranto](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/pranto/32/489_2.png) [@Pranto](https://openmc.discourse.group/u/Pranto)\
**Post date:** [August 4, 2021, 6:33am UTC](https://openmc.discourse.group/t/running-openmc-from-python/1358/2 "2021-08-04T06:33:51Z")

</div>

Welcome to the forum @TimeLard

If you want to run it from python, you can set number of threads with

```python
openmc.run(threads=8)

```

you’ll find more details [here](https://docs.openmc.org/en/stable/pythonapi/generated/openmc.run.html#openmc-run)

From the command line, you can use `-S` command-line argument to set number of threads.

---

<div class="post-metadata">

**Author:** ![TimeLard](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@TimeLard](https://openmc.discourse.group/u/TimeLard)\
**Post date:** [August 4, 2021, 6:05pm UTC](https://openmc.discourse.group/t/running-openmc-from-python/1358/3 "2021-08-04T18:05:32Z")

</div>

Thank you. What does it mean by a “process” in the MPI section?

---

<div class="post-metadata">

**Author:** ![Pranto](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/pranto/32/489_2.png) [@Pranto](https://openmc.discourse.group/u/Pranto)\
**Post date:** [August 5, 2021, 4:35am UTC](https://openmc.discourse.group/t/running-openmc-from-python/1358/4 "2021-08-05T04:35:34Z")

</div>

It means `number of copies of the program` on the given node. Those instances will communicate with each other via MPI.

---

<div class="post-metadata">

**Author:** ![paulromano](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/paulromano/32/486_2.png) [@paulromano](https://openmc.discourse.group/u/paulromano)\
**Post date:** [August 8, 2021, 8:38pm UTC](https://openmc.discourse.group/t/running-openmc-from-python/1358/5 "2021-08-08T20:38:28Z")

</div>

A [process](https://en.wikipedia.org/wiki/Process_(computing)) is simply an application running on your computer with one or more threads. MPI allows you to start multiple copies of the same OpenMC process that run independently (notably each occupies its own memory space) but can communicate through standards calls. OpenMC uses these communication calls in order to collect results from the different processes. If you have multiple cores on a computer, you need to either use threading, MPI, or a combination of them to fully utilize the hardware resources. If you are running on a single machine, threading is usually sufficient. If you are running on a cluster where multiple nodes are connected by a network, MPI is needed to utilize multiple nodes.
