Beispiel #1
0
int main()
{
	G G;
	char a[5000];
	char cmd;

	int vcount;
	
	int eline[5000];
	char *split = " E{<,>}";
	char *p;

	int i;
	int j;
	int start;
	int end;
	
	while(fgets(a,5000,stdin)){
		cmd = a[0];
		if(cmd=='V'){
			sscanf(a,"V %d",&vcount);
			Delete(&G);			
			InitV(&G,vcount);
		}
		else if(cmd=='E'){
			// transfer input into array
			i=0;
			j=0;
			p = strtok(a,split);
			while(p!=NULL) {
				sscanf(p,"%d",&eline[i]);
				//printf("%d ",eline[i]);
				p = strtok(NULL,split);
				i=i+1;
			}
			// check array
			for(j=0;j<i-1;j=j+2){
				if(CheckEdgeInit(&G,eline[j],eline[j+1])==0){
					fflush(stdout);
					break;
				}
			}
			if(j<i-1){
				Delete(&G);
				continue;
				
			}else{
				//  init edge
				InitE(&G,eline,i-1);
				if(G.ecount>0){
					VertexCover(&G);
				}
			}
			//printG(&G);
		}
	}
	return 0;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
	G G;
	char a[5000];
	char cmd;
	int vcount;	
	int eline[5000];
	char *split = " E{<,>}";
	char *p;
	int i,j,k,k2=0,k3=0,k2n=10,k3n=1;

	int thread_flag=0;

	//void* vnum_1;
	//void* vnum_2;
	//void* vnum_3;

	int	s;
	long	time_out[3][10][10]={0};
	float	rate_out[3][10];

	if(argc>1){
		int param = atoi(argv[1]);
		int pfd_gen[2];
		if(pipe(pfd_gen)== -1){
			perror("pipe_gen");
			exit(1);
		}		
		
		for(k=0;k<k2n;k++){
			//sleep(1);
			pid_t gen=fork();
			if(gen == 0){
				close(pfd_gen[0]);
				dup2(pfd_gen[1],STDOUT_FILENO);
				execvp("/home/wdietl/graphGen/graphGen", argv);
			}
		}
		
		close(pfd_gen[1]);
		dup2(pfd_gen[0],STDIN_FILENO);
		
		while(fgets(a,5000,stdin)){
			printf("%s",a);
			cmd = a[0];
			if(cmd=='V'){
				sscanf(a,"V %d",&vcount);
				Delete(&G);			
				InitV(&G,vcount);
			}
			else if(cmd=='E'){
				// transfer input into array
				i=0;
				j=0;
				p = strtok(a,split);
				while(p!=NULL) {
					sscanf(p,"%d",&eline[i]);
					p = strtok(NULL,split);
					i=i+1;
				}
				// check array
				for(j=0;j<i-1;j=j+2){
					if(CheckEdgeInit(&G,eline[j],eline[j+1])==0){
						fflush(stdout);
						break;
					}
				}
				if(j<i-1){
					Delete(&G);
					continue;
					
				}else{
					printf("k2:%d\n",k2);
					//  init edge
					InitE(&G,eline,i-1);
						
					for(k3=0;k3<k3n;k3++){
						//cnf_sat time
						
						pthread_t cnf_sat;
						//cid=0;
						pthread_create(&cnf_sat,NULL,&CNF_SAT,&G);
						s=pthread_getcpuclockid(cnf_sat, &cid);
						if (s != 0)
							handle_error_en(s, "pthread_getcpuclockid");
						pthread_join(cnf_sat,NULL);
						/*
						struct timespec ts1_1;
						clock_gettime(cid_1, &ts1);
						printf("%ld,%ld,%ld\t",ts1.tv_sec,ts1.tv_nsec,ts1.tv_nsec/1000);
						//pclock("cnf_sat:    ", cid_1);
						*/
						time_out[0][k2][k3]=time1;
						sleep(1);

						
						//approx_1 time
						pthread_t approx_1;
						//cid=0;
						pthread_create(&approx_1,NULL,&Approx_1,&G);
						s=pthread_getcpuclockid(approx_1, &cid);
						if (s != 0)
							handle_error_en(s, "pthread_getcpuclockid");
						pthread_join(approx_1,NULL);
						/*
						struct timespec ts2;
						clock_gettime(cid_2, &ts2);
						printf("%ld,%ld,%ld\t",ts2.tv_sec,ts2.tv_nsec,ts2.tv_nsec/1000);
						//pclock("approx_1:    ", cid_2);
						*/
						time_out[1][k2][k3]=time2;
						sleep(1);
						
						
						//approx_2 time
						pthread_t approx_2;
						//cid=0;
						pthread_create(&approx_2,NULL,&Approx_2,&G);
						s=pthread_getcpuclockid(approx_2, &cid);
						if (s != 0)
							handle_error_en(s, "pthread_getcpuclockid");
						pthread_join(approx_2,NULL);
						/*
						struct timespec ts3;
						clock_gettime(cid_3, &ts3);
						printf("%ld,%ld,%ld\n",ts3.tv_sec,ts3.tv_nsec,ts3.tv_nsec/1000);
						//pclock("approx_2:    ", cid_3);
						*/
						time_out[2][k2][k3]=time3;
						sleep(1);
						
					}
					
					rate_out[0][k2]=(float)vnum_1;
					rate_out[1][k2]=(float)vnum_2/(float)vnum_1;
					rate_out[2][k2]=(float)vnum_3/(float)vnum_1;
					

					
					printf("rate_out_1:%f\n",rate_out[1][k2]);
					printf("rate_out_2:%f\n",rate_out[2][k2]);
					printf("rate_vunm_1:%d\n",vnum_1);
					printf("rate_vunm_2:%d\n",vnum_2);
					printf("rate_vunm_3:%d\n",vnum_3);
					
					
					if(k2>=k2n-1){
						//print time , aver , devi
						
						printf("cnf_sat time:\n");
						deviation_time(param,time_out,0,k2n,k3n);
						printf("approx_1 time:\n");
						deviation_time(param,time_out,1,k2n,k3n);
						printf("approx_2 time:\n");
						deviation_time(param,time_out,2,k2n,k3n);

						//print rate , aver , devi
						deviation_rate(param,rate_out,k2n);
					}
					
					k2++;
					

				}
				//printG(&G);
			}
		}
	}

	return 0;
}
Beispiel #3
0
void InitT(P_transform* t, float px, float py, float sx,float sy){

	InitV(&t->position,px,py);
	InitV(&t->scale,sx,sy);
}
Beispiel #4
0
void init()
{
    int i,p,wsp,wan;
    double dp,dM,dum,dum1;
    double kappa,R,R1,R2;

    /****************************************************
                   Correct_Position_flag
    ****************************************************/

    Correct_Position_flag = 0;

    /****************************************************
                        force flag
    ****************************************************/

    F_Kin_flag    = 1;
    F_NL_flag     = 1;
    F_VNA_flag    = 1;
    F_VEF_flag    = 1;
    F_dVHart_flag = 1;
    F_Vxc_flag    = 1;
    F_U_flag      = 1;
    F_dftD_flag   = 1; /* okuno */

    /****************************************************
                  Setting of atomic weight
    ****************************************************/

    for (i=1; i<=atomnum; i++) {
        wsp = WhatSpecies[i];

        if (0.0<Spe_AtomicMass[wsp]) {
            Gxyz[i][20] = Spe_AtomicMass[wsp];
        }
        else {
            wan = Spe_WhatAtom[wsp];
            Gxyz[i][20] = Atom_Weight[wan];
        }
    }

    InitV();

    /* set Beta */

    Beta = 1.0/kB/E_Temp;

    /****************************************************
     (1+(1+x/n)^n)^{-1}
     Complex poles for the modified Matsubara summation
    ****************************************************/

    /*
    dM = POLES*1.000;
    dp = -1.0;
    dum1 = 0.5*PI/dM;
    Beta = 1.0/kB/E_Temp;

    for (p=0; p<POLES; p++){
      dp = dp + 1.0;
      dum = (2.0*dp+1.0)*dum1;
      zp[p] = Complex(cos(dum),sin(dum));
      Ep[p] = Complex(2.0*dM/Beta*(zp[p].r-1.0),2.0*dM/Beta*zp[p].i);
    }
    */


    /****************************************************
    CONTINUED FRACTION
    zero points and residues for the continued fraction
    expansion of exponential function used in integration
    of Green's functions with Fermi-Dirac distribution
    ****************************************************/

    if (Solver==1) {

        zero_cfrac( POLES, zp, Rp );

        /*
        for (p=0; p<(POLES-1); p++){
          printf("%5d %15.12f %15.12f %15.12f\n",p+1,zp[p].i,zp[p+1].i-zp[p].i,Rp[p].r);
        }
        */

        for (p=0; p<POLES; p++) {
            Ep[p].r = 0.0;
            Ep[p].i = zp[p].i/Beta;
        }
    }

    /**********************************************************
                   O(N^2) cluster diagonalization
    **********************************************************/

    if (Solver==9) {

        ON2_Npoles_f = ON2_Npoles;

        /************************************
          for calculation of density matrix
        ************************************/

        /* set up poles */

        zero_cfrac( ON2_Npoles, ON2_zp, ON2_Rp );

        for (p=0; p<ON2_Npoles; p++) {
            ON2_method[p] = 1;
        }

        /* for the zero-th moment */

        R = 1.0e+10;

        ON2_zp[ON2_Npoles].r = 0.0;
        ON2_zp[ON2_Npoles].i = R;

        ON2_Rp[ON2_Npoles].r = 0.0;
        ON2_Rp[ON2_Npoles].i = 0.5*R;

        ON2_method[ON2_Npoles] = 2;

        ON2_Npoles++;

        /*
        for (p=0; p<ON2_Npoles; p++){
          printf("p=%5d zp %15.12f %15.12f Rp %15.12f %15.12f\n",
                  p,ON2_zp[p].r,ON2_zp[p].i,ON2_Rp[p].r,ON2_Rp[p].i);
        }
        */

        /*
        for (p=0; p<Npoles_ON2; p++){
          Ep[p].r = 0.0;
          Ep[p].i = zp[p].i/Beta;
        }
        */

        /*********************************************
          for calculation of energy density matrix
        *********************************************/

        /* calculation of kappa */

        kappa = 0.0;
        for (p=0; p<ON2_Npoles_f; p++) {
            kappa += ON2_Rp[p].r;
        }
        kappa = 4.0*kappa/Beta;

        /* set up poles */

        for (p=0; p<ON2_Npoles_f; p++) {
            ON2_zp_f[p] = ON2_zp[p];
            ON2_Rp_f[p] = ON2_Rp[p];
            ON2_method_f[p] = 1;
        }

        /* for the zero-th order moment */

        if (0) {

            R = 1.0e+8;

            ON2_zp_f[ON2_Npoles_f].r = 0.0;
            ON2_zp_f[ON2_Npoles_f].i = R;

            ON2_Rp_f[ON2_Npoles_f].r = 0.25*R*(kappa - R);
            ON2_Rp_f[ON2_Npoles_f].i = 0.25*R*(kappa + R);

            ON2_method_f[ON2_Npoles_f] = 2;
            ON2_Npoles_f++;

            /* for the 1st order moment */

            ON2_zp_f[ON2_Npoles_f].r = -R;
            ON2_zp_f[ON2_Npoles_f].i = 0.0;

            ON2_Rp_f[ON2_Npoles_f].r = 0.25*R*(R - kappa);
            ON2_Rp_f[ON2_Npoles_f].i = 0.25*R*(R - kappa);

            ON2_method_f[ON2_Npoles_f] = 2;
            ON2_Npoles_f++;

        }


        if (0) {

            R1 = 1.0e+21;
            R2 = 1.0e+7;

            ON2_zp_f[ON2_Npoles_f].r = 0.0;
            ON2_zp_f[ON2_Npoles_f].i = R1;

            ON2_Rp_f[ON2_Npoles_f].r = 0.5*R1*R2;
            ON2_Rp_f[ON2_Npoles_f].i = 0.5*R1*kappa;

            ON2_method_f[ON2_Npoles_f] = 2;
            ON2_Npoles_f++;

            /* for the 1st order moment */

            ON2_zp_f[ON2_Npoles_f].r = 0.0;
            ON2_zp_f[ON2_Npoles_f].i = R2;

            ON2_Rp_f[ON2_Npoles_f].r =-0.5*R2*R2;
            ON2_Rp_f[ON2_Npoles_f].i = 0.0;

            ON2_method_f[ON2_Npoles_f] = 2;
            ON2_Npoles_f++;
        }


        R = 1.0e+7;

        ON2_zp_f[ON2_Npoles_f].r = 0.0;
        ON2_zp_f[ON2_Npoles_f].i = R*R;

        ON2_Rp_f[ON2_Npoles_f].r = 0.5*R*R*R*R/(R-1.0);
        ON2_Rp_f[ON2_Npoles_f].i = 0.5*R*R*R*kappa/(R-1.0);

        ON2_method_f[ON2_Npoles_f] = 2;
        ON2_Npoles_f++;

        /* for the 1st order moment */

        ON2_zp_f[ON2_Npoles_f].r = 0.0;
        ON2_zp_f[ON2_Npoles_f].i = R;

        ON2_Rp_f[ON2_Npoles_f].r =-0.5*R*R*R/(R-1.0);
        ON2_Rp_f[ON2_Npoles_f].i =-0.5*R*kappa/(R-1.0);

        ON2_method_f[ON2_Npoles_f] = 2;
        ON2_Npoles_f++;

    }


    /*
    {

      double sum;
      double complex alpha,weight;

      sum = 0.0;

      for (p=0; p<ON2_Npoles_f; p++){

        if (ON2_method_f[p]==1){
          alpha  = 0.0 + I*(ON2_zp_f[p].i/Beta);
          weight = -2.0*ON2_Rp_f[p].r/Beta*alpha;
        }
        else {
          alpha  = ON2_zp_f[p].r + I*ON2_zp_f[p].i;
          weight = ON2_Rp_f[p].r + I*ON2_Rp_f[p].i;
        }

        sum += creal(weight*1.0/(alpha+2.0));

        printf("%2d %18.15f\n",p,sum);

      }

      printf("\nsum = %18.15f\n",sum);

    }

    MPI_Finalize();
    exit(0);
    */


    /****************************************************
        Matsubara
    ****************************************************/

    /*
    Beta = 1.0/kB/E_Temp;

    for (p=0; p<POLES; p++){

      Rp[p].r = -1.0;
      Rp[p].i = 0.0;

      Ep[p].r = 0.0;
      Ep[p].i = PI*(2.0*(double)p+1.0)/Beta;
    }
    */


    /*

    {
      double f[10],e[10];
      double ChemP,sum,x;

      ChemP = 0.0;

      e[1] = -10.0/eV2Hartree;
      e[2] = -5.0/eV2Hartree;
      e[3] = -2.0/eV2Hartree;
      e[4] =  5.0/eV2Hartree;

      sum = 0.0;

      for (i=1; i<=4; i++){
        x = Beta*(e[i]-ChemP);

        printf("x=%15.12f f=%15.12f\n",x,1.0/(1.0+exp(x)));

        sum += 1.0/(1.0+exp(x));
      }

      printf("Analytic %18.15f\n",sum);

    }

    printf("\n\n");
    printf("POLES %2d\n",POLES);
    */

    /*
    HGF();
    */

    /*
    MM();
    */

    /*
    Matsubara();
    */

    /*
    MPI_Finalize();
    exit(0);
    */

}