Exemplo n.º 1
0
func main() {
	// prepare input data
	fileName := path.Join(os.Args[1], "normals.txt")
	normals := ReadNormals(fileName)

	// run benchmark
	start := time.Now()
	vector := Vector{1, 0, 0}
	const count = 1024 * 1024 * 100

	for i := 0; i < count; i++ {
		vector = ReflectVector(vector, normals[i%len(normals)])
		vector = RefractVector(vector, normals[(i+1)%len(normals)])
	}

	// communicate time to master
	elapsedTime := int(time.Since(start) / time.Millisecond)
	timingStorage := path.Join(filepath.Dir(os.Args[0]), "timing")
	common.StoreBenchmarkTiming(timingStorage, elapsedTime)

	// validation
	if len(normals) != 1024*1024 {
		common.ValidationError("invalid size of normals array")
	}
	if !VIsEqual(vector, Vector{-0.2653, -0.1665, -0.9497}, 1e-3) {
		common.ValidationError("invalid final vector value")
	}
}
Exemplo n.º 2
0
func main() {
	// prepare input data
	fileName := path.Join(os.Args[1], "random_numbers")
	array := ReadNumbersFromFile(fileName)

	// run benchmark
	start := time.Now()
	QuickSort(array)

	// communicate time to master
	elapsedTime := int(time.Since(start) / time.Millisecond)
	timingStorage := path.Join(filepath.Dir(os.Args[0]), "timing")
	common.StoreBenchmarkTiming(timingStorage, elapsedTime)

	// validation
	if len(array) != 4000000 {
		common.ValidationError("invalid size")
	}
	prevValue := array[0]
	for _, value := range array[1:] {
		if prevValue > value {
			common.ValidationError("array is not sorted")
		}
		prevValue = value
	}
}
Exemplo n.º 3
0
func main() {
	// prepare input data
	modelFiles := []string{
		path.Join(os.Args[1], "teapot.stl"),
		path.Join(os.Args[1], "bunny.stl"),
		path.Join(os.Args[1], "dragon.stl"),
	}

	var meshes []*TriangleMesh
	for _, modelFile := range modelFiles {
		meshes = append(meshes, LoadTriangleMesh(modelFile))
	}

	// run benchmark
	start := time.Now()
	var kdTrees []*KdTree
	for _, mesh := range meshes {
		builder := NewKdTreeBuilder(mesh, NewBuildParams())
		kdTrees = append(kdTrees, builder.BuildKdTree())
	}

	// communicate time to master
	elapsedTime := int(time.Since(start) / time.Millisecond)
	timingStorage := path.Join(filepath.Dir(os.Args[0]), "timing")
	common.StoreBenchmarkTiming(timingStorage, elapsedTime)

	// validation
	common.AssertEqualsHex(kdTrees[0].GetHash(), 0xe044c3a15bbf0fe4,
		"model 0: invalid kdtree hash")
	common.AssertEqualsHex(kdTrees[1].GetHash(), 0xc3491ba1f8689922,
		"model 1: invalid kdtree hash")
	common.AssertEqualsHex(kdTrees[2].GetHash(), 0x255732f17a964439,
		"model 2: invalid kdtree hash")
}
Exemplo n.º 4
0
func main() {
	const modelsCount = 3

	// prepare input data
	modelFiles := [modelsCount]string{
		path.Join(os.Args[1], "teapot.stl"),
		path.Join(os.Args[1], "bunny.stl"),
		path.Join(os.Args[1], "dragon.stl"),
	}

	kdTreeFiles := [modelsCount]string{
		path.Join(os.Args[1], "teapot.kdtree"),
		path.Join(os.Args[1], "bunny.kdtree"),
		path.Join(os.Args[1], "dragon.kdtree"),
	}

	var meshes []*TriangleMesh
	var kdTrees []*KdTree

	for i := 0; i < modelsCount; i++ {
		mesh := LoadTriangleMesh(modelFiles[i])
		meshes = append(meshes, mesh)

		kdTree := NewKdTree(kdTreeFiles[i], mesh)
		kdTrees = append(kdTrees, kdTree)
	}

	// run benchmark
	elapsedTime := 0
	for i, kdTree := range kdTrees {
		timeMsec := BenchmarkKdTree(kdTree)
		elapsedTime += timeMsec

		speed := (float64(BenchmarkRaysCount) / 1000000.0) / (float64(timeMsec) / 1000.0)
		baseName := path.Base(modelFiles[i])
		fmt.Printf("raycast performance [%-6s] = %.2f MRays/sec\n",
			baseName[:len(baseName)-4], speed)
	}

	// communicate time to master
	timingStorage := path.Join(filepath.Dir(os.Args[0]), "timing")
	common.StoreBenchmarkTiming(timingStorage, elapsedTime)

	// validation
	common.AssertEquals(uint64(RandUint32()), 3404003823, "error in random generator")

	raysCount := [modelsCount]int{32768, 64, 32}
	for i := 0; i < modelsCount; i++ {
		ValidateKdTree(kdTrees[i], raysCount[i])
	}
}