# In parfor-loop, can I call a multi-threaded mex and get some speed-up?

7 views (last 30 days)

Show older comments

Xingwang Yong
on 3 Jan 2021

Commented: Xingwang Yong
on 4 Jan 2021

I learned the concept of multi-threaded mex from undocumentedmatlab. (It seems this website is unaccessible now ...)

I am wondering if I can call a multi-threaded mex in parfor-loop.

My current code looks like

parfor k=1:1e6

result(k) = mex_wrapper(data(k));

end

mex_wrapper.c looks like

double calculate()

{

int N=50;

for (i=0;i<N;i++)

{

//...

}

}

void mexFunction()

{

calculate();

}

The iterations inside calculate() are independent, so I want to change the sub-routine calculate() to support multi-thread.

Although I am running parfor in process-based-environments, I am not sure if multi-threaded mex would confict with parfor.

So can I use multi-threaded mex in parfor? And would I get some speed-up by doing so?

##### 0 Comments

### Accepted Answer

Edric Ellis
on 4 Jan 2021

### More Answers (0)

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!