# Can a single root macro be run multiple times simulatenously?

**URL:** <https://root-forum.cern.ch/t/can-a-single-root-macro-be-run-multiple-times-simulatenously/58412>\
**Category:** Newbie\
**Tags:** root\
**Created:** [March 6, 2024, 3:28pm UTC](https://root-forum.cern.ch/t/can-a-single-root-macro-be-run-multiple-times-simulatenously/58412 "2024-03-06T15:28:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [March 6, 2024, 3:28pm UTC](https://root-forum.cern.ch/t/can-a-single-root-macro-be-run-multiple-times-simulatenously/58412/1 "2024-03-06T15:28:58Z")

</div>

Hi everyone,  
I have a question (probably more related to the basics of C/C++).

I have a root macro that takes in a file, processes it, and saves the output in a file; the input and output files are indexed(so no overwriting).  
Once I execute the root macro to take input input\_file\_1 and output in output\_1 and it is still running, can I -e-execute that macro with a different input(input\_file\_1) and corresponding out file(output\_file\_2)?

Thanks a lot !

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [March 6, 2024, 8:08pm UTC](https://root-forum.cern.ch/t/can-a-single-root-macro-be-run-multiple-times-simulatenously/58412/2 "2024-03-06T20:08:43Z")

</div>

From what you describe you can launch multiple process either running the macro with the different argument without any problem.

You can also most likely (if your macro/function is thread safe) do it with a single process and multiple threads, for example something like:

```auto
ROOT::EnableThreadSafetly()
std::vector<std::thread> threads;
for( loop over the inputs ) {
   threads.emplace_back( name_of_function, value_arguments);
}
for (auto& t : threads)
  t.join();

```

---

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [March 7, 2024, 5:07am UTC](https://root-forum.cern.ch/t/can-a-single-root-macro-be-run-multiple-times-simulatenously/58412/3 "2024-03-07T05:07:03Z")

</div>

Thank You @pcanal

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [March 8, 2024, 3:20pm UTC](https://root-forum.cern.ch/t/can-a-single-root-macro-be-run-multiple-times-simulatenously/58412/4 "2024-03-08T15:20:38Z")

</div>

An alternative is to use bash for the multiple processes.

```auto
root -l -b -q -e '.L myscript.cpp+'

root -l -b -q myscript.cpp+(arg1) & root -l -b -q myscript.cpp+(arg2) & ...

```
