Example #1
0
func testTextFile() {
	flag.Parse()
	ctx := gopark.NewContext("gopark")
	defer ctx.Stop()
	p := "."
	txt := ctx.TextFileExt(p, "")
	fm := txt.FlatMap(flatmap_func)
	fm = fm.Map(map_func)
	fm = fm.ReduceByKey(reducer_func)
	counts := fm

	ff := counts.Filter(filter_func)

	mm := ff.CollectAsMap()
	fmt.Printf("Word count > 30:%#v\n", mm)

	fmt.Println("TopN=-10\n==========")
	t1 := counts.TopN(-10, less_func)
	for k, v := range t1 {
		fmt.Printf("k, v: %#v %#v\n", k, v)
	}

	fmt.Println("Top10\n==========")
	t2 := counts.Top10(less_func)
	for k, v := range t2 {
		fmt.Printf("k, v: %#v %#v\n", k, v)
	}

}
Example #2
0
func testPi() {
	flag.Parse()
	ctx := gopark.NewContext("gopark")
	defer ctx.Stop()
	N := 100
	data := make([]interface{}, N)
	iters := ctx.ParallelizeN(data, 20)
	iters.Foreach(random_once)
	fmt.Println("Pi =", (4.0 * count.Value().(float64) / float64(N)))
}
Example #3
0
func saveTextFile() {
	ctx := gopark.NewContext("gopark")
	defer ctx.Stop()
	file := ctx.TextFile("wc.go")
	words := file.FlatMap(fn).Map(fnMap)

	fm := words.ReduceByKey(fnReduce)

	tt := fm.Map(map_string)
	abc := tt.SaveAsTextFileM("abc/", "", true, true)
	fmt.Printf("%#v\n", abc)
}
Example #4
0
func CountPI1() {
	flag.Parse()
	ctx := gopark.NewContext("gopark")
	defer ctx.Stop()
	N := 10000
	data := make([]interface{}, N)
	iters := ctx.ParallelizeN(data, 20)

	iters.Foreach(random_once)
	val := count.Value().(float64)
	fmt.Println(val)
	fmt.Printf("Pi = %f \n", (4.0 * val / float64(N)))
}
Example #5
0
func CountPI2() {
	flag.Parse()
	N := 5000
	ctx := gopark.NewContext("gopark")
	defer ctx.Stop()

	data := make([]interface{}, N)

	iters := ctx.ParallelizeN(data, 10)
	m := iters.Map(map_func)

	count := m.Reduce(reducer_func).(int)
	fmt.Println(count)
	fmt.Printf("Pi = %f \n", (4.0 * float64(count) / float64(N)))
}
Example #6
0
func Top10() {
	ctx := gopark.NewContext("gopark")
	defer ctx.Stop()
	file := ctx.TextFile("wc.go")
	words := file.FlatMap(fn).Map(fnMap)

	fm := words.ReduceByKey(fnReduce)

	fmt.Println("Top10\n==========")
	t2 := fm.Top10(fnLess)
	for k, v := range t2 {
		fmt.Printf("k, v: %#v %#v\n", k, v)
	}

}
Example #7
0
func textSearch() {
	ctx := gopark.NewContext("gopark")
	defer ctx.Stop()

	textfile := ctx.TextFileExt("./", ".go")
	f := textfile.Map(fnMap_line)
	log := f.Filter(filter_fn).Cache()
	results := log.Collect()
	fmt.Printf("results.: %#v\n", results)
	fmt.Printf("glog.: %d\n", log.Count())
	fmt.Printf("fatal: %d\n", log.Filter(filter_fatal).Count())
	for _, line := range log.Filter(filter_info).Collect() {
		fmt.Println(line)
	}

}
Example #8
0
func WC() {
	ctx := gopark.NewContext("gopark")
	defer ctx.Stop()
	file := ctx.TextFile("wc.go")
	words := file.FlatMap(fn).Map(fnMap)

	wc := words.ReduceByKey(fnReduce).CollectAsMap()
	if len(wc) <= 0 {
		panic("wc is nil")
	} else {
		fmt.Printf("=====>>%d  func count %d\n", len(wc), wc[interface{}("func")])
		for k, v := range wc {
			fmt.Printf("k:%#v, v:%#v\n", k, v)
		}
	}
}