Re: Matrix initialization at run-time
Peter Gottschling <[email protected]> Mon, 20 Feb 2006 08:58:01 -0500
| Newsgroups | gmane.comp.lib.mtl.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Jaime,
Why don't you call the constructor in a moment when you know the size
of the matrix? When you have initialized your grid you know the
number of unknowns, then you can construct the matrix with the right
number of rows and columns and then fill it. Something like this
int main()
{
init_grid(..., m, n, ...); // tells you the number of rows
and columns (certainly equal)
Matrix A(m, n);
setup_linear_system(A, b);
solve_linear_system(A, x, b);
}
You can write matrix values in a sparse matrix like A(3, 4) = 17.8.
I know that this is not the most efficient way for sparse matrices
if you use a compressed format. The type array2D is more efficient
in insertion but a little less efficient in using it. There will be
a fast insertion for compressed matrices in future releases.
Cheers,
Peter
On Feb 20, 2006, at 7:49 AM, Jaime Ambrus wrote:
> Hi...
>
> I'm developing a code to calculate heat transfer problems in linux
> and I would
> like to use a sparse matrix to store the linear system elements.
> I was giving a look in the MTL examples and the sparse
> initilization is done
> using arrays, but that is known at compilation time. I also tried
> pointers but
> the compilation failed. In ITL examles (Blas interface) there's some
> initialization using std::vectors but how do it at run time if
> there's no
> function to initialize the matrix and I can not call the
> constructor later??? I
> could use a dense matrix and copy it to a sparse one, but for large
> linear
> systems it is too slow...
>
> My basic idea is something like this..
>
> Matrix A(); // initialization in some header file.. in some class
> for example
> //I don't know the size at this point
> //read files and calculate some
> //stuff to initilize the matrix - vector or pointer ...
>
> A.Initilize(...); // or
> A.sparse_matrix(n,nn,nnz,*vec, /*or whatever i need */);//call in
> some way the
> constructor again
>
> Does someone have an idea ???
>
> Thanks
>
> ___________________________________________________________
> Jaime Ambrus.
>
> SINMEC - Computational Fluid Dynamics Laboratory.
> www.sinmec.ufsc.br
>
> Florianópolis - SC - Brazil.
>
> _______________________________________________
> This list is archived at http://www.osl.iu.edu/MailArchives/mtl-devel/
>
------------
Peter Gottschling
Research Associate
Open Systems Laboratory
Indiana University
301i Lindley Hall
Bloomington, IN 47405
Tel.: +1 812 855-8898 Fax: +1 812 856 0853
http://www.osl.iu.edu/~pgottsch
_______________________________________________
This list is archived at http://www.osl.iu.edu/MailArchives/mtl-devel/