mex

Is it possible to debug mex code with Eclipse?

浪尽此生 提交于 2019-11-30 04:50:49
I am trying to write some mex code but it is painful to debug it on the console with gbd. Is it possible to use Eclipse or the GUI of Matlab? If these are not feasible methods, what is the best way of writing mex code that provides good debug capabilities? Eitan T Debugging C/C++ MEX files in gdb is already comprehensively covered in the official documentation , so my suggestion is to try and integrate gdb with Eclipse CDT. There's plenty of information out there about how to do it properly, so I'm not going to repeat everything here. The best tutorial I know is IBM's two-part guide,

Matlab API reading .mat file from c++, using STL container

…衆ロ難τιáo~ 提交于 2019-11-30 04:07:50
I have to read some .mat data files from c++, I read through the documentation, but I would like to know how to handle the data in a clean and elegant way, e.g. using std:vector(modest .mat file size(10M~1G), but memory issues should be taken seriously) My function is sth like: #include <stdio.h> #include "mat.h" #include <vector> int matread(const char *file, const vector<double>& pdata_v) { MATFile *pmat; pmat=matOpen("data.mat","r"); if (pmat == NULL) { printf("Error opening file %s\n", file); return(1); } mxArray *pdata = matGetVariable(pmat, "LocalDouble"); // pdata -> pdata_v mxDestroy

Matlab mex file is slow compared to its straight C equivalent

拜拜、爱过 提交于 2019-11-30 03:04:55
I'm at a loss to explain (and avoid) the differences in speed between a Matlab mex program and the corresponding C program with no Matlab interface. I've been profiling a numerical analysis program: int main(){ Well_optimized_code(); } compiled with gcc 4.4 against the Matlab-Mex equivalent (directed to use gcc44, which is not the version currently supported by Matlab, but it's required for other reasons): void mexFunction(int nlhs,mxArray* plhs[], int nrhs, const mxArray* prhs[]){ Well_optimized_code(); //literally the exact same code } I performed the timings as: $ time ./C_version vs. >>

mex linking of cuda code in separate compilation mode

こ雲淡風輕ζ 提交于 2019-11-29 15:48:49
问题 I'm trying to use CUDA code inside MATLAB mex, under linux. With the "whole program compilation" mode, it works good for me. I take the following two steps inside Nsight: (1) Add "-fPIC" as a compiler option to each .cpp or .cu file, then compile them separately, each producing a .o file. (2) Set the linker command to be "mex" and add "-cxx" to indicate that the type of all the .o input files are cpp files, and add the library path for cuda. Also add a cpp file that contains the mexFunction

Matlab 2013b generated code produces Undefined symbols for architecture x86_64 error in mex

穿精又带淫゛_ 提交于 2019-11-29 15:47:08
I have a C-Code generated by the Simulink Coder that I need to use in a C S-function. This may sound a bit strange but I need this Code to be executed multiple times within the s-function before writing the outputs of the s-function (it's an evolutionary algorithm that needs to simulate a prediction for a lot of individuals before evaluation and ranking...but those details do not really matter). The Problem is that I seem to have a problem with the 64bit instruction set when trying to mex my code. I am taking the generated erg_main.c as an example on how to interact with the generated code: /*

Matlab mex-file with mexCallMATLAB is almost 300 times slower than the corresponding m-file

微笑、不失礼 提交于 2019-11-29 14:26:07
问题 I started implementing a few m-files in C++ in order to reduce run times. The m-files produce n-dimensional points and evaluate function values at these points. The functions are user-defined and they are passed to m-files and mex-files as function handles. The mex-files use mexCallMATLAB with feval for finding function values. I constructed the below example where a function handle fn constructed in the Matlab command line is passed to matlabcallingmatlab.m and mexcallingmatlab.cpp routines.

shared library locations for matlab mex files:

ⅰ亾dé卋堺 提交于 2019-11-29 13:24:25
问题 I am trying to write a matlab mex function which uses libhdf5; My Linux install provides libhdf5-1.8 shared libraries and headers. However, my version of Matlab, r2007b, provides a libhdf5.so from the 1.6 release. (Matlab .mat files bootstrap hdf5, evidently). When I compile the mex, it segfaults in Matlab. If I downgrade my version of libhdf5 to 1.6 (not a long-term option), the code compiles and runs fine. question: how do I solve this problem? how do I tell the mex compilation process to

/usr/../libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by …)

寵の児 提交于 2019-11-29 12:46:56
I have been stuck on this problem for several weeks and been looking around on Internet for solution but so far not so good... So I have a program written by someone else and I try to compile it in Matlab to make it work. My computer is Red-hat enterprise Linux workstation (64 bits) with gcc 4.4.3 and Matlab 2011b installed. The gcc is compatible with my Matlab ( http://www.mathworks.com/support/compilers/R2011b/glnxa64.html ). The compilation works fine (I mean, no error message occurs in Matlab command window). But after compilation, every time when I use a specific function from the

How to speed up Eigen library's matrix product?

大城市里の小女人 提交于 2019-11-29 10:29:07
问题 I'm studying simple multiplication of two big matrices using the Eigen library. This multiplication appears to be noticeably slower than both Matlab and Python for the same size matrices. Is there anything to be done to make the Eigen operation faster? Problem Details X : random 1000 x 50000 matrix Y : random 50000 x 300 matrix Timing experiments (on my late 2011 Macbook Pro) Using Matlab: X*Y takes ~1.3 sec Using Enthought Python: numpy.dot( X, Y) takes ~ 2.2 sec Using Eigen: X*Y takes ~2.7

how to read an integer array in MEX-function

你离开我真会死。 提交于 2019-11-29 09:46:50
I am passing an integer array of uint8 type from MATLAB to a MEX-function. How do I read these values? I tried using: int *n; n = (int * ) mxGetData(prhs[0]); but the values come out as junk. I also tried double *n; n= mxGetPr(prhs[0]); and in this case junk values also appear. What is the solution to this? Basically I want to read the integer value in the MEX-function but mxGetPr returns double type. Take a look at the demo MEX-function explore.c, which you can open in MATLAB using edit([matlabroot '/extern/examples/mex/explore.c']); In there you'll find a bunch of functions whose names all