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

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

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

        具有全局變量的 multiprocessing.Pool

        multiprocessing.Pool with a global variable(具有全局變量的 multiprocessing.Pool)

        <legend id='3kDOW'><style id='3kDOW'><dir id='3kDOW'><q id='3kDOW'></q></dir></style></legend>
          <tbody id='3kDOW'></tbody>

        <small id='3kDOW'></small><noframes id='3kDOW'>

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

                • 本文介紹了具有全局變量的 multiprocessing.Pool的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我正在使用 python 多處理庫中的 Pool 類編寫一個將在 HPC 集群上運行的程序.

                  I am using the Pool class from python's multiprocessing library write a program that will run on an HPC cluster.

                  這是我正在嘗試做的抽象:

                  Here is an abstraction of what I am trying to do:

                  def myFunction(x):
                      # myObject is a global variable in this case
                      return myFunction2(x, myObject)
                  
                  def myFunction2(x,myObject):
                      myObject.modify() # here I am calling some method that changes myObject
                      return myObject.f(x)
                  
                  poolVar = Pool()
                  argsArray = [ARGS ARRAY GOES HERE]
                  output = poolVar.map(myFunction, argsArray)
                  

                  函數 f(x) 包含在 *.so 文件中,即它正在調用 C 函數.

                  The function f(x) is contained in a *.so file, i.e., it is calling a C function.

                  我遇到的問題是每次運行程序時輸出變量的值都不同(即使函數 myObject.f() 是確定性函數).(如果我只有一個進程,那么每次運行程序時輸出變量都是相同的.)

                  The problem I am having is that the value of the output variable is different each time I run my program (even though the function myObject.f() is a deterministic function). (If I only have one process then the output variable is the same each time I run the program.)

                  我嘗試創建對象而不是將其存儲為全局變量:

                  I have tried creating the object rather than storing it as a global variable:

                  def myFunction(x):
                      myObject = createObject()
                      return myFunction2(x, myObject)
                  

                  然而,在我的程序中,對象的創建成本很高,因此,創建一次 myObject 然后在每次調用 myFunction2() 時修改它要容易得多.因此,我不想每次都創建對象.

                  However, in my program the object creation is expensive, and thus, it is a lot easier to create myObject once and then modify it each time I call myFunction2(). Thus, I would like to not have to create the object each time.

                  你有什么建議嗎?我對并行編程很陌生,所以我可能會做錯這一切.我決定使用 Pool 類,因為我想從簡單的東西開始.但我愿意嘗試更好的方法.

                  Do you have any tips? I am very new to parallel programming so I could be going about this all wrong. I decided to use the Pool class since I wanted to start with something simple. But I am willing to try a better way of doing it.

                  推薦答案

                  我正在使用 python 多處理庫中的 Pool 類來做HPC 集群上的一些共享內存處理.

                  進程不是線程!不能簡單地將 Thread 替換為 Process 并期望所有進程都能正常工作.進程共享內存,這意味著全局變量被復制,因此它們在原始進程中的值不會改變.

                  Processes are not threads! You cannot simply replace Thread with Process and expect all to work the same. Processes do not share memory, which means that the global variables are copied, hence their value in the original process doesn't change.

                  如果你想在進程之間使用共享內存那么你必須使用multiprocessing的數據類型,例如ValueArray、或使用 Manager 創建共享列表等.

                  If you want to use shared memory between processes then you must use the multiprocessing's data types, such as Value, Array, or use the Manager to create shared lists etc.

                  您可能對 Manager.register 方法感興趣,該方法允許 Manager 創建共享的自定義對象(盡管它們必須是可挑選的).

                  In particular you might be interested in the Manager.register method, which allows the Manager to create shared custom objects(although they must be picklable).

                  但是我不確定這是否會提高性能.由于進程之間的任何通信都需要酸洗,而酸洗通常需要更多時間,然后只是實例化對象.

                  However I'm not sure whether this will improve the performance. Since any communication between processes requires pickling, and pickling takes usually more time then simply instantiating the object.

                  請注意,您可以在創建 initializer 和 initargs 參數對工作進程進行一些初始化.org/3.3/library/multiprocessing.html#multiprocessing.pool.Pool" rel="noreferrer">Pool.

                  Note that you can do some initialization of the worker processes passing the initializer and initargs argument when creating the Pool.

                  例如,以最簡單的形式,在工作進程中創建一個全局變量:

                  For example, in its simplest form, to create a global variable in the worker process:

                  def initializer():
                      global data
                      data = createObject()
                  

                  用作:

                  pool = Pool(4, initializer, ())
                  

                  那么worker函數就可以放心的使用data全局變量了.

                  Then the worker functions can use the data global variable without worries.

                  樣式說明:從不為您的變量/模塊使用內置名稱.在您的情況下, object 是內置的.否則,您最終會遇到意想不到的錯誤,這些錯誤可能晦澀難懂且難以追蹤.

                  Style note: Never use the name of a built-in for your variables/modules. In your case object is a built-in. Otherwise you'll end up with unexpected errors which may be obscure and hard to track down.

                  這篇關于具有全局變量的 multiprocessing.Pool的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多處理模塊的 .join() 方法到底在做什么?)
                  Passing multiple parameters to pool.map() function in Python(在 Python 中將多個參數傳遞給 pool.map() 函數)
                  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 多進程池.當其中一個工作進程確定不再需要完成工作時,如何退出腳本?) - IT屋-程序員
                  How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊列引用傳遞給 pool.map_async() 管理的函數?)
                  yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(與多處理錯誤的另一個混淆,“模塊對象沒有屬性“f)

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

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

                      <bdo id='BXF55'></bdo><ul id='BXF55'></ul>
                    • <tfoot id='BXF55'></tfoot>

                          <tbody id='BXF55'></tbody>
                          • <legend id='BXF55'><style id='BXF55'><dir id='BXF55'><q id='BXF55'></q></dir></style></legend>
                            主站蜘蛛池模板: 欧洲色综合 | 国产精品毛片va一区二区三区 | 天天摸夜夜操 | 成年免费视频黄网站在线观看 | 久久久久久久影院 | 激情网五月天 | 99热免费| 亚洲二级片 | 中文字幕在线免费播放 | 久久91精品 | 欧美理论在线观看 | 欧美精品日韩 | 91久久久久久久久 | 蜜桃一区二区 | igao在线观看 | 国产亚洲精品成人av久久ww | 久久精品视频国产 | 中文字幕第一区综合 | 日韩一级免费视频 | 刘玥大战28公分黑人 | 一级肉体裸体bbbb | 午夜国产在线观看 | 一区二区三区网站 | 高清一级片 | 日本黄色免费视频 | 四虎在线播放 | 男人爱看的网站 | 亚洲免费一区二区 | 日韩久久久久久久 | 欧美日韩三区 | 伊人9999| 视频一区二区三区在线观看 | 欧美日韩亚洲一区二区 | 亚洲国产精品va在线看黑人 | 天天cao| 美日韩在线 | 午夜国产福利 | 成人不卡视频 | 五月婷婷激情 | av黄色在线 | 99小视频|