parallel for loop in mex
1 次查看(过去 30 天)
显示 更早的评论
The outer loop in this code should be parallelizable
#include "mex.h"
#include "matrix.h"
#include <math.h>
//[reX imX]=cfrft(rectpuls(t),0.5,linspace(-10,10,2^12),-5:0.01:5);
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[]) {
nlhs=2;
const double pi = 3.1415926535897;
double *f= mxGetPr(prhs[0]);
size_t flen=mxGetNumberOfElements(prhs[0]);
double *ap= mxGetPr(prhs[1]);
double p = (*ap)*pi/2; double cscp = 2/sin(p); double cotp = 1/tan(p);
double *t= mxGetPr(prhs[2]);
// size_t tlen=mxGetNumberOfElements(prhs[2]);
double *w= mxGetPr(prhs[3]);
size_t wlen=mxGetNumberOfElements(prhs[3]);
plhs[0]=mxCreateDoubleMatrix(1, static_cast<int>(wlen), mxREAL);
plhs[1]=mxCreateDoubleMatrix(1, static_cast<int>(wlen), mxREAL);
double *reF = mxGetPr(plhs[0]);
double *imF = mxGetPr(plhs[1]);
double dt=t[1]-t[0];
for (int i = 0;i<wlen;i++){ //<<<<< THIS LOOP
double re=0;
double im=0;
double wc=w[i];
double wc2=wc*wc;
for(int j=0;j<flen;j++){
re += cos(pi*(cotp*wc2-cscp*t[j]*wc+cotp*t[j]*t[j]))*f[j];
im += sin(pi*(cotp*wc2-cscp*t[j]*wc+cotp*t[j]*t[j]))*f[j];
}
reF[i]=re*dt;
imF[i]=im*dt;
}
}
How do I use parallel loops in mex? My compiler is Building with 'Microsoft Windows SDK 7.1 (C++)'.
0 个评论
回答(1 个)
James Tursa
2015-8-4
Some Microsoft compilers support OpenMP, but I don't think the vanilla SDK compiler is one of them. Did you mean using OpenMP, or something else?
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!