Hi Tamás, Thanks for the quick response! I just tried this and with igraph_set_interruption_handler() it works great (already integrated with Mathematica).
Szabolcs On 29 August 2015 at 23:03, Tamas Nepusz <nta...@rmki.kfki.hu> wrote: > Hi Szabolcs, > > Not all igraph routines support interruptions, but those that do call > a macro named IGRAPH_ALLOW_INTERRUPTION() at regular intervals. This > macro will in turn call a so-called interruption handler, which you > can set with the igraph_set_interruption_handler() function (see > https://github.com/igraph/igraph/blob/master/src/interrupt.c). Within > the interruption handler, you must check whether the host environment > (Mathematica in your case) has signalled that the user wishes to > interrupt the computation. (For instance, in Python, I call the > PyErr_CheckSignals() function here). If the user wishes to interrupt > the computation, you must call IGRAPH_FINALLY_FREE() and then return > IGRAPH_INTERRUPTED; otherwise return IGRAPH_SUCCESS. See the Python > interface for an example: > > https://github.com/igraph/python-igraph/blob/master/src/igraphmodule.c#L147 > > I'm not sure how this translates to Mathematica - ideally, Mathematica > should have some kind of an internal flag that is set when the user > wishes to interrupt the computation. Your task would be to check this > flag whenever the interrupt handler is called. > > T. > > T. > > > On Sat, Aug 29, 2015 at 10:28 PM, Szabolcs Horvát <szhor...@gmail.com> wrote: >> Dear All, >> >> Does the C interface to igraph have any facility for >> aborting/interrupting computations that take very long? >> >> I assume it does because interrupting is possible with igraph/R. E.g. >> the following takes a long time: >> >> rewire(erdos.renyi.game(1000, 0.5, 'gnp'), keeping_degseq(niter=10000000)) >> >> But pressing the stop button in R cancels it without killing the R session. >> >> How is this implemented? >> >> So far I tried setting a status handler as follows: >> >> int igStatusHandler(const char *, void *) { return IGRAPH_INTERRUPTED; } >> >> igraph_set_status_handler(igStatusHandler); >> >> But igraph_rewire() still runs to the finish without interruption. >> >> Use case: I am working on a (partial) Mathematica interface and the >> ability to interrupt would be a big usability improvement. I was >> using igraph through the R interface from Mathematica before >> (https://github.com/szhorvat/IGraphR) but that has its limitations. >> >> Szabolcs >> >> _______________________________________________ >> igraph-help mailing list >> igraph-help@nongnu.org >> https://lists.nongnu.org/mailman/listinfo/igraph-help > > _______________________________________________ > igraph-help mailing list > igraph-help@nongnu.org > https://lists.nongnu.org/mailman/listinfo/igraph-help _______________________________________________ igraph-help mailing list igraph-help@nongnu.org https://lists.nongnu.org/mailman/listinfo/igraph-help