# Guidance on parallel writing of Xdmf from Python

**URL:** https://discourse.paraview.org/t/guidance-on-parallel-writing-of-xdmf-from-python/14545
**Category:** ParaView Support
**Created:** [May 3, 2024, 9:17am UTC](https://discourse.paraview.org/t/guidance-on-parallel-writing-of-xdmf-from-python/14545 "2024-05-03T09:17:40Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![paulmelis](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/4bbf92/32.png) [@paulmelis](https://discourse.paraview.org/u/paulmelis)
#### Post date: [May 3, 2024, 9:17am UTC](https://discourse.paraview.org/t/guidance-on-parallel-writing-of-xdmf-from-python/14545/1 "2024-05-03T09:17:41Z")

</div>

For one of our users I’m trying to get a Python script working that reads an OpenFoam dataset (using the empty .foam file trick), adding a few Calculator filters and then saving the output to a parallel Xdmf dataset for later parallel visualization.

The script is made using a trace from the GUI and the load/save statements look like this:

```auto
testfoam = OpenFOAMReader(registrationName='test.foam', FileName='/home/user/Test_paraview/Fresh-Salt/test.foam')
testfoam.MeshRegions = ['internalMesh']
testfoam.CellArrays = ['U', 'epsilon', 'k', 'nut', 'p']

<set up pipeline>

SaveData('/home/paulm/doh.xmf', proxy=calculator3, PointDataArrays=['U', 'coords_X', 'coords_Y', 'coords_Z', 'epsilon', 'k', 'nut', 'p'],
    FieldDataArrays=['CasePath'])

```

When I load this into the ParaView GUI as state, or run it directly under `pvbatch`, then it executes fine and saves the Xdmf file.

So the question is then, can such a script be used unmodified to write a parallel Xdmf file (or any file format), simply by allocating an MPI job and running it under `srun pvbatch`? Because when I do, the job gets stuck and simply doesn’t finish. Even though it only takes a few seconds in the GUI with the test datasets I’m using. Is there any documentation specifically on writing in parallel from Python? And is Xdmf special in this respect?

Also, I’m using a self-compiled ParaView 5.11.2 here, so there might be something up with MPI, options, etc.

Thanks for any guidance!

---

<div class="post-metadata">

### Author: ![paulmelis](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/4bbf92/32.png) [@paulmelis](https://discourse.paraview.org/u/paulmelis)
#### Post date: [June 3, 2024, 6:05pm UTC](https://discourse.paraview.org/t/guidance-on-parallel-writing-of-xdmf-from-python/14545/2 "2024-06-03T18:05:45Z")

</div>

Answering to myself, but for now we’ll use the workaround of running `foamToVTK` on the OpenFOAM case output (possibly with the `-parallel` option). And then a bit of Python and VTK to convert those VTK files to HDF5+Xdmf:

```auto
#!/usr/bin/env python3
import sys, vtk
dr = vtk.vtkDataSetReader()
dr.SetFileName(sys.argv[1])
dw = vtk.vtkXdmf3Writer()
dw.SetInputConnection(dr.GetOutputPort())
dw.SetFileName(sys.argv[2])
dw.Write()

```
