Message Boards Message Boards

Changes in MathLink in Version 10 ?

POSTED BY: Frank Kampas
28 Replies
Posted 4 years ago
POSTED BY: TRAN ANH
Posted 4 years ago

Hi Tran. Did you ever solve this problem? I have the same issue.

Thanks,

POSTED BY: Chase Vaughn
Posted 9 years ago

Thanks, that worked! I added this directory to the PATH variable:

enter image description here

POSTED BY: nat dlsantos
Posted 9 years ago

Is this change from MathLink to "Wolfram Symbolic Transfer Protocol", the reason why I'm getting this error msg from Mathematica Link:

"MathLink libraries are not installed or outdated. Before linking, you must install Mathematica or the latest version of the MathLink libraries."

I have installed Mathematica 10..2.0.0, Excel 2013 32-bit and MLinkforExcel_3.6.0. Inside Excel. ExcelLink works fine inside Mathematica but MathLink is not accessible from inside Excel.

Any help would be appreciated. Thanks.MathLink error msg

POSTED BY: nat dlsantos

I might be completely wrong about this, but I seem to recall reading somewhere that the MathLink dynamic libraries (DLLs) used to be installed system-wide (in C:\Windows\system32 maybe?) before, but they are not since some recent version of Mathematica. You might try finding the libraries (presumably i3 versions, not i4; also make sure you copy the MathLink ones, not the WSTP one) in the Mathematica installation directory, and copying them next to the ExcelLink executable, if it has one.

I have never worked with ExcelLink, so I am not familiar with how it works.

To answer your question: I don't think this is because of the renaming to WSTP. The ML-prefixe version still ships with Mathematica and new versions of Mathematica are still compatible with old MathLink programs.

POSTED BY: Szabolcs Horvát

@SteveWilson

I'm right now investigating a bug report for MATLink on Linux. It appears that cycling a string through MATLink appends a zero character code at the end somehow, on Linux only (but not on OS X). I still haven't gotten to the bottom of the issue, and it is possible that I'm using the MathLink API incorrectly, but it looks more like a bug. I'm going to report it once I have had the time to create a minimal test case, but I wanted to give you advance warning.

enter image description here

The zero is likely appended when sending the string through MathLink the first time, not when receiving it back the Mma kernel.

The sending function is as simple as this:

void eng_make_String(const unsigned short *str, int len, int characters) {
    mwSize mbDims[2] = {1, len}; // use len, not characters, because no support for 4-byte characters in either Mma 9 or MATLAB
    mxArray *var = mxCreateCharArray(2, mbDims);
    std::copy(str, str+len, (unsigned short *) mxGetChars(var));
    returnHandle(var);
}

with template:

:Begin:
:Function:   eng_make_String
:Pattern:     engMakeString[string_]
:Arguments:     {string}
:ArgumentTypes: {UTF16String}
:ReturnType:    Manual
:End:

(You can actually ignore the guts of the functions, as it's MATLAB-specific code, but I thought a bit of context is always good. Also, I'm not sure it's still true that MathLink doesn't support UTF16 characters that need to be stored on 4 (not 2) bytes).

POSTED BY: Szabolcs Horvát
POSTED BY: Szabolcs Horvát
POSTED BY: Steve Wilson

Steve, I am sorry for your loss.

I will summarize my findings and send them to support next weekend, so you can receive them next week.

POSTED BY: Szabolcs Horvát
POSTED BY: Steve Wilson
POSTED BY: Szabolcs Horvát
POSTED BY: Steve Wilson
POSTED BY: Szabolcs Horvát

Some LibraryLink code I wrote using MathLink to transfer data still works in Version 10, even though the functions have been deprecated. I imagine that means it won't work when Version 11 comes out.

POSTED BY: Frank Kampas

The LibraryLink interface that includes MathLink is very much tied to the interface used internally by the Kernel. If the Kernel is using MathLink interface 4, then the LibraryLink dlls need updated to support interface 4. The deprecated functions may continue to work for a time, however, as all things deprecated go, WRI may eventually remove those API functions from the interface altogether in a future release.

POSTED BY: Steve Wilson
POSTED BY: Steve Wilson

Thank you for the response!

Will Installable MathLink programs compiled with the default MLINTERFACE 4 and linked against ML64i4 still work with earlier Mathematica versions?

For example, let's assume that we have the source code for an installable MathLink program that worked with some older version of Mathematica. Now I re-run mprep and re-compile the program, linking it against ML64i4 or ML32i4. Will the resulting binary be usable with older versions of Mathematica, e.g. Mathematcia 8 or 9?


I know that I can #define MLINTERFACE 3 and link against ML64i3 for compatibility, but the question is whether this is necessary?

POSTED BY: Szabolcs Horvát

The programs compiled and linked with the interface 4 version of the library should indeed work with older versions of Mathematica. I assume at some point you will run into issues such as older operating systems that will eventually result in incompatibilities the further you go back with your Mathematica revisions, but if you can run the two copies of Mathematica on the same machine, then your newer binary should work with the older Kernel.

POSTED BY: Steve Wilson

Thanks for the reply! Then from now on I'll distribute binaries linked against interface 4.

Some more questions, just out of curiosity:

  • How does the new "IntraProcess" protocol perform for transferring large data? I'm asking because LibraryLink currently doesn't allow returning complex datatypes. For example, it's not possible to return both a matrix and a tensor from the same function, and returning them via multiple LibraryLink functions has the potential to introduce a mess (it forces me to maintain a library state, which isn't a good fit for Mathematica as it prefers side-effect-less functions). I think transferring very large packed arrays was already quite fast with MathLink with the "SharedMemory" protocol, but I'm not sure about many small arrays (or the overhead for each transfer).

  • Did MathLink receive any performance improvements in version 10, and generally does it have any advantages to link against interface 4 if I'm not using any interface 4 only features?

POSTED BY: Szabolcs Horvát
POSTED BY: Steve Wilson

MathLink did receive performance enhancements in Version 10 with respect to string and symbol transfers. These enhancements are automatically enabled with communicating with another Version 10 MathLink library and disabled when communicating with an older version of the library.

Are these performance enhancements present even if I compile with -DMLINTERFACE=3 -lML64i3 (but using the libraries shipped with v10)?

In other words, does linking against libML64i4 have any benefits if I do not actually use any of the interface version 4 functions?

POSTED BY: Szabolcs Horvát

Could you please take a look at this question?

POSTED BY: Szabolcs Horvát

Is there an option for mprep that causes it to output Interface 3 compatible code?

Also, have you seen this type of linking error with v10 on Linux? libML64i3.so: undefined reference to `uuid_parse'

POSTED BY: Szabolcs Horvát

You can find a helpful description of the changes in Interface 4 at http://reference.wolfram.com/language/tutorial/WSTPInterface4.html.

POSTED BY: Steve Wilson

This is very useful. I didn't find this page myself.

POSTED BY: Szabolcs Horvát
POSTED BY: Frank Kampas

I should have probably called it interface version 4, I'm not sure which is the official term used by WRI. It just means that the version number has been changed, which means that compatiblity with other interface versions is not guaranteed (new functions may be added, old functions removed or the calling syntax may change).

There is a seprate versioning for the public documented MathLink C interface and for the MathLink library. When the MathLink library gets a bugfix, the API to access it does not necessarily change. The API didn't change between Mathematica 8 and Mathematica 9, to my knowledge. But don't quote me on this, I'm not an expert on the topic.

POSTED BY: Szabolcs Horvát

The interface level has been bumped to 4. If you look in mathlink.h, you'll find a list of new functions and a list of removed functions (quoted at the end). The functions can be looked up in the documentation. There's probably more to say here, and I'm curious about the changes too.

I also noticed that parallel kernels launch much faster in version 10, which is likely due to MathLink changes.


The name chage, in my opinion, is pretty counterproductive. Renaming all API functions (used for engineering) just because of a marketing decision (!!) to rebrand the system is just wrong and I don't see how it could bring aything but trouble ...

Now Mathematica comes with two separate directories, one for MathLink and one for WSTP. The two look identical other than the renaming. One contains the libraries and header files with the ML prefixed functions, the other one has the WS prefixed functions.


    /*
     * Interface 4 adds the following exported functions:
     *
     * MLCreateLinkWithExternalProtocol
     * MLDoNotHandleSignalParameter
     * MLEnableLinkLock
     * MLFilterArgv
     * MLGetAvailableLinkProtocolNames
     * MLGetInteger8
     * MLGetInteger8Array
     * MLGetInteger8ArrayData
     * MLGetInteger8List
     * MLGetLinksFromEnvironment
     * MLGetNumberAsByteString
     * MLGetNumberAsString
     * MLGetNumberAsUCS2String
     * MLGetNumberAsUTF16String
     * MLGetNumberAsUTF32String
     * MLGetNumberAsUTF8String
     * MLHandleSignal
     * MLIsLinkLoopback
     * MLLinkEnvironment
     * MLLogFileNameForLink
     * MLLogStreamToFile
     * MLLowLevelDeviceName
     * MLPutInteger8
     * MLPutInteger8Array
     * MLPutInteger8ArrayData
     * MLPutInteger8List
     * MLPutRealNumberAsUCS2String
     * MLPutRealNumberAsUTF16String
     * MLPutRealNumberAsUTF32String
     * MLPutRealNumberAsUTF8String
     * MLReleaseInteger8Array
     * MLReleaseInteger8List
     * MLReleaseLinkProtocolNames
     * MLReleaseLinksFromEnvironment
     * MLReleaseLogFileNameForLink
     * MLReleaseLowLevelDeviceName
     * MLReleaseParameters
     * MLSetThreadSafeLinksParameter
     * MLStopHandlingSignal
     * MLStopLoggingStream
     * MLValid
     * MLWaitForLinkActivity
     * MLWaitForLinkActivityWithCallback
     *
     * Interface 4 removes the following API functions.
     *
     ....
     */
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