Exemple #1
0
    def create_lock(self):
        from util import lazy_write_file
        from util import ashes_env

        str_ = ashes_env.render('irp_lock.f90', {'entity': sorted(self.d_entity)})
        filename = os.path.join(irpf90_t.irpdir, 'irp_locks.irp.F90')
        lazy_write_file(filename, str_)
Exemple #2
0
def create(modules, variables):
    # (Dict[str,Module]. Dict[str, Variable]) -> None
    '''Create the fortran90 finalize subroutine and the touched one'''

    main_modules_name = [m.name for m in modules.values() if m.is_main]

    d_template_finalize = {
        'id':
        irp_id,
        'use': [
            m.name for m in modules.values()
            if not m.is_main and m.has_irp_module
        ],
        'entity_array': [{
            'name': e.name,
            'name_root': e.same_as
        } for e in variables.values()
                         if e.fmodule not in main_modules_name and e.dim]
    }

    d_template_touch = {
        'do_debug':
        command_line.do_debug,
        'entity': [
            e.d_touche_template for e in variables.values()
            if e.fmodule not in main_modules_name and e.d_touche_template
        ]
    }
    import util
    str_out = util.ashes_env.render('touch.f90',
                                    d_template_touch) + util.ashes_env.render(
                                        'finalize.f90', d_template_finalize)

    filename = os.path.join(irpdir, 'irp_touches.irp.F90')
    util.lazy_write_file(filename, '%s\n' % util.remove_empy_lines(str_out))
Exemple #3
0
def run(d_entity, d_routine):

    for v in d_entity.values():
        do_print(v, d_entity)

    l_subs = d_routine.values()

    l_data_to_write = [("%s.l" % os.path.join(mandir, s.name),
                        do_print_subroutines(s)) for s in l_subs]

    def worker(l):
        filename, text = l
        lazy_write_file(filename, text)

    parmap(worker, l_data_to_write)

    tags = []

    for v in d_entity.keys():
        line = d_entity[v].prototype
        tags.append('%s\t%s\t%d\n' % (v, line.filename[0], line.i))

    for v in d_routine.keys():
        line = d_routine[v].prototype
        tags.append('%s\t%s\t%d\n' % (v, line.filename, line.i))

    lazy_write_file("tags", ''.join(sorted(tags)))

    l_data = [
        e for k, v in sorted(d_entity.items()) for e in do_print_short(v)
    ]
    str_ = '\n'.join(l_data)
    lazy_write_file(filename="irpf90_entities", text='%s\n' % str_)
Exemple #4
0
    def create_stack(self):
        from util import lazy_write_file
        from util import ashes_env

        str_ = ashes_env.render('irp_stack.f90', {
            'do_debug': command_line.do_debug,
            'do_openmp': command_line.do_openmp,
            'do_memory': command_line.do_memory
        })
        filename = os.path.join(irpf90_t.irpdir, 'irp_stack.irp.F90')
        lazy_write_file(filename, str_)
Exemple #5
0
    def write_modules(self):
        from irpf90_t import irpdir
        from util import lazy_write_file
        import os

        for m in self.d_module.values():
            # Module data
            if m.has_irp_module:
                filename = os.path.join(irpdir, '%s.irp.module.F90' % m.filename)
                text = '\n'.join(m.head)
                lazy_write_file(filename, '%s\n' % text)

            # Subroutines
            filename = os.path.join(irpdir, '%s.irp.F90' % m.filename)
            text = '\n'.join(m.header + m.generated_text + m.residual_text)
            lazy_write_file(filename, '%s\n' % text)
