Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary signal handling for low prec mpfr operations. #7879

Closed
robertwb opened this issue Jan 9, 2010 · 26 comments
Closed

Remove unnecessary signal handling for low prec mpfr operations. #7879

robertwb opened this issue Jan 9, 2010 · 26 comments

Comments

@robertwb
Copy link
Contributor

robertwb commented Jan 9, 2010

_sig_on and _sig_off are more expensive than computing the result itself.


Apply only attachment: trac_7879-RR-signal.2.rebased_to_4.7.2.alpha2.patch to the Sage library.

Component: basic arithmetic

Keywords: sd32

Author: Robert Bradshaw

Reviewer: Alex Ghitza, Mariah Lenox, William Stein

Merged: sage-4.7.2.alpha3

Issue created by migration from https://trac.sagemath.org/ticket/7879

@robertwb
Copy link
Contributor Author

robertwb commented Jan 9, 2010

comment:1

Signal handling is omitted for functions/precisions that were clearly and uniformly in the millisecond range or less.

@robertwb

This comment has been minimized.

@robertwb
Copy link
Contributor Author

robertwb commented Jan 9, 2010

Attachment: 7879-RR-signal.patch.gz

@aghitza
Copy link

aghitza commented Jan 20, 2010

Reviewer: Alex Ghitza

@aghitza
Copy link

aghitza commented Jan 20, 2010

Author: Robert Bradshaw

@aghitza
Copy link

aghitza commented Jan 20, 2010

comment:3

This looks good. I have one question: you are hardcoding threshold precisions after which the signals should be used, mostly 1000, but also 10000 in a couple of places. Would it be better to have a global variable PREC_THRESHOLD set to 1000 at the top of the file, and then use it or 10*PREC_THRESHOLD where needed? It would make it easier to change this in the future, since a search for it would be all that's needed.

I'm marking this as needs_info. If you think it's not worth the trouble, I'll put a positive review.

@jdemeyer
Copy link

comment:4

I am proposing to close this ticket as invalid since #9678 makes sig_on() and sig_off() a lot faster. In any case, if you want to keep the patch, it needs rebasing (_sig_on and _sig_off must be replaced by sig_on() and sig_off() but there are more patch conflicts).

@jdemeyer jdemeyer removed this from the sage-4.6.2 milestone Jan 19, 2011
@sagetrac-mariah
Copy link
Mannequin

sagetrac-mariah mannequin commented May 17, 2011

comment:5

Since this ticket is marked sage-duplicate/invalid/wontfix plus has
not been active for 4 months, I believe this ticket can be closed.

@jdemeyer
Copy link

comment:6

Robert, what is your opinion? sig_on() and sig_off() became a lot faster since #9678, but they still take up some cycles.

@robertwb
Copy link
Contributor Author

comment:7

Thanks for taking a look at this. I've been waiting for 4.7 to be released to re-base this, and think it'd still worth having. Perhaps I'll put PREC_THRESHOLD in there while I'm at it, and maybe do some benchmarking.

@robertwb robertwb added this to the sage-4.7.1 milestone May 17, 2011
@jdemeyer
Copy link

comment:9

Replying to @robertwb:

and maybe do some benchmarking.

If you find useful ways to do benchmarks, please let me know. I might re-use those benchmarks to optimize sig_on() and sig_off().

@jdemeyer
Copy link

comment:10

The patch adds one unrelated doctest. This doctest has been moved to #11344.

@robertwb
Copy link
Contributor Author

comment:11
----------------------------------------------------------------------
| Sage Version 4.7, Release Date: 2011-05-23                         |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
Loading Sage library. Current Mercurial branch is: bitrot

sage: L = [RR(k) for k in range(1000)]

sage: %timeit [a.sqrt() for a in L]
 625 loops, best of 3: 569 µs per loop

sage: %timeit [a.sqrt() for a in L]
 625 loops, best of 3: 509 µs per loop

sage: %timeit [a.sqrt() for a in L]
 625 loops, best of 3: 513 µs per loop

sage: timeit("[a.sqrt() for a in L]", number=10000)
10000 loops, best of 3: 519 µs per loop

