Istream& IPstream::read(word& w)
{
    size_t ws;
    readFromBuffer(ws);
    w = &buf_[bufPosition_];
    bufPosition_ += ws + 1;
    checkEof();
    return *this;
}
예제 #2
0
파일: IPstream.C 프로젝트: Brzous/WindFOAM
Foam::Istream& Foam::IPstream::read(word& str)
{
    size_t len;
    readFromBuffer(len);
    str = &buf_[bufPosition_];
    bufPosition_ += len + 1;
    checkEof();
    return *this;
}
예제 #3
0
Foam::Istream& Foam::UIPstream::read(string& str)
{
    size_t len;
    readFromBuffer(len);
    str = &externalBuf_[externalBufPosition_];
    externalBufPosition_ += len + 1;
    checkEof();
    return *this;
}
Istream& IPstream::read(string& s)
{
    size_t ss;
    readFromBuffer(ss);
    s = &buf_[bufPosition_];
    bufPosition_ += ss + 1;
    checkEof();
    return *this;
}
예제 #5
0
Foam::Istream& Foam::UIPstream::read(char* data, std::streamsize count)
{
    if (format() != BINARY)
    {
        FatalErrorIn("UIPstream::read(char*, std::streamsize)")
            << "stream format not binary"
            << Foam::abort(FatalError);
    }

    readFromBuffer(data, count, 8);
    return *this;
}
예제 #6
0
void cluster_t::update_map_distance_gpu(){
#ifdef USE_GPU
  int x_dim = BLOCK_WIDTH * variable_blocks;
  runKernel("update_map_distance",kernel_update_map_distance,x_dim,1,1,BLOCK_WIDTH,1,1);
  float norm1_arr[variable_blocks];
  float norm2_arr[variable_blocks];
  readFromBuffer(buffer_variable_block_norms1,variable_blocks,norm1_arr,"buffer_variable_block_norms1");
  readFromBuffer(buffer_variable_block_norms2,variable_blocks,norm2_arr,"buffer_variable_block_norms2");
  float norm1=0,norm2=0;
  for(int i=0;i<variable_blocks;++i){
    //cerr<<"GPU Block "<<i<<" norm: "<<norm1_arr[i]<<","<<norm2_arr[i]<<endl;
    norm1+=norm1_arr[i];
    norm2+=norm2_arr[i];
  }
  if(config->verbose) cerr<<"GPU Norm1 was "<<norm1<<" and norm2 was "<<norm2<<endl;
  float norm = norm1+norm2;
  this->map_distance = norm;
  this->dist_func = sqrt(this->map_distance+epsilon);
  if(config->verbose)cerr<<"GET_MAP_DISTANCE: New map distance is "<<norm<<" with U distance="<<norm1<<", V distance="<<norm2<<" dist_func: "<<dist_func<<endl;
#endif
}
예제 #7
0
void cluster_t::finalize_iteration_gpu(){
#ifdef USE_GPU
  int x_dim = BLOCK_WIDTH * n;
  runKernel("get_U_norm_diff",kernel_get_U_norm_diff,x_dim,1,1,BLOCK_WIDTH,1,1);
  readFromBuffer(buffer_n_norms,n,norm1_arr,"buffer_n_norms");
  float gpu_U_norm_diff = 0;
  for(int i=0;i<n;++i){
    gpu_U_norm_diff+=norm1_arr[i];
  }
  U_norm_diff = sqrt(gpu_U_norm_diff);

  if(config->verbose)cerr<<"FINALIZE_ITERATION: GPU U_norm_diff: "<<U_norm_diff<<endl;
#endif
}
예제 #8
0
파일: chain.c 프로젝트: brahle/swSharp
extern Chain* chainCreateFromBuffer(char* fileBuffer, SWPrefs* swPrefs) {

    Chain* chain = (Chain*) malloc(sizeof(struct Chain));
    chain->subchain = 0;

    readFromBuffer(chain, fileBuffer, swPrefsGetMatcher(swPrefs));

    if (swPrefsSolveOnly(swPrefs)) {
        chain->reverseCodes = NULL;
        chain->reverseItems = NULL;
    } else {
        addReversedChain(chain);
    }

    return chain;
}
예제 #9
0
void cluster_t::store_U_projection_gpu(){
#ifdef USE_GPU
  int x_dim = BLOCK_WIDTH * variable_blocks;
  runKernel("store_U_project",kernel_store_U_project,x_dim,n,1,BLOCK_WIDTH,1,1);
  bool debug_gpu = false;
  if(debug_gpu){
    float testArr[n*p];
    readFromBuffer(buffer_U_project,n*p,testArr,"buffer_U_project");
    for(int i=0;i<n;++i){
      for(int j=0;j<p;++j){
        if(i>(n-3) && j>(p-3)){
          cerr<<"GPU store U_project for subject,var: "<<i<<","<<j<<": "<<testArr[i*p+j]<<endl;
        }
      }
    }
  }
#endif
}
예제 #10
0
void cluster_t::initialize_gpu(){
#ifdef USE_GPU
  int x_dim = BLOCK_WIDTH * variable_blocks;
  runKernel("init_U",kernel_init_U,x_dim,n,1,BLOCK_WIDTH,1,1);
  bool debug_gpu = false;
  if(debug_gpu){
    float testArr[n*p];
    readFromBuffer(buffer_U_project,n*p,testArr,"buffer_U_project");
    for(int i=0;i<n;++i){
      for(int j=0;j<p;++j){
        if(i==(n-10) && j>(p-10)){
          cerr<<"GPU: U_project_orig "<<i<<","<<j<<": "<<testArr[i*p+j]<<endl;
        }
      }
    }
  }
#endif
}
예제 #11
0
void cluster_t::init_v_project_coeff_gpu(){
#ifdef USE_GPU
  float unweighted_lambda = mu * dist_func / rho;
  writeToBuffer(buffer_unweighted_lambda, 1, &unweighted_lambda, "buffer_unweighted_lambda");
  runKernel("init_v_project_coeff",kernel_init_v_project_coeff,BLOCK_WIDTH*n,n,1,BLOCK_WIDTH,1,1);
  bool debug_gpu = false;
  if(debug_gpu){
    float * testv = new float[triangle_dim];
    readFromBuffer(buffer_V_project_coeff,triangle_dim,testv,"buffer_V_project_coeff");
    for(int index1=0;index1<n-1;++index1){
      for(int index2=index1+1;index2<n;++index2){
        float & scaler  = testv[offsets[index1]+(index2-index1)];
        if (scaler !=0 && scaler !=1 )
          cerr<<"GPU Init_V Index: "<<index1<<","<<index2<<": "<<scaler<<endl;
      }
    }
  }
#endif
}
예제 #12
0
void cluster_t::update_u_gpu(){
#ifdef USE_GPU
  writeToBuffer(buffer_dist_func,1,&dist_func,"buffer_dist_func");
  writeToBuffer(buffer_rho,1,&rho,"buffer_rho");
  int x_dim = BLOCK_WIDTH * variable_blocks;
  runKernel("update_U",kernel_update_U,x_dim,n,1,BLOCK_WIDTH,1,1);
  bool debug_gpu = false;
  if(debug_gpu){
    float testArr[n*p];
    readFromBuffer(buffer_U,n*p,testArr,"buffer_U");
    for(int i=0;i<n;++i){
      for(int j=0;j<p;++j){
        if(i==(n-10) && j>(p-10)){
          cerr<<"update U GPU: U: "<<i<<","<<j<<": "<<testArr[i*p+j]<<endl;
        }
      }
    }
  }
#endif
}
예제 #13
0
bool ZLXMLReader::readDocument(shared_ptr<ZLInputStream> stream) {
	if (stream.isNull() || !stream->open()) {
		return false;
	}

	bool useWindows1252 = false;
	stream->read(myParserBuffer, 256);
	std::string stringBuffer(myParserBuffer, 256);
	stream->seek(0, true);
	int index = stringBuffer.find('>');
	if (index > 0) {
		stringBuffer = stringBuffer.substr(0, index);
		if (!ZLUnicodeUtil::isUtf8String(stringBuffer)) {
			return false;
		}
		stringBuffer = ZLUnicodeUtil::toLower(stringBuffer);
		int index = stringBuffer.find("\"iso-8859-1\"");
		if (index > 0) {
			useWindows1252 = true;
		}
	}
	initialize(useWindows1252 ? "windows-1252" : 0);

	std::size_t length;
	do {
		length = stream->read(myParserBuffer, BUFFER_SIZE);
		if (!readFromBuffer(myParserBuffer, length)) {
			break;
		}
	} while ((length == BUFFER_SIZE) && !myInterrupted);

	stream->close();

	shutdown();

	return true;
}
ssize_t AudioAACStreamIn::read(void* buffer, ssize_t bytes)
{
    
//	while ( GetLock(infd) == 1){ // lock is found
//                ALOGI("lock found sleeping...\n");
//		usleep(500000); // half a second for now
//	}
	
	//ALOGI("No lock found reading...\n");
        AutoMutex lock(mLock);
	struct timeval end;
	gettimeofday(&end, NULL);
	int diff = end.tv_usec-last.tv_usec+1000000ll*(end.tv_sec-last.tv_sec);
	if(diff>250000||diff<0)	{ // 1/4sec
		ALOGI("read:: Resetting time; had %d diff\n", diff);
		gettimeofday(&last, NULL);
	}
	//readFromBuffer(bytes/sizeof(unsigned short),(unsigned short*)buffer);	// bytes/2 is because I care about shorts, not bytes
        readFromBuffer(bytes,(unsigned short*)buffer);

	// advance the time time by a frame
	last.tv_usec += (bytes * 1000000ll) / sizeof(int16_t) / AudioSystem::popCount(channels()) / sampleRate();
	if(last.tv_usec>1000000ll) {
		last.tv_sec++;
		last.tv_usec-=1000000;
	}

	diff = last.tv_usec-end.tv_usec+1000000ll*(last.tv_sec-end.tv_sec);

	if(diff>0)	// If it's positive, sleep the difference between the expected end time and the actual end time
		usleep(diff);

	// set read lock. Must be unlocked by next write.
	//SetLock(infd);
	return bytes/sizeof(unsigned short);
}
GpsSatInfoHolder::GpsSatInfoHolder(Buffer *buf)
{
   m_satInfo = 0;
   readFromBuffer(buf);
}
예제 #16
0
Stack iteration (int sockfd, char* buffer, Stack stack) {  
  bzero(buffer, PACKET_SIZE_MAX);
  
  struct sockaddr_in serv_addr;
  socklen_t servlen = sizeof(serv_addr);
  
  int n = recvfrom(sockfd, buffer, PACKET_SIZE_MAX, 0, (struct sockaddr *)&serv_addr ,&servlen);  
  if (n < 0)exception("ERROR reading from socket");
  //printf("READ %d bytes fom a reply\n", n);
  
  Packet p = readFromBuffer(buffer, n);
  ppacket(p, "RECV");
  // only possible exit
  if (p.pt == EOT) {
    if (p.sn != checkStackWindow(stack)) {
      failure("Packet SN out of order on EOT");
      
      return iteration(sockfd, buffer, stack);
    }
    ppacket(p, "SEND");
    writeToBuffer(buffer, PACKET_SIZE_MAX, p);
    int n = sendto(sockfd, buffer, p.pl, 0, (struct sockaddr *)&serv_addr, sizeof(serv_addr));    
    if (n < 0)exception("ERROR writing to socket");
    stack = addPacket(stack, p);
    
    return stack;
  }
  
  if (p.pt != DAT) {
    failure("Packet Type other than EOT and DAT aren't supportted");
    
    return iteration(sockfd, buffer, stack);
  }
  if (p.sn < stack.window_low || p.sn > stack.window_high) {
    failure("Packet SN out of order");
    
    return iteration(sockfd, buffer, stack);
  }
  
  
  p.pt = ACK;
  stack = addPacket(stack, p);
  // dummy window size management for now
  stack.window_high = stack.size;
  //stack = updateStackWindow(stack, p);
  
  p.pl = PACKET_SIZE_MIN;
#ifdef GBN
  p.sn = checkStackWindow(stack) - 1;
#endif
#ifdef SR
  // don't need to do anything
#endif
  ppacket(p, "SEND");
  if (p.sn >= 0){
    writeToBuffer(buffer, PACKET_SIZE_MAX, p);
    int n = sendto(sockfd, buffer, p.pl, 0, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
    if (n < 0)exception("ERROR writing to socket");
  }
  
  return iteration(sockfd, buffer, stack);
}
예제 #17
0
void cluster_t::get_U_gpu(){
#ifdef USE_GPU
  readFromBuffer(buffer_U,n*p,U,"buffer_U");
#endif
}
예제 #18
0
Foam::Istream& Foam::UIPstream::read(label& val)
{
    readFromBuffer(val);
    return *this;
}
예제 #19
0
Foam::Istream& Foam::UIPstream::read(doubleScalar& val)
{
    readFromBuffer(val);
    return *this;
}
예제 #20
0
파일: IPstream.C 프로젝트: Brzous/WindFOAM
Foam::Istream& Foam::IPstream::read(floatScalar& val)
{
    readFromBuffer(val);
    return *this;
}
예제 #21
0
	void DeathCommand::unserialize( const char* buffer, size_t& index )
	{
		Message::unserialize( buffer, index );
		readFromBuffer( m_deadActorID, buffer, index );
	}
Istream& IPstream::read(doubleScalar& s)
{
    readFromBuffer(s);
    return *this;
}
Istream& IPstream::read(floatScalar& s)
{
    readFromBuffer(s);
    return *this;
}
Istream& IPstream::read(label& l)
{
    readFromBuffer(l);
    return *this;
}