예제 #1
0
 void operator() ( const blocked_range<size_t>& r ) const {
  for ( size_t i = r.begin(); i != r.end(); ++i ) {
   size_t max_size = 0, max_pos = 0;
   for (size_t j = 0; j < str.size(); ++j) 
    if (j != i) {
     size_t limit = str.size()-( i > j ? i : j );
     for (size_t k = 0; k < limit; ++k) {
      if (str[i + k] != str[j + k]) break;
      if (k+1 > max_size) {
       max_size = k+1;
       max_pos = j;
      }
     }
    }
   max_array[i] = max_size;
   pos_array[i] = max_pos;
  }
 }
예제 #2
0
		void operator()( const blocked_range<int>& r ) const {  
			for (int i=r.begin(); i!=r.end(); i++ ){  
				for(int j = 0; j < cols; ++j) {
					const int out_offset = i + (j*rows);
					// For each pixel, do the stencil
					for(int x = i - radius, kx = 0; x <= i + radius; ++x, ++kx) {
						for(int y = j - radius, ky = 0; y <= j + radius; ++y, ++ky) {
							if(x >= 0 && x < rows && y >= 0 && y < cols) {
								const int in_offset = x + (y*rows);
								const int k_offset = kx + (ky*dim);
								out[out_offset].red   += kernel[k_offset] * in[in_offset].red;
								out[out_offset].green += kernel[k_offset] * in[in_offset].green;
								out[out_offset].blue  += kernel[k_offset] * in[in_offset].blue;
							}
						}
					}
				}
			}  
		}  
예제 #3
0
  void operator_3( const blocked_range<size_t>& r ) {   
	double value;
	IntVector indexArray(m_lenArray.size());
	DoubleVector argArray(m_lenArray.size());
    Index1DToArray(r.begin(), m_lenArray, indexArray);

	int nStride0 = m_ControlGridArray[0].strides()[0];
	const char *pBegin0 = (const char*) (m_ControlGridArray[0].array().data());
	const char *pEnd0 = pBegin0 + (nStride0 * m_ControlGridArray[0].size());
	const char *pData0 = pBegin0 + (nStride0 * indexArray[0]);
	int nStride1 = m_ControlGridArray[1].strides()[0];
	const char *pBegin1 = (const char*) (m_ControlGridArray[1].array().data());
	const char *pEnd1 = pBegin1 + (nStride1 * m_ControlGridArray[1].size());
	const char *pData1 = pBegin1 + (nStride1 * indexArray[1]);
	int nStride2 = m_ControlGridArray[2].strides()[0];
	const char *pBegin2 = (const char*) (m_ControlGridArray[2].array().data());
	const char *pEnd2 = pBegin2 + (nStride2 * m_ControlGridArray[2].size());
	const char *pData2 = pBegin2 + (nStride2 * indexArray[2]);
	
    for( size_t index=r.begin(); index!=r.end(); ++index ){
      argArray[0] = * (double*) pData0;
	  argArray[1] = * (double*) pData1;
	  argArray[2] = * (double*) pData2;

  	  value = m_params.objectiveFunction(argArray);	  
      if (value > m_value_of_max) {
        m_value_of_max = value;
		m_argmax = argArray;
      }

	  pData2 += nStride2;
	  if (pData2 == pEnd2) {
	    pData2 = pBegin2;
	    pData1 += nStride1;
		if (pData1 == pEnd1) {
		  pData1 = pBegin1;
		  pData0 += nStride0;
		}
	  }	  
    }
  }
예제 #4
0
    void operator() (const blocked_range<uint64>& r)
    {
        const size_t size = v.size();
        uint64 size2 = size*2;
        for ( uint64 i=r.begin(); i<r.end(); ++i )
        {
            int len = 1;
            uint64 n = i;
            while ( n != 1 )
            {
                if ( n % 2 == 0 )
                {
                    n = n/2;
                    if ( n<size )
                    {
                        const short len1 = -v[size_t(n)];
                        if ( len1 > 0 )
                        {
                            len += len1;
                            break;
                        }
                    }
                    else if ( n<size2 )
                    {
                        const short len1 = v[size_t(n - size)];
                        if ( len1 > 0 )
                        {
                            len += len1;
                            break;
                        }
                    }
                }
                else
                    n = 3*n + 1;

                ++len;
            }
            v[size_t(i - size)] = len;
            updateResult(res, i, len);
        }
    }
예제 #5
0
  void operator_any( const blocked_range<size_t>& r ) {   
    char *pData = NULL;    
	double value, arg;
	unsigned int j;
	IntVector indexArray(m_lenArray.size());
	DoubleVector argArray(m_lenArray.size());
    
    for( size_t index=r.begin(); index!=r.end(); ++index ){
	  Index1DToArray(index, m_lenArray, indexArray);
	  for (j=0; j<indexArray.size(); j++) {
	    //pData = (m_gridPtrArray[j]->data) + (m_gridPtrArray[j]->strides[0] * indexArray[j]);
		pData = ((char*) (m_ControlGridArray[j].array().data())) + (m_ControlGridArray[j].strides()[0] * indexArray[j]);
		arg = * (double*) pData;
		argArray[j] = arg;
	  }
      value = m_params.objectiveFunction(argArray);	  
      if (value > m_value_of_max) {
        m_value_of_max = value;
		m_argmax = argArray;
      }
    }
  }
예제 #6
0
    void operator() (const blocked_range<uint64>& r)
    {
        for ( uint64 i=r.begin(); i<r.end(); ++i )
        {
            int len = 1;
            uint64 n = i;
            while ( n != 1 )
            {
                if ( n % 2 == 0 )
                {
                    n = n/2;
                    if ( n < i && len+prevRes.len < res.len )
                        break;
                }
                else
                    n = 3*n + 1;

                ++len;
            }
            updateResultAndPrev(res, prevRes, i, len);
        }
    }
예제 #7
0
  void operator_1( const blocked_range<size_t>& r ) {   
	double value;
	IntVector indexArray(m_lenArray.size());
	DoubleVector argArray(m_lenArray.size());
    Index1DToArray(r.begin(), m_lenArray, indexArray);
	
	int nStride0 = m_ControlGridArray[0].strides()[0];
	const char *pBegin0 = (const char*) (m_ControlGridArray[0].array().data());
	const char *pEnd0 = pBegin0 + (nStride0 * m_ControlGridArray[0].size());
	const char *pData0 = pBegin0 + (nStride0 * indexArray[0]);
	
    for( size_t index=r.begin(); index!=r.end(); ++index ){
      argArray[0] = * (double*) pData0;

  	  value = m_params.objectiveFunction(argArray);	  
      if (value > m_value_of_max) {
        m_value_of_max = value;
		m_argmax = argArray;
      }
	  
	  pData0 += nStride0;	  
    }
  }
예제 #8
0
			void operator()( const blocked_range<size_t> &r ) const
			{
				for ( size_t i = r.begin(); i != r.end(); ++i )
				{
					for ( size_t j = 0; j < 1000; j++ )
					{
						if ( ( i + j ) % 7 == 0 )
						{
							SharedSceneInterfaces::clear();
						}

						ConstSceneInterfacePtr scene = SharedSceneInterfaces::get("test/IECore/data/sccFiles/attributeAtRoot.scc");

						try 
						{
							scene->readAttribute( m_attribute, 0 );
						}
						catch( Exception &e )
						{
							m_errors++;
						}
					}
				}
			}
예제 #9
0
// Note: parallel_tracks_vector should have n items allocated already.
void TBBSearchByPair::operator() (const blocked_range<int>& r) const{
  for (int i = r.begin(); i != r.end(); ++i) {
    searchByPair(i, parallel_tracks_vector[i]);
  }
}
예제 #10
0
파일: first.cpp 프로젝트: migal-drew/TBB
 void operator()( const blocked_range<int>& range ) const {
     for( int i=range.begin(); i!=range.end(); ++i ) {
         output[i] = (input[i-1]+input[i]+input[i+1])*(1/3.f);
         cout << output[i] << ' ';
     }
 }
예제 #11
0
 //! iterate thorough range
 void operator()( const blocked_range<int> &range ) const {
     int i_end = range.end();
     for( int i = range.begin(); i != i_end; ++i ) {
         my_stream.Queue.push( Matrix1110 ); // push initial matrix
     }
 }
예제 #12
0
파일: main.cpp 프로젝트: bcfehrman/school
 void operator() ( const blocked_range<int>& r ) const {
   for ( int i = r.begin(); i != r.end(); i++ ) { // iterates over the entire chunk
     p_array_sum[i] = p_array_a[i] + p_array_b[i];
   }
 }
예제 #13
0
 void operator()( const blocked_range<int> &r, T) {
     // see tag.is_final_scan() for what tag is used
     for( int k = r.begin() + first; k < r.end(); ++k )
         sum = sum * Matrix1110;
     first = 0; // reset flag, because this method can be reused for next range
 }
예제 #14
0
 //! Process multiplications
 void operator()( const blocked_range<int> &r ) {
     for( int k = r.begin() + splitted; k < r.end(); ++k )
         sum = sum * Matrix1110;
     splitted = 0; // reset flag, because this method can be reused for next range
 }
예제 #15
0
 void operator() (blocked_range<size_t>& r) const {
     for (size_t i=r.begin(); i!=r.end(); ++i) {
         f_distance[i] = g_distance[i] = INF;
         predecessor[i] = N;
     }
 }
예제 #16
0
파일: TBBCode.cpp 프로젝트: Chalenko/PCM
		void operator()(const blocked_range<int>& r) const{
			int begin = r.begin(), end = r.end();
			for (int i = begin; i < end; i++){
				dst[i] = value;
			}
		}
예제 #17
0
 // the blocked_range<T> is a template class provided by the library
 // it describes a one-dimensional iteration space over type T
 void operator()(const blocked_range<size_t>& r) const
 {
     float* a = my_a;
     for (size_t i = r.begin(); i < r.end(); i++)
         foo(a[i]);
 }
예제 #18
0
		void operator()(const blocked_range<uint>& r) const {
			for(uint i=r.begin(); i!=r.end(); ++i) {
				c->buckets[i].clear();
			}
		}
예제 #19
0
 void operator()( const blocked_range<int>& range ) {
     for( int j=range.begin(); j!=range.end(); ++j ) 
         sum += my_a[j]*my_b[i-j];
 }
예제 #20
0
파일: TBBCode.cpp 프로젝트: Chalenko/PCM
		void operator()(const blocked_range<int>& r) const{
			int begin = r.begin(), end = r.end();
			for (int i = begin; i < end; i++){
				TransposeCol(src, &dst[i * wN], i, wN, hN);
			}
		}
예제 #21
0
파일: TBBCode.cpp 프로젝트: Chalenko/PCM
		void operator()(const blocked_range<int>& r) const{
			int begin = r.begin(), end = r.end();
			for (int i = begin; i < end; i++){
				result[i] += vector[i] ;
			}
		}
	//LOOPC-STYLE:
	void operator()(blocked_range<int> range) const
	{
		for(int iblock=range.begin(); iblock<range.end(); iblock++)
		{
			
			const BlockInfo info = destblocks[iblock];
			assert(destblocks[iblock].ptrBlock != NULL);
			VelocityBlock& my_b = *(VelocityBlock*)destblocks[iblock].ptrBlock;
			
			HCFMM::BoxIterator<tBox,tbb::scalable_allocator> it1(rootNode);
			
			tBox* current;
			bool canRemove;
			
			//clean velocity field:
			my_b.clear();
			
			while(it1!=NULL && (it1->nParticles>0))
			{
				canRemove=true;
				current=it1;
				
				const bool is_close = _isclose_box(current, info, _THETA);
				
				if(!is_close && current->parent!=NULL)
				{
					const bool parent_is_close = _isclose_box(current->parent, info, _THETA);
					
					if(parent_is_close) //if we were already well separated from parent, we should skipt this.

							for(int iy=0; iy<B::sizeY; iy++)
								for(int ix=0; ix<B::sizeX; ix++)
								{
									Real target_pos[2] = {0,0};
									info.pos(target_pos, ix, iy);
									
									if(current->parent==NULL || !(ws_barnes_hut(current->parent, target_pos, _THETA)))
									{
										VelocityRHS rhs;
										
										it1->expansions.evaluateExpansions(target_pos, &rhs);
										
										my_b.u[0][iy][ix] += rhs.x[0];
										my_b.u[1][iy][ix] += rhs.x[1];

										measurements.num_indirect_evals[iblock] += 1;
									}
								}
				}
				else  
				{
					//treat each point separately
						for(int iy=0; iy<B::sizeY; iy++)
							for(int ix=0; ix<B::sizeX; ix++)
							{
								Real target_pos[2] = {0,0};
								info.pos(target_pos,ix,iy);
								
								if(current->parent==NULL || !(ws_barnes_hut(current->parent, target_pos, _THETA))) 
								{	
									//when we were already well separated from the parent, we should not further interact.
									if (ws_barnes_hut(current, target_pos, _THETA))
									{
										measurements.num_indirect_evals[iblock] += 1;

										VelocityRHS rhs;
										
										it1->expansions.evaluateExpansions(target_pos, &rhs);
										
										my_b.u[0][iy][ix] += rhs.x[0];
										my_b.u[1][iy][ix] += rhs.x[1];
									}
									else
									{
										if(!it1->isleaf) 
											//Case 2: its not a leaf so we further traverse into the tree (summing up the children and bailing out)
											canRemove=false;
										else  //its close and a leaf ->interactDirectly with particles
										{
											Real u[2] = {0,0};
											
											const int nof_sources = current->nParticles;
											const VelocitySourceParticle * const p = current->vparticles;
											
											measurements.num_direct_evals[iblock] += nof_sources;

											if (_is_intersecting(*current, info)) //tBox current and this block are intersecting
												for (int i=0;i<nof_sources;++i)
												{
													Real r[2] = {
														target_pos[0] - p[i].x[0],
														target_pos[1] - p[i].x[1]
													};
													
													const Real distance_2 = r[0]*r[0] + r[1]*r[1];
													
													if (distance_2==0) continue;
													
													const Real factor = 1/distance_2;
													
													u[0] -= factor*p[i].w[0]*r[1];
													u[1] += factor*p[i].w[0]*r[0];
												}												
											else
												for (int i=0;i<nof_sources;++i)
												{
													Real r[2] = {
														target_pos[0] - p[i].x[0],
														target_pos[1] - p[i].x[1]
													};
													
													const Real factor = 1/(r[0]*r[0] + r[1]*r[1]);
													
													u[0] -= factor*p[i].w[0]*r[1];
													u[1] += factor*p[i].w[0]*r[0];
												}													
											
											assert(!isnan(u[0]));
											assert(!isnan(u[1]));
											
											my_b.u[0][iy][ix] += u[0];
											my_b.u[1][iy][ix] += u[1];
										}
									} 
								}
							}
				}
				
				if(canRemove)
					it1.advanceRemove();
				else
					it1++;
			}
			
			//multiply by scaling factor
			{
				Real * const ue = (Real *)my_b.u[0];
				Real * const ve = (Real *)my_b.u[1];
				const Real scale = 1./(2.0*M_PI)*inv_scaling;
				static const int n = FluidBlock2D::sizeY*FluidBlock2D::sizeX;
				for(int i=0; i<n; i++) 
				{
					ue[i] *= scale;
					ve[i] *= scale;
				}
			}
#ifndef _FMMSILENT
			printf("Done with %d %d %d l=%d\n", info.index[0], info.index[1], info.index[2], info.level);
#endif
		}
		
	}
예제 #23
0
파일: TBBCode.cpp 프로젝트: Chalenko/PCM
		void operator()(const blocked_range<int>& r){
			int begin = r.begin(), end = r.end();
			for (int i = begin; i < end; i++){
				c += a[i];
			}
		}
예제 #24
0
 void operator() ( const blocked_range<int>& range ) const {
    for ( int i = range.begin(); i!=range.end(); ++i){
       output[i]=i;
    }
 }
예제 #25
0
파일: TBBCode.cpp 프로젝트: Chalenko/PCM
		void operator()(const blocked_range<int>& r){
			int begin = r.begin();
			int end = r.end();
			c += TBBSclMlt(&(a[begin]), &(b[begin]), (end - begin));
		}
예제 #26
0
파일: tbb.cpp 프로젝트: xiazemin/openMP
	void operator () (const blocked_range<size_t> & r) const
	{
		float * a = my_a;
		for (size_t i = r.begin(); i != r.end(); ++ i)
			printf("%.2f\n ",my_a[i]);//Foo(a[i]);
	}
예제 #27
0
파일: main.cpp 프로젝트: irvingnor/TPCD
 void operator()( const blocked_range<int>& range ) const {
     for( int i=range.begin(); i!=range.end(); ++i )
         nAdverbios1[list1[i].getTipo()-1] += dFile1[list1[i].getAdverbio()];
 }
예제 #28
0
 void operator()( const blocked_range<int>& r ) const {  
     for (int i=r.begin(); i!=r.end(); i++ ){  
         printf("Alien #%d says hello, they're #%d in line.\n",pthread_self(),i);
     }  
 }  
예제 #29
0
 void operator() (blocked_range<size_t>& r) const {
     utility::FastRandom my_random((unsigned int)r.begin());
     for (size_t i=r.begin(); i!=r.end(); ++i) {
         vertices[i] = generate_random_point(my_random);
     }
 }