Example #1
0
def compute_computer_output(program: Program, noun: int, verb: int) -> int:
    initial_state = program.copy()
    initial_state[1] = noun
    initial_state[2] = verb
    cmp = Computer(initial_state, None, None)
    cmp.run_until_stop()
    return cmp._state[0]
Example #2
0
from util import Program

ITER_LIMITS = [1, 2, 3, 4]  # [100, 1000, 10000, 100000]
ITER_LIMITS_AMOUNT = len(ITER_LIMITS)

TRIALS_AMOUNT = 3
WAIT_TIME = 1

PROCESSORS_AMOUNTS = [1, 2, 4, 8]
PROCESSORS_AMOUNTS_AMOUNT = len(PROCESSORS_AMOUNTS)

CODE_DIR = '../code/'

SEQUENTIAL_PROGRAM = Program(
    name='sequential',
    command=f'{os.path.join(CODE_DIR, "mandelbrot_sequential/build/mandelbrot_sequential")} {{iter_limit}}',
    index=0
)

OMP_SCHEDULES = ('static', 'dynamic', 'guided')

PARALLEL_PROGRAMS = [
    Program(
        name='MPI (send-recv)',
        command='lamboot -b -H && '
                f'mpirun -np {{p}} '
                f'{os.path.join(CODE_DIR, "mandelbrot_mpi_send_recv/build/mandelbrot_mpi_send_recv {iter_limit}")} && '
                'lamhalt -H',
        index=1
    ),
    Program(
Example #3
0
 def p_program_single(self, p):
     'program : section'
     self.program = Program(p[1])
     print 'p_program: %s' % list(p)
Example #4
0
class Parser():

    def  __init__(self):
        self.lexer = lex.lex(module=self)
        self.parser = yacc.yacc(module=self)

        self.sections = {}

    tokens = (
        'HEX',
        'NUMBER',
        'FLOAT',
        'LPAR',
        'RPAR',
        'WORD',
        'STRING',
        'POINTER',
        'REG',
    #    'QUOT',
        'COLON',
        'INDENT',
        'SPACE',
        'COMMA',
        'NEWLINE',
    )

    t_LPAR = r'\('
    t_RPAR = r'\)'
    t_POINTER = r'&'

    @lex.Token(r'r\d')
    def t_REG(self, t):
        t.value = Register(int(t.value[1]))
        return t
    
    t_STRING = r'"[\w\.\?' + "'" + '\s,\\\\n]+"'
    t_WORD = r'[\w\.\?]+'
#    t_QUOT = '"'
    t_COLON = ':'
    t_INDENT = r'\t+'
    t_COMMA = ','
    t_NEWLINE = r'\n'

    t_ignore = ''

    @lex.Token(r'0x[abcdef\d]+')
    def t_HEX(self, t):
        t.value = int(t.value[2:], 16)
        return t

    @lex.Token(r'\d+\.\d+')
    def t_FLOAT(self, t):
        t.value = float(t.value)
        return t

    @lex.Token(r'\d+')
    def t_NUMBER(self, t):
        t.value = int(t.value)
        return t

    @lex.Token(r'[ ]+')
    def t_SPACE(self, t):
        t.value = ' '
        return t

    def t_error(self, t):
        raise TypeError('Error on %s' % t.value)

    def lex(self, text):
        self.lexer.input(text)
        return iter(self.lexer.token, None)

    def p_program_single(self, p):
        'program : section'
        self.program = Program(p[1])
        print 'p_program: %s' % list(p)

    def p_program(self, p):
        'program : program section'
        self.program.append(p[2])

    def p_section(self, p):
        'section : section_name section_block'
        p[0] = Section(p[1], *p[2])
        print 'p_section: %s' % list(p)

    def p_section_name(self, p):
        'section_name :  WORD COLON NEWLINE'
        print 'section_name: %s' % list(p)
        p[0] = p[1]

    def p_section_block_single(self, p):
        'section_block : section_line'
        p[0] = [p[1]]

        print 'section_block_single: %s' % list(p)

    def p_section_block(self, p):
       'section_block : section_block section_line'
       if isinstance(p[1], list):
           p[1].append(p[2])
           p[0] = p[1]
       else:
           p[0] = [p[1], p[2]]

       print 'section_block: %s' % list(p)

    def p_section_line(self, p):
        'section_line : INDENT statement NEWLINE'
        p[0] = p[2]
        print 'section_line: %s' % list(p)

    def p_statement(self, p):
        'statement : WORD SPACE args'
        p[0] = Command(p[1], *p[3])

        print 'p_statement: %s' % list(p)

    def p_statement_import(self, p):
        'statement : comma_list'
        p[0] = Imports(*p[1])
        print 'p_statement: %s' % list(p)

    def p_arg(self, p):
        """
        arg : NUMBER
        arg : HEX
        arg : STRING
        arg : WORD
        arg : call
        arg : string
        arg : REG
        arg : import
        """
        p[0] = [p[1]]
        print 'p_arg: %s' % list(p)

    def p_args_single(self, p):
        'args : arg'
        p[0] = p[1]

        print 'p_args: %s' % list(p)

    def p_args(self, p):
        'args : args SPACE arg'
        print 'DEBUG %s' % list(p)
        if isinstance(p[1], list):
            p[0] = p[1] + p[3]
        else:
            p[0] = [p[1]]+p[3]

        print 'p_args: %s' % list(p)

    def p_comma_list_s(self, p):
        'comma_list : arg'
        p[0] = p[1]

    def p_comma_list(self, p):
        'comma_list : comma_list COMMA SPACE arg'
        if isinstance(p[1], list):
            p[0] = p[1] + p[4]
        else:
            p[0] = [p[1]]+p[4]

        print 'p_comma_list: %s' % list(p)

    def p_import(self, p):
        'import : WORD COLON COLON WORD'
        p[0] = (p[1], p[4])
        print 'p_import: %s' % list(p)

#    def p_fill(self, p):
#        """
#        fill : WORD LPAR NUMBER RPAR
#        fill : WORD LPAR HEX RPAR
#        """

#        p[0] = {'type': 'fill', 'data': p[3]}

    def p_string(self, p):
        'string : STRING'
        p[0] = p[1]

        print 'p_string: %s' % list(p)

    def p_call(self, p):
        'call : WORD LPAR args RPAR'
        p[0] = FunctionCall(p[1], *p[3])

    def p_error(self, p):
        raise TypeError('Error on %s and %s, next: %s' % (p.value, p.type, yacc.token()))

    def parse(self, text):
        self.parser.parse(text)