sage: 
Exiting Sage (CPU time 0m19.94s, Wall time 1m9.75s).
robertwb@sage:/scratch/robertwb/sage-4.7/devel/sage-bitrot$ hg qpush
applying 7879-RR-signal.patch
now at: 7879-RR-signal.patch
robertwb@sage:/scratch/robertwb/sage-4.7/devel/sage-bitrot$ ../../sage -br
[...]
----------------------------------------------------------------------
| Sage Version 4.7, Release Date: 2011-05-23                         |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
Loading Sage library. Current Mercurial branch is: bitrot

sage: L = [RR(k) for k in range(1000)]

sage: %timeit [a.sqrt() for a in L]
 625 loops, best of 3: 498 µs per loop

sage: %timeit [a.sqrt() for a in L]
 625 loops, best of 3: 498 µs per loop

sage: %timeit [a.sqrt() for a in L]
 625 loops, best of 3: 496 µs per loop

sage: timeit("[a.sqrt() for a in L]", number=10000)
10000 loops, best of 3: 499 µs per loop

Looks like about a 5% win (much smaller than I remember it being before).

@robertwb
Copy link
Contributor Author

Attachment: 7879-RR-signal.2.patch.gz

Rebased on 4.7

@sagetrac-mariah
Copy link
Mannequin

sagetrac-mariah mannequin commented Jun 1, 2011

comment:12

patch attachment: 7879-RR-signal.2.patch applied to sage-4.7.1.alpha1. Then did 'sage -b' followed by 'make testlong'.
The following test failed:

eno% ./sage -t  -long -force_lib "devel/sage/sage/rings/residue_field.pyx"
sage -t -long -force_lib "devel/sage/sage/rings/residue_field.pyx"
**********************************************************************
File "/home/mariah/sage/sage-4.7.1.alpha1-x86_64-Linux-core2-fc-review-7879/devel/sage/sage/rings/residue_field.pyx", line 670:
    sage: I = QQ[3^(1/3)].factor(5)[1][0]; I
Exception raised:
    Traceback (most recent call last):
      File "/home/mariah/sage/sage-4.7.1.alpha1-x86_64-Linux-core2-fc-review-7879/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/home/mariah/sage/sage-4.7.1.alpha1-x86_64-Linux-core2-fc-review-7879/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/home/mariah/sage/sage-4.7.1.alpha1-x86_64-Linux-core2-fc-review-7879/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_10[2]>", line 1, in <module>
        I = QQ[Integer(3)**(Integer(1)/Integer(3))].factor(Integer(5))[Integer(1)][Integer(0)]; I###line 670:
    sage: I = QQ[3^(1/3)].factor(5)[1][0]; I
      File "ring.pyx", line 167, in sage.rings.ring.Ring.__getitem__ (sage/rings/ring.c:2007)
      File "expression.pyx", line 8287, in sage.symbolic.expression.Expression.minpoly (sage/symbolic/expression.cpp:31950)
      File "/home/mariah/sage/sage-4.7.1.alpha1-x86_64-Linux-core2-fc-review-7879/local/lib/python/site-packages/sage/calculus/calculus.py", line 925, in minpoly
        if g(ex).simplify_trig().simplify_radical() == 0:
      File "expression.pyx", line 6546, in sage.symbolic.expression.Expression.simplify_trig (sage/symbolic/expression.cpp:24657)
      File "expression.pyx", line 460, in sage.symbolic.expression.Expression._maxima_ (sage/symbolic/expression.cpp:3674)
      File "sage_object.pyx", line 429, in sage.structure.sage_object.SageObject._interface_ (sage/structure/sage_object.c:3451)
      File "lazy_import.pyx", line 167, in sage.misc.lazy_import.LazyImport.__getattr__ (sage/misc/lazy_import.c:1353)
      File "lazy_import.pyx", line 110, in sage.misc.lazy_import.LazyImport._get_object (sage/misc/lazy_import.c:1023)
      File "/home/mariah/sage/sage-4.7.1.alpha1-x86_64-Linux-core2-fc-review-7879/local/lib/python/site-packages/sage/interfaces/maxima_lib.py", line 152, in <module>
        ecl_eval("#$%s$"%l)
      File "ecl.pyx", line 1224, in sage.libs.ecl.ecl_eval (sage/libs/ecl.c:6301)
      File "ecl.pyx", line 1239, in sage.libs.ecl.ecl_eval (sage/libs/ecl.c:6252)
      File "ecl.pyx", line 252, in sage.libs.ecl.ecl_safe_eval (sage/libs/ecl.c:2544)
    RuntimeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined.
