Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #13835 > unrolled thread

Getting an array into a C program through mathlink

Started byBrentt <brenttnewman@gmail.com>
First post2013-03-14 11:12 +0000
Last post2013-04-04 17:10 +0000
Articles 6 — 4 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Getting an array into a C program through mathlink Brentt <brenttnewman@gmail.com> - 2013-03-14 11:12 +0000
    Re: Getting an array into a C program through mathlink debguy <johnandsara2@cox.net> - 2013-04-01 04:57 +0000
    Re: Getting an array into a C program through mathlink John Fultz <jfultz@wolfram.com> - 2013-04-02 07:26 +0000
    Re: Getting an array into a C program through mathlink "John D. Hendrickson and Sara Darnell" <johnandsara2@cox.net> - 2013-04-03 08:08 +0000
    Re: Getting an array into a C program through mathlink John Fultz <jfultz@wolfram.com> - 2013-04-04 02:50 +0000
    Re: Getting an array into a C program through mathlink "John D. Hendrickson and Sara Darnell" <johnandsara2@cox.net> - 2013-04-04 17:10 +0000

#13835 — Getting an array into a C program through mathlink

FromBrentt <brenttnewman@gmail.com>
Date2013-03-14 11:12 +0000
SubjectGetting an array into a C program through mathlink
Message-ID<khsbap$35l$1@smc.vnet.net>
Hello, I've been wrestling with this example code from the manual to try to
get a numerical array to a C program through mathlink. But how does one set
up the template file for this kind of program (e.g. setting up a pattern to
actually call the program in Mathematica)? I tried to guess how to write a
template for this code, but nothing seemed to work (primarily errors about
incompatible types).

void f(MLINK lp)
> {
>     double *data;
>     int *dims;
>     char **heads;
>     int d; /* stores the rank of the array */
>
>     if(! MLGetReal64Array(lp, &data, &dims, &heads, &d))
>         {
>             /* unable to read the array from lp */
>             return;
>         }
>
>     /* ... */
>
>     MLReleaseReal64Array(lp, data, dims, heads, d);
> }
>

 I've got some functions using simple data types working using Mathlink,
and I even go the MLPut*Array type functions working. It's just getting an
array from mathematica in to an external (C) program that I haven't found
much detailed information in the manual about. A lot of examples like these
that aren't really functional as is.

Thank you in advance

[toc] | [next] | [standalone]


#13992

Fromdebguy <johnandsara2@cox.net>
Date2013-04-01 04:57 +0000
Message-ID<kjb43l$8jq$1@smc.vnet.net>
In reply to#13835
my advice is to avoid mathlink because library issues cause
compatibility problems (see Wolfram problem reports).  ie after or
without upgrade it's broken for someone trying to use.

if you can accept fast but not fastest results I suggest this:

to use "exec" in C to call math binary with piped commands (we're
talking text input output) and use Put to get what into a file (can
even be forked, run in background, doing it that way).  then your
application reads file when done (fread is fast, maybe not fast as
direct read from mathlink).

most tasks can be done without ever using C.  doing some special
graphics or something?

[toc] | [prev] | [next] | [standalone]


#14010

FromJohn Fultz <jfultz@wolfram.com>
Date2013-04-02 07:26 +0000
Message-ID<kje169$h03$1@smc.vnet.net>
In reply to#13835
That's an interesting observation, but I can't say it matches my own 
experience.  I've found MathLink to be remarkably compatible across 
major version number changes of Mathematica, and to be generally robust. 
 It is the only way the FE and the kernel communicate with each other 
(not to mention other lesser components of the system), and the nature 
of that connection is not simple; I would say it uses a majority of the 
features that MathLink has to offer.

It's not clear to me exactly what you're referring to as "Wolfram 
problem reports".  But I'd certainly be interested in knowing about any 
issues that you or anyone else may be experiencing with MathLink.

John Fultz
jfultz@wolfram.com
User Interface Group
Wolfram Research, Inc.



On Apr 1, 2013, at 12:00 AM, debguy <johnandsara2@cox.net> wrote:

