[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## DLD files and memory allocation

**From**: |
Fredrik Lingvall |

**Subject**: |
DLD files and memory allocation |

**Date**: |
Fri, 27 Jan 2006 18:01:21 +0100 |

**User-agent**: |
Mozilla Thunderbird 1.0.7 (X11/20051019) |

Hi,

`I am working on a few MEX/DLD functions for performing in-place
``operation on
``(large) matrices for SMP-machines. The simplest one is just for copying
``data from
`one matrix to another using several threads in parallel.
I'm doing this by changing the contents of pre-allocated matrices to avoid

`the overhead of (temporary) allocating new memory. Using Matlab this
``works fine, but
``in Octave the address of the input parameters seems to change when I
``call the copy function
``several times. Furthermore, altering the contents of an input parameter
``has no effect.
`
An example (I do a printf("A = %p B = %p\n",A,B); inside the mex-function)
1) Matlab:
>> n_threads = 1;
>> A = zeros(5,5);
>> B = randn(5,5);
>> copy_p(A,[1 5],[1 5],B,n_threads);
A = 0xb53e4a70 B = 0xb53e4c30
>> copy_p(A,[1 5],[1 5],B,n_threads);
A = 0xb53e4a70 B = 0xb53e4c30
>> copy_p(A,[1 5],[1 5],B,n_threads);
A = 0xb53e4a70 B = 0xb53e4c30
>> copy_p(A,[1 5],[1 5],B,n_threads);
A = 0xb53e4a70 B = 0xb53e4c30
The adress of A and B do not change between calls.
2) Octave (2.1.71):
octave:18> n_threads = 1;
octave:19> A = zeros(5,5);
octave:20> B = randn(5,5);
octave:21> copy_p(A,[1 5],[1 5],B,n_threads);
A = 0x8b31cf0 B = 0x8b31f40
octave:22> copy_p(A,[1 5],[1 5],B,n_threads);
A = 0x8b31cf0 B = 0x8b31780
octave:23> copy_p(A,[1 5],[1 5],B,n_threads);
A = 0x8b317d8 B = 0x8b32060
octave:24> copy_p(A,[1 5],[1 5],B,n_threads);
A = 0x8b316d8 B = 0x8b32018
Here A and B gets a new adress each time I call the function. Does this
mean that Octave make copies of all input parameters? Not good
if A and B is large.
I'm using the octave-forge mex-tools for building the oct-files.
/Fredrik
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------

**DLD files and memory allocation**,
*Fredrik Lingvall* **<=**