-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathmex.html
207 lines (178 loc) · 5.84 KB
/
mex.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<html>
<head>
<title>
MEX - The MATLAB Compiler
</title>
</head>
<body bgcolor="#eeeeee" link="#cc0000" alink="#ff3300" vlink="#000055">
<h1 align = "center">
MEX <br> The MATLAB Compiler
</h1>
<hr>
<p>
<b>MEX</b>
is the MATLAB compiler, which
enables a user to design a MATLAB program which can call
a function written in C, C++, FORTRAN77 or FORTRAN90,
and to transmit information to and from such functions.
</p>
<p>
This facility means a user can design a program that
combines features of multiple languages, or takes advantage
of the fact that a useful function is already available in
source code form. Also, a user can take advantage of
the interactive and graphic features of MATLAB in combination
with calculations carried out in a traditional language.
</p>
<p>
A particular reason to use MEX occurs when a highly efficient
kernel or library has been written in a compilable language, but
the user also needs the interactivity, graphics, or other features
of MATLAB.
</p>
<p>
The C/C++/F77/F90 function can accept input, return values,
and print data. However, the function needs to communicate with
MATLAB according to rules defined by the MEX compiler. This means
that things such as the data types of variables and the specific
form of commands to print data must be handled according to these
rules.
</p>
<p>
Once the user function has been created, it can be compiled by the
command "mex filename". This will create compiled code that can be
called directly by MATLAB. For instance, the HELLO example includes
a short C function called "hello.c". Issuing the command "mex hello.c"
invokes a C compiler that includes the necessary MATLAB libraries,
and creates a compiled file called "hello.mexmaci64" (the extension
indicates that I have compiled with MEX on a MACintosh computer using
64 bit integer addressing). MATLAB can invoke this compiled function
by the command "hello".
</p>
<p>
In order to use MATLAB's MEX compiler, the following things must be
true:
<ul>
<li>
the user has the source code for a C, C++, F77 or F90 function;
</li>
<li>
the user has access to a C, C++, F77 or F90 compiler that
is supported by MATLAB (on Linux/Unix systems, gcc and gfortran
are suitable choices);
</li>
<li>
the user has indicated which compiler is to be used by using
the MATLAB command:
<pre>
mex -setup
</pre>
</li>
<li>
the user has created the appropriate interface routine to pass
data between MATLAB and the user's function;
</li>
<li>
the user has compiled the function with a MATLAB command like
<pre>
mex myfun.c
</pre>
</li>
<li>
the compiled code, which might have a name like myfun.maci64,
is located in the same directory as the MATLAB code that will
call it, or is visible in the MATLAB path.
</li>
</ul>
</p>
<h3 align = "center">
Licensing:
</h3>
<p>
The computer code and data files described and made available on this web page
are distributed under
<a href = "../../txt/gnu_lgpl.txt">the GNU LGPL license.</a>
</p>
<h3 align = "center">
Languages:
</h3>
<p>
<b>MEX</b> is available in
<a href = "../../m_src/mex/mex.html">a MATLAB version</a>.
</p>
<h3 align = "center">
Related Data and Programs:
</h3>
<p>
<a href = "../../m_src/matlab_calls_c/matlab_calls_c.html">
MATLAB_CALLS_C</a>,
MATLAB programs which
illustrate how C functions can be written, compiled, and
called from MATLAB using the MEX facility;
</p>
<p>
<a href = "../../m_src/matlab_calls_f77/matlab_calls_f77.html">
MATLAB_CALLS_F77</a>,
MATLAB programs which
illustrate how FORTRAN77 functions can be written, compiled, and
called from MATLAB using MATLAB's <b>mex</b> facility;
</p>
<p>
<a href = "../../c_src/nsasm/nsasm.html">
NSASM</a>,
a C library which
computes the jacobian matrix associated
with a finite element approximation of the incompressible
steady (time independent) Navier-Stokes equations in 2D, and to store these as
a sparse matrix, by Per-Olof Persson. It is designed to be compiled
with MATLAB's mex compiler and called from a MATLAB
main program.
</p>
<h3 align = "center">
Reference:
</h3>
<p>
<ol>
<li>
The MathWorks,<br>
MATLAB Compiler User's Guide<br>
</li>
</ol>
</p>
<h3 align = "center">
Examples and Tests:
</h3>
<p>
<b>HELLO</b> is the standard "Hello, world!" example. It uses a
function written in C.
<ul>
<li>
<a href = "hello.c">hello.c</a>,
the source code.
</li>
<li>
<a href = "timestamp.m">timestamp.m</a>,
prints the YMDHMS date as a timestamp.
</li>
<li>
<a href = "hello_test.m">hello_test.m</a>,
a MATLAB script that combines the compilation of "hello.c"
with an invocation of the "hello" command.
</li>
<li>
<a href = "hello_test_output.txt">hello_test_output.txt</a>,
the output file.
</li>
</ul>
</p>
<p>
You can go up one level to <a href = "../m_src.html">
the MATLAB source codes</a>.
</p>
<hr>
<i>
Last modified on 07 April 2012.
</i>
<!-- John Burkardt -->
</body>
</html>