Skip to content

Commit

Permalink
[WIP] Try to avoid stage 4 sorting for polynomials
Browse files Browse the repository at this point in the history
  • Loading branch information
tueda committed Jul 7, 2017
1 parent 0ca6935 commit 08cb08f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 12 deletions.
10 changes: 5 additions & 5 deletions form/formlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ def open(self, args=None, keep_log=False):
fd_parentin, fd_childout = os.pipe()
fd_loggingin, fd_loggingout = os.pipe()

args.append('-M')
args.append('-pipe')
args.append('{0},{1}'.format(fd_childin, fd_childout))
args.append(self._INIT_FRM)

pid = os.fork()
if pid:
# parent process
Expand Down Expand Up @@ -179,11 +184,6 @@ def open(self, args=None, keep_log=False):
os.close(fd_loggingin)
os.dup2(fd_loggingout, sys.__stdout__.fileno())

args.append('-M')
args.append('-pipe')
args.append('{0},{1}'.format(fd_childin, fd_childout))
args.append(FormLink._INIT_FRM)

# In Python 3.2, subprocess.Popen() on UNIX changed the default
# value for close_fds from False to True, in order to stop leaking
# file descriptors. File descriptors to be kept open should be
Expand Down
40 changes: 40 additions & 0 deletions form/poly/init.frm
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
* Adopt the default values.
#:filepatches 256
#:largepatches 256
#:largesize 50000000
#:smallextension 20000000
#:smallsize 10000000
#:sortiosize 100000
#:termsinsmall 100000

* Try to avoid stage 4 sorting for $-variables by increasing these values.
#:subfilepatches 256
#:sublargepatches 256
#:sublargesize 50000000
#:subsmallextension 20000000
#:subsmallsize 10000000
#:subsortiosize 100000
#:subtermsinsmall 100000

* Smaller maxtermsize for each monomial in polynomials.
#:maxtermsize 10000

* The following is the same as form/init.frm.
Off stats;
Off finalstats;
Format nospaces;
Format 255;
#ifndef `PIPES_'
#message "No pipes found"
.end;
#endif
#if `PIPES_' <= 0
#message "No pipes found"
.end;
#endif
#setexternal `PIPE1_'
#toexternal "OK"
#do FORMLINKLOOPVAR=1,1
#fromexternal
#enddo
.end
2 changes: 1 addition & 1 deletion form/poly/poly.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Polynomial(object):
def get_instance(cls):
"""Return the FORM instance for polynomial arithmetic."""
if cls._form is None:
cls._form = singleton.FormSingleton()
cls._form = singleton.PolyFormLink()
# Implicit declaration for symbols.
cls._form.install_hook(
'Auto S '
Expand Down
14 changes: 9 additions & 5 deletions form/poly/singleton.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
"""Singleton."""
"""Singleton for polynomial arithmetic."""

from .. import formlink
from ..datapath import get_data_path
from ..six import string_types


class FormSingleton(formlink.FormLink):
"""Customized FormLink for a singleton."""
class PolyFormLink(formlink.FormLink):
"""Customized FormLink for polynomial arithmetic."""

# Override the input file for FORM.
_INIT_FRM = get_data_path('form', 'poly/init.frm')

def __init__(self):
"""Construct a link to FORM."""
Expand All @@ -14,11 +18,11 @@ def __init__(self):
self._id_next = 0
self._id_pool = []
self._hooks = []
super(FormSingleton, self).__init__()
super(PolyFormLink, self).__init__()

def open(self, *args, **kwargs):
"""Open a connection."""
super(FormSingleton, self).open(*args, **kwargs)
super(PolyFormLink, self).open(*args, **kwargs)
self._init_instance()

def _init_instance(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
'Topic :: Scientific/Engineering :: Physics',
],
keywords='binding, form, computer algebra',
package_data={'form': ['init.frm']},
package_data={'form': ['init.frm', 'poly/init.frm']},
setup_requires=['nose'],
)

Expand Down

0 comments on commit 08cb08f

Please sign in to comment.