#!/usr/bin/env python from __future__ import print_function, division import subprocess from os.path import splitext, split def run_fit(filename): head, tail = split(filename) root, ext = splitext(tail) output = root + '.hdf5' cmd = ["./fit", filename, "-o", output] subprocess.call(cmd) if __name__ == '__main__': import argparse from multiprocessing import Pool, cpu_count import signal import os parser = argparse.ArgumentParser("fit multiple zdab files") parser.add_argument("-j", "--jobs", type=int, default=None, help="number of jobs") parser.add_argument("filenames", nargs="+", help="zdab files") args = parser.parse_args() jobs = args.jobs if jobs is None: jobs = cpu_count() # see https://stackoverflow.com/questions/11312525/catch-ctrlc-sigint-and-exit-multiprocesses-gracefully-in-python handler = signal.signal(signal.SIGINT, signal.SIG_IGN) p = Pool(jobs) signal.signal(signal.SIGINT, handler) try: result = p.map_async(run_fit,args.filenames) result.get() except KeyboardInterrupt: print("ctrl-c caught. quitting...") p.terminate() os.killpg(os.getpgid(0),9) else: p.close() p.join() ='/cgit/chroma/log/src/random.h'>logtreecommitdiff
path: root/src/random.h
blob: b084c19e73cc84b465ccaa35e5cbfd42385718a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef __RANDOM_H__
#define __RANDOM_H__

#include <curand_kernel.h>

#include "physical_constants.h"

__device__ float uniform(curandState *s, const float &low, const float &high)
{
	return low + curand_uniform(s)*(high-low);
}

__device__ float3 uniform_sphere(curandState *s)
{
	float theta = uniform(s, 0.0f, 2*PI);
	float u = uniform(s, -1.0f, 1.0f);
	float c = sqrtf(1.0f-u*u);

	return make_float3(c*cosf(theta), c*sinf(theta), u);
}

extern "C"
{

__global__ void init_rng(int nthreads, curandState *s, unsigned long long seed, unsigned long long offset)
{
	int id = blockIdx.x*blockDim.x + threadIdx.x;

	if (id >= nthreads)
		return;

	curand_init(seed, id, offset, &s[id]);
}

__global__ void fill_uniform(int nthreads, curandState *s, float *a, float low, float high)
{
	int id = blockIdx.x*blockDim.x + threadIdx.x;

	if (id >= nthreads)
		return;

	a[id] = uniform(&s[id], low, high);

}

__global__ void fill_uniform_sphere(int nthreads, curandState *s, float3 *a)
{
	int id = blockIdx.x*blockDim.x + threadIdx.x;

	if (id >= nthreads)
		return;

	a[id] = uniform_sphere(&s[id]);
}

} // extern "c"

#endif