首先时解释一下我要做什么,我打算用julia进行一些并行计算。
问题的起源是基于一个文档,文档链接在这里。这里面介绍了关于并行计算的一些配置方法和使用方法,比如可以在本地添加一些核心(processor),也可以添加远程的核心,这里面添加核心用的是addprocs
函数。还要一些函数比如@spawn
@spawnat
@fetch
就不细说了,看下文档便知一二,而且有中文文档可以看。
现在我就来说一下如何添加远程核心,我能够查到的资料有两个,一个是官方STL,另外一个是邮件列表里的一个问题。
文档是这样说的:
addprocs(machines; tunnel=false, dir=JULIA_HOME, sshflags::Cmd=``) → List of process identifiers
Add processes on remote machines via SSH. Requires julia to be installed in the same location on each node, or to be available via a shared file system.
machines is a vector of host definitions of the form [user@]host[:port]. A worker is started for each such definition.
Keyword arguments:
tunnel : if true then SSH tunneling will be used to connect to the worker.
dir : specifies the location of the julia binaries on the worker nodes.
sshflags : specifies additional ssh options, e.g. sshflags=`-i /home/foo/bar.pem` .
大概是说,要几个参数,第一个是machines
,它是一个向量;第二个参数是tunnel
,是个布尔值;第个是dir
,它代表julia
命令存放位置的一个字符串,比如/usr/bin
;最后是一些sshflags
,暂时用不到。
于是我们就可以用了,首先在终端输入julia
,
- 你可以添加本地的processor,
addprocs(3)
就添加了三个本地核心。 - 要添加远程的,应该用
addprocs({"eccstartup@xxx.xxx.xxx.xxx[:port]"},tunnel=true,dir="/usr/bin")
端口可以不指定,会提示输入远程的ssh密码。
这样就好了,试试nprocs()
吧,很方便吧?
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。