void
PipelineInterests::handleData(const Interest& interest, const Data& data)
{
  BOOST_ASSERT(data.getName().equals(interest.getName()));

  uint64_t recv_segno = data.getName()[-1].toSegment();
  if (m_highData < recv_segno) {
    m_highData = recv_segno;
  }

  shared_ptr<SegmentInfo> seg_info = m_segmentInfoMap[recv_segno];
  BOOST_ASSERT(seg_info != nullptr);
  if (seg_info->state == retransmitReceived) {
    m_segmentInfoMap.erase(recv_segno);
    return; // ignore already-received segment
  }

  if (m_options.isVerbose) {
    duration_in_ms rtt = time::steady_clock::now() - seg_info->timeSent;
    std::cerr << "Received the segment #" << recv_segno
              << ", rtt=" << rtt.count() << "ms"
              << ", rto=" << seg_info->rto << "ms" << std::endl;
  }

  // for segments in retransmission queue, no need to decrement m_inFligh since
  // it's already been decremented when segments timed out.
  if (seg_info->state != inRetxQueue && m_inFlight > 0) {
    m_inFlight--;
  }

  m_numOfSegmentReceived++;
  adjustCwnd();
  m_onData(interest, data);

  if (seg_info->state == firstTimeSent ||
      seg_info->state == inRetxQueue) { // donot sample RTT for retransmitted segments
    m_rttEstimator.rttMeasurement(recv_segno, seg_info->timeSent, seg_info->rto);
    m_segmentInfoMap.erase(recv_segno); // remove the entry associated with the received segment
  }
  else { // retransmission
    seg_info->state = retransmitReceived;
  }

  if (allSegmentsReceived() == true) {
    printSummary();
    if (m_options.keepStats) {
      writeStats();
      m_rttEstimator.writeStats();
    }
    cancel();
  }
  else {
    schedulePackets();
  }
}
Пример #2
0
void PartitionIO<MeshType>::write (const meshPartsPtr_Type& meshParts)
{
    M_meshPartsOut = meshParts;
    M_numParts = M_meshPartsOut->size();

    M_HDF5IO.openFile (M_fileName, M_comm, false);
    writeStats();
    writePoints();
    writeEdges();
    writeFaces();
    writeElements();
    M_HDF5IO.closeFile();

    M_meshPartsOut.reset();
}
Пример #3
0
void
ROLoader::processRoutes(SUMOTime start, SUMOTime end,
                        RONet& net, SUMOAbstractRouter<ROEdge, ROVehicle>& router) {
    SUMOTime absNo = end - start;
    // skip routes that begin before the simulation's begin
    // loop till the end
    bool endReached = false;
    bool errorOccured = false;
    const SUMOTime firstStep = myLoaders.getFirstLoadTime();
    SUMOTime lastStep = firstStep;
    for (SUMOTime time = firstStep; time < end && !errorOccured && !endReached; time += DELTA_T) {
        writeStats(time, start, absNo);
        myLoaders.loadNext(time);
        net.saveAndRemoveRoutesUntil(myOptions, router, time);
        endReached = !net.furtherStored();
        lastStep = time;
        errorOccured = MsgHandler::getErrorInstance()->wasInformed() && !myOptions.getBool("ignore-errors");
    }
    if (myLogSteps) {
        WRITE_MESSAGE("Routes found between time steps " + time2string(firstStep) + " and " + time2string(lastStep) + ".");
    }
}
Пример #4
0
int run(boost::mpi::environment& env, boost::scoped_ptr<nemo::Network>& net, unsigned ncount, unsigned scount,
		unsigned duration, unsigned nType, unsigned mType, const char* outfile, const char* configFile, const char* logDir) {

	boost::mpi::communicator world;

	boost::filesystem::path logDirPath(logDir);
	boost::filesystem::create_directory(logDirPath);

	std::ostringstream simDir;
	simDir << logDir << "/simulation-p" << world.size() << "-n" << ncount << "-s" << scount << "-nt" << nType << "-mt" << mType;
	boost::filesystem::path simDirPath(simDir.str());
	boost::filesystem::create_directory(simDirPath);

	try {
		if ( world.rank() == nemo::mpi::MASTER ) {
			nemo::Configuration conf(world.rank(), configFile);
			std::cout << "Constructing master..." << std::endl;
			nemo::mpi::Master master(env, world, *net, mType, conf, logDir);

			std::ostringstream filename;
			filename << simDir.str() << "/" << outfile;
			std::ofstream file(filename.str().c_str());

			rng_t rng;
			uirng_t randomNeuron(rng, boost::uniform_int<>(0, ncount - 1));

			master.resetTimer();
			nemo::Simulation::firing_stimulus firingStimulus(10);

			for ( unsigned ms = 0; ms < duration; ++ms ) {
				for ( unsigned i = 0; i < 10; i++ )
					firingStimulus[i] = randomNeuron();

				master.step(firingStimulus);
				const std::vector<unsigned>& firing = master.readFiring();
				file << ms << ": ";
				std::copy(firing.begin(), firing.end(), std::ostream_iterator<unsigned>(file, " "));
				file << std::endl;
			}

			std::ostringstream oss;
			oss << "Simulated " << master.elapsedSimulation() << " ms wall clock time: " << master.elapsedWallclock() << "ms"
					<< std::endl;
			std::cout << oss.str() << std::endl;

			/* Write general stats to simulation folder */
			filename.str("");
			filename.clear();
			filename << simDir.str() << "/general-stats.txt";
			writeStats(filename.str().c_str(), scount, master.elapsedSimulation(), master.elapsedWallclock(), *net, conf);
			master.appendMpiStats(filename.str().c_str());

			/* Write firing counters to simulation folder */
			filename.str("");
			filename.clear();
			filename << simDir.str() << "/firing-counters.txt";
			master.writeFiringCounters(filename.str().c_str());
		}
		else {
			std::cout << "Starting worker " << world.rank() << "..." << std::endl;
			nemo::Configuration conf(world.rank(), configFile);
			if ( conf.stdpEnabled() ) {
				std::cout << "STDP enabled" << std::endl;
				setStandardStdpFunction(conf);
			}
			nemo::mpi::runWorker(env, world, conf, simDir.str().c_str());
		}
	}
	catch (nemo::exception& e) {
		std::cerr << world.rank() << ":" << e.what() << std::endl;
		env.abort(e.errorNumber());
	}
	catch (boost::mpi::exception& e) {
		std::cerr << world.rank() << ": " << e.what() << std::endl;
		env.abort(-1);
	}

	return 0;
}
Пример #5
0
/*! \note when Master is a proper subclass of Simulation, we can share code
 * between the two run functions. */
