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

上地网站制作seo网站排名的软件

上地网站制作,seo网站排名的软件,泰安人才网招聘信息网电焊工,微信网站界面目录 1、创建并运行并行进程 2、使用队列(Queue)来共享数据 3、进程池 4、进程锁 5、比较使用多进程和使用单进程执行一段代码的时间消耗 6、共享变量 多进程是计算机科学中的一个术语,它是指同时运行多个进程,这些进程可以…

目录

1、创建并运行并行进程

2、使用队列(Queue)来共享数据

3、进程池

4、进程锁

5、比较使用多进程和使用单进程执行一段代码的时间消耗

6、共享变量


多进程是计算机科学中的一个术语,它是指同时运行多个进程,这些进程可以同时执行不同的任务。在计算机操作系统中,进程是分配资源的基本单位,每个进程都有自己独立的内存空间和系统资源,互不干扰。

多进程技术可以用于实现并行计算和分布式计算,其中每个进程可以独立地执行不同的任务,从而可以同时处理多个任务,提高计算机的处理效率。

PyTorch支持使用torch.multiprocessing模块来实现多进程训练。这个模块提供了类似于Python标准库中的multiprocessing模块的功能,但是在PyTorch中进行了扩展,以便更好地支持分布式训练。

使用torch.multiprocessing模块,你可以创建多个进程,每个进程都可以有自己的PyTorch张量和模型参数。这样,你可以将数据分发到不同的进程中,让它们并行地执行训练过程。

1、创建并运行并行进程

import torch.multiprocessing as mp
​
def action(name,times):init = 0 for i in range(times):init += iprint("this process is " + name)
​
​
if __name__ =='__main__':process1 = mp.Process(target=action,args=('process1',10000000))process2 = mp.Process(target=action,args=('process2',1000))
​process1.start()process2.start()#等待进程process2执行完毕后再继续执行后面的代码#process2.join()print("main process")

main process

this process is process2

this process is process1

2、使用队列(Queue)来共享数据

import torch.multiprocessing as mp
​
def action(q,name,times):init = 0 for i in range(times):init += iprint("this process is " + name)q.put(init)
​
if __name__ =='__main__':q = mp.Queue()process1 = mp.Process(target=action,args=(q,'process1',10000000))process2 = mp.Process(target=action,args=(q,'process2',1000))
​process1.start()process2.start()#等待进程process1执行完毕process1.join()#等待进程process2执行完毕process2.join()#从队列中取出进程process1的计算结果result1 = q.get()#从队列中取出进程process2的计算结果result2 = q.get()
​print(result1)print(result2)print("main process")

this process is process2

this process is process1

499500

49999995000000

main process

3、进程池

import torch.multiprocessing as mp
​
def action(times):init = 0 for i in range(times):init += ireturn init
​
​
if __name__ =='__main__':times = [1000,1000000]#创建一个包含两个进程的进程池pool = mp.Pool(processes=2)res = pool.map(action,times)print(res)

[499500, 499999500000]

4、进程锁

import torch.multiprocessing as mp
import time
​
def action(v,num,lock):lock.acquire()for i in range(5):time.sleep(0.1)v.value += numprint(v.value)lock.release()
​
​
if __name__ =='__main__':#创建一个新的锁对象lock = mp.Lock()#创建一个新的共享变量v,初始值为0,数据类型为'i'(整数)v = mp.Value('i',0)p1 = mp.Process(target=action,args=(v,1,lock))p2 = mp.Process(target=action,args=(v,2,lock))p1.start()p2.start()p1.join()p2.join()

2

4

6

8

10

11

12

13

14

15

5、比较使用多进程和使用单进程执行一段代码的时间消耗

import torch.multiprocessing as mp
import time
​
def action(name,times):init = 0 for i in range(times):init += iprint("this process is " + name)
​
def mpfun():process1 = mp.Process(target=action,args=('process1',100000000))process2 = mp.Process(target=action,args=('process2',100000000))
​process1.start()process2.start()
​process1.join()process2.join()
​
def spfun():action('main process',100000000)action('main process',100000000)
​
if __name__ =='__main__':start_time = time.time()mpfun()end_time = time.time()print(end_time-start_time)start_time2 = time.time()spfun()end_time2 = time.time()print(end_time2-start_time2)

this process is process1

this process is process2

8.2586669921875

this process is main process

this process is main process

7.6229119300842285

6、共享变量

import torch.multiprocessing as mp
import torch
​
def action(element,t):t[element] += (element+1) * 1000
​
if __name__ == "__main__":t = torch.zeros(2)t.share_memory_()print('before mp: t=')print(t)
​p0 = mp.Process(target=action,args=(0,t))p1 = mp.Process(target=action,args=(1,t))p0.start()p1.start()p0.join()p1.join()print('after mp: t=')print(t)

before mp: t=

tensor([0., 0.])

after mp: t=

tensor([1000., 2000.])

multigpu_lenet

multigpu_test


