Beispiel #1
0
func main() {
	var subsample, maxs float64
	var fn, cpuprof string
	flag.Float64Var(&subsample, "subfraction", 1.01, "Subsampling fraction")
	flag.Float64Var(&maxs, "maxs", 200, "maximum s value")
	flag.StringVar(&fn, "fn", "", "Filename")
	flag.StringVar(&cpuprof, "cpuprofile", "", "CPU Filename")
	flag.Parse()

	if fn == "" {
		log.Fatal(errors.New("A filename must be specified"))
	}

	if cpuprof != "" {
		fp, err := os.Create(cpuprof)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(fp)
		defer pprof.StopCPUProfile()
	}

	p, err := mesh.ReadParticles(fn, subsample)
	fmt.Println("Read in Particles")
	if err != nil {
		log.Fatal(err)
	}

	t1 := time.Now()
	cc := twopt.NewSMuPairCounter(5, 5, maxs)
	cc.Count(p, p, 1.0)
	dt := time.Since(t1)

	fmt.Println(dt)

}
Beispiel #2
0
func main() {

	// Define the input parameters
	var (
		nworkers            int
		meshsize, subsample float64
		Dfn, Rfn, cpuprof   string
		Ns, Nmu             int
		maxs                float64
		outprefix           string
		help                bool
		noRR                bool
	)

	// Basic flags
	flag.BoolVar(&help, "help", false, "Prints the help message and quits")
	flag.BoolVar(&noRR, "noRR", false, "Don't do the RR calculation")
	flag.StringVar(&Dfn, "dfn", "", "D filename")
	flag.StringVar(&Rfn, "rfn", "", "D filename")
	flag.StringVar(&outprefix, "outprefix", "", "Output prefix")
	flag.IntVar(&Ns, "ns", 100, "Number of s bins")
	flag.IntVar(&Nmu, "nmu", 100, "Number of mu bins")
	flag.Float64Var(&maxs, "maxs", 200, "Maximum s value")
	// Tuning flags
	flag.IntVar(&nworkers, "nworkers", 1, "Number of workers")
	flag.Float64Var(&meshsize, "meshsize", -1, "Mesh size (defaults to maxs*1.01/2 if -ve)")
	flag.Float64Var(&subsample, "subsample", 1.01, "Subsampling fraction")
	flag.StringVar(&cpuprof, "cpuprofile", "", "CPU Filename")
	flag.Parse()
	if help {
		flag.Usage()
		os.Exit(0)
	}
	if Dfn == "" {
		log.Fatal(errors.New("A data filename must be specified"))
	}
	if Rfn == "" {
		log.Fatal(errors.New("A random filename must be specified"))
	}
	if outprefix == "" {
		log.Fatal(errors.New("An output prefix must be specified"))
	}
	if meshsize < 0 {
		meshsize = maxs * 1.01 / 2
	}

	// Read in the particle data
	pD, err := mesh.ReadParticles(Dfn, subsample)
	boxDmin, boxDmax := pD.MinMax()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Data read in from %s \n", Dfn)
	pR, err := mesh.ReadParticles(Rfn, subsample)
	boxRmin, boxRmax := pR.MinMax()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Data read in from %s \n", Rfn)

	// Set up meshes
	boxmin := boxRmin.Min(boxDmin)
	boxmax := boxRmax.Max(boxDmax)
	mD := mesh.New(pD, meshsize, boxmin, boxmax)
	mR := mesh.New(pR, meshsize, boxmin, boxmax)
	fmt.Println("Meshes created....")

	// Set up profiling if desired
	if cpuprof != "" {
		fp, err := os.Create(cpuprof)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(fp)
		defer pprof.StopCPUProfile()
	}

	fmt.Println("Using nworkers=", nworkers)
	// Do DD, DR, RR
	fmt.Println("Starting DD....")
	doOne(mD, mD, outprefix+"-DD.dat", Nmu, Ns, maxs, true, nworkers)
	fmt.Println("Starting DR....")
	doOne(mD, mR, outprefix+"-DR.dat", Nmu, Ns, maxs, false, nworkers)
	if !noRR {
		fmt.Println("Starting RR....")
		doOne(mR, mR, outprefix+"-RR.dat", Nmu, Ns, maxs, true, nworkers)
	}

	// Print the auxiliary file
	fout, err := os.Create(outprefix + "-norm.dat")
	if err != nil {
		log.Fatal(err)
	}
	defer fout.Close()
	fmt.Fprintln(fout, "# Sum of weights in input files")
	fmt.Fprintf(fout, "%s: %20.15e\n", Dfn, sumOfWeights(mD))
	fmt.Fprintf(fout, "%s: %20.15e\n", Rfn, sumOfWeights(mR))

}