• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python op2.par_loop函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyop2.op2.par_loop函数的典型用法代码示例。如果您正苦于以下问题:Python par_loop函数的具体用法?Python par_loop怎么用?Python par_loop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了par_loop函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_direct

    def test_direct(self, s1, d1):

        def fn(a):
            a[:] = 1.0

        op2.par_loop(fn, s1, d1(op2.WRITE))
        assert np.allclose(d1.data, 1.0)
开发者ID:OP2,项目名称:PyOP2,代码行数:7,代码来源:test_pyparloop.py


示例2: test_linalg_and_parloop

 def test_linalg_and_parloop(self, backend, x, y):
     """Linear algebra operators should force computation"""
     x._data = np.zeros(x.dataset.total_size, dtype=np.float64)
     k = op2.Kernel('void k(double *x) { *x = 1.0; }', 'k')
     op2.par_loop(k, x.dataset.set, x(op2.WRITE))
     z = x + y
     assert all(z.data == y.data + 1)
开发者ID:jabooth,项目名称:PyOP2,代码行数:7,代码来源:test_linalg.py


示例3: test_assemble_rhs

    def test_assemble_rhs(self, rhs, elements, b, coords, f, elem_node, expected_rhs):
        """Assemble a simple finite-element right-hand side and check result."""
        b.zero()
        op2.par_loop(rhs, elements, b(op2.INC, elem_node), coords(op2.READ, elem_node), f(op2.READ, elem_node))

        eps = 1.0e-12
        assert_allclose(b.data, expected_rhs, eps)
开发者ID:OP2,项目名称:PyOP2,代码行数:7,代码来源:test_matrices.py


示例4: test_uninitialized_map

 def test_uninitialized_map(self, backend, iterset, indset, x):
     """Accessing a par_loop argument via an uninitialized Map should raise
     an exception."""
     kernel_wo = "void kernel_wo(unsigned int* x) { *x = 42; }\n"
     with pytest.raises(MapValueError):
         op2.par_loop(op2.Kernel(kernel_wo, "kernel_wo"), iterset,
                      x(op2.WRITE, op2.Map(iterset, indset, 1)))
开发者ID:joshcc3,项目名称:PyOP2,代码行数:7,代码来源:test_indirect_loop.py


示例5: test_onecolor_rw

    def test_onecolor_rw(self, backend, iterset, x, iterset2indset):
        """Increment each value of a Dat by one with op2.RW."""
        kernel_rw = "void kernel_rw(unsigned int* x) { (*x) = (*x) + 1; }\n"

        op2.par_loop(op2.Kernel(kernel_rw, "kernel_rw"),
                     iterset, x(op2.RW, iterset2indset[0]))
        assert sum(x.data) == nelems * (nelems + 1) / 2
开发者ID:joshcc3,项目名称:PyOP2,代码行数:7,代码来源:test_indirect_loop.py


示例6: test_invert_arg_similar_shape

    def test_invert_arg_similar_shape(self, iterset, iter2ind1, x, y):
        self.cache.clear()
        assert len(self.cache) == 0

        kernel_swap = """
static void swap(unsigned int* x, unsigned int* y)
{
  unsigned int t;
  t = *x;
  *x = *y;
  *y = t;
}
"""
        op2.par_loop(op2.Kernel(kernel_swap, "swap"),
                     iterset,
                     x(op2.RW, iter2ind1),
                     y(op2.RW, iter2ind1))

        base._trace.evaluate(set([x]), set())
        assert len(self.cache) == 1

        op2.par_loop(op2.Kernel(kernel_swap, "swap"),
                     iterset,
                     y(op2.RW, iter2ind1),
                     x(op2.RW, iter2ind1))

        base._trace.evaluate(set([y]), set())
        assert len(self.cache) == 1
开发者ID:OP2,项目名称:PyOP2,代码行数:28,代码来源:test_caching.py


示例7: test_vector_map

    def test_vector_map(self, iterset, x2, iter2ind2):
        self.cache.clear()
        assert len(self.cache) == 0

        kernel_swap = """
static void swap(unsigned int* x)
{
  unsigned int t;
  t = x[0];
  x[0] = x[1];
  x[1] = t;
}
"""

        op2.par_loop(op2.Kernel(kernel_swap, "swap"),
                     iterset,
                     x2(op2.RW, iter2ind2))

        base._trace.evaluate(set([x2]), set())
        assert len(self.cache) == 1

        op2.par_loop(op2.Kernel(kernel_swap, "swap"),
                     iterset,
                     x2(op2.RW, iter2ind2))

        base._trace.evaluate(set([x2]), set())
        assert len(self.cache) == 1
开发者ID:OP2,项目名称:PyOP2,代码行数:27,代码来源:test_caching.py


示例8: test_sum_nodes_to_edges

    def test_sum_nodes_to_edges(self, backend):
        """Creates a 1D grid with edge values numbered consecutively.
        Iterates over edges, summing the node values."""

        nedges = nnodes - 1
        nodes = op2.Set(nnodes, "nodes")
        edges = op2.Set(nedges, "edges")

        node_vals = op2.Dat(nodes, numpy.arange(nnodes, dtype=numpy.uint32), numpy.uint32, "node_vals")
        edge_vals = op2.Dat(edges, numpy.zeros(nedges, dtype=numpy.uint32), numpy.uint32, "edge_vals")

        e_map = numpy.array([(i, i + 1) for i in range(nedges)], dtype=numpy.uint32)
        edge2node = op2.Map(edges, nodes, 2, e_map, "edge2node")

        kernel_sum = """
void kernel_sum(unsigned int* nodes, unsigned int *edge, int i)
{ *edge += nodes[0]; }
"""

        op2.par_loop(
            op2.Kernel(kernel_sum, "kernel_sum"), edges, node_vals(op2.READ, edge2node[op2.i[0]]), edge_vals(op2.INC)
        )

        expected = numpy.arange(1, nedges * 2 + 1, 2)
        assert all(expected == edge_vals.data)
开发者ID:joshcc3,项目名称:PyOP2,代码行数:25,代码来源:test_iteration_space_dats.py


示例9: test_assemble_mat

 def test_assemble_mat(self, backend, mass, mat, coords, elements, elem_node,
                       elem_vnode, expected_matrix):
     op2.par_loop(mass, elements(3,3),
                  mat((elem_node[op2.i[0]], elem_node[op2.i[1]]), op2.INC),
                  coords(elem_vnode, op2.READ))
     eps=1.e-5
     assert_allclose(mat.values, expected_matrix, eps)
开发者ID:RomainBrault,项目名称:PyOP2,代码行数:7,代码来源:test_matrices.py


示例10: test_invert_arg_similar_shape

    def test_invert_arg_similar_shape(self, backend, iterset, iter2ind1, x, y):
        self.cache.clear()
        assert len(self.cache) == 0

        kernel_swap = """
void kernel_swap(unsigned int* x, unsigned int* y)
{
  unsigned int t;
  t = *x;
  *x = *y;
  *y = t;
}
"""
        op2.par_loop(op2.Kernel(kernel_swap, "kernel_swap"),
                     iterset,
                     x(iter2ind1[0], op2.RW),
                     y(iter2ind1[0], op2.RW))

        assert len(self.cache) == 1

        op2.par_loop(op2.Kernel(kernel_swap, "kernel_swap"),
                     iterset,
                     y(iter2ind1[0], op2.RW),
                     x(iter2ind1[0], op2.RW))

        assert len(self.cache) == 1
开发者ID:RomainBrault,项目名称:PyOP2,代码行数:26,代码来源:test_caching.py


示例11: test_1d_inc_no_data

    def test_1d_inc_no_data(self, k1_inc_to_global, set, d1):
        g = op2.Global(1, dtype=numpy.uint32)
        op2.par_loop(k1_inc_to_global, set,
                     g(op2.INC),
                     d1(op2.READ))

        assert g.data == d1.data.sum()
开发者ID:OP2,项目名称:PyOP2,代码行数:7,代码来源:test_global_reduction.py


示例12: test_idx_order

    def test_idx_order(self, backend, iterset, iter2ind2, x):
        self.cache.clear()
        assert len(self.cache) == 0

        kernel_swap = """
void kernel_swap(unsigned int* x, unsigned int* y)
{
  unsigned int t;
  t = *x;
  *x = *y;
  *y = t;
}
"""
        op2.par_loop(op2.Kernel(kernel_swap, "kernel_swap"),
                     iterset,
                     x(iter2ind2[0], op2.RW),
                     x(iter2ind2[1], op2.RW))

        assert len(self.cache) == 1

        op2.par_loop(op2.Kernel(kernel_swap, "kernel_swap"),
                     iterset,
                     x(iter2ind2[1], op2.RW),
                     x(iter2ind2[0], op2.RW))

        assert len(self.cache) == 1
开发者ID:RomainBrault,项目名称:PyOP2,代码行数:26,代码来源:test_caching.py


示例13: get_restriction_weights

def get_restriction_weights(coarse, fine):
    mesh = coarse.mesh()
    assert hasattr(mesh, "_shared_data_cache")
    cache = mesh._shared_data_cache["hierarchy_restriction_weights"]
    key = entity_dofs_key(coarse.fiat_element.entity_dofs())
    try:
        return cache[key]
    except KeyError:
        # We hit each fine dof more than once since we loop
        # elementwise over the coarse cells.  So we need a count of
        # how many times we did this to weight the final contribution
        # appropriately.
        if not (coarse.ufl_element() == fine.ufl_element()):
            raise ValueError("Can't transfer between different spaces")
        if coarse.fiat_element.entity_dofs() == coarse.fiat_element.entity_closure_dofs():
            return cache.setdefault(key, None)
        ele = coarse.ufl_element()
        if isinstance(ele, ufl.VectorElement):
            ele = ele.sub_elements()[0]
            weights = firedrake.Function(firedrake.FunctionSpace(fine.mesh(), ele))
        else:
            weights = firedrake.Function(fine)
        c2f_map = coarse_to_fine_node_map(coarse, fine)
        kernel = get_count_kernel(c2f_map.arity)
        op2.par_loop(kernel, op2.LocalSet(mesh.cell_set),
                     weights.dat(op2.INC, c2f_map[op2.i[0]]))
        weights.assign(1/weights)
        return cache.setdefault(key, weights)
开发者ID:kalogirou,项目名称:firedrake,代码行数:28,代码来源:utils.py


示例14: test_indirect

    def test_indirect(self, s1, d2, m12):

        def fn(a):
            a[0] = 1.0

        op2.par_loop(fn, s1, d2(op2.WRITE, m12))
        assert np.allclose(d2.data, 1.0)
开发者ID:OP2,项目名称:PyOP2,代码行数:7,代码来源:test_pyparloop.py


示例15: test_2d_read

    def test_2d_read(self, backend, k2_write_to_dat, set, d1):
        g = op2.Global(2, (1, 2), dtype=numpy.uint32)
        op2.par_loop(k2_write_to_dat, set,
                     d1(op2.IdentityMap, op2.WRITE),
                     g(op2.READ))

        assert all(d1.data == g.data.sum())
开发者ID:RomainBrault,项目名称:PyOP2,代码行数:7,代码来源:test_global_reduction.py


示例16: test_inc_2d_itspace_map

    def test_inc_2d_itspace_map(self, backend, d2, vd2, node2ele, node):
        vd2.data[:, 0] = 3
        vd2.data[:, 1] = 4
        d2.data[:] = numpy.arange(2 * nnodes).reshape(d2.data.shape)

        incs = Block([Incr(Symbol("vd", ("i",), ((1, 0),)), Symbol("d", (0,))),
                      Incr(
                          Symbol("vd", ("i",), ((1, 1),)), Symbol("d", (1,)))],
                     open_scope=True)
        k = FunDecl("void", "k",
                    [Decl("int*", c_sym("d")), Decl("int*", c_sym("vd"))],
                    c_for("i", 1, incs))

        op2.par_loop(op2.Kernel(k, 'k'), node,
                     d2(op2.READ),
                     vd2(op2.INC, node2ele[op2.i[0]]))

        expected = numpy.zeros_like(vd2.data)
        expected[:, 0] = 3
        expected[:, 1] = 4
        expected[:, 0] += numpy.arange(start=0, stop=2 * nnodes, step=4)
        expected[:, 0] += numpy.arange(start=2, stop=2 * nnodes, step=4)
        expected[:, 1] += numpy.arange(start=1, stop=2 * nnodes, step=4)
        expected[:, 1] += numpy.arange(start=3, stop=2 * nnodes, step=4)
        assert all(vd2.data[:, 0] == expected[:, 0])
        assert all(vd2.data[:, 1] == expected[:, 1])