int runNoMPI(unsigned ncount, unsigned scount, unsigned duration, unsigned mType, const char* filename,
		const char* logDir) {
	std::cout << "Start simulation." << std::endl;

	nemo::Network* net;
//nemo::Network* net = simpleNet(15, 64, false);

	if ( mType == 0 )
		net = nemo::random::constructUniformRandom(ncount, scount, 40, false);
	else if ( mType == 1 )
		net = nemo::random::constructWattsStrogatz(20, 0.1, ncount, 40, false);
	else if ( mType == 43 )
		net = nemo::random::simpleNet(15, 64, false);
	else
		exit(1);

	nemo::Configuration conf;

	conf.setCudaBackend();
	//conf.setCpuBackend();

	conf.setStdpEnabled(false);
	conf.setStdpPeriod(10);
	conf.setStdpReward(1);
	if ( conf.stdpEnabled() ) {
		std::cout << "STDP enabled" << std::endl;
		setStandardStdpFunction(conf);
	}

	nemo::Simulation* sim = nemo::simulation(*net, conf);

	std::ofstream file(filename);

	nemo::NeuronType neuronType("Izhikevich");

	std::ostringstream oss;
	for ( unsigned n = 0; n < 15; n++ ) {
		oss << "Neuron " << n << " --- Parameters: ";

		for ( unsigned i = 0; i < neuronType.parameterCount(); i++ )
			oss << "  " << net->getNeuronParameter(n, i);

		oss << " --- State: ";
		for ( unsigned i = 0; i < neuronType.stateVarCount(); i++ )
			oss << "  " << net->getNeuronState(n, i);

		oss << std::endl;
	}

	std::cout << oss.str() << std::endl;

	sim->resetTimer();
	std::vector<unsigned> stim;

	for ( unsigned ms = 0; ms < duration; ++ms ) {
		if ( ms % 2 == 0 ) {
			stim.push_back(0);
		}
		else {
			stim.clear();
		}
		const std::vector<unsigned>& fired = sim->step(stim);
		file << ms << ": ";
		std::copy(fired.begin(), fired.end(), std::ostream_iterator<unsigned>(file, " "));
		file << std::endl;

		if ( conf.stdpEnabled() && sim->elapsedSimulation() % conf.stdpPeriod() == 0 ) {
			sim->applyStdp(conf.stdpReward());
		}
	}

	oss.str("");
	oss.clear();
	oss << "Simulated " << sim->elapsedSimulation() << " ms wall clock time: " << sim->elapsedWallclock() << "ms"
			<< std::endl;
	std::cout << oss.str() << std::endl;

	oss.str("");
	oss.clear();
	oss << logDir << "/stats_global-n" << ncount << "-s" << scount << "-st" << sim->elapsedSimulation() << ".txt";
	writeStats(oss.str().c_str(), scount, sim->elapsedSimulation(), sim->elapsedWallclock(), *net, conf);

	delete net;

	return 0;
}
Пример #6
0
/**
* Entry point.
*/
int main(int argc,char** argv){
	//Seed the timer...
	srand(time(0));
		
	/**
	* Does the user need help?
	*/
	if(wasArgSpecified("--help",argv,argc)!=0){
		printHelp();
		return 0;
	}

	//Initialize with default configuration.
	BloomOptions_t bloomOptions_t;
	setDefault(&bloomOptions_t);
	//Parset he user's configuration
	getConfiguration(&bloomOptions_t,argv,argc);
	//Show the user the configuration.
	if(!wasArgSpecified("--silent",argv,argc)!=0)
		showDetails(&bloomOptions_t);
	//Do we need to generate new test files?
	if(wasArgSpecified("--generate",argv,argc)!=0){
		generateFiles(bloomOptions_t.numBatches,bloomOptions_t.batchSize);
		generateFilesPrefix(bloomOptions_t.falseBatches,bloomOptions_t.batchSize,
			(char*)"q");
		return 0;
	}
	//Create the bloom filter eing used, and initailize with all 0's.
	char* bloom = (char*)calloc(sizeof(char)*bloomOptions_t.size,sizeof(char));
	int totalNumWords = 0;
	int i = 0;
	for(i = 0;i<bloomOptions_t.numBatches;i++){
		//Do we need to insert it multiple times?
		if(i<bloomOptions_t.trueBatches){
			int y = 0;
			for(;y<bloomOptions_t.numTrueBatchInsertions;y++){
				WordAttributes* wordAttributes = loadFile(i);
				if(y == 0)
					totalNumWords+=wordAttributes->numWords;
				insertWords(bloom,&bloomOptions_t,wordAttributes,bloomOptions_t.prob);
				freeWordAttributes(wordAttributes);
			}
		}else{
			//Only insert it once.
			WordAttributes* wordAttributes = loadFile(i);
			totalNumWords+=wordAttributes->numWords;
			insertWords(bloom,&bloomOptions_t,wordAttributes,bloomOptions_t.prob);
			freeWordAttributes(wordAttributes);
		}
	}

	FILE* pbfOutput = 0;
	if(bloomOptions_t.pbfOutput){
		pbfOutput = fopen(bloomOptions_t.pbfOutput,"w+");
	}

	//Get the stats...
	int numTrueOnesCalculated = 0;
	int numFalseOnesCalculated = 0;
	i = 0;
	for(;i<bloomOptions_t.trueBatches;i++){
		WordAttributes* wordAttributes = loadFile(i);
		int* results = (int*)calloc(sizeof(int)*wordAttributes->numWords,
			sizeof(int));
		queryWords(bloom,&bloomOptions_t,wordAttributes,results);
		if(bloomOptions_t.pbfOutput)
			writeStats(pbfOutput,i,results,wordAttributes->numWords,
				bloomOptions_t.numHashes,bloomOptions_t.prob,wordAttributes->numWords,	
				bloomOptions_t.size);

		free(results);
		freeWordAttributes(wordAttributes);
	}

	if(bloomOptions_t.pbfOutput)
		fprintf(pbfOutput,"false\n");

	for(i = 0;i<bloomOptions_t.falseBatches;i++){
		WordAttributes* wordAttributes = loadFileByPrefix(i,(char*)"q");
		int* results = (int*)calloc(sizeof(int)*wordAttributes->numWords,
			sizeof(int));
		queryWords(bloom,&bloomOptions_t,wordAttributes,results);
		if(bloomOptions_t.pbfOutput){
			writeStats(pbfOutput,i,results,wordAttributes->numWords,
				bloomOptions_t.numHashes,bloomOptions_t.prob,wordAttributes->numWords,	
				bloomOptions_t.size);
		}

		free(results);
		freeWordAttributes(wordAttributes);
	}	

	if(pbfOutput)
		fclose(pbfOutput);

	if(bloomOptions_t.fileName!=0){
		writeBloomFilterToFile(&bloomOptions_t,bloom);
	}

	free(bloom);

	return 0;
}
Пример #7
0
int main(int argc,char** argv){
	
	//Seed the timer.
	srand(time(0));
	//printf("Begin GPU PBF..\n");

	//Does the user need help?
	if(wasArgSpecified("--help",argv,argc)!=0){
		printHelp();
		return 0;
	}
	
	//Initialize with default configuration.
	BloomOptions_t bloomOptions_t;
	setDefault(&bloomOptions_t);	
	//Parse the user's configuration.
	getConfiguration(&bloomOptions_t,argv,argc);
	bloomOptions_t.prob = calculateProb(bloomOptions_t.freq,bloomOptions_t.numKeys);
	bloomOptions_t.size = calculateSize(bloomOptions_t.numHashes,bloomOptions_t.numKeys,bloomOptions_t.prob);

	//showDetails(&bloomOptions_t);

	//Create the bloom filter being used, and initialize it with all 0's.
	char* bloom = (char*)malloc(sizeof(char)*bloomOptions_t.size);
	memset(bloom,0,bloomOptions_t.size);

	//Allocate the GPU bloom filter.
	char* dev_bloom = allocateAndCopyChar(bloom,bloomOptions_t.size); 
	if(dev_bloom==0){
		printf("Could not allocate the bloom filter \n");
		return -1;	
	}

	//Read input keys and insert to PBF
	char* fileName = (char*)malloc(sizeof(char)*50);
	sprintf(fileName,"./data/total_keys.txt");
	WordAttributes* allKeys = loadFileByName(fileName);
	int total_keys = allKeys->numWords;	
	int randOffset = rand()%2432+10;			
	insertWordsPBF(dev_bloom,bloomOptions_t.size,allKeys->currentWords,allKeys->positions,allKeys->numWords,allKeys->numBytes,bloomOptions_t.numHashes,bloomOptions_t.device,bloomOptions_t.prob,randOffset);
	freeWordAttributes(allKeys);
			
	//Query PBF
	sprintf(fileName,"./data/distinct_keys.txt");
	WordAttributes* distinctKeys = loadFileByName(fileName);
	int distinct_keys = distinctKeys->numWords;
	//printf("distinct keys = %d, total keys = %d\n",distinct_keys,total_keys);
	int* results = (int*)calloc(sizeof(int)*distinct_keys,sizeof(int));
	queryWordsPBF(dev_bloom,bloomOptions_t.size,distinctKeys->currentWords,distinctKeys->positions,distinctKeys->numWords,
distinctKeys->numBytes,bloomOptions_t.numHashes,bloomOptions_t.device,results);
	freeWordAttributes(distinctKeys);

	//Read the actual frequency of keys
	int* actual = (int*)calloc(sizeof(int)*distinct_keys,sizeof(int));
	FILE* actualFreqFile = fopen("./data/freq.txt","r");
	if(!actualFreqFile){
		printf("Can not open actual frequency file!\n");
		return -1;
	}
	for(int i = 0; i < distinct_keys; i++){
		char* temp = (char*)malloc(sizeof(char)*15);
		if(fgets(temp,15,actualFreqFile)!=NULL){
			int len = strlen(temp);
			temp[len-1]='\0'; 		
			actual[i]=atoi(temp);
			//printf("%d: actual = %d\n",i,actual[i]);
		}
		free(temp);
	}
	
	//Copy the bloom filter to main memory.
	//copyCharsToHost(bloom,dev_bloom,bloomOptions_t.size);

	//Write the result to output file
	//data format: index, number of 1s, calculated frequency, actual frequency, relative error
	if(bloomOptions_t.pbfOutput){
		FILE* outputFile = fopen(bloomOptions_t.pbfOutput,"w");
		writeStats(outputFile,actual,results,distinct_keys, bloomOptions_t.numHashes,bloomOptions_t.prob,total_keys,bloomOptions_t.size);
		fclose(outputFile);
	}
	
	free(fileName);
	free(actual);
	free(results);
	freeChars(dev_bloom);	
	free(bloom);
	//printf("\n");
	return 0;
}