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

    <legend id='c9GAl'><style id='c9GAl'><dir id='c9GAl'><q id='c9GAl'></q></dir></style></legend>

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

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

      <bdo id='c9GAl'></bdo><ul id='c9GAl'></ul>
    1. 对每个进程使用具有不同随机种子的 python 多处理

      时间:2023-05-26
      <legend id='kuAVL'><style id='kuAVL'><dir id='kuAVL'><q id='kuAVL'></q></dir></style></legend>
    2. <small id='kuAVL'></small><noframes id='kuAVL'>

          <tfoot id='kuAVL'></tfoot>

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

                <bdo id='kuAVL'></bdo><ul id='kuAVL'></ul>

                本文介绍了对每个进程使用具有不同随机种子的 python 多处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我希望并行运行多个模拟实例,但每个模拟都有自己独立的数据集.

                I wish to run several instances of a simulation in parallel, but with each simulation having its own independent data set.

                目前我实现如下:

                P = mp.Pool(ncpus) # Generate pool of workers
                for j in range(nrun): # Generate processes
                    sim = MDF.Simulation(tstep, temp, time, writeout, boundaryxy, boundaryz, relax, insert, lat,savetemp)
                    lattice = MDF.Lattice(tstep, temp, time, writeout, boundaryxy, boundaryz, relax, insert, lat, kb, ks, kbs, a, p, q, massL, randinit, initvel, parangle,scaletemp,savetemp)
                    adatom1 = MDF.Adatom(tstep, temp, time, writeout, boundaryxy, boundaryz, relax, insert, lat, ra, massa, amorse, bmorse, r0, z0, name, lattice, samplerate,savetemp)        
                    P.apply_async(run,(j,sim,lattice,adatom1),callback=After) # run simulation and ISF analysis in each process
                P.close()
                P.join() # start processes  
                

                其中 simadatom1lattice 是传递给启动模拟的函数 run 的对象.

                where sim, adatom1 and lattice are objects passed to the function run which initiates the simulation.

                但是,我最近发现,我同时运行的每个批次(即,每个 ncpus 都用完模拟运行的总 nrun 次)给出完全相同的结果.

                However, I recently found out that each batch I run simultaneously (that is, each ncpus runs out of the total nrun of simulations runs) gives the exact same results.

                这里有人可以指导如何解决这个问题吗?

                Can someone here enlighten how to fix this?

                推荐答案

                只是想我会添加一个实际答案以使其他人清楚.

                Just thought I would add an actual answer to make it clear for others.

                引用 aix 的答案in this问题:

                Quoting the answer from aix in this question:

                发生的情况是,在 Unix 上,每个工作进程都继承相同的来自父进程的随机数生成器的状态.这是为什么它们会生成相同的伪随机序列.

                What happens is that on Unix every worker process inherits the same state of the random number generator from the parent process. This is why they generate identical pseudo-random sequences.

                使用 random.seed() 方法(或 scipy/numpy 等价物)正确设置种子.另请参阅这个 numpy 线程.

                Use the random.seed() method (or the scipy/numpy equivalent) to set the seed properly. See also this numpy thread.

                这篇关于对每个进程使用具有不同随机种子的 python 多处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Python多处理错误:AttributeError:模块'__main__'没 下一篇:将 Python Twisted 与多处理混合使用?

                相关文章

                最新文章

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

                <i id='OYJa2'><tr id='OYJa2'><dt id='OYJa2'><q id='OYJa2'><span id='OYJa2'><b id='OYJa2'><form id='OYJa2'><ins id='OYJa2'></ins><ul id='OYJa2'></ul><sub id='OYJa2'></sub></form><legend id='OYJa2'></legend><bdo id='OYJa2'><pre id='OYJa2'><center id='OYJa2'></center></pre></bdo></b><th id='OYJa2'></th></span></q></dt></tr></i><div id='OYJa2'><tfoot id='OYJa2'></tfoot><dl id='OYJa2'><fieldset id='OYJa2'></fieldset></dl></div>
                  <legend id='OYJa2'><style id='OYJa2'><dir id='OYJa2'><q id='OYJa2'></q></dir></style></legend>
                1. <tfoot id='OYJa2'></tfoot>

                    • <bdo id='OYJa2'></bdo><ul id='OYJa2'></ul>