你可以使用 pip 安装 Mars:
pip
pip install pymars
在单机运行 Mars,有两种方式。
多线程:基于线程的的调度器,它是单机的默认调度器。
本地集群:包含整个分布式运行时的基于进程的调度器。
当安装完成,可启动 Python 命令行并执行
import mars.tensor as mt from mars.session import new_session a = mt.ones((5, 5), chunk_size=3) b = a * 4 # if there isn't a local session, # execute will create a default one first b.execute() # or create a session explicitly sess = new_session() b.execute(session=sess) # run b
你可以在一台机器上启动 Mars 的分布式运行时。首先,使用下面的命令安装分布式 Mars 及相关组件:
pip install 'pymars[distributed]'
目前,本地集群模式仅支持 Linux 和 MacOS。
此后,使用下面的命令启动一个本地集群
import mars.tensor as mt from mars.deploy.local import new_cluster from mars.session import new_session cluster = new_cluster() # new cluster will start a session and set it as default one # execute will then run in the local cluster a = mt.random.rand(10, 10) a.dot(a.T).execute() # cluster.session is the session created (a + 1).execute(session=cluster.session) # users can also create a session explicitly # cluster.endpoint needs to be passed to new_session session2 = new_session(cluster.endpoint) (a * 2).execute(session=session2)