久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    1. <tfoot id='fXRAr'></tfoot>
        <i id='fXRAr'><tr id='fXRAr'><dt id='fXRAr'><q id='fXRAr'><span id='fXRAr'><b id='fXRAr'><form id='fXRAr'><ins id='fXRAr'></ins><ul id='fXRAr'></ul><sub id='fXRAr'></sub></form><legend id='fXRAr'></legend><bdo id='fXRAr'><pre id='fXRAr'><center id='fXRAr'></center></pre></bdo></b><th id='fXRAr'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='fXRAr'><tfoot id='fXRAr'></tfoot><dl id='fXRAr'><fieldset id='fXRAr'></fieldset></dl></div>

      1. <small id='fXRAr'></small><noframes id='fXRAr'>

          <bdo id='fXRAr'></bdo><ul id='fXRAr'></ul>
        <legend id='fXRAr'><style id='fXRAr'><dir id='fXRAr'><q id='fXRAr'></q></dir></style></legend>
      2. 多處理 - 共享數(shù)組

        Multiprocessing - Shared Array(多處理 - 共享數(shù)組)

        • <small id='vvNH4'></small><noframes id='vvNH4'>

          <i id='vvNH4'><tr id='vvNH4'><dt id='vvNH4'><q id='vvNH4'><span id='vvNH4'><b id='vvNH4'><form id='vvNH4'><ins id='vvNH4'></ins><ul id='vvNH4'></ul><sub id='vvNH4'></sub></form><legend id='vvNH4'></legend><bdo id='vvNH4'><pre id='vvNH4'><center id='vvNH4'></center></pre></bdo></b><th id='vvNH4'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vvNH4'><tfoot id='vvNH4'></tfoot><dl id='vvNH4'><fieldset id='vvNH4'></fieldset></dl></div>
        • <tfoot id='vvNH4'></tfoot>
              <bdo id='vvNH4'></bdo><ul id='vvNH4'></ul>

                    <tbody id='vvNH4'></tbody>
                1. <legend id='vvNH4'><style id='vvNH4'><dir id='vvNH4'><q id='vvNH4'></q></dir></style></legend>
                  本文介紹了多處理 - 共享數(shù)組的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時送ChatGPT賬號..

                  所以我試圖在 python 中實現(xiàn)多處理,我希望有一個由 4-5 個進程組成的池并行運行一個方法.這樣做的目的是運行總共一千次 Monte 模擬(每個進程 250-200 次模擬)而不是運行 1000 次.我希望每個進程在處理完一個模擬的結(jié)果,寫入結(jié)果并釋放鎖.所以這應(yīng)該是一個三步過程:

                  So I'm trying to implement multiprocessing in python where I wish to have a Pool of 4-5 processes running a method in parallel. The purpose of this is to run a total of thousand Monte simulations (250-200 simulations per process) instead of running 1000. I want each process to write to a common shared array by acquiring a lock on it as soon as its done processing the result for one simulation, writing the result and releasing the lock. So it should be a three step process :

                  1. 獲取鎖
                  2. 寫入結(jié)果
                  3. 為等待寫入數(shù)組的其他進程釋放鎖.

                  每次我將數(shù)組傳遞給進程時,每個進程都會創(chuàng)建一個我不想要的數(shù)組副本,因為我想要一個公共數(shù)組.任何人都可以通過提供示例代碼來幫助我嗎?

                  Everytime I pass the array to the processes each process creates a copy of that array which I donot want as I want a common array. Can anyone help me with this by providing sample code?

                  推薦答案

                  由于您只是將狀態(tài)從子進程返回到父進程,因此使用共享數(shù)組和顯式鎖是多余的.你可以使用 Pool.mapPool.starmap 來完成你所需要的.例如:

                  Since you're only returning state from the child process to the parent process, then using a shared array and explicity locks is overkill. You can use Pool.map or Pool.starmap to accomplish exactly what you need. For example:

                  from multiprocessing import Pool
                  
                  class Adder:
                      """I'm using this class in place of a monte carlo simulator"""
                  
                      def add(self, a, b):
                          return a + b
                  
                  def setup(x, y, z):
                      """Sets up the worker processes of the pool. 
                      Here, x, y, and z would be your global settings. They are only included
                      as an example of how to pass args to setup. In this program they would
                      be "some arg", "another" and 2
                      """
                      global adder
                      adder = Adder()
                  
                  def job(a, b):
                      """wrapper function to start the job in the child process"""
                      return adder.add(a, b)
                  
                  if __name__ == "__main__":   
                      args = list(zip(range(10), range(10, 20)))
                      # args == [(0, 10), (1, 11), ..., (8, 18), (9, 19)]
                  
                      with Pool(initializer=setup, initargs=["some arg", "another", 2]) as pool:
                          # runs jobs in parallel and returns when all are complete
                          results = pool.starmap(job, args)
                  
                      print(results) # prints [10, 12, ..., 26, 28] 
                  

                  這篇關(guān)于多處理 - 共享數(shù)組的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多處理模塊的 .join() 方法到底在做什么?)
                  Passing multiple parameters to pool.map() function in Python(在 Python 中將多個參數(shù)傳遞給 pool.map() 函數(shù))
                  multiprocessing.pool.MaybeEncodingError: #39;TypeError(quot;cannot serialize #39;_io.BufferedReader#39; objectquot;,)#39;(multiprocessing.pool.MaybeEncodingError: TypeError(cannot serialize _io.BufferedReader object,)) - IT屋-程序員軟件開
                  Python Multiprocess Pool. How to exit the script when one of the worker process determines no more work needs to be done?(Python 多進程池.當(dāng)其中一個工作進程確定不再需要完成工作時,如何退出腳本?) - IT屋-程序員
                  How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊列引用傳遞給 pool.map_async() 管理的函數(shù)?)
                  yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(與多處理錯誤的另一個混淆,“模塊對象沒有屬性“f)

                    1. <i id='SjLfp'><tr id='SjLfp'><dt id='SjLfp'><q id='SjLfp'><span id='SjLfp'><b id='SjLfp'><form id='SjLfp'><ins id='SjLfp'></ins><ul id='SjLfp'></ul><sub id='SjLfp'></sub></form><legend id='SjLfp'></legend><bdo id='SjLfp'><pre id='SjLfp'><center id='SjLfp'></center></pre></bdo></b><th id='SjLfp'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='SjLfp'><tfoot id='SjLfp'></tfoot><dl id='SjLfp'><fieldset id='SjLfp'></fieldset></dl></div>
                      <tfoot id='SjLfp'></tfoot>
                        <tbody id='SjLfp'></tbody>

                            <bdo id='SjLfp'></bdo><ul id='SjLfp'></ul>
                          • <legend id='SjLfp'><style id='SjLfp'><dir id='SjLfp'><q id='SjLfp'></q></dir></style></legend>

                            <small id='SjLfp'></small><noframes id='SjLfp'>

                          • 主站蜘蛛池模板: 九一精品| 美女视频h | 欧美大片一区 | 欧美久久久久久久 | 夏同学福利网 | 在线观看国产91 | 国产一区二区在线视频 | 一区二区三区小视频 | k8久久久一区二区三区 | 手机在线一区二区三区 | 网站黄色在线 | 国产精品一区二区av | 欧美综合一区二区三区 | 激情欧美一区二区三区中文字幕 | 国产精品视频一二三区 | 精品久久久av| 国产成人在线视频免费观看 | 亚洲精品福利在线 | 日韩精品久久 | 欧美精品久久一区 | 亚洲欧美中文日韩在线v日本 | 欧产日产国产精品国产 | 成人福利影院 | 999精品视频 | 免费网站国产 | 网站一区二区三区 | 嫩草视频入口 | 亚洲一区二区三区高清 | 亚洲成av人片在线观看 | 国产免费av在线 | 精品一区二区三区在线观看 | 精品一区二区三区在线观看国产 | 国产成人在线视频免费观看 | 国产精成人 | 欧美精品video | 久久成人国产 | 亚洲精品日本 | 日韩欧美精品在线播放 | 日本高清不卡视频 | 国产在线精品一区二区 | 日韩欧美中文字幕在线观看 |