1

I made a program for a chi square test, which works but was too slow, so I wanted to implement multiprossesing, but it didn't work for me (on a Windows machine). My CPU utilization goes to 100% and starts to fluctuate but i don't get further output. I tried it on a Linux machine and it worked without any problems. I found the problem online but not the solution.

def CalcMT(DIS):
    pool = mp.Pool(4)
    DIS = pool.map(CreateDistribution,[i for i in range(len(methods))])
    return DIS

if __name__ == "__main__":
    print("Start Computing")
    DIS = CalcMT(DIS)
    CHI=[ChiCalc(DIS[i]) for i in range(len(methods))]
    Output(DIS,CHI)
    Plot(DIS,CHI)
    exit()

This is the relevant part of the code. CreateDistribution gives back an array and DIS should be a 2D array.

Link to project

def CreateDistribution(type):
    AA = [0 for i in range(runrange)]

    if type==0:
        for i in range(sampals):
            x = rn.randint(0, len(AA)-1)
            AA[x] = AA[x]+1
        return AA

It's the same for the other types, just a different random number generator.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Movo
  • 11
  • 2
  • Impossible to say without a view of your CreateDistribution function – DarkKnight Feb 04 '22 at 15:02
  • I added it. It,s the same for the other types just a different randomnumbergenerator. – Movo Feb 06 '22 at 13:25
  • Try to remove global variables (`runrange, sampals, DIS,` pass them to functions as args). The fork works differently on Windows and Linux. On Windows, it swaps new empty processes and may not initialize correctly globals. – Askold Ilvento Feb 07 '22 at 11:02

0 Answers0