From: Sang-yeop Chung on
Hi,

I run my own matlab code which contains 'for' loop and 'tsearchn' function.
It works well, but the speed is too slow. I want to speed up my process
without fixing my code.
I use Dual core 2.13GHz cpu.

first,
I use Dual core 2.13GHz cpu.
Is there any function to use dual core cpu at the same time??
In other word, I want to use my whole dual core cpu for the process.

second,
I find 'maxNumcompthreads' funtion, but it doen't work after checking code
run time by 'tic-toc'.
And someone at google report about 'GPUmat'.
I wonder that I can use it.

if anyone can answer my question, I need your helps.

Regards.

Chung
From: Jan Simon on
Dear Chung,

> I run my own matlab code which contains 'for' loop and 'tsearchn' function.
> It works well, but the speed is too slow. I want to speed up my process
> without fixing my code.

Modern versions of Matlab use many multi-threaded function already.
If TSEARCH does not belong to these functions, buy the toolbox for parallel processing and use PARFOR instead of FOR.

Or buy a faster computer.

Finally, fixing your code would be the best and most efficient way.

Kind regards, Jan
From: Rune Allnor on
On 8 Jul, 12:25, "Sang-yeop Chung" <cesar...(a)gmail.com> wrote:
> Hi,
>
> I run my own matlab code which contains 'for' loop and 'tsearchn' function.
> It works well, but the speed is too slow. I want to speed up my process
> without fixing my code.
> I use Dual core 2.13GHz cpu.

The only way to do that is to buy a faster computer.

Mind you - for the past several years CPU speeds haven't
increased as fast as it once used to. Most CPUs have had
clock frequencies between 2 and 3 GHz for at least five
years now. Focus has shifted from faster CPUs to more CPU
cores per computer.

In other words, if you aren't willing to maintain your code,
you will be stuck pretty soon.

Rune
From: Steven Lord on

"Sang-yeop Chung" <cesar419(a)gmail.com> wrote in message
news:i14923$riq$1(a)fred.mathworks.com...
> Hi,
> I run my own matlab code which contains 'for' loop and 'tsearchn'
> function.
> It works well, but the speed is too slow. I want to speed up my process
> without fixing my code.

Then the options available to you are limited; probably getting a faster
computer is the main option. Just about any other change will require
"fixing" your code.

But I want to ask a few questions about your application. Are you calling
TSEARCHN in the loop with one point each time? If so, combine all the
points into one matrix and call TSEARCHN _once_ if at all possible.

Second, are you certain that TSEARCHN is the bottleneck in your code? Run
your code using the Profiler to check this.

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_env/f9-17018.html

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com


From: Bryan on
Avoid using the for loop if you can. One way to avoid the for loop is to vectorize your code. See the following example.

% good programming practice, but not desirable MATLAB programming.
myEvaluate= [];
cnt = 1;
for i = 1:1:length(myArray) %myArray length = 50,000
if sensorfail(i) ~= 1
x_in(cnt) = x(i);
y_in(cnt) = y(i);
myEvaluate (cnt) = 1;
cnt = cnt + 1;
end
end

% Optimized MATLAB code
myEvaulate = 1:1:length(myArray)
myEvaulate = myEvaulate(sensorfail ~= 1)
x_in(cnt) = x(myEvaulate);
y_in(cnt) = y(myEvaulate);

You will see enhanced performance if you run tic; ExampleCode; toc; .

The problem is not your CPU speed or the 'tsearchn' function. Your 'for' loop is the performance dragging culprit. If you cannot avoid, then make it to use smaller index values by using cell arrays.


"Sang-yeop Chung" <cesar419(a)gmail.com> wrote in message <i14923$riq$1(a)fred.mathworks.com>...
> Hi,
>
> I run my own matlab code which contains 'for' loop and 'tsearchn' function.
> It works well, but the speed is too slow. I want to speed up my process
> without fixing my code.
> I use Dual core 2.13GHz cpu.
>
> first,
> I use Dual core 2.13GHz cpu.
> Is there any function to use dual core cpu at the same time??
> In other word, I want to use my whole dual core cpu for the process.
>
> second,
> I find 'maxNumcompthreads' funtion, but it doen't work after checking code
> run time by 'tic-toc'.
> And someone at google report about 'GPUmat'.
> I wonder that I can use it.
>
> if anyone can answer my question, I need your helps.
>
> Regards.
>
> Chung