Exemplo n.º 1
0
void check_src(char* filename)
{
	if(access(filename,F_OK)!=-1)
	{
		printf("deleting file:%s...\n",filename);
		if(-1==unlink(filename))
			perror("unlink error");
	}
	create_big_file(filename);
}
void test2() {
  int i;
  create_big_file("test2file");
  unsigned char key[KEY_LENGTH];
  for (i = 0; i < KEY_LENGTH; ++i) key[i] = (unsigned char) (110 - i);

  for (i = 1; i <= 3; ++i) {
    int p2fd;
    pyramid* p = openit("test2file", &p2fd, key, i);
    print_ids(p, 2);
    closeit(p2fd, p, i);
  }
  
}
void test3() {
  int i;
  unsigned char key[KEY_LENGTH];
  for (i = 0; i < KEY_LENGTH; ++i) key[i] = (unsigned char) (rand() % 256);
  create_big_file("test3file");
  for (i = 1; i <= 3; ++i) {
    int p3fd;
    pyramid *p = openit("test3file", &p3fd, key, i);
    print_ids(p, 3);
    move_id_in_pyramid(p, p, randomly_select_id_pyramid(p));
    move_id_in_pyramid(p->next_level, p, randomly_select_id_pyramid(p->next_level));
    move_id_in_pyramid(p->next_level->next_level, p, randomly_select_id_pyramid(p->next_level->next_level));
    print_ids(p, 3);
    closeit(p3fd, p, i);
  }
}
Exemplo n.º 4
0
int main(int argc, char *argv[]) {
	int nb_threads = atoi(argv[3]);
	int blocksize = atoi(argv[2]);
	int index;
	char filename[6];
	char* mode = argv[1];
	int i = 0;
	double latency, throughput;
	double  avg_latency = 0, avg_throughput = 0, total_throughput = 0;	
	ThreadData thread[nb_threads];
	ThreadData empty_loop;
	pthread_t empty_loop_id;	
	int random_int;
	int re;
		
	srand(time(NULL));	
	random_int = rand()%(MAX_SIZE-blocksize);
	
	
	/* Detect mode betweem Write/Sequential, Write/Random, Read/Sequential, Read/Random */
	index = detect_mode(mode);
	printf("\nBLOCKSIZE : %d B\n",blocksize);
	printf("THREADS   : %d",nb_threads);
	printf("\n=======================================\n\n");

	/* Creating blocksize if needed */
	for(i=0; i < nb_threads; i++){
		if(index ==2 || index == 3){
			snprintf(filename,sizeof(filename),"temp%d",i);	
			create_big_file(filename);
		}
		else{	
			snprintf(filename,sizeof(filename),"temp%d",i);
		}
	}
	sleep(1);

	/* Calculating empty loop_size latency*/
	if(blocksize != 1){
		empty_loop.blocksize = blocksize/nb_threads;
	}
	else{
		empty_loop.blocksize = blocksize;
	}
	empty_loop.diff = 0;
	pthread_create(&empty_loop_id,NULL,loop_time,(void *) argv);
	pthread_join(empty_loop_id, NULL);

	/* Creating threads */		
	for(i=0; i < nb_threads; i++){
		/* Updating thread[i] structure */
		snprintf(filename,sizeof(filename),"temp%d",i);
		strncpy(thread[i].filename,filename,sizeof(filename));
		if(blocksize != 1){
			thread[i].blocksize = blocksize/nb_threads;
		}
		else{
			thread[i].blocksize = blocksize;
		}
		thread[i].random_int = random_int;
		thread[i].diff = 0;
		
		/* Determining thread to be created (Write, Sequential, Sequential, Random) */
		switch(index){	
		case 0:
			re = pthread_create(&(thread[i].thread_id),NULL,write_seq_file,(void *)(&thread[i]));
			break;
		case 1:
			re = pthread_create(&(thread[i].thread_id),NULL,write_ran_file,(void *)(&thread[i]));
			break;
		case 2:
			re = pthread_create(&(thread[i].thread_id),NULL,read_seq_file,(void *)(&thread[i]));
			break;
		case 3:
			re = pthread_create(&(thread[i].thread_id),NULL,read_ran_file,(void *)(&thread[i]));
			break;		
		default:
			return 0;
			break;
		}
		if(re == -1){
			printf("Error creating thread %d",i+1);
		}
		else{
			printf("Thread %d/%d created.\n",i+1,nb_threads);
		}
	}
	
	printf("---------------------------------------\n\n");
	
	/* Wait for all the threads to complete */
	for(i=0; i < nb_threads; i++){
		pthread_join(thread[i].thread_id, NULL);
	}
	sleep(1);

	/* Calculating and printing  throughput and latency for each thread */
	for(i=0; i < nb_threads; i++){
		latency = ((thread[i].diff)-empty_loop.diff); //We substract the empty loop latency
		throughput = (thread[i].blocksize/1000000.0)/latency;
		avg_latency +=latency;	
		total_throughput += throughput;
		printf("Thread      : %d\n", i+1);
		printf("Blocksize   : %d B\n", thread[i].blocksize);
		printf("Latency     : %.5f ms\n",(latency*1000));
		printf("Throughput  : %.2f MB/s\n\n",throughput);
	}

	/* Calculating average throughput and latency */
	avg_latency /= nb_threads;
	avg_throughput = total_throughput/nb_threads;	
	printf("---------------------------------------\n");
	printf("Average latency     : %.5f ms\n", (avg_latency*1000));
	printf("Average throughput  : %.5f MB/s\n", avg_throughput);
	printf("Total throughput    : %.2f MB/s", total_throughput);
	printf("\n---------------------------------------\n");

	return 0;
}