**********************************************************************
File "/home/mariah/sage/sage-4.7.1.alpha1-x86_64-Linux-core2-fc-review-7879/devel/sage/sage/rings/residue_field.pyx", line 672:
    sage: k = I.residue_field(); k
Exception raised:
    Traceback (most recent call last):
      File "/home/mariah/sage/sage-4.7.1.alpha1-x86_64-Linux-core2-fc-review-7879/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/home/mariah/sage/sage-4.7.1.alpha1-x86_64-Linux-core2-fc-review-7879/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/home/mariah/sage/sage-4.7.1.alpha1-x86_64-Linux-core2-fc-review-7879/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_10[3]>", line 1, in <module>
        k = I.residue_field(); k###line 672:
    sage: k = I.residue_field(); k
      File "element.pyx", line 328, in sage.structure.element.Element.__getattr__ (sage/structure/element.c:2792)
      File "parent.pyx", line 277, in sage.structure.parent.getattr_from_other_class (sage/structure/parent.c:2940)
      File "parent.pyx", line 175, in sage.structure.parent.raise_attribute_error (sage/structure/parent.c:2709)
    AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'residue_field'
**********************************************************************

etc.

@williamstein
Copy link
Contributor

comment:13

Replying to @sagetrac-mariah:

patch attachment: 7879-RR-signal.2.patch applied to sage-4.7.1.alpha1. Then did 'sage -b' followed by 'make testlong'.
The following test failed:

eno% ./sage -t  -long -force_lib "devel/sage/sage/rings/residue_field.pyx"
sage -t -long -force_lib "devel/sage/sage/rings/residue_field.pyx"
**********************************************************************
File "/home/mariah/sage/sage-4.7.1.alpha1-x86_64-Linux-core2-fc-review-7879/devel/sage/sage/rings/residue_field.pyx", line 670:
    sage: I = QQ[3^(1/3)].factor(5)[1][0]; I
Exception raised:

These errors don't occur for me with sage-4.7.2.alpha2.

@williamstein
Copy link
Contributor

Changed reviewer from Alex Ghitza to Alex Ghitza, William Stein

@williamstein
Copy link
Contributor

comment:14

I did a full test of Sage on another machine too with 4.7.2.alpha2, and everything works. Code looks good and addresses other people's issues...

@williamstein
Copy link
Contributor

Changed keywords from none to sd32

@nexttime

This comment has been minimized.

@nexttime
Copy link
Mannequin

nexttime mannequin commented Sep 9, 2011

Changed reviewer from Alex Ghitza, William Stein to Alex Ghitza, Mariah Lenox, William Stein

@nexttime
Copy link
Mannequin

nexttime mannequin commented Sep 12, 2011

Sage library patch. Robert's patch rebased to Sage 4.7.2.alpha2, because of fuzz 2.

@nexttime
Copy link
Mannequin

nexttime mannequin commented Sep 12, 2011

Attachment: trac_7879-RR-signal.2.rebased_to_4.7.2.alpha2.patch.gz

Attachment: trac_7879-harmless_fuzz_2.diff.gz

Do not apply. Fuzz against Sage 4.7.2.alpha2. For reference only.

@nexttime

This comment has been minimized.

@nexttime
Copy link
Mannequin

nexttime mannequin commented Sep 12, 2011

comment:17

Attached a rebased patch because of fuzz.

@nexttime
Copy link
Mannequin

nexttime mannequin commented Sep 13, 2011

Merged: sage-4.7.2.alpha3

@nexttime nexttime mannequin removed the s: positive review label Sep 13, 2011
@nexttime nexttime mannequin closed this as completed Sep 13, 2011
This was referenced Jul 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants