Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## [Libmesh-users] Sparsematrix vector multiplication

 [Libmesh-users] Sparsematrix vector multiplication From: John Peterson - 2006-03-30 23:53:43 ```David Xu writes: > Hi Group, > > This is a function I wrote for result = global_matrix_A * x, it > compiles okay. but when I run the code, petsc gives me errors which > are not straightforward for debug. Can anybody give me some hints? > > SparseMatrix *global_matrix_A; > void apply_matrix_A( double *x, double *result ) > { > const unsigned int n=global_matrix_A->m(); > NumericVector *vec_result; > NumericVector *vec_x; You haven't allocated any storage for vec_x or vec_result > // copy data > for( unsigned int i=0; i vec_x->set(i, x[i]); > // multiplication > vec_result->add_vector(*vec_x, *global_matrix_A); > // copy data > for( unsigned int i=0; i result[i] = vec_result->operator()(i); > }; ```

 [Libmesh-users] Sparsematrix vector multiplication From: David Xu - 2006-03-30 23:43:39 ```Hi Group, This is a function I wrote for result =3D global_matrix_A * x, it compiles okay. but when I run the code, petsc gives me errors which are not straightforward for debug. Can anybody give me some hints? SparseMatrix *global_matrix_A; void apply_matrix_A( double *x, double *result ) { const unsigned int n=3Dglobal_matrix_A->m(); NumericVector *vec_result; NumericVector *vec_x; // copy data for( unsigned int i=3D0; iset(i, x[i]); // multiplication vec_result->add_vector(*vec_x, *global_matrix_A); // copy data for( unsigned int i=3D0; ioperator()(i); }; Thanks, David ```
 [Libmesh-users] Sparsematrix vector multiplication From: John Peterson - 2006-03-30 23:53:43 ```David Xu writes: > Hi Group, > > This is a function I wrote for result = global_matrix_A * x, it > compiles okay. but when I run the code, petsc gives me errors which > are not straightforward for debug. Can anybody give me some hints? > > SparseMatrix *global_matrix_A; > void apply_matrix_A( double *x, double *result ) > { > const unsigned int n=global_matrix_A->m(); > NumericVector *vec_result; > NumericVector *vec_x; You haven't allocated any storage for vec_x or vec_result > // copy data > for( unsigned int i=0; i vec_x->set(i, x[i]); > // multiplication > vec_result->add_vector(*vec_x, *global_matrix_A); > // copy data > for( unsigned int i=0; i result[i] = vec_result->operator()(i); > }; ```
 Re: [Libmesh-users] Sparsematrix vector multiplication From: David Xu - 2006-03-31 00:13:33 ```> > > > This is a function I wrote for result =3D global_matrix_A * x, it > > compiles okay. but when I run the code, petsc gives me errors which > > are not straightforward for debug. Can anybody give me some hints? > > > > SparseMatrix *global_matrix_A; > > void apply_matrix_A( double *x, double *result ) > > { > > const unsigned int n=3Dglobal_matrix_A->m(); > > NumericVector *vec_result; > > NumericVector *vec_x; > > You haven't allocated any storage for vec_x or vec_result I tried NumericVector *vec_result(n); didn't work. How should I do that? > > > // copy data > > for( unsigned int i=3D0; i > vec_x->set(i, x[i]); > > // multiplication > > vec_result->add_vector(*vec_x, *global_matrix_A); > > // copy data > > for( unsigned int i=3D0; i > result[i] =3D vec_result->operator()(i); > > }; > ```
 Re: [Libmesh-users] Sparsematrix vector multiplication From: John Peterson - 2006-03-31 00:52:03 ```David Xu writes: > > > > > > This is a function I wrote for result = global_matrix_A * x, it > > > compiles okay. but when I run the code, petsc gives me errors which > > > are not straightforward for debug. Can anybody give me some hints? > > > > > > SparseMatrix *global_matrix_A; > > > void apply_matrix_A( double *x, double *result ) > > > { > > > const unsigned int n=global_matrix_A->m(); > > > NumericVector *vec_result; > > > NumericVector *vec_x; > > > > You haven't allocated any storage for vec_x or vec_result > I tried > NumericVector *vec_result(n); > didn't work. How should I do that? Remove the star. You are creating a pointer. > > > > > > // copy data > > > for( unsigned int i=0; i > > vec_x->set(i, x[i]); > > > // multiplication > > > vec_result->add_vector(*vec_x, *global_matrix_A); > > > // copy data > > > for( unsigned int i=0; i > > result[i] = vec_result->operator()(i); > > > }; > > ```