Ask Your Question
1

Possible to combine @parallel and %cython?

asked 2012-05-25 16:23:40 +0100

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

We have both @parallel and %cython to speed-up calculations. Can we join them?

A simple example to test that indeed all four cores are active.
sage: @parallel(p_iter='multiprocessing')
sage: def spill(n):
... tell=0
... while n>1:
... n=int(n/2-(5n+2)/4((-1)^(n&1)-1))
... tell+=1
... return tell
...
sage: a=9780657630
sage: for X, Y in sorted(list(spill([a]*4))): print X,Y
((9780657630,), {}) 1132
((9780657630,), {}) 1132
((9780657630,), {}) 1132
((9780657630,), {}) 1132


How can I use %cython to optimize the code further? I tried to find a way but always the message 'global name '....' is not defined' appears. N.B.: the '3x+1'-code itself is only an example and not my problem.

Thanks in advance for your suggestions! I use VirtualBox, Win7 64, Sage 4.8 Roland

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2012-05-28 03:39:28 +0100

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I would take the while loop and split it out as it's own function. Then, make that function a cython function and see if you can statically type the variables n and tell.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-05-25 16:23:40 +0100

Seen: 393 times

Last updated: May 28 '12