diff --git a/cpu/kernelcreation.py b/cpu/kernelcreation.py index 9bfd1ea9e69b035d1ad7e07f921807f6e757b425..cbea79d7daa20bb7012e3a4b0851a90d88510afe 100644 --- a/cpu/kernelcreation.py +++ b/cpu/kernelcreation.py @@ -62,12 +62,13 @@ def createKernel(listOfEquations, functionName="kernel", typeForSymbol=None, spl return code -def addOpenMP(astNode, schedule="static"): +def addOpenMP(astNode, schedule="static", numThreads=None): """ Parallelizes the outer loop with OpenMP :param astNode: abstract syntax tree created e.g. by :func:`createKernel` :param schedule: OpenMP scheduling policy e.g. 'static' or 'dynamic' + :param numThreads: explicitly specify number of threads """ assert type(astNode) is ast.KernelFunction body = astNode.body @@ -77,4 +78,5 @@ def addOpenMP(astNode, schedule="static"): outerLoops = [l for l in body.atoms(ast.LoopOverCoordinate) if l.isOutermostLoop] assert outerLoops, "No outer loop found" assert len(outerLoops) <= 1, "More than one outer loop found. Which one should be parallelized?" - outerLoops[0].prefixLines.append("#pragma omp for schedule(%s)" % (schedule,)) + threadsClause = "" if numThreads is None else " num_threads(%s)" % (numThreads,) + outerLoops[0].prefixLines.append("#pragma omp for schedule(%s)%s" % (schedule,threadsClause)) diff --git a/field.py b/field.py index 4c58d322d35c8f3c7920eaeaa97809e04764ee44..12c9be76eb917bb53867de2c47426c4aab7c5282 100644 --- a/field.py +++ b/field.py @@ -83,7 +83,7 @@ class Field: over dimension 0 """ if not layout: - layout = tuple(reversed(range(spatialDimensions))) + layout = tuple(range(spatialDimensions)) if len(layout) != spatialDimensions: raise ValueError("Layout") shapeSymbol = IndexedBase(TypedSymbol(Field.SHAPE_PREFIX + fieldName, Field.SHAPE_DTYPE), shape=(1,))