On Sun, Mar 7, 2010 at 5:06 PM, Gokhan Sever <gokhanse...@gmail.com> wrote: > Parallel Python is a separate module. IPython is the interactive > Python interpreter that comes with Sage. However to use the IPython > parallel features you need to install some additional packages. I am > not sure if you could get it work from within Sage. More recommended > way is to have an external installation. > > I don't know about @parallel yet. Please do tell me and give an > example of its usage. I look at the Parallel Python examples and they > are all lengthy. multiprocessing provides much simpler solution at a > first sight.
I wrote @parallel. Type sage: parallel? for some documentation and look at the source code in Sage. You just do @parallel(4) def f(n): # do some computation then for X in f([1..10]): print X and 4 copies of X will run at once. The actual implementation is *very* simple compared to multiprocessing or Parallel Python. It's about 2 pages of custom code I wrote from scratch just using pure Python and the fork system call (which is part of the os module). However, it has special support for forking Sage itself -- there are a number of issues having to do with pexpect interfaces, etc., which @parallel takes care of, but multiprocessing or Parallel python wouldn't know about. Another nice (imho) thing about @parallel is that it fork's a new process for each evaluation of the function f. This is good because (1) forking is cheap, (2) the entire *state* of your process is copied to the forked processes as is (e.g., you can have @parallel's inside of functions you define on the command line or notebook, etc.), (3) if the computation of f(n) leaks memory or segfaults, the calling program doesn't die. I use @parallel constantly for my research. -- William -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org