octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

MEX interface


From: John W. Eaton
Subject: MEX interface
Date: Thu, 27 Jul 2006 12:05:11 -0400

I've done about all I can for now with the MEX interface for Octave.
It currently supports almost all of the current Matlab MEX interface
but has only had light testing.  All my changes are checked in.

My most extensive test with code written for Matlab was to try to run
the examples from SundialsTB (Sundials is a collection of ODE/DAE
solvers and SundialsTB is a Matlab interface to some of the solvers;
there is more information here: http://www.llnl.gov/CASC/sundials).

With the latest Octave MEX interface code, I'm able to run all the
examples in the cvodes/examples_ser directory in the SundialsTB.  To
build the SundialsTB MEX files, I only needed the following change and
the install_STB.m file worked for me:

--- install_STB.m~      2006-03-06 20:19:46.000000000 -0500
+++ install_STB.m       2006-07-27 11:50:29.000000000 -0400
@@ -151,7 +151,7 @@
 else
   mex_cmd = 'mex';
 end
-mex_cmd = sprintf('%s -v -outdir %s %s %s %s', mex_cmd, cvm, includes, 
sources, libraries);
+mex_cmd = sprintf('%s -v %s %s %s', mex_cmd, includes, sources, libraries);
 eval(mex_cmd);

 % Move back to sundialsTB
@@ -256,7 +256,7 @@
 else
   mex_cmd = 'mex';
 end
-mex_cmd = sprintf('%s -v -outdir %s %s %s %s', mex_cmd, kim, includes, 
sources, libraries);
+mex_cmd = sprintf('%s -v %s %s %s', mex_cmd, includes, sources, libraries);
 eval(mex_cmd);

 % Move back to sundialsTB

Adding an "-outdir DIR" option to mkoctfile (or better, writing a
fully compatible mex function/shell script) would eliminate the need
for this change.

The SundialsTB examples rely on some graphics features that are not
yet supported by Octave, so I had to make some adjustments.  But these
are really problems with the graphics capabilities of Octave, not the
MEX interface.

The cvkx and cvkxb examples seem quite slow.  I'm not sure whether
this is due to data copying or function call overhead or what.  My
profiling efforts stalled when I found that profiling shared libraries
doesn't seem to work (if someone knows how to do that, please let me
know) and I didn't see a simple way to integrate the Sundials MEX
files in a statically linked Octave (I know it can be done, but it
didn't seem worth the effort to me at the moment).

There is still some potential for improved efficiency.  For example,
if you pass a value from Octave to a MEX routine and need to pass it
on to a user-supplied function (via the mexCallMATLAB function), no
copy of the data should be required (it starts out as an octave_value
object and remains that way when passed back to Octave.  But, if you
create a value inside a MEX function and return it to Octave, either
in the output arguments (plhs) or via a call to mexCallMATLAB, a copy
of the data is made.  It might be possible to avoid this copy for real
data, but it is a bit tricky to work out all the details given
Octave's method of handling copies with reference counting.  Because I
have limited time to work on this project, I had to give up on these
issues for now.

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]