Esempio n. 1
0
 def visit_While(self, node):
     self.visit(node.test)
     for b in node.body:
         self.visit(b)
     if len(node.orelse) > 0:
         raise RuntimeError("Else clause in while clauses cannot be translated to C")
     body = c.Block([b.ccode for b in node.body])
     node.ccode = c.DoWhile(node.test.ccode, body)
Esempio n. 2
0
 c.DoWhile(
     't < tIntervals',
     c.Block([
         c.LineComment('Propagates the wave.'),
         c.Statement(
             'ops_par_loop(wavePropagation, "wave_propagation", wave_grid, 2, range,\n\
          ops_arg_dat(d_u_Next, 1, S2D_00, "double", OPS_RW),\n\
          ops_arg_dat(d_u_Current, 1, S2D_8TH, "double", OPS_READ),\n\
          ops_arg_dat(d_u_Previous, 1, S2D_00, "double", OPS_READ),\n\
          ops_arg_dat(d_velocity, 1, S2D_00, "double", OPS_READ),\n\
          ops_arg_dat(d_wx, 1, S2D_2PX, "double", OPS_READ),\n\
          ops_arg_dat(d_wy, 1, S2D_2PY, "double", OPS_READ),\n\
          ops_arg_dat(d_zetax, 1, S2D_00, "double", OPS_READ),\n\
          ops_arg_dat(d_zetay, 1, S2D_00, "double", OPS_READ),\n\
          ops_arg_idx())'),
         c.Line(),
         c.Assign('source_magnitude',
                  'source_field_factor * source[t]'),
         c.Line(),
         c.LineComment('Injects the source.'),
         c.Statement(
             'ops_par_loop(sourceInjection, "source_injection", wave_grid, 2, source_location_range,\n\
          ops_arg_dat(d_u_Next, 1, S2D_00, "double", OPS_WRITE),\n\
          ops_arg_gbl(&source_magnitude, 1, "double", OPS_READ))'),
         c.Line(),
         c.LineComment('Updates Omega X and Y'),
         c.Statement(
             'ops_par_loop(update_omega, "update_omega", wave_grid, 2, range_CPML,\n\
          ops_arg_dat(d_wx, 1, S2D_00, "double", OPS_RW),\n\
          ops_arg_dat(d_wy, 1, S2D_00, "double", OPS_RW),\n\
          ops_arg_dat(d_ax, 1, S2D_00_STRIDE_X, "double", OPS_READ),\n\
          ops_arg_dat(d_ay, 1, S2D_00_STRIDE_Y, "double", OPS_READ),\n\
          ops_arg_dat(d_bx, 1, S2D_00_STRIDE_X, "double", OPS_READ),\n\
          ops_arg_dat(d_by, 1, S2D_00_STRIDE_Y, "double", OPS_READ),\n\
          ops_arg_dat(d_u_Next, 1, S2D_4PT, "double", OPS_READ),\n\
          ops_arg_idx())'),
         c.Line(),
         c.LineComment(
             'ops_print_dat_to_txtfile(d_wx, "output/omegax-ops.txt");'
         ),
         c.Line(),
         c.LineComment('Updates Zeta X and Y'),
         c.Statement(
             'ops_par_loop(update_zeta, "update_zeta", wave_grid, 2, range_CPML,\n\
          ops_arg_dat(d_zetax, 1, S2D_00, "double", OPS_WRITE),\n\
          ops_arg_dat(d_zetay, 1, S2D_00, "double", OPS_WRITE),\n\
          ops_arg_dat(d_wx, 1, S2D_2PX, "double", OPS_READ),\n\
          ops_arg_dat(d_wy, 1, S2D_2PY, "double", OPS_READ),\n\
          ops_arg_dat(d_ax, 1, S2D_00_STRIDE_X, "double", OPS_READ),\n\
          ops_arg_dat(d_ay, 1, S2D_00_STRIDE_Y, "double", OPS_READ),\n\
          ops_arg_dat(d_bx, 1, S2D_00_STRIDE_X, "double", OPS_READ),\n\
          ops_arg_dat(d_by, 1, S2D_00_STRIDE_Y, "double", OPS_READ),\n\
          ops_arg_dat(d_u_Next, 1, S2D_5PT, "double", OPS_READ),\n\
          ops_arg_idx())'),
         c.Line(),
         c.LineComment('Save  dat to file.'),
         c.LineComment('if (t == 0)'),
         c.LineComment('{'),
         c.LineComment(
             '    ops_print_dat_to_txtfile(d_zetax, "output/zetax-ops.txt");'
         ),
         c.LineComment('}'),
         c.Line(),
         c.LineComment(
             'ops_print_dat_to_txtfile(d_u_Current, "output/ops-output.txt");'
         ),
         c.Line(),
         c.LineComment('Transfer current to previous.'),
         c.Statement(
             'ops_par_loop(makeCopy, "copy_current_to_previous", wave_grid, 2, whole_range,\n\
          ops_arg_dat(d_u_Previous, 1, S2D_00, "double", OPS_WRITE),\n\
          ops_arg_dat(d_u_Current, 1, S2D_00, "double", OPS_READ))'
         ),
         c.Line(),
         c.LineComment('Transfer next to current.'),
         c.Statement(
             'ops_par_loop(makeCopy, "copy_next_to_current", wave_grid, 2, whole_range,\n\
          ops_arg_dat(d_u_Current, 1, S2D_00, "double", OPS_WRITE),\n\
          ops_arg_dat(d_u_Next, 1, S2D_00, "double", OPS_READ))'),
         c.Line(),
         c.LineComment('Save  dat to file.'),
         c.LineComment('if (t % 1000 == 0)'),
         c.LineComment(
             '    ops_print_dat_to_txtfile(d_u_Current, "output/u-ops.txt");'
         ),
         c.Line(),
         c.LineComment('printf("%d\\n", t);'),
         c.Statement('t++'),
     ])),