<div dir="ltr"><div>We just recently ran into exactly the same issue calling Cbc to solve individual subproblems in parallel within our decomposition framework (DIP). Rather than calling CbcMain*, we are now just directly calling the branchAndBound of CbcModel and it seems to be working fine, though I haven&#39;t looked into how the performance compares. John can probably say what the difference is between the two methods of calling Cbc. For example, see the code starting here:<br>

<br><a href="https://projects.coin-or.org/Dip/browser/trunk/Dip/src/DecompModel.cpp#L234">https://projects.coin-or.org/Dip/browser/trunk/Dip/src/DecompModel.cpp#L234</a><br><br></div>This is also how Cbc is called within Couenne (and probably Bonmin as well). I believe Couenne was also successfully using Cbc in parallel. Couenne probably does this a bit more smartly (in terms of setting parameters, etc.). You can poke around this file:<br>

<div><br><a href="https://projects.coin-or.org/Couenne/browser/trunk/Couenne/src/main/CouenneBab.cpp">https://projects.coin-or.org/Couenne/browser/trunk/Couenne/src/main/CouenneBab.cpp</a><br><br></div><div>for ideas.<br>

<br>Cheers,<br><br>Ted<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Dec 17, 2013 at 10:34 AM, John Forrest <span dir="ltr">&lt;<a href="mailto:john.forrest@fastercoin.com" target="_blank">john.forrest@fastercoin.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    <div>Cornelius,<br>
      <br>
      static variables were used just because that was the way a main
      program became callable.  Some work was started a few years ago to
      improve - I will have another look to see what minimum work needs
      to be done to make CbcMain0/1 calls threadsafe.<br>
      <br>
      John Forrest<div><div class="h5"><br>
      <br>
      On 17/12/13 15:11, Cornelius Riemenschneider wrote:<br>
    </div></div></div>
    <blockquote type="cite"><div><div class="h5">
      
      
      <div>
        <p class="MsoNormal">Hello,</p>
        <p class="MsoNormal">we use CBC via googles or-tools from java
          in our application.</p>
        <p class="MsoNormal">Compared to scientific problems, our
          problems are small and solved by Cbc in &lt;1s (which is
          great!).</p>
        <p class="MsoNormal">As we process requests from users
          concurrently, we’d also like to call Cbc concurrently.</p>
        <p class="MsoNormal">Currently, this is impossible, because Cbc
          uses the static parameters array in CbcMain0 and CbcMain1 and
          thus crashes or reads incorrect parameters.</p>
        <p class="MsoNormal">One backtrace, for example is:</p>
        <p class="MsoNormal"> </p>
        <p class="MsoNormal">#2 0x00007fb3435bf52b in __libc_message
          (do_abort=&lt;optimized out&gt;, fmt=&lt;optimized out&gt;) at
          ../sysdeps/unix/sysv/linux/libc_fatal.c:189<br>
          #3 0x00007fb3435c8d76 in malloc_printerr (action=3,
          str=0x7fb3436a1248 &quot;double free or corruption (!prev)&quot;,
          ptr=&lt;optimized out&gt;) at malloc.c:6283<br>
          #4 0x00007fb3435cdaac in *__GI___libc_free (mem=&lt;optimized
          out&gt;) at malloc.c:3738<br>
          #5 0x00007fb342733f06 in std::string::assign(std::string
          const&amp;) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6<br>
          #6 0x00007fb2d652cb7b in establishParams(int&amp;,
          CbcOrClpParam*) () from libjnilinearsolver.so<br>
          #7 0x00007fb2d64edc3b in CbcMain0(CbcModel&amp;) () from
          libjnilinearsolver.so<br>
          #8 0x00007fb2d6511bec in callCbc(char const*, CbcModel&amp;)
          () from libjnilinearsolver.so<br>
          #9 0x00007fb2d64e3fce in
          operations_research::CBCInterface::Solve(operations_research::MPSolverParameters
          const&amp;) () from libjnilinearsolver.so<br>
          #10 0x00007fb2d64cfe45 in
          operations_research::MPSolver::Solve(operations_research::MPSolverParameters
          const&amp;) () from libjnilinearsolver.so<br>
          #11 0x00007fb2d64cff3b in
          operations_research::MPSolver::Solve() () from
          libjnilinearsolver.so<br>
          #12 0x00007fb2d64c91cf in
          Java_com_google_ortools_linearsolver_mainJNI_MPSolver_1solve_1_1SWIG_10
          () from libjnilinearsolver.so</p>
        <p class="MsoNormal"># from here on it’s just the JVM</p>
        <p class="MsoNormal"> </p>
        <p class="MsoNormal">As I don’t know the code and it’s hard to
          read, I can’t really fix the problem by myself,</p>
        <p class="MsoNormal">but wouldn’t it be better to move
          parameters inside CbcModel instead of having a static array
          laying around?</p>
        <p class="MsoNormal"> </p>
        <p class="MsoNormal">Andi f that’s done (or another solution is
          found), do you know of any thread-safety issues in cbc?</p>
        <p class="MsoNormal">Keep in mind, we don’t want Cbc to solve
          our problem in multiple threads, we just want to be able to
          solve different problems simultaneous.</p>
        <p class="MsoNormal"> </p>
        <p class="MsoNormal">Regards,</p>
        <p class="MsoNormal"><span>Cornelius Riemenschneider</span></p>
        <p class="MsoNormal"><span>--</span></p>
        <p class="MsoNormal"><span>ITscope GmbH</span></p>
        <p class="MsoNormal"><span>Ludwig-Erhard-Allee 20</span></p>
        <p class="MsoNormal"><span>76131 Karlsruhe</span></p>
        <p class="MsoNormal"><span>Email: <a href="mailto:cornelius.riemenschneider@itscope.de" target="_blank">cornelius.riemenschneider@itscope.de</a></span></p>
        <p class="MsoNormal"><span><a href="https://www.itscope.com" target="_blank">https://www.itscope.com</a></span></p>
        <p class="MsoNormal"><span>Handelsregister: AG Mannheim, HRB
            232782</span></p>
        <p class="MsoNormal"><span>Sitz der Gesellschaft: Karlsruhe</span></p>
        <p class="MsoNormal"><span>Geschäftsführer: Alexander Münkel,
            Benjamin Mund, Stefan Reger</span></p>
        <p class="MsoNormal"> </p>
      </div>
      <br>
      <fieldset></fieldset>
      <br>
      </div></div><pre>_______________________________________________
Cbc mailing list
<a href="mailto:Cbc@list.coin-or.org" target="_blank">Cbc@list.coin-or.org</a>
<a href="http://list.coin-or.org/mailman/listinfo/cbc" target="_blank">http://list.coin-or.org/mailman/listinfo/cbc</a>
</pre>
    </blockquote>
    <br>
  </div>

<br>_______________________________________________<br>
Cbc mailing list<br>
<a href="mailto:Cbc@list.coin-or.org">Cbc@list.coin-or.org</a><br>
<a href="http://list.coin-or.org/mailman/listinfo/cbc" target="_blank">http://list.coin-or.org/mailman/listinfo/cbc</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Dr. Ted Ralphs<br>Associate Professor, Lehigh University<br>(610) 628-1280<br>ted &#39;at&#39; lehigh &#39;dot&#39; edu<br><a href="http://coral.ie.lehigh.edu/~ted" target="_blank">coral.ie.lehigh.edu/~ted</a><br>


</div>