Coder Social home page Coder Social logo

Comments (4)

dfm avatar dfm commented on September 26, 2024 1

This could have something to do with the communication overhead on your specific system or the load on your CPU from other process. Another option is that this has something to do with how Jupyter handles parallelization. One experiment to try would be running this from a script instead of from Jupyter and monitoring the CPU usage during the run. Hope this helps!

from emcee.

porpose avatar porpose commented on September 26, 2024

This could have something to do with the communication overhead on your specific system or the load on your CPU from other process. Another option is that this has something to do with how Jupyter handles parallelization. One experiment to try would be running this from a script instead of from Jupyter and monitoring the CPU usage during the run. Hope this helps!

Thanks so much for the reply! I wrapped the code into a .py script file and ran it on my Windows laptop. The output makes me confused:

1667524053322

(Note that the final run was much faster, at 26 iterations/s)

So instead of seeing just the output from one serial run and one parallel run, I got ten different MCMC run outputs. And yes my CPU cores were at full speed during the parallel run:

1667524021217

from emcee.

dfm avatar dfm commented on September 26, 2024

Good discovery! I think that if you now wrap your script as follows:

if __name__ == "__main__":
    # The rest of the script goes here...

Then it'll only run everything once! This is probably because multiprocessing is forking the process and running all the setup on each worker.

from emcee.

porpose avatar porpose commented on September 26, 2024

Good discovery! I think that if you now wrap your script as follows:

if __name__ == "__main__":
    # The rest of the script goes here...

Then it'll only run everything once! This is probably because multiprocessing is forking the process and running all the setup on each worker.

Thanks! The result I got in my previous reply was actually exactly the effect of adding if __name__ == "__main__": . (I found this solution on StackOverflow just some moments earlier...) I added this line before the part on multiprocessing.

If I don't add anything, I got an error pop out:

RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.

from emcee.

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.