开发者ID:jabooth,项目名称:PyOP2,代码行数:26,代码来源:test_iteration_space_dats.py


示例17: test_1d_inc

    def test_1d_inc(self, backend, k1_inc_to_global, set, d1):
        g = op2.Global(1, 0, dtype=numpy.uint32)
        op2.par_loop(k1_inc_to_global, set,
                     d1(op2.IdentityMap, op2.READ),
                     g(op2.INC))

        assert g.data == d1.data.sum()
开发者ID:RomainBrault,项目名称:PyOP2,代码行数:7,代码来源:test_global_reduction.py


示例18: test_sum_nodes_to_edges

    def test_sum_nodes_to_edges(self, backend):
        """Creates a 1D grid with edge values numbered consecutively.
        Iterates over edges, summing the node values."""

        nedges = nnodes - 1
        nodes = op2.Set(nnodes, "nodes")
        edges = op2.Set(nedges, "edges")

        node_vals = op2.Dat(nodes, numpy.arange(
            nnodes, dtype=numpy.uint32), numpy.uint32, "node_vals")
        edge_vals = op2.Dat(
            edges, numpy.zeros(nedges, dtype=numpy.uint32), numpy.uint32, "edge_vals")

        e_map = numpy.array([(i, i + 1)
                            for i in range(nedges)], dtype=numpy.uint32)
        edge2node = op2.Map(edges, nodes, 2, e_map, "edge2node")

        kernel_sum = FunDecl("void", "kernel_sum",
                             [Decl(
                                 "int*", c_sym("nodes"), qualifiers=["unsigned"]),
                              Decl(
                                  "int*", c_sym("edge"), qualifiers=["unsigned"])],
                             c_for("i", 2, Incr(c_sym("*edge"), Symbol("nodes", ("i",)))))

        op2.par_loop(op2.Kernel(kernel_sum, "kernel_sum"), edges,
                     node_vals(op2.READ, edge2node[op2.i[0]]),
                     edge_vals(op2.INC))

        expected = numpy.arange(1, nedges * 2 + 1, 2)
        assert all(expected == edge_vals.data)
开发者ID:jabooth,项目名称:PyOP2,代码行数:30,代码来源:test_iteration_space_dats.py


示例19: test_dloop_ignore_scalar

    def test_dloop_ignore_scalar(self, iterset, a, b):
        self.cache.clear()
        assert len(self.cache) == 0

        kernel_swap = """
static void swap(unsigned int* x, unsigned int* y)
{
  unsigned int t;
  t = *x;
  *x = *y;
  *y = t;
}
"""
        op2.par_loop(op2.Kernel(kernel_swap, "swap"),
                     iterset,
                     a(op2.RW),
                     b(op2.RW))

        base._trace.evaluate(set([a]), set())
        assert len(self.cache) == 1

        op2.par_loop(op2.Kernel(kernel_swap, "swap"),
                     iterset,
                     b(op2.RW),
                     a(op2.RW))

        base._trace.evaluate(set([b]), set())
        assert len(self.cache) == 1
开发者ID:OP2,项目名称:PyOP2,代码行数:28,代码来源:test_caching.py


示例20: test_1d_read

    def test_1d_read(self, backend, k1_write_to_dat, set, d1):
        g = op2.Global(1, 1, dtype=numpy.uint32)
        op2.par_loop(k1_write_to_dat, set,
                     d1(op2.WRITE),
                     g(op2.READ))

        assert all(d1.data == g.data)
开发者ID:GitPaean,项目名称:PyOP2,代码行数:7,代码来源:test_global_reduction.py



注:本文中的pyop2.op2.par_loop函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pyopencl.create_some_context函数代码示例发布时间:2022-05-27
下一篇:
Python op2.init函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap