Example #1
0
func main() {
	/* Allocate arrays of inputs and outputs */
	x := make([]float64, arraySize)
	pYeppp := make([]float64, arraySize)
	pNaive := make([]float64, arraySize)

	/* Populate the array of inputs with random data */
	for i := range x {
		x[i] = rand.Float64()
	}

	/* Retrieve the number of timer ticks per second */
	frequency := yepLibrary.GetTimerFrequency()

	/* Retrieve the number of timer ticks before calling the Go version of polynomial evaluation */
	startTimeNaive := yepLibrary.GetTimerTicks()

	/* Evaluate polynomial using Go implementation */
	evaluatePolynomialNaive(x, pNaive)

	/* Retrieve the number of timer ticks after calling the Go version of polynomial evaluation */
	endTimeNaive := yepLibrary.GetTimerTicks()

	/* Retrieve the number of timer ticks before calling Yeppp! polynomial evaluation */
	startTimeYeppp := yepLibrary.GetTimerTicks()

	/* Evaluate polynomial using Yeppp! */
	yepMath.EvaluatePolynomial_V64fV64f_V64f(coefs[:], x, pYeppp)

	/* Retrieve the number of timer ticks after calling Yeppp! polynomial evaluation */
	endTimeYeppp := yepLibrary.GetTimerTicks()

	/* Compute time in seconds and performance in FLOPS */
	secsNaive := float64(endTimeNaive-startTimeNaive) / float64(frequency)
	secsYeppp := float64(endTimeYeppp-startTimeYeppp) / float64(frequency)
	flopsNaive := float64(arraySize*(len(coefs)-1)*2) / secsNaive
	flopsYeppp := float64(arraySize*(len(coefs)-1)*2) / secsYeppp

	/* Report the timing and performance results */
	fmt.Println("Naive implementation:")
	fmt.Printf("\tTime = %f secs\n", secsNaive)
	fmt.Printf("\tPerformance = %f GFLOPS\n", flopsNaive*1.0e-9)
	fmt.Println("Yeppp! implementation:")
	fmt.Printf("\tTime = %f secs\n", secsYeppp)
	fmt.Printf("\tPerformance = %f GFLOPS\n", flopsYeppp*1.0e-9)

	/* Make sure the result is correct. */
	fmt.Printf("Max error: %7.3f%%\n", computeMaxError(pNaive, pYeppp)*100.0)
}
Example #2
0
func main() {
	/* Allocate an array of probabilities */
	p := make([]float64, arraySize)

	/* Populate the array of probabilities with random probabilities */
	for i := range p {
		/* 0 < p[i] <= 1.0 */
		p[i] = rand.Float64()
	}

	/* Retrieve the number of timer ticks per second */
	frequency := yepLibrary.GetTimerFrequency()

	/* Retrieve the number of timer ticks before calling naive entropy computation */
	startTimeNaive := yepLibrary.GetTimerTicks()

	/* Compute entropy using naive implementation */
	entropyNaive := computeEntropyNaive(p)

	/* Retrieve the number of timer ticks after calling naive entropy computation */
	endTimeNaive := yepLibrary.GetTimerTicks()

	/* Retrieve the number of timer ticks before calling Yeppp!-based entropy computation */
	startTimeYeppp := yepLibrary.GetTimerTicks()

	/* Compute entropy using Yeppp!-based implementation */
	entropyYeppp := computeEntropyYeppp(p)

	/* Retrieve the number of timer ticks after calling Yeppp!-based entropy computation */
	endTimeYeppp := yepLibrary.GetTimerTicks()

	/* Report the results */
	fmt.Println("Naive implementation:")
	fmt.Printf("\tEntropy = %f\n", entropyNaive)
	fmt.Printf("\tTime = %f\n", float64(endTimeNaive-startTimeNaive)/float64(frequency))
	fmt.Println("Yeppp! implementation:")
	fmt.Printf("\tEntropy = %f\n", entropyYeppp)
	fmt.Printf("\tTime = %f\n", float64(endTimeYeppp-startTimeYeppp)/float64(frequency))
}