matlab mex
来源:互联网 发布:s7edge怎么关闭4g网络 编辑:程序博客网 时间:2024/06/10 07:28
linux matlab版本中OpenMP的使用
需要重点注意linux和window mex编译的参数不一样!
这里参考edgeBOX论文提供代码的参数选择
Next, please compile mex code from within Matlab (note: win64/linux64 binaries included):
mex private/edgesDetectMex.cpp -outdir private [OMPPARAMS]
mex private/edgesNmsMex.cpp -outdir private [OMPPARAMS]
mex private/spDetectMex.cpp -outdir private [OMPPARAMS]
mex private/edgeBoxesMex.cpp -outdir private
Here [OMPPARAMS] are parameters for OpenMP and are OS and compiler dependent.
Windows: [OMPPARAMS] = '-DUSEOMP' 'OPTIMFLAGS="$OPTIMFLAGS' '/openmp"'
Linux V1: [OMPPARAMS] = '-DUSEOMP' CFLAGS="\$CFLAGS -fopenmp" LDFLAGS="\$LDFLAGS -fopenmp"
Linux V2:[OMPPARAMS] = '-DUSEOMP' CXXFLAGS="\$CXXFLAGS -fopenmp" LDFLAGS="\$LDFLAGS -fopenmp"
To compile without OpenMP simply omit [OMPPARAMS]; note that code will be single threaded in this case.
对于windows matlab2014b版本,同样可以使用一下参数进行编译 mex euc_nn_mex_K.cpp COMPFLAGS="/openmp $COMPFLAGS"
但是,在linux上不能使用该参数,否则即使编译通过,线程数也只为1。
在不明确定义线程数的情况下,系统运行可以达到最大线程数,即系统核心数 CPU数目单个CPU核心数*。
另外还可以参考
mex euc_nn_mex.cc CXXFLAGS="\$CXXFLAGS -fopenmp -Wall"
LDFLAGS="\$LDFLAGS -fopenmp";mex kmeans_iter_mex.cc CXXFLAGS="\$CXXFLAGS -Wall"
代码参考
#include <assert.h>#include <math.h>#include "mex.h"#include <sys/time.h>void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) { if (nrhs != 2) mexErrMsgTxt("There should be two input arguments."); if (nlhs != 2 && nlhs != 1) mexErrMsgTxt("There should be one or two output arguments."); int p = mxGetM(prhs[0]); int n = mxGetN(prhs[0]); int nq = mxGetN(prhs[1]); if (mxGetM(prhs[1]) != (unsigned int)p) mexErrMsgTxt("Dimensionality of the two input matrices are not " "consistent."); if (mxGetClassID(prhs[0]) != mxSINGLE_CLASS || mxGetClassID(prhs[1]) != mxSINGLE_CLASS ) mexErrMsgTxt ("Only single precision matrices are supported."); float * b = (float*) mxGetPr(prhs[0]); /* database vectors */ float * v = (float*) mxGetPr(prhs[1]); /* query vectors */ plhs[0] = mxCreateNumericMatrix(nq, 1, mxINT32_CLASS, mxREAL); int * ind = (int*) mxGetPr(plhs[0]); float * dis = NULL; if (nlhs >= 1) { plhs[1] = mxCreateNumericMatrix(nq, 1, mxSINGLE_CLASS, mxREAL); dis = (float*) mxGetPr(plhs[1]); } int j = 0;#pragma omp parallel shared(j) {#pragma omp for for (j = 0; j < nq; j++) { float * vj = v + j * p; // vj points to the j-th query point. float min_dis = 1e10; int best_ind = -1; float * bi = b; // bi points to the i-th data point. // The pointer changes with the for variable i. for (int i = 0; i < n; i++, bi += p) { float disi = 0; for (int k = 0; k < p; k++) { disi += (bi[k] - vj[k]) * (bi[k] - vj[k]); } if (disi < min_dis) { min_dis = disi; best_ind = i; } } if (nlhs >= 1) dis[j] = min_dis; ind[j] = best_ind + 1; // one-based if (best_ind == -1) mexErrMsgTxt ("Something is wrong, ind is still -1."); } }}
- Matlab MEX
- matlab mex
- matlab+mex
- Matlab Mex应用
- Matlab 编译MEX文件
- MATLAB mex -setup 使用
- matlab中的mex编译
- Matlab MEX 使用笔记
- Matlab编译mex文件:
- MATLAB mex -setup
- matlab mex 文件
- matlab mex编译问题
- matlab mex 函数使用
- matlab opencv C++ mex
- Matlab MEX 使用笔记
- [Matlab] mex混编OpenCV
- sudsn mex matlab F1
- Matlab mex文件
- Deep Learning for Nature Language Processing --- 第八讲
- UVALive 6661 Equal Sum Sets
- uva 11218 KTV 暴力(回溯)
- java重载方法重写、继承封装
- Ubuntu之Gitlab安装
- matlab mex
- 爪哇爪瓜_继承与多态
- win7下,本机Apache虚拟主机配置
- 黑马程序员-C语言条件编译的使用
- 类的组成部分
- 莫要过度使用DIV
- Android学习笔记-Activity
- IOS开发遇到的问题连载
- HDU 4311&4312 Meeting point-1&2 (曼哈顿距离&&切比雪夫距离)