ANN: jlcall - Call Julia from MATLAB through the MEX interface

682 views
Skip to first unread message

Tracy Wadleigh

unread,
Oct 2, 2015, 7:45:49 PM10/2/15
to julia-users
I'm pleased to announce jlcall, a project that exposes Julia to MATLAB through the MEX interface. (And only a brief ten months after posting my gist with my proof-of-concept, too. ;-))

Highlights
  • Call any Julia function whose arguments can be marshaled to Julia via MATLAB.jl's jvariable function and whose return value can be marshaled to MATLAB via mxarray.
  • Evaluate arbitrary Julia expressions captured in MATLAB strings.
Advantages
  • MATLAB users: extend your MATLAB workflow with Julia as a new MEX extension language.
  • Julia users: use MATLAB's polished front end for your own work, or at least use jlcall to facilitate better collaboration with your MATLAB-bound colleagues.
  • Can avoid memory copies in some cases when crossing the language boundary, as the two runtimes cohabit a common process and see the same address space.
A caveat: as of this writing, jlcall has been shown to work on exactly one (Win64) machine: my workstation at work. It is the only machine with a MATLAB license to which I have access. If you try it on another platform any time soon, expect breakage. Please report it, though, as I would like to see this project functional across all three platforms on which both Julia and MATLAB are supported.

Tim Holy

unread,
Oct 3, 2015, 5:01:19 AM10/3/15
to julia...@googlegroups.com
Very nice, Tracy!

I plan to try to test soon on Linux, will let you know how it goes. Many
thanks for an excellent contribution!

--Tim

On Friday, October 02, 2015 04:45:49 PM Tracy Wadleigh wrote:
> I'm pleased to announce jlcall <https://github.com/twadleigh/jlcall>, a
> project that exposes Julia to MATLAB through the MEX interface. (And only a
> brief ten months after posting my gist
> <https://gist.github.com/twadleigh/387f7aeb9707226d7d18> with my
> proof-of-concept, too. ;-))
>
> *Highlights*
>
> - Call any Julia function whose arguments can be marshaled to Julia via
> MATLAB.jl's jvariable function and whose return value can be marshaled
> to MATLAB via mxarray.
> - Evaluate arbitrary Julia expressions captured in MATLAB strings.
>
> *Advantages*
>
> - MATLAB users: extend your MATLAB workflow with Julia as a new MEX
> extension language.
> - Julia users: use MATLAB's polished front end for your own work, or at
> least use jlcall to facilitate better collaboration with your
> MATLAB-bound colleagues.
> - Can avoid memory copies in some cases when crossing the language

feza

unread,
Oct 4, 2015, 2:12:07 PM10/4/15
to julia-users
Looks like it works   cheers

Building with 'Microsoft Visual C++ 2015 Professional'.
cl /c /Zp8 /GR /W3 /EHs /nologo /MD /O2 /Oy- /DNDEBUG /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0   /DMATLAB_MEX_FILE -IC:\Julia\Julia-0.5.0-dev\include\julia  -I"C:\Program Files\MATLAB\R2015b\extern\include" -I"C:\Program Files\MATLAB\R2015b\simulink\include" C:\Users\freze\julia_packages\jlcall\src\jlcall.cpp /FoC:\Users\freze\AppData\Local\Temp\mex_11449682771947_5816\jlcall.obj
jlcall.cpp
C:\Julia\Julia-0.5.0-dev\include\julia\julia.h(91): warning C4200: nonstandard extension used: zero-sized array in struct/union
C:\Julia\Julia-0.5.0-dev\include\julia\julia.h(91): note: Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array
C:\Julia\Julia-0.5.0-dev\include\julia\julia.h(121): warning C4200: nonstandard extension used: zero-sized array in struct/union
C:\Julia\Julia-0.5.0-dev\include\julia\julia.h(121): note: Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array
C:\Julia\Julia-0.5.0-dev\include\julia\julia.h(132): warning C4200: nonstandard extension used: zero-sized array in struct/union
C:\Julia\Julia-0.5.0-dev\include\julia\julia.h(132): note: Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array
C:\Julia\Julia-0.5.0-dev\include\julia\julia.h(293): warning C4200: nonstandard extension used: zero-sized array in struct/union
C:\Julia\Julia-0.5.0-dev\include\julia\julia.h(293): note: Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array
C:\Users\freze\julia_packages\jlcall\src\jlcall.cpp(27): warning C4800: 'int': forcing value to bool 'true' or 'false' (performance warning)

link /nologo /manifest  /DLL  /EXPORT:mexFunction C:\Users\freze\AppData\Local\Temp\mex_11449682771947_5816\jlcall.obj  libjulia.dll.a  /LIBPATH:C:\Julia\Julia-0.5.0-dev\lib   /LIBPATH:"C:\Program Files\MATLAB\R2015b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /out:C:\Users\freze\julia_packages\jlcall\m\jlcall.mexw64
   Creating library C:\Users\freze\julia_packages\jlcall\m\jlcall.lib and object C:\Users\freze\julia_packages\jlcall\m\jlcall.exp

mt -outputresource:C:\Users\freze\julia_packages\jlcall\m\jlcall.mexw64;2 -manifest C:\Users\freze\julia_packages\jlcall\m\jlcall.mexw64.manifest
Microsoft (R) Manifest Tool version 6.3.9600.17336

Copyright (c) Microsoft Corporation 2012. 

All rights reserved.


del C:\Users\freze\julia_packages\jlcall\m\jlcall.exp C:\Users\freze\julia_packages\jlcall\m\jlcall.lib C:\Users\freze\julia_packages\jlcall\m\jlcall.mexw64.manifest C:\Users\freze\julia_packages\jlcall\m\jlcall.ilk
MEX completed successfully.
"C:\Users\freze\julia_packages\jlcall\m" is already on the MATLAB path.
Configuration complete.

Kristoffer Carlsson

unread,
Oct 4, 2015, 4:39:33 PM10/4/15
to julia-users
I haven't gotten to try this yet but if this works smoothly it will be a huge step to ease the transition from Matlab to Julia.

Very impressive work.

Patrick Kofod Mogensen

unread,
Oct 5, 2015, 10:25:08 AM10/5/15
to julia-users
I have not tested it, but I really should. Why? I still work with a lot of people who are MATLAB-users, and are not going to transition. This could potentially help Julia <-> MATLAB collaborators a lot!


On Friday, October 2, 2015 at 7:45:49 PM UTC-4, Tracy Wadleigh wrote:
Reply all
Reply to author
Forward
0 new messages