2

I've found in module rpc function pmap. And I've stuck when tried to use it.

The first question - does it requires connection with other nodes, or it would performs as lists:map if there is no connection to other nodes?

I've tried to execute pmap without connection to other nodes, but got exception:

7> rpc:pmap( { erlang, '+' }, [], [[1,1],[2,3]] ).          
** exception exit: badrpc
     in function  rpc:check/2 (rpc.erl, line 745)

After that - I've launched another local node and connected it with current. But still get the same error.

Please provide me how to use rpc:pmap correctly.

Thanks

P.S. Following code works expectedly (returns result 3):

70> erlang:apply( erlang, '+', [1,2] ).
3
71> erlang:'+'(1,2).
3
stemm
  • 5,960
  • 2
  • 34
  • 64

1 Answers1

6

The rpc:map({Module, Function},ExtraArgs,List1) evaluates apply(Module, Function, [Elem|ExtraArgs]), for every element Elem in List1, in parallel.

So the right syntax using erlang:'+' is:

1> rpc:pmap( { erlang, '+' }, [2], [1,2,3] ).

[3,4,5]

2>

which evaluates [1+2,2+2,3+2]

the syntax rpc:pmap( { lists, sum }, [], [[1,2],[4,5]] ) will evaluate [1+2,4+5] and return [3,9]

Pascal

Pascal
  • 13,977
  • 2
  • 24
  • 32
  • Thanks for clarification :) I didn't take into account that `[[1,2] | []]` is `[[1,2]]`, and not `[1,2]`. – stemm Sep 06 '12 at 07:23