julia-p 4将启动4个 worker。这意味着如果运行nprocs(),将有5个进程。id为1的进程为主进程将指导计算,也是本地进程,然后2-5 号进程将是执行并行计算的工作进程。这些进程可能在本地服务器上,也可能在远程服务器上。
using Distributed
nprocess = 4
#添加新的工作进程
addprocs(nprocess)
# 5-element Array{Int64,1}:
# 2
# 3
# 4
# 5
#所有进程ID
procs()
# 5-element Array{Int64,1}:
# 1
# 2
# 3
# 4
# 5
#工作进程总数
workers()
# 4-element Array{Int64,1}:
# 2
# 3
# 4
# 5
#用nprocs()和nworkers()查看进程和Worker数量。一般地,总有nprocs()=nworkers()+1
nprocs()
nworkers()