Ticket #12016: trac_12016-sage.v2.patch
File trac_12016-sage.v2.patch, 24.8 KB (added by , 11 years ago) |
---|
-
doc/en/developer/doctesting.rst
# HG changeset patch # User J. H. Palmieri <palmieri@math.washington.edu> # Date 1321130698 28800 # Node ID 36ba7d92845214da7ef4c0554a85d409537cb352 # Parent 8d81fcf27e1444bfa3778c5fe2cc231c7f84d50a #12016: document make ptestlong -- how to set NUM_THREADS diff --git a/doc/en/developer/doctesting.rst b/doc/en/developer/doctesting.rst
a b its documentation. Testing can be perfor 9 9 multiple threads. After compiling a source version of Sage, doctesting 10 10 can be run on the whole Sage library, on all modules under a given 11 11 directory, or on a specified module only. For the purposes of this 12 chapter, suppose we have compiled Sage 4. 1.1from source and the top12 chapter, suppose we have compiled Sage 4.8 from source and the top 13 13 level Sage directory is 14 14 15 15 :: 16 16 17 [mvngu@sage sage-4. 1.1]$ pwd18 /scratch/mvngu/build/sage-4. 1.117 [mvngu@sage sage-4.8]$ pwd 18 /scratch/mvngu/build/sage-4.8 19 19 20 20 See the section :ref:`chapter-testing` for information on Sage's 21 21 automated testing process. The general syntax for doctesting is as 22 22 follows. To doctest a module in the library of a version of Sage, use 23 23 this syntax:: 24 24 25 /path/to/sage-x.y.z/sage -t [- long] /path/to/sage-x.y.z/path/to/module.py[x]25 /path/to/sage-x.y.z/sage -t [--long] /path/to/sage-x.y.z/path/to/module.py[x] 26 26 27 27 where ``-long`` is an optional argument. The version of ``sage`` used must 28 28 match the version of Sage containing the module we want to doctest. A … … Say we want to run all tests in the sudo 39 39 top level Sage directory of our local Sage installation. Now we can 40 40 start doctesting as demonstrated in the following terminal session:: 41 41 42 [mvngu@sage sage-4. 1.1]$ ./sage -t devel/sage-main/sage/games/sudoku.py42 [mvngu@sage sage-4.8]$ ./sage -t devel/sage-main/sage/games/sudoku.py 43 43 sage -t "devel/sage-main/sage/games/sudoku.py" 44 44 [6.0 s] 45 45 … … takes about six seconds, while testing a 52 52 same amount of time. In this case, we only tested one module so it is 53 53 not surprising that the total testing time is approximately the same 54 54 as the time required to test only that one module. Notice that the 55 syntax is 55 syntax is :: 56 56 57 :: 58 59 [mvngu@sage sage-4.1.1]$ ./sage -t devel/sage-main/sage/games/sudoku.py 57 [mvngu@sage sage-4.8]$ ./sage -t devel/sage-main/sage/games/sudoku.py 60 58 sage -t "devel/sage-main/sage/games/sudoku.py" 61 59 [5.7 s] 62 60 63 61 ---------------------------------------------------------------------- 64 62 All tests passed! 65 63 Total time for all tests: 5.7 seconds 66 [mvngu@sage sage-4. 1.1]$ ./sage -t "devel/sage-main/sage/games/sudoku.py"64 [mvngu@sage sage-4.8]$ ./sage -t "devel/sage-main/sage/games/sudoku.py" 67 65 sage -t "devel/sage-main/sage/games/sudoku.py" 68 66 [5.4 s] 69 67 … … syntax is 71 69 All tests passed! 72 70 Total time for all tests: 5.4 seconds 73 71 74 but not 72 but not :: 75 73 76 :: 77 78 [mvngu@sage sage-4.1.1]$ ./sage -t sage/games/sudoku.py 74 [mvngu@sage sage-4.8]$ ./sage -t sage/games/sudoku.py 79 75 ERROR: File ./sage/games/sudoku.py is missing 80 76 exit code: 1 81 77 … … but not 84 80 85 81 ./sage/games/sudoku.py 86 82 Total time for all tests: 0.0 seconds 87 [mvngu@sage sage-4. 1.1]$ ./sage -t "sage/games/sudoku.py"83 [mvngu@sage sage-4.8]$ ./sage -t "sage/games/sudoku.py" 88 84 ERROR: File ./sage/games/sudoku.py is missing 89 85 exit code: 1 90 86 … … but not 97 93 We can also first ``cd`` to the directory containing the module 98 94 ``sudoku.py`` and doctest that module as follows:: 99 95 100 [mvngu@sage sage-4. 1.1]$ cd devel/sage-main/sage/games/96 [mvngu@sage sage-4.8]$ cd devel/sage-main/sage/games/ 101 97 [mvngu@sage games]$ ls 102 all.py __init__.pysudoku_backtrack.pyx103 hexad.py sudoku_backtrack.c sudoku.py98 __init__.py hexad.py sudoku.py sudoku_backtrack.pyx 99 all.py quantumino.py sudoku_backtrack.c 104 100 [mvngu@sage games]$ ../../../../sage -t sudoku.py 105 101 sage -t "devel/sage-main/sage/games/sudoku.py" 106 102 [5.1 s] … … our system has multiple Sage installatio 128 124 syntax is acceptable because we explicitly specify the Sage 129 125 installation in the current ``SAGE_ROOT``:: 130 126 131 [mvngu@sage sage-4. 1.1]$ ./sage -t devel/sage-main/sage/games/sudoku.py127 [mvngu@sage sage-4.8]$ ./sage -t devel/sage-main/sage/games/sudoku.py 132 128 sage -t "devel/sage-main/sage/games/sudoku.py" 133 129 [5.1 s] 134 130 135 131 ---------------------------------------------------------------------- 136 132 All tests passed! 137 133 Total time for all tests: 5.1 seconds 138 [mvngu@sage sage-4. 1.1]$ ./sage -t "devel/sage-main/sage/games/sudoku.py"134 [mvngu@sage sage-4.8]$ ./sage -t "devel/sage-main/sage/games/sudoku.py" 139 135 sage -t "devel/sage-main/sage/games/sudoku.py" 140 136 [5.0 s] 141 137 … … installation in the current ``SAGE_ROOT` 143 139 All tests passed! 144 140 Total time for all tests: 5.0 seconds 145 141 146 With a regular user account, the following syntax is not recommended 147 as we are using a system-wideSage installation (if it exists)::142 The following syntax is not recommended as we are using a system-wide 143 Sage installation (if it exists):: 148 144 149 [mvngu@sage sage-4. 1.1]$ sage -t devel/sage-main/sage/games/sudoku.py145 [mvngu@sage sage-4.8]$ sage -t devel/sage-main/sage/games/sudoku.py 150 146 Traceback (most recent call last): 151 147 File "/usr/local/sage/local/bin/sage-test", line 49, in 152 148 os.makedirs(TMP) 153 149 File "/usr/local/sage/local/lib/python/os.py", line 157, in makedirs 154 150 mkdir(name, mode) 155 151 OSError: [Errno 13] Permission denied: '/usr/local/sage/tmp/tmp' 156 [mvngu@sage sage-4. 1.1]$ sage -t "devel/sage-main/sage/games/sudoku.py"152 [mvngu@sage sage-4.8]$ sage -t "devel/sage-main/sage/games/sudoku.py" 157 153 Traceback (most recent call last): 158 154 File "/usr/local/sage/local/bin/sage-test", line 49, in 159 155 os.makedirs(TMP) … … regular user, we cannot write to directo 171 167 write permission. The following syntax is also discouraged when we 172 168 login as a regular user:: 173 169 174 [mvngu@sage sage-4. 1.1]$ cd170 [mvngu@sage sage-4.8]$ cd 175 171 [mvngu@sage ~]$ sage -t devel/sage-main/sage/games/sudoku.py 176 172 Traceback (most recent call last): 177 173 File "/usr/local/sage/local/bin/sage-test", line 49, in … … there. As a regular user, we do not usua 195 191 the directory ``/root`` nor do we have privileges to write to the root 196 192 directory:: 197 193 198 [mvngu@sage sage-4. 1.1]$ ls /root/194 [mvngu@sage sage-4.8]$ ls /root/ 199 195 ls: cannot open directory /root/: Permission denied 200 [mvngu@sage sage-4. 1.1]$ cd /196 [mvngu@sage sage-4.8]$ cd / 201 197 [mvngu@sage /]$ touch demo.txt 202 198 touch: cannot touch `demo.txt': Permission denied 203 199 … … and then using two threads. For this exa 219 215 all the modules under ``sage/crypto/``. We can use a syntax similar to 220 216 that shown above to achieve this:: 221 217 222 [mvngu@sage sage-4. 1.1]$ ./sage -t devel/sage-main/sage/crypto/218 [mvngu@sage sage-4.8]$ ./sage -t devel/sage-main/sage/crypto/ 223 219 sage -t "devel/sage-main/sage/crypto/lfsr.py" 224 220 [2.5 s] 225 221 sage -t "devel/sage-main/sage/crypto/cryptosystem.py" … … that shown above to achieve this:: 260 256 Total time for all tests: 35.7 seconds 261 257 262 258 Now we do the same thing, but this time we also use the optional 263 argument ``- long``::259 argument ``--long``:: 264 260 265 [mvngu@sage sage-4. 1.1]$ ./sage -t-long devel/sage-main/sage/crypto/266 sage -t - long "devel/sage-main/sage/crypto/lfsr.py"261 [mvngu@sage sage-4.8]$ ./sage -t --long devel/sage-main/sage/crypto/ 262 sage -t --long "devel/sage-main/sage/crypto/lfsr.py" 267 263 [1.9 s] 268 sage -t - long "devel/sage-main/sage/crypto/cryptosystem.py"264 sage -t --long "devel/sage-main/sage/crypto/cryptosystem.py" 269 265 [2.0 s] 270 sage -t - long "devel/sage-main/sage/crypto/block_cipher/miniaes.py"266 sage -t --long "devel/sage-main/sage/crypto/block_cipher/miniaes.py" 271 267 [2.6 s] 272 sage -t - long "devel/sage-main/sage/crypto/block_cipher/all.py"268 sage -t --long "devel/sage-main/sage/crypto/block_cipher/all.py" 273 269 [0.1 s] 274 sage -t - long "devel/sage-main/sage/crypto/block_cipher/__init__.py"270 sage -t --long "devel/sage-main/sage/crypto/block_cipher/__init__.py" 275 271 [0.1 s] 276 sage -t - long "devel/sage-main/sage/crypto/classical.py"272 sage -t --long "devel/sage-main/sage/crypto/classical.py" 277 273 [2.7 s] 278 sage -t - long "devel/sage-main/sage/crypto/mq/mpolynomialsystem.py"274 sage -t --long "devel/sage-main/sage/crypto/mq/mpolynomialsystem.py" 279 275 [8.7 s] 280 sage -t - long "devel/sage-main/sage/crypto/mq/mpolynomialsystemgenerator.py"276 sage -t --long "devel/sage-main/sage/crypto/mq/mpolynomialsystemgenerator.py" 281 277 [2.2 s] 282 sage -t - long "devel/sage-main/sage/crypto/mq/__init__.py"278 sage -t --long "devel/sage-main/sage/crypto/mq/__init__.py" 283 279 [0.1 s] 284 sage -t - long "devel/sage-main/sage/crypto/mq/sbox.py"280 sage -t --long "devel/sage-main/sage/crypto/mq/sbox.py" 285 281 [2.9 s] 286 sage -t - long "devel/sage-main/sage/crypto/mq/sr.py"282 sage -t --long "devel/sage-main/sage/crypto/mq/sr.py" 287 283 [56.6 s] 288 sage -t - long "devel/sage-main/sage/crypto/stream_cipher.py"284 sage -t --long "devel/sage-main/sage/crypto/stream_cipher.py" 289 285 [2.5 s] 290 sage -t - long "devel/sage-main/sage/crypto/all.py"286 sage -t --long "devel/sage-main/sage/crypto/all.py" 291 287 [0.1 s] 292 sage -t - long "devel/sage-main/sage/crypto/stream.py"288 sage -t --long "devel/sage-main/sage/crypto/stream.py" 293 289 [1.9 s] 294 sage -t - long "devel/sage-main/sage/crypto/__init__.py"290 sage -t --long "devel/sage-main/sage/crypto/__init__.py" 295 291 [0.1 s] 296 sage -t - long "devel/sage-main/sage/crypto/classical_cipher.py"292 sage -t --long "devel/sage-main/sage/crypto/classical_cipher.py" 297 293 [1.9 s] 298 sage -t - long "devel/sage-main/sage/crypto/cipher.py"294 sage -t --long "devel/sage-main/sage/crypto/cipher.py" 299 295 [1.9 s] 300 296 301 297 ---------------------------------------------------------------------- … … argument ``-long``:: 303 299 Total time for all tests: 88.0 seconds 304 300 305 301 Notice the time difference between the first set of tests and the 306 second set, which uses the optional argument ``- long``. Many tests in the302 second set, which uses the optional argument ``--long``. Many tests in the 307 303 Sage library are flagged with ``# long time`` because these are known to 308 take a long time to run through. Without using the optional ``- long``304 take a long time to run through. Without using the optional ``--long`` 309 305 argument, the module ``sage/crypto/mq/sr.py`` took about five 310 306 seconds. With this optional argument, it required 57 seconds to run 311 307 through all tests in that module. Here is a snippet of a function in … … as taking a long time:: 315 311 def test_consistency(max_n=2, **kwargs): 316 312 r""" 317 313 Test all combinations of ``r``, ``c``, ``e`` and ``n`` in ``(1, 318 2)`` for consistency of random encryptions and their polynomial 319 systems. `\GF{2}` and `\GF{2^e}` systems are tested. This test 320 takes 314 2)`` for consistency of random encryptions and their polynomial 315 systems. `\GF{2}` and `\GF{2^e}` systems are tested. This test takes 321 316 a while. 322 317 323 318 INPUT: … … as taking a long time:: 328 323 TESTS:: 329 324 330 325 sage: from sage.crypto.mq.sr import test_consistency 331 sage: test_consistency(1) # long time -- calling w/ max_n = 2 requires a LOT of RAM (>> 2GB, evidently). Calling w/ max_n = 1 is far more manageable.326 sage: test_consistency(1) # long time (80s on sage.math, 2011) 332 327 True 333 334 The above doctest used to fail on a machine with "only" 2GB RAM.335 Using ``max_n = 1`` appears to be a more reasonable memory usage.336 328 """ 337 329 338 Now we doctest the same directory in parallel using twothreads::330 Now we doctest the same directory in parallel using four threads:: 339 331 340 [mvngu@sage sage-4. 1.1]$ ./sage -tp 2devel/sage-main/sage/crypto/332 [mvngu@sage sage-4.8]$ ./sage -tp 4 devel/sage-main/sage/crypto/ 341 333 Global iterations: 1 342 334 File iterations: 1 343 335 Using cached timings to run longest doctests first. 344 Doctesting 17 files doing 2jobs in parallel336 Doctesting 17 files doing 4 jobs in parallel 345 337 sage -t devel/sage-main/sage/crypto/lfsr.py 346 338 [2.7 s] 347 339 sage -t devel/sage-main/sage/crypto/cryptosystem.py … … Now we doctest the same directory in par 382 374 Timings have been updated. 383 375 Total time for all tests: 19.3 seconds 384 376 385 [mvngu@sage sage-4. 1.1]$ ./sage -tp 2-long devel/sage-main/sage/crypto/377 [mvngu@sage sage-4.8]$ ./sage -tp 4 --long devel/sage-main/sage/crypto/ 386 378 Global iterations: 1 387 379 File iterations: 1 388 380 No long cached timings exist; will create upon successful finish. 389 Doctesting 17 files doing 2jobs in parallel390 sage -t - long devel/sage-main/sage/crypto/cryptosystem.py381 Doctesting 17 files doing 4 jobs in parallel 382 sage -t --long devel/sage-main/sage/crypto/cryptosystem.py 391 383 [2.7 s] 392 sage -t - long devel/sage-main/sage/crypto/lfsr.py384 sage -t --long devel/sage-main/sage/crypto/lfsr.py 393 385 [2.7 s] 394 sage -t - long devel/sage-main/sage/crypto/stream_cipher.py386 sage -t --long devel/sage-main/sage/crypto/stream_cipher.py 395 387 [2.2 s] 396 sage -t - long devel/sage-main/sage/crypto/all.py388 sage -t --long devel/sage-main/sage/crypto/all.py 397 389 [0.1 s] 398 sage -t - long devel/sage-main/sage/crypto/classical.py390 sage -t --long devel/sage-main/sage/crypto/classical.py 399 391 [3.0 s] 400 sage -t - long devel/sage-main/sage/crypto/__init__.py392 sage -t --long devel/sage-main/sage/crypto/__init__.py 401 393 [0.1 s] 402 sage -t - long devel/sage-main/sage/crypto/stream.py394 sage -t --long devel/sage-main/sage/crypto/stream.py 403 395 [2.1 s] 404 sage -t - long devel/sage-main/sage/crypto/classical_cipher.py396 sage -t --long devel/sage-main/sage/crypto/classical_cipher.py 405 397 [2.1 s] 406 sage -t - long devel/sage-main/sage/crypto/cipher.py398 sage -t --long devel/sage-main/sage/crypto/cipher.py 407 399 [2.1 s] 408 sage -t - long devel/sage-main/sage/crypto/block_cipher/all.py400 sage -t --long devel/sage-main/sage/crypto/block_cipher/all.py 409 401 [0.1 s] 410 sage -t - long devel/sage-main/sage/crypto/block_cipher/__init__.py402 sage -t --long devel/sage-main/sage/crypto/block_cipher/__init__.py 411 403 [0.1 s] 412 sage -t - long devel/sage-main/sage/crypto/block_cipher/miniaes.py404 sage -t --long devel/sage-main/sage/crypto/block_cipher/miniaes.py 413 405 [2.8 s] 414 sage -t - long devel/sage-main/sage/crypto/mq/mpolynomialsystemgenerator.py406 sage -t --long devel/sage-main/sage/crypto/mq/mpolynomialsystemgenerator.py 415 407 [2.0 s] 416 sage -t - long devel/sage-main/sage/crypto/mq/__init__.py408 sage -t --long devel/sage-main/sage/crypto/mq/__init__.py 417 409 [0.1 s] 418 sage -t - long devel/sage-main/sage/crypto/mq/sbox.py410 sage -t --long devel/sage-main/sage/crypto/mq/sbox.py 419 411 [3.1 s] 420 sage -t - long devel/sage-main/sage/crypto/mq/mpolynomialsystem.py412 sage -t --long devel/sage-main/sage/crypto/mq/mpolynomialsystem.py 421 413 [9.1 s] 422 sage -t - long devel/sage-main/sage/crypto/mq/sr.py414 sage -t --long devel/sage-main/sage/crypto/mq/sr.py 423 415 [56.0 s] 424 416 425 417 ---------------------------------------------------------------------- … … Parallel testing the whole Sage library 443 435 The main Sage library resides in the directory 444 436 ``SAGE_ROOT/devel/sage-main/``. We can use the syntax described above 445 437 to doctest the main library using multiple threads. When doing release 446 management or patching the main Sage library, a release manager would 447 parallel test the library using ten or more threads:: 438 management or patching the main Sage library, a release manager might 439 parallel test the library using ten threads with the following 440 command:: 448 441 449 [mvngu@sage sage-4. 1.1]$ ./sage -tp 10-long devel/sage-main/442 [mvngu@sage sage-4.8]$ ./sage -tp 10 --long devel/sage-main/ 450 443 451 Another way is to edit the file ``Makefile`` in the top level Sage 452 directory so that the variable ``NUM_THREADS`` is set to ``10``:: 444 Another way is to run ``make ptestlong``, which builds Sage (if 445 necessary), builds the Sage documentation (if necessary), and then 446 runs parallel doctests. By default, this determines the number of 447 threads by reading the environment variable :envvar:`MAKE`: if it is 448 set to ``make -j12``, then use 12 threads. If :envvar:`MAKE` is not 449 set, then it uses ``min(8, cpu_count())``, where ``cpu_count()`` is 450 the number of CPUs in the machine, as determined by the Python 451 function ``multiprocessing.cpu_count()``. The number of threads can be 452 overridden by setting the environment variable 453 :envvar:`SAGE_NUM_THREADS`. 453 454 454 # How many threads should be used when doing parallel testing (and 455 # sometime in the future, parallel building)? 456 NUM_THREADS=10 455 In any case, this will test the Sage library with multiple threads:: 457 456 458 After saving all changes to ``Makefile``, we can parallel test with the 459 ``-long`` option using ten threads:: 460 461 [mvngu@sage sage-4.1.1]$ make ptestlong 457 [mvngu@sage sage-4.8]$ make ptestlong 462 458 463 459 Any of the following commands would also doctest the Sage library or 464 460 one of its clones:: … … by the symbolic link ``devel/sage``. 497 493 498 494 * ``make ptest`` --- Similar to the commands ``make test`` and ``make 499 495 check``. However, doctesting is run with the number of threads as 500 specified by the variable ``NUM_THREADS``. See the file 501 ``SAGE_ROOT/Makefile`` for further details. 496 described above for ``make ptestlong``. 502 497 503 498 * ``make ptestlong`` --- Similar to the command ``make ptest``, but 504 499 using the optional argument ``-long`` for doctesting. … … by the symbolic link ``devel/sage``. 507 502 Beyond the Sage library 508 503 ======================= 509 504 510 The doctesting scripts of a Sage installation currently have limited 511 support for doctesting of modules outside of the Sage library for 512 that version of Sage. We cannot use the doctesting scripts of Sage 513 4.1.1 to doctest modules in, say, Sage 4.1. Doing so would result 514 in errors:: 515 516 [mvngu@sage sage-4.1.1]$ ./sage -t ../sage-4.1/devel/sage-main/sage/games/sudoku.py 517 sage -t "../sage-4.1/devel/sage-main/sage/games/sudoku.py" 518 File "./sudoku.py", line 18 519 from ../sage-4.1/devel/sage-main/sage/games/sudoku import * 520 ^ 521 SyntaxError: invalid syntax 522 523 [0.2 s] 524 exit code: 1024 525 526 ---------------------------------------------------------------------- 527 The following tests failed: 528 529 530 sage -t "../sage-4.1/devel/sage-main/sage/games/sudoku.py" 531 Total time for all tests: 0.2 seconds 532 533 However, suppose we have a Python script called ``my_python_script.py`` 534 that uses the Sage library. Our Python script has the following 535 content:: 505 Doctesting also works fine for files not in the Sage library. For 506 example, suppose we have a Python script called 507 ``my_python_script.py``:: 536 508 537 509 [mvngu@sage build]$ cat my_python_script.py 538 510 from sage.all_cmdline import * # import sage library 539 511 540 512 def square(n): 541 513 """ 542 514 Return the square of n. 543 515 544 516 EXAMPLES:: 545 517 546 518 sage: square(2) 547 519 4 548 520 """ 549 521 return n**2 550 522 551 We can use any version of Sage to doctest our Python script, so long 552 as that version of Sage has features that are used in our script. For 553 example, we can use both Sage 4.1.1 and 4.1 to doctest the above 554 Python script:: 523 Then we can doctest it just as with Sage library files:: 555 524 556 [mvngu@sage build]$ sage-4. 1/sage -t my_python_script.py525 [mvngu@sage build]$ sage-4.8/sage -t my_python_script.py 557 526 sage -t "my_python_script.py" 558 527 [1.3 s] 559 528 560 529 ---------------------------------------------------------------------- 561 530 All tests passed! 562 531 Total time for all tests: 1.3 seconds 563 [mvngu@sage build]$ sage-4.1.1/sage -t my_python_script.py564 sage -t "my_python_script.py"565 [1.4 s]566 567 ----------------------------------------------------------------------568 All tests passed!569 Total time for all tests: 1.4 seconds570 571 Doctesting can also be performed on Sage scripts. Say we have a Sage572 script called ``my_sage_script.sage`` with the following content::573 574 [mvngu@sage build]$ cat my_sage_script.sage575 def cube(n):576 r"""577 Return the cube of n.578 579 EXAMPLES::580 581 sage: cube(2)582 8583 """584 return n**3585 586 This must be converted to an equivalent Python script prior to587 doctesting. First, we use Sage to convert ``my_sage_script.sage`` to588 an equivalent Python script called ``my_sage_script.py``::589 590 [mvngu@sage build]$ sage-4.1.1/sage my_sage_script.sage591 [mvngu@sage build]$ cat my_sage_script.py592 # This file was *autogenerated* from the file my_sage_script.sage.593 from sage.all_cmdline import * # import sage library594 _sage_const_3 = Integer(3)595 def cube(n):596 r"""597 Return the cube of n.598 599 EXAMPLES::600 601 sage: cube(2)602 8603 """604 return n**_sage_const_3605 606 Doctesting is then performed on that equivalent Python script::607 608 [mvngu@sage build]$ sage-4.1.1/sage -t my_sage_script.py609 sage -t "my_sage_script.py"610 [1.5 s]611 612 ----------------------------------------------------------------------613 All tests passed!614 Total time for all tests: 1.5 seconds -
doc/en/installation/source.rst
diff --git a/doc/en/installation/source.rst b/doc/en/installation/source.rst
a b process: 588 588 time. Alternatively, run "make build-serial" which sets this 589 589 environment variable for you. 590 590 591 - :envvar:`SAGE_NUM_THREADS` - if this is set to a number, then when 592 building the documentation, parallel doctesting, or running ``sage 593 -b``, use this many threads. If it is set to ``0``, then use as 594 many threads as seems sensible. If it is set to ``auto``, then 595 build the documentation serially, but parallel test or run ``sage 596 -b`` using as many threads as seems sensible. If this is not set, 597 then determine the number of threads using the value of the 598 :envvar:`MAKE` variable, as above. 599 591 600 - :envvar:`SAGE_CHECK` - if this is set to "yes", then during the 592 601 build process, run the test suite for each package which has one. 593 602 -
setup.py
diff --git a/setup.py b/setup.py
a b def execute_list_of_commands(command_lis 292 292 OUTPUT: 293 293 For each entry in command_list, we attempt to run the command. 294 294 If it is a string, we call os.system. If it is a pair [f, v], 295 we call f(v). On machines with more than 1 cpu the commands 296 are run in parallel. 295 we call f(v). If the '-j' flag in 'MAKE' is set, run in parallel. 297 296 """ 298 297 t = time.time() 299 cpu_count = number_of_threads() # try hard to determine the actual cpu count 300 assert(cpu_count>=1) 301 nthreads = 0 # number of threads to use; zero means don't know 302 303 if os.environ.has_key('MAKE'): # user-supplied number of threads takes precedence 304 MAKE = os.environ['MAKE'] 305 # from the manpage: If there is more than one -j option, the last one is effective. 306 pos = MAKE.rfind(' -j') 307 if pos>=0: 308 try: 309 if MAKE[pos+3] == '=': # make -j=N is the same as make -jN 310 pos += 1 311 nthreads = int(MAKE[pos+3:].split()[0]) 312 except IndexError, ValueError: 313 # make -j without number means unlimited threads 314 nthreads = 2*cpu_count 315 316 if nthreads==0: 317 nthreads = cpu_count 318 319 if nthreads > 2*cpu_count: # sanity check 320 print "Warning: The number of threads ("+str(nthreads)+") seems impossibly large." 321 nthreads = min(nthreads, cpu_count) 322 print "I reduced it to "+str(nthreads)+"." 298 # Determine the number of threads from the environment variable 299 # SAGE_NUM_THREADS, which is set automatically by the script 300 # sage-env, using the setting of the variable MAKE. 301 NUM_THREADS = os.environ.get('SAGE_NUM_THREADS', 1) 302 try: 303 nthreads = int(NUM_THREADS) 304 except ValueError: 305 # NUM_THREADS might be 'auto', in which case use the number of 306 # cpus. 307 nthreads = 0 308 # If SAGE_NUM_THREADS is 0, use the number of cpus. 309 if nthreads == 0: 310 nthreads = number_of_threads() 311 assert(nthreads >= 1) 323 312 324 313 # normalize the command_list to handle strings correctly 325 314 command_list = [ [run_command, x] if isinstance(x, str) else x for x in command_list ]