charm4py并行编程框架
charm4p的Python项目详细描述
(注意:在版本v0.11中,我们已经将项目名称更改为charm4py。见 有关详细信息,请参见forum。
charm4py(charm++for python-以前是charmpy-)是一个通用的并行程序,并且
基于
可移植的python对象和远程方法调用;构建在自适应
C++运行时系统提供^ {EM1} $速度EEM>、^ {EM1} $可伸缩性
charm4py允许开发从笔记本电脑到 超级计算机,使用python语言。它建在Charm++之上。
简短示例
下面使用任意数量的计算机和处理器并行计算pi:
fromcharm4pyimportcharm,Chare,Group,ReducerfrommathimportpiimporttimeclassWorker(Chare):defwork(self,n_steps,pi_future):h=1.0/n_stepss=0.0foriinrange(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 futureself.contribute(s*h,Reducer.sum,pi_future)defmain(args):n_steps=1000iflen(args)>1:n_steps=int(args[1])mypi=charm.createFuture()workers=Group(Worker)# create one instance of Worker on every processort0=time.time()workers.work(n_steps,mypi)# invoke 'work' method on every workerprint('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)
这是一个简单的例子,只演示了charm4py的一些特性一些需要注意的事情 从这个例子来看:
- chares是分布式python对象。
- group是一种分布式集合,其中指定的 在每个处理器上创建字符类型
- charm4py中的远程方法调用是asynchronous
在这个例子中,每个处理器只有一个字符,但是有多个字符(相同的 或不同类型的)可以存在于任何给定的处理器上,这可以带来性能。 好处有关详细信息,请参阅documentation。