Ask Your Question
0

Sage @fork Parallel Decorator Breaking Interface to Singular

asked 2020-01-02 16:05:40 +0100

StrongPiccolo gravatar image

updated 2020-01-07 16:20:24 +0100

Iguananaut gravatar image

Exception raised by child process with pid=1704:

Traceback (most recent call last):
File "/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/parallel/use_fork.py", line 177, in __call__
self._subprocess(f, dir, *v0)
File "/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/parallel/use_fork.py", line 302, in _subprocess
value = f(*args, **kwds)
File "<ipython-input-9-532b53e3019b>", line 167, in master
reduktion = reduction(polynomial)
File "<ipython-input-9-532b53e3019b>", line 94, in reduction
singular.set_ring(currentRing)
File "/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/interfaces/singular.py", line 1098, in set_ring
self.eval("setring %s; short=0"%R.name(), allow_semicolon=True)
File "/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/interfaces/singular.py", line 658, in eval
raise SingularError('Singular error:\n%s'%s)
SingularError: Singular error:
? sage1317 is no name of a ring/qring
? error occurred in or before STDIN line 11: `setring sage1317; short=0;`

I've been implementing parallelism on a program built in Sage MATH using its interface to Singular. I am attempting to use Sage's @fork parallel decorator, which seems to cause issues with Singular (this error does not occur if the decorator is not present). I'm very new to parallelism and am unsure what the issue here could be. Thanks for any and all help! :D

edit retag flag offensive close merge delete

Comments

Interfaces and "fork" don't mix. If it works at all, you'll end up with two processes interfacing with the same pipe (the parent and the child process). Apart from causing issues when both send commands, there's going to be the even more severe issue of it being undetermined which of the two processes will be consuming output from the singular process as it becomes available.

What should be workable is to create a new singular interface after forking. That will be a private singular process for your fork child.

nbruin gravatar imagenbruin ( 2020-01-02 21:26:53 +0100 )edit

Thanks for the comment! I'm not totally sure what you mean by create a new singular interface, in my code I've just been using singular.<command>. I can post my code if that would be illuminating. I assumed that each call to Singular via Sage was a new instance of the interface, but maybe that is a misinterpretation.

StrongPiccolo gravatar imageStrongPiccolo ( 2020-01-03 16:42:49 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-01-03 18:34:26 +0100

nbruin gravatar image

updated 2020-01-03 18:54:31 +0100

With

s1=Singular()
s2=Singular()

you get two different singular interfaces. Each has its own state. Sage does make some effort to hide the importance of state and just let you get on with wrapped objects, but behind the scenes there's a lot of state management (changing rings etc.)

If your program has any kind of parallelism then you need to be make sure that at any time, there is only one thread/process communicating with a particular singular interface instance. So either you need some semaphore/locking mechanism (the usual for managing access to finite resources) or you just ensure that every thread/process has a private Singular interface instance to talk to.

The way files are shared across a fork is tricky (as in: unix doesn't really help you with that). In general, you're probably safest by assuming that after a fork, any interface instances in the child inherited from the parent are not functional (i.e., they belong to the parent), so any interfaces that you use in the child should be instantiated after the fork.

edit flag offensive delete link more

Comments

Thank you! I'm unsure of implementation, I'm using a master function that calls other functions which contain calls to Singular. I would like to spawn multiple processes of the master function with @fork. Do I need to create individual singular interfaces for each function, even if the function itself is not parallelized, just the function calling it? I can't seem to space out my code, but hopefully you can decipher the blob.

`@fork

def master(polynomial, goal): s1 = Singular() singular.current_ring = currentRing polynomial = currentPolynomial global hits reduktion = reduction(polynomial) if testForICIS(polynomial, reduktion) == True:`

StrongPiccolo gravatar imageStrongPiccolo ( 2020-01-03 18:46:23 +0100 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-01-02 16:05:40 +0100

Seen: 309 times

Last updated: Jan 07 '20