Coder Social home page Coder Social logo

Comments (2)

ilarischeinin avatar ilarischeinin commented on May 27, 2024

I agree the documentation and behavior is confusing.

When run with mc.preschedule=TRUE (default) and mc.cores=1L, mclapply() will actually not fork a separate process:

Line 117 in mclapply():

    if (cores < 2L) return(lapply(X = X, FUN = FUN, ...))

i.e. same behavior you noted for pvec(). However, I guess technically this doesn't go against the documentation, since it says:

a integer giving the maximum allowed number of additional R processes allowed to be run in parallel to the current R process.

So, when mc.cores=1L, allowed additional processes are either 0 (as with mclapply(mc.preschedule=TRUE) or 1 (as with mclapply(mc.preschedule=FALSE).

But like I said, that is confusing and also inconsistent. It makes no sense to fork one additional process and have the main process simply wait.

The idea of the main process simply waiting I guess is the rational behind using mc.cores=detectCores() instead of - 1L. The point isn't so much to define how many simultaneous processes are allowed, but how many processes are allowed to compute at the same time. (Hence the two different behaviors of mclapply(mc.cores=1L) of one or two simultaneous processes, but only one actually doing anything.)

from wishlist-for-r.

HenrikBengtsson avatar HenrikBengtsson commented on May 27, 2024

Thanks for the comments @ilarischeinin and for spotting the mcapply(mc.preschedule=TRUE) case; I've updated my top comment accordingly. To me this indicates that the developer(s) had similar ideas but at some point we ended up with a requirement of mc.cores >= 1.

I've also fixed a typo in my code suggestion: It should be if (mc.cores == 0 || (isChild() && !isTRUE(mc.allow.recursive))) and nothing else.

About the number of active versus computing processes: Yes, it's true that the main process shouldn't consume that much of the CPU since it is "just" spawning and polling for results. Having said this, I can imagine that there are obnoxiously strict compute clusters that would kick you out if you ran one process more than you requested (regardless of it's CPU usage). Moreover, this is holds for mclapply(). If you use for instance mcparallel(), there is nothing preventing you from running for computations in the main process as well. This can certainly becomes a reality with futures, where a main loop spawns of background processes and collects and post-processes results as they come back in while still polling for results of non-finished processes. This is why I think it is very important that the definition of mc.cores is very transparent and clear.

from wishlist-for-r.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.