> my advice is to avoid mathlink because library issues cause
> compatibility problems (see Wolfram problem reports).  ie after or
> without upgrade it's broken for someone trying to use.
>
> if you can accept fast but not fastest results I suggest this:
>
> to use "exec" in C to call math binary with piped commands (we're
> talking text input output) and use Put to get what into a file (can
> even be forked, run in background, doing it that way).  then your
> application reads file when done (fread is fast, maybe not fast as
> direct read from mathlink).
>
> most tasks can be done without ever using C.  doing some special
> graphics or something?
>

[toc] | [prev] | [next] | [standalone]


#14033

From"John D. Hendrickson and Sara Darnell" <johnandsara2@cox.net>
Date2013-04-03 08:08 +0000
Message-ID<kjgo1g$put$1@smc.vnet.net>
In reply to#13835
Ok I think you asked for a little more info about why mathlink which 
seems fine on developer's machine might not be fine elsewhere.

Why is because to work mathlink needs to link against OS libraries 
which change.

http://reference.wolfram.com/mathematica/tutorial/MathLinkDeveloperGuide-Unix.html#725481284

clearly says it is library hooked and versional to specific libraries.

http://support.wolfram.com/search/?query=mathlink&lang=en&noImg=1&submit.x=0&submit.y=0

are some problem reports of:

LinkConnect::"linkc": "\!\(\[LeftSkeleton] 1 \[RightSkeleton]\) is 
dead; attempt to connect failed."

(there were many unsure if wr has removed them.  or search Google and 
find some.  it's hard to believe you looked hard if you can't find any.)

For example I have Mathematix Version zzz.  I later upgrade Linux. 
Mathlink is now broken.  I may be able to run simple pre-compiled ones 
(unlikely to be available for my exact linux disto) but most won't 
work because the libs have changed or they are for a different linux 
distro.  You'd think "just recompile mathlink apps".  NO.

To resolve this I need to run Mathematica and any mathlink apps in a 
chroot of a previous Linux version.  Compilation of other people's 
mathlink apps would also have to be done in the chroot - which won't 
work for newer mathlink apps.  Too much effort.

You'd think I can just compile against older libs: surprise that works 
at compile time but not run-time since libML.a is loaded accessed 
through the newer libs and it is older: IT WON'T EVER WORK.

My other choice is to buy new mathematica.  But if I had any mathlink 
apps I needed I'd have to rewrite them since they won't compile with 
the new linux libs / environment.  This also requires a new computer. 
$$  And how long is it until it's all broken again?

(obviously upgrading Mathematica is better if you have time and money 
for the "upgrade escapade")

(Note I mean Linux distribution, the linux kernel isn't usually 
involved.  unlike the old days: often binaries today often won't work 
when copied from one distro to another, due to lib variations they 
keep uploading)

Obviously there's another answer: wolfram releases a different 
mathlink that doesn't rely on lib offsets runtime :)  I won't go into 
it but I know what breaks it.

--------------------------------

John Fultz wrote:
> That's an interesting observation, but I can't say it matches my own experience.  I've found MathLink to be remarkably compatible across major version number changes of Mathematica, and to be generally robust.  It is the only way the FE and the kernel communicate with each other (not to mention other lesser components of the system), and the nature of that connection is not simple; I would say it uses a majority of the features that MathLink has to offer.
> 
> It's not clear to me exactly what you're referring to as "Wolfram problem reports".  But I'd certainly be interested in knowing about any issues that you or anyone else may be experiencing with MathLink.
> 
> John Fultz
> jfultz@wolfram.com
> User Interface Group
> Wolfram Research, Inc.
> 
> 
> 
> On Apr 1, 2013, at 12:00 AM, debguy <johnandsara2@cox.net> wrote:
> 
>> my advice is to avoid mathlink because library issues cause
>> compatibility problems (see Wolfram problem reports).  ie after or
>> without upgrade it's broken for someone trying to use.
>>
>> if you can accept fast but not fastest results I suggest this:
>>
>> to use "exec" in C to call math binary with piped commands (we're
>> talking text input output) and use Put to get what into a file (can
>> even be forked, run in background, doing it that way).  then your
>> application reads file when done (fread is fast, maybe not fast as
>> direct read from mathlink).
>>
>> most tasks can be done without ever using C.  doing some special
>> graphics or something?
>>
> 
> 

[toc] | [prev] | [next] | [standalone]


#14044

