Esempio n. 1
0
def bench_file(filename):
    """
    Perform comparative benchmark on matrices loaded from Matrix Market files.
    :param filename: a Matrix Market file
    """
    bs = dict()
    for dtype in WANT_DTYPES:
    	print("# loading matrix from file ", filename)
    	lt = - rsb.rsb_time()
    	a = rsb.rsb_matrix(filename,dtype=dtype)
    	lt = lt + rsb.rsb_time()
    	printf("# loaded a matrix with %.1e nnz in %.1e s (%.1e nnz/s)\n",a.nnz,lt,a.nnz/lt)
    	printf("# loaded as type %s/%c (default is %s/%c)\n", a.dtype, DT2TC[a.dtype], rsb.rsb_dtype, DT2TC[rsb.rsb_dtype])
    	if not a._is_unsymmetric():
    	    if WANT_SYMMETRIZE:
    	        print("# NOTE: loaded RSB matrix is NOT unsymmetric: expanding symmetry to cope with csr.")
    	        (I, J, V) = a.find()
    	        a = rsb.rsb_matrix((np.append(V,V), (np.append(I,J), np.append(J,I))), a.shape, dtype=dtype)
    	    else:
    	        print("# NOTE: loaded RSB matrix is NOT unsymmetric, but scipy will only perform unsymmetric SpMM")
    	if a is not None:
    	    (I, J, V) = a.find()
    	    c = sp.sparse.csr_matrix((V, (I, J)))
    	    ( mtxname, _ ) = os.path.splitext(os.path.basename(filename))
    	    ( mtxname, _ ) = os.path.splitext(mtxname)
    	    bd = bench_matrix(a, c, mtxname)
    	    dict_stat_merge(bs, derived_bench_stats(bd))
    bsc = bs.copy()
    dict_sum_average_all(bsc)
    print_perf_record(bsc,beg="pyrsb:speedups:",fields=True)
    return bs
Esempio n. 2
0
def bench_random_files():
    for nrA in want_nrA:
        ncA = nrA
        dnst = (math.sqrt(1.0 * nrA)) / nrA
        # print("# generating ",nrA,"x",ncA," with density ",dnst)
        printf("# generating %d x %d with with density %.1e\n", nrA, ncA, dnst)
        c = sp.sparse.rand(nrA,
                           ncA,
                           density=dnst,
                           format=want_psf,
                           dtype=sp.double)
        (I, J, V) = sp.sparse.find(c)
        a = rsb.rsb_matrix((V, (I, J)), [nrA, ncA])
        bench_matrix(a, c)
Esempio n. 3
0
def bench_random_files():
    """
    Perform comparative benchmark on randomly generated matrices.
    """
    for nrA in WANT_NRA:
        ncA = nrA
        dnst = (math.sqrt(1.0 * nrA)) / nrA
        # print("# generating ",nrA,"x",ncA," with density ",dnst)
        printf("# generating %d x %d with with density %.1e\n", nrA, ncA, dnst)
        gt = -rsb.rsb_time()
        c = sp.sparse.rand(nrA, ncA, density=dnst, format=WANT_PSF, dtype=sp.double)
        gt = gt + rsb.rsb_time()
        (I, J, V) = sp.sparse.find(c)
        ct = -rsb.rsb_time()
        a = rsb.rsb_matrix((V, (I, J)), [nrA, ncA])
        ct = ct + rsb.rsb_time()
        printf("# generated a matrix with %.1e nnz in %.1e s (%.1e nnz/s), converted to RSB in %.1e s\n",a.nnz(),gt,a.nnz()/gt,ct)
        bench_matrix(a, c)
Esempio n. 4
0
def bench_random_matrices():
    """
    Perform comparative benchmark on randomly generated matrices.
    """
    for dtype in WANT_DTYPES:
        for nrA in WANT_NRA:
            ncA = nrA
            dnst = (math.sqrt(1.0 * nrA)) / nrA
            # print("# generating ",nrA,"x",ncA," with density ",dnst)
            printf("# generating %d x %d with with density %.1e\n", nrA, ncA, dnst)
            gt = -rsb.rsb_time()
            c = sp.sparse.rand(nrA, ncA, density=dnst, format=WANT_PSF, dtype=rsb.rsb_dtype)
            gt = gt + rsb.rsb_time()
            (I, J, V) = sp.sparse.find(c)
            V = dtype(V)
            c = sp.sparse.csr_matrix((V, (I, J)), [nrA, ncA])
            ct = -rsb.rsb_time()
            a = rsb.rsb_matrix((V, (I, J)), [nrA, ncA], dtype=dtype)
            ct = ct + rsb.rsb_time()
            printf("# generated a matrix with %.1e nnz in %.1e s (%.1e nnz/s), converted to RSB in %.1e s\n",a.nnz,gt,a.nnz/gt,ct)
            bd = bench_matrix(a, c, "random")
            derived_bench_stats(bd)
