def info(): """Print date and version information as a html-table.""" # Define styles style1 = " style='border: 2px solid #fff; text-align: left;'" style2 = " style='background-color: #ccc;" style2 += "width: 10%; border: 2px solid #fff;'" # Print date and time info as title html = "<h3>%s</h3>" % time.strftime('%a %b %d %H:%M:%S %Y %Z') # Start table html += '<table>' # empymod, OS, threads, IPython html += "<tr" + style1 + ">" html += "<td" + style2 + ">%s</td>" % empymod.__version__ html += "<td" + style1 + ">empymod</td>" html += "<td" + style2 + ">%s</td>" % platform.system() html += "<td" + style1 + ">OS</td>" html += "<td" + style2 + ">%s</td>" % numexpr.detect_number_of_threads() html += "<td" + style1 + ">CPU(s)</td>" html += "<td" + style2 + ">%s</td>" % IPython.__version__ html += "<td" + style1 + ">IPython</td>" html += "</tr>" # numpy, scipy, numexpr, matplotlib html += "<tr" + style1 + ">" html += "<td" + style2 + ">%s</td>" % numpy.__version__ html += "<td" + style1 + ">numpy</td>" html += "<td" + style2 + ">%s</td>" % scipy.__version__ html += "<td" + style1 + ">scipy</td>" html += "<td" + style2 + ">%s</td>" % numexpr.__version__ html += "<td" + style1 + ">numexpr</td>" html += "<td" + style2 + ">%s</td>" % matplotlib.__version__ html += "<td" + style1 + ">matplotlib</td>" html += "</tr>" # sys.version html += "<tr" + style1 + ">" html += "<td" + style1 + " colspan='8'>%s</td>" % sys.version html += "</tr>" # vml version html += "<tr" + style2 + ">" html += "<td" + style2 + " colspan='8'>%s</td>" % numexpr.get_vml_version() html += "</tr>" # Finish table html += "</table>" return HTML(html)
def test_omp_num_threads(self): with _environment('OMP_NUM_THREADS', '5'): self.assertEquals(5, numexpr.detect_number_of_threads())
def __init__(self, xsrc, ysrc, sch1, sch2, **kwargs): """Kappa analysis of a shear map. :param list xsrc: x coordinates :param list xsrc: y coordinates :param list sch1: schear 1 :param list sch2: schear 2 :param list filt: filter to apply Possible kwargs: :param int step: Step of the grid :param float rinner: Inner cut in pixel :param float router: Outer cut in pixel :param float theta0: Maturi outer cut in pixel :param float aprad: Aperture mass outer cut in pixel """ assert len(xsrc) == len(ysrc) == len(sch1) == len(sch2) # numba? self.use_numba = kwargs.get("numba", False) and 'numba' in sys.modules # numexpr? self.use_numexpr = kwargs.get("numexpr", False) and 'numexpr' in sys.modules if self.use_numba: for func in to_jit: apply_decorator(func, numba.jit) for func in to_vectorize: apply_decorator(func, numba.vectorize) elif self.use_numexpr: numexpr.set_num_threads(numexpr.detect_number_of_threads()) # Make sure all list are actually numpy arrays xsrc, ysrc, sch1, sch2 = [np.array(x.tolist()) for x in [ xsrc, ysrc, sch1, sch2]] # Do we have to filter? if kwargs.get('filt', None) is not None: assert len(kwargs['filt']) == len(xsrc) self._idata = {'xsrc': xsrc, 'ysrc': ysrc, 'sch1': sch1, 'sch2': sch2, 'flag': np.array(kwargs.get('filt'))} print("Filtering data") print(" - Before cut: %i sources" % len(xsrc)) xsrc, ysrc, sch1, sch2 = [arr[np.array(kwargs.get('filt'))] for arr in [xsrc, ysrc, sch1, sch2]] print(" - After cut: %i sources" % len(xsrc)) self.filtered = True else: self._idata = None self.filtered = False # Save the data self.data = {'xsrc': xsrc, 'ysrc': ysrc, 'sch1': sch1, 'sch2': sch2} # Get or compute some useful parameters self.parameters = { # size of the image 'sizex': max(xsrc) - min(xsrc), 'sizey': max(ysrc) - min(ysrc), # step, useful for test purpose 'step': kwargs.get('step', 1), # number of points for each axis 'nxpoints': int((max(xsrc) - min(xsrc)) / kwargs.get('step', 1)), 'nypoints': int((max(ysrc) - min(ysrc)) / kwargs.get('step', 1)), # inner and outer radius 'rinner': kwargs.get('rinner', 500.0), 'router': kwargs.get('router', 8000.0), # maximum radius 'rmax': np.sqrt((max(xsrc) - min(xsrc))**2 + (max(ysrc) - min(ysrc))**2), 'theta0': kwargs.get('theta0', 6000.0), 'aprad': kwargs.get('aprad', 6000.0) } # Define needed dictionnary self.maps = self.weights = {} # Get the weights and the maps self._get_weights() self._get_kappa(xsampling=kwargs.get('xsampling', 10)) self.save_maps()
def test_numexpr_num_threads(self): with _environment("OMP_NUM_THREADS", "5"): with _environment("NUMEXPR_NUM_THREADS", "3"): self.assertEquals(3, numexpr.detect_number_of_threads())
def test_numexpr_num_threads(self): with _environment('OMP_NUM_THREADS', '5'): with _environment('NUMEXPR_NUM_THREADS', '3'): self.assertEqual(3, numexpr.detect_number_of_threads())
from math import nan matplotlib.use('Agg') from matplotlib import pyplot #from VTKWrapper import saveToVTK import os from timeit import default_timer as timer #from numba import jit from functions import sumf, equ, ucprod, copyfunc, allfunc from functions import set_omega from concurrent.futures import ThreadPoolExecutor tstart = timer() from numpy import * #os.system("taskset -p 0xff %d" % os.getpid()) #print('number of cores detected is '); print(ne.detect_number_of_threads()) ne.set_num_threads(ne.detect_number_of_threads()) # Plot Settings Pinterval = 1000 # iterations to print next output SavePlot = False #save plots SaveVTK = False # save files in vtk format project = 'ldc' #for naming output files OutputFolder = './output' CurrentFolder = os.getcwd() # Lattice Parameters maxIt = 3000 # time iterations Re = 1000.0 # Reynolds number 100 400 1000 3200 5000 7500 10000 #Number of cells xsize, ysize = 320, 320
def good_process_number(total_cores, numexpr=True): if numexpr: thread_num = ne.detect_number_of_threads() else: thread_num = 1 return max(1, total_cores // thread_num)