int find(TreeNode* node, TreeNode* target, int k, vector<int>& v) {
        if (node == nullptr) {
            return -1;
        }

        if (node == target) {
            gather(node, k, v);
            return 0;
        }
        else {
            int distance = find(node->left, target, k, v);
            if (distance != -1) {
                distance++;
                if (distance == k) {
                    v.push_back(node->val);
                }
                gather(node->right, k - distance - 1, v);
            }
            else {
                distance = find(node->right, target, k, v);
                if (distance != -1) {
                    distance++;
                    if (distance == k) {
                        v.push_back(node->val);
                    }
                    gather(node->left, k - distance - 1, v);
                }
            }
            return distance;
        }
    }
    void gather(TreeNode* node, int remainingDistance, vector<int>& v) {
        if (node == nullptr) {
            return;
        }

        if (remainingDistance == 0) {
            v.push_back(node->val);
        }
        else if (remainingDistance > 0) {
            gather(node->left, remainingDistance - 1, v);
            gather(node->right, remainingDistance - 1, v);
        }
    }
Exemple #3
0
ens_rc_t EnsTcpSendIovecl(ens_sock_t s,
                          int len1, char *buf1,
                          int len2, char *buf2,
                          int len3, char *buf3)
{
    int nvecs = 0;
    int total_len = len1 + len2 + len3;
    int ret = 0, len=0;
    
    EnsTrace(NAME,"tcpsend_iovecl: %d %d %d", len1, len2, len3);
    if (len3>0) nvecs =3;
    else nvecs=2;
    gather(send_iova, len1, buf1, len2, buf2, len3, buf3);
        
#ifndef _WIN32
    send_msghdr.msg_iovlen = nvecs;
    ret = sendmsg(s, &send_msghdr, 0) ;
    if (-1 == ret)
        return ENS_ERROR;
    if (ret != total_len) EnsPanic("Error, did not send everything");
#else
    ret = WSASend(s, send_iova, nvecs, &len, 0, NULL, NULL);

    if (SOCKET_ERROR == ret)
        return ENS_ERROR;        
    if (len != total_len) EnsPanic("Error, did not send everything");
#endif
    
    return ENS_OK;
}
Exemple #4
0
int main (int argc, char const * argv []) 

