Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Implementing c++ best programming practice

Subject: Implementing c++ best programming practice

From: Moritz

Date: 5 Sep, 2013 12:08:05

Message: 1 of 2

Dear all,

i am using the method of line in order to discretize a convectionc diffusion PDE. It is a degenerate hyperbolic-parabolic PDE. (phenomenolocical sedimentation model)

The Implementation is slow because my flux and diffusion function are slow. E.g calling my flux function in c++ 1e5 times takes in c++ less than 1 sec and in Matlab 5-7 seconds.

So for every space point the diffusion and the flux term have to be determined. I vectorized that in MATLAB.

In c++ i use loops.

So what is the best way to implement this functions as mex file ? Doing the loop inside the c++ function and return a vector ? So do not have to call the function that often.

Or call the function from within MATLAB for every space point and return a double ?

By the way, is it fair to compare a function from MATLAB and c++ by calling it e.g 1e5 times inside a loop ?

I hope somenone can give me a hint

Kind Regards

Moritz

Subject: Implementing c++ best programming practice

From: Torsten

Date: 5 Sep, 2013 12:39:06

Message: 2 of 2

"Moritz" wrote in message <l09s75$p82$1@newscl01ah.mathworks.com>...
> Dear all,
>
> i am using the method of line in order to discretize a convectionc diffusion PDE. It is a degenerate hyperbolic-parabolic PDE. (phenomenolocical sedimentation model)
>
> The Implementation is slow because my flux and diffusion function are slow. E.g calling my flux function in c++ 1e5 times takes in c++ less than 1 sec and in Matlab 5-7 seconds.
>
> So for every space point the diffusion and the flux term have to be determined. I vectorized that in MATLAB.
>
> In c++ i use loops.
>
> So what is the best way to implement this functions as mex file ? Doing the loop inside the c++ function and return a vector ? So do not have to call the function that often.
>
> Or call the function from within MATLAB for every space point and return a double ?
>
> By the way, is it fair to compare a function from MATLAB and c++ by calling it e.g 1e5 times inside a loop ?
>
> I hope somenone can give me a hint
>
> Kind Regards
>
> Moritz

If you already programmed the discretization in C++, why not using a C++ ODE-solver as well ?

Best wishes
Torsten.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us