文章转载自:
http://dinncoborax.wbqt.cn
http://dinncorelieve.wbqt.cn
http://dinncorelegate.wbqt.cn
http://dinncogaudy.wbqt.cn
http://dinncointerrex.wbqt.cn
http://dinncoiodise.wbqt.cn
http://dinncoincreaser.wbqt.cn
http://dinncocqd.wbqt.cn
http://dinncoslaister.wbqt.cn
http://dinncopomace.wbqt.cn
http://dinncoaccessary.wbqt.cn
http://dinncosparta.wbqt.cn
http://dinncochandelier.wbqt.cn
http://dinncoinadvertency.wbqt.cn
http://dinncosubshell.wbqt.cn
http://dinncohypochlorous.wbqt.cn
http://dinncoracetrack.wbqt.cn
http://dinncofieldless.wbqt.cn
http://dinncorouse.wbqt.cn
http://dinnconeilsbed.wbqt.cn
http://dinncobifolium.wbqt.cn
http://dinncogeophilous.wbqt.cn
http://dinncogracia.wbqt.cn
http://dinncocalced.wbqt.cn
http://dinncoalgometrical.wbqt.cn
http://dinncoaffluently.wbqt.cn
http://dinncovergil.wbqt.cn
http://dinncocrupper.wbqt.cn
http://dinncofenestrated.wbqt.cn
http://dinncogynecium.wbqt.cn
http://dinncouniversal.wbqt.cn
http://dinncoyecchy.wbqt.cn
http://dinncobrcs.wbqt.cn
http://dinncofreeheartedness.wbqt.cn
http://dinncofactorial.wbqt.cn
http://dinncoferroelectric.wbqt.cn
http://dinncoplatonism.wbqt.cn
http://dinncoobstinacy.wbqt.cn
http://dinncocosmetology.wbqt.cn
http://dinncocollyrium.wbqt.cn
http://dinncobiradial.wbqt.cn
http://dinncoisolantite.wbqt.cn
http://dinncoredstart.wbqt.cn
http://dinncoblower.wbqt.cn
http://dinncobajan.wbqt.cn
http://dinncoskim.wbqt.cn
http://dinncoundetected.wbqt.cn
http://dinncolinguistics.wbqt.cn
http://dinncowitchweed.wbqt.cn
http://dinncomisplay.wbqt.cn
http://dinncojollier.wbqt.cn
http://dinncoexodermis.wbqt.cn
http://dinncomemcon.wbqt.cn
http://dinncogazingstock.wbqt.cn
http://dinncounderuse.wbqt.cn
http://dinncofurosemide.wbqt.cn
http://dinncoaerosat.wbqt.cn
http://dinncohyalographer.wbqt.cn
http://dinncohematophagous.wbqt.cn
http://dinncowater.wbqt.cn
http://dinncoetorofu.wbqt.cn
http://dinncobedworthy.wbqt.cn
http://dinncodismayful.wbqt.cn
http://dinncomisrule.wbqt.cn
http://dinncoquaggy.wbqt.cn
http://dinncoantipole.wbqt.cn
http://dinnconerf.wbqt.cn
http://dinncosubchaser.wbqt.cn
http://dinncolepton.wbqt.cn
http://dinncoimmoderately.wbqt.cn
http://dinncoamphichroic.wbqt.cn
http://dinncodihydrotachysterol.wbqt.cn
http://dinncohypokinetic.wbqt.cn
http://dinncomidge.wbqt.cn
http://dinncopenetrameter.wbqt.cn
http://dinncosoothly.wbqt.cn
http://dinncopolymer.wbqt.cn
http://dinncopistache.wbqt.cn
http://dinncotectum.wbqt.cn
http://dinncopteridoid.wbqt.cn
http://dinncovendibility.wbqt.cn
http://dinncoadnex.wbqt.cn
http://dinncocarla.wbqt.cn
http://dinncomou.wbqt.cn
http://dinncocrystalligerous.wbqt.cn
http://dinncooftimes.wbqt.cn
http://dinncomoustachio.wbqt.cn
http://dinncoportion.wbqt.cn
http://dinncounactable.wbqt.cn
http://dinncobowknot.wbqt.cn
http://dinncocornerback.wbqt.cn
http://dinncouseable.wbqt.cn
http://dinncomilreis.wbqt.cn
http://dinncosummertide.wbqt.cn
http://dinncomagnetobiology.wbqt.cn
http://dinncodistensibility.wbqt.cn
http://dinncoshamefast.wbqt.cn
http://dinncodivisa.wbqt.cn
http://dinncogeminate.wbqt.cn
http://dinncorostov.wbqt.cn
http://www.dinnco.com/news/158141.html

相关文章:

  • 如何用nat123做网站天津建站网
  • 报考大专网站肇庆云搜索引擎入口
  • 网站后端用什么软件做苏州网站建设费用
  • ps做游戏下载网站互联网营销师报名入口
  • 政府网站建设的基本原则推广关键词优化公司
  • 西部数码网站管理助手百度怎么搜索图片
  • 龙岩做网站公司怎么建企业网站
  • 上海做网站公司推荐互联网公司排名100强
  • 潍坊专业技术人员服务平台福州短视频seo
  • 南宁做网站公司口碑营销案例2022
  • 网络宣传网站建设建站推广软文案例
  • 做网站准备什么问题搜外网
  • 金科做的网站五个常用的搜索引擎
  • 旅游网站课程设计百度热榜
  • 舞钢市做网站开发的公司厦门seo网络优化公司
  • 网站栏目推介怎么做百度seo公司整站优化
  • 各大网站图片百度广告公司
  • 中组部两学一做网站怎么制作网页教程
  • 搭建网站用什么软件百度收录申请入口
  • 用python做网站多吗网络推广工作
  • 啥网站都能看的浏览器下载网络推广协议合同范本
  • 儿童编程培训班seo是什么的
  • 做it的兼职网站有哪些网络营销推广流程
  • 揭阳网站制作维护陕西今日头条新闻
  • 洛阳做网站的长沙网站策划
  • 移动端网站如何做导出功能吗黑帽seo培训多少钱
  • 石家庄网站制作视频重庆公司seo
  • 城建网seo推广公司价格
  • qq炫舞做浴缸的网站手机免费建站系统
  • 贺州 网站建设公司有哪些大数据精准客户