{
	byte buffer [256];
	char string [] = 
	{
		"Hello World"
	};
	unsigned number = 0x12345678;
	struct field fields [] = 
	{
		{
			0,
			string,
			sizeof (string)
		},
		{
			0,
			&number,
			sizeof (number)
		},
		{
			1,
			&number,
			sizeof (number)
		}
	};
	memset (buffer, 0, sizeof (buffer));
	gather (buffer, sizeof (buffer), fields, SIZEOF (fields));
	hexdump (buffer, 0, sizeof (buffer), stdout);
	return (0);
}
Exemple #5
0
void bfmcommIroIro<Float>::comm_start  (int result_cb, Fermion_t psi,int dag)  
{
  // gather the faces. Routines here are threaded.
  // All threads cooperate in gathering.

  int me = this->thread_barrier();
  if ( me == 0 ) {
    recv_init((Fermion_t)psi);
  }
  this->thread_barrier();

  gather (result_cb,psi,dag);

  this->thread_barrier();
  if ( me == 0 ) {

    // Slow initial implementation 
    // Ideally insert BGNET calls and exit here after the BGNET_Put starts 
    // running asynchronously.
    for(int mu=0;mu<4;mu++){
      int simd_factor = this->simd();
      simd_factor = simd_factor/this->simd_grid[mu];
      int words  = this->simd_nbound[mu] * HALF_SPINOR_SIZE * simd_factor * this->cbLs;
      int idx=2*mu;
      int idxp=2*mu+1;
      Communicator::instance()->transfer_bk((double *)this->simd_rbuf[idx],(double *)this->sendbufs[idx],words,mu);
      Communicator::instance()->transfer_fw((double *)this->simd_rbuf[idxp],(double *)this->sendbufs[idxp],words,mu);
    }
  }
  this->thread_barrier();

  return;
}
Exemple #6
0
void
Stokhos::SmolyakPseudoSpectralOperator<ordinal_type,value_type,point_compare_type>::
transformPCE2QP_smolyak(
  const value_type& alpha, 
  const Teuchos::SerialDenseMatrix<ordinal_type,value_type>& input,
  Teuchos::SerialDenseMatrix<ordinal_type,value_type>& result, 
  const value_type& beta,
  bool trans) const {
  Teuchos::SerialDenseMatrix<ordinal_type,value_type> op_input, op_result;
  result.scale(beta);

  for (ordinal_type i=0; i<operators.size(); i++) {
    Teuchos::RCP<operator_type> op = operators[i];
    if (trans) {
      op_input.reshape(input.numRows(), op->coeff_size());
      op_result.reshape(result.numRows(), op->point_size());
    }
    else {
      op_input.reshape(op->coeff_size(), input.numCols());
      op_result.reshape(op->point_size(), result.numCols());
    }
    
    gather(scatter_maps[i], input, trans, op_input);
    op->transformPCE2QP(smolyak_coeffs[i], op_input, op_result, 0.0, trans);
    scatter(gather_maps[i], op_result, trans, result);
  }
}
void CMTSumCheckVerifier::
requestPoly(MPZVector& poly, const mpz_t rand)
{
  MPZVector r(1);
  r.set(0, rand);
  broadcastZVector(CMTCommConsts::REQ_SC_POLY, r);
  gather(poly, CMTCommConsts::REQ_SC_POLY);
}
Hierarchies get_by_type(Hierarchy mhd,
                        GetByType t)
{
  Hierarchies out;
  gather(mhd, MHDMatchingType(t),
         std::back_inserter(out));
  return out;
}
Exemple #9
0
/*}}}*/
static void do_tile(int I, int J, struct node *cursor, struct tower_table *table, FILE *out)/*{{{*/
{
    struct micro sub[16][16];
    /* Clear the array */
    clear_sub(sub);

    gather(4, 0, 0, cursor, sub);
    render(I, J, cursor, sub, table, out);
}
int main(int argc, char* argv[])
{
  mpi::environment env(argc, argv);
  mpi::communicator world;

  std::srand(time(0) + world.rank());
  int my_number = std::rand();
  if (world.rank() == 0) {
    std::vector<int> all_numbers;
    gather(world, my_number, all_numbers, 0);
    for (int proc = 0; proc < world.size(); ++proc)
      std::cout << "Process #" << proc << " thought of "
                << all_numbers[proc] << std::endl;
  } else {
    gather(world, my_number, 0);
  }

  return 0;
}
Exemple #11
0
void
Master::step(const std::vector<unsigned>& fstim)
{
	m_timer.step();

#ifdef NEMO_MPI_DEBUG_TIMING
	m_mpiTimer.reset();
#endif

	unsigned wcount = workers();

	std::vector<SimulationStep> oreqData(wcount);
	std::vector<boost::mpi::request> oreqs(wcount);

	distributeFiringStimulus(m_mapper, fstim, oreqData);
#ifdef NEMO_MPI_DEBUG_TIMING
	m_mpiTimer.substep();
#endif

	for(unsigned r=0; r < wcount; ++r) {
		oreqs.at(r) = m_world.isend(r+1, MASTER_STEP, oreqData.at(r));
	}
#ifdef NEMO_MPI_DEBUG_TIMING
	m_mpiTimer.substep();
#endif

	boost::mpi::wait_all(oreqs.begin(), oreqs.end());
#ifdef NEMO_MPI_DEBUG_TIMING
	m_mpiTimer.substep();
#endif

	m_firing.push_back(std::vector<unsigned>());

	std::vector<unsigned> dummy_fired;
	std::vector< std::vector<unsigned> > fired;
	gather(m_world, dummy_fired, fired, MASTER);

	/* If neurons are allocated to nodes ordered by neuron index, we can get a
	 * sorted list by just concatening the per-node lists in rank order */
	for(unsigned r=0; r < wcount; ++r) {
		const std::vector<unsigned>& node_fired = fired.at(r+1);
		std::copy(node_fired.begin(), node_fired.end(), std::back_inserter(m_firing.back()));
#ifdef NEMO_MPI_DEBUG_TRACE
		MPI_LOG("Master received %u firings from %u\n", node_fired.size(), r+1);
#endif
	}

#ifdef NEMO_MPI_DEBUG_TRACE
	std::copy(m_firing.back().begin(), m_firing.back().end(), std::ostream_iterator<unsigned>(std::cout, " "));
#endif
#ifdef NEMO_MPI_DEBUG_TIMING
	m_mpiTimer.substep();
	m_mpiTimer.step();
#endif
}
void GatherWorkspaces::execEvent() {

  // Every process in an MPI job must hit this next line or everything hangs!
  mpi::communicator included; // The communicator containing all processes
  // The root process needs to create a workspace of the appropriate size
  EventWorkspace_sptr outputWorkspace;
  if (included.rank() == 0) {
    g_log.debug() << "Total number of spectra is " << totalSpec << "\n";
    // Create the workspace for the output
    outputWorkspace = boost::dynamic_pointer_cast<EventWorkspace>(
        API::WorkspaceFactory::Instance().create("EventWorkspace", sumSpec,
                                                 numBins + hist, numBins));
    // Copy geometry over.
    API::WorkspaceFactory::Instance().initializeFromParent(
        eventW, outputWorkspace, true);
    setProperty("OutputWorkspace", outputWorkspace);
    ExperimentInfo_sptr inWS = inputWorkspace;
    outputWorkspace->copyExperimentInfoFrom(inWS.get());
  }

  for (size_t wi = 0; wi < totalSpec; wi++) {
    if (included.rank() == 0) {
      // How do we accumulate the data?
      std::string accum = this->getPropertyValue("AccumulationMethod");
      std::vector<Mantid::DataObjects::EventList> out_values;
      gather(included, eventW->getEventList(wi), out_values, 0);
      for (int i = 0; i < included.size(); i++) {
        size_t index = wi; // accum == "Add"
        if (accum == "Append")
          index = wi + i * totalSpec;
        outputWorkspace->dataX(index) = eventW->readX(wi);
        outputWorkspace->getOrAddEventList(index) += out_values[i];
        const ISpectrum *inSpec = eventW->getSpectrum(wi);
        ISpectrum *outSpec = outputWorkspace->getSpectrum(index);
        outSpec->clearDetectorIDs();
        outSpec->addDetectorIDs(inSpec->getDetectorIDs());
      }
    } else {
      gather(included, eventW->getEventList(wi), 0);
    }
  }
}
Exemple #13
0
int main(int argc, char* argv[])
#endif
{
	char *s, buf[1500];
	int fd;
	FILE* f;
	long pos = 0;
	struct ifreq interface;

	memset(&interface, 0, sizeof(interface));
	interface.ifr_addr.sa_family = AF_INET;
	if(argc > 1)
		strcpy(interface.ifr_name, argv[1]);
	else
		strcpy(interface.ifr_name, "eth0");

	scache_init(&statistic, 20, free);
	get_actual_ifaces(&argc, argv);

	if(xap_init(argc, argv, 0) != 1) {
		fprintf(stderr, "error while initializing xAP\n");
		scache_free(&statistic);
		return -1;
	}

	if(ioctl(g_xap_sender_sockfd, SIOCGIFADDR, &interface) != 0) {
		printf("error while determining address\n");
		exit(-1);
	} else {
		sprintf(buf, "src\n{\naddr=%s\n}\n", inet_ntoa(((struct sockaddr_in*)(&interface.ifr_addr))->sin_addr));
		s = buf + strlen(buf);
	}

	fd = open("/proc/net/dev", O_ASYNC | O_NONBLOCK);
	fcntl(fd, F_SETFL, O_ASYNC);
	f = fdopen(fd, "r");

	s = fgets(s, 1400, f);
	s = fgets(s, 1400, f);
	pos = ftell(f);

	while(1) {
		xap_heartbeat_tick(HBEAT_INTERVAL);
		gather(f, s);

		xap_send_message(buf);
		sleep(1);
		fseek(f, pos, SEEK_SET);
	}

	scache_free(&statistic);
	return 0;
}
Exemple #14
0
TEST_F(TestIRStmt, TestGatherStmt)
{
    IRTypes types;
    IRStmt* condStmt = MakeBlock(&types);
    IRValue* category = new IRStringConst("illuminance");
    IRGlobalVar pos("P", types.GetPointTy(), kIRVarying, NULL, false);
    IRValues args;
    args.push_back(&pos);
    IRStmt* body = MakeBlock(&types, true);
    IRStmt* elseStmt = MakeBlock(&types);
    IRGatherLoop gather(category, args, body, elseStmt, IRPos());
    std::cout << gather;
}
Exemple #15
0
int main(int argc, char **argv){

    if(data_size * 8 > 4096){
        coarray_init(2*4*data_size, argc, argv);
    } else {
        coarray_init(4096,argc, argv);
    }

    local_array<int> gather_result(num_images() * data_size);
    coarray<int, 1> source(dims{data_size});//parenthesis do not work here
    coarray<int, 1> scatter_result(dims{data_size});

    for( int i = 0; i < data_size; i++ ) {
        source[i] = data_size * this_image() + i;
    }
    print(source);

    gather(gather_result, source);

    if(this_image() == 0) {
        cout << "Gather result:" << endl;
        for(int i = 0; i < num_images() * data_size; i++) {
            cout << gather_result[i] << ", ";
            gather_result[i]++;// = gather_result[i] + 1;
        }
        cout << endl;

        scatter(gather_result, scatter_result);

    }
    sync_all();
    for(int i = 0; i < num_images(); i++) {
        if(this_image() != i) {
            cout << "scatter result(" << this_image() << "): ";
            for(int i = 0; i < data_size; i++)
                cout << scatter_result[i] << ", ";
            cout << endl;
        }
    }

    sync_all();

    if(this_image() == 0) {
        collect(gather_result, scatter_result);
        cout << "collect result:" << endl;
        for(int i = 0; i < data_size; i++)
            cout << scatter_result[i] << ", ";
        cout << endl;
    }
}
_NAMESPACE_BEGIN

GearsMeshBuilder::GearsMeshBuilder( KeyValueIni *ini,const char *meshName,const void *data,
								   uint32 dlen, MeshImporter *mi,const char *options,
								   MeshImportApplicationResource *appResource )
{
	mINI = ini;
	mCurrentMesh = 0;
	mCurrentCollision = 0;
	mAppResource = appResource;
	importAssetName(meshName,0);
	mi->importMesh(meshName,data,dlen,this,options,appResource);
	gather();
}
Exemple #17
0
Fichier : tcs3.c Projet : rc0/cstum
/*}}}*/
static void inner_get_ranges(struct node *cursor,/*{{{*/
    struct tower_table *table,
    int level, int I, int J,
    struct tower_data *data)
{
  if (level == THE_LEVEL) {
    if (cursor->d) {
      gather(2, cursor->d, table, I, J, data);
      gather(3, cursor->d, table, I, J, data);
    }

  } else {
    int i, j;
    for (i=0; i<2; i++) {
      for (j=0; j<2; j++) {
        if (cursor->c[i][j]) {
          inner_get_ranges(cursor->c[i][j], table, level + 1, (I<<1)+i, (J<<1)+j, data);
        }
      }
    }
  }

}
Exemple #18
0
void add(char x1[], char x2[], char result[]) {
    char man1[23] = {(char)0};
    char man2[23] = {(char)0};
    char resMan[23] = {(char)0};
    char resExp[8] = {(char)0};
    char tmpExp[8] = {(char)0};
    int exp1, exp2, i;

    // Split the result
    split(result, resMan, resExp);

    // Split x1, get exp1
    split(x1, man1, tmpExp);
    exp1 = bin2dec(tmpExp);

    // Split x2, get exp2
    split(x2, man2, tmpExp);
    exp2 = bin2dec(tmpExp);

    // Align the two mantissas
    int bigExp = align(exp1, man1, exp2, man2);

    // Write the result exponent
    dec2bin(bigExp, resExp);

    // Add the mantissas 
    int tmp = 0;
    int rem = 0;
    for (i = 22; i >= 0; i--) {
        tmp = (int) man1[i] + (int) man2[i] + rem;
        if (tmp == 3) {
            rem = 1;
            resMan[i] = (char) 1;
        } else if (tmp == 2) {
            rem = 1;
            resMan[i] = (char) 0;
        } else if (tmp == 1) {
            rem = 0;
            resMan[i] = (char) 1;
        } else if (tmp == 0) {
            rem = 0;
            resMan[i] = (char) 0;
        }
    }

    // Gather the result
    result[0] = (char) 0; // Assuming always positive, as per the hw document
    gather(resMan, resExp, result);
}
Exemple #19
0
double aliquot (struct face *fac, int atom_number)
{
	int i, n_numbers;
	int atom_numbers[MAXPA];
	double area_quot;

	n_numbers = gather (fac, atom_numbers); 
	if (error()) return ((double) 0.0);
	if (n_numbers <= 0) return ((double) 0.0);
	area_quot = fac -> area / n_numbers;
	for (i = 0; i < n_numbers; i++)
		if (atom_number == atom_numbers[i])
			return (area_quot);
	return ((double) 0.0);
}
Exemple #20
0
int main(int argc, char *argv[]){    
	const int tmax=atoi(argv[1]); /* number of simulation rounds */
	const int gran=atoi(argv[2]); /* granularity */
	const char *pName=argv[3]; /* bodies file name */
	double time, time1, time2, time3; /* total, scatter, simulate, and gather running times */ 
	int rank, size; /* rank of process, number of processes */
	
	MPI_Init(&argc, &argv);
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
	MPI_Comm_size(MPI_COMM_WORLD, &size);

	body *bodies = (body *) malloc(gran*sizeof(body));

	time = MPI_Wtime();
	/****************************************************************
	1. Scatter:
	Reading the input from file and assigning each line to a process
	****************************************************************/
	time1 = MPI_Wtime();
	scatter(pName, rank, size, gran, bodies);
	time1 = MPI_Wtime() - time1;
	if(rank==0) printf("Scatter time is %.4f seconds\n", time1);	
	/****************************************************************
	2. Simulate:
	Passing the data of each process to other processes and simulate
	****************************************************************/
	time2 = MPI_Wtime();
	simulate(tmax, rank, size, gran, bodies);
	time2 = MPI_Wtime() - time2;
	if(rank==0) printf("Simulate time is %.4f seconds\n", time2);	
	/****************************************************************
	3. Gather:
	Writing the the last positions to "peval_out.txt" 
	****************************************************************/
	time3 = MPI_Wtime();
	gather(rank, size, gran, bodies);
	time3 = MPI_Wtime() - time3;
	if(rank==0) printf("Gather time is %.4f seconds\n", time3);	
	
	/* Finalizing */
	free(bodies);
	time = MPI_Wtime() - time;
	if(rank==0) printf("Computation time is %.4f seconds\n", time);	
	MPI_Finalize();
	return(0);
}
Exemple #21
0
// Find the maximum wave speed on the current level
Real OldLevelGodunov::getMaxWaveSpeed(const LevelData<FArrayBox>& a_U)
{
  const DisjointBoxLayout& disjointBoxLayout = a_U.disjointBoxLayout();
  DataIterator dit = disjointBoxLayout.dataIterator();

  // Initial maximum wave speed
  Real speed = 0.0;

  // This computation doesn't need involve a time but the time being set
  // is checked by OldPatchGodunov::getMaxWaveSpeed so we have to set it
  // to something...
  m_patchGodunov->setCurrentTime(0.0);

  // Loop over all grids to get the maximum wave speed
  for (dit.begin(); dit.ok(); ++dit)
    {
      const Box& currentBox = disjointBoxLayout.get(dit());

      // Set the current box and get the maximum wave speed on the current grid
      m_patchGodunov->setCurrentBox(currentBox);
      Real speedOverBox = m_patchGodunov->getMaxWaveSpeed(a_U[dit()],
                                                          currentBox);

      // Compute a running maximum
      speed = Max(speed,speedOverBox);
    }

  // Gather maximum wave speeds and broadcast the maximum over these
  Vector<Real> allSpeeds;

  gather(allSpeeds,speed,uniqueProc(SerialTask::compute));

  if (procID() == uniqueProc(SerialTask::compute))
    {
      speed = allSpeeds[0];
      for (int i = 1; i < allSpeeds.size (); ++i)
        {
          speed = Max(speed,allSpeeds[i]);
        }
    }

  broadcast(speed,uniqueProc(SerialTask::compute));

  // Return the maximum wave speed
  return speed;
}
Exemple #22
0
/*}}}*/
static void gather(int to_go, int I, int J, struct node *cursor, struct micro sub[16][16])/*{{{*/
{
    int i;
    int j;
    if (to_go > 0) {
        for (i=0; i<2; i++) {
            for (j=0; j<2; j++) {
                if (cursor->c[i][j]) {
                    gather(to_go - 1, (I<<1)+i, (J<<1)+j, cursor->c[i][j], sub);
                }
            }
        }
    } else {
        /* Process this 1/16 x 1/16 block */
        do_fragment(cursor->d, &sub[I][J]);
    }
}
Exemple #23
0
void convert(double x, char mantissa_exponent[]) {
    int i;
    char mantissa[23] = {(char)0};
    char exponent[8] = {(char)0};

    // Calculate sign bit first
    if (x < 0) {
        mantissa_exponent[0] = 1;
        x *= -1;
    } else
        mantissa_exponent[0] = 0;
    
    // Seperate the decimal and fractional parts
    int decPart = (int) x;
    double fracPart = x - decPart;

    // Conver the decimal part to binary, put it at the end of the array
    for (i = 0; decPart >= 1; i++) {
        mantissa[22-i] = (char) (decPart % 2);
        decPart = decPart / 2;
    }
    i--;
    int exp = i;

    // Shift mantissa to left 22-exp
    shiftl(mantissa, 22-exp);

    // Put exponent in mantissa_exponent array
    dec2bin(exp, exponent);

    // Deal with fractional part
    if (fracPart != 0.0) {
        i = exp+1; // Current position in mantissa
        for (; i < 32; i++) {
            fracPart = fracPart * 2;
            mantissa[i] = (char) ((int)fracPart);
            fracPart -= (int)fracPart;
        }
    }

    // Gather result
    gather(mantissa, exponent, mantissa_exponent);
}
inline void gatherResultstoProcZero(MPI_Comm comm, SearchResults& boxIdPairResults)
{
    int procId=-1;
    MPI_Comm_rank(comm, &procId);

    int numProc=-1;
    MPI_Comm_size(comm, &numProc);

    int procIdDestination = 0;
    stk::CommAll gather(comm);
    for (int phase=0; phase<2; ++phase)
    {
        if ( procId != procIdDestination )
        {
            for (size_t j=0;j<boxIdPairResults.size();++j)
            {
                gather.send_buffer(procIdDestination).pack< std::pair<Ident, Ident> >(boxIdPairResults[j]);
            }
        }

        if (phase == 0) { //allocation phase
          gather.allocate_buffers( numProc / 4 );
        }
        else { // communication phase
          gather.communicate();
        }
    }

    if ( procId == procIdDestination )
    {
        for ( int p = 0 ; p < numProc ; ++p )
        {
            stk::CommBuffer &buf = gather.recv_buffer( p );
            while ( buf.remaining() )
            {
                std::pair<Ident, Ident> temp;
                buf.unpack< std::pair<Ident, Ident> >( temp );
                boxIdPairResults.push_back(temp);
            }
        }
    }
}
void actualSort( const TestInfo *ti, Data *data )
{
	PhaseHandle sortingP, sequentialSortP;
	srand( time(0) );
	
	// init phase "computation
	computationP = startPhase( ti, "computation" );
	stopPhase( ti, computationP );

	sortingP = startPhase( ti, "sorting" );
		scatter( ti, data ); // scattering

		resumePhase( ti, computationP );
			sequentialSortP = startPhase( ti, "sequential sort" );
			sequentialSort( ti, data );
			stopPhase( ti, sequentialSortP );
		stopPhase( ti, computationP );
	stopPhase( ti, sortingP );

	gather( ti, data ); // gathering
}
Exemple #26
0
void AntBot::advance()
{
  m_doPheromoneDeregistration = false;

  /* Ant states turn to "DroppingPheromone" as soon as they have found the food source for
   * the first time.  This enables them to continue dropping pheromone on the tiles leading
   * to the food source, but also to "restart" the foraging experience (so that they do not
   * end up continuously running between nest and food). */
  switch( m_state )
  {
    case Gathering:
      gather();
      break;
    case Foraging:            // deliberate fall-through
    case DroppingPheromone:
      forage();
      break;
    case Dead:
      break;
  }
}
void SkeletalExporterBase::gather(INode* node, Vector<ExportNode>& physiqueNodes, Vector<ExportNode>& skinNodes)
{
    if (!node)
        return;

    auto doExport = !onlyExportSelected || (onlyExportSelected && node->Selected());

    // Look for a physique modifier on this node
    auto modifier = findModifier(node, Class_ID(PHYSIQUE_CLASS_ID_A, PHYSIQUE_CLASS_ID_B));
    if (modifier)
        physiqueNodes.emplace(node, modifier, doExport);

    // Look for a skin modifier on this node
    modifier = findModifier(node, SKIN_CLASSID);
    if (modifier)
        skinNodes.emplace(node, modifier, doExport);

    // Go through child nodes
    for (auto i = 0; i < node->NumberOfChildren(); i++)
        gather(node->GetChildNode(i), physiqueNodes, skinNodes);
}
Exemple #28
0
void Voronoi::getData(){
	c_loop_order_periodic vl(*Mycon,*porder);
	voronoicell_neighbor c;

	double vol0;
	vector<int> nei;
	vector<double> area0;
	int ia=0;
	if(vl.start())
		do {
			if(Mycon->compute_cell(c,vl)) {
				vol0=c.volume();
				c.neighbors(nei);
				c.face_areas(area0);
				gather(nei);
				Vol[cindex[ia]]=vol0;
				Neighs[cindex[ia]]=nei;
				Surface[cindex[ia]]=area0;
				ia++;
			}
		} while(vl.inc());
	nei.clear();
	area0.clear();

	area=0.0;
	for(int o=0;o<nresid;o++) {
		vector<int> & cindex=ResidueCM::getind(o);
		double sum_v=0.0;
		for(unsigned int ia=0;ia<cindex.size();ia++){
			int i=cindex[ia];
			sum_v+=Vol[i];
			for(unsigned int p=0;p<Neighs[i].size();p++)
				area[o][getTypes(Neighs[i][p])]+=Surface[i][p];
		}
		Vols[o]=sum_v;
	}
	time++;
}
Exemple #29
0
inline OutputIterator unique_copy(InputIterator first,
                                  InputIterator last,
                                  OutputIterator result,
                                  BinaryPredicate op,
                                  command_queue &queue)
{
    if(first == last){
        return result;
    }

    const context &context = queue.get_context();
    size_t count = detail::iterator_range_size(first, last);

    // flags marking unique elements
    vector<uint_> flags(count, context);

    // find each unique element and mark it with a one
    transform(
        first, last - 1, first + 1, flags.begin() + 1, not2(op), queue
    );

    // first element is always unique
    fill_n(flags.begin(), 1, 1, queue);

    // storage for desination indices
    vector<uint_> indices(count, context);

    // copy indices for each unique element
    vector<uint_>::iterator last_index = detail::copy_index_if(
        flags.begin(), flags.end(), indices.begin(), lambda::_1 == 1, queue
    );

    // copy unique values from input to output using the computed indices
    gather(indices.begin(), last_index, first, result, queue);

    // return an iterator to the end of the unique output range
    return result + std::distance(indices.begin(), last_index);
}
Exemple #30
0
/* combine hunk lists a and b, while adjusting b for offset changes in a/
   this deletes a and b and returns the resultant list. */
static struct flist *combine(struct flist *a, struct flist *b)
{
	struct flist *c = NULL;
	struct frag *bh, *ct;
	int offset = 0, post;

	if (a && b)
		c = lalloc((lsize(a) + lsize(b)) * 2);

	if (c) {

		for (bh = b->head; bh != b->tail; bh++) {
			/* save old hunks */
			offset = gather(c, a, bh->start, offset);

			/* discard replaced hunks */
			post = discard(a, bh->end, offset);

			/* insert new hunk */
			ct = c->tail;
			ct->start = bh->start - offset;
			ct->end = bh->end - post;
			ct->len = bh->len;
			ct->data = bh->data;
			c->tail++;
			offset = post;
		}

		/* hold on to tail from a */
		memcpy(c->tail, a->head, sizeof(struct frag) * lsize(a));
		c->tail += lsize(a);
	}

	lfree(a);
	lfree(b);
	return c;
}