예제 #1
0
파일: app.c 프로젝트: gawallsibya/BIT_C-CPP
void Run()
{
	
	int i;
	while(1)
	{
		menu();
		printf("선택:");
		fflush(stdin);
		scanf("%d",&i);
		switch(i)
		{
		case 1:push_front();break;
		case 2:printall();break;
		case 3:search();break;
		case 4:change();break;
		case 5:dele();break;
		default:return;
		}
	}
}
예제 #2
0
void search()
{
	NODE *cur;
	char ch;	
	printall();
	printf("검색 문자:");
	fflush(stdin);
	scanf("%c",&ch);
	cur = find(ch);


	if (cur == NULL)
	{
		printf("데이터가 없습니다..\n");
	}
	else
	{
		printf("찾은 문자:%c, 주소 : %d\n",cur->data, &cur->data);
	}
	system("pause");
}
예제 #3
0
int main()
{
	struct Graph *node;
	int num,i,j,naddj,adj,s;
	printf("enter total number of node : ");
	scanf("%d",&num);
	node=create(num);
	for(i=0;i<num;i++)
	{
		printf("enter the no of adj for %d node",i);
		scanf("%d",&naddj);
		for(j=0;j<naddj;j++){
		printf("enter the  adj node as num: ");
		scanf("%d",&adj);
		insert(node,i,adj);
		}
	}
		display(node);
	printf("enter the source vertx");
	scanf("%d",&s);
	bfs_search(node,s);
	printall(node);

}
void binary_search_tree::printall(void)
{
    printall(root);
}
void *malloc(size_t size)
{
	printf("	[malloc]\n");
	if (size == 0) return NULL;
	/* initialize base and pos */
	if (pos == NULL) 
	{
		pos = base.next = &base;
		base.nunit = 0;
	}
	atom *ret;
	atom *itr;
	atom *prev;
	size_t unit = sizeof(atom);
	size_t n = (size - 1) / unit + 1; /* num of units required by user */
	size_t bsize = n * unit; /* bytes will be used by user */
	/* if base has been initialized, search for one block satisfies*/
	size_t i;
	prev = &base;
	pos = base.next;
	while (pos != &base)
	{
		if (pos->nunit >= n) break;
		prev = pos;
		pos = pos->next;
	}
/*	printf("	[malloc] break at %p\n", pos);*/
	/* if no enough space to return to user, 
		request memory from sys and return */
	/* if no space has been sbrked for malloc, request memory from sys */
	if (pos == &base)
	{
		printf("	[malloc] ->reqst bsize=%lu MB \n", bsize/1024/1024);
		ret = reqst(bsize, unit, n);
		if (ret == NULL) return NULL;
		ret++;
		printf("	[malloc] <-reqst return pointer at %p\n", ret);
		printall();
		return (void *)ret;
	}
	/* if enough space found, 
			size equals, return this block, 
			bigger than required, partition the later part of the block, reset metadata, and return the later part to user */
	if (pos != &base && pos->nunit > n) 
	{
		pos->nunit = pos->nunit - n - 1;
		itr = pos + pos->nunit + 1;
		itr->nunit = n;
		itr->next = NULL;
		ret = itr + 1;
/*		printf("[malloc] return %lu to user from pool ptr = %p cur pos unit=%lu\n", n, ret, pos->nunit);*/
		printall();
		return (void *)ret;
	}
	if (pos != &base && pos->nunit == n)
	{
		ret = pos + 1;
		prev->next = pos->next;
/*		printf("[malloc] return to user from pool block equlas need\n");*/
		printall();
		return (void *)ret;
	}
	return NULL;
}
예제 #6
0
파일: as2.c 프로젝트: Alecs94/DSA-lab
int main()
    {
        int x;
        FILE *f_in=fopen("input.dat","r");
        if (f_in == NULL)
        {
            perror("cannot open the file!");
        }

        FILE *f_out=fopen("output.dat","a");
        char option[15];

        while (fscanf(f_in,"%s",option)>0)
        {

            if (strcmp(option,"AF")==0)
            {
                fscanf(f_in,"%d",&x);
                addFirst(x);
            }

            if (strcmp(option,"AL")==0)
            {
                fscanf(f_in,"%d",&x);
                addLast(x);
            }

            if (strcmp(option,"DF")==0)
            {
                deleteFirst();
            }

            if (strcmp(option,"DL")==0)
            {
                deleteLast();
            }

            if (strcmp(option,"DOOM_THE_LIST")==0)
            {
                doom();
            }

            if (strcmp(option,"DE")==0)
            {
                fscanf(f_in,"%d",&x);
                delete_X(x);
            }

            if (strcmp(option,"PRINT_ALL")==0)
            {
                printall();
            }

            if (strcmp(option,"PRINT_F")==0)
            {
                fscanf(f_in,"%d",&x);
                print_first_X(x);
            }

           if (strcmp(option,"PRINT_L")==0)
            {
                fscanf(f_in,"%d",&x);
                print_last_X(x,f_out);
            }


        }

        fclose(f_in);
        fclose(f_out);


        return 0;
    }
예제 #7
0
mainwindow::mainwindow()
{
    // Interface Construction
    ui.setupUi(this);
    pt_mth = pt_type = -1;
    evt = isreset = 1;
    pdfpath = "./PDF/";
    lstroll = "";


    dt = QDate::currentDate().toString("dd.MM.yyyy");
    ui.date->setText(dt);

    mwsdt = new sdetails();
    // Scene Construction
    setdmscene();


    // Load Modules
    btable = new bulkprint(this,ui.tab_5);
    btable->show();
    selprint = new selectiveprint(this);
    setupmenu();


    // Start the Authentication Dialog
    AuthenDialog *authendialog = new AuthenDialog(this);
    authendialog->show();

    // Printer Info
    QPrinter print;
    QPrinterInfo pinfo(print);
    ui.pinfo->setText(pinfo.printerName());//.section("",-1,-1));

    // Fetch Printing Positions
    QFile file2("./positions.dat");
    file2.open(QIODevice::ReadOnly);
    QDataStream inp(&file2);
    inp >> lt;

    //set printer
    setprinter();

    //Connections
    connect(ui.bselback,SIGNAL(pressed()),selprint,SLOT(back()));
    connect(ui.bqreset,SIGNAL(pressed()),this,SLOT(breset()));
    connect(ui.bqprint,SIGNAL(pressed()),this,SLOT(qprint()));
    connect(ui.bbulkprintall,SIGNAL(pressed()),this,SLOT(bprintall()));
    connect(ui.bbulkselprint,SIGNAL(pressed()),this,SLOT(bprintsel()));
    connect(ui.bselnext,SIGNAL(released()),selprint,SLOT(next()));
    connect(ui.babortprint,SIGNAL(released()),this,SLOT(abortprint()));
    connect(ui.bpositions,SIGNAL(released()),this,SLOT(positionsdialog()));
    connect(ui.changeButton,SIGNAL(released()),this,SLOT(changepasswd()));

    connect(ui.leqroll,SIGNAL(textChanged(const QString &)),this,SLOT(rollchanged(const QString &)));
    connect(ui.leqsname,SIGNAL(textChanged(const QString &)),this,SLOT(snamechanged(const QString &)));
    connect(ui.leqfname,SIGNAL(textChanged(const QString &)),this,SLOT(fnamechanged(const QString &)));
    connect(ui.cbcourse,SIGNAL(currentIndexChanged(const QString &)),this,SLOT(coursechanged(const QString &)));
    connect(ui.cbbranch,SIGNAL(currentIndexChanged(const QString &)),this,SLOT(branchchanged(const QString &)));
    connect(ui.cbyear,SIGNAL(currentIndexChanged(const QString &)),this,SLOT(yearchanged(const QString &)));
    connect(ui.cbsem,SIGNAL(currentIndexChanged(const QString &)),this,SLOT(semchanged(const QString &)));
    //connect(ui.cbpl,SIGNAL(currentIndexChanged(const QString &)),this,SLOT(ptchanged(const QString &)));
    connect(ui.leqfrom,SIGNAL(textChanged(const QString &)),this,SLOT(fromchanged(const QString &)));
    connect(ui.leqto,SIGNAL(textChanged(const QString &)),this,SLOT(tochanged(const QString &)));
    connect(ui.lepurpose,SIGNAL(textChanged(const QString &)),this,SLOT(ppchanged(const QString &)));
    connect(ui.cbgen,SIGNAL(currentIndexChanged(int)),this,SLOT(genchanged(int)));
    connect(ui.modetab,SIGNAL(currentChanged(int)),this,SLOT(pmode(int)));


    connect(ui.ptcombo,SIGNAL(currentIndexChanged(QString)),ui.ltype,SLOT(setText(const QString &)));
    connect(ui.outbox,SIGNAL(currentIndexChanged(QString)),ui.lout,SLOT(setText(const QString &)));
    connect(ui.gbcno,SIGNAL(toggled(bool)),this,SLOT(cidtoggle(bool)));
    connect(ui.sbcno,SIGNAL(valueChanged (int)),this,SLOT(cidvalue(int)));
    connect(ui.actionQuit,SIGNAL(triggered()),this,SLOT(close()));
    connect(ui.actionAbout,SIGNAL(triggered()),this,SLOT(about_p()));
    connect(actionselprintall,SIGNAL(triggered()),selprint,SLOT(printall()));
    connect(actionselprintsel,SIGNAL(triggered()),selprint,SLOT(printsel()));
    connect(ui.actionPrint,SIGNAL(triggered()),this,SLOT(qprint()));
    connect(ui.actionReset,SIGNAL(triggered()),this,SLOT(reset()));

    ui.leqroll->setFocus();
    ui.lepurpose->setText("Bus Pass");
    qp1 = "select STUDENT_ID from student_admission where STUDENT_ROLLNO=";
    qp2 = "select student_name,father_name,gender from student_info where student_id=" ;
    qp3 = "select course,branch_id,current_sem,current_year from student_academic where student_id=" ;

}
		void printall(void){dev->printall();};
예제 #9
0
int main(int argc, char *argv[])
{
	//usage error check
	if(argc < 2) { printf("usage : ./server <port number>\n"); exit(1); }
	//make port number
	int server_port = atoi(argv[1]);
	
	//socket variables
	int chat_sd;
	int game_sd;
	int listen_sd;
	struct sockaddr_in addr;
	struct timeval timeout;
	fd_set select_result;
	int on=1;
	
	//pthread variables
	pthread_t thr;

	//etc variables
	int i, j, buf_len, rc;
	int x, y, winner;
	char buffer[4096];
	char smbuf[5];

	//server init
	listen_sd = socket(AF_INET, SOCK_STREAM, 0);
	if(listen_sd<0){printf("socket error\n"); exit(2);}
	rc = setsockopt(listen_sd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on));
	if(rc<0){printf("setsockopt error\n"); exit(2);}

	memset(&addr, 0, sizeof(addr));
	addr.sin_family 		= AF_INET;
	addr.sin_addr.s_addr 	= htonl(INADDR_ANY);
	addr.sin_port			= htons(server_port);

	rc = bind(listen_sd, (struct sockaddr *)&addr, sizeof(addr));
	if(rc < 0){printf("bind error\n"); exit(3);} 

	rc = listen(listen_sd, 32);
	if(rc < 0){printf("listen error\n"); exit(4);}

	init_set();
	add_to_set(listen_sd);

	//timeval init
	timeout.tv_sec = 3*60;
	timeout.tv_usec = 0;

	//Waiting client
	printf("Waiting client\n");
	chat_sd = accept(listen_sd, (struct sockaddr *)NULL, NULL);
	add_to_set(chat_sd);
	printf("accept chat_sd\n");

	game_sd = accept(listen_sd, (struct sockaddr *)NULL, NULL);
	add_to_set(game_sd);
	printf("accept game_sd\n");
	
	//ncurses init
	window=initscr();
	keypad(stdscr,TRUE);
	mousemask(BUTTON1_RELEASED, NULL);


	//game init
	initlog();
	init_board();
	while(1)
	{
		//your turn
		
		addlog(" < YOUR TURN > ", 3, 1);

		//make thread to check mouse
		pipe(pipefd);
		add_to_set(pipefd[0]);
		pthread_create(&thr, NULL, thr_mouse, NULL);
		while(1)
		{
			printall(1);
			memcpy(&select_result, &master_set, sizeof(master_set));
			rc = select(max_sd+1,&select_result, NULL,NULL, &timeout);
			if(rc<0) s_exit(5);
			if(rc==0) s_exit(6); //timecheck error
			if(FD_ISSET(game_sd, &select_result)) w_exit(-1);
			else if(FD_ISSET(pipefd[0],&select_result))
			{
				read(pipefd[0],smbuf,2);
				pthread_cancel(thr);
				y=smbuf[0];
				x=smbuf[1];
				board[y][x] = 1;
				send(game_sd,smbuf,2,0);
				if(winner = finish_board())
					w_exit(winner);
				break;

			}
			else if(FD_ISSET(chat_sd, &select_result))
			{
				rc = recv(chat_sd, buffer, 4096, 0);
				if(rc<0) s_exit(7);	//recv error
				if(rc == 0) w_exit(-1); //disconnected
				buffer[rc]='\0';
				addlog(buffer, 2, 1);
			}
		}
		//opp turn
		
		while(1)
		{
			printall(2);
			memcpy(&select_result, &master_set, sizeof(master_set));
			rc = select(max_sd+1, &select_result, NULL,NULL,&timeout);
			if(rc<0) s_exit(5);
			if(rc==0) s_exit(6); //timeout;
			if(FD_ISSET(game_sd, &select_result))
			{
				rc = recv(game_sd, smbuf,2 ,0);
				if(rc<0) s_exit(7); //recv error
				if(rc==0) w_exit(-1); //disconnected
				if(smbuf[0] == 't')
				{
					addlog("Opponent timeout", 3, 2);
					break;
				}
				else
				{
					y = smbuf[0];
					x = smbuf[1];
					board[y][x] = 2;
					if(winner = finish_board())
						w_exit(winner);
					break;
				}
			}
			else if(FD_ISSET(chat_sd, &select_result))
			{
				rc = recv(chat_sd, buffer, 4096,0);
				if(rc<0) s_exit(7);
				if(rc == 0) w_exit(-1);
				buffer[rc]= '\0';
				addlog(buffer, 2, 2);
			}
		}
	}
	
	s_exit(0);
}
예제 #10
0
int main (int argc, char *argv[]) {
	int rank, size;

	MPI_Init(&argc, &argv);
	MPI_Comm_size(MPI_COMM_WORLD, &size);
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
	MPI_Status status;
	if (argc < 4) {
		if (rank == ROOT) {
			fprintf(stderr, "Insufficient args\n");
			fprintf(stderr, "Usage: %s N input_file output_file", argv[0]);
		}
		MPI_Barrier(MPI_COMM_WORLD);
		MPI_Finalize();
		return 0;
	}

	int N = atoi(argv[1]), alloc_num, former_alloc_num=0, last_alloc_num=0;
	const char *inName = argv[2];
	const char *outName = argv[3];
	double start, finish, iotime = 0, commtime = 0, io_all, comm_all, cpu_all, cputime = 0, cpustart, cpufinish;
	int *root_ptr; // for root process (which rank == 0) only
  
	// Part 1: Read file
	/* Note: You should deal with cases where (N < size) in Homework 1 */
	int rc, i, trend = NOTSORTED;
	int *array;
	MPI_File fp;
	MPI_File fh;
	MPI_Offset my_offset;
	MPI_Request req;
	rc = MPI_File_open(MPI_COMM_WORLD, inName, MPI_MODE_RDONLY, MPI_INFO_NULL, &fp); 
	if(rc != MPI_SUCCESS){
		MPI_Abort(MPI_COMM_WORLD, rc);
	}
	MPI_Offset total_number_of_bytes;
	MPI_File_get_size(fp, &total_number_of_bytes);
	if(total_number_of_bytes/sizeof(int)<N){
		if(rank==ROOT)
			puts("N is bigger than testcase in input file, read to the end");
		N = total_number_of_bytes/sizeof(int);
	}
	// sheu
    // todo
    // detect whether the file is sorted
    //--------------------------------------------------------------------------------
	if(rank!=ROOT){
		MPI_File_open(MPI_COMM_WORLD, outName, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh);		
	}
	else{
		alloc_num = N;
		MPI_File_seek(fp,(MPI_Offset)0, MPI_SEEK_SET);
		array = (int*)malloc(sizeof(int)*alloc_num);
		start = MPI_Wtime();
		MPI_File_read(fp, array, alloc_num, MPI_INT, &status);
		finish = MPI_Wtime();
		iotime += finish-start;
		MPI_File_open(MPI_COMM_WORLD, outName, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh);		
		if(N>=2){
#ifdef DEBUG
			printall(array, alloc_num);
#endif
			if(array[0]>array[1])
				trend = -1;
			else if(array[0]==array[1])
				trend = 0;
			else
				trend = 1;
			for(i=2;i<alloc_num;i++){
				if(array[i-1]>array[i]&&(trend==-1||trend==0)){
					trend = -1;
					continue;
				}
				else if(array[i-1]==array[i]&&trend==0)
					continue;
				else if(array[i-1]<array[i]&&(trend==1||trend==0)){
					trend = 1;
					continue;
				}
				else{
					trend = NOTSORTED;
					break;
				}
			}
#ifdef DEBUG
			printf("%d\n", trend);
#endif
			if(trend==1||trend==0){
				printf("sorted file\n");
				my_offset = 0;
				printall(array, alloc_num);
				start = MPI_Wtime();
				MPI_File_write_at(fh, my_offset, array, alloc_num, MPI_INT, &status);
				finish = MPI_Wtime();
				iotime += finish - start;
				printf("iotime   : %8.5lf\ncommtime : %8.5lf\n",iotime,commtime);			
			}
			else if(trend==-1){
				printf("descending sorted file\n");
				root_ptr = (int*)malloc(sizeof(int)*alloc_num);
				for(i=0;i<alloc_num;i++){
					root_ptr[i] = array[alloc_num-i-1];
				}
				my_offset = 0;
				start = MPI_Wtime();
				MPI_File_write_at(fh, my_offset, root_ptr, alloc_num, MPI_INT, &status);
				finish = MPI_Wtime();
				iotime += finish - start;
				printf("iotime   : %8.5lf\ncommtime : %8.5lf\n",iotime,commtime);
			}
		}
		else{
			// N==1
			trend = 0;
			my_offset = 0;
			start = MPI_Wtime();
			MPI_File_write_at(fh, my_offset, array, alloc_num, MPI_INT, &status);
			finish = MPI_Wtime();
			iotime += finish - start;
			printf("iotime   : %8.5lf\ncommtime : %8.5lf\n",iotime,commtime);
			
		}
	}
	MPI_Barrier(MPI_COMM_WORLD);
	MPI_Bcast(&trend, 1, MPI_INT, ROOT, MPI_COMM_WORLD);
	if(trend==-1||trend==0||trend==1){
		MPI_Finalize();
		exit(0);
	}
	// read data in memory
	// sheu if N < 2 x  # of processes, root take over all computation
	
	alloc_num = N/size;
	if(2*size>N){
		// if N < 2 x size, root take over
		if(rank!=ROOT){			
			MPI_Finalize();
			exit(0);
		}
		else{
			alloc_num = N;
			MPI_File_seek(fp,(MPI_Offset)0, MPI_SEEK_SET);
			array = (int*)malloc(sizeof(int)*alloc_num);
			start = MPI_Wtime();
			MPI_File_read(fp, array, alloc_num, MPI_INT, &status);
			finish = MPI_Wtime();
			iotime = finish-start;
			cpustart = MPI_Wtime();
			singleOESort(array, alloc_num);
			cpufinish = MPI_Wtime();
			cputime = cpufinish - cpustart;
#ifdef DEBUG
			printall(array, alloc_num);      
#endif
			my_offset = 0;
			start = MPI_Wtime();
			MPI_File_write_at(fh, my_offset, array, alloc_num, MPI_INT, &status);
			finish = MPI_Wtime();
			iotime += finish - start;
			printf("iotime   : %8.5lfs\ncommtime : %8.5lfs\ncputime  : %8.5fs\n",iotime,commtime,cputime);
			MPI_Finalize();
			exit(0);
		}
	}
	else if((alloc_num)%2){
		// if alloc_num is odd number
		// every process alloc_num-- to guarantee every process has even elements
		// except last node
		alloc_num--;
		former_alloc_num = alloc_num;
		MPI_File_seek(fp,(MPI_Offset)alloc_num*rank*sizeof(int), MPI_SEEK_SET);
		if(rank==size-1){
			alloc_num = N - alloc_num * rank;
		}
		last_alloc_num = N - alloc_num * rank;
		array = (int*)malloc(sizeof(int)*alloc_num);
		start = MPI_Wtime();
		MPI_File_read(fp, array, alloc_num, MPI_INT, &status);
		finish = MPI_Wtime();
		iotime += finish-start;
	}
	else{
		// last process need deal with more inputs
		former_alloc_num = alloc_num;
		MPI_File_seek(fp, (MPI_Offset)rank*alloc_num*sizeof(int), MPI_SEEK_SET);
		if(rank==size-1){			
			alloc_num = N - alloc_num * rank;
		}	
		last_alloc_num = N - alloc_num * rank;
		array = (int*)malloc(sizeof(int)*alloc_num);
		start = MPI_Wtime();
		MPI_File_read(fp, array, alloc_num, MPI_INT, &status);
		finish = MPI_Wtime();
		iotime += finish-start;
	}
	
	// sheu
	// todo
	// sort and communicate with other
	//--------------------------------------------------------------------------------
	int tmp1,tmp2,sorted_temp,count=0;
	int sorted=0;
#ifdef DEBUG
	int *num_ptr, *pos_ptr; 
	if(rank==ROOT){
		root_ptr = (int*)calloc(0,sizeof(int)*N);	
		num_ptr = (int*)malloc(sizeof(int)*size);
		pos_ptr = (int*)malloc(sizeof(int)*size);
		for(i=0;i<size;i++){
			num_ptr[i] = former_alloc_num;
			pos_ptr[i] = i * former_alloc_num;
		}
		num_ptr[size-1] = last_alloc_num;
	}
#endif
	cpustart = MPI_Wtime();
	while(!sorted){
		sorted=1;
		for(i=0;i+1<alloc_num;i+=2){
			if(array[i]>array[i+1]){
				swap(&array[i],&array[i+1]);
				sorted = 0;
			}
		}
		for(i=1;i<alloc_num;i+=2){
			if(i==alloc_num-1){
				start = MPI_Wtime();
				// has even elements, which is guaranteed but last process
			
				// send to rank+1, last node do nothing
				if(rank!=size-1){
					MPI_Isend(&array[i],1,MPI_INT,rank+1,0,MPI_COMM_WORLD,&req);
				}
				// receive from rank-1, root node do nothing
				if(rank!=ROOT){
					MPI_Recv(&tmp1,1,MPI_INT,rank-1,MPI_ANY_TAG,MPI_COMM_WORLD,&status);  
				}
				if(array[0]<tmp1&&rank!=ROOT){
					swap(&array[0],&tmp1);
					sorted = 0;
				}
				// tmp1 will always be smaller
				if(rank!=size-1)
					MPI_Wait(&req, MPI_STATUS_IGNORE);
				// send to rank-1, root node do nothing
				if(rank!=ROOT){
					MPI_Isend(&tmp1,1,MPI_INT,rank-1,0,MPI_COMM_WORLD, &req);
				}
				// receive from rank+1, last node do nothing
				if(rank!=size-1){
					MPI_Recv(&tmp2,1,MPI_INT,rank+1,MPI_ANY_TAG,MPI_COMM_WORLD,&status);
				}
				if(array[i]>tmp2&&rank!=size-1){
					swap(&array[i],&tmp2);
					sorted = 0;
				}
				if(rank!=ROOT)
					MPI_Wait(&req, MPI_STATUS_IGNORE);
				finish = MPI_Wtime();
				commtime += finish - start;
				continue;
			}
			else if(array[i]>array[i+1]){
				swap(&array[i],&array[i+1]);
				sorted = 0;
			}
			if(rank==size-1&&alloc_num%2&&i==alloc_num-2){
				start = MPI_Wtime();
				// has odd elements, only in last process
				MPI_Recv(&tmp1,1,MPI_INT,rank-1,MPI_ANY_TAG,MPI_COMM_WORLD,&status);        
				if(array[0]<tmp1){
					swap(&array[0],&tmp1);
					sorted = 0;
				}
				MPI_Isend(&tmp1,1,MPI_INT,rank-1,0,MPI_COMM_WORLD,&req);
				finish = MPI_Wtime();
				commtime += finish - start;
			}
		}
		start = MPI_Wtime();
		MPI_Allreduce(&sorted,&sorted_temp,1,MPI_INT,MPI_LAND,MPI_COMM_WORLD);
		finish = MPI_Wtime();
		commtime += finish - start;
		sorted = sorted_temp;
		count++;
		/*if(count>2*N){
			printf("quite weird, I can't finish");
			break;
		}*/
	}
	cpufinish = MPI_Wtime();
	cputime = cpufinish - cpustart - commtime;
#ifdef DEBUG
	MPI_Barrier(MPI_COMM_WORLD);
	printall(array,alloc_num);
	MPI_Gatherv(array, alloc_num, MPI_INT, root_ptr, num_ptr, pos_ptr, MPI_INT, ROOT, MPI_COMM_WORLD);
	if(rank==ROOT){
		printall(root_ptr, N);
	}
#endif
	my_offset = rank*former_alloc_num*sizeof(int);
	start = MPI_Wtime();
	MPI_File_write_at(fh, my_offset, array, alloc_num, MPI_INT, &status);
	finish = MPI_Wtime();
	iotime += finish - start;
	MPI_Allreduce(&iotime,&io_all,1,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD);
	MPI_Allreduce(&commtime,&comm_all,1,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD);
	MPI_Allreduce(&cputime,&cpu_all,1,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD);
	io_all /= size;
	comm_all /= size;
	if(rank==ROOT)
		printf("iotime   : %8.5lfs\ncommtime : %8.5lfs\ncputime  : %8.5lfs(sum)\n",io_all ,comm_all, cpu_all);
	MPI_Finalize();
	return 0;
}