@staticmethod
def gen_ocl_init(parent, kernels, num_queues):
    """
        Generates a subroutine to initialise the OpenCL environment and
        construct the list of OpenCL kernel objects used by this PSy layer.

        :param parent: the node in the f2pygen AST representing the module                        that will contain the generated subroutine.
        :type parent: :py:class:`psyclone.f2pygen.ModuleGen`
        :param kernels: List of kernel names called by the PSy layer.
        :type kernels: list of str
        :param int num_queues: total number of queues needed for the OpenCL                                implementation.
        """
    from psyclone.f2pygen import SubroutineGen, DeclGen, AssignGen, CallGen, UseGen, CommentGen, CharDeclGen, IfThenGen
    sub = SubroutineGen(parent, 'psy_init')
    parent.add(sub)
    sub.add(UseGen(sub, name='fortcl', only=True, funcnames=['ocl_env_init',
        'add_kernels']))
    sub.add(DeclGen(sub, datatype='logical', save=True, entity_decls=[
        'initialised'], initial_values=['.False.']))
    sub.add(CommentGen(sub,
        ' Check to make sure we only execute this routine once'))
    ifthen = IfThenGen(sub, '.not. initialised')
    sub.add(ifthen)
    ifthen.add(AssignGen(ifthen, lhs='initialised', rhs='.True.'))
    ifthen.add(CommentGen(ifthen, ' Initialise the OpenCL environment/device'))
    ifthen.add(CallGen(ifthen, 'ocl_env_init', [num_queues]))
    ifthen.add(CommentGen(ifthen,
        ' The kernels this PSy layer module requires'))
    nkernstr = str(len(kernels))
    ifthen.add(CharDeclGen(ifthen, length='30', entity_decls=[
        'kernel_names({0})'.format(nkernstr)]))
    for idx, kern in enumerate(kernels):
        ifthen.add(AssignGen(ifthen, lhs='kernel_names({0})'.format(idx + 1
            ), rhs='"{0}"'.format(kern)))
    ifthen.add(CommentGen(ifthen,
        ' Create the OpenCL kernel objects. Expects to find all of the compiled'
        ))
    ifthen.add(CommentGen(ifthen, ' kernels in PSYCLONE_KERNELS_FILE.'))
    ifthen.add(CallGen(ifthen, 'add_kernels', [nkernstr, 'kernel_names']))
