[Networkit] parallel Graph iterators for Python

Christian Staudt christian.staudt at kit.edu
Thu Nov 19 16:56:40 CET 2015


What about the Cython level then? If I have a simple function (see example below) and put it inside a .pyx file, would it work with the parallel iterator?

		def sweep(u):
			""" switch states of nodes"""
			if state[u] == S:
				pass
			elif state[u] == E:
				# exposed nodes become infectious after eTime
				if (t - timestamp[u]) >= self.eTime:
					setState(u, I)
			elif state[u] == I:
				# contact neighbors of infectious nodes with a chance to transmit infection
				for v in self.G.neighbors(u):
					contact(v)
				# infectious nodes become removed after iTime
				if (t - timestamp[u]) >= self.iTime:
					setState(u, R)
			elif state[u] == R:
				pass

		# apply here
		self.G.forNodes(sweep)


On 19 Nov 2015, at 05:51, Michael Hamann <michael.hamann at kit.edu> wrote:

> Hi,
> 
> On Wednesday 18 November 2015 19:25:29, Christian Staudt wrote:
>> is there a reason why only the sequential Graph iterators are pythonized?
>> Can the parallel iterators be accessed via Python and/or Cython?
> 
> There are several reasons. First of all the parallel iterators use new
> threads. Each of these threads needs to be initialized for Python (see also
> [0]). The second reason is that all code that is pure Python code needs to
> hold the global interpreter lock (GIL). We would need to acquire that lock for
> every single node or edge which is a huge overhead and means that that the
> only way that the code for several nodes or edges can run in parallel is if it
> releases the GIL again. For example if the Python callback calls other
> NetworKit methods this would be the case for run()-methods, but not for simple
> getter or setter methods. We could add that there of course, but I think that
> in many cases releasing and acquiring the lock is more work than the actual
> method call.
> 
> Therefore I think that it doesn't make sense to find out how to make the
> parallel iterators accessible in Python as there is probably no benefit of
> having them available.
> 
> Best regards,
> Michael
> 
> [0] https://gist.github.com/liuyu81/3473376 for a C-API example,
> http://stackoverflow.com/questions/29243881/communication-between-python-cython-c-in-multithreaded-environment describes the setting we would need -
> but does not have a real answer.
> 
> _______________________________________________
> NetworKit mailing list
> NetworKit at ira.uni-karlsruhe.de
> https://lists.ira.uni-karlsruhe.de/mailman/listinfo/networkit

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 495 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <https://lists.ira.uni-karlsruhe.de/mailman/private/networkit/attachments/20151119/0d969113/attachment.sig>


More information about the NetworKit mailing list