FromJohn Fultz <jfultz@wolfram.com>
Date2013-04-04 02:50 +0000
Message-ID<kjipqg$3k9$1@smc.vnet.net>
In reply to#13835
If MathLink is broken, Mathematica is broken.  MathLink is not just some 
toss-off library used in a few corner cases by a few random users and 
barely supported by Wolfram.  It is a core part of the system, and if 
it's busted, Mathematica won't even run.  I could point to a dozen 
binaries in the Mathematica distribution that work MathLink harder than 
most user programs do, but I really only need to point to two -- the 
Mathematica kernel and the Mathematica front end.  MathLink is the one 
and only mechanism by which these two components communicate with each 
other.

It is true that there can be dependencies on versions of operating 
systems and libraries.  And to maintain maximum compatibility with a 
wide range of systems, we're very careful about which build systems and 
libraries we build our binaries (MathLink, FE, kernel, etc.) against, 
generally favoring somewhat older versions so we don't accidentally 
slurp in newer dependencies that could break on legacy systems.  The 
range of operating systems and libraries Mathematica (and thus MathLink) 
work against are generally pretty well advertised, and we've done a 
pretty good job of supporting operating systems at least 5 years out of 
date (save on MacOS, where the user culture tends to be highly 
aggressive about updating operating systems, so the support window is a 
bit shorter).

In summary, I would claim that, to the extent that your worries about 
MathLink are true, they apply to Mathematica itself.  The fact that 
Mathematica is not constantly broken on every new Linux distribution 
suggests that your concerns, while not invalid, are not as serious as 
you seem to suggest.

Sincerely,

John Fultz
jfultz@wolfram.com
User Interface Group
Wolfram Research, Inc.



On Apr 2, 2013, at 5:04 PM, "John D. Hendrickson and Sara Darnell" <johnandsara2@cox.net> wrote:

> Ok I think you asked for a little more info about why mathlink which seems fine on developer's machine might not be fine elsewhere.
>
> Why is because to work mathlink needs to link against OS libraries which change.
>
> 
http://reference.wolfram.com/mathematica/tutorial/MathLinkDeveloperGuide-Unix.html#725481284
>
> clearly says it is library hooked and versional to specific libraries.
>
> 
http://support.wolfram.com/search/?query=mathlink&lang=en&noImg=1&submit.x=0&submit.y=0
>
> are some problem reports of:
>
> LinkConnect::"linkc": "\!\(\[LeftSkeleton] 1 \[RightSkeleton]\) is dead; attempt to connect failed."
>
> (there were many unsure if wr has removed them.  or search Google and find some.  it's hard to believe you looked hard if you can't find any.)
>
> For example I have Mathematix Version zzz.  I later upgrade Linux. Mathlink is now broken.  I may be able to run simple pre-compiled ones (unlikely to be available for my exact linux disto) but most won't work because the libs have changed or they are for a different linux distro.  You'd think "just recompile mathlink apps".  NO.
>
> To resolve this I need to run Mathematica and any mathlink apps in a chroot of a previous Linux version.  Compilation of other people's mathlink apps would also have to be done in the chroot - which won't work for newer mathlink apps.  Too much effort.
>
> You'd think I can just compile against older libs: surprise that works at compile time but not run-time since libML.a is loaded accessed through the newer libs and it is older: IT WON'T EVER WORK.
>
> My other choice is to buy new mathematica.  But if I had any mathlink apps I needed I'd have to rewrite them since they won't compile with the new linux libs / environment.  This also requires a new computer. $$  And how long is it until it's all broken again?
>
> (obviously upgrading Mathematica is better if you have time and money for the "upgrade escapade")
>
> (Note I mean Linux distribution, the linux kernel isn't usually involved.  unlike the old days: often binaries today often won't work when copied from one distro to another, due to lib variations they keep uploading)
>
> Obviously there's another answer: wolfram releases a different mathlink that doesn't rely on lib offsets runtime :)  I won't go into it but I know what breaks it.
>
> --------------------------------
>
> John Fultz wrote:
>> That's an interesting observation, but I can't say it matches my own experience.  I've found MathLink to be remarkably compatible across major version number changes of Mathematica, and to be generally robust. It is the only way the FE and the kernel communicate with each other (not to mention other lesser components of the system), and the nature of that connection is not simple; I would say it uses a majority of the features that MathLink has to offer.
>> It's not clear to me exactly what you're referring to as "Wolfram problem reports".  But I'd certainly be interested in knowing about any issues that you or anyone else may be experiencing with MathLink.
>> John Fultz
>> jfultz@wolfram.com
>> User Interface Group
>> Wolfram Research, Inc.
>> On Apr 1, 2013, at 12:00 AM, debguy <johnandsara2@cox.net> wrote:
>>> my advice is to avoid mathlink because library issues cause
>>> compatibility problems (see Wolfram problem reports).  ie after or
>>> without upgrade it's broken for someone trying to use.
>>>
>>> if you can accept fast but not fastest results I suggest this:
>>>
>>> to use "exec" in C to call math binary with piped commands (we're
>>> talking text input output) and use Put to get what into a file (can
>>> even be forked, run in background, doing it that way).  then your
>>> application reads file when done (fread is fast, maybe not fast as
>>> direct read from mathlink).
>>>
>>> most tasks can be done without ever using C.  doing some special
>>> graphics or something?
>>>
>

[toc] | [prev] | [next] | [standalone]


#14050

From"John D. Hendrickson and Sara Darnell" <johnandsara2@cox.net>
Date2013-04-04 17:10 +0000
Message-ID<kjkc69$7n8$1@smc.vnet.net>
In reply to#13835
you've crossed your own testimony

"we're very careful about compile targets" doesn't mean it works.

you've said if MathLink doesn't work Mathematica won't either 
certainly isn't true.

I run Mathemaitca but can't make ANY mathlink apps.  not after I upgraded from 
(woody to sarge).  If you don't know why then why comment on the 
subject?  I did find a way to do addtwo: which WR could have done but 
didn't.

I said wasn't talking about Mathematica's own binaries but mathlink 
apps users made and posted for others to compile and use: which is 
what Mathematica's documentation implies why one might be using mathlink.

You skirt the fact I'm not the only one who runs Mathematica and could 
not get mathgl3d / mathview3d to compile and run and reported it. 
Which was because I upgraded my OS to a slightly newer version.

For example if I compile against old libs libML.a might not seg-fault: 
but that forces GL to link against old GL libs: which won't work 
against new GL libs runtime.  That's assuming the rest worked, which i 
said had similar breakage issues.  That's due to libML.a  And GL isn't 
the only lib one might run into like that: all too many such will 
happen.  and libML.a's insistance to be a backport is why.

Your skirting the fact of how much trouble it is to backport like that 
only hoping it'd work on a new system when finished: it's an 
ass-whooping.  what find install old OS to work on new PC?

That's not what the mathgl3d author was thinking end users might be 
doing to run his nifty app is it?

look i really don't want to talk about it any further.  mathgl3d was 
the only mathlink project I wanted to see and it's not going to work.

I made a makefile that does it.  Yet again the use of it is too 
limited - it is bound to work only for examples and only given the 
particular way my OS version packaged old libs to be used.

Again - i don't want to make or use any mathlink thinking i can 
distribute it to others.

And a good reason is the above.

I'll stick by my word and say: avoid mathlink if you plan others to 
use it, if you plan it to be portable over time.  There will be lib 
issues you hadn't imagined.

You can't get convince me to say otherwise can you?  You have no 
evidence I do.


