def METHOD_NAME( mpi_size, npts, mpi_dims_mask=None ):
    if mpi_dims_mask is None:
        mpi_dims_mask = [True] * len(npts)
    else:
        assert len(mpi_dims_mask) == len(npts), "mpi_dims_mask must have one entry for each dimension."
        assert all(isinstance(m, bool) for m in mpi_dims_mask), "mpi_dims_mask must only contain True/False values."
        assert any(mpi_dims_mask), "mpi_dims_mask must contain at least one True value."
    nprocs = [1]*len( npts )
    shape = []
    for n, use_dim in zip(npts, mpi_dims_mask):
        if use_dim:
            shape += [n]
        else:
            shape += [-1]
    f = factorint( mpi_size, multiple=True )
    f.sort( reverse=True )
    for a in f:
        i = np.argmax( shape )
        max_shape = shape[i]
        if shape.count( max_shape ) > 1:
            i = ma.array( nprocs, mask=np.not_equal( shape, max_shape ) ).argmin()
        nprocs[i]  *= a
        shape [i] //= a
    for i, use_dim in enumerate(mpi_dims_mask):
        if not use_dim:
            shape[i] = npts[i]
    return nprocs, shape