コード例 #1
0
ファイル: Gerade2D.cpp プロジェクト: quiN68/NAC
float Gerade2D::gerichteterAbstand(Vektor2D x) const {
	Vektor2D diff(x);
	diff.subtrahiere(m_Aufpunkt);
	return m_Normale.skalarprodukt(diff) / m_Normale.betrag();
}
コード例 #2
0
ファイル: combineAlphaFits.C プロジェクト: CMSROMA/EFlow
void combineAlphaFits(
		      TString file1="",
		      TString file2="",
		      TString suffix1="",
		      TString suffix2="",
		      float errAlphaCut=999.,
		      float ndof1Cut=0,
		      float ndof2Cut=0,
		      float chi2Cut=999.,
		      int det=0
		      )
{


  float alpha1[61200];
  float alpha2[61200];
  float chi2red1[61200];
  float chi2red2[61200];
  float ndof1[61200];
  float ndof2[61200];
  float err1_alpha[61200];
  float err2_alpha[61200];
  int status1[61200];
  int status2[61200];
  int bad1[61200];
  int bad2[61200];
  int index1[61200];
  int index2[61200];
  int ieta1[61200];
  int ieta2[61200];
  int iphi1[61200];
  int iphi2[61200];
  int sign1[61200];
  int sign2[61200];


  TFile *f1=TFile::Open(file1);
  if (!f1)
    {
      std::cout << "Cannot open " << file1 << std::endl;
      exit(-1);
    }
  TTree* res1= (TTree*)f1->Get("fitResults");
  
  int status,index,bad,ieta,iphi,sign;
  double alpha,delta_alpha,err_alpha,chi2Min,ndof;
  
  TBranch *b_ieta=res1->GetBranch("ieta");
  TBranch *b_iphi=res1->GetBranch("iphi");
  TBranch *b_sign=res1->GetBranch("sign");
  TBranch *b_alpha=res1->GetBranch("alpha0");
  TBranch *b_dalpha=res1->GetBranch("delta_alpha");
  TBranch *b_erralpha=res1->GetBranch("err_alpha");
  TBranch *b_status=res1->GetBranch("status");
  TBranch *b_bad=res1->GetBranch("badXtal");
  TBranch *b_index=res1->GetBranch("index");
  TBranch *b_chi2=res1->GetBranch("chi2Min");
  TBranch *b_ndof=res1->GetBranch("ndof");
  
  res1->SetBranchAddress("ieta", &ieta, &b_ieta);
  res1->SetBranchAddress("iphi", &iphi, &b_iphi);
  res1->SetBranchAddress("sign", &sign, &b_sign);
  res1->SetBranchAddress("alpha0", &alpha, &b_alpha);
  res1->SetBranchAddress("delta_alpha", &delta_alpha, &b_dalpha);
  res1->SetBranchAddress("err_alpha", &err_alpha, &b_erralpha);
  res1->SetBranchAddress("status", &status, &b_status);
  res1->SetBranchAddress("badXtal", &bad, &b_bad);
  res1->SetBranchAddress("index", &index, &b_index);
  res1->SetBranchAddress("chi2Min", &chi2Min, &b_chi2);
  res1->SetBranchAddress("ndof", &ndof, &b_ndof);
  
  int nentries1 = res1->GetEntries();

  for(int jentry=0;jentry<nentries1;++jentry)
    {
      res1->GetEntry(jentry);
      int ii=index-1;
      if (det==1)
	ii=index;

      alpha1[ii]=alpha+delta_alpha;
      err1_alpha[ii]=err_alpha;
      status1[ii]=status;
      bad1[ii]=bad;
      index1[ii]=index;
      ieta1[ii]=ieta;
      iphi1[ii]=iphi;
      sign1[ii]=sign;
      chi2red1[ii]=chi2Min/(float)ndof;
      ndof1[ii]=ndof;
    }
    
  std::cout << "Read alpha fits for " << nentries1 << " xtals " << std::endl;



  TFile *f2=TFile::Open(file2);
  if (!f2)
    {
      std::cout << "Cannot open " << file2 << std::endl;
      exit(-1);
    }
  TTree* res2= (TTree*)f2->Get("fitResults");
  

  TBranch *b_ieta=res2->GetBranch("ieta");
  TBranch *b_iphi=res2->GetBranch("iphi");
  TBranch *b_sign=res2->GetBranch("sign");
  TBranch *b_alpha=res2->GetBranch("alpha0");
  TBranch *b_dalpha=res2->GetBranch("delta_alpha");
  TBranch *b_erralpha=res2->GetBranch("err_alpha");
  TBranch *b_status=res2->GetBranch("status");
  TBranch *b_bad=res2->GetBranch("badXtal");
  TBranch *b_index=res2->GetBranch("index");
  TBranch *b_chi2=res2->GetBranch("chi2Min");
  TBranch *b_ndof=res2->GetBranch("ndof");
  
  res2->SetBranchAddress("ieta", &ieta, &b_ieta);
  res2->SetBranchAddress("iphi", &iphi, &b_iphi);
  res2->SetBranchAddress("sign", &sign, &b_sign);
  res2->SetBranchAddress("alpha0", &alpha, &b_alpha);
  res2->SetBranchAddress("delta_alpha", &delta_alpha, &b_dalpha);
  res2->SetBranchAddress("err_alpha", &err_alpha, &b_erralpha);
  res2->SetBranchAddress("status", &status, &b_status);
  res2->SetBranchAddress("badXtal", &bad, &b_bad);
  res2->SetBranchAddress("index", &index, &b_index);
  res2->SetBranchAddress("chi2Min", &chi2Min, &b_chi2);
  res2->SetBranchAddress("ndof", &ndof, &b_ndof);
  
  int nentries2 = res2->GetEntries();

  for(int jentry=0;jentry<nentries2;++jentry)
    {
      res2->GetEntry(jentry);
      int ii=index-1;
      if (det==1)
	ii=index;
      alpha2[ii]=alpha+delta_alpha;
      err2_alpha[ii]=err_alpha;
      status2[ii]=status;
      bad2[ii]=bad;
      index2[ii]=index;
      ieta2[ii]=ieta;
      iphi2[ii]=iphi;
      sign2[ii]=sign;
      chi2red2[ii]=chi2Min/(float)ndof;
      ndof2[ii]=ndof;
    }  
    
  std::cout << "Read alpha fits for " << nentries2 << " xtals " << std::endl;

  int nXtal=TMath::Max(nentries1,nentries2);


  TH1F diff("diff","diff",500,-10,10);
  TH2F* diffMap;
  if (det==0)
    diffMap=new TH2F("diffMap","diffMap",360,0.5,360.5,171,-85.5,85.5);
  else if (det==1)
    diffMap=new TH2F("diffMap","diffMap",200,0.5,200.5,100,0.5,100.5);
  
  TProfile p("p","p",100,-1,4);

  float alpha1Array[61200];
  float alpha2Array[61200];
  float erralpha1Array[61200];
  float erralpha2Array[61200];
  int nGoodXtals=0;
  for (int ixtal=0;ixtal<61200;++ixtal)
    {
      //      if (bad1[ixtal]==0 && bad2[ixtal]==0 && status1[ixtal]==0 && status2[ixtal]==0 && alpha1[ixtal]>0.01 && alpha2[ixtal]>0.01 && err1_alpha[ixtal]<0.12 && err2_alpha[ixtal]<0.12)
      //      if (bad1[ixtal]==0 && bad2[ixtal]==0 && status1[ixtal]==0 && status2[ixtal]==0 && alpha1[ixtal]>0.01 && alpha2[ixtal]>0.01 && chi2red1[ixtal]<3. && chi2red2[ixtal]<3.)
      if (bad1[ixtal]==0 && bad2[ixtal]==0 && status1[ixtal]==0 && status2[ixtal]==0 && alpha1[ixtal]>0.1 && alpha2[ixtal]>0.1 && ndof1[ixtal]>ndof1Cut && ndof2[ixtal]>ndof2Cut && chi2red1[ixtal]<chi2Cut && chi2red2[ixtal]<chi2Cut && err1_alpha[ixtal]<errAlphaCut && err2_alpha[ixtal]<errAlphaCut)
	{
	  alpha1Array[nGoodXtals]=alpha1[ixtal];
	  alpha2Array[nGoodXtals]=alpha2[ixtal];
	  erralpha1Array[nGoodXtals]=err1_alpha[ixtal];
	  erralpha2Array[nGoodXtals]=err2_alpha[ixtal];
	  //  diff.Fill((alpha1Array[nGoodXtals]-alpha2Array[nGoodXtals])/(sqrt(err1_alpha[ixtal]*err1_alpha[ixtal]+err2_alpha[ixtal]*err2_alpha[ixtal])));
	  diff.Fill((alpha1Array[nGoodXtals]-alpha2Array[nGoodXtals]));
	  p.Fill(alpha1Array[nGoodXtals],alpha2Array[nGoodXtals]);
	  if (det==0)
	    {
	      int etaIndex=(index1[ixtal]-1)/360+1;
	      int phiIndex=(index1[ixtal]-1)%360+1;
	      if (etaIndex>85)
		etaIndex++;
	      else
		etaIndex=86-etaIndex;
	      diffMap->SetBinContent(phiIndex,etaIndex,(alpha1Array[nGoodXtals]-alpha2Array[nGoodXtals])+1.);
	    }
	  else if (det==1)
	    {
	      diffMap->SetBinContent(ieta1[ixtal]+100*sign1[ixtal],iphi1[ixtal],(alpha1Array[nGoodXtals]-alpha2Array[nGoodXtals])+1.);
	    }
	  nGoodXtals++;
	}
    }
  
  std::cout << "Found " << nGoodXtals << " good xtals " << std::endl;

  gStyle->SetOptTitle(0);
  gStyle->SetOptFit(11);
  TH2F a("a","a",10,-1,4,10,-1,4);
  a.GetXaxis()->SetTitle(suffix1);
  a.GetYaxis()->SetTitle(suffix2);
  TGraphErrors corr(nGoodXtals,alpha1Array,alpha2Array,erralpha1Array,erralpha2Array);
  a.SetStats(false);
  a.Draw();
  corr.Draw("PXSAME");
  corr.Fit("pol1","0+");
  TF1* f=(TF1*) corr.GetFunction("pol1");
  f->SetLineColor(2);
  f->SetLineWidth(4);
  f->Draw("SAME");
//   p.SetMarkerColor(kRed);
//   p.SetLineColor(kRed);
//   p.SetMarkerStyle(20);
//   p.SetMarkerSize(1.2);
//   p.Draw("ESAME");
  TString suffix=suffix1+"_vs_"+suffix2;

  c1->SaveAs("plotsFitDiff/corrAlpha_"+suffix+".png");

  diff.Draw();
  diff.Fit("gaus","","",diff.GetMean()-3*diff.GetRMS(),diff.GetMean()+3*diff.GetRMS());
  c1->SaveAs("plotsFitDiff/diffAlpha_"+suffix+".png");

  gStyle->SetOptStat(0);
  diffMap->GetZaxis()->SetRangeUser(0.5,1.5);
  diffMap->Draw("COLZ");
  c1->SaveAs("plotsFitDiff/diffAlphaMap_"+suffix+".png");

}
コード例 #3
0
ファイル: ofxMSATimer.cpp プロジェクト: iloveican/AscoGraph
uint64_t ofxMSATimer::getAppTimeMicros(){
	clock_gettime(CLOCK_MONOTONIC_RAW, &tmpTime);
	timespec diffTime = diff(startTime, tmpTime);
	return  ((int64_t)diffTime.tv_sec*1000000000 + (int64_t)diffTime.tv_nsec)/1000;
}
コード例 #4
0
ファイル: incr_eigcg.c プロジェクト: Finkenrath/tmLQCD
int incr_eigcg(const int N, const int nrhs,  const int nrhs1, spinor * const x, spinor * const b, 
               const int ldh, matrix_mult f, const double eps_sq1, const double eps_sq, double restart_eps_sq,  
               const int rand_guess_opt, const int rel_prec, const int maxit, int nev, const int v_max) 
{ 
  /*Static variables and arrays.*/
  static spinor **solver_field; /*4 spinor fields*/

  static int ncurEvals=0;       /* current number of stored eigenvectors */
  static int ncurRHS=0;         /* current number of the system being solved */                   

  static spinor **evecs;        /* accumulated eigenvectors for deflation. */

  static void *_evals;
  static double *evals;         /* Ritz values */

  static void *_v;
  static spinor  *V;            /* work array for eigenvector search basis in eigCG */

  static void *_h;
  static _Complex double  *H;            /* The ncurEvals^2 matrix: H=evecs'*A*evecs */ 

  static void *_hu;
  static _Complex double  *HU;           /* used for diagonalization of H if eigenvalues requested
                                   also used as a copy of H if needed*/
  static void *_initwork;                            
  static _Complex double  *initwork;     /* vector of size ldh using with init-CG */ 

  static void *_ework;
  static _Complex double  *ework;
  /* end of the thinking part */

  static void *_work;
  static _Complex double  *work;

  static void *_rwork;
  static double *rwork;
  
  static void *_IPIV;
  static int *IPIV;        /*integer array to store permutations when solving the small linear system*/

  /* some constants */
  char cU='U'; char cN='N';  char cV='V'; 
  _Complex double  tpone= 1.0e+00;
  _Complex double  tzero= 0.0e+00;
  //tpone.re=+1.0e+00; tpone.im=0.0e+00; 
  //tzero.re=+0.0e+00; tzero.im=0.0e+00;

  /* Timing vars */
  double wt1,wt2,wE,wI;

  double eps_sq_used;

 
  /* Variables */
  double machEps = 1e-15;  
  double normb, normsq, tmpd,tmpd2;
  _Complex double  tempz;
  int i,j, ONE = 1;
  int tmpsize,tmpi,info=0;
  int numIts, flag, nAdded, nev_used;
  int maxit_remain;
  int esize,nrsf;

  int parallel; /* for parallel processing of the scalar products */

  /* leading dimension for spinor vectors */
  int LDN;
  if(N==VOLUME)
     LDN = VOLUMEPLUSRAND;
  else
     LDN = VOLUMEPLUSRAND/2;
  
 
  #ifdef TM_USE_MPI
    parallel=1;
  #else
    parallel=0;
  #endif
 
  /*think more about this */
  esize=2*12*N+4*nev*nev;  /* fixed size for ework used for restarting in eigcg*/

  nrsf=4;  /*number of solver fields */
  
  int lwork=3*ldh;

  double cur_res; //current residual squared (initial value will be computed in eigcg)

  /*increment the RHS counter*/
  ncurRHS = ncurRHS +1; 

  //set the tolerance to be used for this right-hand side 
  if(ncurRHS > nrhs1){
    eps_sq_used = eps_sq;
  }
  else{
    eps_sq_used = eps_sq1;
  }

  if(ncurRHS==1)/* If this is the first system, allocate needed memory for the solver*/
  {
    init_solver_field(&solver_field, LDN, nrsf); 
  }

  if(nev==0){ /*incremental eigcg is used as a cg solver. No need to restart forcing no-restart*/
    if(g_proc_id == g_stdio_proc && g_debug_level > 0) {
       fprintf(stdout, "CG won't be restarted in this mode since no deflation will take place (nev=0)\n"); 
       fflush(stdout);
    } 
  
    restart_eps_sq=0.0;
  }




  if((ncurRHS==1) && (nev >0) )/* If this is the first right-hand side and eigenvectors are needed, allocate needed memory*/
  { 
    init_solver_field(&evecs, LDN, ldh); 
     
    #if (defined SSE || defined SSE2 || defined SSE3)

    /*Extra elements are needed for allignment */
    //_v = malloc(LDN*v_max*sizeof(spinor)+ALIGN_BASE);
    _v = calloc(LDN*v_max+ALIGN_BASE,sizeof(spinor));
    V  = (spinor *)(((unsigned long int)(_v)+ALIGN_BASE)&~ALIGN_BASE);

    //_h=malloc(ldh*ldh*sizeof(_Complex double )+ALIGN_BASE);
    _h=calloc(ldh*ldh+ALIGN_BASE,sizeof(_Complex double ));
    H = (_Complex double  *)(((unsigned long int)(_h)+ALIGN_BASE)&~ALIGN_BASE);
 
    //_hu=malloc(ldh*ldh*sizeof(_Complex double )+ALIGN_BASE);
    _hu=calloc(ldh*ldh+ALIGN_BASE,sizeof(_Complex double ));
    HU = (_Complex double  *)(((unsigned long int)(_hu)+ALIGN_BASE)&~ALIGN_BASE);
    
    //_ework = malloc(esize*sizeof(_Complex double )+ALIGN_BASE);
    _ework = calloc(esize+ALIGN_BASE,sizeof(_Complex double ));
    ework=(_Complex double  *)(((unsigned long int)(_ework)+ALIGN_BASE)&~ALIGN_BASE);

    //_initwork = malloc(ldh*sizeof(_Complex double )+ALIGN_BASE);
    _initwork = calloc(ldh+ALIGN_BASE,sizeof(_Complex double ));
    initwork = (_Complex double  *)(((unsigned long int)(_initwork)+ALIGN_BASE)&~ALIGN_BASE);

    //_work = malloc(lwork*sizeof(_Complex double )+ALIGN_BASE);
    _work = calloc(lwork+ALIGN_BASE,sizeof(_Complex double ));
    work = (_Complex double  *)(((unsigned long int)(_work)+ALIGN_BASE)&~ALIGN_BASE);

    //_rwork = malloc(3*ldh*sizeof(double)+ALIGN_BASE);
    _rwork = calloc(3*ldh+ALIGN_BASE,sizeof(double));
    rwork = (double *)(((unsigned long int)(_rwork)+ALIGN_BASE)&~ALIGN_BASE);

    
    //_IPIV = malloc(ldh*sizeof(int)+ALIGN_BASE);
    _IPIV = calloc(ldh+ALIGN_BASE,sizeof(int));
    IPIV = (int *)(((unsigned long int)(_IPIV)+ALIGN_BASE)&~ALIGN_BASE);

    //_evals = malloc(ldh*sizeof(double)+ALIGN_BASE);
    _evals = calloc(ldh+ALIGN_BASE,sizeof(double)); 
    evals = (double *)(((unsigned long int)(_evals)+ALIGN_BASE)&~ALIGN_BASE);


    #else

    V = (spinor *) calloc(LDN*v_max,sizeof(spinor));
    H = calloc(ldh*ldh, sizeof(_Complex double ));
    HU= calloc(ldh*ldh, sizeof(_Complex double ));
    initwork = calloc(ldh, sizeof(_Complex double ));
    ework = calloc(esize, sizeof(_Complex double ));
    work = calloc(lwork,sizeof(_Complex double ));
    rwork= calloc(3*ldh,sizeof(double));
    IPIV = calloc(ldh, sizeof(int));
    evals = (double *) calloc(ldh, sizeof(double));

    #endif
    
  } /*if(ncurRHS==1)*/

  
  if(g_proc_id == g_stdio_proc && g_debug_level > 0) {
    fprintf(stdout, "System %d, eps_sq %e\n",ncurRHS,eps_sq_used); 
    fflush(stdout);
  } 
  
     /*---------------------------------------------------------------*/
     /* Call eigCG until this right-hand side converges               */
     /*---------------------------------------------------------------*/
  wE = 0.0; wI = 0.0;     /* Start accumulator timers */
  flag = -1;    	   /* First time through. Run eigCG regularly */
  maxit_remain = maxit;   /* Initialize Max and current # of iters   */
  numIts = 0;  

  while( flag == -1 || flag == 3)
  {
    //if(g_proc_id==g_stdio_proc)
      //printf("flag= %d, ncurEvals= %d\n",flag,ncurEvals);
    
    if(ncurEvals > 0)
    {
      /* --------------------------------------------------------- */
      /* Perform init-CG with evecs vectors                        */
      /* xinit = xinit + evecs*Hinv*evec'*(b-Ax0) 		     */
      /* --------------------------------------------------------- */

      wt1 = gettime();

      /*r0=b-Ax0*/
      normsq = square_norm(x,N,parallel);
      if(normsq>0.0)
      {
	f(solver_field[0],x); /* solver_field[0]= A*x */
	diff(solver_field[1],b,solver_field[0],N);  /* solver_filed[1]=b-A*x */		
      }
      else
	assign(solver_field[1],b,N); /* solver_field[1]=b */
	
      /* apply the deflation using init-CG */
      /* evecs'*(b-Ax) */
      for(i=0; i<ncurEvals; i++)
      {
        initwork[i]= scalar_prod(evecs[i],solver_field[1],N,parallel);
      }
    
      /* solve the linear system H y = c */
      tmpsize=ldh*ncurEvals;
      _FT(zcopy) (&tmpsize,H,&ONE,HU,&ONE); /* copy H into HU */
      _FT(zgesv) (&ncurEvals,&ONE,HU,&ldh,IPIV,initwork,&ldh,&info);

      if(info != 0)
      {
         if(g_proc_id == g_stdio_proc) {
            fprintf(stderr, "Error in ZGESV:, info =  %d\n",info); 
            fflush(stderr);
         }
         exit(1);
      }
    
      /* x = x + evecs*inv(H)*evecs'*r */
      for(i=0; i<ncurEvals; i++)
      {
        assign_add_mul(x,evecs[i],initwork[i],N);
      }
      
      /* compute elapsed time and add to accumulator */

      wt2 = gettime();
      
      wI = wI + wt2-wt1;
      
    }/* if(ncurEvals > 0) */


    /* ------------------------------------------------------------ */
    /* Adjust nev for eigcg according to available ldh/restart      */
    /* ------------------------------------------------------------ */
    if (flag == 3) { /* restart with the same rhs, set nev_used = 0 */
      nev_used = 0;
    }
    else
    {    
      /* First time through this rhs. Find nev evecs */
      /* limited by the ldh evecs we can store in total */
      if (ldh-ncurEvals < nev)
	       nev = ldh - ncurEvals;
      nev_used = nev;
    }

    /* ------------------------------------------------------------ */
    /* Solve Ax = b with x initial guess                            */
    /* ------------------------------------------------------------ */

    wt1 = gettime();

    eigcg( N, LDN, x, b, &normb, eps_sq_used, restart_eps_sq, rel_prec, maxit_remain, 
	     &numIts, &cur_res, &flag, solver_field, f, 
	     nev_used, v_max, V, esize, ework);
     
    //if(g_proc_id == g_stdio_proc) 
        //printf("eigcg flag= %d \n",flag); 
      
    wt2 = gettime();

    wE = wE + wt2-wt1;
    
    /* if flag == 3 update the remain max number of iterations */
    maxit_remain = maxit - numIts;
    
  }
  /* end while (flag ==-1 || flag == 3)               */
  /* ------------------------------------------------ */

  /* ---------- */
  /* Reporting  */
  /* ---------- */
  /* compute the exact residual */
  f(solver_field[0],x); /* solver_field[0]= A*x */
  diff(solver_field[1],b,solver_field[0],N);  /* solver_filed[1]=b-A*x */	
  normsq=square_norm(solver_field[1],N,parallel);
  if(g_debug_level > 0 && g_proc_id == g_stdio_proc)
  {
    fprintf(stdout, "For this rhs:\n");
    fprintf(stdout, "Total initCG Wallclock : %-f\n", wI);
    fprintf(stdout, "Total eigpcg Wallclock : %-f\n", wE);
    fprintf(stdout, "Iterations: %-d\n", numIts); 
    fprintf(stdout, "Residual: %e, Actual Resid of LinSys  : %e\n", cur_res,normsq);
    if (flag != 0) {
      fprintf(stderr, "Error: eigcg returned with nonzero exit status\n");
      return flag;
      fflush(stderr);
    }
    fflush(stdout);
  }
  /* ------------------------------------------------------------------- */
  /* ------------------------------------------------------------------- */
  /* Update the evecs and the factorization of evecs'*A*evecs            */
  /* ------------------------------------------------------------------- */
  if (nev > 0) 
  {

    wt1 = gettime();

    /* Append new Ritz vectors to the basis and orthogonalize them to evecs */
    for(i=0; i<nev_used; i++)
      assign(evecs[i+ncurEvals],&V[i*LDN],N);
    
    nAdded = ortho_new_vectors(evecs,N,ncurEvals,nev_used,machEps);

    /* expand H */
    for(j=ncurEvals; j< (ncurEvals+nAdded); j++)
    {
      f(solver_field[0],evecs[j]);
      
      for(i=0; i<=j; i++)
      {
	       H[i+j*ldh] = scalar_prod(evecs[i],solver_field[0],N,parallel);
	       H[j+i*ldh]=  conj(H[i+j*ldh]);
	       //H[j+i*ldh].re =  H[i+j*ldh].re;
	       //H[j+i*ldh].im = -H[i+j*ldh].im;
      }
      
    }
    
    /* update the number of vectors in the basis */
    ncurEvals = ncurEvals + nAdded;

    /* ---------- */
    /* Reporting  */
    /* ---------- */

    wt2 = gettime();

    
    if(g_proc_id == g_stdio_proc && g_debug_level > 0)
    {
      fprintf(stdout,"ncurRHS %d\n",ncurRHS);
      fprintf(stdout,"ncurEvals %d \n",ncurEvals);
      fprintf(stdout,"Update\n");
      fprintf(stdout,"Added %d vecs\n",nAdded);
      fprintf(stdout,"U Wallclock : %-f\n", wt2-wt1);
      fprintf(stdout,"Note: Update Wall time doesn't include time for computing eigenvalues and their residuals.\n"); 
      fflush(stdout);     
    }
    
    if(g_debug_level > 3)  /*compute eigenvalues and their residuals if requested*/
    {
      /* copy H into HU */
      tmpsize=ldh*ncurEvals;
      _FT(zcopy) (&tmpsize,H,&ONE,HU,&ONE);

      /* compute eigenvalues and eigenvectors of HU (using V and spinor fields as tmp work spaces)*/
      _FT(zheev)(&cV, &cU, &ncurEvals, HU, &ldh, evals, work, &lwork, rwork, &info,1,1);

      if(info != 0)
      {
	if(g_proc_id == g_stdio_proc) 
	{
	  fprintf(stderr,"Error in ZHEEV:, info =  %d\n",info); 
          fflush(stderr);
	}
	exit(1);
      }

      /* compute residuals and print out results */
      for(i=0; i<ncurEvals; i++)
      {
	    tmpi=12*N;
            tmpsize=12*LDN;

	    
            _FT(zgemv)(&cN,&tmpi,&ncurEvals,&tpone,(_Complex double  *)evecs[0],&tmpsize,
			                 &HU[i*ldh], &ONE,&tzero,(_Complex double  *) solver_field[0],&ONE,1);

            normsq=square_norm(solver_field[0],N,parallel);
            
            f(solver_field[1],solver_field[0]);

            tempz = scalar_prod(solver_field[0],solver_field[1],N,parallel);

            evals[i] = creal(tempz)/normsq;

            mul_r(solver_field[2],evals[i],solver_field[0],N);

            diff(solver_field[3],solver_field[1],solver_field[2], N);
	    
	    tmpd2= square_norm(solver_field[3],N,parallel);

            tmpd= sqrt(tmpd2/normsq);
	    
	    if(g_proc_id == g_stdio_proc)
	    {fprintf(stdout,"RR Eval[%d]: %22.15E rnorm: %22.15E\n", i+1, evals[i], tmpd); fflush(stdout);}
	
      } 
       
    }/*if(plvl >= 2)*/
  } /* if(nev>0) */

  /*--------------------------------------*/
  /*free memory that is no longer needed  */
  /* and reset ncurRHS and ncurEvals      */
  /*--------------------------------------*/

  if(ncurRHS == nrhs) /*this was the last system to be solved */
  {
     ncurRHS=0;
     ncurEvals=0;
     finalize_solver(solver_field,nrsf);
  }

  if( (ncurRHS == nrhs) && (nev >0) )/*this was the last system to be solved and there were allocated memory for eigenvector computation*/
  {
     finalize_solver(evecs,ldh);
     #if (defined SSE || defined SSE2 || defined SSE3)
     free(_v);
     free(_h);
     free(_hu);
     free(_ework);
     free(_initwork);
     free(_IPIV);
     free(_evals);
     free(_rwork);
     free(_work);
     #else
     free(V);
     free(H);
     free(HU);
     free(ework);
     free(initwork);
     free(IPIV);
     free(evals);
     free(rwork);
     free(work);
     #endif
  }

  return numIts;
}
コード例 #5
0
ファイル: bicgstab_complex.c プロジェクト: Finkenrath/tmLQCD
/* P inout (guess for the solving spinor)
   Q input
*/
int bicgstab_complex(spinor * const P,spinor * const Q, const int max_iter, 
		     double eps_sq, const int rel_prec, 
		     const int N, matrix_mult f){
  double err, squarenorm;
  _Complex double rho0, rho1, omega, alpha, beta, nom, denom;
  int i;
  spinor * r, * p, * v, *hatr, * s, * t;
  spinor ** solver_field = NULL;
  const int nr_sf = 6;

  if(N == VOLUME) {
    init_solver_field(&solver_field, VOLUMEPLUSRAND, nr_sf);
  }
  else {
    init_solver_field(&solver_field, VOLUMEPLUSRAND/2, nr_sf);
  }
  hatr = solver_field[0];
  r = solver_field[1];
  v = solver_field[2];
  p = solver_field[3];
  s = solver_field[4];
  t = solver_field[5];

  f(r, P);
  diff(p, Q, r, N);
  assign(r, p, N);
  assign(hatr, p, N);
  rho0 = scalar_prod(hatr, r, N, 1);
  squarenorm = square_norm(Q, N, 1);

  for(i = 0; i < max_iter; i++){
    err = square_norm(r, N, 1);
    if(g_proc_id == g_stdio_proc && g_debug_level > 2) {
      printf("%d %e\n", i, err);
      fflush(stdout);
    }
  
    if((((err <= eps_sq) && (rel_prec == 0)) || ((err <= eps_sq*squarenorm) && (rel_prec == 1))) && i>0) {
      finalize_solver(solver_field, nr_sf);
      return(i);
    }
    f(v, p);
    denom = scalar_prod(hatr, v, N, 1);
    alpha = rho0 / denom;
    assign(s, r, N);
    assign_diff_mul(s, v, alpha, N);
    f(t, s);
    omega = scalar_prod(t,s, N, 1);
    omega /= square_norm(t, N, 1);
    assign_add_mul_add_mul(P, p, s, alpha, omega, N);
    assign(r, s, N);
    assign_diff_mul(r, t, omega, N);
    rho1 = scalar_prod(hatr, r, N, 1);
    if(fabs(creal(rho1)) < 1.e-25 && fabs(cimag(rho1)) < 1.e-25)
    {
      finalize_solver(solver_field, nr_sf);
      return(-1);
    }
    nom = alpha * rho1;
    denom = omega * rho0;
    beta = nom / denom;
    omega = -omega;
    assign_mul_bra_add_mul_ket_add(p, v, r, omega, beta, N);
    rho0 = rho1;
  }
  finalize_solver(solver_field, nr_sf);
  return -1;
}
コード例 #6
0
ファイル: iblt-decode.cpp プロジェクト: philsong/bitcoin-iblt
static bool recover_block(const raw_iblt &theirs,
						  const raw_iblt &ours,
						  u64 seed,
						  const txmap &mempool,
						  txmap block)
{
	// Difference iblt.
	iblt diff(theirs, ours);

	// Create ids from my mempool, using their seed.
	ibltpool pool(seed, mempool);

	iblt::bucket_type t;
	txslice s;

	// For each txid48, we keep all the slices.
	std::set<txslice> slices;

	// While there are still singleton buckets...
	while ((t = diff.next(s)) != iblt::NEITHER) {
		if (t == iblt::OURS) {
			auto it = pool.tx_by_txid48.find(s.get_txid48());
			// If we can't find it, we're corrupt.
			if (it == pool.tx_by_txid48.end()) {
				return false;
			} else {
				// Remove entire tx.
				diff.remove_our_tx(*it->second->btx, s.get_txid48());
				// Make sure we make progress: remove it from consideration.
				if (!pool.tx_by_txid48.erase(s.get_txid48()))
					return false;
			}
		} else if (t == iblt::THEIRS) {
			// Gave us the same slice twice?  Fail.
			if (!slices.insert(s).second) {
				return false;
			}
			diff.remove_their_slice(s);
		}
	}

	// If we didn't empty it, we've failed decode.
	if (!diff.empty()) {
		return false;
	}

	// Try to assemble the slices into txs.
	size_t count = 0;
	std::vector<txslice> transaction;
	std::vector<bitcoin_tx> recovered;

	for (const auto &s: slices) {
		if (count == 0) {
			// Do we expect this to be the first fragment?
			if (s.get_txid48().frag_base() != s.fragid) {
				return false;
			}
			size_t num = s.slices_expected();
			if (!num || num > 0xFFFF) {
				return false;
			}
			transaction = std::vector<txslice>(num);
			transaction[0] = s;
			count = 1;
		} else {
			// Missing part of transaction?
			if (s.txidbits != transaction[count-1].txidbits) {
				return false;
			}
			// Fragment id wrong?
			if (s.fragid != transaction[count-1].fragid + 1) {
				return false;
			}
			transaction[count++] = s;
		}
		if (count == transaction.size()) {
			// We recovered the entire transaction!
			bitcoin_tx tx((varint_t)0, (varint_t)0);

			if (!rebuild_tx(transaction, tx))
				return false;

			recovered.push_back(tx);
			count = 0;
		}
	}

	// Some left over?
	if (count != 0) {
		return false;
	}

	// The block contents should be equal to recovered + tx_by_txid48.
	for (const auto &tx: recovered) {
		if (!block.erase(tx.txid()))
			return false;
	}
	for (const auto &pair: pool.tx_by_txid48) {
		if (!block.erase(pair.second->txid))
			return false;
	}
	return block.empty();
}
コード例 #7
0
float getElapsedTime() {
	return (float)diff(startTime , endTime).tv_sec + (float) diff(startTime,endTime).tv_nsec/1E9 ;	
}		/* -----  end of function getElapsedTime  ----- */
コード例 #8
0
ファイル: operator.c プロジェクト: chjost/tmLQCD
void op_invert(const int op_id, const int index_start, const int write_prop) {
  operator * optr = &operator_list[op_id];
  double atime = 0., etime = 0., nrm1 = 0., nrm2 = 0.;
  int i;
  optr->iterations = 0;
  optr->reached_prec = -1.;
  g_kappa = optr->kappa;
  boundary(g_kappa);

  atime = gettime();
  if(optr->type == TMWILSON || optr->type == WILSON || optr->type == CLOVER) {
    g_mu = optr->mu;
    g_c_sw = optr->c_sw;
    if(optr->type == CLOVER) {
      if (g_cart_id == 0 && g_debug_level > 1) {
	printf("#\n# csw = %e, computing clover leafs\n", g_c_sw);
      }
      init_sw_fields(VOLUME);
      sw_term( (const su3**) g_gauge_field, optr->kappa, optr->c_sw); 
      /* this must be EE here!   */
      /* to match clover_inv in Qsw_psi */
      sw_invert(EE, optr->mu);
    }

    for(i = 0; i < 2; i++) {
      if (g_cart_id == 0) {
        printf("#\n# 2 kappa mu = %e, kappa = %e, c_sw = %e\n", g_mu, g_kappa, g_c_sw);
      }
      if(optr->type != CLOVER) {
	if(use_preconditioning){
	  g_precWS=(void*)optr->precWS;
	}
	else {
	  g_precWS=NULL;
	}
	
	optr->iterations = invert_eo( optr->prop0, optr->prop1, optr->sr0, optr->sr1,
				      optr->eps_sq, optr->maxiter,
				      optr->solver, optr->rel_prec,
				      0, optr->even_odd_flag,optr->no_extra_masses, optr->extra_masses, optr->id );
	
	/* check result */
	M_full(g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+1], optr->prop0, optr->prop1);
      }
      else {
	optr->iterations = invert_clover_eo(optr->prop0, optr->prop1, optr->sr0, optr->sr1,
					    optr->eps_sq, optr->maxiter,
					    optr->solver, optr->rel_prec,
					    &g_gauge_field, &Qsw_pm_psi, &Qsw_minus_psi);
	/* check result */
 	Msw_full(g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+1], optr->prop0, optr->prop1);
      }

      diff(g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI], optr->sr0, VOLUME / 2);
      diff(g_spinor_field[DUM_DERI+1], g_spinor_field[DUM_DERI+1], optr->sr1, VOLUME / 2);

      nrm1 = square_norm(g_spinor_field[DUM_DERI], VOLUME / 2, 1);
      nrm2 = square_norm(g_spinor_field[DUM_DERI+1], VOLUME / 2, 1);
      optr->reached_prec = nrm1 + nrm2;

      /* convert to standard normalisation  */
      /* we have to mult. by 2*kappa        */
      if (optr->kappa != 0.) {
        mul_r(optr->prop0, (2*optr->kappa), optr->prop0, VOLUME / 2);
        mul_r(optr->prop1, (2*optr->kappa), optr->prop1, VOLUME / 2);
      }
      if (optr->solver != CGMMS && write_prop) /* CGMMS handles its own I/O */
        optr->write_prop(op_id, index_start, i);
      if(optr->DownProp) {
        optr->mu = -optr->mu;
      } else 
        break;
    }
  }
  else if(optr->type == DBTMWILSON || optr->type == DBCLOVER) {
    g_mubar = optr->mubar;
    g_epsbar = optr->epsbar;
    g_c_sw = 0.;
    if(optr->type == DBCLOVER) {
      g_c_sw = optr->c_sw;
      if (g_cart_id == 0 && g_debug_level > 1) {
	printf("#\n# csw = %e, computing clover leafs\n", g_c_sw);
      }
      init_sw_fields(VOLUME);
      sw_term( (const su3**) g_gauge_field, optr->kappa, optr->c_sw); 
      sw_invert_nd(optr->mubar*optr->mubar-optr->epsbar*optr->epsbar);
    }

    for(i = 0; i < SourceInfo.no_flavours; i++) {
      if(optr->type != DBCLOVER) {
	optr->iterations = invert_doublet_eo( optr->prop0, optr->prop1, optr->prop2, optr->prop3, 
					      optr->sr0, optr->sr1, optr->sr2, optr->sr3,
					      optr->eps_sq, optr->maxiter,
					      optr->solver, optr->rel_prec);
      }
      else {
	optr->iterations = invert_cloverdoublet_eo( optr->prop0, optr->prop1, optr->prop2, optr->prop3, 
						    optr->sr0, optr->sr1, optr->sr2, optr->sr3,
						    optr->eps_sq, optr->maxiter,
						    optr->solver, optr->rel_prec);
      }
      g_mu = optr->mubar;
      if(optr->type != DBCLOVER) {
	M_full(g_spinor_field[DUM_DERI+1], g_spinor_field[DUM_DERI+2], optr->prop0, optr->prop1); 
      }
      else {
	Msw_full(g_spinor_field[DUM_DERI+1], g_spinor_field[DUM_DERI+2], optr->prop0, optr->prop1); 
      }
      assign_add_mul_r(g_spinor_field[DUM_DERI+1], optr->prop2, -optr->epsbar, VOLUME/2);
      assign_add_mul_r(g_spinor_field[DUM_DERI+2], optr->prop3, -optr->epsbar, VOLUME/2);

      g_mu = -g_mu;
      if(optr->type != DBCLOVER) {
	M_full(g_spinor_field[DUM_DERI+3], g_spinor_field[DUM_DERI+4], optr->prop2, optr->prop3); 
      }
      else {
	Msw_full(g_spinor_field[DUM_DERI+3], g_spinor_field[DUM_DERI+4], optr->prop2, optr->prop3);
      }
      assign_add_mul_r(g_spinor_field[DUM_DERI+3], optr->prop0, -optr->epsbar, VOLUME/2);
      assign_add_mul_r(g_spinor_field[DUM_DERI+4], optr->prop1, -optr->epsbar, VOLUME/2);

      diff(g_spinor_field[DUM_DERI+1], g_spinor_field[DUM_DERI+1], optr->sr0, VOLUME/2); 
      diff(g_spinor_field[DUM_DERI+2], g_spinor_field[DUM_DERI+2], optr->sr1, VOLUME/2); 
      diff(g_spinor_field[DUM_DERI+3], g_spinor_field[DUM_DERI+3], optr->sr2, VOLUME/2); 
      diff(g_spinor_field[DUM_DERI+4], g_spinor_field[DUM_DERI+4], optr->sr3, VOLUME/2); 

      nrm1  = square_norm(g_spinor_field[DUM_DERI+1], VOLUME/2, 1); 
      nrm1 += square_norm(g_spinor_field[DUM_DERI+2], VOLUME/2, 1); 
      nrm1 += square_norm(g_spinor_field[DUM_DERI+3], VOLUME/2, 1); 
      nrm1 += square_norm(g_spinor_field[DUM_DERI+4], VOLUME/2, 1); 
      optr->reached_prec = nrm1;
      g_mu = g_mu1;
      /* For standard normalisation */
      /* we have to mult. by 2*kappa */
      mul_r(g_spinor_field[DUM_DERI], (2*optr->kappa), optr->prop0, VOLUME/2);
      mul_r(g_spinor_field[DUM_DERI+1], (2*optr->kappa), optr->prop1, VOLUME/2);
      mul_r(g_spinor_field[DUM_DERI+2], (2*optr->kappa), optr->prop2, VOLUME/2);
      mul_r(g_spinor_field[DUM_DERI+3], (2*optr->kappa), optr->prop3, VOLUME/2);
      /* the final result should be stored in the convention used in */
      /* hep-lat/0606011                                             */
      /* this requires multiplication of source with                 */
      /* (1+itau_2)/sqrt(2) and the result with (1-itau_2)/sqrt(2)   */

      mul_one_pm_itau2(optr->prop0, optr->prop2, g_spinor_field[DUM_DERI], 
                       g_spinor_field[DUM_DERI+2], -1., VOLUME/2);
      mul_one_pm_itau2(optr->prop1, optr->prop3, g_spinor_field[DUM_DERI+1], 
                       g_spinor_field[DUM_DERI+3], -1., VOLUME/2);
      /* write propagator */
      if(write_prop) optr->write_prop(op_id, index_start, i);

      mul_r(optr->prop0, 1./(2*optr->kappa), g_spinor_field[DUM_DERI], VOLUME/2);
      mul_r(optr->prop1, 1./(2*optr->kappa), g_spinor_field[DUM_DERI+1], VOLUME/2);
      mul_r(optr->prop2, 1./(2*optr->kappa), g_spinor_field[DUM_DERI+2], VOLUME/2);
      mul_r(optr->prop3, 1./(2*optr->kappa), g_spinor_field[DUM_DERI+3], VOLUME/2);

      /* mirror source, but not for volume sources */
      if(i == 0 && SourceInfo.no_flavours == 2 && SourceInfo.type != 1) {
        if (g_cart_id == 0) {
          fprintf(stdout, "# Inversion done in %d iterations, squared residue = %e!\n",
                  optr->iterations, optr->reached_prec);
        }
        mul_one_pm_itau2(g_spinor_field[DUM_DERI], g_spinor_field[DUM_DERI+2], optr->sr0, optr->sr2, -1., VOLUME/2);
        mul_one_pm_itau2(g_spinor_field[DUM_DERI+1], g_spinor_field[DUM_DERI+3], optr->sr1, optr->sr3, -1., VOLUME/2);

        mul_one_pm_itau2(optr->sr0, optr->sr2, g_spinor_field[DUM_DERI+2], g_spinor_field[DUM_DERI], +1., VOLUME/2);
        mul_one_pm_itau2(optr->sr1, optr->sr3, g_spinor_field[DUM_DERI+3], g_spinor_field[DUM_DERI+1], +1., VOLUME/2);

      }
      /* volume sources need only one inversion */
      else if(SourceInfo.type == 1) i++;
    }
  }
  else if(optr->type == OVERLAP) {
    g_mu = 0.;
    m_ov=optr->m;
    eigenvalues(&optr->no_ev, 5000, optr->ev_prec, 0, optr->ev_readwrite, nstore, optr->even_odd_flag);
/*     ov_check_locality(); */
/*      index_jd(&optr->no_ev_index, 5000, 1.e-12, optr->conf_input, nstore, 4); */
    ov_n_cheby=optr->deg_poly;

    if(use_preconditioning==1)
      g_precWS=(void*)optr->precWS;
    else
      g_precWS=NULL;


    if(g_debug_level > 3) ov_check_ginsparg_wilson_relation_strong(); 

    invert_overlap(op_id, index_start); 

    if(write_prop) optr->write_prop(op_id, index_start, 0);
  }
  etime = gettime();
  if (g_cart_id == 0 && g_debug_level > 0) {
    fprintf(stdout, "# Inversion done in %d iterations, squared residue = %e!\n",
            optr->iterations, optr->reached_prec);
    fprintf(stdout, "# Inversion done in %1.2e sec. \n", etime - atime);
  }
  return;
}
コード例 #9
0
ファイル: qdeclarativetester.cpp プロジェクト: mortenelund/qt
void QDeclarativeTester::updateCurrentTime(int msec)
{
    QDeclarativeItemPrivate::setConsistentTime(msec);
    if (!testscript && msec > 16 && options & QDeclarativeViewer::Snapshot)
        return;

    QImage img(m_view->width(), m_view->height(), QImage::Format_RGB32);

    if (options & QDeclarativeViewer::TestImages) {
        img.fill(qRgb(255,255,255));

#ifdef Q_WS_MAC
        bool oldSmooth = qt_applefontsmoothing_enabled;
        qt_applefontsmoothing_enabled = false;
#endif
        QPainter p(&img);
#ifdef Q_WS_MAC
        qt_applefontsmoothing_enabled = oldSmooth;
#endif

        m_view->render(&p);
    }

    bool snapshot = msec == 16 && (options & QDeclarativeViewer::Snapshot
                                   || (testscript && testscript->count() == 2));

    FrameEvent fe;
    fe.msec = msec;
    if (msec == 0 || !(options & QDeclarativeViewer::TestImages)) {
        // Skip first frame, skip if not doing images
    } else if (0 == ((m_savedFrameEvents.count()-1) % 60) || snapshot) {
        fe.image = img;
    } else {
        QCryptographicHash hash(QCryptographicHash::Md5);
        hash.addData((const char *)img.bits(), img.bytesPerLine() * img.height());
        fe.hash = hash.result();
    }
    m_savedFrameEvents.append(fe);

    // Deliver mouse events
    filterEvents = false;

    if (!testscript) {
        for (int ii = 0; ii < m_mouseEvents.count(); ++ii) {
            MouseEvent &me = m_mouseEvents[ii];
            me.msec = msec;
            QMouseEvent event(me.type, me.pos, me.button, me.buttons, me.modifiers);

            if (me.destination == View) {
                QCoreApplication::sendEvent(m_view, &event);
            } else {
                QCoreApplication::sendEvent(m_view->viewport(), &event);
            }
        }

        for (int ii = 0; ii < m_keyEvents.count(); ++ii) {
            KeyEvent &ke = m_keyEvents[ii];
            ke.msec = msec;
            QKeyEvent event(ke.type, ke.key, ke.modifiers, ke.text, ke.autorep, ke.count);

            if (ke.destination == View) {
                QCoreApplication::sendEvent(m_view, &event);
            } else {
                QCoreApplication::sendEvent(m_view->viewport(), &event);
            }
        }
        m_savedMouseEvents.append(m_mouseEvents);
        m_savedKeyEvents.append(m_keyEvents);
    }

    m_mouseEvents.clear();
    m_keyEvents.clear();

    // Advance test script
    while (testscript && testscript->count() > testscriptidx) {

        QObject *event = testscript->eventAt(testscriptidx);

        if (QDeclarativeVisualTestFrame *frame = qobject_cast<QDeclarativeVisualTestFrame *>(event)) {
            if (frame->msec() < msec) {
                if (options & QDeclarativeViewer::TestImages && !(options & QDeclarativeViewer::Record)) {
                    qWarning() << "QDeclarativeTester(" << m_script << "): Extra frame.  Seen:"
                               << msec << "Expected:" << frame->msec();
                    imagefailure();
                }
            } else if (frame->msec() == msec) {
                if (!frame->hash().isEmpty() && frame->hash().toUtf8() != fe.hash.toHex()) {
                    if (options & QDeclarativeViewer::TestImages && !(options & QDeclarativeViewer::Record)) {
                        qWarning() << "QDeclarativeTester(" << m_script << "): Mismatched frame hash at" << msec
                                   << ".  Seen:" << fe.hash.toHex()
                                   << "Expected:" << frame->hash().toUtf8();
                        imagefailure();
                    }
                }
            } else if (frame->msec() > msec) {
                break;
            }

            if (options & QDeclarativeViewer::TestImages && !(options & QDeclarativeViewer::Record) && !frame->image().isEmpty()) {
                QImage goodImage(frame->image().toLocalFile());
                if (frame->msec() == 16 && goodImage.size() != img.size()){
                    //Also an image mismatch, but this warning is more informative. Only checked at start though.
                    qWarning() << "QDeclarativeTester(" << m_script << "): Size mismatch. This test must be run at " << goodImage.size();
                    imagefailure();
                }
                if (goodImage != img) {
                    QString reject(frame->image().toLocalFile() + QLatin1String(".reject.png"));
                    qWarning() << "QDeclarativeTester(" << m_script << "): Image mismatch.  Reject saved to:"
                               << reject;
                    img.save(reject);
                    bool doDiff = (goodImage.size() == img.size());
                    if (doDiff) {
                        QImage diffimg(m_view->width(), m_view->height(), QImage::Format_RGB32);
                        diffimg.fill(qRgb(255,255,255));
                        QPainter p(&diffimg);
                        int diffCount = 0;
                        for (int x = 0; x < img.width(); ++x) {
                            for (int y = 0; y < img.height(); ++y) {
                                if (goodImage.pixel(x,y) != img.pixel(x,y)) {
                                    ++diffCount;
                                    p.drawPoint(x,y);
                                }
                            }
                        }
                        QString diff(frame->image().toLocalFile() + QLatin1String(".diff.png"));
                        diffimg.save(diff);
                        qWarning().nospace() << "                    Diff (" << diffCount << " pixels differed) saved to: " << diff;
                    }
                    imagefailure();
                }
            }
        } else if (QDeclarativeVisualTestMouse *mouse = qobject_cast<QDeclarativeVisualTestMouse *>(event)) {
            QPoint pos(mouse->x(), mouse->y());
            QPoint globalPos = m_view->mapToGlobal(QPoint(0, 0)) + pos;
            QMouseEvent event((QEvent::Type)mouse->type(), pos, globalPos, (Qt::MouseButton)mouse->button(), (Qt::MouseButtons)mouse->buttons(), (Qt::KeyboardModifiers)mouse->modifiers());

            MouseEvent me(&event);
            me.msec = msec;
            if (!mouse->sendToViewport()) {
                QCoreApplication::sendEvent(m_view, &event);
                me.destination = View;
            } else {
                QCoreApplication::sendEvent(m_view->viewport(), &event);
                me.destination = ViewPort;
            }
            m_savedMouseEvents.append(me);
        } else if (QDeclarativeVisualTestKey *key = qobject_cast<QDeclarativeVisualTestKey *>(event)) {

            QKeyEvent event((QEvent::Type)key->type(), key->key(), (Qt::KeyboardModifiers)key->modifiers(), QString::fromUtf8(QByteArray::fromHex(key->text().toUtf8())), key->autorep(), key->count());

            KeyEvent ke(&event);
            ke.msec = msec;
            if (!key->sendToViewport()) {
                QCoreApplication::sendEvent(m_view, &event);
                ke.destination = View;
            } else {
                QCoreApplication::sendEvent(m_view->viewport(), &event);
                ke.destination = ViewPort;
            }
            m_savedKeyEvents.append(ke);
        }
        testscriptidx++;
    }

    filterEvents = true;

    if (testscript && testscript->count() <= testscriptidx) {
        //if (msec == 16) //for a snapshot, leave it up long enough to see
        //    (void)::sleep(1);
        complete();
    }
}
コード例 #10
0
ファイル: Ptilde_nd.c プロジェクト: LorenzoRiggio/tmLQCD
void degree_of_Ptilde(int * _degree, double ** coefs,
		      const double EVMin, const double EVMax,
		      const int sloppy_degree, const double acc, 
		      matrix_mult_nd Qsq, const int repro) {
  int i, j;
  double temp, temp2;
  int degree;
  double sum=0.0;

  spinor *ss=NULL, *ss_=NULL, *sc=NULL, *sc_=NULL;
  spinor *auxs=NULL, *auxs_=NULL, *auxc=NULL, *auxc_=NULL;
  spinor *aux2s=NULL, *aux2s_=NULL, *aux2c=NULL, *aux2c_=NULL;

  *coefs = calloc(phmc_max_ptilde_degree, sizeof(double)); 

  ss_   = calloc(VOLUMEPLUSRAND/2+1, sizeof(spinor));
  auxs_ = calloc(VOLUMEPLUSRAND/2+1, sizeof(spinor));
  aux2s_= calloc(VOLUMEPLUSRAND/2+1, sizeof(spinor));
  sc_   = calloc(VOLUMEPLUSRAND/2+1, sizeof(spinor));
  auxc_ = calloc(VOLUMEPLUSRAND/2+1, sizeof(spinor));
  aux2c_= calloc(VOLUMEPLUSRAND/2+1, sizeof(spinor));

  ss    = (spinor *)(((unsigned long int)(ss_)+ALIGN_BASE)&~ALIGN_BASE);
  auxs  = (spinor *)(((unsigned long int)(auxs_)+ALIGN_BASE)&~ALIGN_BASE);
  aux2s = (spinor *)(((unsigned long int)(aux2s_)+ALIGN_BASE)&~ALIGN_BASE);
  sc    = (spinor *)(((unsigned long int)(sc_)+ALIGN_BASE)&~ALIGN_BASE);
  auxc  = (spinor *)(((unsigned long int)(auxc_)+ALIGN_BASE)&~ALIGN_BASE);
  aux2c = (spinor *)(((unsigned long int)(aux2c_)+ALIGN_BASE)&~ALIGN_BASE);

  Ptilde_cheb_coefs(EVMin, EVMax, *coefs, phmc_max_ptilde_degree, -1.0); 

  if(g_proc_id == g_stdio_proc && g_debug_level > 0){
    printf("# NDPOLY Acceptance Polynomial: EVmin = %f  EVmax = %f\n", EVMin, EVMax);
    printf("# NDPOLY ACceptance Polynomial: desired accuracy is %e \n", acc);
    fflush(stdout);
  }

  degree = 2*sloppy_degree;

  for(i = 0; i < 100 ; i++) {
    if (degree > phmc_max_ptilde_degree) {
      fprintf(stderr, "Error: n_cheby=%d > phmc_max_ptilde_degree=%d in ptilde\n",
              degree, phmc_max_ptilde_degree);
      fprintf(stderr, "Increase n_chebymax\n");
#ifdef MPI
      MPI_Finalize();
#endif
      exit(-5);
    }

    sum=0;
    for(j=degree; j<phmc_max_ptilde_degree; j++){ 
      sum += fabs(coefs[0][j]);
    }

    if((g_proc_id == g_stdio_proc) && (g_debug_level > 0)) {
      printf("# NDPOLY Acceptance Polynomial: Sum remaining | d_n | = %e for degree=%d\n", sum, degree);
      printf("# NDPOLY Acceptance Polynomial: coef[degree] = %e\n", (*coefs)[degree]);
    }
    if(sum < acc) { 
      break;
    }
    degree= (int)(degree*1.2);
  }

  if(g_debug_level > 2) {
    /* Ptilde P S P  Ptilde X - X */
    /* for random spinor X        */
    random_spinor_field_eo(ss, repro, RN_GAUSS);
    random_spinor_field_eo(sc, repro, RN_GAUSS);

    Ptilde_ndpsi(&auxs[0], &auxc[0], *coefs, degree, &ss[0], &sc[0], Qsq);
    Ptilde_ndpsi(&aux2s[0], &aux2c[0], phmc_dop_cheby_coef, phmc_dop_n_cheby, &auxs[0], &auxc[0], Qsq);
    Qsq(&auxs[0], &auxc[0], &aux2s[0], &aux2c[0]);
    Ptilde_ndpsi(&aux2s[0], &aux2c[0], phmc_dop_cheby_coef, phmc_dop_n_cheby, &auxs[0], &auxc[0], Qsq);
    Ptilde_ndpsi(&auxs[0], &auxc[0], *coefs, degree, &aux2s[0], &aux2c[0], Qsq);

    diff(&aux2s[0],&auxs[0], &ss[0], VOLUME/2);
    temp = square_norm(&aux2s[0], VOLUME/2, 1) / square_norm(&ss[0], VOLUME/2, 1) / 4.0;

    diff(&aux2c[0],&auxc[0], &sc[0], VOLUME/2);
    temp2 = square_norm(&aux2c[0], VOLUME/2, 1)/square_norm(&sc[0], VOLUME/2, 1) / 4.0;

    if(g_epsbar == 0){
      temp2 = 0.0;
    }
    /* || (Ptilde P S P Ptilde - 1)X ||^2 / || 2X ||^2 */
    if(g_proc_id == g_stdio_proc) {
      printf("# NDPOLY Acceptance Polynomial: relative squared accuracy in components:\n# UP=%e  DN=%e \n", temp, temp2);
    }

    temp = chebtilde_eval(degree, *coefs, EVMin);
    temp *= cheb_eval(phmc_dop_n_cheby, phmc_dop_cheby_coef, EVMin);
    temp *= EVMin;
    temp *= cheb_eval(phmc_dop_n_cheby, phmc_dop_cheby_coef, EVMin);
    temp *= chebtilde_eval(degree, *coefs, EVMin);
    temp = 0.5*fabs(temp - 1);
    if(g_proc_id == g_stdio_proc) {
      printf("# NDPOLY Acceptance Polynomial: Delta_IR at s=%f: | Ptilde P s_low P Ptilde - 1 |/2 = %e \n", EVMin, temp);
    }
  }
  if(g_proc_id == g_stdio_proc) {
    printf("# NDPOLY Acceptance Polynomial degree set to %d\n\n", degree);
  }

  *_degree = degree;
  free(ss_);
  free(auxs_);
  free(aux2s_);
  free(sc_);
  free(auxc_);
  free(aux2c_);
  return;
}
コード例 #11
0
ファイル: rrt.cpp プロジェクト: dseredyn/planar_manipulator
 double RRT::costLine(const KDL::Frame &x1, const KDL::Frame &x2) const {
     KDL::Twist diff( KDL::diff(x1, x2, 1.0) );
     return diff.vel.Norm() + diff.rot.Norm();
 }
コード例 #12
0
ファイル: stencil9.c プロジェクト: n7jti/Parallel_Computing
int main() {
  int i, j;
  struct timespec tStart;
  struct timespec tEnd;

  initArr(X);
  //printArr(X);
  
  double delta = 0.0;
  int numIters = 0;

  clock_gettime(CLOCK_REALTIME, &tStart);

  do {
    numIters += 1;

    //
    // TODO: implement the stencil computation here
    //

   #pragma omp parallel for default(none) private(i,j) shared(X,Y)
   for (i=1; i <= N; ++i) {
      for (j=1; j <= N; ++j) {
         double center = X[i][j] * 0.25;
         double adjacent = (X[i-1][j] + X[i+1][j] + X[i][j-1] + X[i][j+1]) * 0.125;
         double diagonals = (X[i-1][j-1] + X[i+1][j-1] + X[i-1][j+1] + X[i+1][j+1]) * 0.0625;

         Y[i][j] = 
            (center + adjacent + diagonals);
      }
   }

    // TODO: implement the computation of delta and get ready for the
    // next iteration here...
    //
    // 1) check for termination here by computing delta -- the largest
    //    absolute difference between corresponding elements of X and Y
    //    (i.e., the biggest change due to the application of the stencil 
    //    for this iteration of the while loop)
    //
    // 2) copy Y back to X to set up for the next execution
    //

   //Compute Delta
   delta = 0.0;
   #pragma omp parallel for default(none) private(j) shared(X,Y) reduction(max:delta)
   for (i=1; i <= N; ++i) {
      for (j=1; j <= N; ++j) {
         double temp = fabs(Y[i][j] - X[i][j]);
         if (delta < temp) delta = temp;
      }
   }

   #pragma omp parallel for default(none) private(j) shared(X,Y)
   // copy Y back to X to setup for next iteration
   for (i=1; i <=N; ++i) {
      for (j=1; j <=N; ++j) {
         X[i][j] = Y[i][j];
      }
   }

  } while (delta > epsilon);

  clock_gettime(CLOCK_REALTIME, &tEnd);
  
  //printArr(X);

  printf("Took %d iterations to converge\n", numIters);
  struct timespec tsDiff = diff(tStart, tEnd);
  //printf("Elapsed Time: %d.%09d Sec.\n", tsDiff.tv_sec, tsDiff.tv_nsec);
  printf("%d.%09d\n",tsDiff.tv_sec, tsDiff.tv_nsec);

}
コード例 #13
0
ファイル: vector2s.cpp プロジェクト: GarretReece/stheno
vector2s vector2s::operator-(const vector2s &rhs) {
	vector2s diff(*this);
	diff[0] -= rhs[0];
	diff[1] -= rhs[1];
	return diff;
}
コード例 #14
0
ファイル: QuadWarp.cpp プロジェクト: imclab/PixelPyros
void QuadWarp :: draw(bool lockAxis) {
	
	if(!visible) return;
	
	if(curPointIndex>=0) {
		
		ofVec3f diff(ofGetMouseX(), ofGetMouseY());
		diff-=dragStartPoint;
		diff*=0.1;
		
		if(lockAxis) {
			if(abs(diff.x)-abs(diff.y)>1) diff.y = 0;
			else if (abs(diff.y)-abs(diff.x)>1) diff.x = 0;
		}

		ofVec3f& curPoint = dstPoints[curPointIndex];
		
		
		curPoint = dragStartPoint+diff+clickOffset;
		
		curPoint.x = round(curPoint.x*10)/10;
		curPoint.y = round(curPoint.y*10)/10;
				
	}

	
	
	ofPushStyle();
	ofNoFill();
	
	
	ofEnableSmoothing();
	//ofScale(1024, 768);
	for(int i = 0; i < dstPoints.size(); i++) {
		ofSetColor(ofColor::black);
		ofSetLineWidth(3);
		
		
		ofVec3f& point = dstPoints[i];
		
		ofCircle(point, 1);
		ofSetColor(pointColour);
		ofSetLineWidth(1);
		ofCircle(point, pointRadius);
		ofCircle(point, 1);
	
		if(i == curPointIndex){
			
			ofLine(point.x, point.y - 100, point.x, point.y+100); 
			ofLine(point.x-100, point.y, point.x+100, point.y);
			
			ofDrawBitmapStringHighlight(ofToString(point.x), point.x, point.y-30, ofColor(0,0,0,100));
			ofDrawBitmapStringHighlight(ofToString(point.y), point.x-30, point.y, ofColor(0,0,0,100));
		}
		
		
	}
	
	
	ofPopStyle();
	
}
コード例 #15
0
ファイル: vector4.hpp プロジェクト: Cosmotronic/hexahedra
const vector4<type> diff (vector4<type> a, vector4<type> b)
{
    return vector4<type>(diff(a.x, b.x), diff(a.y, b.y),
                         diff(a.z, b.z), diff(a.w, b.w));
}
コード例 #16
0
ファイル: utilsopencl.c プロジェクト: lasoren/ml-optimization
uint64_t get_execution_time() {
  struct timespec delta = diff(time1,time2);
  return (uint64_t) (GIG * (uint64_t) delta.tv_sec + (uint64_t) delta.tv_nsec);
}
コード例 #17
0
ファイル: tff_controller.cpp プロジェクト: Telpr2/pr2_doors
void TFFController::update()
{
  // get time
  ros::Time time = robot_state_->getTime();
  ros::Duration dt = time - last_time_;
  last_time_ = time;

  // get joint positions
  chain_.getPositions(jnt_pos_);

  // get the joint velocities
  chain_.getVelocities(jnt_posvel_);

  // get the chain jacobian
  jnt_to_jac_solver_->JntToJac(jnt_pos_, jacobian_);

  // get cartesian twist and pose
  FrameVel frame_twist;
  jnt_to_twist_solver_->JntToCart(jnt_posvel_, frame_twist);
  pose_meas_ = frame_twist.value();
  twist_meas_ = pose_meas_.M.Inverse() * (frame_twist.deriv());

  // calculate the distance traveled along the axes of the tf
  position_ += pose_meas_.M.Inverse() * diff(pose_meas_old_, pose_meas_);
  pose_meas_old_ = pose_meas_;

  // calculate desired wrench
  wrench_desi_ = Wrench::Zero();
  for (unsigned int i=0; i<6; i++){
    if (mode_[i] == tff_controller::TaskFrameFormalism::FORCE)
      wrench_desi_[i] = value_[i];
    else if (mode_[i] ==  tff_controller::TaskFrameFormalism::VELOCITY)
      wrench_desi_[i] = twist_to_wrench_[i] * (value_[i] + vel_pid_controller_[i].updatePid(twist_meas_[i] - value_[i], dt));
    else if (mode_[i] == tff_controller::TaskFrameFormalism::POSITION)
      wrench_desi_[i] = twist_to_wrench_[i] * (pos_pid_controller_[i].updatePid(position_[i] - value_[i], dt));
  }

  // convert wrench to base reference frame
  wrench_desi_ = (pose_meas_.M * wrench_desi_);

  // convert the wrench into joint efforts
  for (unsigned int i = 0; i < kdl_chain_.getNrOfJoints(); i++){
    jnt_eff_(i) = 0;
    for (unsigned int j=0; j<6; j++)
      jnt_eff_(i) += (jacobian_(j,i) * wrench_desi_(j));
  }

  // set effort to joints
  chain_.setEfforts(jnt_eff_);

  // publish state
  if (++loop_count_ % 100 == 0){
    if (state_position_publisher_){
      if (state_position_publisher_->trylock()){
        state_position_publisher_->msg_.linear.x = position_.vel(0);
        state_position_publisher_->msg_.linear.y = position_.vel(1);
        state_position_publisher_->msg_.linear.z = position_.vel(2);
        state_position_publisher_->msg_.angular.x = position_.rot(0);
	state_position_publisher_->msg_.angular.y = position_.rot(1);
        state_position_publisher_->msg_.angular.z = position_.rot(2);
        state_position_publisher_->unlockAndPublish();
      }
    }
  }

}