John Fultz wrote:
> If MathLink is broken, Mathematica is broken.  MathLink is not just some toss-off library used in a few corner cases by a few random users and barely supported by Wolfram.  It is a core part of the system, and if it's busted, Mathematica won't even run.  I could point to a dozen binaries in the Mathematica distribution that work MathLink harder than most user programs do, but I really only need to point to two -- the Mathematica kernel and the Mathematica front end.  MathLink is the one and only mechanism by which these two components communicate with each other.
> 
> It is true that there can be dependencies on versions of operating systems and libraries.  And to maintain maximum compatibility with a wide range of systems, we're very careful about which build systems and libraries we build our binaries (MathLink, FE, kernel, etc.) against, generally favoring somewhat older versions so we don't accidentally slurp in newer dependencies that could break on legacy systems.  The range of operating systems and libraries Mathematica (and thus MathLink) work against are generally pretty well advertised, and we've done a pretty good job of supporting operating systems at least 5 years out of date (save on MacOS, where the user culture tends to be highly aggressive about updating operating systems, so the support window is a bit shorter).
> 
> In summary, I would claim that, to the extent that your worries about MathLink are true, they apply to Mathematica itself.  The fact that Mathematica is not constantly broken on every new Linux distribution suggests that your concerns, while not invalid, are not as serious as you seem to suggest.
> 
> Sincerely,
> 
> John Fultz
> jfultz@wolfram.com
> User Interface Group
> Wolfram Research, Inc.
> 
> 
> 
> On Apr 2, 2013, at 5:04 PM, "John D. Hendrickson and Sara Darnell" <johnandsara2@cox.net> wrote:
> 
>> Ok I think you asked for a little more info about why mathlink which seems fine on developer's machine might not be fine elsewhere.
>>
>> Why is because to work mathlink needs to link against OS libraries which change.
>>
>> http://reference.wolfram.com/mathematica/tutorial/MathLinkDeveloperGuide-Unix.html#725481284
>>
>> clearly says it is library hooked and versional to specific libraries.
>>
>> http://support.wolfram.com/search/?query=mathlink&lang=en&noImg=1&submit.x=0&submit.y=0
>>
>> are some problem reports of:
>>
>> LinkConnect::"linkc": "\!\(\[LeftSkeleton] 1 \[RightSkeleton]\) is dead; attempt to connect failed."
>>
>> (there were many unsure if wr has removed them.  or search Google and find some.  it's hard to believe you looked hard if you can't find any.)
>>
>> For example I have Mathematix Version zzz.  I later upgrade Linux. Mathlink is now broken.  I may be able to run simple pre-compiled ones (unlikely to be available for my exact linux disto) but most won't work because the libs have changed or they are for a different linux distro.  You'd think "just recompile mathlink apps".  NO.
>>
>> To resolve this I need to run Mathematica and any mathlink apps in a chroot of a previous Linux version.  Compilation of other people's mathlink apps would also have to be done in the chroot - which won't work for newer mathlink apps.  Too much effort.
>>
>> You'd think I can just compile against older libs: surprise that works at compile time but not run-time since libML.a is loaded accessed through the newer libs and it is older: IT WON'T EVER WORK.
>>
>> My other choice is to buy new mathematica.  But if I had any mathlink apps I needed I'd have to rewrite them since they won't compile with the new linux libs / environment.  This also requires a new computer. $$  And how long is it until it's all broken again?
>>
>> (obviously upgrading Mathematica is better if you have time and money for the "upgrade escapade")
>>
>> (Note I mean Linux distribution, the linux kernel isn't usually involved.  unlike the old days: often binaries today often won't work when copied from one distro to another, due to lib variations they keep uploading)
>>
>> Obviously there's another answer: wolfram releases a different mathlink that doesn't rely on lib offsets runtime :)  I won't go into it but I know what breaks it.
>>
>> --------------------------------
>>
>> John Fultz wrote:
>>> That's an interesting observation, but I can't say it matches my own experience.  I've found MathLink to be remarkably compatible across major version number changes of Mathematica, and to be generally robust.  It is the only way the FE and the kernel communicate with each other (not to mention other lesser components of the system), and the nature of that connection is not simple; I would say it uses a majority of the features that MathLink has to offer.
>>> It's not clear to me exactly what you're referring to as "Wolfram problem reports".  But I'd certainly be interested in knowing about any issues that you or anyone else may be experiencing with MathLink.
>>> John Fultz
>>> jfultz@wolfram.com
>>> User Interface Group
>>> Wolfram Research, Inc.
>>> On Apr 1, 2013, at 12:00 AM, debguy <johnandsara2@cox.net> wrote:
>>>> my advice is to avoid mathlink because library issues cause
>>>> compatibility problems (see Wolfram problem reports).  ie after or
>>>> without upgrade it's broken for someone trying to use.
>>>>
>>>> if you can accept fast but not fastest results I suggest this:
>>>>
>>>> to use "exec" in C to call math binary with piped commands (we're
>>>> talking text input output) and use Put to get what into a file (can
>>>> even be forked, run in background, doing it that way).  then your
>>>> application reads file when done (fread is fast, maybe not fast as
>>>> direct read from mathlink).
>>>>
>>>> most tasks can be done without ever using C.  doing some special
>>>> graphics or something?
>>>>
> 
> 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web