int main(int argc,char **argv)
{
if(argc==3)
{
nRows=atoi(argv[1]);chunk_size=atoi(argv[2]);
}

else if(argc==2)
{
nRows=atoi(argv[1]);
printf("\nWe assuming chunk size  as  4096\n");chunk_size=4096;
}
else if(argc==1)
{
printf("\n We assuming array size as 8192 and Chunk Size as 4096\n");
nRows=8192;
chunk_size=4096;

}
nCols=nRows;
fillMatrix("./MatrixA");
printf("\n\n Matrix A is......\n\n");
//printMatrix("./MatrixA");
fillMatrix("./MatrixB");
printf("\n\n Matrix B is ...........\n\n");
fillMatrix("./MatrixC");
printf("\n\n Matric C.....\n\n");
//printMatrix("./MatrixC");

map_Matrix();
printf("\n\n-----------------------------------------------------------------------------------------------\n\n");
getchar();getchar();getchar();
printMatrix("./MatrixC");
return 0;
}
void MainWindow::on_pushButton_clicked()
{
    if ( !_started ) {
        fillMatrix(ui->tableWidget);
        fillMatrix(ui->tableWidget_2);
    }
}
Exemple #3
0
void
Nonlinear3D::computeIncrementalDeformationGradient(std::vector<ColumnMajorMatrix> & Fhat)
{
  // A = grad(u(k+1) - u(k))
  // Fbar = 1 + grad(u(k))
  // Fhat = 1 + A*(Fbar^-1)
  ColumnMajorMatrix A;
  ColumnMajorMatrix Fbar;
  ColumnMajorMatrix Fbar_inverse;
  ColumnMajorMatrix Fhat_average;
  Real volume(0);

  _Fbar.resize(_solid_model.qrule()->n_points());

  for (unsigned qp = 0; qp < _solid_model.qrule()->n_points(); ++qp)
  {
    fillMatrix(qp, _grad_disp_x, _grad_disp_y, _grad_disp_z, A);
    fillMatrix(qp, _grad_disp_x_old, _grad_disp_y_old, _grad_disp_z_old, Fbar);

    A -= Fbar;

    Fbar.addDiag(1);

    _Fbar[qp] = Fbar;

    // Get Fbar^(-1)
    // Computing the inverse is generally a bad idea.
    // It's better to compute LU factors.   For now at least, we'll take
    // a direct route.

    invertMatrix(Fbar, Fbar_inverse);

    Fhat[qp] = A * Fbar_inverse;
    Fhat[qp].addDiag(1);

    if (_volumetric_locking_correction)
    {
      // Now include the contribution for the integration of Fhat over the element
      Fhat_average += Fhat[qp] * _solid_model.JxW(qp);

      volume += _solid_model.JxW(qp); // Accumulate original configuration volume
    }
  }

  if (_volumetric_locking_correction)
  {
    Fhat_average /= volume;
    const Real det_Fhat_average(detMatrix(Fhat_average));

    // Finalize volumetric locking correction
    for (unsigned qp = 0; qp < _solid_model.qrule()->n_points(); ++qp)
    {
      const Real det_Fhat(detMatrix(Fhat[qp]));
      const Real factor(std::cbrt(det_Fhat_average / det_Fhat));

      Fhat[qp] *= factor;
    }
  }
  //    Moose::out << "Fhat(0,0)" << Fhat[0](0,0) << std::endl;
}
Exemple #4
0
int main(){

  //double **x = malloc(a * sizeof *x + (a * (b * sizeof **x)));
  //double **y = malloc(b * sizeof *y + (b * (c * sizeof **y)));
  //double **z = malloc(a * sizeof *z + (a * (c * sizeof **z)));

  int size1 = a*b*sizeof(double);
  int size2 = b*c*sizeof(double);
  int size3 = a*c*sizeof(double);

  double *x = (double*)malloc(size1);
  double *y = (double*)malloc(size2);
  double *z = (double*)malloc(size3);

  fillMatrix(x,a,b);
  fillMatrix(y,b,c);

  clock_t begin, end;
  double time_spent;
  begin = clock();

  product(x,y,z);

  end = clock();
  time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  printf("%lf\n", time_spent);

  //print(z,a,c);

  //print(z,a,c);

}
int main(int argc,char *argv[])
{
    pthread_mutex_init(&lock,NULL);
    if(argc==1)
    {
        nRows=nCols=1000;
        nThread=100;
    }
    if(argc==2)
    {
        nRows=nCols=atoi(argv[1]);
        nThread=100;
    }

    if(argc==4)
    {
        nRows=atoi(argv[1]);
        nCols=atoi(argv[2]);
        nThread=atoi(argv[3]);
    }
    int i,j;
    MatrixA=(int **)malloc(sizeof(int*)*nRows);
    for(i=0; i<nRows; i++)
        MatrixA[i]=(int *)malloc(sizeof(int)*nCols);
    MatrixB=(int **)malloc(sizeof(int*)*nCols);
    for(i=0; i<nCols; i++)
        MatrixB[i]=(int *)malloc(sizeof(int)*nRows);
    MatrixC=(int **)malloc(sizeof(int*)*nRows);
    for(i=0; i<nRows; i++)
        MatrixC[i]=(int *)malloc(sizeof(int)*nRows);
    fillMatrix(MatrixA,nRows,nCols);
    fillMatrix(MatrixB,nCols,nRows);
    rowthread=(pthread_t*)malloc(sizeof(pthread_t)*nThread);
//colthread=(pthread_t*)malloc(sizeof(pthread_t)*nThread);
//calculationthread=(pthread_t*)malloc(sizeof(pthread_t)*nThread);
    printf_matrix(MatrixA,nRows,nCols);
    printf_matrix(MatrixB,nRows,nCols);
//printf("\n  starting ---------------\n");
    for(i=0; i<nThread; i++)
    {
        printf("\n created ---\n");
        int a=pthread_create(&rowthread[i],NULL,RowMultiply,&i);
        if(a!=0)
        {

            printf("Thread Creation Error..\n");
            exit(1);
        }
    }
    for(i=0; i<nThread; i++)
        pthread_join(rowthread[i],NULL);

    printf_matrix(MatrixC,nRows,nRows);
    free(MatrixA);
    free(MatrixB);
    free(MatrixC);
    return 0;
}
int main() {
  std::cout << "Parallel Framework: " << PARALLEL_FRAMEWORK << std::endl;

  std::size_t length(1000);
  std::vector<std::vector<double>> a(length, std::vector<double>(length)),
      b(length, std::vector<double>(length)),
      c(length, std::vector<double>(length));
  fillMatrix(a);
  fillMatrix(b);

  std::chrono::high_resolution_clock::time_point t1 =
      std::chrono::high_resolution_clock::now();
  parallel_for_each(par, 0, length, [&a, &b, &c, length](std::size_t i) {
    for (std::size_t j = 0; j < length; ++j) {
      for (std::size_t k = 0; k < length; ++k) {
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  });

  std::chrono::high_resolution_clock::time_point t2 =
      std::chrono::high_resolution_clock::now();
  std::chrono::duration<double> time_span =
      std::chrono::duration_cast<std::chrono::duration<double>>(t2 - t1);
  std::cout << "It took me " << time_span.count() << " seconds." << std::endl;

  std::cout << "serial fallback: " << std::endl;
  t1 = std::chrono::high_resolution_clock::now();
  parallel_for_each(seq, 0, length, [&a, &b, &c, length](std::size_t i) {
    for (std::size_t j = 0; j < length; ++j) {
      for (std::size_t k = 0; k < length; ++k) {
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  });

  t2 = std::chrono::high_resolution_clock::now();
  time_span =
      std::chrono::duration_cast<std::chrono::duration<double>>(t2 - t1);
  std::cout << "It took me " << time_span.count() << " seconds." << std::endl;

  std::cout << "serial old: " << std::endl;
  t1 = std::chrono::high_resolution_clock::now();
  for (std::size_t i = 0; i < length; ++i) {
    for (std::size_t j = 0; j < length; ++j) {
      for (std::size_t k = 0; k < length; ++k) {
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }
  t2 = std::chrono::high_resolution_clock::now();
  time_span =
      std::chrono::duration_cast<std::chrono::duration<double>>(t2 - t1);
  std::cout << "It took me " << time_span.count() << " seconds." << std::endl;

  return 0;
}
void
gaussianEstimator_Pred ( Matrix *xEst, Matrix *CEst, Matrix *U, Matrix *Cw, Matrix (*afun)(Matrix m, float t), float *dt, Matrix *m_opt)
{
float D = elem(sizeOfMatrix(*m_opt),0,1)+1;       //printf("%f\n", D);
float w_opt = 1/D;                                //printf("%f\n", w_opt);
float Nx = elem(sizeOfMatrix(*xEst),0,0);         //printf("%f\n", Nx);
float d = Nx*(D-1) + 1;                           //printf("%f\n", d);
float w = 1/d;                                    //printf("%f\n", w);

/* Eigenvectors, Eigenvalues */
int dimC = elem ( sizeOfMatrix(*CEst), 0, 0 );
Matrix Vec = zeroMatrix(dimC, dimC);    
Matrix Val = zeroMatrix(dimC, dimC);
eig ( CEst, &Vec, &Val );

/* m1 = vec*sqrtf(val) */
int i;
for ( i = 0; i < dimC; ++i )
    setElem(Val, i, i, sqrtf(fabs(elem(Val, i,i))));
Matrix m1 = mulMatrix(Vec, Val);

freeMatrix(Vec);
freeMatrix(Val);

/*  rotate & scale samples: m = m1*S */
Matrix m = scaledSamplePoints(m1, *m_opt);

/* x = x*ones(1,d) */
Matrix x = fillMatrix(*xEst, d);

/* shift samples: m = m + x */
m = addMatrix(m, x);              //printMatrix(m);

/* afun */
/* Prediction: mean
   xPredDiracs = feval(afun,m, [], [], t);
   xPred = w*sum(xPredDiracs, 2);*/
   
Matrix xPredDiracs = (*afun) (m, *dt);                   //printMatrix(xPredDiracs);
Matrix xPredDiracsSum = sumMatrix(xPredDiracs, 2);       //printMatrix(xPredDiracsSum);
Matrix xPred = mulScalarMatrix(w, xPredDiracsSum);       //printMatrix(xPred);

//mxDiracs = xPredDiracs-repmat(xPred, 1, d);
//CPred = w_opt*mxDiracs*mxDiracs';
Matrix mxDiracs = subMatrix(xPredDiracs, fillMatrix(xPred, d));   //printMatrix(mxDiracs);
Matrix CPred = mulScalarMatrix(w_opt, mulMatrix(mxDiracs, transposeMatrix(mxDiracs)));  //printMatrix(CPred);


//RETURN
*xEst = xPred;        //printMatrix(*xEst);
*CEst = CPred;        //printMatrix(*CEst);

freeMatrix(m);
freeMatrix(xPredDiracs);
freeMatrix(xPredDiracsSum);
}
int main(int argc,char **argv)
{
    pthread_mutex_init(&lock,NULL);
    if(argc==4)
    {
        nRows=atoi(argv[1]);
        chunk_size=atoi(argv[2]);
        nThread=atoi(argv[3]);
        if(chunk_size&(chunk_size-1)!=0)
        {
            printf("\n Chunk_Size should be Power of 2\n");
            exit(1);
        }
    }

    else if(argc==2)
    {
        nRows=atoi(argv[1]);
        nThread=16;
        printf("\nWe assuming chunk size  as  4096 and nThread  as 16\n");
        chunk_size=4096;
    }
    else if(argc==1)
    {
        printf("\n We assuming array size as 8192 and Chunk Size as 4096 and nThread as 16\n");
        nRows=8192;
        chunk_size=4096;
        nThread=16;
    }
    nCols=nRows;

    fillMatrix("./MatrixA");
    printf("\n\n Matrix A is......\n\n");
//printMatrix("./MatrixA");
    fillMatrix("./MatrixB");
    printf("\n\n Matrix B is ...........\n\n");
//printMatrix("./MatrixB");
    fillMatrix("./MatrixC");
    printf("\n\n Matric C.....\n\n");
//printMatrix("./MatrixC");
    nRows=nRows;
    nCols=nRows+padding;
    thread_block=nRows/nThread;
    t=(pthread_t *)malloc(sizeof(pthread_t)*nThread);
    struct timeval tv_start,tv_end;
    gettimeofday(&tv_start,NULL);
    map_Matrix();
    gettimeofday(&tv_end,NULL);
    nCols=nCols-padding;
    padding=0;
//printMatrix("./MatrixC");
    printf("\n\n-----------------------------------------------------------------------------------------------\n\n");

    printf("\n \n time taken is  %f sec \n",(double)((tv_end.tv_sec-tv_start.tv_sec)+((tv_end.tv_usec-tv_start.tv_usec)*0.000001)));
    return 0;
}
int main(int argc,char **argv)
{
	if(argc==3)
	{
			nRows=atoi(argv[1]);chunk_size=atoi(argv[2]);
		if(chunk_size&(chunk_size-1)!=0)
		{
			printf("\n Chunk_Size should be Power of 2\n");
			exit(1);
		}
	}

	else if(argc==2)
	{
			nRows=atoi(argv[1]);
			printf("\nWe assuming chunk size  as  4096\n");chunk_size=4096;
	}
	else if(argc==1)
	{
			printf("\n We assuming array size as 8192 and Chunk Size as 4096\n");
			nRows=8192;
			chunk_size=4096;

	}
		nCols=nRows;
padding=nRows%(chunk_size/4);//if nRows not power of 2
	if(padding!=0)
	padding=chunk_size/4-padding;

fillMatrix("./MatrixA");
printf("\n\n Matrix A is......\n\n");
//printMatrix("./MatrixA");
fillMatrix("./MatrixB");
printf("\n\n Matrix B is ...........\n\n");
//printMatrix("./MatrixB");
fillMatrix("./MatrixC");
printf("\n\n Matric C.....\n\n");
//printMatrix("./MatrixC");
nRows=nRows;
nCols=nRows+padding;//appaanding 0's when rwo is not multiple of page size

struct timeval tv_start,tv_end;
gettimeofday(&tv_start,NULL);

map_Matrix();
gettimeofday(&tv_end,NULL);
nCols=nCols-padding;
padding=0;

//printMatrix("./MatrixC");
printf("\n\n-----------------------------------------------------------------------------------------------\n\n");

printf("\n \n time taken is  %f sec ",(double)((tv_end.tv_sec-tv_start.tv_sec)+((tv_end.tv_usec-tv_start.tv_usec)/1000000)));
return 0;
}
Exemple #10
0
Eigen::Block<M,Rows,Cols> returnBlock() {
    static typename boost::remove_const<typename boost::remove_reference<M>::type>::type m(3,4);
    m.setZero();
    Eigen::Block<M,Rows,Cols> b(m, 1, 0, 2, 3);
    fillMatrix(b);
    return b;
}
bool
SMatrix::calculate(double Frequency){
 fillMatrix(Frequency);

 QValueList<FormulaElement>::Iterator it;
 for ( it = Formula.List.begin(); it != Formula.List.end(); it++) {
   switch((*it).formula()) {
    case 0: *(SMatrix_ + (*it).a()) =  *(SMatrix_ + (*it).b()) * *(SMatrix_ + (*it).c());
            break;
    case 1: *(SMatrix_ + (*it).a()) += *(SMatrix_ + (*it).b()) * *(SMatrix_ + (*it).c());
            break;
    case 2: *(SMatrix_ + (*it).a()) =  *(SMatrix_ + (*it).b()) * *(SMatrix_ + (*it).c()) / (1.0 - *(SMatrix_ + (*it).d()));
            break;
    case 3: *(SMatrix_ + (*it).a()) += *(SMatrix_ + (*it).b()) * *(SMatrix_ + (*it).c()) / (1.0 - *(SMatrix_ + (*it).d()));
            break;
    default: break;
   }
 }
//   std::cout << "S11: (" << s11().real() << "," << s11().imag() << ")  ";
//   std::cout << "S12: (" << s12().real() << "," << s12().imag() << ")  ";
//   std::cout << "S21: (" << s21().real() << "," << s21().imag() << ")  ";
//   std::cout << "S22: (" << s22().real() << "," << s22().imag() << ")\n";

 return true;
}
int main(int argc, char *argv[])
{
  int rows = SIZE;
  int cols = SIZE;
  float density = DENSITY;

  EigenSparseMatrix sm1(rows,cols), sm3(rows,cols);

  BenchTimer timer;
  for (float density = DENSITY; density>=MINDENSITY; density*=0.5)
  {
    fillMatrix(density, rows, cols, sm1);

    // dense matrices
    #ifdef DENSEMATRIX
    {
      DenseMatrix m1(rows,cols), m3(rows,cols);
      eiToDense(sm1, m1);
      BENCH(for (int k=0; k<REPEAT; ++k) m3 = m1.transpose();)
      std::cout << "  Eigen dense:\t" << timer.value() << endl;
    }
    #endif

    std::cout << "Non zeros: " << sm1.nonZeros()/float(sm1.rows()*sm1.cols())*100 << "%\n";

    // eigen sparse matrices
    {
      BENCH(for (int k=0; k<REPEAT; ++k) sm3 = sm1.transpose();)
      std::cout << "  Eigen:\t" << timer.value() << endl;
    }
Exemple #13
0
int main(int argc, char *argv[])
{
  int rows = SIZE;
  int cols = SIZE;
  float density = DENSITY;
  BenchTimer timer;
  #if 1
  EigenSparseTriMatrix sm1(rows,cols);
  typedef Matrix<Scalar,Dynamic,1> DenseVector;
  DenseVector b = DenseVector::Random(cols);
  DenseVector x = DenseVector::Random(cols);

  bool densedone = false;

  for (float density = DENSITY; density>=MINDENSITY; density*=0.5)
  {
    EigenSparseTriMatrix sm1(rows, cols);
    fillMatrix(density, rows, cols, sm1);

    // dense matrices
    #ifdef DENSEMATRIX
    if (!densedone)
    {
      densedone = true;
      std::cout << "Eigen Dense\t" << density*100 << "%\n";
      DenseMatrix m1(rows,cols);
      Matrix<Scalar,Dynamic,Dynamic,Dynamic,Dynamic,RowMajorBit> m2(rows,cols);
      eiToDense(sm1, m1);
      m2 = m1;

      BENCH(x = m1.marked<UpperTriangular>().solveTriangular(b);)
      std::cout << "   colmajor^-1 * b:\t" << timer.value() << endl;
//       std::cerr << x.transpose() << "\n";

      BENCH(x = m2.marked<UpperTriangular>().solveTriangular(b);)
Exemple #14
0
int main() {
	typedef hpc12::matrix<double,hpc12::column_major> matrix_type;
	matrix_type A(10,10);
	fillMatrix(A);
	
	std::cout << A;

	return 0;
}
Exemple #15
0
Real
NonlinearRZ::volumeRatioOld(unsigned int qp) const
{
  ColumnMajorMatrix Fnm1T;
  fillMatrix( qp, _grad_disp_r_old, _grad_disp_z_old, _disp_r_old, Fnm1T);
  Fnm1T.addDiag( 1 );

  return detMatrix(Fnm1T);
}
// class definition
TestCpp::TestCpp(int N_, const MyArray<double>& A): N(N_){
	cout<<endl;
	cout << "Printing from the constructor of TestCpp" << endl;
	cout << "N: " << N << endl;

	someArray.redim(N, N);	// Now someArray = A and someArray.size = NxN

	fillMatrix(A);
}
Exemple #17
0
saulZeroKernel::saulZeroKernel(matd &data, unsigned int l):_l(l){
  fillMatrix(data,_data);
  _data.transposeInPlace();
  _p = _data.rows();
  _n = _data.cols();
  _dataNorm.resize(_n);
  for(size_t i=0; i<_n;++i){
    _dataNorm(i) = _data.col(i).stableNorm();
  }
}
Exemple #18
0
int main(int argc, char** argv)
{
/*    printf("argc=%d\n", argc);
    int ss;
    for(ss = 0; ss < argc; ss++)
        printf("argv#%d=%s\n", ss, argv[ss]);
*/

    int N;
    scanf("%d", &N);
    matrix *M1 = malloc(sizeof(matrix)), *M2 = malloc(sizeof(matrix));
    mallocMatrix(M1, N, N);
    mallocMatrix(M2, N, N);

    fillMatrix(M1);

    #ifdef DEBUG
        fprintf(stderr, "A=\n");
        printMatrix(M1);
    #endif

    getInverseCopy(M1, M2, NULL);

    #ifdef DEBUG
        fprintf(stderr, "A^-1=\n");
        printMatrix(M2);
    #else
        if(argc == 1 || (argc >= 2 && argv[1][0] == 'i'))
        {
            printf("%d\n", M2->R);
            printMatrix(M2);
        }
    #endif

    matrix *M3 = malloc(sizeof(matrix));
    mallocMul(M1, M2, M3);
    mulMatrix(M1, M2, M3);

    #ifdef DEBUG
        fprintf(stderr, "A*A^-1=\n");
        printMatrix(M3);
    #else
        if(argc >= 2 && argv[1][0] == 'e')
        {
            printf("%d\n", M3->R);
            printMatrix(M3);
        }
    #endif

    freeMatrix(M1);
    freeMatrix(M2);

    return(0);
}
Exemple #19
0
int main() {
	omp_set_num_threads(16);
	typedef hpc12::matrix<double,hpc12::column_major> matrix_type;
	for (int N = 512;N < 20000;N*=2) {
		matrix_type A(N,N);
		matrix_type B(N,N);
		matrix_type C(N,N);
		fillMatrix(A);
		fillMatrix(B);
		//C = A*B
		Timer _t(1);
		dgemm_libsci(A,B,C);
		_t.stop();
		Measurement m("dgemm with acml ,16thrds",N,N,_t.elapsed_s());
		std::cout << m;
	}


	return 0;
}
Exemple #20
0
 vector<vector<int>> generateMatrix(int n) {
     vector<vector<int>> res;
     for (int i = 0; i < n; i++) {
         vector<int> row;
         for (int j = 0; j < n; j++)
             row.push_back(0);
         res.push_back(row);
     }
     fillMatrix(res, n, 0, 1);
     return res;
 }
Exemple #21
0
int main(int argc, char** argv) {
    std::cout << "YARP math test" << std::endl;

    int vec_times = 1000;
    int mat_times = 1;
    int vec_size = 1000000;
    int mat_size = 1000;
    double t1, t2;

    yarp::sig::Vector vec = yarp::sig::Vector(vec_size);
    yarp::sig::Matrix mat = yarp::sig::Matrix(mat_size, mat_size);
    yarp::sig::Vector matvec = yarp::sig::Vector(mat_size);

    t1 = yarp::os::Time::now();
    fillVector(vec);
    t2 = yarp::os::Time::now();
    std::cout << "Filling random vector(" << vec.size() << "): " << (t2 - t1) << std::endl;

    t1 = yarp::os::Time::now();
    fillMatrix(mat);
    t2 = yarp::os::Time::now();
    std::cout << "Filling random matrix(" << mat.rows() << "," << mat.cols() << "): " << (t2 - t1) << std::endl;
    fillVector(matvec);

    t1 = yarp::os::Time::now();
    for(int i = 0; i < vec_times; i++) {
        double t = yarp::math::dot(vec, vec);
    }
    t2 = yarp::os::Time::now();
    std::cout << "Vector dot product: " << (t2 - t1) << std::endl;

    t1 = yarp::os::Time::now();
    for(int i = 0; i < vec_times; i++) {
        yarp::sig::Vector t = yarp::math::operator*(mat, matvec);
    }
    t2 = yarp::os::Time::now();
    std::cout << "Matrix/Vector product: " << (t2 - t1) << std::endl;

    t1 = yarp::os::Time::now();
    for(int i = 0; i < mat_times; i++) {
        yarp::sig::Matrix t = yarp::math::operator*(mat, mat);
    }
    t2 = yarp::os::Time::now();
    std::cout << "Matrix/Matrix product: " << (t2 - t1) << std::endl;

    t1 = yarp::os::Time::now();
    for(int i = 0; i < mat_times; i++) {
        yarp::sig::Matrix t = yarp::math::luinv(mat);
    }
    t2 = yarp::os::Time::now();
    std::cout << "Matrix inverse: " << (t2 - t1) << std::endl;

}
int main(int argc, char *argv[])
{
  int rows = SIZE;
  int cols = SIZE;
  float density = DENSITY;

  EigenSparseMatrix sm1(rows,cols);
  DenseVector v1(cols), v2(cols);
  v1.setRandom();

  BenchTimer timer;
  for (float density = DENSITY; density>=MINDENSITY; density*=0.5)
  {
    fillMatrix(density, rows, cols, sm1);

    // dense matrices
    #ifdef DENSEMATRIX
    {
      std::cout << "Eigen Dense\t" << density*100 << "%\n";
      DenseMatrix m1(rows,cols);
      eiToDense(sm1, m1);

      timer.reset();
      timer.start();
      for (int k=0; k<REPEAT; ++k)
        v2 = m1 * v1;
      timer.stop();
      std::cout << "   a * v:\t" << timer.value() << endl;

      timer.reset();
      timer.start();
      for (int k=0; k<REPEAT; ++k)
        v2 = m1.transpose() * v1;
      timer.stop();
      std::cout << "   a' * v:\t" << timer.value() << endl;
    }
    #endif

    // eigen sparse matrices
    {
      std::cout << "Eigen sparse\t" << sm1.nonZeros()/float(sm1.rows()*sm1.cols())*100 << "%\n";

      BENCH(for (int k=0; k<REPEAT; ++k) v2 = sm1 * v1;)
      std::cout << "   a * v:\t" << timer.value() << endl;

      
      BENCH(for (int k=0; k<REPEAT; ++k) { asm("#mya"); v2 = sm1.transpose() * v1; asm("#myb"); })
      
      std::cout << "   a' * v:\t" << timer.value() << endl;
    }
int
main(int argc, char *argv[])
{
    float density;   // density of the platform
    int cells;       // amount of calculated living cells based on the density and size (size*size*density/100)
    int steps = 1;

    // init global platform
    platform.row    = SIZE;
    platform.column = SIZE;

    cplat.row    = SIZE;
    cplat.column = SIZE;

    // user input
    printf("Bitte geben Sie die Dichte des Spielfelds (in Prozent) ein : ");
    do {scanf("%f",&density);} while (getchar() != '\n');

    // calculate amount of cells
    cells = calculateCellCount(density);
    printf("Returning number of living Cells %i", cells);

    // filling matrix with random positioning of cells
    platform = fillMatrix (platform, cells);  
    showMatrix (platform);

    // start iterating
    clock_t last = clock();
    while(1){
        clock_t current = clock();
        if (current >= (last + TIME_TO_WAIT * CLOCKS_PER_SEC)) {
           printf ("\nNach dem %i Schritt(en):\n", steps);
           steps++;
           cplat = platform;
           platform = iterateMatrix (platform);

           // If it's the same after two steps, stop it
           if (compareMatricies (platform, cplat)) {
               printf ("\nDie Matrix verändert sich nicht mehr!\n\n");
               return EXIT_SUCCESS;
            }

           showMatrix (platform);

           // reset timer
           last = current;
        }
    }
}
Exemple #24
0
void main()
{
   
   
   printf("Enter the number of cities: ");
   scanf("%d",&n);

   printf("\n The adjacency matrix of the random Hamiltonian Graph is: \n");
   fillMatrix(n);
   
   printf("\n Without the loss of generality, assuming the tour starts from node 0. The solution is : \n  0 ---> ");
  
   greedyCalculate();
   
}
Exemple #25
0
int main()
{
setlocale(LC_ALL , "Russian");

int i=0, k=0, max=0, height, width, lenght;

const int n=5, m=5;
cout << "Введите высоту и ширину матрицы" << endl;

cin >> height >> width;

int** matrix = new int*[height]; //Выделение памяти для двухмерного массива matrix
{
	for (i=0; i < height; i++) matrix[i] = new int[width];	//Введение массивов в массив matrix
}
int* vector = new int[width]; 

int* resultVector = new int[width];

int* result = new int[width];

fillArray(vector,width);

fillMatrix(matrix, height, width);

multiply(matrix, vector, result, width, height);

display(result, width);

showMaxElement(result, width);

delete []vector;

delete []resultVector;

delete []result;

for(int i = 0; i < height; i++)
{
	delete[] matrix[i];
}

delete[] matrix;

system("pause");

return 0;
}
Exemple #26
0
    void fillMatrix(vector<vector<int>>& matrix, int n, int round, int start) {
        if (n < 1) return;
        if (n == 1) { matrix[round][round] = start; return ; }

        for (int t = 0; t < 4 * (n - 1); t++) {
            int times = t / (n - 1);
            int i, j;
            if      (times == 0) { i = round;                   j = round + t; }
            else if (times == 1) { i = round + t % (n - 1);     j = round + n - 1; }
            else if (times == 2) { i = round + n - 1;               j = round + n - 1 - t % (n - 1); }
            else                 { i = round + n - 1 - t % (n - 1); j = round; }
            matrix[i][j] = start++;
        }

        fillMatrix(matrix, n - 2, round + 1, start);
    }
Exemple #27
0
Real
NonlinearPlaneStrain::volumeRatioOld(unsigned int qp) const
{
  Real strain_zz_old;
  if (_have_strain_zz)
    strain_zz_old = _strain_zz_old[qp];
  else if (_have_scalar_strain_zz && _scalar_strain_zz.size()>0)
    strain_zz_old = _scalar_strain_zz_old[qp];
  else
    strain_zz_old = 0.0;

  ColumnMajorMatrix Fnm1T;
  fillMatrix( qp, _grad_disp_x_old, _grad_disp_y_old, strain_zz_old, Fnm1T);
  Fnm1T.addDiag( 1 );

  return detMatrix(Fnm1T);
}
Exemple #28
0
int main()
{
    int rows, cols = 0;
    printf("Rows:\n");
    scanf("%d", &rows);
    printf("Cols:\n");
    scanf("%d", &cols);
    int **array = new int*[rows];
    fillMatrix(array, rows, cols);
    MatrixSorter *sorter = new MatrixSorter(array, rows, cols);
    printf("Before sort:\n");
    sorter->print();
    printf("Arter sort:\n");
    sorter->sort();
    sorter->print();
    delete sorter;
    return 0;
}
Exemple #29
0
int main(){

double **matrix, *vector, *result;
int i,j;
matrix = malloc(SIZE * sizeof(double *));
for (i = 0; i < SIZE; i++){
  matrix[i] = malloc(SIZE * sizeof(double *));
}
vector = malloc(SIZE * sizeof(double *));
result = malloc(SIZE * sizeof(double *));

fillMatrix(matrix,SIZE,SIZE);
fillVector(vector,SIZE);
SAXPY(vector,matrix,result,SIZE);
//pr(result,SIZE);
free(matrix);
free(vector);
free(result);
return 0;
}
Exemple #30
0
void main()
{
  int n,i;
  printf("Enter the number of cities: ");
  scanf("%d",&n);

  printf("\nThe adjacency matrix of the random Hamiltonian Graph is: \n");
  fillMatrix(n);

  Array init;

  for(i=1;i<n;i++)
  {
    init.myArray[i-1]=i;
  }
 
  int result;
  result = optimal(0,init,n-1);
  printf("\n The optimal route cost is %d \n",result); 
}