# \[pvpython\] Optimizing for performance

**URL:** https://discourse.paraview.org/t/pvpython-optimizing-for-performance/7205
**Category:** ParaView Support
**Tags:** python
**Created:** [May 11, 2021, 12:20pm UTC](https://discourse.paraview.org/t/pvpython-optimizing-for-performance/7205 "2021-05-11T12:20:57Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![luco](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/l/91b2a8/32.png) [@luco](https://discourse.paraview.org/u/luco)
#### Post date: [May 11, 2021, 12:20pm UTC](https://discourse.paraview.org/t/pvpython-optimizing-for-performance/7205/1 "2021-05-11T12:20:57Z")

</div>

Hi,

Heads-up: I am fairly new to Paraview.

I have been running `pvpython` (ParaView version 5.6.0) on a HPC cluster with many cores and lots of memory available, but the scripts seem to run very slowly, no matter the resources I allocate. I’m calculating gradients of scalar fields in a 2D domain and then save the fields along an isoconour as CSV files. My code to compute the gradients looks something like

```auto
gradientOfUnstructuredDataSet1 = GradientOfUnstructuredDataSet(registrationName='GradientOfUnstructuredDataSet1', Input=infilenek5000)
gradientOfUnstructuredDataSet1.ScalarArray = ['POINTS', 'temperature']

# rename source object
RenameSource('grad_T', gradientOfUnstructuredDataSet1)

# Properties modified on gradientOfUnstructuredDataSet1
gradientOfUnstructuredDataSet1.ResultArrayName = 'grad_T'

# create a new 'Gradient Of Unstructured DataSet'
gradientOfUnstructuredDataSet1_1 = GradientOfUnstructuredDataSet(registrationName='GradientOfUnstructuredDataSet1', Input=gradientOfUnstructuredDataSet1)
gradientOfUnstructuredDataSet1_1.ScalarArray = ['POINTS', 'grad_T']

# rename source object
RenameSource('grad_grad_T', gradientOfUnstructuredDataSet1_1)

# Properties modified on gradientOfUnstructuredDataSet1_1
gradientOfUnstructuredDataSet1_1.ResultArrayName = 'grad_grad_T'

```

and for saving the fields:

```auto
contour1 = Contour(registrationName='Contour1', Input=gradientOfUnstructuredDataSet1_7)
contour1.ContourBy = ['POINTS', 'temperature']
contour1.Isosurfaces = [3.8]
contour1.PointMergeMethod = 'Uniform Binning'

# save data
SaveData(outdir + '/out.csv', 
	     proxy=contour1, 
	     WriteTimeSteps=1)

```

I’m not sure how to optimize for performance, so I have a few questions:  
(a) Does `pvpython` run in parallel?  
(b) Can increasing the available RAM reduce runtime? What is reasonable here?  
(c) Are there more general strategies to speed up calculating gradients and extracting the fields? Is there a way to restrict the operations to an area of the domain?

Any help would be very much appreciated!

Cheers,  
Lukas

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [May 11, 2021, 12:24pm UTC](https://discourse.paraview.org/t/pvpython-optimizing-for-performance/7205/2 "2021-05-11T12:24:36Z")

</div>

> (a) Does `pvpython` run in parallel?

No, use pvbatch

> (b) Can increasing the available RAM reduce runtime? What is reasonable here?

No, unless you are swapping. Never use swap for computation anyway.

> (c) Are there more general strategies to speed up calculating gradients and extracting the fields?

- Reduce the size of the data you are working with.
- Work in parallel
- Increase number of cores

> Is there a way to restrict the operations to an area of the domain?

ExtractSelection ?

---

<div class="post-metadata">

### Author: ![luco](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/l/91b2a8/32.png) [@luco](https://discourse.paraview.org/u/luco)
#### Post date: [May 11, 2021, 2:09pm UTC](https://discourse.paraview.org/t/pvpython-optimizing-for-performance/7205/3 "2021-05-11T14:09:35Z")

</div>

Beautiful, thank you sir. I was unaware of `pvbatch`.
