Exemplo n.º 1
0
void SpinAdapted::MatrixMultiply (double d, const Matrix& a, Matrix& b)
{
  //  b += d * a;
#ifdef BLAS 
  assert ((a.Nrows () == b.Nrows ()) && (a.Ncols () == b.Ncols ()));
  int n = a.Nrows () * a.Ncols ();
  GAXPY (n, d, a.Store (), 1, b.Store (), 1);
#else
  b += d * a;
#endif
}
Exemplo n.º 2
0
/** 
 * Perform \f$self := scalar \times x + self\f$.
 *
 * @param self   A vector object.
 * @param x      Another vector object.
 * @param scalar A scalar.
 *
 * @return 0 on success.
 */
int parms_VecAXPY(FLOAT *self, FLOAT *x, FLOAT scalar, parms_Map map)   
{
    int i, lsize;

    lsize = parms_MapGetLocalSize(map);

#ifdef HAS_BLAS
    i = 1;
    GAXPY(lsize, scalar, x, i, self, i);
#else
    for (i = 0; i < lsize; i++)
    {
        self[i] += scalar * x[i];
    }
#endif 

    return 0;
}
Exemplo n.º 3
0
/**
 * Perform \f$self = scalar \times self + x\f$.(block version)
 *
 * @param self    A vector object.
 * @param x 	  Another vector object.
 * @param scalar  A scalar.
 *
 * @return 0 on success.
 */
int parms_VecAYPX_b(FLOAT *self, FLOAT *x, FLOAT scalar, parms_Map map)
{
    int lsize, i;
    lsize = parms_MapGetLocallSize(map);//should be point lsize instead of block lsize

#ifdef HAS_BLAS
    FLOAT  t;
    i = 1;
    t = 1.0;
    GSCAL(lsize, scalar, self, i);
    GAXPY(lsize, t, x, i, self, i);
#else

    for (i = 0; i < lsize; i++) {
        self[i] = scalar * self[i] + x[i];
    }
#endif 
    return 0;
}
Exemplo n.º 4
0
void SpinAdapted::MatrixTensorProduct (const Matrix& a_ref, char conjA, Real scaleA, const Matrix& b_ref, char conjB, Real scaleB, Matrix& c, int rowstride, int colstride, bool allocate)
{
#ifndef BLAS
  Matrix A;
  Matrix B;
#endif
  Matrix& a = const_cast<Matrix&>(a_ref); // for BLAS calls
  Matrix& b = const_cast<Matrix&>(b_ref);

  int arows = a.Nrows();
  int acols = a.Ncols();
  
  // some specialisations
#ifdef FAST_MTP
  //  if ((brows == 1) && (bcols == 1))
    {
      double b00 = *b.Store();
      if (conjA == 'n')
	{
	  double* cptr = c.Store()+ rowstride*c.Ncols() + colstride;
	  for (int i=0; i< a.Nrows();i++) 
	    DAXPY(a.Ncols(), scaleA * scaleB * b00, a.Store()+i*a.Ncols(), 1, cptr + i*c.Ncols(), 1);
	  return;
	}
      else 	
	{
	  double* aptr = a.Store();
	  double* cptr = c.Store() + rowstride*c.Ncols() + colstride;
	  for (int col = 0; col < acols; ++col)
	    {
	      DAXPY(arows, scaleA * scaleB * b00, aptr, acols, cptr, 1);
	      ++aptr;
	      cptr += c.Ncols();//arows;
	    }

	  return;
	}	
    }
    //  else
    //    abort();
#else 
      try
	{
	  if (conjA == 'n' && conjB == 'n')
	    {
	      if (allocate)
		{
		  c.ReSize (a.Nrows () * b.Nrows (), a.Ncols () * b.Ncols ());
		  Clear (c);
		}
	      //assert ((c.Nrows () == (a.Nrows () * b.Nrows ())) && (c.Ncols () == (a.Ncols () * b.Ncols ())));
#ifdef BLAS
	      int aRows = a.Nrows ();
	      int aCols = a.Ncols ();
	      int bRows = b.Nrows ();
	      int bCols = b.Ncols ();

	      for (int i = 0; i < aRows; ++i)
		for (int j = 0; j < aCols; ++j)
		  {
		    Real scale = scaleA * scaleB * a (i+1,j+1);
		    for (int k = 0; k < bRows; ++k)
		      GAXPY (bCols, scale, &b (k+1,1), 1, &c (i * bRows + k+1 +rowstride,j * bCols+1+colstride), 1);
		  }
	      return;
#else
	      A = a;
	      B = b;
#endif
	    }
	  else if (conjA == 't' && conjB == 'n')
	    {
	      if (allocate)
		{
		  c.ReSize (a.Ncols () * b.Nrows (), a.Nrows () * b.Ncols ());
		  Clear (c);
		}
	      //assert ((c.Nrows () == (a.Ncols () * b.Nrows ())) && (c.Ncols () == (a.Nrows () * b.Ncols ())));
#ifdef BLAS
	      int aRows = a.Ncols ();
	      int aCols = a.Nrows ();
	      int bRows = b.Nrows ();
	      int bCols = b.Ncols ();
	      
	      for (int i = 0; i < aRows; ++i)
		for (int j = 0; j < aCols; ++j)
		  {
		    Real scale = scaleA * scaleB * a (j+1,i+1);
		    for (int k = 0; k < bRows; ++k)
		      GAXPY (bCols, scale, &b (k+1,1), 1, &c (i * bRows + k+1+rowstride,j * bCols+1+colstride), 1);
		  }
	      return;
#else	  
	      A = a.t ();
	      B = b;
#endif
	    }
	  else if (conjA == 'n' && conjB == 't')
	    {
	      if (allocate)
		{
		  c.ReSize (a.Nrows () * b.Ncols (), a.Ncols () * b.Nrows ());
		  Clear (c);
		}
	      //assert ((c.Nrows () == (a.Nrows () * b.Ncols ())) && (c.Ncols () == (a.Ncols () * b.Nrows ())));
#ifdef BLAS
	      int aRows = a.Nrows ();
	      int aCols = a.Ncols ();
	      int bRows = b.Ncols ();
	      int bCols = b.Nrows ();
	      
	      for (int i = 0; i < aRows; ++i)
		for (int j = 0; j < aCols; ++j)
		  {
		    Real scale = scaleA * scaleB * a (i+1,j+1);
		    for (int k = 0; k < bRows; ++k)
		      GAXPY (bCols, scale, &b (1,k+1), bRows, &c (i * bRows + k+1+rowstride,j * bCols+1+colstride), 1);
		  }
	      return;
#else
	      A = a;
	      B = b.t ();
#endif
	    }
	  else if (conjA == 't' && conjB == 't')
	    {
	      if (allocate)
		{
		  c.ReSize (a.Ncols () * b.Ncols (), a.Nrows () * b.Nrows ());
		  Clear (c);
		}
	      //assert ((c.Nrows () == (a.Ncols () * b.Ncols ())) && (c.Ncols () == (a.Nrows () * b.Nrows ())));
#ifdef BLAS
	      int aRows = a.Ncols ();
	      int aCols = a.Nrows ();
	      int bRows = b.Ncols ();
	      int bCols = b.Nrows ();
	      
	      for (int i = 0; i < aRows; ++i)
		for (int j = 0; j < aCols; ++j)
		  {
		    Real scale = scaleA * scaleB * a (j+1,i+1);
		    for (int k = 0; k < bRows; ++k)
		      GAXPY (bCols, scaleA * scaleB * a (j+1,i+1), &b (1,k+1), bRows, &c (i * bRows + k+1+rowstride,j * bCols+1+colstride), 1);
		  }
	      return;
#else
	      A = a.t ();
	      B = b.t ();
#endif
	    }
	  else
	    abort ();
#ifndef BLAS
	  for (int i = 1; i <= A.Nrows (); ++i)
	    for (int j = 1; j <= A.Ncols (); ++j)
	      c.SubMatrix ((i - 1) * B.Nrows () + 1, i * B.Nrows (), (j - 1) * B.Ncols () + 1, j * B.Ncols ()) += (scaleA * scaleB) * A (i,j) * B; 
#endif
	  
	}
      catch (Exception)
	{
	  pout << Exception::what () << endl;
	  abort ();
	}   
#endif
}