Exemplo n.º 1
0
int main(int argc,char *argv[])
{
	int arr[10];
	int n=10,i;
	for(i=0;i<n;i++){
		arr[i]=n-1-i;
	}
	arrPrint(arr,n);
	MergeSort(arr,n);
	arrPrint(arr,n);

	





	return 0;
}
Exemplo n.º 2
0
int main(int argc, const char * argv[]) {
    std::cout << "==== NEW RUN ====\n";
    if (argc < 9) {
        displayHelp();
        return 0;
    } else if (1 < argc) {
        MAX_TIME    = atoi(argv[1]);
        LATICE_SIZE = atoi(argv[2]);
        W0          = atof(argv[3]);
        C_MIU       = atof(argv[4]);
        C_SIGMA     = atof(argv[5]);
        C_MODE      = atof(argv[6]);
        VERBOSE     = atoi(argv[7]);
        AVERAGES    = atoi(argv[8]);
    } else {
        LATICE_SIZE = 100;
        W0 = 0.1;
        C_MODE = DISTRIBUTION_GAUSS;
        C_MIU = 0.5;
        C_SIGMA = 0.1;
        MAX_TIME = 1000000;
        AVERAGES = 10;
        VERBOSE = false;
    }
    std::ofstream outputFile( argv[9] , std::ios::out | std::ios::app );
    std::cout << "CHECKING FILE\n";
    std::cout << "Writing to: '" << argv[9] << "' \n";
    if (!outputFile) {
        std::cout << argv[9] << "\n";
        printf("ERR");
        outputFile.close();
        return 1;
    }
    
    std::cout << "FILE OK\n";
    
    gsl_rng_env_setup();

    T = gsl_rng_mt19937;
    r = gsl_rng_alloc (T);
    long seed = time (NULL) * getpid();
    gsl_rng_set(r, seed);

    begin = clock();

    std::cout << "MT OK\n";
    
    short * LATICE           = (short *)malloc(LATICE_SIZE*sizeof(short));
    short * NEXT_STEP_LATICE = (short *)malloc(LATICE_SIZE*sizeof(short));

    std::cout << "INIT SIMULATION\n";

    for (int a = 1; a <= AVERAGES; a++) {
        std::cout << "RESET MCS: " << "\n";
        updateMonteCarloSteps(true);
        
        std::cout << "AVERAGE: " << a << "\n";
        initAntiferromagnet(LATICE);
        double start_rho = bondDensity(LATICE);
        double rho=0, sum_rho=0;
        double sum_c = 0;
        int magnetization = 0;
        
        for (int t = 1; t <= MAX_TIME; t++) {
            if (VERBOSE) {
                arrPrint(LATICE);printf("\n");
            }
            rho = bondDensity(LATICE);

            if (rho == 0.0 || t == MAX_TIME) {
                end = clock();
                time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
                outputFile << " " << t << " ";
                outputFile << " " << monte_carlo_steps << " ";
                outputFile << " " << matnetization(LATICE) << " ";
                outputFile << " " << rho << "\n";
                std::cout << "cputime:"   << time_spent << "\n";
                break;
            }

            double C = distribution(C_MIU, C_SIGMA, C_MODE);
            sum_c += C;

            int first_i = randInRange(0, LATICE_SIZE);
            int last_i = first_i + (C * LATICE_SIZE);

            for (int i = 0; i < LATICE_SIZE; i++) {

                if (first_i <= i && i <= last_i) {
                    int left  = (i-1) % LATICE_SIZE;
                    int right = (i+1) % LATICE_SIZE;

                    if ( LATICE[left] == LATICE[right] ) {
                        NEXT_STEP_LATICE[i] = LATICE[left];
                        updateMonteCarloSteps();
                    } else if ( W0 > randomUniform() ) {
                        NEXT_STEP_LATICE[i] = swaped(LATICE[i]);
                        updateMonteCarloSteps();
                    }
                } else {
                    NEXT_STEP_LATICE[i] = LATICE[i];
                }

            }

            std::swap(LATICE, NEXT_STEP_LATICE);
        }
    
    }
    gsl_rng_free (r);
    free(LATICE);
    free(NEXT_STEP_LATICE);

    return 0;
}