Esempio n. 1
0
int main(int argc, char** argv)
{
  int stat = 0;

  try
		{
      GlobalMPISession session(&argc, &argv);
      Tabs tabs;
      TimeMonitor timer(totalTimer());

      

      EvalVector::shadowOps() = true;
      bool isOK = true;
      Array<string> failures;
      

      TempStack s(1);

      typedef RCP<EvalVector> Vec;

      Vec A = s.popVector();
      Vec B = s.popVector();
      Vec C = s.popVector();
      Vec D = s.popVector();

      double& a = *(A->start());
      double& b = *(B->start());
      double& c = *(C->start());
      double& d = *(D->start());

      a = 1.1;
      b = 0.8;
      c = 0.5;
      d = 1.2;

      A->setString("A");
      B->setString("B");
      C->setString("C");
      D->setString("D");

      std::cerr << "A = " << *A << std::endl;

      std::cerr << "B = " << *B << std::endl;

      std::cerr << "C = " << *C << std::endl;

      std::cerr << "D = " << *D << std::endl;

      double aSave;
      double bSave;
      double cSave;
      double dSave;
      double error;
      double tol = 1.0e-13;

      
      
      TESTER((A->add_SV(1.23, B.get())), (aSave + 1.23*b));

      TESTER((A->add_SVV(4.56, B.get(), C.get())), (aSave + 4.56*b*c));

      TESTER((A->add_V(B.get())), (aSave + b));

      TESTER((A->add_S(7.89)), (aSave + 7.89));

      TESTER((A->add_VV(B.get(), C.get())), (aSave + b*c));

      TESTER((A->multiply_S_add_SV(1.23, 4.56, D.get())), (aSave*1.23 + 4.56*d));

      TESTER((A->multiply_S_add_S(0.0123, 0.0456)), (aSave*0.0123 + 0.0456));

      TESTER((A->multiply_V_add_VVV(B.get(), B.get(), C.get(), D.get())), (aSave*b + b*c*d));

      TESTER((A->multiply_V_add_SVV(B.get(), 1.23, C.get(), D.get())), (aSave*b + 1.23*c*d));

      TESTER((A->multiply_V_add_SV(B.get(), 1.23, C.get())), (aSave*b + 1.23*c));

      TESTER((A->multiply_VV(B.get(), C.get())), (aSave*b*c));

      TESTER((A->multiply_SV(4.56, C.get())), (aSave*4.56*c));

      TESTER((A->multiply_V(C.get())), (aSave*c));

      TESTER((A->multiply_S(1.2)), (aSave*1.2));

      
      TESTER((A->setTo_S_add_SVV(4.56, 1.23, C.get(), D.get())), (4.56 + 1.23*c*d));

      TESTER((A->setTo_S_add_VV(4.56, C.get(), D.get())), (4.56 + c*d));

      TESTER((A->setTo_S_add_SV(4.56, 1.23, D.get())), (4.56 + 1.23*d));

      TESTER((A->setTo_S_add_V(4.56, C.get())), (4.56 + c));

      TESTER((A->setTo_V(B.get())), (b));

      TESTER((A->setTo_VV(B.get(), C.get())), (b*c));

      TESTER((A->setTo_SV(1.23, C.get())), (1.23*c));

      TESTER((A->setTo_SVV(1.23, C.get(), D.get())), (1.23*c*d));


      if (isOK)
        {
          std::cerr << "all tests PASSED!" << std::endl;
        }
      else
        {
          stat = -1;
          std::cerr << "test FAILED!" << std::endl;
        }
      TimeMonitor::summarize();
    }
	catch(std::exception& e)
		{
      stat = -1;
      std::cerr << "test FAILED!" << std::endl;
      std::cerr << "detected exception: " << e.what() << std::endl;
		}

  return stat;
  
}
Esempio n. 2
0
double funcOps(const Array<Vec>& vecs, int nTrials, double alpha, double beta, 
               double gamma)
{
  Array<int> abcd = tuple(0,1,2,3);
  int n = vecs[0]->length();

  Time t("loop");
  double t0 = t.totalElapsedTime();
  t.start();

  for (int m=0; m<nTrials; m++)
    {
      Vec A = vecs[abcd[0]];
      {
        const Vec& B = vecs[abcd[1]];
        A->setTo_SV(alpha, B.get());
      }
      {
        const Vec& C = vecs[abcd[2]];
        const Vec& D = vecs[abcd[3]];
        A->add_SVV(beta, C.get(), D.get());
      }
      {
        const Vec& B = vecs[abcd[1]];
        const Vec& C = vecs[abcd[2]];
        const Vec& D = vecs[abcd[3]];
        A->multiply_V_add_SVV(B.get(), gamma, C.get(), D.get());
      }
      {
        const Vec& B = vecs[abcd[1]];
        A->multiply_V(B.get());
      }
      {
        const Vec& C = vecs[abcd[2]];
        A->multiply_S_add_SV(alpha, beta, C.get());
      }
      {
        const Vec& B = vecs[abcd[1]];
        A->setTo_SV(alpha, B.get());
      }
      {
        const Vec& C = vecs[abcd[2]];
        const Vec& D = vecs[abcd[3]];
        A->add_SVV(beta, C.get(), D.get());
      }
      {
        const Vec& B = vecs[abcd[1]];
        const Vec& C = vecs[abcd[2]];
        const Vec& D = vecs[abcd[3]];
        A->multiply_V_add_SVV(B.get(), gamma, C.get(), D.get());
      }
      {
        const Vec& B = vecs[abcd[1]];
        A->multiply_V(B.get());
      }
      {
        const Vec& C = vecs[abcd[2]];
        A->multiply_S_add_SV(alpha, beta, C.get());
      }
      {
        const Vec& B = vecs[abcd[1]];
        A->setTo_SV(alpha, B.get());
      }
      {
        const Vec& C = vecs[abcd[2]];
        const Vec& D = vecs[abcd[3]];
        A->add_SVV(beta, C.get(), D.get());
      }
      {
        const Vec& B = vecs[abcd[1]];
        const Vec& C = vecs[abcd[2]];
        const Vec& D = vecs[abcd[3]];
        A->multiply_V_add_SVV(B.get(), gamma, C.get(), D.get());
      }
      {
        const Vec& B = vecs[abcd[1]];
        A->multiply_V(B.get());
      }
      {
        const Vec& C = vecs[abcd[2]];
        A->multiply_S_add_SV(alpha, beta, C.get());
      }
      {
        const Vec& B = vecs[abcd[1]];
        A->setTo_SV(alpha, B.get());
      }
      {
        const Vec& C = vecs[abcd[2]];
        const Vec& D = vecs[abcd[3]];
        A->add_SVV(beta, C.get(), D.get());
      }
      {
        const Vec& B = vecs[abcd[1]];
        const Vec& C = vecs[abcd[2]];
        const Vec& D = vecs[abcd[3]];
        A->multiply_V_add_SVV(B.get(), gamma, C.get(), D.get());
      }
      {
        const Vec& B = vecs[abcd[1]];
        A->multiply_V(B.get());
      }
      {
        const Vec& C = vecs[abcd[2]];
        A->multiply_S_add_SV(alpha, beta, C.get());
      }
    }
  t.stop();
  return t.totalElapsedTime() - t0;
}