Пример #1
0
int main() {
	int cho;
	char check,c,esc;
	
	system("clear");
	strcpy(filename,"pranav");
	while(1)
	{    	
		system("clear");
		printf(BOLDYELLOW"\n\n\n\n\n\t\t\t\t\t----------------------*******---------------------"RESET);
		printf(BOLDCYAN"\n\n\n\t\t\t\tHello !! Welcome to PRANAV's Library --- choose from the following menu"RESET);
		printf(YELLOW"\n\n\n\t\t\t\t\t1.Add Book Information"RESET);
		printf(YELLOW"\n\n\t\t\t\t\t2.Display Book Information"RESET);
		printf(YELLOW"\n\n\t\t\t\t\t3.Delete Book Information"RESET);
		printf(YELLOW"\n\n\t\t\t\t\t4.Search a Book "RESET);
		printf(YELLOW"\n\n\t\t\t\t\t5.Edit available book Information"RESET);
		printf(YELLOW"\n\n\t\t\t\t\t6.Exit from this menu"RESET);
		printf(BOLDYELLOW"\n\n\n\n\n\t\t\t\t\t----------------------*******---------------------"RESET);
		printf(BOLDCYAN"\n\n\t\t\t\t\t\t Your Choice:"RESET);
		scanf("%d",&cho);
		switch(cho)
		{
			case 1:
					Password();
					addbook();
					break;
			case 2:
					display_book(lib);
					sleep(2);
					break;
			case 3:
					Password();			
					delete_book(lib);
					sleep(2);
					break;
			case 4:
					search(lib);
					sleep(2);
					break;
			case 5:
					Password();
					edit_info(lib);
					break;
			case 6:
					exitp();
			default:
					printf(BOLDRED"\n\t\t\t\tChoose from following choices only \n"RESET);
					printf(RED"\t\t\tEnter 1 2 3 4 5 6 7"RESET);
		}
	}
}
Пример #2
0
int main(int argc, char* argv[])
{
    struct timeval begin, now;
    long counter;

    printf("\n -- EYEBOT Viewer -- \n\n");

    // Allocate buffers
    img_buffer = malloc(SIZE * CHANNELS);
    read_buffer = malloc(SIZE + PADDING);

    scaled_up_img = malloc(UP_S * CHANNELS);
    scaled_up_img_dbl = malloc(UP_S * CHANNELS);

    unsigned char b[4096];

    display = XOpenDisplay(NULL);
    visual = DefaultVisual(display, 0);
    
    window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, 320, 300, 1, 0, 0);
    XMapWindow(display, window);
    XFlush(display);

    if(visual->class!=TrueColor)
    {
        fprintf(stderr, "Cannot handle non true color visual ...\n");
        exit(1);
    }

    //XMapWindow(display, window);
    //XFlush(display);

    image = NULL;

    struct addrinfo hints, *res;
    int socket_fd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
    if(socket_fd == -1)
    {
        printf("Could not make a socket\n");
        return 1;
    }

    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_STREAM;
    getaddrinfo(SERVER_HOSTNAME, SERVER_PORT, &hints, &res);

    sleep(1);
    memset(b, 0, sizeof(b));
    sprintf(b, "Eyebot Line Follower - LiveEye");
    XSetForeground(display, DefaultGC(display, 0), 0x00ff0000); // red
    XDrawString(display, window, DefaultGC(display, 0), 10, 20, b, strlen(b));
    
    memset(b, 0, sizeof(b));
    sprintf(b, "Copyright (C) 2013 Andre Christensen and Jacob Pedersen");
    XSetForeground(display, DefaultGC(display, 0), 0x000000EF); // red
    XDrawString(display, window, DefaultGC(display, 0), 10, 35, b, strlen(b));

    XFlush(display);

    while (1)
    {
        printf("Connecting to EYEBOT! (%s:%s)\n", SERVER_HOSTNAME, SERVER_PORT);

        // Connect loop
        while (1)
        {
            if (connect(socket_fd, res->ai_addr, res->ai_addrlen) == -1)
            {
                sleep(1);
            } 
            else
            {
                printf("Connected!\n");
                break;
            }
        }

        // Two seconds of timeout. Useful so that recv doesn't wait 
        // forever to receive all its bytes.
        struct timeval tv;
        tv.tv_sec = 2;  
        tv.tv_usec = 0; 
        setsockopt(socket_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval));

        // Measure time at beginning
        counter = 0;
        gettimeofday(&begin, NULL);

        // Frame update loop
        while (1)
        {
            int bytes_read;
            int total = 0;
            unsigned int x = 0, y = 0, error, error_upper, mass;
            int l_x, l_y, u_x, u_y;

            fd_set fds;
            FD_ZERO(&fds);
            FD_SET(socket_fd, &fds);

            struct timeval timeout;
            timeout.tv_sec = 6 * 60;
            timeout.tv_usec = 0;

            if (select(sizeof(fds) * 8, &fds, NULL, NULL, &timeout) < 0)
            {
                exitp("select()");
            }

            if (read(socket_fd, &l_x, sizeof(l_x)) < 0)
            {
                exitp("read() (error x)");
            }

            if (read(socket_fd, &l_y, sizeof(l_y)) < 0)
            {
                exitp("read() (error y)");
            }

            if (read(socket_fd, &u_x, sizeof(u_x)) < 0)
            {
                exitp("read() (error x)");
            }

            if (read(socket_fd, &u_y, sizeof(u_y)) < 0)
            {
                exitp("read() (error y)");
            }

            if (read(socket_fd, &error, sizeof(error)) < 0)
            {
                exitp("read() (error)");
            }

            if (read(socket_fd, &error_upper, sizeof(error_upper)) < 0)
            {
                exitp("read() (error)");
            }


            if (read(socket_fd, &mass, sizeof(mass)) < 0)
            {
                exitp("read() (error mass)");
            }

            // Clear the read buffer
            memset(read_buffer, 0, SIZE);

            //
            // Read the 76800 bytes a frame consist of
            //
            
            bytes_read = recv(socket_fd, read_buffer, SIZE, MSG_WAITALL);
            if (bytes_read < 0)
            {
                perror("recv");
                break;
            }
            else if (bytes_read == SIZE)
            {
                copy_to_x_buffer(read_buffer, bytes_read);
                draw_center_point(l_x, l_y, 0, 0, 255);
                draw_center_point(u_x, u_y, 0, 255, 0);
                draw_center_lines();

                //upscale_image();

                if (image != NULL)
                {
                    XDestroyImage(image);
                }

                //upscale_image();
                //draw_center_point2(l_x, l_y, 0, 0, 255);
                //draw_center_point2(u_x, u_y, 0, 255, 0);
                //draw_center_lines2();

                //scaled_up_img_dbl = malloc(UP_S * CHANNELS);
                //memcpy(scaled_up_img_dbl, scaled_up_img, UP_S * CHANNELS);


                // Allocate a new buffer for next frame. 
                // The old one is freed by XDestroyImage
                img_disp_buffer = (unsigned char *) malloc(SIZE * CHANNELS);
                memcpy(img_disp_buffer, img_buffer, SIZE * CHANNELS);
                
                image = XCreateImage(display, visual, 24, ZPixmap, 0, img_disp_buffer, 320, 240, 32, 0);
                XPutImage(display, window, DefaultGC(display, 0), image, 0, 0, 0, 0, 320, 240);

                //image = XCreateImage(display, visual, 24, ZPixmap, 0, scaled_up_img_dbl, 640, 480, 32, 0);
                //XPutImage(display, window, DefaultGC(display, 0), image, 0, 0, 0, 0, 640, 480);

                // Clear text area
                XSetForeground(display, DefaultGC(display, 0), 0x00ffffff); 
                XFillRectangle(display, window, DefaultGC(display, 0), 0, 240, 320, 60);

                // memset(b, 0, sizeof(b));
                // sprintf(b, "Center: (%d, %d)", x,y);
                XSetForeground(display, DefaultGC(display, 0), 0x00ff0000); // red
                // XDrawString(display, window, DefaultGC(display, 0), 5, 260, b, strlen(b));

                memset(b, 0, sizeof(b));
                sprintf(b, "Error (upper): %d", error_upper);
                XDrawString(display, window, DefaultGC(display, 0), 5, 250, b, strlen(b));

                memset(b, 0, sizeof(b));
                sprintf(b, "Error (lower): %d", error);
                XDrawString(display, window, DefaultGC(display, 0), 5, 280, b, strlen(b));

                memset(b, 0, sizeof(b));
                sprintf(b, "Mass: %d", mass);
                XDrawString(display, window, DefaultGC(display, 0), 150, 250, b, strlen(b));


                // Calculate and display fps
                gettimeofday(&now, NULL);
                double  elapsed = (now.tv_sec - begin.tv_sec) * 1000.0;
                elapsed += (now.tv_usec - begin.tv_usec) / 1000.0;
                elapsed /= 1000.0;
                memset(b, 0, sizeof(b));
                sprintf(b, "FPS: %.2f", ((counter / elapsed) * 3));
                XDrawString(display, window, DefaultGC(display, 0), 150, 280, b, strlen(b));

                counter++;
            }
            else
            {   
                printf("Connection lost - retrying!\n");
                close(socket_fd);
                break;
            }
        }
    }

	printf("Closing the socket\n");
    if(close(socket_fd) == -1)
    {
    	printf("Could not close socket\n");
     	return 0;
    }
}
Пример #3
0
main()
{
	int winning[SIZE] = { 1, 3, 5, 7, 9, 11 }; // winning numbers + bonus

    register int i;
	char option;
	int pickedNumbers[SIZE];
    int freq[MAX+1] = {0}; // max is the highest number user can enter, so only MAX elements are needed in this array - MAX+1 so number is same as position - initially set to 0
    int num_match;
    int numbersEntered = 0; // false
    int b_match = 0; // bonus does not match

	//main program loop
	//
	do
    {
        system("cls");//clears the screen
        printf("Enter 1 - 5, or 0 to select an option from below:\n\n");

        printf("________________________________________________________________________________\n");
        printf("(1) Enter the 6 Numbers ( range: 1 - 42 )\n\n");
        printf("(2) Display the Entered Numbers\n\n");
        printf("(3) Display Numbers in Increasing Order\n\n");
        printf("(4) Did I Win?\n\n");
        printf("(5) Display Frequency of Numbers Entered\n\n");
        printf("(0) Exit Program\n");
        printf("________________________________________________________________________________\n\n");
        
        printf("Enter option:  ");
        scanf("%1s", &option);
        flushall();  // clear buffer
        
        system("cls");//clears the screen

        switch (option)
        {
        	case '1':
        	{
        		//get input
        		getInput(pickedNumbers, freq);
                numbersEntered++;
        		break;
        	}//end case 1
        	case '2':
        	{
                if ( numbersEntered == 0 )
                {
                    printf("**You did not Enter Your Numbers\n\n");
                }//end if

        		else // display numbers
        		{
                    displayInput(pickedNumbers);
        		}//end else
                break;
        	}//end case 2
        	case '3':
        	{
                if ( numbersEntered == 0 )
                {
                    printf("**You did not Enter Your Numbers\n\n");
                }
        		else // sort the numbers
        		{
                    sort(pickedNumbers);
        		}
                break;
        	}//end case 3
        	case '4':
        	{
                if ( numbersEntered == 0 )
                {
                    printf("**You did not Enter Your Numbers\n\n");
                }
        		else // see match
        		{
                    num_match = compare(pickedNumbers, winning);
                    
                    // check bonus
                    //
                    for ( i = 0; i < SIZE; i++ )
                    {
                        if ( *(pickedNumbers + i) == BONUS )
                        {
                            b_match++;
                            break; // dont check rest of numbers 
                        }//end if
                    }//end for

                    switch ( num_match )
                    {
                        case 3:
                        {
                            if ( b_match > 0 )
                                printf("You Won a Cinema Ticket\n");
                            else
                                printf("You Lost :(\n");
                            break;
                        }
                        case 4:
                        {
                            if ( b_match > 0 )
                                printf("You Won a Weekend Away\n");
                            else
                                printf("You Won a Night Out\n");
                            break;
                        }
                        case 5:
                        {
                            if ( b_match > 0 )
                                printf("You Won a New Car\n");
                            else
                                printf("You Won a Holiday\n");
                            break;
                        }
                        case 6:
                        {
                            printf("You Won the JACKPOT!!!\n");
                            break;
                        }
                        default:
                        {
                            printf("You Lost :(\n");
                        }
                    }//end switch
                    
        		}//end else
                break;
        	}//end case 4
        	case '5':
        	{
                if ( numbersEntered == 0 )
                {
                    printf("**You did not Enter Your Numbers\n");
                }//end if
        		else //get frequency
        		{
                    frequency( freq );
                }//end else
                break;
        	}//end case 5
        	case '0':
        	{
        		exitp();
        		break;
        	}//end case 0
        	default:
        	{
                system("cls");//clears the screen
                printf("**Error: Input value not valid\n\n");
            }
        }//end switch

        printf("\n\n**Press Enter to Continue");
        getchar();
    }//end do
    while ( option != '0' );
} //end main
Пример #4
0
int  main(int argc, char **argv){

    int rc,num_processors,rank;
    rc=MPI_Init(&argc,&argv);
    if (rc != MPI_SUCCESS) {
    	printf("Error starting MPI program. Terminating\n");
           MPI_Abort(MPI_COMM_WORLD, rc);
    }
   
    MPI_Comm_size(MPI_COMM_WORLD,&num_processors);
    MPI_Comm_rank(MPI_COMM_WORLD,&rank);

   //**************************************************************************************//
   //                  reading input information by all cores                              //
   //**************************************************************************************//
    FILE     *fpenergy=fopen("./energy","w"); // Print the energy evolution
    FILE     *fprestart=fopen("./restart","w"); //print the generation and popsize coordinates
    FILE     *fpoptim=fopen("./optim.xyz","wb");
    FILE     *fp=fopen("data.txt","r");
    time_t    current_time;
    double    seconds,start,end,seconds_new,seconds_old,seconds_total;
    struct    timespec now,tmstart;
    char*     c_time_string,c_time_final;
    int       flag_converge=0;
    int       i=0; 
   
    srand(time(NULL)+rank);
    clock_gettime(CLOCK_REALTIME, &tmstart);
    printf("hello from processor %ld\n",rank);
    start = (double)clock() /(double) CLOCKS_PER_SEC;
    seconds_old=  (double)(tmstart.tv_sec+tmstart.tv_nsec*1e-9);
    current_time = time(NULL);
    c_time_string = ctime(&current_time);
    printf("Current time is %s\n", c_time_string);
    printf("hello from processor %ld\n",rank);
   
 
    char skip[10];
    FILE     *fp_input2 = fopen("ga_dftb_input1.1","r");
    int       NSTEP=0;
    int       step=0;
    double    ee_mate=0 ;       // the energy cretiria for accepting children cluster. the larger, the less restrict. can be 0.1 0 or -0.1 
    double    ELITRATE=0.2;
    int       POPSIZE=0;
    int       min_step=0;
    int       NEWPOPSIZE=POPSIZE;
    double    delte=0.00001 ; //0.00001;
    int       ptnatm,runatm,cnatm;
    double    boxl=0;
    double    Mu=0.2;
    double    dptc;
    int       glob=0,globconvg=20;
    double    globe[30];
    int       Temp; 
    int       flag_res=0;
    double    cell[9];
    int       esize=0;
    int       num_cores_child;
      
    fscanf(fp_input2,"%d  %d %d %s\n", &ptnatm, &runatm,&cnatm,&skip);
    fscanf(fp_input2,"%d %s\n ", &POPSIZE,skip);
    fscanf(fp_input2,"%d %s\n", &NSTEP,skip);
    fscanf(fp_input2,"%d %s\n", &globconvg,skip);
    fscanf(fp_input2,"%lf %s\n",&ELITRATE,skip);
    fscanf(fp_input2,"%lf %s\n",&delte,skip);
    fscanf(fp_input2,"%d %s\n",&Temp,skip);
    fscanf(fp_input2,"%d %s\n",&min_step,skip);
    fscanf(fp_input2,"%lf %s\n",&ee_mate,skip);
    fscanf(fp_input2,"%lf %s\n",&dptc,skip);
    fscanf(fp_input2,"%lf %s\n",&boxl,skip);
    fscanf(fp_input2,"%d %s\n",&flag_res,skip);
    fscanf(fp_input2,"%d %s\n",&num_cores_child,skip);
    int ii=0;
    for (ii=0;ii<3;ii++){
        fscanf(fp_input2,"%lf %lf %lf\n", cell+ii*3+0,cell+ii*3+1,cell+ii*3+2);


   //**************************************************************************************//
   //         Above are the information that all processors need to know                   //
   //**************************************************************************************//

    if(rank==0){
        }
       
        printf("********************JOB started*****************************\n");
        printf("********************JOB started*****************************\n");
        printf("********************JOB started*****************************\n\n\n");


        printf("Attention!! The  dftb excutable file must be in ~/bin and must be named 'dftb+' !!\n");
        printf("Attention!! The  dftb excutable file must be in ~/bin and must be named 'dftb+' !!\n");
        printf("Attention!! The  dftb excutable file must be in ~/bin and must be named 'dftb+' !!\n");
        printf("Attention!! The  dftb excutable file must be in ~/bin and must be named 'dftb+' !!\n");
        printf("Attention!! The  dftb excutable file must be in ~/bin and must be named 'dftb+' !!\n");


        printf("Number of atoms %d %d %d\n", ptnatm,runatm,cnatm);
        if(ptnatm+runatm>=Max_Atom || cnatm>=CMax_Atom) exitp("Number of atoms exceed allowed Max!");
        printf("POPSIZE         %d\n",POPSIZE);
        printf("NSTEP           %d\n",NSTEP);
        printf("globconvg       %d\n",globconvg);
        printf("ELITRATE        %lf\n",ELITRATE);
        printf("delte           %lf\n",delte);
        printf("Temprature      %d\n",Temp);
        printf("minimiz   step  %d\n",min_step);
        printf("ee_mate         %lf\n",ee_mate);
        printf("dptc            %lf\n",dptc);
        printf("intial boxl     %lf\n",boxl);
        printf("reading from pt_coord?  %d\n",flag_res);
        printf("Total number of processsors required  %d\n",num_processors);
        printf("Number of processors for each child  %d\n",num_cores_child);
        printf("\n\n\n******** end reading input information ***********************\n\n\n");
    }
    if(POPSIZE!=num_processors/num_cores_child){
        printf("Error!,POPSZIE=%d num_processrs=%d num_cores_child=%d num_processrs/num_cores_child=%d",\
                POPSIZE,num_processors,num_cores_child,num_processors/num_cores_child);
        MPI_Abort(MPI_COMM_WORLD,0);
    }    

 
    ga_struct *population = malloc(sizeof(ga_struct)*POPSIZE);
    ga_struct *beta_population = malloc(sizeof(ga_struct)*POPSIZE);

 
//****************************************************************************************//
//define new mpi structure for data transfer between processors                           //
//****************************************************************************************//
    int count=4;
    int length[4]={1,3*Max_Atom,3*CMax_Atom,1};
    MPI_Aint offset[4]={offsetof(ga_struct,fitness),offsetof(ga_struct,gen),offsetof(ga_struct,cgen),offsetof(ga_struct,ep)} ;
    MPI_Datatype type[4]={MPI_DOUBLE,MPI_DOUBLE,MPI_DOUBLE,MPI_DOUBLE};
    MPI_Datatype popDatatype;
    MPI_Type_struct(count,length,offset,type,&popDatatype);
    MPI_Type_commit(&popDatatype);
//****************************************************************************************//


//****************************************************************************************//
//Initialization the population for all processors                                        // 
//****************************************************************************************//

    
    
    if(rank==0){
        printf("Total number of processors is %d\n",num_processors);
        printf("Total number of population is %d\n",POPSIZE);
        printf ("For each candidate, there are %d processors to be used\n",num_processors/POPSIZE);
        init_population(ptnatm+runatm,cnatm,POPSIZE,population,beta_population,boxl,flag_res);
        printf("argc=%d\n",argc);
//        int  i=0,j=0;
//        int  esize=POPSIZE*ELITRATE;
        cal_pop_energy(POPSIZE,population,ptnatm,runatm,cnatm,cell,argc, argv);
///        for (i=0;i<POPSIZE;i++){
////////      center(ptnatm+runatm,population[i].gen);  
///           write_coord(fpoptim,ptnatm,runatm,cnatm,population[i].gen,population[i].cgen,population[i].ep);
//           shift(ptnatm+runatm, population[i].gen,dptc);  
///        } 
//        for (i=0;i<POPSIZE;i++)
//           write_coord(fpoptim,ptnatm,runatm,cnatm,population[i].gen,population[i].cgen,population[i].ep);
        fflush(fpoptim);
    }

    char command[30];
    char filename[30];
 
    sprintf(command,"mkdir core%d",rank);
    system(command);
    sprintf(command,"cp dftb_in.hsd *.coord *.skf core%d",rank);
    system(command);
    sprintf(filename,"core%d",rank);
    chdir(filename);
    system("pwd");    

//****************************************************************************************//
//              Loop started                                                              // 
//****************************************************************************************//

    for (step=0;step<NSTEP;step++){ 


       //*********************************************************************************//
       //              master core preparation                                            // 
       //*********************************************************************************//

        if(rank==0){
            cal_pop_energy(POPSIZE,population,ptnatm,runatm,cnatm,cell, argc, argv);
            printf("\n\n\n\n***********************************************\n");
            printf(  "***********************************************\n");
            printf(  "***********************************************\n");
            printf("Gen= %d starting optimization..................\n\n",step); 
        
            qsort (population, POPSIZE, sizeof(ga_struct),sort_func);
        
            normal_fitness(POPSIZE,population);
        
            for(i=0;i<POPSIZE;i++){
                fprintf(fpenergy,"%d num %d   %lf\n",step, i,population[i].ep);
                fflush(fpenergy);
            }  
        
            printf("fabs %lf\n",fabs(population[0].ep-population[POPSIZE-1].ep));
        
            if(fabs(population[0].ep-population[POPSIZE-1].ep)<delte){    
                fprintf(fpenergy,"%d %lf  %lf global minimum \n",step,population[0].ep,population[0].fitness);
                globe[glob]=population[POPSIZE-1].ep;
                glob=glob+1;           
            }
        
            if(glob>20){
                if(fabs(globe[glob]-globe[glob-20])<delte){
                    fprintf(fpenergy,"%d %lf  %lf final global minimum \n",step,population[0].ep,population[0].fitness);
                    flag_converge=1;
                }
            }

///// PPreserve the first esize parentes from the previous generation. copy from population to beta_population
            esize=POPSIZE*ELITRATE;
            if (esize<1){esize=1;}
            elitism(esize,ptnatm+runatm, cnatm,population,beta_population);

            for (i=1;i<num_processors;i++)
                MPI_Send(population,POPSIZE,popDatatype,i,0,MPI_COMM_WORLD); 
        
            
               //send coordinates and energy information to other ith  processors
        }else MPI_Recv(population,POPSIZE,popDatatype,0,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE);

       //*********************************************************************************//
       //              master core preparation ended                                      // 
       //*********************************************************************************//



       //*********************************************************************************//
       //              other cores mating start                                           // 
       //*********************************************************************************//


       //receive coordinates and energy information from 0(master) core
        MPI_Bcast(&flag_converge, 1, MPI_INT,0,MPI_COMM_WORLD);
//        printf("rank=%d,xyz=%lf\n",rank,population[0].gen[0][0]);

        if(flag_converge ==1) {MPI_Finalize(); exit(0);}    
        
//        for (i=0;i<POPSIZE;i++)
//           write_coord(fpoptim,ptnatm,runatm,cnatm,population[i].gen,population[i].cgen,population[i].ep);
        fflush(fpoptim);
//        printf("rank=%d,xyz=%lf\n",rank,population[0].gen[0][0]);

       // Generate the rest part of beta_generation by mating process
        if(rank!=0&&rank<POPSIZE)
            mate(ptnatm,runatm,cnatm,cell,esize,POPSIZE,population,beta_population,Temp,ee_mate,dptc,min_step,argc, argv);
        MPI_Barrier(MPI_COMM_WORLD);
                       
        if(rank!=0&&rank<POPSIZE)
            MPI_Send(&beta_population[0],1,popDatatype,0,1,MPI_COMM_WORLD); //send the information of first children(optimized) from other processors to master core 

       //*********************************************************************************//
       //              other cores mating ended                                           // 
       //*********************************************************************************//
 


        if(rank==0){
            for (i=1;i<POPSIZE;i++)
                MPI_Recv(&population[i],1,popDatatype,i,1,MPI_COMM_WORLD,MPI_STATUS_IGNORE); //recieve coordinates and energy information to other ith  processors
            if (ptnatm!=0&&runatm!=0)
                mutate_perm (ptnatm,runatm, Mu, POPSIZE, beta_population);
            fprestart=fopen("./restart","w");
            for (i=0;i<POPSIZE;i++){
                write_coord(fpoptim,ptnatm,runatm,cnatm,population[i].gen,population[i].cgen,population[i].ep);
                write_coord(fprestart,ptnatm,runatm,cnatm,population[i].gen,population[i].cgen,population[i].ep);
                fflush(fpoptim);
                fflush(fprestart);
            } 
            fclose(fprestart);

         
        clock_gettime(CLOCK_REALTIME, &now);
        seconds_new = (double)((now.tv_sec+now.tv_nsec*1e-9));
        seconds=seconds_new-seconds_old;
        seconds_total = (double)((now.tv_sec+now.tv_nsec*1e-9) - (double)(tmstart.tv_sec+tmstart.tv_nsec*1e-9));
        printf("\nWall time for this generation is %lf s\n",seconds);
        printf("\nWall time totally  %lf s\n",seconds_total);
        seconds_old=seconds_new;
    
        }
 	  
   }




//*********************************************************************************
//************************************loop ended***********************************
//*********************************************************************************


    if(rank==0){ 
        printf("\n********************JOB FINISHED*****************************\n");
        fclose(fpenergy);
        fclose(fpoptim);
       
///////// time information
        current_time = time(NULL);
        c_time_string = ctime(&current_time);
        printf("Current time is %s\n", c_time_string);
        
         // measure elapsed wall time
        clock_gettime(CLOCK_REALTIME, &now);
        seconds = (double)((now.tv_sec+now.tv_nsec*1e-9) - (double)(tmstart.tv_sec+tmstart.tv_nsec*1e-9));
        printf("wall time %fs\n", seconds);
       
         // measure CPU  time
        end = (double)clock() / (double) CLOCKS_PER_SEC;
        printf("cpu time %fs\n", end - start);
        printf("\n********************JOB FINISHED*****************************\n");
        free(population);
        free(beta_population);
    }     
}