[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] How to efficiently use temporary vectors and matrices

From: M Atakan Gurkan
Subject: Re: [Help-gsl] How to efficiently use temporary vectors and matrices
Date: Thu, 12 Feb 2004 18:33:51 -0600
User-agent: Mutt/

On Fri, Feb 13, 2004 at 01:25:10AM +0100, Boris Langendoen wrote:
> Hello,
> The problem I have, is that I have written several functions, each of 
> which needs a number of 'temporary' matrices and vectors to do its 
> internal calculations. These matrices and vectors' sizes can be computed 
>   when the filter starts, and remain fixed during runtime. The values of 
> the elements are not always constant.
> If I follow the examples from the gsl documentation, I see only two 
> options to create these temporary matrices within my functions.
> Either (re-)allocate all the temporary matrices each time I call a 
> function, fill them with the required values and then use them. I have 
> been told this is not very fast, and looks unnecessarily complex to me.
> Or allocate all the temporary matrices when the filter starts (during 
> the startup routine), and pass them as arguments to the functions. This 
> should make the code fast in the sense that allocation / deallocation 
> will not have to be done so often, but is also complex as all the 
> temporary matrices are declared and allocated somewhere outside of the 
> calling functions (at the moment I need 37 temporary matrices and 27 
> temporary vectors in total). It also looks like quite hard to debug.
> I would like to know if I missed some (perhaps obvious) solution to this 
> problem. I am not a computer science student so I have no formal 
> training in the field.
it is not a nice solution and makes debugging harder unless you document
it but, you can make your matirces etc.  global variables. this way you
allocate and free them once (possibly in a seperate routine), and still
access them from within your functions without passing them as arguments.

a harder but IMHO cleaner solution is to put related matrices etc. into
different structures and pass these to functions. it won't bloat your
prototypes, but you won't have the confusion of global variables.

good luck,


reply via email to

[Prev in Thread] Current Thread [Next in Thread]