Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Parallel slower than non parallel

Howdy. I just made my first attempt at parallel computing in Sage. It didn't go well: My parallel version of the program is slower than the non-parallel version. I assume I've done something wrong. How can I fix this, or at least diagnose the problem? Note that the input (M) is a matrix.

Here's the parallel version:

@parallel
def totaler(i, M_4, M_2, M):
    return M_4[i][i] - sum(M_2[i]) - (sum(M[i]) ** 2 - sum(M[i]))
def bccounter(M):
    M_2 = M ** 2
    M_4 = M_2 ** 2
    n = len(M[1])
    total = sum([x[1] for x in totaler([(x, M_4, M_2, M) for x in range(n)])])
    return total / 8

Here's the non-parallel version:

def bccounter(M):
    M_2 = M ** 2
    M_4 = M_2 ** 2
    n = len(M[1])
    total = 0
    for i in range(n):
        total += M_4[i][i] - sum(M_2[i]) - (sum(M[i]) ** 2 - sum(M[i]))
    return total / 8

If you're curious, it counts the number of 4-cycles in a graph with adjacency matrix M.

click to hide/show revision 2
fixed a variable. problem persists.

Parallel slower than non parallel

Howdy. I just made my first attempt at parallel computing in Sage. It didn't go well: My parallel version of the program is slower than the non-parallel version. I assume I've done something wrong. How can I fix this, or at least diagnose the problem? Note that the input (M) is a matrix.

Here's the parallel version:

@parallel
def totaler(i, M_4, M_2, M):
    return M_4[i][i] - sum(M_2[i]) - (sum(M[i]) ** 2 - sum(M[i]))
def bccounter(M):
    M_2 = M ** 2
    M_4 = M_2 ** 2
    n = len(M[1])
    total = sum([x[1] for x in totaler([(x, totaler([(y, M_4, M_2, M) for x y in range(n)])])
    return total / 8

Here's the non-parallel version:

def bccounter(M):
    M_2 = M ** 2
    M_4 = M_2 ** 2
    n = len(M[1])
    total = 0
    for i in range(n):
        total += M_4[i][i] - sum(M_2[i]) - (sum(M[i]) ** 2 - sum(M[i]))
    return total / 8

If you're curious, it counts the number of 4-cycles in a graph with adjacency matrix M.