Example #1
0
int main(int argc, char ** argv) {
  char * secID;
  time_t t;

  unsigned int pagesize=getpagesize();
  setbuf(stdout,0);
  retBuffer=(unsigned char *)(((long)retBufferArea + pagesize-1) & ~(pagesize-1));
  if(mprotect(retBuffer, 1024, PROT_READ|PROT_EXEC|PROT_WRITE)) {
    printf("mprotect failed\n");
    return(1);
  }
  if (argc==1) srand((unsigned) time(&t));
  else {
    unsigned int seed=atoi(argv[1]);
    srand(seed);
  }
  getGrades(aGrades,ASIZE);
  getGrades(bGrades,BSIZE);
  getAvg(aGrades,ASIZE);
  getAvg(bGrades,BSIZE);

  printf("Choose section A or B: ");
  secID=getUserLine();
  printf("\n");
  
  if (secID[0]=='A') {
    printGrades(aGrades,ASIZE,100);
  } else if (secID[0]=='B') {
    printGrades(bGrades,BSIZE,200);
  } else {
    printf("Unable to determine which section you wanted.\n");
  }
  // free(retBufferArea);
  exit(0);
}
Example #2
0
void printGlobalStats(struct config* config) 
{
	pthread_mutex_lock(&stats_lock);
	{
		struct timeval currentTime;
		gettimeofday(&currentTime, NULL);
		double timeDiff = currentTime.tv_sec - global_stats.last_time.tv_sec + 1e-6*(currentTime.tv_sec - global_stats.last_time.tv_sec);
		double rps = global_stats.requests/timeDiff;
		double std = getStdDev(&global_stats.response_time);
		double q90 = findQuantile(&global_stats.response_time, .90);
		double q95 = findQuantile(&global_stats.response_time, .95);
		double q99 = findQuantile(&global_stats.response_time, .99);

		printf("%10s,%8s,%16s, %8s,%11s,%10s,%13s,%10s,%10s,%10s,%12s,%10s,%10s,%11s,%14s\n", 
			"timeDiff", "rps", "requests", "gets", "sets",  "hits", "misses", "avg_lat", "90th", "95th", "99th", "std", "min", "max", "avgGetSize");
		printf("%10f, %9.1f,  %10d, %10d, %10d, %10d, %10d, %10f, %10f, %10f, %10f, %10f, %10f, %10f, %10f\n", 
			timeDiff, rps, global_stats.requests, global_stats.gets, global_stats.sets, global_stats.hits, global_stats.misses,
			1000*getAvg(&global_stats.response_time), 1000*q90, 1000*q95, 1000*q99, 1000*std, 
			1000*global_stats.response_time.min, 1000*global_stats.response_time.max, getAvg(&global_stats.get_size));
		
		printf("Outstanding requests per worker:\n");
		for(int i=0; i<config->n_workers; i++){
			printf("%d ", config->workers[i]->n_requests);
		} 
		printf("\n");

		//Reset stats
		memset(&global_stats, 0, sizeof(struct memcached_stats));
		global_stats.response_time.min = 1000000;
		global_stats.last_time = currentTime;

		checkExit(config);
	}
	pthread_mutex_unlock(&stats_lock);
}
Example #3
0
void *getAvgThread(void *StructPtr) { 
    struct thread_args *args = StructPtr;
    int mylen = args->len;
    int *myarrPtr = args->arrPtr;
    getAvg(mylen, myarrPtr);
    pthread_exit(0);
}
Example #4
0
double Core::getJitter(QList<double> RTT){

    double mean = getAvg(RTT);
    double temp = 0;
    for(double a :RTT)
        temp += (mean-a)*(mean-a);
    temp = temp/RTT.size();
    return temp/2; //variance RTT/2 pour avoir jitter
}
Example #5
0
// сглаживание
void applySmooth(frGeomStrip* src){
	
	// Непосредственно сглаживание (в окрестности 30-ти точков)
	for( int i =  src->edgeA.size() *0.05; i < src->edgeA.size() * (1 - 0.05); i++){		// 0.05 вместо O_o - for smooth
		if( i < src->edgeA.size()){
			if( vertical ) {
				src->edgeA[i].x = getAvg(&(src->edgeA), i, 30);
				src->edgeB[i].x = getAvg(&(src->edgeB), i, 30);
			} else {
				src->edgeA[i].y = getAvg(&(src->edgeA), i, 30);
				src->edgeB[i].y = getAvg(&(src->edgeB), i, 30);
			}

		}

	}

}
Example #6
0
File: Q37.c Project: pain400/c_base
void Q37()
{
	puts(Question37);
	Stu stu;
	printf("Please input Student's No and his 8 score:\n");
	scanf("%s %f %f %f %f %f %f %f %f", stu.stuNo, &stu.class1, &stu.class2, &stu.class3, &stu.class4, &stu.class5, &stu.class6, &stu.class7, &stu.class8);
	getAvg(&stu);
	printf("No.%s student's avg score is: %5.2f\n", stu.stuNo, stu.avg);
	return 0;
}
void SmoothingMedianFilter::pushValue(double val)
{
  pthread_mutex_lock(&mutex);
  double avg = getAvg();
  if(val > avg + maxRange) val = avg + maxRange;
  else if(val < avg - maxRange) val = avg - maxRange;
  currentMedian = -1;
  data[nextInsert] = val;
  nextInsert = (nextInsert+1)%size;
  pthread_mutex_unlock(&mutex);
}
Example #8
0
double variance(std::vector<T> _vData) {

	double average = getAvg(_vData);

	double difference = 0;

	for (unsigned int i = 0; i < _vData.size(); i++) {
		difference += pow((average - _vData[i]), 2.0);
	}

	return difference;
}
Example #9
0
double standardDeviation(std::vector<T> _vData) {
	double average = getAvg(_vData);
	double standardDeviation = 0;

	double difference = 0;

	for (unsigned int i = 0; i < _vData.size(); i++) {
		difference += pow((average - _vData[i]), 2.0);
	}

	standardDeviation = sqrt(fabs(difference));
	return standardDeviation;
}
Example #10
0
int
main(){

        double sd = 0;
        double old_avg = (double) stats->system_time / stats->packets_served;
        double ratio = pow(stats->sd,2)+ pow(old_avg, 2);
        double old_avg_sqred = ratio * (double) stats->packets_served;
        double new_avg = getAvg(old_avg, elem, stats->packets_served);

        double firstTerm = (old_avg_sqred + pow(elem,2)) / (double)(stats->packets_served+1);
        double variance = firstTerm +  pow(new_avg,2);
        sd = sqrt(variance);

        return sd;
}
Example #11
0
int MyMpiQsort(array* myArray){
	int ProcNum=0,rank=0,color=0,count=0;
	ninja myNinja=NINJA_INIT;
	double lider=0.; //ведущий элемент
	MPI_Comm currentComm = MPI_COMM_WORLD;
	
	MPI_Comm_size(currentComm, &ProcNum);
	
	if(!isPowerOfTwo(ProcNum)){
		myerror=WRONG_PROC_NUMBER;
		return 0;
	}
	
	//Сортировка(пузырек)
	MyBubbleSort(myArray);
	
	//Сортировка(MPI_QSORT)
	while(ProcNum!=1){
		++count;
		MPI_Comm_rank(currentComm,&rank);		
		
		//Ведущий элемент
		lider=getAvg(myArray, currentComm);
		
		//Получаем ниндзя
		myNinja=getNinja(myArray,lider);
		
		//Обмениваемся данными и сливаем массивы
		MyQsortSwapAndMerge(myArray, &myNinja, rank, ProcNum, currentComm);
		
		//Помечаем процессы для разбиения на группы
		color=(rank<ProcNum/2)?0:1;
		MPI_Comm_split(currentComm,color,rank,&currentComm);
		MPI_Comm_size(currentComm,&ProcNum);
	}
	
	return count;
}
Example #12
0
double Core::getAvgDelay(QList<double> RTT){

    double mean = getAvg(RTT);
    mean /=2; //on divise RTT par 2 pour avoir la latence
    return mean;
}
Example #13
0
//解决第一个问题的函数
int work1(int _arr[],int _len)
{
    return getAvg(_arr, _len);
}
Example #14
0
void
analyze(char* fileName, OMRPortLibrary portLibrary)
{
	std::vector<double> mark_values;
	std::vector<double> sweep_values;
	std::vector<double> expand_values;
	std::vector<double> gcduration_values;

	pugi::xpath_node_set markTimes;
	pugi::xpath_node_set sweepTimes;
	pugi::xpath_node_set expandTimes;
	pugi::xpath_node_set gcTimes;

	double maxMark = 0;
	double minMark = 0;
	double avgMark = 0;

	double maxSweep = 0;
	double minSweep = 0;
	double avgSweep = 0;

	double maxExpand = 0;
	double minExpand = 0;
	double avgExpand = 0;

	double maxGCDuration = 0;
	double minGCDuration = 0;
	double avgGCDuration = 0;

	pugi::xml_document doc;
	pugi::xml_parse_result result = doc.load_file(fileName);

	OMRPORT_ACCESS_FROM_OMRPORT(&portLibrary);
	if(!result) {
		omrtty_printf("Error loading file : %s\n", fileName);
		return;
	} else {
		omrtty_printf("\nResults for : %s\n",fileName);
	}

	markTimes = doc.select_nodes(XPATH_GET_ALL_MARK_TIME);
	for (pugi::xpath_node_set::const_iterator it = markTimes.begin(); it != markTimes.end(); ++it) {
	    pugi::xpath_node node = *it;
	    double value = node.node().attribute("timems").as_double();
	    mark_values.push_back(value);
	}

	sweepTimes = doc.select_nodes(XPATH_GET_ALL_SWEEP_TIME);
	for (pugi::xpath_node_set::const_iterator it = sweepTimes.begin(); it != sweepTimes.end(); ++it) {
	    pugi::xpath_node node = *it;
	    double value = node.node().attribute("timems").as_double();
	    sweep_values.push_back(value);
	}

	expandTimes = doc.select_nodes(XPATH_GET_ALL_EXPAND_TIME);
	for (pugi::xpath_node_set::const_iterator it = expandTimes.begin(); it != expandTimes.end(); ++it) {
	    pugi::xpath_node node = *it;
	    double value = node.node().attribute("timems").as_double();
	    expand_values.push_back(value);
	}

	gcTimes = doc.select_nodes(XPATH_GET_TOTAL_GC_TIME);
	for (pugi::xpath_node_set::const_iterator it = gcTimes.begin(); it != gcTimes.end(); ++it) {
	    pugi::xpath_node node = *it;
	    double value = node.node().attribute("durationms").as_double();
	    gcduration_values.push_back(value);
	}

	if (!mark_values.empty()) {
		maxMark = *std::max_element(mark_values.begin(), mark_values.end());
		minMark = *std::min_element(mark_values.begin(), mark_values.end());
		avgMark = getAvg(mark_values);
	}

	if (!sweep_values.empty()) {
		maxSweep = *std::max_element(sweep_values.begin(), sweep_values.end());
		minSweep = *std::min_element(sweep_values.begin(), sweep_values.end());
		avgSweep = getAvg(sweep_values);
	}

	if (!expand_values.empty()) {
		maxExpand = *std::max_element(expand_values.begin(), expand_values.end());
		minExpand = *std::min_element(expand_values.begin(), expand_values.end());
		avgExpand = getAvg(expand_values);
	}

	if (!gcduration_values.empty()) {
		maxGCDuration = *std::max_element(gcduration_values.begin(), gcduration_values.end());
		minGCDuration = *std::min_element(gcduration_values.begin(), gcduration_values.end());
		avgGCDuration = getAvg(gcduration_values);
	}

	omrtty_printf("            Mark           Sweep          Expand        GCDuration\n");
	omrtty_printf("-------------------------------------------------------------------\n");
	omrtty_printf("Max     : %f        %f        %f        %f\n",
						maxMark, maxSweep, maxExpand, maxGCDuration);

	omrtty_printf("Min     : %f        %f        %f        %f\n",
								minMark, minSweep, minExpand, minGCDuration);

	omrtty_printf("Average : %f        %f        %f        %f\n\n",
								avgMark, avgSweep, avgExpand, avgGCDuration);
}