from mpi4py import MPI
import numpy as np

x1 = -2.0
x2 =  1.0
y1 = -1.0
y2 =  1.0

w = 600
h = 400
maxit = 255

## import os
## dirname = os.path.abspath(os.path.dirname(__file__))
## executable = os.path.join(dirname, 'mandelbrot-worker.exe')
executable = 'mandelbrot-worker.exe'

# spawn worker
worker = MPI.COMM_SELF.Spawn(executable, maxprocs=5)
size = worker.Get_remote_size()

# send parameters
rmsg = np.array([x1, x2, y1, y2], dtype='f')
imsg = np.array([w, h, maxit], dtype='i')
worker.Bcast([rmsg, MPI.REAL], root=MPI.ROOT)
worker.Bcast([imsg, MPI.INTEGER], root=MPI.ROOT)

# gather results
counts = np.empty(size, dtype='i')
indices = np.empty(h, dtype='i')
cdata = np.empty([h, w], dtype='i')
worker.Gather(sendbuf=None,
              recvbuf=[counts, MPI.INTEGER],
              root=MPI.ROOT)
worker.Gatherv(sendbuf=None,
               recvbuf=[indices, (counts, None), MPI.INTEGER],
               root=MPI.ROOT)
worker.Gatherv(sendbuf=None,
               recvbuf=[cdata, (counts * w, None), MPI.INTEGER],
               root=MPI.ROOT)

# disconnect worker
worker.Disconnect()

M = np.zeros([h,w], dtype='i')
M[indices, :] = cdata

try:
    from matplotlib import pyplot as plt
except ImportError:
    pass
else:
    plt.imshow(M, aspect='equal')
    plt.spectral()
    try:
        import sys, signal
    except ImportError:
        pass
    else:
        def action(*args):
            raise SystemExit
        signal.signal(signal.SIGALRM, action)
        signal.alarm(2)
        try: plt.show()
        except: pass

from mpi4py import MPI
import numpy as np

x1 = -2.0
x2 =  1.0
y1 = -1.0
y2 =  1.0

w = 600
h = 400
maxit = 255

import os
dirname = os.path.abspath(os.path.dirname(__file__))
executable = os.path.join(dirname, 'mandelbrot-worker.exe')

# spawn worker
worker = MPI.COMM_SELF.Spawn(executable, maxprocs=5)
size = worker.Get_remote_size()

# send parameters
rmsg = np.array([x1, x2, y1, y2], dtype='f')
imsg = np.array([w, h, maxit], dtype='i')
worker.Bcast([rmsg, MPI.REAL], root=MPI.ROOT)
worker.Bcast([imsg, MPI.INTEGER], root=MPI.ROOT)

# gather results
counts = np.empty(size, dtype='i')
indices = np.empty(h, dtype='i')
cdata = np.empty([h, w], dtype='i')
worker.Gather(sendbuf=None,
              recvbuf=[counts, MPI.INTEGER],
              root=MPI.ROOT)
worker.Gatherv(sendbuf=None,
               recvbuf=[indices, (counts, None), MPI.INTEGER],
               root=MPI.ROOT)
worker.Gatherv(sendbuf=None,
               recvbuf=[cdata, (counts * w, None), MPI.INTEGER],
               root=MPI.ROOT)

# disconnect worker
worker.Disconnect()

M = np.zeros([h,w], dtype='i')
M[indices, :] = cdata

try:
    from matplotlib import pyplot as plt
except ImportError:
    pass
else:
    plt.imshow(M, aspect='equal')
    plt.spectral()
    try:
        import sys, signal
    except ImportError:
        pass
    else:
        def action(*args):
            raise SystemExit
        signal.signal(signal.SIGALRM, action)
        signal.alarm(2)
        try: plt.show()
        except: pass

Use absolute path for spawning worker executable in Mandelbrot demo