[erlang-questions] Clarify: HiPE auto-spawning?

Kostis Sagonas kostis@REDACTED
Fri Nov 16 13:18:02 CET 2007


Philip Robinson wrote:
> Does HiPE automatically spread (spawn) a program across multiple cores?
> 
> For example, if I have a function:
> 
> test(A, B) ->
>     {A + B, A * B}.
> 
> Will HiPE convert it into something like the following?
> 
> test(A, B) ->
>     PidThis = self(),
>     Pid1 = spawn(fun() -> PidThis ! {self(), A + B} end),
>     Pid2 = spawn(fun() -> PidThis ! {self(), A * B} end),
>     Tmp1 = receive {Pid1, Result1} -> Result1 end,
>     Tmp2 = receive {Pid2, Result2} -> Result2 end,
>     {Tmp1, Tmp2}.
> 
> I suspect not, but I cannot find any confirmation.

Of course not.  HiPE is a native code compiler, not a parallelizing 
compiler. (Not to mention the fact that the transformation is a 
pessimization rather than an optimization in the above program.)

More generally, HiPE is not allowed to alter the observable behaviour of 
your program -- or at least it tries to.  For example, suppose you have 
an observer process that counts the number of processes a program 
spawns.  The result of that program would change based on whether HiPE 
compilation was used or not, if HiPE (automatically) did what you 
suggested and the BEAM compiler did not.

Kostis



More information about the erlang-questions mailing list