Parallel computing with &SCSCP;
Managing multiple requests
Using procedure calls explained in the previous section, the user can
create several requests to multiple services to execute them in parallel,
or to wait until the fastest result will be available.
<#Include Label="SynchronizeProcesses">
<#Include Label="FirstProcess">
is
a list of hosts and ports to search for &SCSCP; services
(which may be not only represented by &GAP; services, but also
by another &SCSCP;-compliant systems).
It is used by parallel skeletons
and .
The initial value of this variable is specified in the file
scscp/configpar.g and may be reassigned later.
<#Include Label="ParQuickWithSCSCP">
<#Include Label="FirstTrueProcess">
MasterWorker skeleton
In this section we will present more general framework to run parallel
computations, which has a number of useful features:
-
it is implemented purely in &GAP;;
-
the client (i.e. master, which orchestrates the computation)
will work in UNIX/Linux, Mac OS X and MS Windows;
-
it may orchestrate both &GAP; and non-&GAP; &SCSCP; servers;
-
if one of servers (i.e. workers) will be lost, it will retry the
computation on another available server;
-
it allows to add dynamically new workers during the computation
on hostnames and ports from a range perviously declared in
.
To configure this functionality,
the file scscp/configpar.g assigns the global variable
SCSCPservers which specifies a list of hosts and ports to
search for &SCSCP; services (which may be not only represented by
&GAP; services, but also by another &SCSCP;-compliant systems).
See comments in this file for further instructions.
<#Include Label="ParListWithSCSCP">
<#Include Label="SCSCPreset">
<#Include Label="SCSCPLogTracesToGlobal">
can be easily modified to have parallel versions
of other list operations like
,
,
,
,
,
and also to have the skeleton in which the queue may be modified during
the computation (for example, to compute orbits).
We plan to provide such tools in one of the next versions of the package.
Example: parallelising Karatsuba multiplication for polynomials
The file scscp/example/karatsuba.g contains an implementation of
the Karatsuba multiplication algorithm for polynomials. This algorithm can
be easily parallelized since each recursive step creates three recursive
calls of the same function for other polynomials. We will not parallelize
each recursive call, since this will create enormous data flow. Instead
of this we parallelize only the top-level function.
For our experiments with parallelising Karatsuba multiplication for
polynomials with integer coefficients we used the multi-core workstation,
on which we started one &SCSCP; client and two &SCSCP; servers. To use
it, modify the server configuration file adding to it the command to
read the file scscp/example/karatsuba.g, then define there
the following function
and finally add the following lines to made it available as an &SCSCP;
procedure under the name WS_Karatsuba:
(we do not include it into the default scscp/example/myserver.g
since the code contains a call to ).
This function provides a "bridge" between the client's function
KaratsubaPolynomialMultiplicationWS and the server's function
KaratsubaPolynomialMultiplicationExtRep, which performs the
actual work on the server. WS_Karatsuba converts its string arguments
into internal representation of univariate polynomials (basically, lists of
integers) and then converts the result back into string (since such data
exchange format was chosen).
\newpage
We are going to parallelize the following part of the client's code:
and this can be done straightforwardly - we replace two first calls by
calls of the appropriate &SCSCP; services, then perform the 3rd call locally
and then collect the results from the two remote calls:
We obtain almost double speedup on three cores on randomly generated polynomials
of degree 32000:
ReadPackage("scscp/example/karatsuba.g");
gap> fam:=FamilyObj(1);;
gap> f:=LaurentPolynomialByCoefficients( fam,
> List([1..32000],i->Random(Integers)), 0, 1 );;
gap> g:=LaurentPolynomialByCoefficients( fam,
> List([1..32000],i->Random(Integers)), 0, 1 );;
gap> t2:=KaratsubaPolynomialMultiplication(f,g);;time;
5892
gap> t3:=KaratsubaPolynomialMultiplicationWS(f,g);;time;
2974
]]>