Skip to content
Prev 473 / 2152 Next

snow and foreach memory issue?

Zhang, Ivan wrote:
as.list(iter(datapoints, <etc>)) makes a full copy of datapoints.
clusterApply creates another copy, distributed across cores. So if
they're on the same machine you now use 3 * sizeof(datapoints) memory,
even before any calculations done on the workers. Ouch.

A first approach might iter(datapoints, chunksize=nrow(datapoints) / N)
coupled with clusterApplyLB -- there will be N chunks (assuming N >
NUMCORES), and clusterApplyLB will only ever have in play a portion
NUMCORES / N of datapoints (clusterApply would divide the N chunks into
two groups, again forwarding the entire data to the workers!), so the
memory use will be (2 + NUMCORES / N) * sizeof(datapoints).

A better approach is to avoid the duplication implied by
as.list(iter(<etc>)). This would require an implementation like
snow::dynamicClusterApply, where the first NUMCORES chunks of iter() are
forwarded to the workers, and then a loop is entered where the manager
receives one result and forwards the next chunk to the worker that
provided the result. Memory use would then be (1 + NUMCORES / N) *
sizeof(datapoints). Presumably this is the strategy taken by %dopar%.

multicore should be the winner here, though, since all workers should
have access to the data without copying -- sizeof(datapoints) memory
use. I haven't used multicore extensively, and especially not on
windows. When you say "it didn't work well" it would be helpful to
understand why. My limited experimentation suggested no problems when
used with data sets that were not too close to the windows memory
limits. Perhaps you are really just running out of memory, and multicore
is not reporting this as nicely as it could? I'm sure the multicore
author would appreciate something more precise in terms of user experience.

A final consideration is that calculations on the workers are likely to
duplicate a subset of datapoints, so that actual memory use will include
an additional component that scales approximately linearly with
NUMCORES. If the worker computations are memory intensive, then you'll
quickly find yourself in trouble again.

Hope that helps,

Martin