def run_ode( FORMULA, FUNCTIONS, INPUTS, inits, params, T , fs, inputs = None, decimate=1 ,variable_length = False, stochastic = False, Tterm = 0, gpu = False, nthreads = 4 , dtype = np.float32, debug = False,seed =None,threads_per_block=32 ): from gpuODE import ode, param_grid, funcs2code PARAMETERS = params.keys() odeRK4 = ode("ode") odeRK4.setup(FORMULA, PARAMETERS, INPUTS) Tt = T + Tterm dt = 1.0/np.array(fs) N = np.int32(Tt*fs) Nterm = np.int32(Tterm*fs) extra_funcs = funcs2code(FUNCTIONS, gpu = gpu) odeRK4.extra_func = extra_funcs odeRK4.generate_code(debug=debug, gpu = gpu,variable_length = variable_length, stochastic=stochastic, dtype = dtype) odeRK4.compile() if gpu==True: time, out = odeRK4.run(inits, param_grid(**params) , dt, decimate = decimate, inputs=inputs, N = N, Nterm = Nterm,seed = seed,threads_per_block=threads_per_block) return time, out else: import distributed_exploration as de import timeit from random import randint seed_off = 0 #Modifications are needed to change the seed on differnet threads def func(**args): seedr = seed + randint(0,10000) time,out = odeRK4.run(inits, args, dt ,decimate=decimate, inputs=inputs, N = N , Nterm = Nterm,seed = seedr) return time, out tic = timeit.default_timer() out0 = de.explore_thread(func, param_grid(**params) ,nthreads=nthreads) toc = timeit.default_timer() Nm = int(T*fs)/decimate M = len(out0) out = {} for j,k in enumerate(FORMULA.keys()): out[k] = np.zeros((Nm,M)) for i,o in enumerate(out0): for j,k in enumerate(FORMULA.keys()): out[k][:,i] = o['out'][1][k].T[0,:N] return toc-tic, out
M = 32 mu = np.linspace(-1,10,M) params = {'mu': mu} Tterm = 0 T = 100 + Tterm fs = 100 dt = 1/fs N = int(T*fs) Nterm = int(Tterm*fs) t = np.arange(N-Nterm)/fs pgrid = param_grid(**params) time, out = vdp.run(x0, pgrid ,dt, N = N, Nterm = Nterm) x = out['x'] print x.dtype pl.figure(56) pl.clf() pl.plot( x[:,-1] ,'o-',label="float32") vdp.generate_code(debug=False, stochastic = False, gpu = True, dtype = np.float64) vdp.compile() time, out = vdp.run(x0, pgrid ,dt, N = N, Nterm = Nterm) x = out['x']
T = T + Tterm dt = 1.0/float(fs) N = np.int32(T*fs) Nterm = np.int32(Tterm*fs).min() dtype = np.float32 variable_length = False extra_funcs = funcs2code(FUNCTION, gpu = gpu) odeRK4.extra_func = extra_funcs odeRK4.generate_code(debug=debug, gpu = gpu,variable_length = variable_length, stochastic=stochastic, dtype = dtype ) odeRK4.compile() if gpu==True: time, out = odeRK4.run(x0, param_grid(**params) , dt, decimate = decimate, inputs=inputs, N = N, Nterm = Nterm) w = out['w'] else: time,out = odeRK4.run(x0, param_grid(**params) , dt,decimate=decimate, inputs=inputs, N = N , Nterm = Nterm,seed = 1234) w = out['w'] # # #pl.figure()