Ejemplo n.º 1
0
//main: time.Time the Walk
func main() {
	var n, s int
	var scale uint
	scale = *scaleptr
	n = 2 << scale
	//fmt.Printf("scale:%d,", scale)
	s = 1
	k := 6
	stepsize := make([]int, k)
	tg := timing.New(k)
	correctsum := Dtype((n * (n - 1)) / 2)
	stepsize[0] = 1
	for i := 1; i < len(stepsize); i++ {
		stepsize[i] = 2 * stepsize[i-1]
	}
	//fmt.Printf("strides:%v,\n",stepsize)
	sdr := Strider{make([]Dtype, n), s}
	var sum Dtype
	for i, k := range stepsize {
		sdr.stride = k
		sdr.Fill()
		tg.Tic(i)
		for iter := 0; iter < 10; iter++ {
			sum = sdr.Walk()
		}
		tg.Toc(i)
		if correctsum != sum {
			fmt.Println("we did not hit all the elements")
			fmt.Println(correctsum, sum)
		}
	}

	perm := rand.Perm(n)
	ptg := timing.New(1)
	ptg.Tic(0)
	var randsum Dtype
	for run := 0; run < 10; run++ {
		randsum = 0
		for _, j := range perm {
			randsum += sdr.data[j]
		}
	}
	ptg.Toc(0)
	if randsum != correctsum {
		fmt.Printf("random ordered produced wrong sum: %v, %v,\n", randsum, correctsum)
	}
	tg.Resolve()
	fmt.Print(tg)
	ptg.Resolve()
	fmt.Printf(" %v\n", ptg)
}
Ejemplo n.º 2
0
func TestBigList(t *testing.T) {
	fmt.Println("benching")
	var node *Node
	var sum Dtype
	var ell List
	maxscale := 20
	minscale := 18
	tg := timing.New(maxscale - minscale)

	for k := minscale; k < maxscale; k++ {
		os.Stderr.WriteString(fmt.Sprintf("starting scale %d\n", k))
		ell = New()
		size := 2 << uint(k)
		//Fill the list full of data
		for i := 0; i < size; i++ {
			ell.Insert(i, Dtype(i))
		}
		//Extract all of the data
		sum = 0
		node = ell.Head
		tg.Tic(k - minscale)
		for node != nil {
			sum += node.Datum
			node = node.Next
		}
		tg.Toc(k - minscale)
		//Checking that we made the traversal correctly
		correctsum := (size * (size - 1)) / 2
		if Dtype(correctsum) != sum {
			t.Errorf("incomplete traversal: %v %v", sum, correctsum)
		}
	}
	tg.Resolve()
	fmt.Println(tg.TupleString("\n"))
}
Ejemplo n.º 3
0
func TestParforCPU(t *testing.T) {
	var data []int
	tmr := timing.New(rounds - 1)
	var ans int
	for i := 1; i < rounds; i++ {
		runtime.GOMAXPROCS(i)
		tmr.Tic(i - 1)
		for k := 0; k < reps; k++ {
			ans = Parfor(cpusum, i, numdata, data)
		}
		tmr.Toc(i - 1)
		if ans != rightans {
			t.Fail()
		}
	}
	tmr.Resolve()
	tmrKeyPrint(tmr, "ParforCPU")
}
Ejemplo n.º 4
0
func TestLoad(t *testing.T) {
	tmr := timing.New(rounds - 1)
	var k int
	for k = 1; k < rounds; k++ {
		count := 2 << uint(k)
		ch := make(chan int, count)
		tmr.Tic(k - 1)
		for i := 0; i < count; i++ {
			go run(i, ch)
		}
		var sum int
		for i := 0; i < count; i++ {
			sum += <-ch
		}
		tmr.Toc(k - 1)
	}
	tmr.Resolve()
	tmrKeyPrint(tmr, "Load")
	return
}
Ejemplo n.º 5
0
func TestParforMem(t *testing.T) {
	data := make([]int, numdata)
	fmt.Printf("numdata:%d\n", numdata)
	for i := 0; i < numdata; i++ {
		data[i] = i
	}
	tmr := timing.New(rounds - 1)
	var ans int
	for i := 1; i < rounds; i++ {
		runtime.GOMAXPROCS(i)
		tmr.Tic(i - 1)
		for k := 0; k < reps; k++ {
			ans = Parfor(memsum, i, numdata, data)
		}
		tmr.Toc(i - 1)
		if ans != rightans {
			t.Fail()
		}
	}
	tmr.Resolve()
	tmrKeyPrint(tmr, "ParforMem")
}