# Accessing MPI comm in a pvbatch script

**URL:** https://discourse.paraview.org/t/accessing-mpi-comm-in-a-pvbatch-script/11637
**Category:** ParaView Support
**Tags:** mpi, python
**Created:** [March 15, 2023, 11:11pm UTC](https://discourse.paraview.org/t/accessing-mpi-comm-in-a-pvbatch-script/11637 "2023-03-15T23:11:57Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Prathamesh\_Sirmalla](https://discourse.paraview.org/user_avatar/discourse.paraview.org/prathamesh_sirmalla/32/7328_2.png) [@Prathamesh\_Sirmalla](https://discourse.paraview.org/u/Prathamesh_Sirmalla)
#### Post date: [March 15, 2023, 11:11pm UTC](https://discourse.paraview.org/t/accessing-mpi-comm-in-a-pvbatch-script/11637/1 "2023-03-15T23:11:57Z")

</div>

I have a python script which reads a .cgns file, computes my quantities of interest and writes it to a file. Initially I was using pvpython to run this script, but as my data sets are growing I wish to switch to pvbatch. When I tried pvbatch everything was working fine but I was receiving output from every MPI rank, i.e.  
`print("Hello World")`  
would be printed by every rank, and every rank would write the same value to the file as I did  
`file.write(value)`

Is there a way I could make these commands execute on root rank ? Maybe a pythonic way of accessing MPI comm ? Any help is appreciated.

regards

Prathamesh

---

<div class="post-metadata">

### Author: ![Christos\_Tsolakis](https://discourse.paraview.org/user_avatar/discourse.paraview.org/christos_tsolakis/32/4450_2.png) [@Christos\_Tsolakis](https://discourse.paraview.org/u/Christos_Tsolakis)
#### Post date: [March 16, 2023, 12:21am UTC](https://discourse.paraview.org/t/accessing-mpi-comm-in-a-pvbatch-script/11637/2 "2023-03-16T00:21:10Z")

</div>

To get the process id :

```python
import paraview.servermanager
pm = paraview.servermanager.vtkProcessModule.GetProcessModule()

processId = pm.GetGlobalController().GetLocalProcessId()
if processId == 0:

```

For more examples take a look into  
[https://gitlab.kitware.com/paraview/paraview/-/tree/master/Remoting/Application/Testing/Python](https://gitlab.kitware.com/paraview/paraview/-/tree/master/Remoting/Application/Testing/Python)

And look for examples with “Parallel” in their name.
