Skip to content

Instantly share code, notes, and snippets.

@dfm
Created November 30, 2012 14:56
Show Gist options
  • Save dfm/4176241 to your computer and use it in GitHub Desktop.
Save dfm/4176241 to your computer and use it in GitHub Desktop.
Strange mpi4py error.

The script works.py runs fine and give reasonable results but the script notworking.py throws a cPickle.UnpicklingError and then stalls. The only difference is the line:

nwalkers = 100  # Works.
nwalkers = 150  # Doesn't work.
import sys
import numpy as np
import emcee
from emcee.utils import MPIPool
def lnprob(x):
return -0.5 * np.sum(x ** 2)
ndim = 50
nwalkers = 150
p0 = [np.random.rand(ndim) for i in xrange(nwalkers)]
pool = MPIPool()
if not pool.is_master():
# Wait for instructions from the master process.
pool.wait()
sys.exit(0)
sampler = emcee.EnsembleSampler(nwalkers, ndim, lnprob, pool=pool)
pos, prob, state = sampler.run_mcmc(p0, 1)
import sys
import numpy as np
import emcee
from emcee.utils import MPIPool
def lnprob(x):
return -0.5 * np.sum(x ** 2)
ndim = 50
nwalkers = 100
p0 = [np.random.rand(ndim) for i in xrange(nwalkers)]
pool = MPIPool()
if not pool.is_master():
# Wait for instructions from the master process.
pool.wait()
sys.exit(0)
sampler = emcee.EnsembleSampler(nwalkers, ndim, lnprob, pool=pool)
pos, prob, state = sampler.run_mcmc(p0, 1)
@juliohm
Copy link

juliohm commented Apr 22, 2014

I'm experiencing similar cPickle.UnpicklingError with simpler snippets of code:

import emcee
import numpy as np

pool = emcee.utils.MPIPool()

def f(x): return np.empty(2500)

X = np.empty([100,50000])

Y = np.array(pool.map(f, [x for x in X]))

pool.close()

If I reduce the size of the array returned by f from 2500 to 100 for instance, the code just works. This issue might be related to MPI buffer size limits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment