Example #1
0
int main( int argc, char *argv[] )
{
	/* Matrix B of size mxn times vector c, storing the result in vector a. */
	/* The result is obtained by computing the dot product of the rows of 	*/
	/* matrix B and vector c. */

	double *a, *b, *c;
	int i, j, m, n;

	printf( "Matrix B is mxn, give m and n:" );
	scanf( "%d %d", &m, &n );

	if( ( a = (double *) malloc( m*sizeof(double) ) ) == NULL )
		perror( "Memory alloaction error for a" );
	if( ( b = (double *) malloc( m*n*sizeof(double) ) ) == NULL )
		perror( "Memory alloaction error for b" );
	if( ( c = (double *) malloc( n*sizeof(double) ) ) == NULL )
		perror( "Memory alloaction error for c" );

	printf( "Initializing vector c (nx1), c[i]=2, 1<=i<=n\n" );
	for( j=0; j<n; j++ )
	{
		c[j] = 2.0;
		printf( "%8.6f ", c[j] );
	}
	printf( "\n" );

	printf( "Initializing matrix B (mxn)\n" );
	for( i=0; i<m; i++ )
	{
		for( j=0; j<n; j++ )
		{
			b[i*n+j] = i;
			printf( "%8.6f ", b[i*n+j] );
		}
		printf( "\n" );
	}

	printf( "Executing mxv function for m = %d, n = %d\n", m, n );
	(void) mxv( m, n, a, b, c );

	printf( "Result is matrix a=Bc (mx1):\n" );
	for( i=0; i<m; i++ )
		printf( "%8.6f ", a[i] );
	printf( "\n" );

	free(a);
	free(b);
	free(c);
	return(0);
}
int main( int argn, char *arg[] )
{
  srand( 1234567 );
  omp_set_num_threads(2);
  
  std::cout << "Number columns:      " << N_COL << std::endl;
  std::cout << "Number rows:         " << N_ROW << std::endl;
  std::cout << "Total Number Values: " << N_ROW * N_COL << std::endl;
  std::cout << "Number Non-Zeros:    " << NNZ << std::endl;
  std::cout << "Max Number Threads:  " << omp_get_max_threads() << std::endl;
  
  // allocate some memory
  // ... for matrix and fill it with random values
  double Aval[NNZ] = {1.0, 3.0, 4.0, 2.0, 5.0, 2.0, 1.0};
  int AcolInd[NNZ] = {1,   3,   2,   0,   4,   2,   3};
  int ArowPt[N_ROW+1] = {0, 2, 3, 5, 6};
  
  // ... for vector and fill it with random, non-zero, values
  double Vval[N_COL] = {1.0, 3.0, 4.0, 2.0, 3.0};
  
  // ... for result and make sure, it's zero everywhere
  double Yval[N_ROW];
  for ( int i = 0; i < N_ROW; i++ ) {
    Yval[i] = 0;
  }
  
  // print input if dimenions not too high
  if ( N_COL < 10 && N_ROW < 10 && NNZ < 15 ) {
    printSparseMat( Aval, AcolInd, ArowPt );
    printVec( Vval, N_COL );
  }
  
  // multiply --- here we go!
  mxv( Aval, AcolInd, ArowPt, Vval, Yval );
  
  // print result if dimenions not too high
  if ( N_ROW < 10 ) {
    printVec( Yval, N_ROW );
  }
  // print squared norm of solution vector as a measurement for correctness
  double sqnorm = 0;
  for ( int i = 0; i < N_ROW; i++ ) {
    sqnorm += Yval[i] * Yval[i];
  }
  std::cout << "Squared Norm of Y is: " << sqnorm << std::endl;
}
Example #3
0
void test_mul(VectorF3 & res, const Matrix3x3 & m, const VectorF3 & v){
  return mxv(res, m, v);
}