def distribute_tasks(n, memlim):
    """Util function for distribute tasks in matrix computation in order to
    save memory or to parallelize computations.

    Parameters
    ----------
    n: int
        the number of rows.
    memlim: int
        the limit of rows we are able to compute at the same time.

    Returns
    -------
    lims: list
        the list of limits for each interval.

    """
    lims = []
    inflim = 0
    while True:
        if inflim + memlim >= n:
            lims.append([inflim, n])
            break
        else:
            lims.append([inflim, inflim+memlim])
            inflim = inflim+memlim
    return lims