示例#1
0
void RAIDProcess::newMsg() {
	RAIDProcessState *myState = (RAIDProcessState*) getState();
	int ldelay = msgDelay();
	IntVTime sendTime = dynamic_cast<const IntVTime&> (getSimulationTime());
	RAIDRequest* newRequest = new RAIDRequest(sendTime, sendTime + ldelay + 1,
			this, outputHandle);

	newRequest->setSourceObject(getName());
	newRequest->setSinkObject("");
	newRequest->setStartCylinder(-1);

	DiscreteUniform stripe(0, totalStripeSize, myState->getGen());
	DiscreteUniform read(0, 1, myState->getGen());
	DiscreteUniform size(1, maxStripeSize, myState->getGen());

	newRequest->setStartStripe((int) stripe());
	newRequest->setStartSector(-1);
	newRequest->setSizeRead((int) size());
	newRequest->setLogicalSector(-1);

	if (newRequest->getSizeRead() == 0) {
		cerr << "\n\n\n\nHold IT! sizeRead = 0\n\n\n\n\n" << "\n";
	}

	// If we try and read off the end of the array then move our starting
	// location, so that we can still read the same amount of data.
	if ((newRequest->getStartStripe() + newRequest->getSizeRead())
			>= totalStripeSize) {
		newRequest->setStartStripe(maxStripeSize - newRequest->getSizeRead());
	}

	newRequest->setBeginningOfStrype(newRequest->getStartStripe());
	newRequest->setTokenNumber(myState->getNumRequests() + 1);
	myState->setBeginningOfStrype(newRequest->getBeginningOfStrype());
	myState->set_size(newRequest->getSizeRead());
	newRequest->setSizeParity(0);
	newRequest->setParityMsg(false);

	if (read() == 0) {
		newRequest->setRead(false);
//		cout
//				<< "Write Started of size----------------------------------------------------------------------------------  "
//				<< myState->get_size() << endl;

		myState->setRead(false);
	} else {
		newRequest->setRead(true);
		myState->setRead(true);
//		cout
//				<< "Read Started of size----------------------------------------------------------------------------------  "
//				<< myState->get_size() << endl;
	}

	myState->setDiskOperationPending(true);
	myState->setBeginningOfStrype(newRequest->getStartStripe());
	myState->setStrypeSize(newRequest->getSizeRead());
	myState->setNumRequests(myState->getNumRequests() + 1);

	getObjectHandle(outputName)->receiveEvent(newRequest);
} // End of newMsg()
示例#2
0
// Get a sequence by its chunk id and id.
void HTKDataDeserializer::GetSequenceById(size_t chunkId, size_t id, vector<SequenceDataPtr>& r)
{
    const auto& chunkDescription = m_chunks[chunkId];
    size_t utteranceIndex = chunkDescription.GetUtteranceForChunkFrameIndex(id);
    const UtteranceDescription* utterance = chunkDescription.GetUtterance(utteranceIndex);
    auto utteranceFrames = chunkDescription.GetUtteranceFrames(utteranceIndex);
    size_t frameIndex = id - utterance->GetStartFrameIndexInsideChunk();

    // wrapper that allows m[j].size() and m[j][i] as required by augmentneighbors()
    MatrixAsVectorOfVectors utteranceFramesWrapper(utteranceFrames);

    size_t leftExtent = m_augmentationWindow.first;
    size_t rightExtent = m_augmentationWindow.second;

    // page in the needed range of frames
    if (leftExtent == 0 && rightExtent == 0)
    {
        leftExtent = rightExtent = msra::dbn::augmentationextent(utteranceFramesWrapper[0].size(), m_dimension);
    }

    HTKSequenceDataPtr result = make_shared<HTKSequenceData>();
    result->m_buffer.resize(m_dimension, 1);
    const vector<char> noBoundaryFlags; // TODO: dummy, currently to boundaries supported.
    msra::dbn::augmentneighbors(utteranceFramesWrapper, noBoundaryFlags, frameIndex, leftExtent, rightExtent, result->m_buffer, 0);

    result->m_numberOfSamples = 1;
    msra::dbn::matrixstripe stripe(result->m_buffer, 0, result->m_buffer.cols());
    if (m_elementType == ElementType::tfloat)
    {
        result->m_data = &stripe(0, 0);
    }
    else
    {
        assert(m_elementType == ElementType::tdouble);
        const size_t dimensions = stripe.rows();
        double *doubleBuffer = new double[dimensions];
        const float *floatBuffer = &stripe(0, 0);

        for (size_t i = 0; i < dimensions; i++)
        {
            doubleBuffer[i] = floatBuffer[i];
        }

        result->m_data = doubleBuffer;
    }

    r.push_back(result);
}
示例#3
0
void TexturedFeather::sampleColor(float lod)
{
	m_stripe->create(resShaft() * m_vane[0].gridU() * 2 + 1, resBarb() + 1);
	unsigned nu, nv;
	computeLODGrid(lod, nu, nv);
	stripe()->begin();
	
	sampleColor(nu, nv, 0);
	sampleColor(nu, nv, 1);
}
示例#4
0
文件: hessian_tbb.cpp 项目: 8l/kalmar
		void operator()( const tbb::blocked_range<int>& r )
		{
			utils::Rect stripe( r.begin(), _roi.left, r.end()-1, _roi.right );

			float Xc = 0.5f * (float)(_roi.right + _roi.left);
			float Yc = 0.5f * (float)(_roi.bottom + _roi.top);

			double Hl[PARAM_CNT][PARAM_CNT];
			double bl[PARAM_CNT];

			HESS_FUNC( Hl, bl, _I1, _wI2, stripe, _gradThresh, Xc, Yc, _sigma );

			for( int i = 0; i < PARAM_CNT; i++ )
			{
				for( int j = 0; j < PARAM_CNT; j++ )
					H[i][j] += Hl[i][j];
			}

			for(int i = 0; i < PARAM_CNT; i++)
				b[i] += bl[i];
		}
示例#5
0
void *watch_temp()

{
    int length, i = 0, wd;
    int fd;
    char buffer[BUF_LEN];

    int wds[MAX_WTD];	//for the wds
    int trigger[MAX_WTD];	//for the event->wd that trigger the current wds
    String dirs[MAX_WTD];	//for the directory names that is trigger by the wds
    int counter = 1;

    /*Initialize inotify*/
    fd = inotify_init();
    if ( fd < 0 ) {
       perror( "Couldn't initialize inotify" );
    }
    /*add watch to directory*/
    wd = inotify_add_watch(fd, TEMP_LOC, IN_ALL_EVENTS);
    wds[counter-1] = wd;
    strcpy(dirs[counter-1], TEMP_LOC);

    if (wd == -1){
        syslog(LOG_INFO, "FileTransaction: Couldn't add watch to %s\n", TEMP_LOC);
    } else {
        syslog(LOG_INFO, "FileTransaction: WRITE :: Watching:: %s\n", TEMP_LOC);

    }

    /*do it forever*/
    while(1){
	//select(fd+1, &descriptors, NULL, NULL, &time_to_wait);
       create_link();
       i = 0;
       length = read(fd, buffer, BUF_LEN);

       if (length < 0){
          perror("read");
       }
       while(i < length){
           struct inotify_event *event = (struct inotify_event *) &buffer[i];

           if (event->len){

	      if (event->mask & IN_CREATE){
		if (event->mask & IN_ISDIR){
		     //printf("%s is created.\n", event->name);
		     String dir_to_watch = "";
		     String root = "";
		     String arr[MAXDEPTH];
		     int d;
		    //Initialize array....
		     for (d = 0; d < 30; d++){
			strcpy(arr[d], "");
		     }

		     get_root(wds,trigger, dirs, counter,event->wd,arr);

		     for (d = 1; d < counter; d++){
			if(strcmp(arr[d], "") != 0) {
			    strcat(root, arr[d]);
			    strcat(root, "/");
			}
		     }

		     String x;
		     sprintf(x, "%s%s", root, event->name);

                     sprintf(dir_to_watch,"%s/%s%s/", TEMP_LOC, root, event->name);
		     wd = inotify_add_watch(fd, dir_to_watch, IN_ALL_EVENTS);

                     if (wd == -1){

		     } else {
			syslog(LOG_INFO, "FileTransaction: WRITE := Watching := %s\n", dir_to_watch);
		     }
		     //printf("DIR_TO_WATCH := %s\n", dir_to_watch);

		     wds[counter] = wd;
		     trigger[counter] = event->wd;
                     strcpy(dirs[counter], event->name);



		/***************CREATES in /mnt/CVFSFSTorage AND LINK DIRECTORY to SHare *********/
		     String dir = "", chmod = "",  sors = "", dest = "";
		     sprintf(dir, "mkdir '%s/%s'", SHIT_STORAGE, event->name);
		     system(dir);

                    sprintf(chmod, "chmod 777 -R '%s/%s'", SHIT_STORAGE, event->name);
		    system(chmod);

		     sprintf(sors, "%s/%s", SHIT_STORAGE, event->name);
		     sprintf(dest, "%s/%s", SHARE_LOC, x);
		     symlink(sors,dest);
	         /******************************************************************************/
		     make_folder(x);
		     counter++;
		}
              }

              if (event->mask & IN_CLOSE){
		if (event->mask & IN_ISDIR){
		} else {
		     String root = "";
		     String arr[MAXDEPTH];
		     int n = sizeof(wds) / sizeof(wds[0]);
		     int d, i, rooti;
		      //initialize the array...
		      for (d = 0; d < MAXDEPTH; d++){
			strcpy(arr[d], "");
		      }


		      get_root(wds, trigger, dirs, counter, event->wd, arr);
		      for (d = 1; d < counter; d++){
			if(strcmp(arr[d], "") != 0) {
			    strcat(root, arr[d]);
			    strcat(root, "/");
			}
		      }

                      String filepath = "";
		      String filename = "";
		      sprintf(filename, "%s%s", root, event->name);
                      FILE *fp;
                      sprintf(filepath, "%s/%s%s", TEMP_LOC, root, event->name);
		      //syslog(LOG_INFO, "FileTransaction: FILEPATH := %s\n", filepath);
		      //syslog(LOG_INFO, "FileTransaction: hahahaa: filepath:%s\n\tfilename:%s", filepath, filename);
                      fp = fopen(filepath, "rb");
                      if (fp != NULL){
                         fseek(fp, 0L, SEEK_END);
                         long sz = ftell(fp);
                         rewind(fp);
                         //check if stripe file
                        if (sz > STRIPE_SIZE){
                           //before striping, check cache
			   printf("STRIPED: %s | SIZE : %ld bytes\n", event->name, sz);
                           //printf("%s will be striped.\n", event->name);
			   //printf("Inserting into CacheContent...\n");
                           update_cache_list(event->name, root);
                           //printf("Cache Count: %d\n", getCacheCount());
                          // if (getCacheCount() < MAX_CACHE_SIZE) { //max cache size is 10
                           printf("Cache Size: %d\n", getCacheCount());
			   printf("%s will be put to cache.\n", filename);
                           file_map_cache(filename, event->name);
                             //create_link_cache(filename);
                          // }
                           //stripe(event->n);
                           //refreshCache();	
			   //printf("ROOT = %s\n", root);
			   //printf("FILEPATH := %s\n", filepath);
			   //printf("FILENAME := %s\n", filename);
			   stripe(root, filepath, filename);
			   //refreshCache();
                        } else {
			   syslog(LOG_INFO, "FileTransaction: Transferring %s to targets...\n", filename);
                           file_map(filepath, filename);
                        }
		    }
                  }
              }

              if (event->mask & IN_MOVED_TO){
                 if (event->mask & IN_ISDIR)
                      printf("The directory %s is transferring.\n", event->name);
                  else
                      printf("The file %s is transferring.\n", event->name);

              }

              i += EVENT_SIZE + event->len;
           }
       }
    }
    /* Clean up */
    inotify_rm_watch(fd, wd);
    close(fd);
}
示例#6
0
static bool process(void)
{

	fill(0);
	if (pause("00 ", DELAY)) {
		return false;
	}

	fill(0xff);
	if (pause("ff ", DELAY)) {
		return false;
	}

	fill(0x55);
	if (pause("55 ", DELAY)) {
		return false;
	}

	fill(0x44);
	if (pause("44 ", DELAY)) {
		return false;
	}

	fill(0xf7);
	if (pause("f7 ", DELAY)) {
		return false;
	}
	print_char('\n');

	print("stripe(00) ");

	stripe(0xff, 0x00);
	if (pause("ff ", DELAY)) {
		return false;
	}

	stripe(0x01, 0x00);
	if (pause("01 ", DELAY)) {
		return false;
	}
	print_char('\n');

	print("stripe(ff) ");

	stripe(0x00, 0xff);
	if (pause("00 ", DELAY)) {
		return false;
	}

	stripe(0xee, 0xff);
	if (pause("7f ", DELAY)) {
		return false;
	}
	print_char('\n');

	display_image(0x00);
	if (pause("image(00)", DELAY)) {
		return false;
	}
	print_char('\n');

	display_image(0xff);
	if (pause("image(ff)", DELAY)) {
		return false;
	}
	print_char('\n');

	return true;
}
示例#7
0
文件: hessian_tbb.cpp 项目: 8l/kalmar
//----
bool update_trz_ppl_lambda( H3& dH, const utils::Matrix<float>& I1,  const utils::Matrix<float>& wI2, float sigma, float gradThresh, const  utils::Rect& roi )
{
	static const int PARAM_CNT = 4;

	class Worker
	{
	public:
		Worker() {
			memset( H, 0, PARAM_CNT*PARAM_CNT*sizeof(double) );
			memset( b, 0,           PARAM_CNT*sizeof(double) );
		};

	public: // state
		double H[PARAM_CNT][PARAM_CNT];
		double b[PARAM_CNT];
	};

	utils::Rect validRgn( roi.top+1, roi.left+1, roi.bottom-1, roi.right-1 ); // avoid problems with gradients
	//Worker w( I1, wI2, sigma, gradThresh, validRgn );
	//

	Concurrency::combineable<Worker> workers;
	Concurrency::parallel_for(validRgn.top, validRgn.bottom+1, [&](int r) {
		utils::Rect stripe( r.begin(), validRgn.left, r.end()-1, validRgn.right );

		float Xc = 0.5f * (float)(validRgn.right + validRgn.left);
		float Yc = 0.5f * (float)(validRgn.bottom + validRgn.top);

		double Hl[PARAM_CNT][PARAM_CNT];
		double bl[PARAM_CNT];

		sse::hessianTRZ( Hl, bl, I1, wI2, stripe, gradThresh, Xc, Yc, sigma );

		for( int i = 0; i < PARAM_CNT; i++ )
		{
			for( int j = 0; j < PARAM_CNT; j++ )
				init.H[i][j] += Hl[i][j];
		}

		for(int i = 0; i < PARAM_CNT; i++)
			init.b[i] += bl[i];

	});

	[=](const tbb::blocked_range<int> &r,  Worker init)->Worker {

		utils::Rect stripe( r.begin(), validRgn.left, r.end()-1, validRgn.right );

		float Xc = 0.5f * (float)(validRgn.right + validRgn.left);
		float Yc = 0.5f * (float)(validRgn.bottom + validRgn.top);

		double Hl[PARAM_CNT][PARAM_CNT];
		double bl[PARAM_CNT];

		sse::hessianTRZ( Hl, bl, I1, wI2, stripe, gradThresh, Xc, Yc, sigma );

		for( int i = 0; i < PARAM_CNT; i++ )
		{
			for( int j = 0; j < PARAM_CNT; j++ )
				init.H[i][j] += Hl[i][j];
		}

		for(int i = 0; i < PARAM_CNT; i++)
			init.b[i] += bl[i];

		return init;

	},
		[](const Worker &x, const Worker &y)->Worker {
			Worker z;
			for( int i = 0; i < PARAM_CNT; i++ )
			{
				for( int j = 0; j < PARAM_CNT; j++ )
					z.H[i][j] = x.H[i][j] + y.H[i][j];
			}

			for(int i = 0; i < PARAM_CNT; i++)
				z.b[i] = x.b[i] + y.b[i];

			return z;
	},
		tbb::auto_partitioner());


#if 1
	double dx[PARAM_CNT];


	// solve and generate update
	dH.zeros();
	if( solve_ChD<double, PARAM_CNT>(dx, w.H, w.b) )
	{
		dH[0] =  dx[0];
		dH[1] =  dx[1];

		dH[3] = -dx[1];
		dH[4] =  dx[0];

		dH[2] =  dx[2];
		dH[5] =  dx[3];

		return true;
	}
#endif

	return false; // ill conditioned hessian matrix (can not solve)
}