carstenbauer / MonteCarlo.jl

Classical and quantum Monte Carlo simulations in Julia
https://carstenbauer.github.io/MonteCarlo.jl/dev/
Other
185 stars 18 forks source link

MPI Implementation examples. #173

Closed kfkq closed 1 year ago

kfkq commented 1 year ago

Hello, is there any examples how to use parallel computing (MPI) in DQMC? how does the parallel works in principle? does each worker run independent simulation?

ffreyer commented 1 year ago

With these kinds of Monte Carlo simulations you generally do 1 core per simulation because you have many simulations, many combinations of parameters (temperature, system size, model parameters).

What you use to get there depends on your system. Some allow you to start a bunch of simulations as independent jobs, i.e. jobs that can finish independently. That's the easiest setup.

If you're restricted to using full nodes you'll want a bit of management. Otherwise you'll end up with some faster simulations (low system size, high temperature, and/or maybe partially finished) finishing and leaving your job half occupied. For that you can use pmap or, if that doesn't work, the mpi_queue function implemented here.

I've also implemented some parallel tempering updates. Now these come with trade of - you should get better statistics with them but you also need to sync and wait on simulations, leading to less sweeps in an equal time frame leading to worse statistics. So it may or may not be worth it. I personally haven't tested these updates much, iirc only on my local PC. For MPI there is an example here. The version using Julia parallelism works the same way (you construct the update with a worker id which it should exchange with). Note that you can't do parallel tempering between different temperatures or system sizes since that leads to differently sized configurations.