Welcome to the forums. Please post in English or French.

You are not logged in.

#1 2020-07-23 05:02:39

aep93
Member
Registered: 2020-02-21
Posts: 27

Parallelization of a python loop

Hello all,
How can I make a python loop inside my comm file parallel?
I think the mpi and openMP versions of code aster can only deal with code_aster commands and when I have a python loop, I should make it parallel manually. But how is that possible?
I tried to use the following command in my comm file:

DEBUT(PAR_LOT='NON',);
from joblib import Parallel, delayed
import multiprocessing
NN=5;
inputs = range(NN) 

def processInput(i):
     (tasks inside my loop)

# numm is nuber of cores
numm=4
results=Parallel(n_jobs=numm)(delayed(processInput)(i) for i in inputs)

FIN();
 

However, when I put it inside my comm file I get the following error:

"OSError: aster_core must be initialized before (see aster_core.register)"
How should I initialize my  aster_core?

I also changed the "ncpus" in my export file and put it equal to 4 (number of cores in my code). However, the problem was not solved.
Thanks in advance

Last edited by aep93 (2020-07-23 05:09:19)

Offline

#2 2020-08-02 07:43:32

phoenix22
Member
Registered: 2017-02-20
Posts: 25

Re: Parallelization of a python loop

Hello,
It's better for everyone to check with your mess file (and the mesh file if needed).
I am sorry that I cannot help you to answer your question directly, but I recommend that the parallelization can be easily obtained via U2.08.07 (Parametric calculations).
Regards,
Phoenix,

Offline

#3 2020-08-02 17:06:02

ing.nicola
Member
Registered: 2017-12-11
Posts: 51

Re: Parallelization of a python loop

why you use multiprocessing if you don't use it?
Basic usage:

    pool=multiprocessing.Pool(<num_cores>)
    pool.map(<function>,<iterbale object>)
    pool.close()
    pool.join()

Last edited by ing.nicola (2020-08-02 17:07:46)

Offline