The TEMPLATE directive declares one or more templates, specifying for each the name, the rank (number of dimensions), and the extent in each dimension. It must appear in the specification-part of a scoping unit.
In the language of F95:14.1.2 in the Fortran standard, templates are local entities of class (1); therefore a template may not have the same name as a variable, named constant, internal procedure, etc., in the same scoping unit. Template names obey the rules for host and use association as other names in the list in F95:18.104.22.168.1 in the Fortran standard.
A template declared in a module has the default accessibility of the module.
A template is simply an abstract space of indexed positions; it can be considered as an ``array of nothings'' (as compared to an ``array of integers,'' say). A template may be used as an abstract align-target that may then be distributed.
H331 template-directive is TEMPLATE template-decl-list H332 template-decl is template-name [ ( explicit-shape-spec-list ) ]
!HPF$ TEMPLATE A(N) !HPF$ TEMPLATE B(N,N), C(N,2*N) !HPF$ TEMPLATE DOPEY(100,100),SNEEZY(24),GRUMPY(17,3,5)
If the "::" syntax is used, then the declared templates may optionally be distributed in the same combined-directive. In this case all templates declared by the directive must have the same rank so that the DISTRIBUTE attribute will be meaningful. The DIMENSION attribute may also be used.
!HPF$ TEMPLATE, DISTRIBUTE(BLOCK,*) :: & !HPF$ WHINEY(64,64),MOPEY(128,128) !HPF$ TEMPLATE, DIMENSION(91,91) :: BORED,WHEEZY,PERKY
Templates are useful in the particular situation where one must align several arrays relative to one another but there is no need to declare a single array that spans the entire index space of interest. For example, one might want four arrays aligned to the four corners of a template of size (N+1)x(N+1):
!HPF$ TEMPLATE, DISTRIBUTE(BLOCK, BLOCK) :: EARTH(N+1,N+1) REAL, DIMENSION(N,N) :: NW, NE, SW, SE !HPF$ ALIGN NW(I,J) WITH EARTH( I , J ) !HPF$ ALIGN NE(I,J) WITH EARTH( I ,J+1) !HPF$ ALIGN SW(I,J) WITH EARTH(I+1, J ) !HPF$ ALIGN SE(I,J) WITH EARTH(I+1,J+1)
Templates may also be useful in making assertions about the mapping of dummy arguments (see Section 4).
Unlike arrays, templates cannot be in COMMON. So two templates declared in different scoping units will always be distinct, even if they are given the same name. The only way for two program units to refer to the same template is to declare the template in a module that is then used by the two program units.
Templates are not passed through the subprogram argument interface. The template to which a dummy argument is aligned is always distinct from the template to which the actual argument is aligned, though it may be a copy (see section 4.4.2). On exit from a subprogram, an HPF implementation arranges that the actual argument is aligned with the same template with which it was aligned before the call.
Returning from a subprogram causes all templates declared local to that subprogram to become undefined. It is not HPF-conforming for any variable to be aligned to a template at the time the template becomes undefined unless at least one of two conditions holds:
Variables in COMMON or having the SAVE attribute may be mapped to a locally declared template, but because the first condition cannot hold for such variable (they don't become undefined), the second condition must be observed.