Exemple #6
0
    def __init__(self, l_dir=None, l_file=None):
        # (Iter, Iter) -> None

        # Create directories
        from itertools import ifilterfalse
        i_folder = ifilterfalse(os.path.exists, (irpf90_t.irpdir, irpf90_t.mandir))
        map(os.mkdir, i_folder)

        # List file

        l_dir = l_dir if l_dir else (command_line.include_dir + ['.'])
        l_not_dir = [d for d in l_dir if not (os.path.exists(d) and os.path.isdir(d))]
        if l_not_dir:
            logger.error('Try to include no existing directory: [%s]' % ','.join(l_not_dir))
            sys.exit(1)

        # Create folder in IRPDIR
        i_folder = ifilterfalse(os.path.exists, (os.path.join(irpf90_t.irpdir, d) for d in l_dir))
        map(os.mkdir, i_folder)

        s_folder_abs = set(os.path.abspath(path) for path in l_dir)

        s_file_folder_all = set(flatten(listdir(path, abspath=True) for path in s_folder_abs))

        # Take everything!
        s_file_folder = filter(lambda f: os.path.isfile(f) and not f.startswith("."),
                               s_file_folder_all)

        s_file_tot = set(l_file) if l_file else set()
        s_file_tot.update(s_file_folder)

        s_file_rel = set(os.path.relpath(f, self.cwd) for f in s_file_tot)

        # Lazy Copy file
        for f in s_file_rel:
            src = os.path.join(self.cwd, f)
            text_ref = open(src, 'rb').read()

            dest = os.path.join(self.cwd, irpf90_t.irpdir, f)
            lazy_write_file(dest, text_ref)

        if command_line.do_codelet:
            s_file_tot.update(command_line.codelet[3])

        # No filter the irpf90 file
        self.irpf90_files_ordered = sorted(filter(lambda f: f.endswith(".irp.f"), s_file_rel))
Exemple #7
0
def do_print(entity, d_entity):
    assert type(entity) == Entity
    filename = entity.prototype.filename[0]
    name = entity.name

    l_data = []

    l_data.append(
        '.TH "IRPF90 entities" l {0} "IRPF90 entities" {0}'.format(name))

    if entity.same_as != entity.name:
        entity = d_entity[entity.same_as]
    l_data.extend([".SH Declaration", ".nf"])
    l_data += process_types(entity, d_entity)

    l_data.append(".ni")

    if entity.doc:
        l_data.append(".SH Description")
        for l in entity.doc:
            l_data += process_doc(l)

    l_data.append(".SH File\n.P")
    l_data.append(filename)

    if entity.needs:
        l_data.append(".SH Needs")
        l_data += process_deps(entity.needs)

    if entity.needed_by:
        l_data.append(".SH Needed by")
        l_data += process_deps(entity.needed_by)

    l_data.append(".SH Instability factor")
    fo = len(entity.children)
    fi = len(entity.parents)
    l_data.append("%5.1f %%" % (100. * (fi / (fi + fo + .000001))))
    l_data.append(".br")
    str_ = '\n'.join(l_data)
    lazy_write_file("%s%s.l" % (mandir, name), '%s\n' % str_)
Exemple #8
0
def run():
    template = """
program codelet_%(name)s
  implicit none
  integer :: i
  double precision :: ticks_0, ticks_1, cpu_0, cpu_1
  integer, parameter :: irp_imax = %(NMAX)d

  %(precondition)s

  call provide_%(name)s

  double precision :: irp_rdtsc

  call cpu_time(cpu_0)
  ticks_0 = irp_rdtsc()
  do i=1,irp_imax
    call bld_%(name)s
  enddo
  ticks_1 = irp_rdtsc()
  call cpu_time(cpu_1)
  print *, '%(name)s'
  print *, '-----------'
  print *, 'Cycles:'
  print *,  (ticks_1-ticks_0)/dble(irp_imax)
  print *, 'Seconds:'
  print *,  (cpu_1-cpu_0)/dble(irp_imax)
end

  """

    name, NMAX, precondition, filename = command_line.codelet
    if precondition is None:
        precondition = ""
    else:
        precondition = "PROVIDE " + precondition

    from util import lazy_write_file
    lazy_write_file(filename, template % locals())
Exemple #9
0
 def worker(l):
     filename, text = l
     lazy_write_file(filename, text)