Esempio n. 5
0
def test_demo():
    import numpy
    import scipy
    from scipy.sparse import csr_matrix
    from rsb import rsb_matrix

    V = [11.0, 12.0, 22.0]
    I = [0, 0, 1]
    J = [0, 1, 1]
    c = csr_matrix((V, (I, J)))
    print(c)
    # several constructor forms, as with csr_matrix:
    a = rsb_matrix((V, (I, J)))
    a = rsb_matrix((V, (I, J)), [3, 3])
    a = rsb_matrix((V, I, J))
    a = rsb_matrix((V, I, J), sym="S")  # symmetric example
    print(a)
    a = rsb_matrix((4, 4))
    a = rsb_matrix(c)
    nrhs = 1  # set to nrhs>1 to multiply by multiple vectors at once
    nr = a.shape[0]
    nc = a.shape[1]
    order = "F"
    x = numpy.empty([nc, nrhs], dtype=scipy.double, order=order)
    y = numpy.empty([nr, nrhs], dtype=scipy.double, order=order)
    x[:, :] = 1.0
    y[:, :] = 0.0
    print(a)
    print(x)
    print(y)
    # import rsb # import operators
    # a.autotune() # makes only sense for large matrices
    y = y + a * x
    # equivalent to y=y+c*x
    print(y)
    del a
Esempio n. 6
0
def test_init_tuple():
    V = [11.0, 12.0, 22.0]
    I = [0, 0, 1]
    J = [0, 1, 1]
    mat = rsb_matrix((V, I, J))
    assert mat.shape == (2, 2)
Esempio n. 7
0
import numpy
import scipy
from scipy.sparse import csr_matrix
from rsb import rsb_matrix
V = [11., 12., 22.]
I = [0, 0, 1]
J = [0, 1, 1]
c = csr_matrix((V, (I, J)))
print(c)
# several constructor forms, as with csr_matrix:
a = rsb_matrix((V, (I, J)))
a = rsb_matrix((V, (I, J)), [3, 3])
a = rsb_matrix((V, I, J))
a = rsb_matrix((V, I, J), sym='S')  # symmetric example
print(a)
a = rsb_matrix((4, 4))
a = rsb_matrix(c)
nrhs = 1  # set to nrhs>1 to multiply by multiple vectors at once
nr = a.shape[0]
nc = a.shape[1]
x = numpy.empty([nc, nrhs], dtype=scipy.double)
y = numpy.empty([nr, nrhs], dtype=scipy.double)
x[:, :] = 1.0
y[:, :] = 0.0
print(a)
print(x)
print(y)
#import rsb # import operators
# a.autotune() # makes only sense for large matrices
y = y + a * x
# equivalent to y=y+c*x
    #A, HF_TRANS = derv.computeFourierDerivativeMatrix(DIMS)
    #A = derv.computeCompactFiniteDiffDerivativeMatrix1(DIMS, REFS[0])
    #A = derv.computeCubicSplineDerivativeMatrix(DIMS, REFS[0], True)

    # Make a dense teste vector (MUST be NX1 for Octave to work)
    ACSR = sps.csr_matrix(np.real(A))
    V = np.expand_dims(REFS[0], 1) * np.ones((NX + 1, 1))

    # Test native dot product
    start = time.time()
    R1 = A.dot(V)
    end = time.time()
    print('Native numpy MV: ', end - start, ' sec')

    # Test native rsb dot product
    AR = rsb_matrix(ACSR)
    #AR.autotune()
    start = time.time()
    R2 = AR.dot(V)
    end = time.time()
    print('PyRSB SpMV: ', end - start, ' sec')

    # Test SpMV serial implementation
    start = time.time()
    R3 = computeMatVecDotParfor(ACSR, V, False)
    end = time.time()
    print('Serial SpMV: ', end - start, ' sec')

    # Test SpMV parallel implementation
    start = time.time()
    R4 = computeMatVecDotParfor(ACSR, V, True)
Esempio n. 9
0
    print ("# bench timeout:", WANT_TIMEOUT )
    print ("# operands alloc:", not WANT_ZERO_ALLOC)
    print ("# want RSB and scipy.sparse:", WANT_BOTH)
    print ("# render:", WANT_RENDER)
    print ("# symmetrize:", WANT_SYMMETRIZE )
if len(args) > 0:
    bs = dict()
    if len(args):
        printf("# will load matrix files:")
        for arg in args[0:]:
            printf(" %s", arg)
        printf("\n")
    elt0 = elapsed_time()
    if True:
        # warm up threads
        u = rsb.rsb_matrix(np.ones(shape=(1000,1000)))
        u.autotune(verbose=False,nrhs=1,tmax=0.0001)
        del u
    for arg in args[0:]:
        bd = bench_file(arg)
        dict_stat_merge(bs, bd)
        elt1 = elapsed_time()
        printf("# time elapsed: %.1f s\n", elt1-elt0)
    dict_sum_average_all(bs)
    print_perf_record(bs,beg="pyrsb:speedups:",fields=True)
else:
    # bench_file("venkat50.mtx.gz")
    bench_random_matrices()
    # a.save("file.mtx")
rsb.rsb_lib_exit()