[BCP] Invoking BCP as a subroutine in a larger program

Dani danielpa at wanadoo.es
Tue Sep 2 12:59:24 EDT 2008


I would say that removing the exit call leaves a lot of memory unreachable
since it's supposed to be freed by the process destruction procedure.

Try launching your own process:

// For fork().
#include <unistd.h>
// For waitpid().
#include <sys/wait.h>

...

void MyClass::launch() {

int res = -1;

if ((res = fork()) == 0) {
  // Child process

  // Initializations is your class inheriting from USER_initialize
  Initializations init;

  bcp_main(0, NULL, &init);
}
else if (res > 0) {
  // Parent process

  int status = 0;

  waitpid(res,&status,0);

  assert(WIFEXITED(status));
}
else {
  // error forking
}
}


I don't know if it's the best way to go but it works for me.

Dani Pérez.


On Tue, Sep 2, 2008 at 5:49 PM, Eric W Anderson
<Eric.Anderson at colorado.edu>wrote:

> I'm new to using BCP, so I apologize if this is a dumb question:  Is there
> a
> right way to invoke a BCP-based solver as a subroutine?  I see that
> bcp_main
> terminates with exit(), at least in serial mode, rather than returning.  If
> I
> comment out the exit(0) call in BCP_single_environment::register_process(),
> and
> my application calls bcp_main(), everything seems to work as intended.
>
> It seems like this is actively subverting the way BCP wants to be run,
> though,
> so I'm wondering: (a) is there a hidden pitfall to doing what I'm doing,
> and
> (b) is there a better way to be doing it?
>
> Thanks for any help,
> Eric
>
> --
> Eric W. Anderson                                   University of Colorado
> eric.anderson at colorado.edu                      Dept. of Computer Science
> phone: +1-720-984-8864                   Systems Research Lab - ECCR 1B54
>
>                         PGP key fingerprints:
>       personal: 1BD4 CFCE 8B59 8D6E EA3E  EBD5 4DC9 3E61 656C 462B
>       academic: D3C5 D6FF EDED 9F1F C36D  53A3 74B7 53A6 3C74 5F12
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQFIvWCBdLdTpjx0XxIRAtv+AJ0X2brpHmeML1BjQz1tLpMItU24fgCffjZ2
> cVaXoVM71rxqLyiCUqRpK1Q=
> =D/BK
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> BCP mailing list
> BCP at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/bcp
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://list.coin-or.org/pipermail/bcp/attachments/20080902/14eb08c7/attachment.html 


More information about the BCP mailing list