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

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

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

    <tfoot id='iZbEA'></tfoot>

  • <legend id='iZbEA'><style id='iZbEA'><dir id='iZbEA'><q id='iZbEA'></q></dir></style></legend>
        • <bdo id='iZbEA'></bdo><ul id='iZbEA'></ul>
      1. multiprocessing pool.map 按特定順序調用函數

        multiprocessing pool.map call functions in certain order(multiprocessing pool.map 按特定順序調用函數)
        • <bdo id='vNYSU'></bdo><ul id='vNYSU'></ul>

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

        • <legend id='vNYSU'><style id='vNYSU'><dir id='vNYSU'><q id='vNYSU'></q></dir></style></legend>
            <tbody id='vNYSU'></tbody>

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

                  本文介紹了multiprocessing pool.map 按特定順序調用函數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  如何讓 multiprocessing.pool.map 按數字順序分配進程?

                  How can I make multiprocessing.pool.map distribute processes in numerical order?

                  更多信息:
                  我有一個程序可以處理幾千個數據文件,為每個文件繪制一個圖.我正在使用 multiprocessing.pool.map 將每個文件分發(fā)到處理器,并且效果很好.有時這需要很長時間,在程序運行時查看輸出圖像會很好.如果 map 進程按順序分發(fā)快照,這會容易得多;相反,對于我剛剛執(zhí)行的特定運行,分析的前 8 個快照是:0、78、156、234、312、390、468、546.有沒有辦法讓它按數字順序更緊密地分布它們?

                  More Info:
                  I have a program which processes a few thousand data files, making a plot of each one. I'm using a multiprocessing.pool.map to distribute each file to a processor and it works great. Sometimes this takes a long time, and it would be nice to look at the output images as the program is running. This would be a lot easier if the map process distributed the snapshots in order; instead, for the particular run I just executed, the first 8 snapshots analyzed were: 0, 78, 156, 234, 312, 390, 468, 546. Is there a way to make it distribute them more closely to in numerical order?

                  示例:
                  這是一個包含相同關鍵元素的示例代碼,并顯示相同的基本結果:

                  Example:
                  Here's a sample code which contains the same key elements, and show's the same basic result:

                  import sys
                  from multiprocessing import Pool
                  import time
                  
                  num_proc  = 4; num_calls = 20; sleeper   = 0.1
                  
                  def SomeFunc(arg):
                      time.sleep(sleeper)
                      print "%5d" % (arg),
                      sys.stdout.flush()     # otherwise doesn't print properly on single line
                  
                  proc_pool = Pool(num_proc)
                  proc_pool.map( SomeFunc, range(num_calls) )
                  

                  產量:

                     0  4  2  6   1   5   3   7   8  10  12  14  13  11   9  15  16  18  17  19
                  

                  <小時>

                  答案:

                  來自@Hayden:使用chunksize"參數,def map(self, func, iterable, chunksize=None).

                  更多信息:
                  chunksize 決定了每次分配給每個處理器的迭代次數.例如,我上面的示例使用了 2 的塊大小——這意味著每個處理器關閉并在函數的 2 次迭代中執(zhí)行其操作,然后返回更多(簽入").chunksize 背后的權衡是,當處理器必須與其他處理器同步時,簽入"會產生開銷——這表明你想要一個 large chunksize.另一方面,如果你有大塊,那么一個處理器可能會完成它的塊,而另一個處理器還有很長的時間要走——所以你應該使用 small chunksize.我想額外的有用信息是有多少范圍,每個函數調用可以花費多長時間.如果它們真的都應該花費相同的時間 - 使用大塊大小會更有效.另一方面,如果某些函數調用的時間可能是其他函數的兩倍,那么您需要一個較小的塊大小,這樣處理器就不會等待.

                  More Info:
                  The chunksize determines how many iterations are allocated to each processor at a time. My example above, for instance, uses a chunksize of 2---which means that each processor goes off and does its thing for 2 iterations of the function, then comes back for more ('check-in'). The trade-off behind chunksize is that there is overhead for the 'check-in' when the processor has to sync up with the others---suggesting you want a large chunksize. On the other hand, if you have large chunks, then one processor might finish its chunk while another-one has a long time left to go---so you should use a small chunksize. I guess the additional useful information is how much range there is, in how long each function call can take. If they really should all take the same amount of time - it's way more efficient to use a large chunk size. On the other hand, if some function calls could take twice as long as others, you want a small chunksize so that processors aren't caught waiting.

                  對于我的問題,每個函數調用都應該花費非常接近相同的時間(我認為),所以如果我希望按順序調用進程,我會因為簽入而犧牲效率開銷.

                  For my problem, every function call should take very close to the same amount of time (I think), so if I want the processes to be called in order, I'm going to sacrifice efficiency because of the check-in overhead.

                  推薦答案

                  發(fā)生這種情況的原因是因為每個進程在調用 map 的開始時都被賦予了預定義的工作量,這取決于 塊大小.我們可以通過查看 chunksize">pool.map

                  The reason that this occurs is because each process is given a predefined amount of work to do at the start of the call to map which is dependant on the chunksize. We can work out the default chunksize by looking at the source for pool.map

                  chunksize, extra = divmod(len(iterable), len(self._pool) * 4)
                  if extra:
                    chunksize += 1
                  

                  因此,對于 20 個范圍和 4 個進程,我們將獲得 2 個的 chunksize.

                  So for a range of 20, and with 4 processes, we will get a chunksize of 2.

                  如果我們修改您的代碼以反映這一點,我們應該會得到與您現在得到的結果相似的結果:

                  If we modify your code to reflect this we should get similar results to the results you are getting now:

                  proc_pool.map(SomeFunc, range(num_calls), chunksize=2)

                  這會產生輸出:

                  0 2 6 4 1 7 5 3 8 10 12 14 9 13 15 11 16 18 17 19

                  現在,設置 chunksize=1 將確保池中的每個進程一次只分配一個任務.

                  Now, setting the chunksize=1 will ensure that each process within the pool will only be given one task at a time.

                  proc_pool.map(SomeFunc, range(num_calls), chunksize=1)

                  與未指定塊大小時相比,這應該確保相當好的數字排序.例如,塊大小為 1 會產生輸出:

                  This should ensure a reasonably good numerical ordering compared to that when not specifying a chunksize. For example a chunksize of 1 yields the output:

                  0 1 2 3 4 5 6 7 9 10 8 11 13 12 15 14 16 17 19 18

                  這篇關于multiprocessing pool.map 按特定順序調用函數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構造函數有未知關鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)

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

                        1. <legend id='jx8xs'><style id='jx8xs'><dir id='jx8xs'><q id='jx8xs'></q></dir></style></legend>

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

                            主站蜘蛛池模板: 久久免费精品 | aaa大片免费观看 | 欧美激情精品久久久久久免费 | 欧洲一区二区在线 | 热re99久久精品国99热观看 | 一区二区三区四区国产 | 91在线看| 一区二区成人 | 国产一区二区在线视频 | 国产一区二区影院 | 日韩一二三区 | 日韩视频一区二区在线 | 麻豆视频在线免费看 | 成人在线国产 | 1204国产成人精品视频 | 美女福利视频网站 | 日本三级在线视频 | 色偷偷人人澡人人爽人人模 | 中文字幕丁香5月 | 亚洲一区二区三区在线播放 | 国产成人网 | 国产综合精品 | 国产乱码精品一区二区三区五月婷 | 91久久久久久 | 亚洲欧美日韩高清 | 成人九色 | 日韩一区不卡 | 国产一区二区精 | 成人三区四区 | 欧美aⅴ | 免费在线观看黄色av | 成人乱人乱一区二区三区软件 | 日韩中文电影 | 日韩欧美三区 | 中文字幕福利视频 | 香蕉大人久久国产成人av | 在线三级电影 | 日韩欧美精品在线 | 日本国产欧美 | 国产在视频一区二区三区吞精 | 欧美日韩国产一区二区三区 |