def profile_memsize_nthreads( executable, nthreads=[1, 2, 4], gridsize=np.arange(200, 800 + 1, 200), timecmd="time", nsteps=1000, fplu=7, double=False, verbose=False, showplot=False, figname="", ): """Record the time the execution of a programme takes""" NN = gridsize timefmt = "%e" # iterate over nthreads time = np.zeros((len(nthreads), len(NN))) for iN, N in enumerate(NN): executable_with_args = executable + " -n {0}".format(N) for inthr, OMP_NUM_THREADS in enumerate(nthreads): print "\nNow running on ", OMP_NUM_THREADS, " threads" # set environment variable os.environ["OMP_NUM_THREADS"] = str(OMP_NUM_THREADS) # get execution time time[inthr, iN] = timeomp.get_execution_time( executable_with_args, timecmd=timecmd, timefmt=timefmt, verbose=verbose )[0] # write data to file data = dict(nthreads=nthreads, time=time, NN=NN, nsteps=nsteps, fplu=fplu, double=double) with open("scaling_memsize_nthreads.pkl", "wb") as fout: pickle.dump(data, fout) # plot data if showplot or figname: plot.plot_flops_vs_memsize(savefig=bool(figname), figname=figname, **data)
def profile_nthreads(executable,nthreads=[],timecmd="time",timefmt="%e %U %S", labels=None,verbose=False,savefig=False): """Record the time the execution of a programme takes""" # iterate over nthreads times = np.zeros((len(nthreads),len(timefmt.split()))) for i,omp_num_threads in enumerate(nthreads): print '\nNow running on ',omp_num_threads,' threads' os.environ['OMP_NUM_THREADS'] = str(omp_num_threads) times[i,:] = timeomp.get_execution_time(executable,timecmd=timecmd, timefmt=timefmt,labels=labels, verbose=verbose) data = dict(nthreads=nthreads,times=times) # write output to file with open('scaling_nthreads.pkl','w') as fout: pickle.dump(data,fout) plot.plot_times_vs_nthread(labels=labels,**data)