Multi-Threading w/ MEX: Adding Two Vectors

Version 1.0.0 (5.95 KB) by oreoman
A basic MEX function that adds two vectors together, but utilizes multiple threads. Created as a way to learn MEX multi-threading.
Updated 27 Feb 2019

View License

In order to optimize certain pieces of a simulation, I tried to build out a multi-threaded algorithm for solving certain linear algebra problems that I couldn't find good solutions to in various libraries or that couldn't be vectorized in proper MATLAB code.

Since I found a lot of the tutorials available online very confusing, once I figured things out I thought it would be handy to share what I learned. With thanks to Yair Altman and his multi-threading example from 2018 that included all of the information I needed to finally figure things out:

To add non-Windows compatibility, you can add in pthreads by following along with Yair's example.

This needs to be compiled with the command, "mex -R2018a madd.cpp"

Cite As

oreoman (2024). Multi-Threading w/ MEX: Adding Two Vectors (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2018b
Compatible with R2018a and later releases
Platform Compatibility
Windows macOS Linux
Find more on MATLAB Algorithm Acceleration in Help Center and MATLAB Answers
Tags Add Tags

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes