double piOMPEntrelacerCritical(int n)
    {
    const int NB_THREAD = OmpTools::setAndGetNaturalGranularity();
    const double DX = (double) 1 / n;
    double somme = 0;

#pragma omp parallel
	{
	const int TID = OmpTools::getTid();
	int s = TID;
	double xs;
	double sommeThread = 0;

	while (s < n)
	    {
	    xs = s * DX;
	    sommeThread += fpi(xs);
	    s += NB_THREAD;
	    }
#pragma opm critical toto
	    {
	    somme += sommeThread;
	    }
	}

    return somme / n;
    }
示例#2
0
void DirRelation::writeDocumentation(OutputList &ol)
{
  static bool generateTreeView = Config_getBool(GENERATE_TREEVIEW);
  ol.pushGeneratorState();
  ol.disableAllBut(OutputGenerator::Html);

  QCString shortTitle=theTranslator->trDirRelation(
                      m_src->shortName()+" &rarr; "+
                      m_dst->dir()->shortName());
  QCString title=theTranslator->trDirRelation(
                 m_src->displayName()+" -> "+
                 m_dst->dir()->shortName());
  startFile(ol,getOutputFileBase(),getOutputFileBase(),
            title,HLI_None,!generateTreeView,m_src->getOutputFileBase());

  if (!generateTreeView)
  {
    // write navigation path
    m_src->writeNavigationPath(ol);
    ol.endQuickIndices();
  }
  ol.startContents();

  ol.writeString("<h3>"+shortTitle+"</h3>");
  ol.writeString("<table class=\"dirtab\">");
  ol.writeString("<tr class=\"dirtab\">");
  ol.writeString("<th class=\"dirtab\">");
  ol.parseText(theTranslator->trFileIn(m_src->pathFragment()));
  ol.writeString("</th>");
  ol.writeString("<th class=\"dirtab\">");
  ol.parseText(theTranslator->trIncludesFileIn(m_dst->dir()->pathFragment()));
  ol.writeString("</th>");
  ol.writeString("</tr>");

  SDict<FilePair>::Iterator fpi(m_dst->filePairs());
  FilePair *fp;
  for (fpi.toFirst();(fp=fpi.current());++fpi)
  {
    ol.writeString("<tr class=\"dirtab\">");
    ol.writeString("<td class=\"dirtab\">");
    writePartialFilePath(ol,m_src,fp->source());
    ol.writeString("</td>");
    ol.writeString("<td class=\"dirtab\">");
    writePartialFilePath(ol,m_dst->dir(),fp->destination());
    ol.writeString("</td>");
    ol.writeString("</tr>");
  }
  ol.writeString("</table>");

  ol.endContents();
  
  endFileWithNavPath(m_src,ol);

  ol.popGeneratorState();
}
示例#3
0
double piSequentiel(int n)
    {
    //TODO
    double somme = 0;
    double dx = 1./n;
    double x;
    for (int i = 0; i < n; i++)
	{
	x = i * dx;
	somme += fpi(x);
	}
    return somme/n;
    }
/**
 * synchronisation couteuse!
 */
double piOMPforAtomic(int n)
    {
    const double DX = 1 / (double) n;
    double xi;
    double sum = 0;
#pragma omp parallel for private(xi)
    for (int i = 1; i <= n; i++)
	{
	xi = i * DX;
	// !! Catastrophique en terme de performances !! (comme critique)
#pragma omp atomic
	sum += fpi(xi);
	}
    return sum / n;
    }
示例#5
0
/**
 * synchronisation couteuse!
 */
double piOMPforAtomic(int n)
    {
    double somme = 0;
        double dx = 1. / n;
        double x;
    #pragma omp parallel for private (x)
        for (int i = 0; i < n; i++)
    	{
    	x = i * dx;
#pragma omp atomic (toto)
    	somme += fpi(x);

    	}
        return somme / n;

    }
示例#6
0
void DirRelation::writeDocumentation(OutputList &ol)
{
  ol.pushGeneratorState();
  ol.disableAllBut(OutputGenerator::Html);

  QCString shortTitle=m_src->shortName()+" &rarr; "+
                      m_dst->dir()->shortName()+" Relation";//theTranslator->trDirRelation(m_shortName);
  QCString title=m_src->displayName()+" -> "+
                 m_dst->dir()->shortName()+" Relation";//theTranslator->trDirRelation(m_dispName);
  startFile(ol,getOutputFileBase(),getOutputFileBase(),title);

  // write navigation path
  m_src->writeNavigationPath(ol);

  //startTitle(ol,getOutputFileBase());
  //  ol.parseText(shortTitle);
  //endTitle(ol,getOutputFileBase(),title);
  ol.writeString("<h3>"+shortTitle+"</h3>");
  
  ol.writeString("<table class=\"dirtab\">");
  ol.writeString("<tr class=\"dirtab\">");
  ol.writeString("<th class=\"dirtab\">File in ");
  m_src->writePathFragment(ol);
  ol.writeString("</th>");
  ol.writeString("<th class=\"dirtab\">Includes file in ");
  m_dst->dir()->writePathFragment(ol);
  ol.writeString("</th>");
  ol.writeString("</tr>");

  SDict<FilePair>::Iterator fpi(m_dst->filePairs());
  FilePair *fp;
  for (fpi.toFirst();(fp=fpi.current());++fpi)
  {
    ol.writeString("<tr class=\"dirtab\">");
    ol.writeString("<td class=\"dirtab\">");
    writePartialFilePath(ol,m_src,fp->source());
    ol.writeString("</td>");
    ol.writeString("<td class=\"dirtab\">");
    writePartialFilePath(ol,m_dst->dir(),fp->destination());
    ol.writeString("</td>");
    ol.writeString("</tr>");
  }
  ol.writeString("</table>");
  
  endFile(ol); 
  ol.popGeneratorState();
}
示例#7
0
/**
 * synchronisation couteuse!
 */
double piOMPforAtomic(int n)
    {
    double somme = 0;
    double dx = 1.0/(double)n;
    double x;

    // V2
    #pragma omp parallel for private (x)
	for(int i = 0; i < n; i++)
	    {
	    // V1 : double x = ....
	    x = i * dx;

	    // pas bon ! n * NB_THREAD / NB_THREAD
	    // mais quand meme meilleur que critical for car fpi(x) est fait en parallel et += séquentiellement
	#pragma omp atomic
		somme += fpi(x);
	    }
	return somme/n;
    }
/**
 * synchronisation couteuse!
 */
double piOMPforCritique(int n)
    {
    double somme = 0;
    double dx = 1.0/(double)n;
    double x;

    // V2
    #pragma omp parallel for private (x)
	for(int i = 0; i < n; i++)
	    {
	    // V1 : double x = ....
	    x = i * dx;

	    // pas bon ! n * NB_THREAD / NB_THREAD
	#pragma omp critical (toto)
		{
		somme += fpi(x);
		}
	    }
	return somme/n;
    }
示例#9
0
int main()
{ /* Brents example program */
    flash x,pi;
    miracl *mip=mirsys(-35,0);
    x=mirvar(0);
    pi=mirvar(0);
    mip->RPOINT=ON;
    printf("Calculating pi..\n");
    fpi(pi);
    cotnum(pi,stdout); /* output pi */
    printf("Calculating exp(pi*(163/9)^0.5)\n");
    fconv(163,9,x);
    froot(x,2,x);
    fmul(x,pi,x);
    fexp(x,x);
    cotnum(x,stdout);
    printf("Calculating exp(pi*(163)^0.5)\n");
    fpower(x,3,x);
    cotnum(x,stdout);
    return 0;
}
示例#10
0
static int norm(_MIPD_ int type,flash y)
{ /* convert y to first quadrant angle *
   * and return sign of result         */
    int s;
#ifndef MR_GENERIC_MT
    miracl *mr_mip=get_mip();
#endif
    if (mr_mip->ERNUM) return 0;
    s=PLUS;
    if (size(y)<0)
    {
        negify(y,y);
        if (type!=COS) s=(-s);
    }
    fpi(_MIPP_ mr_mip->pi);
    fpmul(_MIPP_ mr_mip->pi,1,2,mr_mip->w8);
    if (fcomp(_MIPP_ y,mr_mip->w8)<=0) return s;
    fpmul(_MIPP_ mr_mip->pi,2,1,mr_mip->w8);
    if (fcomp(_MIPP_ y,mr_mip->w8)>0)
    { /* reduce mod 2.pi */
        fdiv(_MIPP_ y,mr_mip->w8,mr_mip->w9);
        ftrunc(_MIPP_ mr_mip->w9,mr_mip->w9,mr_mip->w9);
        fmul(_MIPP_ mr_mip->w9,mr_mip->w8,mr_mip->w9);
        fsub(_MIPP_ y,mr_mip->w9,y);
    }
    if (fcomp(_MIPP_ y,mr_mip->pi)>0)
    { /* if greater than pi */
        fsub(_MIPP_ y,mr_mip->pi,y);
        if (type!=TAN) s=(-s);
    }
    fpmul(_MIPP_ mr_mip->pi,1,2,mr_mip->w8);
    if (fcomp(_MIPP_ y,mr_mip->w8)>0)
    { /* if greater than pi/2 */
        fsub(_MIPP_ mr_mip->pi,y,y);
        if (type!=SIN) s=(-s);
    }
    return s;
}
示例#11
0
static BOOL act(int p,int q)
{ /* act on selected key */
    int k,n,c;
    aprint(PRESSED,4+5*p,6+3*q,keys[q][p]);
    switch(p+7*q)
    {
    case 0:  if (degrees) fmul(x,radeg,x);
             if (hyp) fsinh(x,x);
             else     fsin(x,x);
             newx=TRUE;
             break;
    case 1:  if (degrees) fmul(x,radeg,x);
             if (hyp) fcosh(x,x);
             else     fcos(x,x);
             newx=TRUE;
             break;
    case 2:  if (degrees) fmul(x,radeg,x);
             if (hyp) ftanh(x,x);
             else     ftan(x,x);
             newx=TRUE;
             break;
    case 3:  if (lgbase>0)
             {
                 n=size(x);
                 if (abs(n)<MR_TOOBIG)
                 {
                     convert(lgbase,x);
                     if (n<0) frecip(x,x);
                     fpower(x,abs(n),x);
                     newx=TRUE;
                     break;
                 }
                 if (lgbase==2)  fmul(x,loge2,x);
                 if (lgbase==10) fmul(x,loge10,x);
             }
             fexp(x,x);
             newx=TRUE;
             break;
    case 4:  mip->RPOINT=!mip->RPOINT;
             newx=TRUE;
             break;
    case 5:  clrall();
             newx=TRUE;
             break;
    case 6:  return TRUE;
    case 7:  if (hyp) fasinh(x,x);
             else     fasin(x,x);
             if (degrees) fdiv(x,radeg,x);
             newx=TRUE;
             break;
    case 8:  if (hyp) facosh(x,x);
             else     facos(x,x);
             if (degrees) fdiv(x,radeg,x);
             newx=TRUE;
             break;
    case 9:  if (hyp) fatanh(x,x);
             else     fatan(x,x);
             if (degrees) fdiv(x,radeg,x);
             newx=TRUE;
             break;
    case 10: flog(x,x);
             if (lgbase==2)  fdiv(x,loge2,x);
             if (lgbase==10) fdiv(x,loge10,x);
             newx=TRUE;
             break;
    case 11: newx=TRUE;
             k=3;
             forever
             {
                 aprint(INVER,2+stptr[k],2,settings[k][option[k]]);
                 curser(2+stptr[k],2);
                 c=arrow(gethit());
                 if (c==1)
                 {
                     if (option[k]==nops[k]) option[k]=0;
                     else option[k]+=1;
                     continue;
                 }
                 aprint(STATCOL,2+stptr[k],2,settings[k][option[k]]);
                 if (c==0 || c==2) break;
                 if (c==4 && k>0) k--;
                 if (c==3 && k<3) k++;
             }
             setopts();
             break;
    case 12: chekit(7);
             break;
    case 13: result=FALSE;
             if (ipt==0) break;
             ipt--;
             mybuff[ipt]='\0';
             if (ipt==0) clr();
             just(mybuff);
             cinstr(x,mybuff);
             newx=TRUE;
             break;
    case 14: if (!next('7')) putchar(BELL);
             break;
    case 15: if (!next('8')) putchar(BELL);
             break;
    case 16: if (!next('9')) putchar(BELL);
             break;
    case 17: chekit(6);
             break;
    case 18: chekit(5);
             break;
    case 19: chekit(4);
             break;
    case 20: copy(m,x);
             newx=TRUE;
             break;
    case 21: if (!next('4')) putchar(BELL);
             break;
    case 22: if (!next('5')) putchar(BELL);
             break;
    case 23: if (!next('6')) putchar(BELL);
             break;
    case 24: fmul(x,x,x);
             newx=TRUE;
             break;
    case 25: froot(x,2,x);
             newx=TRUE;
             break;
    case 26: chekit(3);
             break;
    case 27: brkt=0;
             chekit(0);
             flag=OFF;
             fadd(m,x,m);
             newx=TRUE;
             break;
    case 28: if (!next('1')) putchar(BELL);
             break;
    case 29: if (!next('2')) putchar(BELL);
             break;
    case 30: if (!next('3')) putchar(BELL);
             break;
    case 31: frecip(x,x);
             newx=TRUE;
             break;
    case 32: fpi(x);
             newx=TRUE;
             break;
    case 33: chekit(2);
             break;
    case 34: negify(x,x);
             newx=TRUE;
             break;
    case 35: if (!next('0')) putchar(BELL);
             break;
    case 36: if (!next('/')) putchar(BELL);
             break;
    case 37: if (!next('.')) putchar(BELL);
             break;
    case 38: if (ipt>0)
             {
                 putchar(BELL);
                 result=FALSE;
             }
             else
             {
                 zero(x);
                 brkt+=1;
                 newx=TRUE;
             }
             break;
    case 39: if (brkt>0)
             {
                 chekit(0);
                 brkt-=1;
             }
             else
             {
                 putchar(BELL);
                 result=FALSE;
             }
             break;
    case 40: chekit(1);
             break;
    case 41: brkt=0;
             equals(0);
             flag=OFF;
             break;
    }
    return FALSE;
}
bool idaapi dump_funcs_ctree(void *ud, qstring &crypto_prefix) 
{
	logmsg(DEBUG, "dump_funcs_ctree entered\n");

	std::map<ea_t, ctree_dump_line> data_to_dump;

	// enumerate through all the functions in the idb file
	bool heuristic_flag;
	size_t count = 0, heur_count = 0, crypto_count = 0;
	size_t total_func_qty = get_func_qty();
	for (size_t i = 0 ; i < total_func_qty ; i ++) {
		heuristic_flag = 0;
		
		func_t *function = getn_func(i);
		if (function != NULL) {
			bool crypto_flag = func_name_has_prefix(crypto_prefix, function->startEA);
			
			// skip libs that are not marked as crypto
			if ( ((function->flags & FUNC_LIB) != 0) && !crypto_flag )
				continue;
			
			// From this point on, we have a function outside of lib or a crypto one
			
			// Ignore functions less than MIN_FUNC_SIZE_DUMP bytes
			if ( ((function->endEA - function->startEA) < MIN_FUNC_SIZE_DUMP) && !crypto_flag )
				continue;
			
			// If function is bigger than MIN_HEURISTIC_FUNC_SIZE_DUMP, mark as being triggered by the heuristic
			if (function->endEA - function->startEA > MIN_HEURISTIC_FUNC_SIZE_DUMP)
				heuristic_flag = 1;
				
			// dump up to N_CRYPTO_FUNCS_TO_DUMP crypto functions
			// dump up to N_HEUR_FUNCS_TO_DUMP heuristic functions
			// at least N_FUNCS_TO_DUMP functions will be dumped
			if ((count < N_FUNCS_TO_DUMP) || (crypto_flag && (crypto_count < N_CRYPTO_FUNCS_TO_DUMP)) || (heuristic_flag && (heur_count < N_HEUR_FUNCS_TO_DUMP))) {
				hexrays_failure_t hf;
				cfuncptr_t cfunc = decompile(function, &hf);

				logmsg(DEBUG, "\nafter decompile()\n");
				if (cfunc != NULL) {
					ctree_dumper_t ctree_dumper;
					ctree_dumper.apply_to(&cfunc->body, NULL);
					
					ctree_dump_line func_dump;
					func_dump.ctree_dump = ctree_dumper.ctree_dump;
					func_dump.ctree_for_hash = ctree_dumper.ctree_for_hash;

					func_dump.func_depth = -1;

					func_dump.func_start = function->startEA;
					func_dump.func_end = function->endEA;

					qstring func_name;
					if (get_func_name2(&func_name, function->startEA) != 0) {
						if (func_name.length() > 0) {
							func_dump.func_name = func_name;
						}
					}
					
					func_parent_iterator_t fpi(function);
					for (ea_t addr = get_first_cref_to(function->startEA); addr != BADADDR; addr = get_next_cref_to(function->startEA, addr)) {
						func_t *referer = get_func(addr);
						if (referer != NULL) {
							func_dump.referres.push_back(referer->startEA);
						}
					}
					
					func_dump.heuristic_flag = heuristic_flag; // 0 or 1 depending on code above
					if (heuristic_flag)
						heur_count++;

					if (crypto_flag)
						crypto_count++;
					
					count++;
					
					data_to_dump[function->startEA] = func_dump;
				}
			}
		}
	}
	
	dump_ctrees_in_file(data_to_dump, crypto_prefix);

	return true;
}
inline
bool
SlicedCurvilinear<ScalarParam,dimensionParam,ValueScalarParam>::Locator::newtonRaphsonStep(
	const typename SlicedCurvilinear<ScalarParam,dimensionParam,ValueScalarParam>::Point& position)
	{
	typedef Geometry::Matrix<Scalar,dimension,dimension> Matrix;
	
	/* Transform the current cell position to domain space: */
	const Point* baseVertex=ds->grid.getArray()+baseVertexIndex;
	
	/* Perform multilinear interpolation: */
	Point p[CellTopology::numVertices>>1]; // Array of intermediate interpolation points
	int interpolationDimension=dimension-1;
	int numSteps=CellTopology::numVertices>>1;
	for(int pi=0;pi<numSteps;++pi)
		{
		const Point* vPtr=baseVertex+ds->vertexOffsets[pi];
		p[pi]=Geometry::affineCombination(vPtr[0],vPtr[1],cellPos[interpolationDimension]);
		}
	for(int i=1;i<dimension;++i)
		{
		--interpolationDimension;
		numSteps>>=1;
		for(int pi=0;pi<numSteps;++pi)
			p[pi]=Geometry::affineCombination(p[pi],p[pi+numSteps],cellPos[interpolationDimension]);
		}
	
	/* Calculate f(x_i): */
	Vector fi=p[0]-position;
	
	/* Check for convergence: */
	if(fi.sqr()<epsilon2)
		return true;
	
	/* Calculate f'(x_i): */
	Matrix fpi=Matrix::zero;
	for(int i=0;i<dimension;++i)
		{
		/* Calculate cell's edge vectors for current dimension: */
		int iMask=1<<i;
		for(int v0=0;v0<CellTopology::numVertices;++v0)
			if((v0&iMask)==0)
				{
				/* Calculate edge vector and convex combination weight: */
				const Point* vPtr=baseVertex+ds->vertexOffsets[v0];
				Vector d=vPtr[ds->vertexStrides[i]]-vPtr[0];
				Scalar weight=Scalar(1);
				for(int j=0;j<dimension;++j)
					if(j!=i)
						{
						int jMask=1<<j;
						if(v0&jMask)
							weight*=cellPos[j];
						else
							weight*=Scalar(1)-cellPos[j];
						}
				
				/* Add weighted vector to Jacobian matrix: */
				for(int j=0;j<dimension;++j)
					fpi(j,i)+=d[j]*weight;
				}
		}
	
	/* Calculate the step vector as f(x_i) / f'(x_i): */
	CellPosition stepi=fi/fpi;
	
	/* Adjust the cell position: */
	for(int i=0;i<dimension;++i)
		cellPos[i]-=stepi[i];
	
	return false;
	}