Compiling a MEX file with Visual Studio

Victor Fang's Computing Space

1) If we are working on matrix multiplication, then after compiling the .br file we generate a .cpp like below. Modify the .cpp file directly to use the MEX API. The sections in bold are the minimum code changes necessary.


#include “common.h”

#include “Timer.h”

#include “mex.h”


static int retval = 0;


//int main(int argc, char** argv)

void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[])



float A<Height, Width>;

float B<Width, Height>;

float C<Height, Height>;


streamRead(A, inputA);

streamRead(B, inputB);

// Run the brook program here

for (i = 0; i < cmd.Iterations; ++i)


simple_matmult((float)Width, A, B, C);



// Write data back from stream here

streamWrite(C, output);




mexPrintf(“Time to execute matrix multiplication – fast \n”);




2) Follow the direction below to build MEX-files with the Microsoft Visual C++ integrated development environment. These are…

View original post 308 more words


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s