Beispiel #1
0
// single invocation for matops and lapack functions
func runCheck(A *matrix.FloatMatrix, LB int) (bool, time.Duration, time.Duration) {

	var flags matops.Flags
	N := A.Rows()
	ipiv := make([]int, N, N)
	ipiv0 := make([]int32, N, N)
	flags = matops.LOWER
	lopt := linalg.OptLower
	if testUpper {
		flags = matops.UPPER
		lopt = linalg.OptUpper
	}
	W := matrix.FloatZeros(A.Rows(), LB+2)
	fnc := func() {
		_, ERRmatops = matops.DecomposeBK(A, W, ipiv, flags, LB)
	}

	if verbose && N < 10 {
		fmt.Fprintf(os.Stderr, "A start:\n%v\n", A)
	}
	A0 := A.Copy()
	mperf.FlushCache()
	time0 := mperf.Timeit(fnc)
	if verbose && N < 10 {
		fmt.Fprintf(os.Stderr, "ipiv:%v\n", ipiv)
		fmt.Fprintf(os.Stderr, "A end:\n%v\n", A)
	}

	fn2 := func() {
		ERRlapack = lapack.Sytrf(A0, ipiv0, lopt)
	}
	if verbose && N < 10 {
		fmt.Fprintf(os.Stderr, "A0 start:\n%v\n", A0)
	}
	mperf.FlushCache()
	time2 := mperf.Timeit(fn2)
	if verbose && N < 10 {
		fmt.Fprintf(os.Stderr, "ipiv0:%v\n", ipiv0)
		fmt.Fprintf(os.Stderr, "A0 end:\n%v\n", A0)
	}
	// now A == A0 && ipiv == ipiv0

	ok := A.AllClose(A0)
	okip := checkIPIV(ipiv, ipiv0)
	if !ok || !okip {
		// save result to globals
		Rlapack = A0
		Rmatops = A
		IPIVlapack = ipiv0
		IPIVmatops = ipiv
	}
	return ok && okip, time0, time2
}
Beispiel #2
0
// single invocation for matops and lapack functions
func runCheck(A *matrix.FloatMatrix, LB int) (bool, time.Duration, time.Duration) {

	M := A.Rows()
	N := A.Cols()
	nN := N
	if M < N {
		nN = M
	}
	ipiv := make([]int, nN, nN)
	ipiv0 := make([]int32, nN, nN)
	fnc := func() {
		_, ERRmatops = matops.DecomposeLU(A, ipiv, LB)
	}

	if verbose && N < 10 {
		fmt.Fprintf(os.Stderr, "A start:\n%v\n", A)
	}
	A0 := A.Copy()
	mperf.FlushCache()
	time0 := mperf.Timeit(fnc)
	if verbose && N < 10 {
		fmt.Fprintf(os.Stderr, "A end:\n%v\n", A)
		fmt.Fprintf(os.Stderr, "ipiv:%v\n", ipiv)
	}

	fn2 := func() {
		ERRlapack = lapack.Getrf(A0, ipiv0)
	}
	if verbose && N < 10 {
		fmt.Fprintf(os.Stderr, "A0 start:\n%v\n", A0)
	}
	mperf.FlushCache()
	time2 := mperf.Timeit(fn2)
	if verbose && N < 10 {
		fmt.Fprintf(os.Stderr, "A0 end:\n%v\n", A0)
		fmt.Fprintf(os.Stderr, "ipiv0:%v\n", ipiv0)
	}
	// now A == A0 && ipiv == ipiv0

	ok := A.AllClose(A0)
	okip := checkIPIV(ipiv, ipiv0)
	_ = okip
	if !ok || !okip {
		// save result to globals
		Rlapack = A0
		Rmatops = A
		IPIVlapack = ipiv0
		IPIVmatops = ipiv
	}
	return ok && okip, time0, time2
}
Beispiel #3
0
// single invocation for matops and lapack functions
func runCheck(A *matrix.FloatMatrix, LB int) (bool, time.Duration, time.Duration) {

	var W *matrix.FloatMatrix = nil
	N := A.Cols()
	tau := matrix.FloatZeros(N, 1)
	if LB > 0 {
		W = matrix.FloatZeros(A.Rows(), LB)
	}
	fnc := func() {
		_, ERRmatops = matops.DecomposeQR(A, tau, W, LB)
	}

	if verbose && N < 10 {
		fmt.Fprintf(os.Stderr, "A start:\n%v\n", A)
	}
	A0 := A.Copy()
	tau0 := tau.Copy()

	mperf.FlushCache()
	time0 := mperf.Timeit(fnc)
	if verbose && N < 10 {
		fmt.Fprintf(os.Stderr, "A end:\n%v\n", A)
		tau.SetSize(1, N, 1)
		fmt.Fprintf(os.Stderr, "tau: %v\n", tau)
	}

	fn2 := func() {
		ERRlapack = lapack.Geqrf(A0, tau0)
	}

	mperf.FlushCache()
	time2 := mperf.Timeit(fn2)
	if verbose && N < 10 {
		fmt.Fprintf(os.Stderr, "A0 end:\n%v\n", A0)
		tau0.SetSize(1, N, 1) // row vector
		fmt.Fprintf(os.Stderr, "tau0: %v\n", tau0)
	}
	// now A == A0 && tau == tau0

	ok := A.AllClose(A0)
	oktau := tau.AllClose(tau0)
	if !ok || !oktau {
		// save result to globals
		Rlapack = A0
		Rmatops = A
		TAUlapack = tau0
		TAUmatops = tau
	}
	return ok && oktau, time0, time2
}
Beispiel #4
0
func runRefTest(A *matrix.FloatMatrix, ntest, LB int) time.Duration {

	var mintime time.Duration

	lopt := linalg.OptLower
	if testUpper {
		lopt = linalg.OptUpper
	}

	fnc := func() {
		ERRlapack = lapack.Potrf(A, lopt)
	}

	A0 := A.Copy()
	for n := 0; n < ntest; n++ {
		if n > 0 {
			// restore original A
			A0.CopyTo(A)
		}
		mperf.FlushCache()
		time0 := mperf.Timeit(fnc)
		if n == 0 || time0 < mintime {
			mintime = time0
		}
	}
	return mintime
}
Beispiel #5
0
func runTest(A *matrix.FloatMatrix, ntest, LB int) time.Duration {

	var flags matops.Flags
	var mintime time.Duration

	flags = matops.LOWER
	if testUpper {
		flags = matops.UPPER
	}

	fnc := func() {
		_, ERRmatops = matops.DecomposeCHOL(A, flags, LB)
	}

	A0 := A.Copy()
	for n := 0; n < ntest; n++ {
		if n > 0 {
			// restore original A
			A0.CopyTo(A)
		}
		mperf.FlushCache()
		time0 := mperf.Timeit(fnc)
		if n == 0 || time0 < mintime {
			mintime = time0
		}
		if verbose {
			fmt.Printf("%.4f ms\n", time0.Seconds()*1000.0)
		}
	}
	return mintime
}
Beispiel #6
0
func runRefTest(A *matrix.FloatMatrix, ntest, LB int) time.Duration {

	var mintime time.Duration

	M := A.Rows()
	N := A.Cols()
	nN := N
	if M < N {
		nN = M
	}
	ipiv := make([]int32, nN, nN)

	fnc := func() {
		ERRlapack = lapack.Getrf(A, ipiv)
	}

	A0 := A.Copy()
	for n := 0; n < ntest; n++ {
		if n > 0 {
			// restore original A
			A0.CopyTo(A)
		}
		mperf.FlushCache()
		time0 := mperf.Timeit(fnc)
		if n == 0 || time0 < mintime {
			mintime = time0
		}
	}
	return mintime
}
Beispiel #7
0
func runTest(A *matrix.FloatMatrix, ntest, LB int) time.Duration {

	var mintime time.Duration

	M := A.Rows()
	N := A.Cols()
	nN := N
	if M < N {
		nN = M
	}
	ipiv := make([]int, nN, nN)

	fnc := func() {
		_, ERRmatops = matops.DecomposeLU(A, ipiv, LB)
	}

	A0 := A.Copy()
	for n := 0; n < ntest; n++ {
		if n > 0 {
			// restore original A
			A0.CopyTo(A)
		}
		mperf.FlushCache()
		time0 := mperf.Timeit(fnc)
		if n == 0 || time0 < mintime {
			mintime = time0
		}
		if verbose {
			fmt.Printf("%.4f ms\n", time0.Seconds()*1000.0)
		}
	}
	return mintime
}
Beispiel #8
0
func runRefTest(A *matrix.FloatMatrix, ntest, LB int) time.Duration {

	var mintime time.Duration

	N := A.Cols()
	tau := matrix.FloatZeros(N, 1)

	fnc := func() {
		ERRlapack = lapack.Geqrf(A, tau)
	}

	A0 := A.Copy()
	for n := 0; n < ntest; n++ {
		if n > 0 {
			// restore original A
			A0.CopyTo(A)
			tau.Scale(0.0)
		}
		mperf.FlushCache()
		time0 := mperf.Timeit(fnc)
		if n == 0 || time0 < mintime {
			mintime = time0
		}
	}
	return mintime
}
Beispiel #9
0
func runTest(A *matrix.FloatMatrix, ntest, LB int) time.Duration {
	var W *matrix.FloatMatrix = nil
	var mintime time.Duration

	N := A.Cols()
	tau := matrix.FloatZeros(N, 1)
	if LB > 0 {
		W = matrix.FloatZeros(A.Rows(), LB)
	}
	fnc := func() {
		_, ERRmatops = matops.DecomposeQR(A, tau, W, LB)
	}

	A0 := A.Copy()
	for n := 0; n < ntest; n++ {
		if n > 0 {
			// restore original A
			A0.CopyTo(A)
			tau.Scale(0.0)
		}
		mperf.FlushCache()
		time0 := mperf.Timeit(fnc)
		if n == 0 || time0 < mintime {
			mintime = time0
		}
		if verbose {
			fmt.Printf("%.4f ms\n", time0.Seconds()*1000.0)
		}
	}
	return mintime
}
Beispiel #10
0
func runRefTest(A *matrix.FloatMatrix, ntest, LB int) time.Duration {

	var flags matops.Flags
	var mintime time.Duration

	N := A.Rows()
	ipiv := make([]int, N, N)
	flags = matops.LOWER
	if testUpper {
		flags = matops.UPPER
	}

	W := matrix.FloatZeros(A.Rows(), LB+2)
	fnc := func() {
		_, ERRref = matops.DecomposeLDL(A, W, ipiv, flags, 0)
	}

	A0 := A.Copy()
	for n := 0; n < ntest; n++ {
		if n > 0 {
			// restore original A
			A0.CopyTo(A)
		}
		mperf.FlushCache()
		time0 := mperf.Timeit(fnc)
		if n == 0 || time0 < mintime {
			mintime = time0
		}
	}
	return mintime
}
Beispiel #11
0
// single invocation for matops and lapack functions
func runCheck(A *matrix.FloatMatrix, LB int) (bool, time.Duration, time.Duration) {

	var flags matops.Flags
	N := A.Rows()
	flags = matops.LOWER
	lopt := linalg.OptLower
	if testUpper {
		flags = matops.UPPER
		lopt = linalg.OptUpper
	}

	fnc := func() {
		_, ERRmatops = matops.DecomposeCHOL(A, flags, LB)
	}

	if verbose && N < 10 {
		fmt.Fprintf(os.Stderr, "A start:\n%v\n", A)
	}
	A0 := A.Copy()
	mperf.FlushCache()
	time0 := mperf.Timeit(fnc)
	if verbose && N < 10 {
		fmt.Fprintf(os.Stderr, "A end:\n%v\n", A)
	}

	fn2 := func() {
		ERRlapack = lapack.Potrf(A0, lopt)
	}
	if verbose && N < 10 {
		fmt.Fprintf(os.Stderr, "A0 start:\n%v\n", A0)
	}
	mperf.FlushCache()
	time2 := mperf.Timeit(fn2)
	if verbose && N < 10 {
		fmt.Fprintf(os.Stderr, "A0 end:\n%v\n", A0)
	}
	// now A == A0 && ipiv == ipiv0

	ok := A.AllClose(A0)
	if !ok {
		// save result to globals
		Rlapack = A0
		Rmatops = A
	}
	return ok, time0, time2
}
Beispiel #12
0
func main() {
	flag.Parse()
	runtime.GOMAXPROCS(nWorker)
	matops.NumWorkers(nWorker)
	rand.Seed(time.Now().UnixNano())

	testFunc, ok := tests[testName]
	if !ok {
		fmt.Printf("Error: test %s does not exists.\nKnown tests:\n", testName)
		for tname := range tests {
			fmt.Printf("\t%s\n", tname)
		}
		return
	}
	var checkFunc mperf.MatrixCheckFunc
	if transpose[0] == 'A' {
		checkFunc = CheckTransA
	} else {
		checkFunc = CheckNoTrans
	}

	if singleTest {
		fnc, A, X, Y0 := testFunc(M, N, P)
		mperf.FlushCache()
		tm := mperf.Timeit(fnc)
		if check {
			reftime, ok := mperf.CheckWithFunc(A, X, Y0, checkFunc)
			if verbose {
				fmt.Fprintf(os.Stderr, "%s: %v\n", testName, tm)
				fmt.Fprintf(os.Stderr, "Reference: [%v] %v (%.2f) \n",
					ok, reftime, tm.Seconds()/reftime.Seconds())
			}
		}
		//sec, _ := mperf.SingleTest(testName, testFunc, M, N, P, check, verbose)
		if asGflops {
			gflops := 2.0 * float64(int64(M)*int64(N)*int64(P)) / tm.Seconds() * 1e-9
			fmt.Printf("%.4f Gflops\n", gflops)
		} else if asEps {
			eps := float64(int64(M)*int64(N)) / tm.Seconds()
			fmt.Printf("%.4f Eps\n", eps)
		} else {
			fmt.Printf("%vs\n", tm.Seconds())
		}
		return
	}

	if len(sizeList) > 0 {
		sizes = parseSizeList(sizeList)
	}
	times := mperf.MultipleSizeTests(testFunc, sizes, testCount, verbose)
	if asGflops || asEps {
		if verbose {
			fmt.Printf("calculating Gflops ...\n")
		}
		for sz := range times {
			n := int64(sz)
			if asGflops {
				times[sz] = 2.0 * float64(n*n) / times[sz] * 1e-9
			} else {
				times[sz] = float64(n) / times[sz]
			}
		}
	}
	// print out as python dictionary
	fmt.Printf("{")
	i := 0
	for sz := range times {
		if i > 0 {
			fmt.Printf(", ")
		}
		fmt.Printf("%d: %v", sz, times[sz])
		i++
	}
	fmt.Printf("}\n")
}