1. ray库介绍
金融、工程模型需要大量使用 Pandas 和 Numpy 来做矩阵计算,需要针对 Pandas/Numpy 有更好的支持,ray库就是其中一种可以加速计算的框架。
Ray 有如下特点:
- 分布式异步调用
- 内存调度
- Pandas/Numpy 的分布式支持
- 支持 Python
- 整体性能出众
2. ray安装
电脑是win10+python3.7.3,安装ray库,下面的顺序不能错
pip install -i https://mirrors.aliyun.com/pypi/simple/pytest-runner
pip install -i https://mirrors.aliyun.com/pypi/simple/ray
3. 初步使用的基本形式
# 导入ray,并初始化执行环境
import ray
ray.init()
# 定义ray remote函数
@ray.remote
def hello():
return "Hello world !"
# 异步执行remote函数,返回结果id
object_id = hello.remote()
# 同步获取计算结果
hello = ray.get(object_id)
# 输出计算结果
print hello
4. 测试一个简单的例子
使用ray库计算100次的延迟1秒
import ray
import time
import numpy as np
# 启动Ray.
ray.init()
#定义remote函数
@ray.remote
def sleep1(n):
time.sleep(n)
#程序开始时的时间
time_start=time.time()
result_ids = []

本文介绍了Ray库,一个用于加速Pandas/Numpy计算的分布式计算框架,包括其特点、Windows安装步骤、基本使用示例、系统架构及应用案例。重点讲解了分布式异步调用、内存管理和任务图动态构建等内容。
&spm=1001.2101.3001.5002&articleId=114983041&d=1&t=3&u=afe609aa67b1402aba22111e01285afb)
2694

被折叠的 条评论
为什么被折叠?



