コード例 #1
0
ファイル: gmIncGC.cpp プロジェクト: Guthius/gs2emu-googlecode
void gmGarbageCollector::FullCollect()
{
  m_fullThrottle = true;

  if(IsOff()) // If GC is off
  {
    ReclaimObjectsAndRestartCollection(); // Do flip and turn it back on
  }

  while(!Collect())
  {
    // Do the collect phase
  }
  ReclaimObjectsAndRestartCollection(); // Do flip and turn it back on

  // Collect a second time to catch floating black objects
  while(!Collect())
  {
    // Do the collect phase
  }
  ReclaimObjectsAndRestartCollection(); // Do flip and turn it back on

  // NOTE: The GC is now restarted and in an 'On' state, meaning it will now collect again from the machine.
  //       This behavior may not be desirable, so this function really needs more analysis to determine the
  //       optimum sequence for a full collect with minimal redundancy.

  // Free memory of garbage objects
  while(ReclaimSomeFreeObjects())
  {
    // Reclaim all garbage
  }
  m_fullThrottle = false;
}
コード例 #2
0
void TransposeAxpyContract
( T alpha, const ElementalMatrix<T>& A,
  ElementalMatrix<T>& B, bool conjugate )
{
    EL_DEBUG_CSE
    const Dist U = B.ColDist();
    const Dist V = B.RowDist();
    if( A.ColDist() == V && A.RowDist() == U )
    {
        TransposeAxpy( alpha, A, B, conjugate );
    }
    else if( (A.ColDist() == V && A.RowDist() == Partial(U)) ||
             (A.ColDist() == V && A.RowDist() == Collect(U)) ||
             (A.RowDist() == U && A.ColDist() == Partial(V)) ||
             (A.RowDist() == U && A.ColDist() == Collect(V)) )
    {
        unique_ptr<ElementalMatrix<T>>
                                    ASumFilt( B.ConstructTranspose(B.Grid(),B.Root()) );
        if( B.ColConstrained() )
            ASumFilt->AlignRowsWith( B, true );
        if( B.RowConstrained() )
            ASumFilt->AlignColsWith( B, true );
        Contract( A, *ASumFilt );
        if( !B.ColConstrained() )
            B.AlignColsWith( *ASumFilt, false );
        if( !B.RowConstrained() )
            B.AlignRowsWith( *ASumFilt, false );

        // We should have ensured that the alignments are compatible
        TransposeAxpy( alpha, ASumFilt->LockedMatrix(), B.Matrix(), conjugate );
    }
    else
        LogicError("Incompatible distributions");
}
コード例 #3
0
ファイル: Contract.hpp プロジェクト: nooperpudd/Elemental
void Contract
( const BlockMatrix<T>& A,
        BlockMatrix<T>& B )
{
    DEBUG_ONLY(CSE cse("Contract"))
    AssertSameGrids( A, B );
    const Dist U = B.ColDist();
    const Dist V = B.RowDist();
    // TODO: Shorten this implementation?
    if( A.ColDist() == U && A.RowDist() == V )
    {
        Copy( A, B );
    }
    else if( A.ColDist() == U && A.RowDist() == Partial(V) )
    {
        B.AlignAndResize
        ( A.BlockHeight(), A.BlockWidth(),
          A.ColAlign(), A.RowAlign(), A.ColCut(), A.RowCut(),
          A.Height(), A.Width(), false, false );
        Zeros( B.Matrix(), B.LocalHeight(), B.LocalWidth() );
        AxpyContract( T(1), A, B );
    }
    else if( A.ColDist() == Partial(U) && A.RowDist() == V )
    {
        B.AlignAndResize
        ( A.BlockHeight(), A.BlockWidth(),
          A.ColAlign(), A.RowAlign(), A.ColCut(), A.RowCut(),
          A.Height(), A.Width(), false, false );
        Zeros( B.Matrix(), B.LocalHeight(), B.LocalWidth() );
        AxpyContract( T(1), A, B );
    }
    else if( A.ColDist() == U && A.RowDist() == Collect(V) )
    {
        B.AlignColsAndResize
        ( A.BlockHeight(), A.ColAlign(), A.ColCut(), A.Height(), A.Width(),
          false, false );
        Zeros( B.Matrix(), B.LocalHeight(), B.LocalWidth() );
        AxpyContract( T(1), A, B );
    }
    else if( A.ColDist() == Collect(U) && A.RowDist() == V )
    {
        B.AlignRowsAndResize
        ( A.BlockWidth(), A.RowAlign(), A.RowCut(), A.Height(), A.Width(),
          false, false );
        Zeros( B.Matrix(), B.LocalHeight(), B.LocalWidth() );
        AxpyContract( T(1), A, B );
    }
    else if( A.ColDist() == Collect(U) && A.RowDist() == Collect(V) )
    {
        Zeros( B, A.Height(), A.Width() );
        AxpyContract( T(1), A, B );
    }
    else
        LogicError("Incompatible distributions");
}
コード例 #4
0
ファイル: pcarith.c プロジェクト: robocopone/nq-bg
word	WordPow( word w, int * pn )
{
   expvec ev;
   word ww;
   int n;

   n = * pn;
   if ( n == 0 ) {
      Free( (void *)w );
      return WordGen( 0 );
   }
   if ( n < 0 ) {
      ww = Invert( w );
      Free( (void *)w );
      w = ww;
      n = -n;
   }

   if ( n == 1 )
      return w;

   ev = ExpVecWord( w );
   if ( Collect( ev, w, (exp)(n-1) ) ) {
      Free( (void *)w );
      Free( (void *)ev );
      return (word) 0;
   }

   Free( (void *)w );
   w = WordExpVec( ev );
   Free( (void *)ev );
   return w;
}
コード例 #5
0
ファイル: GC.cpp プロジェクト: scztt/sc-debug
PyrObject *PyrGC::NewFrame(size_t inNumBytes, long inFlags, long inFormat, bool inAccount)
{
	PyrObject *obj = NULL;

#if SANITYCHECK
	SanityCheck();
#endif

	// obtain size info

	int32 alignedSize = (inNumBytes + kAlignMask) & ~kAlignMask; // 16 byte align
	int32 numSlots = alignedSize / sizeof(PyrSlot);
	numSlots = numSlots < 1 ? 1 : numSlots;
	int32 sizeclass = LOG2CEIL(numSlots);
	sizeclass = sc_min(sizeclass, kNumGCSizeClasses-1);

	int32 credit = 1L << sizeclass;
	mAllocTotal += credit;
	mNumAllocs++;
	if (inAccount) {
		mNumToScan += credit;
		if (mNumToScan >= kScanThreshold) {
			Collect();
		}
	}

	GCSet *gcs = mSets + sizeclass;

	obj = (PyrObject*)gcs->mFree;
	if (!IsMarker(obj)) {
		// from free list
		gcs->mFree = obj->next;
	} else {
		if (sizeclass > kMaxPoolSet) {
			SweepBigObjects();
			int32 allocSize = sizeof(PyrObjectHdr) + (sizeof(PyrSlot) << sizeclass);
			obj = (PyrObject*)mPool->Alloc(allocSize);
		} else {
			int32 allocSize = sizeof(PyrObjectHdr) + (sizeof(PyrSlot) << sizeclass);
			obj = (PyrObject*)mNewPool.Alloc(allocSize);
		}
		if (!obj) {
			post("Frame alloc failed. size = %d\n", inNumBytes);
			MEMFAILED;
		}
		DLInsertAfter(&gcs->mWhite, obj);
	}

	obj->obj_sizeclass = sizeclass;
	obj->obj_format = inFormat;
	obj->obj_flags = inFlags;
	obj->size = 0;
	obj->classptr = class_frame;
	obj->gc_color = mWhiteColor;

#if SANITYCHECK
	SanityCheck();
#endif
	return obj;
}
コード例 #6
0
Win32Callstack::Win32Callstack()
{
	bool ret = InitDbgHelp();

	if(ret && renderdocBase != NULL)
		Collect();
}
PyObject *PyAtom::Retrieve(size_t id)
{
    ObjMap::iterator it = objmap.find(id);
    PyObject *ret = it == objmap.end()?NULL:it->second;
    Collect();
    return ret;
}
コード例 #8
0
ファイル: GC.cpp プロジェクト: ASauer/supercollider
PyrObject *PyrGC::NewFinalizer(ObjFuncPtr finalizeFunc, PyrObject *inObject, bool inCollect)
{
	PyrObject *obj = NULL;

#ifdef GC_SANITYCHECK
	SanityCheck();
#endif

	// obtain size info

	int32 sizeclass = 1;

	int32 credit = 1L << sizeclass;
	mNumToScan += credit;
	mAllocTotal += credit;
	mNumAllocs++;

	if (inCollect && mNumToScan >= kScanThreshold) {
		Collect();
	}

	GCSet *gcs = mSets + kFinalizerSet;

	obj = (PyrObject*)gcs->mFree;
	if (!IsMarker(obj)) {
		// from free list
		gcs->mFree = obj->next;
	} else {
		if (sizeclass > kMaxPoolSet) {
			SweepBigObjects();
			int32 allocSize = sizeof(PyrObjectHdr) + (sizeof(PyrSlot) << sizeclass);
			obj = (PyrObject*)mPool->Alloc(allocSize);
		} else {
			int32 allocSize = sizeof(PyrObjectHdr) + (sizeof(PyrSlot) << sizeclass);
			obj = (PyrObject*)mNewPool.Alloc(allocSize);
		}
		if (!obj) {
			post("Finalizer alloc failed.\n");
			MEMFAILED;
		}
		DLInsertAfter(&gcs->mWhite, obj);
	}


	obj->obj_sizeclass = sizeclass;
	obj->obj_format = obj_slot;
	obj->obj_flags = 0;
	obj->size = 2;
	obj->classptr = class_finalizer;
	obj->gc_color = mWhiteColor;

	SetPtr(obj->slots+0, (void*)finalizeFunc);
	SetObject(obj->slots+1, inObject);

#ifdef GC_SANITYCHECK
	SanityCheck();
#endif
	return obj;
}
コード例 #9
0
////////////////
// Thread entry
wxThread::ExitCode FontsCollectorThread::Entry() {
	// Collect
	Collect();
	collector->CloseButton->Enable(true);

	// Return
	if (IsDetached()) Delete();
	return 0;
}
コード例 #10
0
void RadixSort(SLList &L)//基数排序
{
 int i;
    ArrType f,e;//队头指针,队尾                                                                                                                                                                                                                                                       
 for(i=0;i<L.keynum;i++)//进行keynum趟分配,收集
 {
  Distribute(L,i,f,e);//第i趟分配
  Collect(L,i,f,e);//第i趟分收集
 }
}
size_t PyAtom::Register(PyObject *obj)
{
    Collect();

    Py_INCREF(obj);
    objmap[++curix] = obj;

#ifdef _DEBUG
//    post("REG %p (%i)\n",obj,objmap.size());
#endif
    return curix;
}
コード例 #12
0
ファイル: RadixSort.cpp プロジェクト: pengfeifan/JustForTest
void RadixSort(SList *L)
	/*对L进行基数排序,使得L成为按关键字非递减的静态链表,L.r[0]为头结点*/
{ 
	int i;
	addr f,r;
	for(i=0;i<(*L).keynum;i++)			/*由低位到高位依次对各关键字进行分配和收集*/
	{				
		Distribute((*L).data,i,f,r);	/*第i趟分配*/
		Collect((*L).data,f,r);			/*第i趟收集*/
		printf("第%d趟收集后:",i+1);
		PrintList2(*L);
	}
}
コード例 #13
0
ファイル: 81.c プロジェクト: zyxstar/md_note
void RadixSort(SLList *L)
{  int i;
   ArrType f,e;

   for(i=0;i<L->recnum;i++)
   L->r[i].next=i+1;
   L->r[L->recnum].next=0;

   for(i=0;i<L->keynum;i++)
   {   Distribute(L,i,f,e);
       Collect(L,i,f,e);
   }/*end of for */
}/*end of RadixSort() function*/
コード例 #14
0
ファイル: ALGO1017.CPP プロジェクト: PengJi/Data-Structure
void RadixSort(SLList &L) {  // 算法10.17
    // L是采用静态链表表示的顺序表。
    // 对L作基数排序,使得L成为按关键字自小到大的有序静态链表,
    // L.r[0]为头结点。
    int i;
    ArrType f, e;
    for (i=1; i<L.recnum; ++i) L.r[i-1].next = i;
    L.r[L.recnum].next = 0;     // 将L改造为静态链表
    for (i=0; i<L.keynum; ++i) {
        // 按最低位优先依次对各关键字进行分配和收集
        Distribute(L, i, f, e);    // 第i趟分配
        Collect(L, i, f, e);       // 第i趟收集
        print_SLList2(L, i);
    }
} // RadixSort
コード例 #15
0
ファイル: alg10-11.c プロジェクト: beike2020/source
 void RadixSort(SLList *L)
 { /* L是采用静态链表表示的顺序表。对L作基数排序,使得L成为按关键字 */
   /* 自小到大的有序静态链表,L.r[0]为头结点。算法10.17 */
   int i;
   ArrType f,e;
   for(i=0;i<(*L).recnum;++i)
     (*L).r[i].next=i+1;
   (*L).r[(*L).recnum].next=0; /* 将L改造为静态链表 */
   for(i=0;i<(*L).keynum;++i)
   { /* 按最低位优先依次对各关键字进行分配和收集 */
     Distribute((*L).r,i,f,e); /* 第i趟分配 */
     Collect((*L).r,f,e); /* 第i趟收集 */
     printf("第%d趟收集后:\n",i+1);
     printl(*L);
     printf("\n");
   }
 }
コード例 #16
0
 static void RadixSort(SLList &L)
 { // L是采用静态链表表示的顺序表。对L作基数排序,使得L成为按关键字
   // 自小到大的有序静态链表,L.r[0]为头结点。算法10.17
   int i;
   ArrType f,e;
   for(i=0;i<L.recnum;++i)
     L.r[i].next=i+1;
   L.r[L.recnum].next=0; // 将L改造为静态链表
   for(i=0;i<L.keynum;++i)
   { // 按最低位优先依次对各关键字进行分配和收集
     Distribute(L.r,i,f,e); // 第i趟分配
     Collect(L.r,f,e); // 第i趟收集
     printf("第%d趟收集后:\n",i+1);
     printl(L);
     printf("\n");
   }
 }
コード例 #17
0
ファイル: pcarith.c プロジェクト: robocopone/nq-bg
word	WordMult( word u, word w )
{
   expvec ev;

   ev = ExpVecWord( u );
   Free( (void *)u ); 
   if ( Collect( ev, w, (exp)1 ) ) {
      Free( (void *)w );
      Free( (void *)ev );
      return (word)0;
   }

   Free( (void *)w );
   w = WordExpVec( ev );
   Free( (void *)ev );
   return w;
}
コード例 #18
0
ファイル: e11.cpp プロジェクト: cqiyi/kaoshi
void Radixsort() {
	/*对R[0...n-1]进行基数排序,R[i].key为非负整数,且位数不超过KeySize*/
	int i,k;
	for (i=0; i<Radix; i++)
		InitQueue(i);
	for (i=KeySize-1; i>=0; i--) {
		Distribute(i);
		Collect(B);
		if ((KeySize-i)==m) {
			printf("第%d趟的结果是:",m);
			for(k=0; k<n; k++)
				printf("%5d",R[k].key);
			printf("\n");
			printf("请输入还要输出第几趟结果,不想输出时请输入0:");
			scanf("\n%d",&m);
		}
	}
	printf("最终排序结果是:");
	for (k=0; k<n; k++)
		printf("%5d",R[k].key);
	printf("\n");
}/*Radixsort*/
コード例 #19
0
ファイル: pcarith.c プロジェクト: robocopone/nq-bg
word	WordConj( word u, word w )
{
   word uw, x;
   expvec ev;

   /* x = u^w = w^-1 * u * w   <===>   w * x = u * w. */
   ev = ExpVecWord( u );
   Free( (void *)u );

   if ( Collect( ev, w, (exp)1 ) ) {
      Free( (void *)ev );
      Free( (void *)w );
      return (word)0;
   }
   uw = WordExpVec( ev );
   Free( (void *)ev );

   x = Solve( w, uw );
   Free( (void *)w );
   Free( (void *)uw );

   return x;
}
コード例 #20
0
//*****************************************************************
//	更新・描画
//*****************************************************************
void	Event_Mission::Update(void)
{
	if (m_Collect.eventflag) Collect();
	if (m_Stay.eventflag) Stay();
}
コード例 #21
0
void
avtStreamlineInfoQuery::PostExecute()
{
    //Everyone communicate data to proc 0.
#ifdef PARALLEL
    int nProcs = PAR_Size();
    int *counts = new int[nProcs];
    for (int i = 0; i < nProcs; i++)
        counts[i] = 0;
    
    counts[PAR_Rank()] = slData.size();
    Collect(counts, nProcs);
    
    int tag = GetUniqueMessageTag();
    MPI_Status stat;
    if (PAR_Rank() == 0)
    {
        for (int i = 1; i < nProcs; i++)
        {
            if (counts[i] > 0)
            {
                float *vals = new float[counts[i]];
                void *ptr = (void *)&vals[0];
                MPI_Recv(ptr, counts[i], MPI_FLOAT, i, tag, VISIT_MPI_COMM, &stat);

                for (int j = 0; j < counts[i]; j++)
                    slData.push_back(vals[j]);
                delete [] vals;
            }
        }
    }
    else
    {
        if (slData.size() > 0)
        {
            void *ptr = (void *)&slData[0];
            MPI_Send(ptr, slData.size(), MPI_FLOAT, 0, tag, VISIT_MPI_COMM);
        }
    }
    delete [] counts;
#endif
    
    std::string msg;
    char str[128];
    int i = 0, sz = slData.size();

    int slIdx = 0;
    MapNode result_node;
    while (i < sz)
    {
        sprintf(str, "Streamline %d: Seed %f %f %f Arclength %f\n", slIdx, slData[i], slData[i+1], slData[i+2], slData[i+3]);
        MapNode sl_res_node;
        doubleVector sl_res_seed;
        sl_res_seed.push_back(slData[i]);
        sl_res_seed.push_back(slData[i+1]);
        sl_res_seed.push_back(slData[i+2]);
        sl_res_node["seed"] = sl_res_seed;
        sl_res_node["arclength"] = slData[i+3];
        i+=4;
        msg += str;

        if (dumpSteps)
        {
            int numSteps =  (int)slData[i++];
            doubleVector sl_steps;
            for (int j = 0; j < numSteps; j++)
            {
                sprintf(str, " %f %f %f \n", slData[i], slData[i+1], slData[i+2]);// slData[i+3], slData[i+4]);
                sl_steps.push_back(slData[i]);
                sl_steps.push_back(slData[i+1]);
                sl_steps.push_back(slData[i+2]);
                i+=5;
                msg += str;
            }
            sl_res_node["steps"] = sl_steps;
        }
        sprintf(str, "streamline %d", slIdx);
        result_node[str] = sl_res_node;
        slIdx++;
    }

    SetResultMessage(msg.c_str());
    SetXmlResult(result_node.ToXML());
}
コード例 #22
0
ファイル: Query.cpp プロジェクト: czchen/clang-tools-extra
bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
  unsigned MatchCount = 0;

  for (llvm::ArrayRef<ASTUnit *>::iterator I = QS.ASTs.begin(),
                                           E = QS.ASTs.end();
       I != E; ++I) {
    ASTUnit *AST = *I;
    MatchFinder Finder;
    std::vector<BoundNodes> Matches;
    DynTypedMatcher MaybeBoundMatcher = Matcher;
    if (QS.BindRoot) {
      llvm::Optional<DynTypedMatcher> M = Matcher.tryBind("root");
      if (M)
        MaybeBoundMatcher = *M;
    }
    CollectBoundNodes Collect(Matches);
    if (!Finder.addDynamicMatcher(MaybeBoundMatcher, &Collect)) {
      OS << "Not a valid top-level matcher.\n";
      return false;
    }
    Finder.matchAST(AST->getASTContext());

    for (std::vector<BoundNodes>::iterator MI = Matches.begin(),
                                           ME = Matches.end();
         MI != ME; ++MI) {
      OS << "\nMatch #" << ++MatchCount << ":\n\n";

      for (BoundNodes::IDToNodeMap::const_iterator BI = MI->getMap().begin(),
                                                   BE = MI->getMap().end();
           BI != BE; ++BI) {
        switch (QS.OutKind) {
        case OK_Diag: {
          clang::SourceRange R = BI->second.getSourceRange();
          if (R.isValid()) {
            TextDiagnostic TD(OS, AST->getASTContext().getLangOpts(),
                              &AST->getDiagnostics().getDiagnosticOptions());
            TD.emitDiagnostic(
                R.getBegin(), DiagnosticsEngine::Note,
                "\"" + BI->first + "\" binds here",
                ArrayRef<CharSourceRange>(CharSourceRange::getTokenRange(R)),
                ArrayRef<FixItHint>(), &AST->getSourceManager());
          }
          break;
        }
        case OK_Print: {
          OS << "Binding for \"" << BI->first << "\":\n";
          BI->second.print(OS, AST->getASTContext().getPrintingPolicy());
          OS << "\n";
          break;
        }
        case OK_Dump: {
          OS << "Binding for \"" << BI->first << "\":\n";
          BI->second.dump(OS, AST->getSourceManager());
          OS << "\n";
          break;
        }
        }
      }

      if (MI->getMap().empty())
        OS << "No bindings.\n";
    }
  }

  OS << MatchCount << (MatchCount == 1 ? " match.\n" : " matches.\n");
  return true;
}
コード例 #23
0
ファイル: linux_callstack.cpp プロジェクト: qqdiguo/renderdoc
		LinuxCallstack()
		{
			RDCEraseEl(addrs);
			numLevels = 0;
			Collect();
		}
コード例 #24
0
void
avtResampleFilter::ResampleInput(void)
{
    int  i, j, k;

    avtDataset_p output = GetTypedOutput();
    double bounds[6] = { 0, 0, 0, 0, 0, 0 };
    bool is3D = GetBounds(bounds);

    debug4 << "Resampling over space: " << bounds[0] << ", " << bounds[1]
           << ": " << bounds[2] << ", " << bounds[3] << ": " << bounds[4]
           << ", " << bounds[5] << endl;
    
    //
    // Our resampling leaves some invalid values in the data range.  The
    // easiest way to bypass this is to get the data range from the input and
    // pass it along (since resampling does not change it in theory).
    //
    double range[2];
    if (GetInput()->GetInfo().GetAttributes().ValidActiveVariable())
    {
        GetDataExtents(range);
        output->GetInfo().GetAttributes().GetDesiredDataExtents()->Set(range);
    }

    avtViewInfo view;
    double scale[3];
    CreateViewFromBounds(view, bounds, scale);

    //
    // What we want the width, height, and depth to be depends on the
    // attributes.
    //
    int width, height, depth;
    GetDimensions(width, height, depth, bounds, is3D);

    //
    // If there are no variables, then just create the mesh and exit.
    //
    bool thereAreNoVariables = 
          (GetInput()->GetInfo().GetAttributes().GetNumberOfVariables() <= 0);
    if (thereAreNoVariables)
    {
        if (PAR_Rank() == 0)
        {
            vtkRectilinearGrid *rg = CreateGrid(bounds, width, height, depth,
                                      0, width, 0, height, cellCenteredOutput, is3D);
            avtDataTree_p tree = new avtDataTree(rg, 0);
            rg->Delete();
            SetOutputDataTree(tree);
        }
        else
        {
            //
            // Putting in a NULL data tree can lead to seg faults, etc.
            //
            avtDataTree_p dummy = new avtDataTree();
            SetOutputDataTree(dummy);
        }

        return;
    }

    //
    // World space is a right-handed coordinate system.  Image space (as used
    // in the sample point extractor) is a left-handed coordinate system.
    // This is because large X is at the right and large Y is at the top.
    // The z-buffer has the closest points at z=0, so Z is going away from the
    // screen ===> left handed coordinate system.  If we reflect across X,
    // then this will account for the difference between the coordinate 
    // systems.
    //
    scale[0] *= -1.;

    //
    // We don't want an Update to go all the way up the pipeline, so make
    // a terminating source corresponding to our input.
    //
    avtDataset_p ds;
    avtDataObject_p dObj = GetInput();
    CopyTo(ds, dObj);
    avtSourceFromAVTDataset termsrc(ds);

    //
    // The sample point extractor expects everything to be in image space.
    //
    avtWorldSpaceToImageSpaceTransform trans(view, scale);
    trans.SetInput(termsrc.GetOutput());

    bool doKernel = 
        (GetInput()->GetInfo().GetAttributes().GetTopologicalDimension() == 0);
    avtSamplePointExtractor extractor(width, height, depth);
    extractor.SendCellsMode(false);
    extractor.Set3DMode(is3D);
    extractor.SetInput(trans.GetOutput());
    if (doKernel)
        extractor.SetKernelBasedSampling(true);
    avtSamplePoints_p samples = extractor.GetTypedOutput();

    //
    // If the selection this filter exists to create has already been handled,
    // or if there are no pieces for this processor to process, then we can skip
    // execution. But, take care to emulate the same collective
    // calls other processors may make before returning.
    //
    if (GetInput()->GetInfo().GetAttributes().GetSelectionApplied(selID))
    {
        debug1 << "Bypassing Resample operator because database plugin "
                  "claims to have applied the selection already" << endl;

        SetOutputDataTree(GetInputDataTree());

        // we can save a lot of time if we know everyone can bypass
        if (UnifyMaximumValue(0) == 0)
            return;

        // here is some dummied up code to match collective calls below
        int effectiveVars = samples->GetNumberOfRealVariables();
        double *ptrtmp = new double[width*height*depth];
        for (int jj = 0; jj < width*height*depth; jj++)
            ptrtmp[jj] = -FLT_MAX;
        for (i = 0 ; i < effectiveVars ; i++)
            Collect(ptrtmp, width*height*depth);
        delete [] ptrtmp;
        return;
    }
    else
    {
        UnifyMaximumValue(1);
    }

    //
    //
    // PROBLEM SIZED WORK OCCURS BEYOND THIS POINT
    // If you add (or remove) collective calls below this point, make sure to
    // put matching sequence into bypass code above
    //
    //

    avtSamplePointCommunicator communicator;
    avtImagePartition partition(width, height, PAR_Size(), PAR_Rank());
    communicator.SetImagePartition(&partition);
    bool doDistributedResample = false;
#ifdef PARALLEL
    doDistributedResample = atts.GetDistributedResample();
#endif

    if (doDistributedResample)
    {
        partition.SetShouldProduceOverlaps(true);
        avtDataObject_p dob;
        CopyTo(dob, samples);
        communicator.SetInput(dob);
        samples = communicator.GetTypedOutput();
    }

    // Always set up an arbitrator, even if user selected random.
    bool arbLessThan = !atts.GetUseArbitrator() || atts.GetArbitratorLessThan();
    std::string arbName = atts.GetArbitratorVarName();
    if (arbName == "default")
        arbName = primaryVariable;
    extractor.SetUpArbitrator(arbName, arbLessThan);

    //
    // Since this is Execute, forcing an update is okay...
    //
    samples->Update(GetGeneralContract());

    if (samples->GetInfo().GetValidity().HasErrorOccurred())
    {
        GetOutput()->GetInfo().GetValidity().ErrorOccurred();
        GetOutput()->GetInfo().GetValidity().SetErrorMessage(
                          samples->GetInfo().GetValidity().GetErrorMessage());
    }

    //
    // Create a rectilinear dataset that is stretched according to the 
    // original bounds.
    //
    int width_start  = 0;
    int width_end    = width;
    int height_start = 0;
    int height_end   = height;
    if (doDistributedResample)
    {
        partition.GetThisPartition(width_start, width_end, height_start, 
                                   height_end);
        width_end += 1;
        height_end += 1;
    }

    //
    // If we have more processors than domains, we have to handle that
    // gracefully.  Communicate how many variables there are so that those
    // that don't have data can play well.
    //
    int realVars  = samples->GetNumberOfRealVariables();
    int numArrays = realVars;
    if (doKernel)
        numArrays++;
    vtkDataArray **vars = new vtkDataArray*[numArrays];
    for (i = 0 ; i < numArrays ; i++)
    {
        vars[i] = vtkDoubleArray::New();
        if (doKernel && (i == numArrays-1))
            vars[i]->SetNumberOfComponents(1);
        else
        {
            vars[i]->SetNumberOfComponents(samples->GetVariableSize(i));
            vars[i]->SetName(samples->GetVariableName(i).c_str());
        }
    }

    if (doKernel)
        samples->GetVolume()->SetUseKernel(true);

    avtImagePartition *ip = NULL;
    if (doDistributedResample)
        ip = &partition;

    // We want all uncovered regions to get the default value.  That is
    // what the first argument of GetVariables is for.  But if the
    // default value is large, then it will screw up the collect call below,
    // which uses MPI_MAX for an all reduce.  So give uncovered regions very
    // small values now (-FLT_MAX) and then replace them later.
    double defaultPlaceholder = -FLT_MAX;
    samples->GetVolume()->GetVariables(defaultPlaceholder, vars, 
                                       numArrays, ip);

    if (!doDistributedResample)
    {
        //
        // Collect will perform the parallel collection.  Does nothing in
        // serial.  This will only be valid on processor 0.
        //
        for (i = 0 ; i < numArrays ; i++)
        {
            double *ptr = (double *) vars[i]->GetVoidPointer(0);
            Collect(ptr, vars[i]->GetNumberOfComponents()*width*height*depth);
        }
    }
    
    // Now replace the -FLT_MAX's with the default value.  (See comment above.)
    for (i = 0 ; i < numArrays ; i++)
    {
        int numTups = vars[i]->GetNumberOfComponents()
                    * vars[i]->GetNumberOfTuples();
        if (numTups > 0)
        {
            double *ptr = (double *) vars[i]->GetVoidPointer(0);
            for (j = 0 ; j < numTups ; j++)
                ptr[j] = (ptr[j] == defaultPlaceholder 
                                 ? atts.GetDefaultVal() 
                                 : ptr[j]);
        }
    }
   
    bool iHaveData = false;
    if (doDistributedResample)
        iHaveData = true;
    if (PAR_Rank() == 0)
        iHaveData = true;
    if (height_end > height)
        iHaveData = false;
    if (iHaveData)
    {
        vtkRectilinearGrid *rg = CreateGrid(bounds, width, height, depth,
                                        width_start, width_end, height_start,
                                        height_end, cellCenteredOutput, is3D);

        if (doKernel)
        {
            double min_weight = avtPointExtractor::GetMinimumWeightCutoff();
            vtkDataArray *weights = vars[numArrays-1];
            int numVals = weights->GetNumberOfTuples();
            for (i = 0 ; i < realVars ; i++)
            {
                for (j = 0 ; j < vars[i]->GetNumberOfComponents() ; j++)
                {
                    for (k = 0 ; k < numVals ; k++)
                    {
                        double weight = weights->GetTuple1(k);
                        if (weight <= min_weight)
                            vars[i]->SetComponent(k, j, atts.GetDefaultVal());
                        else
                            vars[i]->SetComponent(k, j, 
                                         vars[i]->GetComponent(k, j) / weight);
                    }
                }
            }
        }

        //
        // Attach these variables to our rectilinear grid.
        //
        for (i = 0 ; i < realVars ; i++)
        {
            const char *varname = vars[i]->GetName();
            if (strcmp(varname, primaryVariable) == 0)
            {
                if (vars[i]->GetNumberOfComponents() == 3)
                    if (cellCenteredOutput)
                        rg->GetCellData()->SetVectors(vars[i]);
                    else
                        rg->GetPointData()->SetVectors(vars[i]);
                else if (vars[i]->GetNumberOfComponents() == 1)
                {
                    if (cellCenteredOutput)
                    {
                        rg->GetCellData()->AddArray(vars[i]);
                        rg->GetCellData()->SetScalars(vars[i]);
                    }
                    else
                    {
                        rg->GetPointData()->AddArray(vars[i]);
                        rg->GetPointData()->SetScalars(vars[i]);
                    }
                }
                else
               {
                    if (cellCenteredOutput)
                        rg->GetCellData()->AddArray(vars[i]);
                    else
                        rg->GetPointData()->AddArray(vars[i]);
               }
            }
            else
            {
                if (cellCenteredOutput)
                    rg->GetCellData()->AddArray(vars[i]);
                else
                    rg->GetPointData()->AddArray(vars[i]);
            }
        }

        avtDataTree_p tree = new avtDataTree(rg, 0);
        rg->Delete();
        SetOutputDataTree(tree);
    }
    else
    {
        //
        // Putting in a NULL data tree can lead to seg faults, etc.
        //
        avtDataTree_p dummy = new avtDataTree();
        SetOutputDataTree(dummy);
    }

    for (i = 0 ; i < numArrays ; i++)
    {
        vars[i]->Delete();
    }
    delete [] vars;
}
コード例 #25
0
void ship::Steering()
{
	//static int i = 0;

	if ((*Target).size()-1 == 0)return;

	if (Destination > (int)((*Target).size() - 1))
	{
		Destination = 0;
	}
//	m_TopSpeed = 2.0f;
	float Speed = 0;
	 X = false;
	 Y = false;

	Vector2 TargetVector((*Target)[Destination]->m_x, (*Target)[Destination]->m_y);
	Vector2 V;
	Vector2 Pos(m_x, m_y);
	Vector2 m_force;
	Vector2 Velocity;


	V = Normalize(TargetVector - Pos) * m_TopSpeed ;

	m_force = V - Velocity;
	Velocity = Velocity + m_force;
	Pos = Pos + Velocity;

	m_x = Pos.x;
	m_y = Pos.y;

	m_angle = atan2(Velocity.x,-Velocity.y);
	m_angle *= 180 / (float)M_PI;
	m_angle -= 90;

	if (Pathing == false)
	{
		if (m_x <= (*Target)[Destination]->m_x + 10 && m_x >= (*Target)[Destination]->m_x - 10)
		{
			X = true;
		};

		if (m_y <= (*Target)[Destination]->m_y + 10 && m_y >= (*Target)[Destination]->m_y - 10)
		{
			Y = true;
		};
	}
	else
	{
		if (m_x <= (*Target)[Destination]->m_x + 5 && m_x >= (*Target)[Destination]->m_x - 5)
		{
			X = true;
		};

		if (m_y <= (*Target)[Destination]->m_y + 5 && m_y >= (*Target)[Destination]->m_y - 5)
		{
			Y = true;
		};
	};


	//m_Home = 2;
	if (Pathing == false)
	{
		if (X && Y && Destination == m_Home)
		{
			Idle = true; AtDestination = true;
		}
		else if (X && Y)
		{
			Destination = m_Home; Collect(); AtDestination = true; Hull -= 4;
		};
	}
	else if (Pathing == true)
	{
		while (true)
		{
			if (Path.size() <= 0)
			{

				return;
			}
			
			Destination = Path[0]->Index;

			if (X == true && Y == true)
			{
				Path.erase(Path.begin());
				Destination = Path[0]->Index;
				X = false;
				Y = false;
			}
			else
			{
				break;
			}

		}
	};
}
コード例 #26
0
ファイル: Query.cpp プロジェクト: vmiklos/clang-tools-extra
bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
  unsigned MatchCount = 0;

  for (auto &AST : QS.ASTs) {
    MatchFinder Finder;
    std::vector<BoundNodes> Matches;
    DynTypedMatcher MaybeBoundMatcher = Matcher;
    if (QS.BindRoot) {
      llvm::Optional<DynTypedMatcher> M = Matcher.tryBind("root");
      if (M)
        MaybeBoundMatcher = *M;
    }
    CollectBoundNodes Collect(Matches);
    if (!Finder.addDynamicMatcher(MaybeBoundMatcher, &Collect)) {
      OS << "Not a valid top-level matcher.\n";
      return false;
    }
    Finder.matchAST(AST->getASTContext());

    if (QS.PrintMatcher) {
      std::string prefixText = "Matcher: ";
      OS << "\n  " << prefixText << Source << "\n";
      OS << "  " << std::string(prefixText.size() + Source.size(), '=') << '\n';
    }

    for (auto MI = Matches.begin(), ME = Matches.end(); MI != ME; ++MI) {
      OS << "\nMatch #" << ++MatchCount << ":\n\n";

      for (auto BI = MI->getMap().begin(), BE = MI->getMap().end(); BI != BE;
           ++BI) {
        if (QS.DiagOutput) {
          clang::SourceRange R = BI->second.getSourceRange();
          if (R.isValid()) {
            TextDiagnostic TD(OS, AST->getASTContext().getLangOpts(),
                              &AST->getDiagnostics().getDiagnosticOptions());
            TD.emitDiagnostic(
                FullSourceLoc(R.getBegin(), AST->getSourceManager()),
                DiagnosticsEngine::Note, "\"" + BI->first + "\" binds here",
                CharSourceRange::getTokenRange(R), None);
          }
        }
        if (QS.PrintOutput) {
          OS << "Binding for \"" << BI->first << "\":\n";
          BI->second.print(OS, AST->getASTContext().getPrintingPolicy());
          OS << "\n";
        }
        if (QS.DetailedASTOutput) {
          OS << "Binding for \"" << BI->first << "\":\n";
          BI->second.dump(OS, AST->getSourceManager());
          OS << "\n";
        }
      }

      if (MI->getMap().empty())
        OS << "No bindings.\n";
    }
  }

  OS << MatchCount << (MatchCount == 1 ? " match.\n" : " matches.\n");
  return true;
}
コード例 #27
0
ファイル: GC.cpp プロジェクト: ASauer/supercollider
void PyrGC::Collect(int32 inNumToScan)
{
	mNumToScan = sc_max(mNumToScan, inNumToScan);
	Collect();	// collect space
}
コード例 #28
0
ファイル: GC.cpp プロジェクト: ASauer/supercollider
void PyrGC::FullCollection()
{
	Collect(100000000);	// collect space
	SweepBigObjects();
}