def w_theta(data,rand,bins): ra=data['ra'] dec=data['dec'] rar=rand['ra'] decr=rand['dec'] nbins = len(bins)-1 DD_counts = DDtheta_mocks(autocorr=1, nthreads=2, binfile=bins, RA1=ra, DEC1=dec) DR_counts = DDtheta_mocks(autocorr=0, nthreads=2, binfile=bins, RA1=ra, DEC1=dec, RA2=rar, DEC2=decr) #RR_counts = DDtheta_mocks(autocorr=1, nthreads=2, binfile=bins, RA1=rar, DEC1=decr) N=len(data) N_rand=len(rand) cf = np.zeros(nbins) cf[:] = np.nan DR = DR_counts['npairs'] / (N*N_rand) DD = DD_counts['npairs'] / (N*(N-1)) th = DD_counts['thetamax'] nonzero = DR > 0 cf[nonzero] = (DD[nonzero] / DR[nonzero] ) - 1. return th,cf
def benchmark_mocks_threads_all(numpart_frac=[ 0.001, 0.005, 0.01, 0.05, 0.1, 0.2, 0.25, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 ], nrepeats=3, keys=None, isa=None): from Corrfunc.mocks import DDrppi_mocks, DDtheta_mocks allkeys = [ #'DDrppi (DD)', #'DDtheta (DD)', 'DDrppi (DR)', 'DDtheta (DR)' ] allisa = ['avx512f', 'avx', 'sse42', 'fallback'] if keys is None: keys = allkeys else: for k in keys: if k not in allkeys: msg = "Valid routines to benchmark are: {0}\nFound routine"\ " = {1}".format(allkeys, k) raise ValueError(msg) if isa is None: isa = allisa else: for i in isa: if i not in allisa: msg = "Valid instructions sets benchmark are: {0}\n"\ "Found routine = {1}".format(allisa, i) raise ValueError(msg) print("Benchmarking mocks routines = {0} with isa = {1}".format(keys, isa)) mocks_file = pjoin(dirname(abspath(Corrfunc.__file__)), "../mocks/tests/data", "Mr19_mock_northonly.rdcz.ff") allra, alldec, allcz = read_catalog(mocks_file) rand_file = pjoin(dirname(abspath(Corrfunc.__file__)), "../mocks/tests/data", "Mr19_randoms_northonly.rdcz.ff") allrand_ra, allrand_dec, allrand_cz = read_catalog(rand_file) cosmology = 1 rmin = 0.1 rmax = 84.0 angmax = 10.0 nbins = 20 rbins = np.logspace(np.log10(rmin), np.log10(rmax), nbins) # set to rmax for easier handling of # scaling with number of particles pimax = rmax angbins = np.logspace(np.log10(rmin), np.log10(angmax), nbins) nthreads = max_threads dtype = np.dtype([('repeat', np.int), ('name', 'U16'), ('isa', 'U16'), ('rmax', np.float), ('ndata', np.int), ('nrand', np.int), ('nthreads', np.int), ('runtime', np.float), ('serial_time', np.float), ('pair_time', np.float), ('api_time', np.float)]) totN = len(numpart_frac) * len(keys) * len(isa) * nrepeats runtimes = np.empty(totN, dtype=dtype) runtimes['nthreads'][:] = nthreads runtimes['rmax'][:] = rmax index = 0 stderr_filename = 'stderr.txt' for run_isa in isa: for frac in numpart_frac: npts = np.int(frac * len(allra)) npts_rand = np.int(frac * len(allrand_ra)) print("Working with (N, nrand) = {0} {1}".format(npts, npts_rand), file=sys.stderr) ra = np.random.choice(allra, npts, replace=False) dec = np.random.choice(alldec, npts, replace=False) cz = np.random.choice(allcz, npts, replace=False) rand_ra = np.random.choice(allrand_ra, npts_rand, replace=False) rand_dec = np.random.choice(allrand_dec, npts_rand, replace=False) rand_cz = np.random.choice(allrand_cz, npts_rand, replace=False) start_thread_index = index if 'DDtheta (DD)' in keys: for repeat in range(nrepeats): runtimes['repeat'][index] = repeat with stderr_redirected(to=stderr_filename): autocorr = 1 t0 = time.time() _, api_time = DDtheta_mocks(autocorr, nthreads, angbins, ra, dec, verbose=True, c_api_timer=True, isa=run_isa) t1 = time.time() runtimes['name'][index] = 'DDtheta (DD)' runtimes['isa'][index] = run_isa runtimes['ndata'][index] = npts runtimes['nrand'][index] = npts runtimes['nthreads'][index] = nthreads runtimes['runtime'][index] = t1 - t0 serial_time, pair_time = _get_times(stderr_filename) runtimes['serial_time'][index] = serial_time runtimes['pair_time'][index] = pair_time runtimes['api_time'][index] = api_time index += 1 if 'DDtheta (DR)' in keys: for repeat in range(nrepeats): runtimes['repeat'][index] = repeat with stderr_redirected(to=stderr_filename): autocorr = 0 t0 = time.time() _, api_time = DDtheta_mocks(autocorr, nthreads, angbins, ra, dec, RA2=rand_ra, DEC2=rand_dec, verbose=True, c_api_timer=True, isa=run_isa) t1 = time.time() runtimes['name'][index] = 'DDtheta (DR)' runtimes['isa'][index] = run_isa runtimes['ndata'][index] = npts runtimes['nrand'][index] = npts_rand runtimes['nthreads'][index] = nthreads runtimes['runtime'][index] = t1 - t0 serial_time, pair_time = _get_times(stderr_filename) runtimes['serial_time'][index] = serial_time runtimes['pair_time'][index] = pair_time runtimes['api_time'][index] = api_time index += 1 if 'DDrppi (DD)' in keys: for repeat in range(nrepeats): runtimes['repeat'][index] = repeat with stderr_redirected(to=stderr_filename): autocorr = 1 t0 = time.time() _, api_time = DDrppi_mocks(autocorr, cosmology, nthreads, pimax, rbins, ra, dec, cz, verbose=True, c_api_timer=True, isa=run_isa) t1 = time.time() runtimes['name'][index] = 'DDrppi (DD)' runtimes['isa'][index] = run_isa runtimes['ndata'][index] = npts runtimes['nrand'][index] = npts runtimes['nthreads'][index] = nthreads runtimes['runtime'][index] = t1 - t0 serial_time, pair_time = _get_times(stderr_filename) runtimes['serial_time'][index] = serial_time runtimes['pair_time'][index] = pair_time runtimes['api_time'][index] = api_time index += 1 if 'DDrppi (DR)' in keys: for repeat in range(nrepeats): runtimes['repeat'][index] = repeat with stderr_redirected(to=stderr_filename): autocorr = 0 t0 = time.time() _, api_time = DDrppi_mocks(autocorr, cosmology, nthreads, pimax, rbins, ra, dec, cz, RA2=rand_ra, DEC2=rand_dec, CZ2=rand_cz, verbose=True, c_api_timer=True, isa=run_isa) t1 = time.time() runtimes['name'][index] = 'DDrppi (DR)' runtimes['isa'][index] = run_isa runtimes['ndata'][index] = npts runtimes['nrand'][index] = npts_rand runtimes['nthreads'][index] = nthreads runtimes['runtime'][index] = t1 - t0 serial_time, pair_time = _get_times(stderr_filename) runtimes['serial_time'][index] = serial_time runtimes['pair_time'][index] = pair_time runtimes['api_time'][index] = api_time index += 1 print("{0}".format(runtimes[start_thread_index:index])) sys.stdout.flush() print("index = {0} totN = {1}".format(index, totN)) return keys, isa, runtimes
def benchmark_mocks_threads_all(rmax_array=[10.0, 20.0, 40.0, 80.0, 100.0], thetamax_array=[2., 4., 8., 16., 20.], nrepeats=1, keys=None, isa=None): from Corrfunc.mocks import DDrppi_mocks, DDtheta_mocks allkeys = [ #'DDrppi (DD)', #'DDtheta (DD)', 'DDrppi (DR)', 'DDtheta (DR)' ] allisa = ['avx512f', 'avx', 'sse42', 'fallback'] if keys is None: keys = allkeys else: for k in keys: if k not in allkeys: msg = "Valid routines to benchmark are: {0}\nFound routine"\ " = {1}".format(allkeys, k) raise ValueError(msg) if isa is None: isa = allisa else: for i in isa: if i not in allisa: msg = "Valid instructions sets benchmark are: {0}\n"\ "Found routine = {1}".format(allisa, i) raise ValueError(msg) rmax_array = np.array(rmax_array) thetamax_array = np.array(thetamax_array) print("Benchmarking mocks routines = {0} with isa = {1}".format(keys, isa)) mocks_file = pjoin(dirname(abspath(Corrfunc.__file__)), "../mocks/tests/data", "Mr19_mock_northonly.rdcz.ff") ra, dec, cz = read_catalog(mocks_file) rand_file = pjoin(dirname(abspath(Corrfunc.__file__)), "../mocks/tests/data", "Mr19_randoms_northonly.rdcz.ff") rand_ra, rand_dec, rand_cz = read_catalog(rand_file) cosmology = 1 rmin = 0.1 nbins = 20 nthreads = max_threads dtype = np.dtype([('repeat', np.int), ('name', 'U16'), ('isa', 'U16'), ('rmax', np.float), ('nthreads', np.int), ('runtime', np.float), ('serial_time', np.float), ('pair_time', np.float), ('api_time', np.float)]) totN = len(rmax_array) * len(keys) * len(isa) * nrepeats runtimes = np.empty(totN, dtype=dtype) index = 0 stderr_filename = 'stderr.txt' for run_isa in isa: for thetamax, rmax in zip(thetamax_array, rmax_array): rbins = np.logspace(np.log10(rmin), np.log10(rmax), nbins) thetabins = np.logspace(np.log10(rmin), np.log10(thetamax), nbins) pimax = rmax # Set to rmax for comparisons between wp and xi print("Working on rmax = {0}".format(rmax), file=sys.stderr) start_thread_index = index if 'DDtheta (DD)' in keys: for repeat in range(nrepeats): runtimes['repeat'][index] = repeat with stderr_redirected(to=stderr_filename): autocorr = 1 t0 = time.time() _, api_time = DDtheta_mocks(autocorr, nthreads, thetabins, ra, dec, verbose=True, c_api_timer=True, isa=run_isa) t1 = time.time() runtimes['name'][index] = 'DDtheta (DD)' runtimes['isa'][index] = run_isa runtimes['rmax'][index] = thetamax runtimes['nthreads'][index] = nthreads runtimes['runtime'][index] = t1 - t0 serial_time, pair_time = _get_times(stderr_filename) runtimes['serial_time'][index] = serial_time runtimes['pair_time'][index] = pair_time runtimes['api_time'][index] = api_time index += 1 if 'DDtheta (DR)' in keys: for repeat in range(nrepeats): runtimes['repeat'][index] = repeat with stderr_redirected(to=stderr_filename): autocorr = 0 t0 = time.time() _, api_time = DDtheta_mocks(autocorr, nthreads, thetabins, ra, dec, RA2=rand_ra, DEC2=rand_dec, verbose=True, c_api_timer=True, isa=run_isa) t1 = time.time() runtimes['name'][index] = 'DDtheta (DR)' runtimes['isa'][index] = run_isa runtimes['rmax'][index] = thetamax runtimes['nthreads'][index] = nthreads runtimes['runtime'][index] = t1 - t0 serial_time, pair_time = _get_times(stderr_filename) runtimes['serial_time'][index] = serial_time runtimes['pair_time'][index] = pair_time runtimes['api_time'][index] = api_time index += 1 if 'DDrppi (DD)' in keys: for repeat in range(nrepeats): runtimes['repeat'][index] = repeat with stderr_redirected(to=stderr_filename): autocorr = 1 t0 = time.time() _, api_time = DDrppi_mocks(autocorr, cosmology, nthreads, pimax, rbins, ra, dec, cz, verbose=True, c_api_timer=True, isa=run_isa) t1 = time.time() runtimes['name'][index] = 'DDrppi (DD)' runtimes['isa'][index] = run_isa runtimes['rmax'][index] = rmax runtimes['nthreads'][index] = nthreads runtimes['runtime'][index] = t1 - t0 serial_time, pair_time = _get_times(stderr_filename) runtimes['serial_time'][index] = serial_time runtimes['pair_time'][index] = pair_time runtimes['api_time'][index] = api_time index += 1 if 'DDrppi (DR)' in keys: for repeat in range(nrepeats): runtimes['repeat'][index] = repeat with stderr_redirected(to=stderr_filename): autocorr = 0 t0 = time.time() _, api_time = DDrppi_mocks(autocorr, cosmology, nthreads, pimax, rbins, ra, dec, cz, RA2=rand_ra, DEC2=rand_dec, CZ2=rand_cz, verbose=True, c_api_timer=True, isa=run_isa) t1 = time.time() runtimes['name'][index] = 'DDrppi (DR)' runtimes['isa'][index] = run_isa runtimes['rmax'][index] = rmax runtimes['nthreads'][index] = nthreads runtimes['runtime'][index] = t1 - t0 serial_time, pair_time = _get_times(stderr_filename) runtimes['serial_time'][index] = serial_time runtimes['pair_time'][index] = pair_time runtimes['api_time'][index] = api_time index += 1 print("{0}".format(runtimes[start_thread_index:index])) sys.stdout.flush() print("index = {0} totN = {1}".format(index, totN)) return keys, isa, runtimes