之前从qiime2的更新介绍中了解到了这个模块,这里再详细了解一下!哪天用起来呀!
Parsl是一个基于Python的开源(https://github.com/Parsl/parsl)并行编程库,使用户能够并行化 Python 程序并在各类计算资源(例如个人电脑、集群和超算集群)上扩展且高效地运行它们。
Parsl已应用于多个科学领域的工作流中,在多个大型超算集群部署和验证,如美国国家能源研究科学计算中心(NESRC)等。相关论文(Parsl: Pervasive Parallel Programming in Python)获HPDC 2019大会最佳论文提名,更多介绍可查看Parsl主页(https://parsl-project.org/)。
Parsl 需要 Python3.8+,并且已经在 Linux 和 macOS 上进行了测试。
虽然pip
可用于安装 Parsl,但我们建议使用以下方法当许多 Python 环境可用时进行可靠安装。
$ python3 -m pip install parsl
要将以前安装的 parsl 更新到较新版本,请使用:
python3 -m pip install -U parsl
$ conda create --name parsl_py38 python=3.8
$ source activate parsl_py38
$ python3 -m pip install parsl
# or
$ conda config --add channels conda-forge
$ conda install parsl
Parsl与Python的原生并发库有很多共同之处, 但释放Parsl的潜力需要了解几个主要概念。
Parsl 程序提交要在分布在远程计算机上的工作线程上运行的任务。这些任务的说明包含在用户使用 Python 函数定义的“应用程序”中。每台远程计算机(例如,超级计算机上的节点)都有一个管理工作线程的“执行器”。Parsl 可用的远程资源由“提供者”获取, 它将执行器放置在具有“启动器”的系统上。任务执行由在本地系统上运行的“数据流内核”代理。
Parsl 支持并发执行 Python 函数 (python_app
) 或外部应用程序 (bash_app
)。两者的逻辑都由标有 Parsl 装饰器的 Python 函数描述。调用修饰的函数时,它们在其他资源上异步运行。调用 Parsl 应用程序的结果是 AppFuture
, 它的行为就像一个 Python 未来。
下面的示例演示如何编写一个简单的 Parsl 程序 与hello world Python和Bash应用程序。
>import parsl
from parsl import python_app, bash_app
parsl.load()
@python_app
def hello_python (message):
return 'Hello %s' % message
@bash_app
def hello_bash(message, stdout='hello-stdout'):
return 'echo "Hello %s"' % message
# invoke the Python app and print the result
print(hello_python('World (Python)').result())
# invoke the Bash app and read the result from a file
hello_bash('World (Bash)').result()
with open('hello-stdout', 'r') as f:
print(f.read())
了解有关 Parsl 的更多信息的最佳方式是查看 Parsl 教程。遵循本教程有几个选项: