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

  • <legend id='Rso1o'><style id='Rso1o'><dir id='Rso1o'><q id='Rso1o'></q></dir></style></legend>

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

    1. <tfoot id='Rso1o'></tfoot>

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

        具有單個函數的 Python 多處理

        Python Multiprocessing with a single function(具有單個函數的 Python 多處理)

        <legend id='YtnJ5'><style id='YtnJ5'><dir id='YtnJ5'><q id='YtnJ5'></q></dir></style></legend>
          <tbody id='YtnJ5'></tbody>

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

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

                2. 本文介紹了具有單個函數的 Python 多處理的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我有一個當前正在運行的模擬,但 ETA 大約需要 40 小時 - 我正在嘗試通過多處理來加速它.

                  I have a simulation that is currently running, but the ETA is about 40 hours -- I'm trying to speed it up with multi-processing.

                  它本質上迭代了一個變量 (L) 的 3 個值,以及第二個變量 (a) 的 99 個值.使用這些值,它實際上運行了一個復雜的模擬并返回 9 個不同的標準偏差.因此(盡管我還沒有這樣編碼)它本質上是一個函數,它接受兩個值作為輸入 (L,a) 并返回 9 個值.

                  It essentially iterates over 3 values of one variable (L), and over 99 values of of a second variable (a). Using these values, it essentially runs a complex simulation and returns 9 different standard deviations. Thus (even though I haven't coded it that way yet) it is essentially a function that takes two values as inputs (L,a) and returns 9 values.

                  這是我擁有的代碼的精髓:

                  Here is the essence of the code I have:

                  STD_1 = []
                  STD_2 = []
                  # etc.
                  
                  for L in range(0,6,2):
                      for a in range(1,100):
                          ### simulation code ###
                          STD_1.append(value_1)
                          STD_2.append(value_2)
                          # etc.
                  

                  以下是我可以修改的內容:

                  Here is what I can modify it to:

                  master_list = []
                  
                  def simulate(a,L):
                      ### simulation code ###
                      return (a,L,STD_1, STD_2 etc.)
                  
                  for L in range(0,6,2):
                      for a in range(1,100): 
                          master_list.append(simulate(a,L))
                  

                  由于每個模擬都是獨立的,因此它似乎是實現某種多線程/處理的理想場所.

                  Since each of the simulations are independent, it seems like an ideal place to implement some sort of multi-threading/processing.

                  我將如何編寫這個代碼?

                  How exactly would I go about coding this?

                  另外,是否所有內容都會按順序返回到主列表,或者如果多個進程正在工作,它可能會出現故障?

                  Also, will everything be returned to the master list in order, or could it possibly be out of order if multiple processes are working?

                  編輯 2:這是我的代碼——但它運行不正確.它詢問我是否想在我運行程序后立即終止它.

                  EDIT 2: This is my code -- but it doesn't run correctly. It asks if I want to kill the program right after I run it.

                  import multiprocessing
                  
                  data = []
                  
                  for L in range(0,6,2):
                      for a in range(1,100):
                          data.append((L,a))
                  
                  print (data)
                  
                  def simulation(arg):
                      # unpack the tuple
                      a = arg[1]
                      L = arg[0]
                      STD_1 = a**2
                      STD_2 = a**3
                      STD_3 = a**4
                      # simulation code #
                      return((STD_1,STD_2,STD_3))
                  
                  print("1")
                  
                  p = multiprocessing.Pool()
                  
                  print ("2")
                  
                  results = p.map(simulation, data)
                  

                  編輯 3:還有什么是多處理的限制.我聽說它不能在 OS X 上運行.這是正確的嗎?

                  EDIT 3: Also what are the limitations of multiprocessing. I've heard that it doesn't work on OS X. Is this correct?

                  推薦答案

                  • 將每次迭代的數據包裝成一個元組.
                  • 列出這些元組的data
                  • 編寫函數f處理一個元組并返回一個結果
                  • 創建 p = multiprocessing.Pool() 對象.
                  • 調用results = p.map(f, data)
                    • Wrap the data for each iteration up into a tuple.
                    • Make a list data of those tuples
                    • Write a function f to process one tuple and return one result
                    • Create p = multiprocessing.Pool() object.
                    • Call results = p.map(f, data)
                    • 這將運行盡可能多的 f 實例,因為您的機器在不同進程中擁有內核.

                      This will run as many instances of f as your machine has cores in separate processes.

                      Edit1:示例:

                      from multiprocessing import Pool
                      
                      data = [('bla', 1, 3, 7), ('spam', 12, 4, 8), ('eggs', 17, 1, 3)]
                      
                      def f(t):
                          name, a, b, c = t
                          return (name, a + b + c)
                      
                      p = Pool()
                      results = p.map(f, data)
                      print results
                      

                      多處理應該可以在 OSX 等類 UNIX 平臺上正常工作.只有缺少 os.fork 的平臺(主要是 MS Windows)需要特別注意.但即使在那里它仍然有效.請參閱多處理文檔.

                      Multiprocessing should work fine on UNIX-like platforms such as OSX. Only platforms that lack os.fork (mainly MS Windows) need special attention. But even there it still works. See the multiprocessing documentation.

                      這篇關于具有單個函數的 Python 多處理的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)
                  <legend id='5WY1m'><style id='5WY1m'><dir id='5WY1m'><q id='5WY1m'></q></dir></style></legend>

                3. <tfoot id='5WY1m'></tfoot>

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

                        <small id='5WY1m'></small><noframes id='5WY1m'>

                          <tbody id='5WY1m'></tbody>

                          • <bdo id='5WY1m'></bdo><ul id='5WY1m'></ul>

                            主站蜘蛛池模板: wwww.xxxx免费| 成人国产精品久久久 | 欧美一区二区三区四区五区无卡码 | 人人射人人| av网站在线看 | 国产小视频在线 | 91在线免费视频 | 欧美国产日本一区 | 成人精品在线视频 | 国产在线拍偷自揄拍视频 | 亚洲字幕在线观看 | 久久久青草婷婷精品综合日韩 | 国产精品久久性 | 51ⅴ精品国产91久久久久久 | 亚洲乱码国产乱码精品精98午夜 | 欧美精品第一页 | 日韩电影免费在线观看中文字幕 | 日本在线视频不卡 | 日韩一区中文字幕 | 国产欧美一区二区三区在线看 | 久久乐国产精品 | 日韩中文不卡 | 欧美成人精品一区二区男人看 | 国产精品久久精品 | 亚洲精品一区中文字幕乱码 | 午夜免费观看体验区 | 亚洲高清视频在线观看 | 国产精品久久久久久久久污网站 | 成人在线电影网站 | 国产精品日韩高清伦字幕搜索 | 国产清纯白嫩初高生视频在线观看 | 亚洲欧美日韩在线不卡 | 一区二区三区四区在线免费观看 | 91精品国产综合久久久久久 | 超碰在线播 | 日本精品视频 | 视频一区二区三区中文字幕 | jlzzjlzz国产精品久久 | 久久久久久久一区 | 日韩精品久久一区二区三区 | 国产精品日韩高清伦字幕搜索 |