apple = {1, 2, 3};
sapple = 1;
banana = {10, 20, 30};
sbanana = 10;
kiwi = {100, 200, 300};
skiwi = 100;
data = {"apple", "banana", "kiwi"};
myfun[data_, scale_] := Total[data]/scale
myfun[apple, sapple]
myfun[banana, sbanana]
myfun[kiwi, skiwi]
myfun[ToExpression[#], ToExpression["s" <> ToString[#]]] & /@ data
In parallel, it still works, but with a warning:
ParallelMap[myfun[ToExpression[#], ToExpression["s" <> ToString[#]]] &, data]

What's the correct way of coding this?
WARNING:
@AlbertRetey commented below that
it probably is worth mentioning that while you do get the expected result the code is not evaluated in the parallel kernels but on the master, which is most probably not what you intended. What happens is that the parallel kernels return the unevaluated expressions which then are evaluated on the master...
I am not sure whether this is true. However, I think this is an extremely important observation as MMA DOES NOT tell you this. So users will be cheated by the impression that MMA still works in parallel.
Total::normalwarning messages indicate just that (that's why I made that comment). It is of course a quite consealed message. I'm not sure whether we could expect Mathematica to do something smarter here, though... – Albert Retey Jan 17 '15 at 01:30ParallelMap[$KernelID &, Range@12]shows that in the environment in which the function is evaluated the$KernelIDvaries and (2)ParallelMap[Pause[1] &, Range@12] // AbsoluteTiming(also in "wall clock" time) shows apparent parallel evaluation. – Mr.Wizard Jan 17 '15 at 01:31Totalis called with an undefined symbol as argument (because automatic distribution can't be done asParallelMapdoesn't see symbols but only strings). With a symbolTotalgives the error messages as shown and each kernel returns e.g.Total[kiwi]/skiwi, the partially evaluated result. On the master, there are definitions forkiwiandskiwi, so it now starts its own evaluation which will not give messages and return the expected results. – Albert Retey Jan 17 '15 at 01:38total[data : {__?NumericQ}] := (Print[$KernelID]; data); myfun[data_, scale_] := (total[data]/scale)– Albert Retey Jan 17 '15 at 01:39ParallelMapsees the symbolsdandsand can autodistribute them to the parallel kernels... – Albert Retey Jan 17 '15 at 01:47