当前位置: 首页 > news >正文

安义南昌网站建设公司北京seo排名厂家

安义南昌网站建设公司,北京seo排名厂家,wordpress主题 企业,做网站那几步目录 问题描述 代码1(串行) 代码2(并行) 代码2执行时所用指令 错误信息 解决方案 解决方案1 解决方案2 问题描述 今天正在学习使用mpi4py,在对比运行以下2个代码时疯狂报错: 代码1(串…

目录

问题描述

代码1(串行)

代码2(并行)

代码2执行时所用指令

错误信息

解决方案 

解决方案1 

解决方案2


问题描述

今天正在学习使用mpi4py,在对比运行以下2个代码时疯狂报错:

代码1(串行)

import numpy as np
import timenp.random.seed(2)
size = 1000000x1 = np.random.random(size)
x2 = np.random.random(size)
result = np.zeros(size, dtype=float)since = time.time()
for i in range(size):result[i] = x1[i] + x2[i]
end = time.time()print(end - since)

代码2(并行)

from mpi4py import MPI
import numpy as np
import timecomm = MPI.COMM_WORLD
rank = comm.Get_rank()
nprocs = comm.Get_size()size = 1000000
x1 = np.random.random(size)
x2 = np.random.random(size)if rank == 0:ave, res = divmod(size, nprocs)count = [ave + 1 if p < res else ave for p in range(nprocs)]count = np.array(count)displ = [sum(count[:p]) for p in range(nprocs)]displ = np.array(displ)
else:sendbuf = Nonecount = np.zeros(nprocs, dtype=np.int)displ = Nonet0 = time.time()
comm.Bcast(count, root=0)recvbuf1 = np.zeros(count[rank])
recvbuf2 = np.zeros(count[rank])comm.Scatterv([x1, count, displ, MPI.DOUBLE], recvbuf1, root=0)
comm.Scatterv([x2, count, displ, MPI.DOUBLE], recvbuf2, root=0)print('After Scatterv, process {} has data:'.format(rank), recvbuf1)
print('After Scatterv, process {} has data:'.format(rank), recvbuf2)for i in range(recvbuf1.shape[0]):recvbuf1[i] += recvbuf2[i]sendbuf2 = recvbuf1
recvbuf2 = np.zeros(sum(count))
comm.Gatherv(sendbuf2, [recvbuf2, count, displ, MPI.DOUBLE], root=0)if comm.Get_rank() == 0:print('pi computed in {:.3f} sec'.format(time.time() - t0))print('After Gatherv, process 0 has data:', recvbuf2)

代码2执行时所用指令

# mpi_test.py是该代码存放的代码文件,代码是以root的权限执行的
mpirun -np 4 --allow-run-as-root python mpi_test.py

错误信息

这个错误是我第三次尝试解决,这次终于找到了解决方案,太不容易了,QAQ

解决方案 

参考链接:

python - Possible buffer size limit in mpi4py Reduce() - Stack Overflow

链接中指出,出现这个错误的主要原因是由于

The issue comes from the Cross-Memory Attach (CMA) system calls process_vm_readv() and process_vm_writev() that the shared-memory BTLs (Byte Transfer Layers, a.k.a. the things that move bytes between ranks) of Open MPI use to accelerate shared-memory communication between ranks that run on the same node by avoiding copying the data twice to and from a shared-memory buffer. This mechanism involves some setup overhead and is therefore only used for larger messages, which is why the problem only starts occurring after the messages size crosses the eager threshold.

有以下两个解决方案:

解决方案1 

在执行docker run时,带上参数

--cap-add=SYS_PTRACE

但是由于我拿到的是分好的docker,并不具备执行docker run指令的权限,所以只能选择解决方案2中的解决方法。 

解决方案2

 禁用CMA。

如果是Open MPI 1.8之前的版本,在执行mpirun时带上参数:

mpirun --mca btl_sm_use_cma 0 ...

如果是Open MPI 1.8之后的版本,执行mpirun时带上参数:

mpirun --mca btl_vader_single_copy_mechanism none

附上一个原网站的回答截图以备后续查阅: 

http://www.15wanjia.com/news/48915.html

相关文章:

  • wordpress如何做成app汕头seo
  • 西安北郊网站建设公司最新新闻热点
  • 网站未备案做seo会被k吗企业网站设计方案
  • 给你网站你会怎么做网站排名靠前方法
  • 网站运营分析报告电商网站建设定制
  • 怎么用模板建网站网址模板建站
  • 重庆做网站做得好的公司谷歌推广网站
  • 做弩的网站seo检测
  • wordpress留言群发盐城seo推广
  • 网站免费获取验证码怎么做发布项目信息的平台
  • 个人网站的开发与设计链接推广
  • 个人网站效果图咋做如何开网站详细步骤
  • 如何做单网页网站互联网营销课程体系
  • 世界各国疫情排名一览表宁波网站建设网站排名优化
  • 网站设计与建设开发客源引流推广
  • 北碚免费建站哪家做得好排名优化百度
  • 做仪表宣传哪个网站好宁波企业seo外包
  • 云梦网络做网站怎样做网站推广啊
  • 北京国贸网站建设公司模拟搜索点击软件
  • wordpress网站如何添加内链能打开各种网站的搜索引擎
  • php网站投票源码百度大数据预测平台
  • 江西省建设厅网站官网整合营销方案案例
  • 聊城网站建设网站查询网
  • 网站布局结构分类南昌百度推广公司
  • 浦东做网站公司北京网站优化公司
  • 成都营销网站建设站长之家
  • 汉中疫情最新消息实时更新求好用的seo软件
  • 可以看的网站都有哪些足球联赛排名
  • 做网站用什么语言数据库下列哪些店铺适合交换友情链接
  • 图灵机器人 wordpress南宁百度seo排名