<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Dear Giacomo,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I solved the issue by wrapping the script with the "if __name__ == '__main__'" block, as you suggested.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Now the parallelization works fine both for the minimal example and the expensive black-box function.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Many thanks for your help!</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Best regards,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Cristina</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>Da:</b> Giacomo Nannicini <giacomo.n@gmail.com><br>
<b>Inviato:</b> sabato 14 marzo 2020 20:44<br>
<b>A:</b> Cristina Elsido <cristina.elsido@polimi.it>; rbfopt@list.coin-or.org <rbfopt@list.coin-or.org><br>
<b>Oggetto:</b> Re: [RBFOpt] Problem with parallelization</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">That seems to be a problem with the multiprocessing Python library.<br>
Maybe there is some recursive initialization going on.<br>
Did you properly wrap your script in a "if __name__ == '__main__'"<br>
block? The multiprocessing library imports the modules every time, so<br>
it may keep importing the main script if it is not inside such a<br>
block.<br>
However, you mention that this happens also with the minimal working<br>
examples, so I am a bit at a loss: that example works on every<br>
platform that I tried it on; this makes me think that the problem is<br>
with your particular platform, but I am not sure what's causing it.<br>
<br>
Could you tell me your configuration (architecture, python version)<br>
and post the script that you are trying to run? (Or a simpler version<br>
of it)<br>
<br>
G<br>
<br>
On Fri, Mar 13, 2020 at 6:27 AM Cristina Elsido<br>
<cristina.elsido@polimi.it> wrote:<br>
><br>
> Hi Giacomo,<br>
> Sorry that I was not clear. By getting stuck I mean that nothing happens and there is no output shown to screen.<br>
> In the serial case, this is the output printed in the console:<br>
><br>
> runfile('C:/Users/elsido/Desktop/Prove_Rbfopt/prova_serial.py', wdir='C:/Users/elsido/Desktop/Prove_Rbfopt')<br>
><br>
>   Iter  Cycle  Action             Objective value      Time      Gap<br>
><br>
>   ----  -----  ------             ---------------      ----      ---<br>
><br>
>      0      0  Initialization           -0.782797      3.02   100.00 *<br>
><br>
>      0      0  Initialization           59.515133      3.02   100.00<br>
><br>
>      0      0  Initialization           20.000000      3.02   100.00<br>
><br>
>      0      0  GlobalStep               26.484123      7.14   100.00<br>
><br>
>      1      0  GlobalStep               -9.996551      7.58   100.00 *<br>
><br>
>      2      0  GlobalStep                0.066845      7.91   100.00<br>
><br>
>      3      0  GlobalStep               -8.247187      8.19   100.00<br>
><br>
>      4      0  GlobalStep               -8.500124      8.56   100.00<br>
><br>
>      5      0  LocalStep               -10.000000      8.79   100.00 *<br>
><br>
>      6      1  GlobalStep               -0.010023      9.12   100.00<br>
><br>
>      7      1  GlobalStep               -7.460795      9.41   100.00<br>
><br>
>      8      1  GlobalStep               -9.941907      9.83   100.00<br>
><br>
>      9      1  GlobalStep               -9.992450     10.31   100.00<br>
><br>
>     10      1  GlobalStep               -9.992260     10.69   100.00<br>
><br>
>     11      1  LocalStep               -10.000000     10.94   100.00<br>
><br>
>     12      2  GlobalStep               99.331824     11.26   100.00<br>
><br>
>     13      2  GlobalStep               -5.108895     11.56   100.00<br>
><br>
>     14      2  GlobalStep               -9.874616     11.88   100.00<br>
><br>
>     15      2  GlobalStep               -9.892637     12.18   100.00<br>
><br>
>     16      2  GlobalStep               -9.997121     12.49   100.00<br>
><br>
>     17      2  LocalStep               -10.000000     12.77   100.00<br>
><br>
>     18      3  Discarded                              12.81<br>
><br>
>     19      3  GlobalStep               -0.001899     13.17   100.00<br>
><br>
>     20      3  GlobalStep               -5.979762     13.47   100.00<br>
><br>
>     21      3  GlobalStep               -7.675801     13.75   100.00<br>
><br>
>     22      3  GlobalStep               -9.963098     14.05   100.00<br>
><br>
>     23      3  GlobalStep               -9.999701     14.37   100.00<br>
><br>
>     24      3  LocalStep               -10.000000     14.96   100.00<br>
><br>
>     25      4  GlobalStep                0.305285     15.27   100.00<br>
><br>
>     26      4  GlobalStep               -8.985101     15.70   100.00<br>
><br>
>     27      4  GlobalStep               -9.902675     16.00   100.00<br>
><br>
>     28      4  GlobalStep               -9.987039     16.43   100.00<br>
><br>
>     29      4  GlobalStep               -9.976530     16.82   100.00<br>
><br>
>     30      4  LocalStep               -10.000000     17.14   100.00<br>
><br>
>     31      5  GlobalStep               87.907661     17.47   100.00<br>
><br>
>     32      5  GlobalStep               -5.088840     18.00   100.00<br>
><br>
>     33      5  GlobalStep               -9.915832     18.35   100.00<br>
><br>
>     34      5  GlobalStep               -9.999337     18.69   100.00<br>
><br>
>     35      5  GlobalStep               -9.580714     19.03   100.00<br>
><br>
>     36      5  LocalStep               -10.000000     19.41   100.00<br>
><br>
>     37      5  RefinementStep           -6.357577     19.56   100.00<br>
><br>
>     38      6  Discarded                              19.56<br>
><br>
>     39      6  GlobalStep               30.981585     20.00   100.00<br>
><br>
>     40      6  GlobalStep               -5.263918     20.38   100.00<br>
><br>
>     41      6  GlobalStep               -9.974259     20.93   100.00<br>
><br>
>     42      6  GlobalStep               -9.991540     21.24   100.00<br>
><br>
>     43      6  GlobalStep               -9.998681     21.59   100.00<br>
><br>
>     44      6  AdjLocalStep             -9.997359     22.15   100.00<br>
><br>
>     45      7  Discarded                              22.16<br>
><br>
>     46      7  GlobalStep               36.620812     22.57   100.00<br>
><br>
>     47      7  GlobalStep               -4.323961     23.02   100.00<br>
><br>
>     48      7  GlobalStep               -8.752531     23.57   100.00<br>
><br>
>     49      7  GlobalStep               -9.999654     23.94   100.00<br>
><br>
> Summary: iters  50 evals  50 noisy_evals   0 cycles   7 opt_time   23.94 tot_time   24.09 obj       -10.000000 gap 100.00<br>
><br>
><br>
>  In the parallel case (num_cpus=2):<br>
><br>
> runfile('C:/Users/elsido/Desktop/Prove_Rbfopt/prova_parallel.py', wdir='C:/Users/elsido/Desktop/Prove_Rbfopt')<br>
><br>
>   Iter  Cycle  Action             Objective value      Time      Gap<br>
><br>
>   ----  -----  ------             ---------------      ----      ---<br>
><br>
><br>
> In addition, I have tried adding the following lines at the beginning and at the end of my script:<br>
><br>
> beginning<br>
> import logging<br>
> logging.basicConfig(filename='example_parallel.log', level=logging.DEBUG)<br>
> logging.info('Started')<br>
> end<br>
> logging.info('Finished')<br>
><br>
> As a result, in the serial case a file was printed with the following content:<br>
><br>
> INFO:root:Started<br>
> INFO:root:Finished<br>
><br>
><br>
> Instead, in the parallel case I obtained a list of several "INFO:root:Started", and it was being updated continuously until I stop the code.<br>
><br>
> Please let me know if I can provide additional information to solve the problem.<br>
> Thanks for your help!<br>
> Best regards,<br>
> Cristina<br>
><br>
> ________________________________<br>
> Da: Giacomo Nannicini <giacomo.n@gmail.com><br>
> Inviato: giovedì 12 marzo 2020 19:40<br>
> A: Cristina Elsido <cristina.elsido@polimi.it><br>
> Cc: rbfopt@list.coin-or.org <rbfopt@list.coin-or.org><br>
> Oggetto: Re: [RBFOpt] Problem with parallelization<br>
><br>
> Hi Cristina,<br>
> could you be more specific about "getting stuck"? Can you post a log<br>
> of the parallel and serial version on your problem?<br>
> The minimal working example seems to work fine, even in parallel mode.<br>
> There are many "Discarded" iterations and a few restarts, but that's<br>
> because the algorithm finds the optimum after a few iterations and<br>
> afterward realizes that the model is not improving, hence the<br>
> restarts.<br>
><br>
> G<br>
><br>
> On Thu, Mar 12, 2020 at 1:42 PM Cristina Elsido<br>
> <cristina.elsido@polimi.it> wrote:<br>
> ><br>
> > Hi,<br>
> > First of all thank you for your work and for sharing the Rbfopt library.<br>
> > I have recently downloaded Rbfopt (v4.1.1). I would like to use Rbfopt for the optimization of an expensive black-box function (about 10' per evaluation), but I am experiencing some problems with parallelization. I noticed that if I run an optimization
 problem with the parameter "num_cpus" larger than 1, the optimization gets 'stuck', showing no output or progress even for many hours.<br>
> ><br>
> > I have also tested the parallel version of the optimizer with the minimum working example, and I got the same problem (instead, the serial version with the same parameters except for the num_cpus was solved in few seconds). Here is the script I used:<br>
> ><br>
> > import rbfopt<br>
> > import numpy as np<br>
> ><br>
> > def obj_funct(x):<br>
> >   return x[0]*x[1] - x[2]<br>
> ><br>
> > bb = rbfopt.RbfoptUserBlackBox(3, np.array([0] * 3), np.array([10] * 3),<br>
> >                                np.array(['R', 'I', 'R']), obj_funct)<br>
> > settings = rbfopt.RbfoptSettings(max_evaluations=50,num_cpus=4,print_solver_output=False,algorithm='Gutmann')<br>
> > alg = rbfopt.RbfoptAlgorithm(settings, bb)<br>
> > val, x, itercount, evalcount, fast_evalcount = alg.optimize()<br>
> ><br>
> ><br>
> > Should I use different settings for parallelization? Which parameters do you recommend for the parallel optimizer?<br>
> > Thanks in advance for your help.<br>
> > Best regards,<br>
> > Cristina Elsido, PhD<br>
> > _______________________________________________<br>
> > RBFOpt mailing list<br>
> > RBFOpt@list.coin-or.org<br>
> > <a href="https://list.coin-or.org/mailman/listinfo/rbfopt">https://list.coin-or.org/mailman/listinfo/rbfopt</a><br>
</div>
</span></font></div>
</body>
</html>