Grid - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Toolboxes : Grid Computing : Grid/Map

Grid

  

Map

  

map a procedure over a dataset, using separate processes

 

Calling Sequence

Parameters

Description

Examples

Compatibility

Calling Sequence

Map( f, expr )

Map( f, expr, arg1, arg2, ..., argN )

Map[tasksize=s]( f, expr, ... )

Parameters

f

-

procedure or function

expr

-

any expression

arg1, ..., argN

-

(optional) further arguments to f

s

-

posint

Description

• 

The Map command applies f to the operands or elements of expr in parallel. This is similar to Threads[Map] except that application of f is done in separate processes, rather than separate threads.

• 

The Map command applies f to the operands or elements of expr in parallel.  A typical calling sequence is Map(f, [1,2,...,n]) which applies f to each element of the given list to form the new list, [f(1), f(2), ..., f(n)]. Similarly, Map(f,[1,2,...,n],a,b) will return [f(1,a,b), f(2,a,b), ..., f(n,a,b)], using the extra arguments to Map in each call to f. Computation of each f(i) will be evenly distributed across all available nodes.

• 

The Map command is similar to the top-level map command, and the Threads[Map] commands. The top-level seq command evaluates the entire sequence serially. The Threads[Map] command evaluates elements of the sequence in parallel on separate threads within the same process. The Grid[Map] command evaluates elements of the sequence in parallel on separate processes, and potentially on different machines.

• 

The Map command attempts to initialize remote compute nodes by looking for named values inside of f and assigning those same names in the remote compute nodes. The expr parameter is not searched. If it depends on values that are not fully defined on the remote nodes, use the Grid:-Set command before calling Map to set those values. Similarly, Grid:-Set may be needed to complete the definition of f, in particular, when f is a procedure that calls other locally defined procedures.

• 

Map will always try to use all compute nodes. It will typically subdivide the request into many more tasks than there are available nodes. This helps to more evenly distribute the load when the run-time of processing different requests is unevenly distributed.  However, in some situations, Map may not choose the optimal size. In particular, when there are a large number of short-running tasks, doing more work in the remote nodes in each task may be more efficient. In this case, you can specify the task size using the tasksize option. Map will divide the input into tasks that compute at most tasksize elements within a single task.

• 

Setting infolevel[Grid:-Map] := 3; will enable output of information messages relating to the progress of the computation.

• 

When using hpc or mpi modes, Map is designed to be called on all the nodes of a parallel computation, whereupon the result will only be available on node 0. If the resulting Maple expression is required for further computation on other nodes, it must be sent there explicitly using Send and Receive.

• 

Map is a high-level command which uses Send and Receive calls. Therefore, evaluation of f should not involve other Send and Receive calls.

• 

Because Map has to transfer portions of expr to each node, it will not be efficient when called with a trivial procedure f.  

• 

The result of a Map computation will only be available on node 0. If the resulting Maple expression is required for further computation on other nodes, it must be sent there explicitly using Send and Receive.

• 

This function is part of the Grid package, so it can be used in the short form Map(..) only after executing the command with(Grid). However, it can always be accessed through the long form of the command by using Grid[Map](..).

Examples

This example shows some simple calling sequences

Grid:-Mapx→x2,1,2,3

1,4,9

(1)

Grid:-Mapx,y→x2+y,1|2,3|4,4

581320

(2)

exprrandpolyx,y,z,terms=20

expr:=92x5+6x4y+74x4z+72x3yz+37x2y2z23x2yz2+87x2z3+44xy3z+29y4z+98yz423z540x2z2+42xy350xyz2+23y3z+75yz310y37y2z17x275xy

(3)

Grid:-Mapabs,expr

92x5+6x4y+74x4z+72x3yz+37x2y2z+23x2yz2+87x2z3+44xy3z+29y4z+98yz4+23z5+40x2z2+42xy3+50xyz2+23y3z+75yz3+10y3+7y2z+17x2+75xy

(4)

Grid:-Mapx→x2,table1=1,2=2,3=3,red=4,blue=y

table1=1,2=4,3=9,blue=y2,red=16

(5)

In this example we define two procedures such that Map will not be able to automatically find all definitions to send to external nodes.  The remote operation is not fully defined.

myfunc1x→x2

myfunc1:=x→x2

(6)

myfunc2x→myfunc1x+x

myfunc2:=x→myfunc1x+x

(7)

Grid:-Mapmyfunc2,1,2,3

myfunc11+1,myfunc12+2,myfunc13+3

(8)

The myfunc1 procedure was not defined in the external nodes.  It needs to be set.

Grid:-Setmyfunc1

Grid:-Mapmyfunc2,1,2,3

2,6,12

(9)

In this example the work required for the computation at j=1 is much less than the computation at j=9.  The sequence of heavy computations at the end of the list is may require an adjustment to the default tasksize

time[real]Grid:-Mapj→addi,i=1..10min7,j,`$`1..9

1.087

(10)

time[real]Grid:-Map['tasksize'=1]j→addi,i=1..10min7,j,`$`1..9

0.982

(11)

Compatibility

• 

The Grid[Map] command was introduced in Maple 15.

• 

For more information on Maple 15 changes, see Updates in Maple 15.

• 

The Grid[Map] command was updated in Maple 2015.

• 

The s parameter was introduced in Maple 2015.

• 

For more information on Maple 2015 changes, see Updates in Maple 2015.

See Also

Grid

Grid[Seq]

map

seq

Threads[Map]

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam