YSRESULT YsShellExtEdit_StitchingUtil::CloseOneToNCrack(YsShellExtEdit &shl,Crack &crack)
{
	if(2==crack.path[0].GetN() && 3<=crack.path[1].GetN())
	{
		auto hd=edVtProx.FindEdgeVertexPairFromEdgePiece(crack.path[0]);
		if(1==hd.GetN() && hd[0].IsNotNull())
		{
			edVtProx.DeleteEdgeVertexPair(hd[0]);
		}

		for(YSSIZE_T idx=0; idx<crack.path[1].GetN()-1; ++idx)
		{
			auto hd=edVtProx.FindEdgeVertexPairFromEdgePiece(crack.path[1][idx],crack.path[1][idx+1]);
			if(1==hd.GetN() && hd[0].IsNotNull())
			{
				edVtProx.DeleteEdgeVertexPair(hd[0]);
			}
		}

		YsShellExtEdit_TopologyUtil topoUtil;
		topoUtil.InsertVertexOnEdge(shl,crack.path[0],crack.path[1].GetN(),crack.path[1]);
		return YSOK;
	}
	return YSERR;
}
Пример #2
0
void ParticleSpecies::ResizeDeleteBy(const size_t nDelete){
  if (nDelete > GetN()){
    std::cout << "Error when downsizing ParticleSpecies; nDelete > oldSize!" << std::endl;
    exit(1);
  }
  ResizeDelete(GetN()-nDelete);
}
Пример #3
0
double TrPdf::Integral(double xlow, double xhig) {	
  if (xlow<GetX(0)) {
    if (VERBOSE) printf("TrPdf::Integral-V xlow out of bounds, using low edge.\n");
    xlow = GetX(0);
  }
  if (xhig>GetX(GetN()-1)) {
    if (VERBOSE) printf("TrPdf::Integral-V xhigh out of bounds, using upper edge.\n");
    xhig = GetX(GetN()-1);
  }
  if (xlow>=xhig) {
    if (VERBOSE) printf("TrPdf::Integral-V xlow greater-equal than xhig, returning 0.\n");
    return 0.;
  }
  double sum = 0.;
  double y1,y0,x1,x0;
  for (int i=0; i<GetN()-1; i++) {
    if      (xlow<=GetX(i))   { x0 = GetX(i);   y0 = GetY(i);    }
    else if (xlow>=GetX(i+1)) { x0 = GetX(i+1); y0 = GetY(i+1);  } 
    else                      { x0 = xlow;      y0 = Eval(xlow); }
    if      (xhig<=GetX(i))   { x1 = GetX(i);   y1 = GetY(i);    }
    else if (xhig>=GetX(i+1)) { x1 = GetX(i+1); y1 = GetY(i+1);  }
    else                      { x1 = xhig;      y1 = Eval(xhig); }
    sum  += (y1+y0)*(x1-x0)/2.;
  }
  return sum;
}
Пример #4
0
Bool_t RooHistN::hasIdenticalBinning(const RooHistN& other) const 
{
  // First check if number of bins is the same
  if (GetN() != other.GetN()) {
    return kFALSE ;
  }

  // Next require that all bin centers are the same
  Int_t i ;
  for (i=0 ; i<GetN() ; i++) {
    Double_t x1,x2,y1,y2 ;
    
#if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
    GetPoint(i,x1,y1) ;
    other.GetPoint(i,x2,y2) ;
#else
    const_cast<RooHistN&>(*this).GetPoint(i,x1,y1) ;
    const_cast<RooHistN&>(other).GetPoint(i,x2,y2) ;
#endif

    if (fabs(x1-x2)>1e-10) {
      return kFALSE ;
    }

  }

  return kTRUE ;
}
Пример #5
0
u32 MatchDiv32(u32 pc , Sh4RegType &reg1,Sh4RegType &reg2 , Sh4RegType &reg3)
{

	u32 v_pc=pc;
	u32 match=1;
	for (int i=0;i<32;i++)
	{
		u16 opcode=ReadMem16(v_pc);
		v_pc+=2;
		if ((opcode&MASK_N)==ROTCL_KEY)
		{
			if (reg1==NoReg)
				reg1=(Sh4RegType)GetN(opcode);
			else if (reg1!=(Sh4RegType)GetN(opcode))
				break;
			match++;
		}
		else
		{
			//printf("DIV MATCH BROKEN BY: %s\n",OpDesc[opcode]->diss);
			break;
		}
		
		opcode=ReadMem16(v_pc);
		v_pc+=2;
		if ((opcode&MASK_N_M)==DIV1_KEY)
		{
			if (reg2==NoReg)
				reg2=(Sh4RegType)GetM(opcode);
			else if (reg2!=(Sh4RegType)GetM(opcode))
				break;
			
			if (reg2==reg1)
				break;

			if (reg3==NoReg)
				reg3=(Sh4RegType)GetN(opcode);
			else if (reg3!=(Sh4RegType)GetN(opcode))
				break;
			
			if (reg3==reg1)
				break;

			match++;
		}
		else
			break;
	}
	
	return match;
}
Пример #6
0
u32 MatchDiv32(u32 pc , Sh4RegType &reg1,Sh4RegType &reg2 , Sh4RegType &reg3)
{
	if (settings.dynarec.Safe)
		return 0;

	u32 v_pc=pc;
	u32 match=1;
	for (int i=0;i<32;i++)
	{
		u16 opcode=ReadMem16(v_pc);
		v_pc+=2;
		if ((opcode&MASK_N)==ROTCL_KEY)
		{
			if (reg1==NoReg)
				reg1=(Sh4RegType)GetN(opcode);
			else if (reg1!=(Sh4RegType)GetN(opcode))
				break;
			match++;
		}
		else
			break;
		
		opcode=ReadMem16(v_pc);
		v_pc+=2;
		if ((opcode&MASK_N_M)==DIV1_KEY)
		{
			if (reg2==NoReg)
				reg2=(Sh4RegType)GetM(opcode);
			else if (reg2!=(Sh4RegType)GetM(opcode))
				break;
			
			if (reg2==reg1)
				break;

			if (reg3==NoReg)
				reg3=(Sh4RegType)GetN(opcode);
			else if (reg3!=(Sh4RegType)GetN(opcode))
				break;
			
			if (reg3==reg1)
				break;

			match++;
		}
		else
			break;
	}
	
	return match;
}
Пример #7
0
bool Grid::isConsistent()
{
    bool result = true;
    if(Col1().isConsistent()){result=false;}
    if(Col2().isConsistent()){result=false;}
    if(Col3().isConsistent()){result=false;}
    if(Col4().isConsistent()){result=false;}
    if(Col5().isConsistent()){result=false;}
    if(Col6().isConsistent()){result=false;}
    if(Col7().isConsistent()){result=false;}
    if(Col8().isConsistent()){result=false;}
    if(Col9().isConsistent()){result=false;}

    if(Row1().isConsistent()){result=false;}
    if(Row2().isConsistent()){result=false;}
    if(Row3().isConsistent()){result=false;}
    if(Row4().isConsistent()){result=false;}
    if(Row5().isConsistent()){result=false;}
    if(Row6().isConsistent()){result=false;}
    if(Row7().isConsistent()){result=false;}
    if(Row8().isConsistent()){result=false;}
    if(Row9().isConsistent()){result=false;}
    
    if(GetNO().isConsistent()){result=false;}
    if(GetN().isConsistent()){result=false;}
    if(GetNE().isConsistent()){result=false;}
    if(GetO().isConsistent()){result=false;}
    if(GetC().isConsistent()){result=false;}
    if(GetE().isConsistent()){result=false;}
    if(GetSO().isConsistent()){result=false;}
    if(GetS().isConsistent()){result=false;}
    if(GetSE().isConsistent()){result=false;}
    
    return result;
}
YSRESULT YsShellExtEdit_FreeStitching(YsShellExtEdit &shl)
{
	YsShellExtEdit::StopIncUndo incUndo(shl);

	YsShellExtEdit_StitchingUtil stitchUtil;
	stitchUtil.PrepareForSingleUseEdge(shl.Conv());
	stitchUtil.FilterBySelfLengthAsThresholdCondition(shl.Conv());

	while(YSOK==stitchUtil.ProcessExpandedNearestMutualExclusiveEdgeVertexPair(shl.Conv()))
	{
	}


	stitchUtil.CleanUp(); // ProcessNearestMutualExclusiveEdgeVertexPair will delete all edge-vertex pairs.  Needs re-making.
	stitchUtil.PrepareForSingleUseEdge(shl.Conv());
	stitchUtil.FilterBySelfLengthAsThresholdCondition(shl.Conv());
	auto crackArray=stitchUtil.FindOneToNCrack(shl.Conv());
	printf("%d\n",(int)crackArray.GetN());

	for(auto &crack : crackArray)
	{
		stitchUtil.CloseOneToNCrack(shl,crack);
	}


	YsShellExtEdit_TopologyUtil topoUtil;
	topoUtil.SplitAllDegeneratePolygon(shl);

	return YSOK;
}
Пример #9
0
void TrPdf::Subtract(TrPdf* that, bool logx, bool logy) {
  for (int i=0; i<GetN(); i++) {
    double y0  = GetY(i);
    double y1  = that->Eval(GetX(i),logx,logy);
    SetY(i,y0-y1);
  }
}
Пример #10
0
void TrPdf::Multiply(TrPdf* that, bool logx, bool logy) {
  for (int i=0; i<GetN(); i++) {
    double y0  = GetY(i);
    double y1  = that->Eval(GetX(i),logx,logy); 
    SetY(i,y0*y1);
  }
}
Пример #11
0
Double_t RooHistN::getFitRangeNEvt(Double_t xlo, Double_t xhi) const 
{
  // Calculate integral of histogram in given range 
  Double_t sum(0) ;
  for (int i=0 ; i<GetN() ; i++) {
    Double_t x,y ;

#if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
    GetPoint(i,x,y) ;
#else
    const_cast<RooHistN*>(this)->GetPoint(i,x,y) ;
#endif

    if (x>=xlo && x<=xhi) {
      sum += y ;
    }
  }
  
  if (_rawEntries!=-1) {
    coutW(Plotting) << "RooHistN::getFitRangeNEvt() WARNING: Number of normalization events associated to histogram is not equal to number of events in histogram" << endl
		    << "                           due cut made in RooAbsData::plotOn() call. Automatic normalization over sub-range of plot variable assumes"    << endl
		    << "                           that the effect of that cut is uniform across the plot, which may be an incorrect assumption. To be sure of"   << endl 
		    << "                           correct normalization explicit pass normalization information to RooAbsPdf::plotOn() call using Normalization()" << endl ;
    sum *= _rawEntries / _entries ;
  }

  return sum ;
}
Пример #12
0
bool MatchDiv32s(u32 op,u32 pc)
{
	u32 n = GetN(op);
	u32 m = GetM(op);

	div_som_reg1=NoReg;
	div_som_reg2=(Sh4RegType)m;
	div_som_reg3=(Sh4RegType)n;

	u32 match=MatchDiv32(pc+2,div_som_reg1,div_som_reg2,div_som_reg3);
	printf("DIV32S matched %d%% @ 0x%X\n",match*100/65,pc);
	
	if (match==65)
	{
		//DIV32S was perfectly matched :)
		printf("div32s %d/%d/%d\n",div_som_reg1,div_som_reg2,div_som_reg3);
		return true;
	}
	else //no match ...
	{
		/*
		printf("%04X\n",ReadMem16(pc-2));
		printf("%04X\n",ReadMem16(pc-0));
		printf("%04X\n",ReadMem16(pc+2));
		printf("%04X\n",ReadMem16(pc+4));
		printf("%04X\n",ReadMem16(pc+6));*/
		return false;
	}
}
Пример #13
0
strArray GetCellCharItems(pMatrix ppm, int element, int len)
{
        int m, n, i;
        rMatrix pm = ppm[element];
        pMatrix pa0, **pa;

        if (!mxIsCell(pm))
                ErrMsgTxt("Expecting a cell argument.");

        m = GetM(pm);
        n = GetN(pm);
        if (!(((m == 1) && (n == len)) || ((n == 1) && (m == len))))
                ErrMsgTxt("invalid vector.");
        pa = pa0 = (pMatrix) matCalloc(len, sizeof(*pa));
        for (i = 0; i < len; i++) {
        	*pa = mxGetCell(pm, i);
        	if (!mxIsChar(*pa))
                        break;
                pa++;
        }
        if (i < len) {
                matFree(pa0);
        	ErrMsgTxt("Expecting a character cell element.");
        }
        return(pa0);
}
Пример #14
0
void SimplexLP::ShiftLowerBoundsToZero( void )
{
	//--------------------------------------------------------------------------
	//	Shift lower bounds to zero (where possible, i.e. where the lower bounds
	//	are finite. Adjust the finite upper bound on variable as well as the
	//	value of the objective function fixed adjustment accordingly.
	//
	Int_T i, nn = GetN(), len;
	Ptr<Real_T> a;
	Ptr<Int_T> row;

	for( i = 0; i < nn; i++ )
	{
		Real_T ll = GetL( i );
		Bool_T up = ( GetVarType( i ) & VT_HAS_LO_BND ) ? True : False;

		if( up && IsNonZero( ll ) )
		{
			for( MPS_LP::GetColumn( i, a, row, len ); len; --len, ++a, ++row )
				b[ *row ] -= *a * ll;

			if( up ) u[i] -= ll;

			f += GetC( i ) * ll;
		}
	}
}
Пример #15
0
void RooHistN::printToStream(ostream& os, PrintOption opt, TString indent) const {
  // Print info about this histogram to the specified output stream.
  //
  //   Standard: number of entries
  //      Shape: error CL and maximum value
  //    Verbose: print our bin contents and errors

  oneLinePrint(os,*this);
  RooPlotable::printToStream(os,opt,indent);
  if(opt >= Standard) {
    os << indent << "--- RooHistN ---" << endl;
    Int_t n= GetN();
    os << indent << "  Contains " << n << " bins" << endl;
    if(opt >= Shape) {
      os << indent << "  Errors calculated at" << _nSigma << "-sigma CL" << endl;
      if(opt >= Verbose) {
	os << indent << "  Bin Contents:" << endl;
	for(Int_t i= 0; i < n; i++) {
	  os << indent << setw(3) << i << ") x= " <<  fX[i];
	  if(fEXhigh[i] > 0 || fEXlow[i] > 0) {
	    os << " +" << fEXhigh[i] << " -" << fEXlow[i];
	  }
	  os << " , y = " << fY[i] << " +" << fEYhigh[i] << " -" << fEYlow[i] << endl;
	}
      }
    }
  }
}
Пример #16
0
void EclipseGeometry::GetIJK(size_t index, size_t& i, size_t& j, size_t& k) const
{
  assert(index < GetN());

  i = index % ni_;
  j = (index-i)/ni_ % nj_;
  k = (index - j*ni_ - i)/ni_/nj_;
}
Пример #17
0
void 
CIdDeMux<TBV, TBVFact>::SetCoordinates(unsigned                 id, 
                                       const TDimensionalPoint& coord,
                                       bool                     set_flag)
{
    _ASSERT(coord.size() == GetN());
    SetCoordinatesFast(id, &(coord[0]), set_flag);
}
Пример #18
0
int GetP()
{
	if (*s == '(')
	{
		s++;
		int val = GetE();
		if (*s == ')') { s++; return val; }
	}
	else return GetN();
}
Пример #19
0
Bool_t RooHistN::isIdentical(const RooHistN& other, Double_t tol) const 
{
  Int_t n= GetN();
  for(Int_t i= 0; i < n; i++) {
    if (fabs(fX[i]-other.fX[i])>tol) return kFALSE ;
    if (fabs(fY[i]-other.fY[i])>tol) return kFALSE ;
  }
  
  return kTRUE ;
}
Пример #20
0
int main() {
  long long N = GetN();
  long long nodes = NumberOfNodes();
  long long my_id = MyNodeId();
  long long _min = LLONG_MAX;
  long long _max = LLONG_MIN;
  int found = 0;
  for (long long i = my_id; i < N; i += nodes) {
    long long number = GetNumber(i);
    if(found == 0) {
      found = 1;
      _min = number;
      _max = number;
    }
    else {
      if(_min > number) {
        _min = number;
      }
      if(_max < number) {
        _max = number;
      }
    }
  }
  if (found == 1) {
    PutLL(MASTER_NODE, 1);
    PutLL(MASTER_NODE, _min);
    PutLL(MASTER_NODE, _max);
  }
  PutLL(MASTER_NODE, DONE);
  Send(MASTER_NODE);

  if (my_id == MASTER_NODE) {
    long long global_min = LLONG_MAX;
    long long global_max = LLONG_MIN;
    for (int node = 0; node < nodes; ++node) {
      long long received1 = 0;
      long long received2 = 0;
      Receive(node);
      received1 = GetLL(node);
      if(received1 == 1) {
        received1 = GetLL(node);
        received2 = GetLL(node);
        if(global_min > received1) {
          global_min = received1;
        }
        if(global_max < received2) {
          global_max = received2;
        }
      }
    }
    printf("%lld\n", global_max - global_min);
  }
  return 0;
}
Пример #21
0
Double GetRealScalar(pMatrix ppm, int element)
{
        rMatrix pm = ppm[element];

	if ((GetM(pm) == 1) && (GetN(pm) == 1)
	  && (IsNumeric(pm)) && (!IsComplex(pm)) ) {
		return(mxGetScalar(pm));
	} else {
		ErrMsgTxt("Expecting a scalar argument.");
	}
        return(0.0);
}
Пример #22
0
KString TTokens::ProcessEnumValue(	const KString&	String,
									LPCTSTR			pValueName) const
{
	for(size_t i = 0 ; i < GetN() ; i++)
	{
		const TToken& Token = GetDataRef(i);
		if(String == Token.m_SrcString)
			return Token.m_DstString;
	}

	REPORT_INVALID_VALUE;
}
Пример #23
0
void ParticleSpecies::ResizeDelete(const size_t newSize) {
  if (newSize > GetN()) {
    std::cout << "Error when resizing ParticleSpecies; newSize > oldSize!" << std::endl;
    exit(1);
  }
  z.resize(newSize);
  r.resize(newSize);
  vz.resize(newSize);
  vr.resize(newSize);
  vt.resize(newSize);
  m.resize(newSize);
}
Пример #24
0
double TrPdf::Eval(double x, bool logx, bool logy) {
  if (x<GetX(0)) {
    if (VERBOSE) printf("TrPdf::Eval-V requested x under lower bound, returning 0.\n");
    return 0.; 
  }
  if (x>GetX(GetN()-1)) { 
    if (VERBOSE) printf("TrPdf::Eval-V requested x over upper bound, returning 0.\n");
    return 0.;
  }
  double value = 0.;
  for (int i=0; i<GetN()-1; i++) {
    if ( (x>=X.at(i))&&(x<=X.at(i+1)) ) {
      double y1  = (logy) ? log10(GetY(i+1)) : GetY(i+1);
      double y0  = (logy) ? log10(GetY(i))   : GetY(i);
      double x1  = (logx) ? log10(GetX(i+1)) : GetX(i+1);
      double x0  = (logx) ? log10(GetX(i))   : GetX(i);
      double xx  = (logx) ? log10(x)         : x;
      value = (y1*(xx-x0) + y0*(x1-xx))/(x1-x0);
    }
  }
  return (logy) ? pow(10.,value) : value;
}
Пример #25
0
RooHistN* RooHistN::makeResidHist(const RooCurve& curve,bool normalize) const {
  // Make histogram of (normalized) residuals w.r.t to given curve

  // Copy all non-content properties from hist1
  RooHistN* hist = new RooHistN(_nominalBinWidth) ;
  hist->SetName(Form(normalize?"pull_%s_s":"resid_%s_s",GetName(),curve.GetName())) ;
  hist->SetTitle(Form(normalize?"Pull of %s and %s":"Residual of %s and %s",GetTitle(),curve.GetTitle())) ;  

  // Determine range of curve 
  Double_t xstart,xstop,y ;
#if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
  curve.GetPoint(0,xstart,y) ;
  curve.GetPoint(curve.GetN()-1,xstop,y) ;
#else
  const_cast<RooCurve&>(curve).GetPoint(0,xstart,y) ;
  const_cast<RooCurve&>(curve).GetPoint(curve.GetN()-1,xstop,y) ;
#endif
  
  // Add histograms, calculate Poisson confidence interval on sum value
  for(Int_t i=0 ; i<GetN() ; i++) {    
    Double_t x,point;
#if ROOT_VERSION_CODE >= ROOT_VERSION(4,0,1)
    GetPoint(i,x,point) ;
#else
    const_cast<RooHistN&>(*this).GetPoint(i,x,point) ;
#endif

    // Only calculate pull for bins inside curve range
    if (x<xstart || x>xstop) continue ;

    Double_t y = point - curve.interpolate(x) ;
    Double_t dyl = GetErrorYlow(i) ;
    Double_t dyh = GetErrorYhigh(i) ;
    if (normalize) {
        Double_t norm = (y>0?dyh:dyl);
	if (norm==0.) {
	  coutW(Plotting) << "RooHistN::makeResisHist(" << GetName() << ") WARNING: point " << i << " has zero error, setting residual to zero" << endl ;
	  y=0 ;
	  dyh=0 ;
	  dyl=0 ;
	} else {
	  y   /= norm;
	  dyh /= norm;
	  dyl /= norm;
	}
    }
    hist->addBinWithError(x,y,dyl,dyh);
  }
  return hist ;
}
Пример #26
0
void ParticleSpecies::Order2D() {
  // Zero ordcount
  for (size_t j=0; j<nr; j++) {
    for (size_t k=0; k<nz; k++){
      ordcount[j*(nz+1) + k]= 0;
    }
  }

  //Sort particles
  for (size_t n=0; n<GetN(); n++) {
    int ir = (int)r[n];
    int iz = (int)z[n];

    //Sanity check -- we should be inside the grid
    if ( (ir<0) || (ir>=nr) || (iz<0) || (iz>=nz) ) {
      //Edge cases
      if (r[n] == (double) nr) {
        ir--;
      }
      else if (z[n] == (double) nz) {
        iz--;
      }
      else {
      //Over the edge; it's just wrong!
        fprintf(stderr," !!!ERROR!!! ir=%d iz=%d\n", ir, iz);
        fflush(stderr);

        printf("Error in ParticleSpecies::order_2D(): particle position out-of-range, r=%g, z=%g, (ir,iz)= (%d,%d)\n", r[n], z[n], ir, iz);

        exit(1);
      }
    }

    temP[ir*nz+iz].push_back(n);
    ordcount[ir*(nz+1) + iz]++;
  }

  //Stuff them back into the particle arrays, but now in the correct order
  ShuffleArray(z);
  ShuffleArray(r);
  ShuffleArray(vz);
  ShuffleArray(vr);
  ShuffleArray(vt);
  ShuffleArray(m);
  for (int cidx = 0; cidx < nr*nz; cidx++) {
    temP[cidx].clear();
  }

}
Пример #27
0
double TrPdf::Integral(int first, int last) {
  if (first<0) { 
    if (VERBOSE) printf("TrPdf::Integral-V first index out of bounds (%d, minimum is 0), using 0.\n",first); 
    first = 0; 
  }
  if (last>GetN()-1) { 
    if (VERBOSE) printf("TrPdf::Integral-V last index out of bounds (%d, maximum is N-1 = %d), using %d.\n",last,N-1,N-1); 
    last = GetN()-1; 
  }
  if (first>last) { 
    if (VERBOSE) printf("TrPdf::Integral-V first index greater than last (%d, %d), returning 0.\n",first,last); 
    return 0.; 
  } 
  if (first==last) return 0.;
  double sum = 0.;
  for (int i=first; i<last; i++) {
    double y1 = GetY(i+1);
    double y0 = GetY(i);
    double x1 = GetX(i+1);
    double x0 = GetX(i);
    sum += (y1+y0)*(x1-x0)/2.; 
  }
  return sum;
}
Пример #28
0
	int GetNextBlockSymbolic(int *rowptr, int *colind) const{
		if(iiter >= GetN()){ return 0; }
		rowptr[0] = A->rowptr[iiter];
		rowptr[1] = A->rowptr[iiter+1];
		rowptr[2] = A->rowptr[iiter+2];
		for(int r = 0; r < 2; ++r){
			for(int p = rowptr[r]; p < rowptr[r+1]; ++p){
				*colind = A->colind[p];
				colind++;
			}
		}
		rowptr[1] -= rowptr[0];
		rowptr[2] -= rowptr[0];
		rowptr[0] = 0;
		iiter += 2;
		return 2;
	}
Пример #29
0
// This is a sample solution to the "Sum all integers" problem. Each node sums
// the elements that belong to it (that is, the ones with position equal to
// MyNodeId() modulo NumberOfNodes()).
//
// To showcase the communication a bit better, instead of sending all the
// results to a "master" node, each node sends its result to the next one,
// accumulating the result from the previous node. The last node prints the
// final result.
int main() {
  long long sum = 0LL;
  for (long long pos = MyNodeId(); pos < GetN(); pos += NumberOfNodes()) {
    sum += GetNumber(pos);
  }
  if (MyNodeId() > 0) {
    Receive(MyNodeId() - 1);
    sum += GetLL(MyNodeId() - 1);
  }
  if (MyNodeId() < NumberOfNodes() - 1) {
    PutLL(MyNodeId() + 1, sum);
    Send(MyNodeId() + 1);
  } else {
    printf("%lld\n", sum);
  }
  return 0;
}
Пример #30
0
// -------
// Tokens
// -------
KString TTokens::Process(const KString& String) const
{
	KString DstString;

	for(size_t szStart = 0 ; szStart < String.GetLength() ; )
	{
		// Scanning for the closest token starting at 'szStart'
		const TToken*	pClosestToken = NULL;
		size_t			szClosestTokenPos;

		for(size_t i = 0 ; i < GetN() ; i++)
		{
			const TToken& CurToken = GetDataRef(i);

			size_t szPos = String.Find(CurToken.m_SrcString, szStart);
			if(szPos == UINT_MAX)
				continue;

			if(	pClosestToken == NULL		||
				szPos < szClosestTokenPos	||
				szPos == szClosestTokenPos &&
					CurToken.m_SrcString.GetLength() >
						pClosestToken->m_SrcString.GetLength())
			{
				pClosestToken = &CurToken, szClosestTokenPos = szPos;
			}
		}
		
		if(pClosestToken == NULL) // no more tokens found
		{
			DstString += String.Mid(szStart); // adding leftovers
			break;
		}

		DstString += String.Mid(szStart, szClosestTokenPos - szStart); // adding pre-token part
		DstString += pClosestToken->m_DstString; // adding token replacement
		
		// Forwarding 'szStart' to the end of just substed token
		szStart = szClosestTokenPos + pClosestToken->m_SrcString.GetLength();
	}

	return DstString;
}