CharmPy是一个通用的并行和分布式编程框架

网友投稿 998 2022-10-13

CharmPy是一个通用的并行和分布式编程框架

CharmPy是一个通用的并行和分布式编程框架

Charm4py

Charm4py (Charm++ for Python -formerly CharmPy-) is a distributed computing and parallel programming framework for Python, for the productive development of fast, parallel and scalable applications. It is built on top of Charm++, a C++ adaptive runtime system that has seen extensive use in the scientific and high-performance computing (HPC) communities across many disciplines, and has been used to develop applications that run on a wide range of devices: from small multi-core devices up to the largest supercomputers.

Please see the Documentation for more information.

Short Example

The following computes Pi in parallel, using any number of machines and processors:

from charm4py import charm, Chare, Group, Reducer, Futurefrom math import piimport timeclass Worker(Chare): def work(self, n_steps, pi_future): h = 1.0 / n_steps s = 0.0 for i in range(self.thisIndex, n_steps, charm.numPes()): x = h * (i + 0.5) s += 4.0 / (1.0 + x**2) # perform a reduction among members of the group, sending the result to the future self.reduce(pi_future, s * h, Reducer.sum)def main(args): n_steps = 1000 if len(args) > 1: n_steps = int(args[1]) mypi = Future() workers = Group(Worker) # create one instance of Worker on every processor t0 = time.time() workers.work(n_steps, mypi) # invoke 'work' method on every worker print('Approximated value of pi is:', mypi.get(), # 'get' blocks until result arrives 'Error is', abs(mypi.get() - pi), 'Elapsed time=', time.time() - t0) exit()charm.start(main)

This is a simple example and demonstrates only a few features of Charm4py. Some things to note from this example:

Chares (pronounced chars) are distributed Python objects.A Group is a type of distributed collection where one instance of the specified chare type is created on each processor.Remote method invocation in Charm4py is asynchronous.

In this example, there is only one chare per processor, but multiple chares (of the same or different type) can exist on any given processor, which can bring flexibility and also performance benefits (like dynamic load balancing). Please refer to the documentation for more information.

Contact

We would like feedback from the community. If you have feature suggestions, support questions or general comments, please visit our forum or emails us at , or

Main author at

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:自学HarmonyOS应用开发(70)- 解决ListContainer默认优化问题
下一篇:Linux安装K8s
相关文章

 发表评论

暂时没有评论,来抢沙发吧~