久久久久久久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的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時送ChatGPT賬號..

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

                  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)
                  

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

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

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

                  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.)

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

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

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

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

                  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 類,因?yàn)槲蚁霃暮唵蔚臇|西開始.但我愿意嘗試更好的方法.

                  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 集群上的一些共享內(nèi)存處理.

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

                  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.

                  如果你想在進(jìn)程之間使用共享內(nèi)存那么你必須使用multiprocessing的數(shù)據(jù)類型,例如ValueArray、或使用 Manager 創(chuàng)建共享列表等.

                  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 創(chuàng)建共享的自定義對象(盡管它們必須是可挑選的).

                  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).

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

                  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.

                  請注意,您可以在創(chuàng)建 initializer 和 initargs 參數(shù)對工作進(jìn)程進(jìn)行一些初始化.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.

                  例如,以最簡單的形式,在工作進(jìn)程中創(chuàng)建一個全局變量:

                  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函數(shù)就可以放心的使用data全局變量了.

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

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

                  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.

                  這篇關(guān)于具有全局變量的 multiprocessing.Pool的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 多進(jìn)程池.當(dāng)其中一個工作進(jìn)程確定不再需要完成工作時,如何退出腳本?) - IT屋-程序員
                  How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊(duì)列引用傳遞給 pool.map_async() 管理的函數(shù)?)
                  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>
                            主站蜘蛛池模板: 日韩中文字幕视频 | 日韩中文字幕在线视频观看 | 久久久综合网 | 一级a爱片久久毛片 | 国产精品一区二区电影 | 国产精品久久久久国产a级 欧美日本韩国一区二区 | www.国产精品 | 亚洲福利电影网 | 在线免费观看黄视频 | 日日操操操 | 国产一区欧美一区 | 粉嫩一区二区三区国产精品 | 人人九九 | 亚洲国产精品久久久久秋霞不卡 | 99爱免费 | 99这里只有精品视频 | 国精产品一品二品国精在线观看 | 久久成人人人人精品欧 | 亚洲一区在线播放 | 亚洲综合在线网 | 成年人网站在线观看视频 | 欧美激情国产精品 | 狠狠干网站| 国产成人福利 | 精品国产三级 | 青娱乐av | av在线视 | 91综合网 | 精品一区二区三区免费视频 | 国产高清视频在线观看播放 | 久久国产精品亚洲 | 欧美日韩在线视频一区 | 国产a爽一区二区久久久 | 久久精品国产一区 | 狠狠狠干| 久久精品亚洲国产奇米99 | 国产资源网 | 搞av.com | 国产精品自拍一区 | 久久久久久久久久久福利观看 | 精品一区二区三区在线视频 |