Sage comes built in with a powerful distributed computing framework called Distributed Sage (dsage).
Distributed Sage is a framework that allows one to do distributed computing from within Sage. It includes a server, client and workers as well as a set of classes that one can subclass from to write distributed computation jobs. It is designed to be used mainly for ‘coarsely’ distributed computations, i.e., computations where jobs do not have to communicate much with each other. This is also sometimes referred to as ‘grid’ computing.
There are 3 parts that make up Distributed Sage:
Here are a few illustrations of how get up and running with dsage.
workers and return an object
(d) which is a connection to the server. From here on, your
interaction with dsage will be mainly though the d object.In this example, we will show you how to use the DistributedFactor class that comes built-in with dsage. DistributedFactor attempts to factor numbers by using a combination of the ECM and the QSieve algorithm, as well as trial factorization for small factors.
. You can see
whether or not the factoring job is done by looking at the
factor_job.done attribute. When it is done, you can look at the
prime factors it found by inspecting
factor_job.prime_factors.This example demonstrates a distributed version of the map method. You can find the documentation for the regular map method here: http://docs.python.org/lib/built-in-funcs.html. The syntax is exactly the same.
First, run d = dsage.start_all() if you have not started your dsage session yet; otherwise, you can continue to use the previous d instance.
sage: def f(n): return n*n
sage: j = d.map(f, [25,12,25,32,12])
sage: jobs = d.block_on_jobs(j)
This will block until f has been evaluated for each of the inputs.
This example demonstrates how to use the @parallel decorator with a dsage instance.
First, run d = dsage.start_all() if you have not started your dsage session yet; otherwise, you can continue to use the previous d instance.
sage: P = parallel(p_iter = d.parallel_iter)
sage: @P
... def f(n,m): return n+m
sage: f([(1,2), (5, 10/3)])
dsage stores a few files in $SAGE_ROOT/.sage/dsage: