def gen_code(self, parent): if self.field_space == "every": from psyclone.f2pygen import DeclGen dim_var = DeclGen(parent, datatype="INTEGER", entity_decls=[self._variable_name]) parent.add(dim_var) # loop bounds self._start = "1" if self._loop_type == "inner": index = "1" elif self._loop_type == "outer": index = "2" self._stop = ("SIZE(" + self.field_name + ", " + index + ")") else: # one of our spaces so use values provided by the infrastructure # loop bounds if self._loop_type == "inner": self._start = self.field_space + "%istart" self._stop = self.field_space + "%istop" elif self._loop_type == "outer": self._start = self.field_space + "%jstart" self._stop = self.field_space + "%jstop" Loop.gen_code(self, parent)
def gen_code(self, parent): ''' Generate the Fortran source for this loop ''' # Our schedule holds the names to use for the loop bounds. # Climb up the tree looking for our enclosing Schedule schedule = self.ancestor(GOSchedule) if schedule is None or not isinstance(schedule, GOSchedule): raise GenerationError("Internal error: cannot find parent" " GOSchedule for this Do loop") # Walk down the tree looking for a kernel so that we can # look-up what index-offset convention we are to use go_kernels = self.walk(self.children, GOKern) if len(go_kernels) == 0: raise GenerationError("Internal error: cannot find the " "GOcean Kernel enclosed by this loop") index_offset = go_kernels[0].index_offset if schedule.const_loop_bounds and \ index_offset not in SUPPORTED_OFFSETS: raise GenerationError("Constant bounds generation" " not implemented for a grid offset " "of {0}. Supported offsets are {1}".format( index_offset, SUPPORTED_OFFSETS)) # Check that all kernels enclosed by this loop expect the same # grid offset for kernel in go_kernels: if kernel.index_offset != index_offset: raise GenerationError("All Kernels must expect the same " "grid offset but kernel {0} has offset " "{1} which does not match {2}".format( kernel.name, kernel.index_offset, index_offset)) # Generate the upper and lower loop bounds self._start = self._lower_bound() self._stop = self._upper_bound() Loop.gen_code(self, parent)
def gen_code(self, parent): ''' Work out the appropriate loop bounds and then call the base class to generate the code ''' self._start = "1" if self._loop_type == "colours": self._stop = "ncolour" elif self._loop_type == "colour": self._stop = "ncp_ncolour(colour)" else: self._stop = self.field_name + "%get_ncell()" Loop.gen_code(self, parent)
def gen_code(self, parent): ''' Work out the appropriate loop bounds and then call the base class to generate the code ''' self.start_expr = Literal("1", parent=self) if self._loop_type == "colours": self.stop_expr = Reference("ncolour", parent=self) elif self._loop_type == "colour": self.stop_expr = ArrayReference("ncp_ncolour", parent=self) self.stop_expr.addchild(Reference("colour"), parent=self.stop_expr) else: self.stop_expr = Reference(self.field_name + "%get_ncell()", parent=self) Loop.gen_code(self, parent)
def gen_code(self, parent): if self.field_space == "every": from psyclone.f2pygen import DeclGen from psyclone.psyGen import BinaryOperation, Reference dim_var = DeclGen(parent, datatype="INTEGER", entity_decls=[self._variable_name]) parent.add(dim_var) # Update start loop bound self.start_expr = Literal("1", parent=self) # Update stop loop bound if self._loop_type == "inner": index = "1" elif self._loop_type == "outer": index = "2" self.stop_expr = BinaryOperation(BinaryOperation.Operator.SIZE, parent=self) self.stop_expr.addchild(Reference(self.field_name, parent=self.stop_expr)) self.stop_expr.addchild(Literal(index, parent=self.stop_expr)) else: # one of our spaces so use values provided by the infrastructure # loop bounds # TODO: Issue 440. Implement derive types in PSyIR if self._loop_type == "inner": self.start_expr = Reference( self.field_space + "%istart", parent=self) self.stop_expr = Reference( self.field_space + "%istop", parent=self) elif self._loop_type == "outer": self.start_expr = Reference( self.field_space + "%jstart", parent=self) self.stop_expr = Reference( self.field_space + "%jstop", parent=self) Loop.gen_code(self, parent)
def gen_code(self, parent): if self.field_space == "every": from psyclone.f2pygen import DeclGen dim_var = DeclGen(parent, datatype="INTEGER", entity_decls=[self._variable_name]) parent.add(dim_var) # Update start loop bound self.start_expr = Literal("1", parent=self) # Update stop loop bound if self._loop_type == "inner": index = "1" elif self._loop_type == "outer": index = "2" # TODO: Issue 440. Implement SIZE intrinsic in PSyIR self.stop_expr = Literal("SIZE(" + self.field_name + "," + index + ")", parent=self) else: # one of our spaces so use values provided by the infrastructure # loop bounds # TODO: Issue 440. Implement derive types in PSyIR if self._loop_type == "inner": self.start_expr = Reference( self.field_space + "%istart", parent=self) self.stop_expr = Reference( self.field_space + "%istop", parent=self) elif self._loop_type == "outer": self.start_expr = Reference( self.field_space + "%jstart", parent=self) self.stop_expr = Reference( self.field_space + "%jstop", parent=self) Loop.gen_code(self, parent)