From: James Tursa on
"Aristeidis " <aris262(a)hotmail.com> wrote in message <i0vkb8$kh9$1(a)fred.mathworks.com>...
>
> In the algorithm more specifically, the input images are segmented into regions (much like visual fields) which are then progressively through layers of functions translated/transformed into vectors. One of the bottom layers calculates the max of these "visual fields". The system, for example, resembles somewhat the convolutional network approach as given by Lecun (eg Lenet-5). I am afraid I cannot describe the approach much further but I do hope it gives you a better understanding.

You are getting a lot of advice on this topic, so I will throw in my 2 cents worth as well. Basically, it sounds like you have several large matrices (images) which are segmented into many more smaller matrices. The choice of how to represent the data, your overall data structure, is important because it will dictate which algorithms you can use efficiently downstream. There have been four methods offered to you for your particular max-max calculation:

1) Do it all in C/C++. This avoids all of the MATLAB overhead associated with cells, array slices, loops, etc. So a great speed improvement there. But you cannot use any MATLAB functions on the data without first copying the data into an mxArray. If you don't need much in the way of MATLAB function support, then great. Otherwise there could be a large penalty incurred with all the data copying going on every time you want to use a MATLAB function.

2) Do it all in MATLAB using your cell matrix approach. My guess is you still have the original large image hanging around in memory, and these cells are portions of that larger image matrix. Correct? That means you have already copied the array slice into a cell. Accessing this portion downstream is efficient because it has already been copied, no further copying is necessary. And the data for this small segment is in a contiguous memory block, another plus. The penalty is the cell indexing and looping does take some time.

3) Do it all in MATLAB using a meta-data approach, where you keep track of the small portions by having an array of x-y-size information. I don't see this as saving you much, if anything. To get at the data you will still at some point have to do an array slice operation (same operation you did in 2 above to get the small portion cells), so there is no time savings. There *might* be a memory savings, but probably not so much that it would make a difference in choosing a method since your slices are small.

4) Do some mixture of MATLAB and C/C++ mex routines. This would probably mean keeping the data on the MATLAB side but doing all array slice type operations on the C/C++ side to avoid the MATLAB overhead. How effective this can be will greatly depend on your ability to write mex routines, and to recognize which m-code can benefit the most by this.

Which method is *best* is going to greatly depend on how large the image data is, how many small segments you have, and how often you access them. Sounds like you have a good approach and are trying out different methods. Remember, every time you access an array slice in MATLAB, MATLAB has to copy the data. Using cell arrays can avoid this (except the first time it is copied into the cell), or using mex routines can also avoid this.

James Tursa
From: Bruno Luong on
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i0tkn0$kjm$1(a)fred.mathworks.com>...
> Dear James,
>
> > > For larger matrices, MAX(MAX(A)) can be faster than MAX(A(:)), as I have learned from a comment of Urs.
>
> > Interesting. I must have missed that thread.
>
> No, James, you did not miss a thread. It was in the FEX:
> http://www.mathworks.com/matlabcentral/fileexchange/25625
> There Urs posted (and started to call me <jan>):
> % ic2/2*2.6ghz/2gb/winxp.sp3/r2009b
> x=rand(1000);
> tic;for i=1:1000;min(x(:));end;toc
> % Elapsed time is 1.469955 seconds.
> tic;for i=1:1000;min(min(x));end;toc
> % Elapsed time is 1.491293 seconds.
> for smaller xes, its even faster...
>

I make an independent tic/toc tests with 2010A and i5 (4 cores I believe) and I did not see any significant speed difference one way or another.

Bruno
From: Jan Simon on
Dear James,

> Do you know if anyone has compiled a list of when functions (max, min, sum, etc) were multi-threaded?

Of course TMW should have this list. Obvioulsy it is an advantage not to publish it.

Jan
From: Steven Lord on

"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message
news:i11m8j$2gr$1(a)fred.mathworks.com...
> Dear James,
>
>> Do you know if anyone has compiled a list of when functions (max, min,
>> sum, etc) were multi-threaded?
>
> Of course TMW should have this list. Obvioulsy it is an advantage not to
> publish it.

I don't think we currently publish such a list (I know it's something that
users have requested) but we do document in the Release Notes when we
multithread a function. Check the Mathematics section.

http://www.mathworks.com/access/helpdesk/help/techdoc/rn/bsdgysw-1.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