简体   繁体   English

Python,VTK 和 GIL 版本

[英]Python, VTK and GIL release

I'm trying to parallelise processing of large datasets in VTK using its Python interface.我正在尝试使用其 Python 接口并行处理 VTK 中的大型数据集。 For that, I want to use joblib since I have a (large) number of independent snapshots that I want to process and gather in a large numpy matrix, ie something like:为此,我想使用 joblib,因为我有(大量)独立快照,我想在一个大型 numpy 矩阵中处理和收集这些快照,例如:

import vtk
from vtk.numpy_interface import dataset_adapter as dsa
for i,snap in enumerate(snapshot_list):
   myVtkFilter.SetInputData(snap)
   result = myVtkFilter.GetOutput()
   output[i, :] = dsa.WrapDataObject(result).CellData['myArray']

However, I'm facing some issues:但是,我面临一些问题:

  1. If I use the default loky backend, Python complains about the output matrix not being writable (it's a very large dataset, a matrix like (100, 1000000, 3)).如果我使用默认的 loky 后端,Python 会抱怨 output 矩阵不可写(这是一个非常大的数据集,像 (100, 1000000, 3) 这样的矩阵)。 The fact that it needs to be serialised by loky would be a major overhead anyway;无论如何,它需要由 loky 序列化这一事实将是一个重大开销。
  2. If I want to use Python threads, the code runs alright, but it seems to me that VTK doesn't release the GIL for most of the time (only one core is used for the largest part of the time).如果我想使用 Python 线程,代码运行正常,但在我看来,VTK 大部分时间都不会释放 GIL(大部分时间只使用一个内核)。 I would expect that, like numpy, VTK calls should release the GIL (as per this release note http://vtk.1045678.n5.nabble.com/Announce-vtk-7-0-0-release-candidate-1-is-ready-td5735575.html ), but it doesn't seem to be the case.我希望像 numpy 一样,VTK 调用应该释放 GIL(根据此发行说明http://vtk.1045678.n5.nabble.com/Announce-vtk-7-0-0-release-candidate-1- is-ready-td5735575.html ),但似乎并非如此。

I'm using Python 3.7.3 with VTK 8.1.2.我正在使用 Python 3.7.3 和 VTK 8.1.2。 Any suggestions?有什么建议么?

There was some issue with the GIL in VTK 8.2.0, they have been fixed here: https://gitlab.kitware.com/paraview/paraview/-/issues/14169 and the fix is present in VTK 9.0.1. VTK 8.2.0 中的 GIL 存在一些问题,它们已在此处修复: https://gitlab.kitware.com/paraview/paraview/-/issues/14169并且修复程序存在于 VTK 9.0.1 中。

Update to VTK 9.0.1 and use the VTK_PYTHON_FULL_THREADSAFE=ON CMake option to fix your problem.更新到 VTK 9.0.1 并使用 VTK_PYTHON_FULL_THREADSAFE=ON CMake 选项来解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM