Questions tagged [mathlink-or-wstp]

MathLink is a suite of Mathematica functions that implement a protocol for the communication/interfacing of Mathematica with external programs.

Filter by
Sorted by
Tagged with
47 votes
1 answer
2k views

Transferring a large amount of data in parallel calculations

Bug fixed in version 11.1 Functions like MemberQ, FreeQ, etc. no longer unpack. Yay! This question is inspired by one of @...
  • 228k
121 votes
7 answers
13k views

Minimal effort method for integrating C++ functions into Mathematica

Update: While at the time of writing the question loading DLLs with .NET/Link seemed easier, now I always use LibraryLink, which I recommend to anyone with a similar problem! As of Mathematica 8, ...
  • 228k
31 votes
2 answers
2k views

What is the complete list of valid FrontEnd Packet types?

In response to my question How can I get the unchanged Box form of an arbitrary expression? John Fultz answered with a method using the hilariously named ...
  • 265k
70 votes
6 answers
31k views

How to use Mathematica functions in Python programs?

I'd like to know how can I call Mathematica functions from Python. I appreciate a example, for example, using the Mathematica function Prime. I had search about MathLink but how to use it in Python ...
  • 1,436
13 votes
1 answer
841 views

Passing back "NaN`" and "Inf`" to C via MathLink

In the "usual" double representation of floating point numbers in C there is a NaN and an Inf...
  • 228k
22 votes
2 answers
614 views

MathKernel doesn't return all Messages

In Mathematica I run this command: Plot[Sin[x], {x, 1, 15}, GridLines -> error] It generates a Plot with this error message: A GridLines specification ...
  • 1,412
12 votes
1 answer
756 views

How to set up LinkSnooper for monitoring FrontEnd--Kernel communication?

What is the simplest way to set up LinkSnooper to monitor the communication between the Kernel and the Front End? I am looking for an answer that works on all platforms, including 32-bit Windows.
  • 9,909
25 votes
6 answers
1k views

Returning multiple results from a LibraryLink function

What is the best way to return multiple inhomogeneous results from a LibraryLink function? Imagine that the result of a single computation is several tensors of different dimensions and several ...
  • 228k
28 votes
4 answers
8k views

Efficiently determining if 3D points are within a surface composed of polygons

This is the 2nd part of a previous question which I edited to make into 2 separate questions: Extracting polygons from 3D contour plot surface As an extension of my earlier question involving simple ...
  • 9,502
18 votes
1 answer
568 views

MathLink (WSTP) vs LibraryLink performance

Has anyone benchmarked LibraryLink vs MathLink when passing large arrays? Specifically I would like to know how performance compares when using the following to pass and return a large array: ...
  • 228k
33 votes
3 answers
2k views

Calling IronPython code from Mathematica

I'd like to call some IronPython code from Mathematica using .NET/Link. The problem is that the code lives in .py files, yet from Mathematica I can only load .NET assemblies which are DLLs. So it ...
  • 1,607
14 votes
1 answer
1k views

How to run mathlink external commands in parallel?

I have an external function called increment (for the sake of illustration) that I call from Mathematica using MathLink. I.e., ...
  • 4,941
11 votes
1 answer
2k views

Example program for calling Mathematica from C

I want to call Mathematica from a C program. Suppose I have two numbers x = 2 and y = 3. I want to define ...
  • 111
19 votes
1 answer
1k views

What is the difference between MathLink and WSTP? Which one should I use?

What is the difference between MathLink and WSTP programs? Will the use of MathLink protocol be maintained or not?
  • 191
11 votes
1 answer
2k views

Using Mathlink with the cernlib FORTRAN package MINUIT

I could successfully use Mathlink to call a simple fortran subroutine. However, when I went to a realistic problem, I failed. To be specific, I want to fit a set of data with some function using the ...
  • 1,477
8 votes
1 answer
204 views

How to send packed array from math kernel to 3rd party app via WSTP

Background I'm developing a small python wrapper PyWSTP. The wrapper is still in very early stage and lacking features. One important feature I'm considering is transferring dense array between math ...
  • 676
29 votes
1 answer
1k views

Asynchronous Programming

Consider that you would like to listen for Raw WiFi Packets coming into your NIC. Since Mathematica doesn't have built-in functions for such low level programming (as far as I know), one alternative ...
23 votes
2 answers
882 views

Multiplayer game in Mathematica: how to communicate between kernels?

This may have been asked already, but I am considering making a game in Mathematica that two people can play. However, the issue with my idea is that the other player can't view the cards of the first ...
17 votes
5 answers
2k views

Connecting to and disconnecting from a continuously running kernel, on demand

I realized that there are lots of advantages to driving C/C++/FORTRAN code directly from Mathematica as LibraryLink functions (instead of running them from the command line or a shell script, as I ...
  • 228k
13 votes
1 answer
601 views

How to use RunProcess to import external function?

I have a functions written in an external language called GO. How can I quickly load them into the kernel for use as Mathematica functions? The two ways I've tried are with MathLink and LibraryLink ...
  • 3,551
11 votes
1 answer
643 views

WSTP broken by upgrade to 10.0.1?

Bug introduced v10.0.1 and fixed in 10.0.2 Everything was working fine with WSTP (the successor to MathLink) in 10.0.0. But I upgraded to 10.0.1 today and now I can't compile either my programs (I've ...
  • 8,658
7 votes
1 answer
220 views

Can you trigger update of Dynamic elements from a LinkedLibrary?

Is it possible to write a LinkedLibrary (or WSTP executable) computing a function f such that Dynamic@f[] is updated when the ...
  • 5,619
3 votes
1 answer
422 views

How could get all escape characters in Mathematica?

I am evaluating expression by using KernelLink. But the kernel will be suspended endless when meets a invalid escape character. ...
  • 491
15 votes
4 answers
2k views

Correct way to handle mysterious NaN` result from MathLink function

I have a Mathematica expression that is mapped onto an external C function via MathLink. The external function passes a ...
  • 4,941
14 votes
2 answers
553 views

Link server WSTP API feature not receiving incoming connections

I'd like to apologize ahead of time that this may be a very long post but want to get all of this out there. Also, this post really only pertains to those with WSTP/MathLink experience. My problem ...
  • 582
14 votes
3 answers
2k views

Using LinkSnooper for monitoring the communication with an installable MathLink program

How can I monitor the communication between an installable MathLink program and the kernel? Can LinkSnooper do this?
  • 228k
13 votes
2 answers
809 views

Connect Frontend to Kernel Started by JVM via JLink

I have a MathKernel started and controlled via JLink from a JVM. The $CommandLine for this kernel is: ...
  • 733
11 votes
1 answer
936 views

Running .NET/Link on Mono (On MacOS or any UNIX or Linux Distro)

Has anyone have any luck running .NET/Link on Mono? When I run .NET/Link to call Mathematica from within a Mono program, this is the error message I receive. ...
  • 213
9 votes
1 answer
464 views

How can I wrap a C++ object in WSTP?

I am trying to wrap a sophisticated C/C++ API in Mathematica using WSTP, but can't work out how to return a pointer to a C/C++ data structure. This object was created on the C/C++ side of the wrapper, ...
  • 126
9 votes
2 answers
575 views

Is it possible to set a timeout for LinkWrite[]?

This came up in relation to this answer Is it possible to set a timeout for LinkWrite? LinkWrite seems to block until the sent ...
  • 228k
9 votes
1 answer
376 views

Suppress Mathematica Kernel taskbar tab when using .NETLink

Is there a possibility to suppress the Mathematica Kernel taskbar tab when accessing it through .NETLink on Windows?
  • 93
7 votes
1 answer
204 views

Throwing away all expression on a loopback link

What is the simplest way to throw away all expressions waiting to be read on a loopback link, effectively resetting the link? I am building an expression on a loopback link using the C MathLink ...
  • 228k
6 votes
1 answer
207 views

Wrapping a C library with a streaming interface

I've tried to give this a generic title to help future searchers, but concretely I am trying to parse YAML data. Import doesn't seem to support it natively and I ...
  • 720
5 votes
2 answers
537 views

A bug fix to mathematica 10.0.1.0

There is a bug in the Wolfram Symbolic Transfer Protocol Development in C (Windows). I described it in the next answer by myself, from which I summarize: One cannot successfully compile the ...
5 votes
1 answer
587 views

Reconnecting to remote kernels through SSH tunnelling

This is a follow up question to How can I connect to a remote machine? and the excellent answer provided by ybeltukov. My system is now configured as described in the answer with my MacBook running ...
  • 241
4 votes
1 answer
435 views

Convert C program using mathlink to WSTP

I have been using heavily a custom frontend to mathematica based on mathlink. I derived it from http://library.wolfram.com/infocenter/Demos/174/frontend.c?file_id=4692 . I just learned that mathlink ...
  • 1,640
2 votes
2 answers
218 views

Where to place the essential WSTP files in Visual Studio 2019?

I have Visual Studio for C installed in : C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC From https://reference.wolfram.com/language/tutorial/WSTPDeveloperGuide-Windows.html : "...
19 votes
1 answer
427 views

Control Front End in "mathlink" mode

Note: This question was already posted in the Wolfram community. In a terminal math session, we can start a front end (FE) easily by launching it though ...
  • 111k
18 votes
3 answers
5k views

Write C/C++ programs calling Mathematica functions

I need to write a C/C++ program and call some functions in Mathematica especially those like Solve or NDSolve. The problem is ...
  • 421
18 votes
1 answer
1k views

Calling Mathematica from Visual Studio - example

I am trying to set up a connection between Visual Studio 10 and Mathematica 8.0 on a Windows system. I found several sources of information on the Wolfram website, but I get entirely lost. Most of the ...
  • 183
14 votes
1 answer
1k views

How to run an external program in parallel with a Mathematica package?

Under Mathematica 8 (Linux x84_64) I was able to run an external program in parallel from a Mathematica package. However this procedure breaks down under Mathematica 9. Within my Mathematica package ...
12 votes
1 answer
1k views

MathLink error while calling a custom Mathematica function - MLGet out of sequence

I am trying to call Mathematica 10 from F#. Following the C# sample code found in the Mathematica directory, I have written the following F# code: ...
  • 4,871
11 votes
3 answers
25k views

MathLink linking error after OS X 10.9 (Mavericks) upgrade

After macosx 10.9 mavericks upgrade i have a compilation problem, you can see below. Even the examples given in /Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/MacOSX-x86-64/...
11 votes
1 answer
206 views

Why does LinkRead block when LinkReadyQ returns True?

The LinkRead documentation states: LinkRead will wait until it has read a complete expression before returning. You can test ...
  • 228k
10 votes
1 answer
2k views

Mathematica NDSolve and 'Compile'?

Since the consensus is usually that NDSolve speeds fares badly against compiled code such as c++ ODE solvers using GSL say, is it possible to make up for this lag ...
  • 2,095
9 votes
0 answers
774 views

Configuring remote access when using a VPN

To address some of the responsiveness issues, I use the Mathematica front end (v9 or v10) to access a remote kernel on a Raspberry Pi. The (advanced) kernel configuration used is this: Arguments to ...
8 votes
1 answer
174 views

Pass symbols through MathLink with full context information

How can I ensure that symbols passed through MathLink retain their full context information? When using MathLink naively, they do not. Demonstration, controlling another kernel: ...
  • 228k
8 votes
1 answer
470 views

Has anybody been able to build WSTP applications under Visual Studio 2015's IDE?

I recently picked up an old project involving WSTP (formerly MathLink) programs, and as a starting place tried to get the demos provided by Wolfram to compile. The instructions were dated, referring ...
8 votes
1 answer
406 views

Type conversion: LibraryLink mint vs. MathLink integer type

Assume the following situation: I have a WolframLibrary function which gets as parameter an integer tensor (which is for simplicity of rank 1) and the function should return an integer list through ...
  • 111k
7 votes
1 answer
219 views

Tools for MathLink traffic analysis?

I noticed that the documentation for LinkSnooper says that it is "obsolete". I don't have any experience with this tool, but I thought it looked interesting after seeing results it was able to provide ...
  • 4,251