Message Boards Message Boards

2
|
5346 Views
|
4 Replies
|
5 Total Likes
View groups...
Share
Share this post:

How to service preemptive computations while in a LibraryLink function?

Posted 9 years ago

Cross-posted to Mathematica.SE


The following is from the comparison between WSTP (MathLink) and LibraryLink in the documentation:

When the Wolfram Language is waiting for a WSTP application to return a result, it can be used to service preemptive computations such as those needed for user interface operations. When a library function is running this will not happen without effort by the author of the library.

(Emphasis by me.)

What do I need to do to allow for preemptive computations to be serviced while running LibraryLink functions?

Is there a function similar to libData->AbortQ() that I need to call from time to time? AbortQ() itself won't allow for this (I already checked). I did not find anything promising in WolframLibrary.h, but the documentation suggests that there should be a way.

POSTED BY: Szabolcs Horvát
4 Replies

This makes sense. Then it's sufficient to make a program abortable and it will also service preemptive computations.

In my question I said that I already tried AbortQ and that it did not work. I must have done something wrong, or perhaps didn't call it frequently enough. Now I tried again and it works.

POSTED BY: Szabolcs Horvát

I fixed the documentation, incidentally.

POSTED BY: John Fultz

I didn't know this myself until it came up in discussion recently. The right way to do this is to call libData->AbortQ().

Which makes sense given what I know of the kernel implementation. Both aborts and preemptive calls are kinds of interrupts, and I'm pretty sure that the implementation of interrupts in the kernel consistently checks for and services every kind of interrupt. But I agree that the name doesn't suggest this, and the documentation doesn't state it.

POSTED BY: John Fultz

The following works, but I am not sure of its performance impact and I worry that this is just an abuse of functionality meant for something else.

Periodically execute the following in the LibraryLink function (the same way you would call AbortQ())

MLINK lp = libData->getMathLink(libData);
libData->processMathLink(lp);

Is this the right way to do it?

POSTED BY: Szabolcs Horvát
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract