Python Forum

Full Version: Need help parallelizing while loop
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,

I need some help parallelizing the following:

 
population = []

generations = 100000
generation = 1

while generation < (generations + 1):
        params = {
            'num_char': 100,
            'variables': 'X',
            'constants': 'F+-',
            'axiom': 'FX',
            'rules': {
                'X': {
                    'options': ['+FX', '-FX'],
                    'probabilities': [0.5, 0.5]
                }
            },
            'point': np.array([0, 0]),
            'vector': np.array([0, 1]),
            'length': 1.0,
            'angle': 25  # random
        }

        generation += 1

        population.append(Creature(params).coords) 
I believe joblib's Parallel may be useful but I am unsure of how to feed the params dictionary as well as combining the outputs into a single list

Thank you