Пример #1
0
void SelectStream(int index)
/* ------------------------------------------------------------------
 * Use this function to set the current random number generator
 * stream -- that stream from which the next random number will come.
 * ------------------------------------------------------------------
 */
{
  stream = ((unsigned int)index) % STREAMS;
  if ((initialized == 0) && (stream != 0)) /* protect against        */
    PlantSeeds(DEFAULT);                   /* un-initialized streams */
}
Пример #2
0
int main(int argc, char *argv[])
{
	int i;
	int vet[TAM];
	
	printf("Casa inicial selecionada: %s%s\n", argv[1], argv[2]);
	
	PlantSeeds(time(NULL));
	
	
	for(i = 0; i < TAM; i++)
	{
		vet[i] = (int) Equilikely(0.0, 1.0);
	}
	
	for(i = 0; i < TAM; i++)
	{
		printf("%d\n", vet[i]);
	}
	return 0;
}
Пример #3
0
void
start(void)
{
	int i;
	num_tickets = 0;

	// Set up hardware (schedos-x86.c)
	segments_init();
	interrupt_controller_init(0);
	console_clear();

	// Initialize process descriptors as empty
	memset(proc_array, 0, sizeof(proc_array));
	for (i = 0; i < NPROCS; i++) {
		proc_array[i].p_pid = i;
		proc_array[i].p_state = P_EMPTY;
	}

	// Set up process descriptors (the proc_array[])
	for (i = 1; i < NPROCS; i++) {
		process_t *proc = &proc_array[i];
		uint32_t stack_ptr = PROC1_START + i * PROC_SIZE;

		// Initialize the process descriptor
		special_registers_init(proc);

		// Initialize the extra process descriptors
	    proc->p_share = 1;
		proc->p_time_passed = 0;
		proc->p_priority = 1;

		// Set ESP
		proc->p_registers.reg_esp = stack_ptr;

		// Load process and set EIP, based on ELF image
		program_loader(i - 1, &proc->p_registers.reg_eip);

		// Mark the process as runnable!
		proc->p_state = P_RUNNABLE;

		lock = 0;

		
	}

	// Initialize the cursor-position shared variable to point to the
	// console's first character (the upper left).
	cursorpos = (uint16_t *) 0xB8000;

	// Initialize the scheduling algorithm.
	scheduling_algorithm = 0;

	PlantSeeds(1);

	// Switch to the first process.
	run(&proc_array[1]);


	

	// Should never get here!
	while (1)
		/* do nothing */;
}
Пример #4
0
/**
 *  This function is the main function where commands are called via
 *  other functions in the kmer library.
 *
 *  @param argc argc
 *  @param argv argv
 *
 *  @return program exit value (0 on SUCCESS, otherwise other values)
 */
int main(int argc, char * argv[])
{
    time_t start = time(NULL);
    int s = ALDER_STATUS_SUCCESS;
    int isExitWithHelp = 0;
    alder_kmer_option_t option;
    struct gengetopt_args_info args_info;
    if (my_cmdline_parser (argc, argv, &args_info) != 0) exit(1) ;
    isExitWithHelp = alder_kmer_option_init(&option, &args_info, argc);
    if (isExitWithHelp != 0) {
        my_cmdline_parser_free(&args_info);
        alder_kmer_option_free(&option);
        exit(isExitWithHelp);
    }
    ///////////////////////////////////////////////////////////////////////////
    // Set up a log file if needed.
    alder_file_rm(args_info.log_arg);
    if (args_info.log_given) {
        alder_logger_initialize(args_info.log_arg, (int)args_info.loglevel_arg);
        alder_logger_error_initialize(LOG_WARNING);
    } else {
        alder_logger_initialize(args_info.log_arg, LOG_SILENT);
        alder_logger_error_initialize(LOG_BASIC);
    }
    ///////////////////////////////////////////////////////////////////////////
    // Timing:
    alder_log("START: %.*s", (int)(strlen(ctime(&start))-1), ctime(&start));
    
    ///////////////////////////////////////////////////////////////////////////
    // Count:
    if (args_info.count_flag) {
        PlantSeeds(args_info.seed_arg);
        SelectStream(1);
        command_count_t count;
        if (args_info.dsk_flag == 0) {
            count = &alder_kmer_topkmer;
            args_info.only_init_flag = (int)option.format;
            args_info.no_count_flag = args_info.save_all_flag;
        } else {
            count = &alder_kmer_count;
            args_info.select_version_arg = 7;
        }
        s = (*count)(args_info.select_version_arg,
                     (int)args_info.kmer_arg,
                     args_info.totalmaxkmer_arg,
                     args_info.disk_arg,
                     args_info.memory_arg,
                     (int)args_info.lower_count_arg,
                     (int)args_info.upper_count_arg,
                     option.maxfile,
                     args_info.inbuffer_arg,
                     args_info.outbuffer_arg,
                     (int)args_info.ni_arg,
                     (int)args_info.np_arg,
                     (int)args_info.nh_arg,
                     (int)args_info.nthread_arg,
                     args_info.progress_flag,
                     args_info.progress_to_stderr_flag,
                     args_info.only_init_flag,
                     args_info.no_delete_flag,
                     args_info.no_partition_flag,
                     args_info.no_count_flag,
                     option.infile,
                     args_info.outfile_given,
                     args_info.outdir_arg,
                     args_info.outfile_arg);
    }
    
    ///////////////////////////////////////////////////////////////////////////
    // Partition:
    if (args_info.partition_flag) {
        s = alder_kmer_partition(args_info.select_version_arg,
                                 (int)args_info.kmer_arg,
                                 args_info.disk_arg,
                                 args_info.memory_arg,
                                 args_info.min_table_memory_arg,
                                 args_info.max_table_memory_arg,
                                 option.maxfile,
                                 args_info.inbuffer_arg,
                                 args_info.outbuffer_arg,
                                 (int)args_info.ni_arg,
                                 (int)args_info.np_arg,
                                 (int)args_info.nh_arg,
                                 (int)args_info.nthread_arg,
                                 args_info.progress_flag,
                                 args_info.progress_to_stderr_flag,
                                 args_info.use_seqfile_flag,
                                 args_info.binfile_arg,
                                 args_info.binfile_given,
                                 option.infile,
                                 args_info.outfile_given,
                                 args_info.outdir_arg,
                                 args_info.outfile_arg);
    }
    ///////////////////////////////////////////////////////////////////////////
    // Table:
    if (args_info.table_flag) {
        s = alder_kmer_table(args_info.select_version_arg,
                             0, // -1, why -1?
                             (int)args_info.kmer_arg,
                             // args_info.disk_arg,
                             args_info.memory_arg,
                             option.maxfile,
                             args_info.inbuffer_arg,
                             args_info.outbuffer_arg,
                             (int)args_info.ni_arg,
                             (int)args_info.np_arg,
                             (int)args_info.nh_arg,
                             (int)args_info.nthread_arg,
                             args_info.progress_flag,
                             args_info.progress_to_stderr_flag,
                             (int)args_info.lower_count_arg,
                             (int)args_info.upper_count_arg,
                             args_info.parfile_arg,
                             args_info.parfile_given,
                             option.infile,
                             args_info.outfile_given,
                             args_info.outdir_arg,
                             args_info.outfile_arg);
    }
    
    ///////////////////////////////////////////////////////////////////////////
    // Report/Dump:
    if (args_info.report_flag) {
        if (args_info.dsk_flag == 1) {
            args_info.select_version_arg = 7;
        }
        if (args_info.query_given) {
            s = alder_kmer_report(args_info.select_version_arg,
                                  bdata(option.infile->entry[0]),
                                  args_info.summary_flag,
                                  args_info.sequence_arg);
        } else {
            s = alder_kmer_report(args_info.select_version_arg,
                                  bdata(option.infile->entry[0]),
                                  args_info.summary_flag,
                                  NULL);
        }
    }
    
    ///////////////////////////////////////////////////////////////////////////
    // Query:
    if (args_info.query_flag) {
        s = alder_kmer_query(args_info.select_version_arg,
                             bdata(option.infile->entry[0]),
                             args_info.summary_flag,
                             args_info.sequence_arg);
    }
    
    ///////////////////////////////////////////////////////////////////////////
    // Simulation:
    if (args_info.simulate_flag) {
        PlantSeeds(args_info.seed_arg);
        SelectStream(1);
        if (args_info.error_rate_arg > 0) {
            s = alder_kmer_simulate2(args_info.select_version_arg,
                                     args_info.outfile_given,
                                     args_info.outfile_arg,
                                     args_info.outdir_arg,
                                     option.format,
                                     (int)args_info.nf_arg,
                                     args_info.seed_arg,
                                     (int)args_info.error_rate_arg,
                                     (int)args_info.error_initial_arg,
                                     (int)args_info.error_iteration_arg,
                                     (int)args_info.error_duplicate_arg,
                                     (int)args_info.kmer_arg,
                                     (int)args_info.seqlen_arg,
                                     (size_t)args_info.maxkmer_arg,
                                     args_info.progress_flag,
                                     args_info.progress_to_stderr_flag);
        } else {
            s = alder_kmer_simulate(args_info.select_version_arg,
                                    args_info.outfile_given,
                                    args_info.outfile_arg,
                                    args_info.outdir_arg,
                                    option.format,
                                    args_info.with_parfile_flag,
                                    (int)args_info.nf_arg,
                                    (int)args_info.ni_arg,
                                    (int)args_info.np_arg,
                                    (int)args_info.kmer_arg,
                                    (int)args_info.seqlen_arg,
                                    (size_t)args_info.maxkmer_arg,
                                    args_info.progress_flag,
                                    args_info.progress_to_stderr_flag);
        }
    }
    
    ///////////////////////////////////////////////////////////////////////////
    // Decode/Kmer:
    if (args_info.decode_flag) {
        s = alder_kmer_decode((int)args_info.kmer_arg,
                              args_info.progress_flag,
                              option.infile,
                              args_info.outfile_given,
                              args_info.outdir_arg,
                              args_info.outfile_arg);
    }
    
    ///////////////////////////////////////////////////////////////////////////
    // List:
    if (args_info.list_flag) {
        s = alder_kmer_list((int)args_info.kmer_arg,
                            args_info.with_index_flag,
                            option.infile,
                            args_info.outfile_given,
                            args_info.outdir_arg,
                            args_info.outfile_arg);
    }
    
    ///////////////////////////////////////////////////////////////////////////
    // Match:
    if (args_info.match_flag) {
        s = alder_kmer_match(args_info.progress_flag,
                             option.infile,
                             args_info.tabfile_arg,
                             args_info.format_arg,
                             args_info.outfile_given,
                             args_info.outdir_arg,
                             args_info.outfile_arg);
    }
    
    ///////////////////////////////////////////////////////////////////////////
    // Uncompress:
    if (args_info.uncompress_flag) {
        alder_kmer_uncompress(args_info.progress_flag,
                              option.infile,
                              args_info.outfile_given,
                              args_info.outdir_arg,
                              args_info.outfile_arg);
    }
    
    ///////////////////////////////////////////////////////////////////////////
    // View:
    if (args_info.view_flag) {
        alder_kmer_view((int)args_info.format_arg,
                        option.infile,
                        args_info.outfile_given,
                        args_info.outdir_arg,
                        args_info.outfile_arg,
                        (int)args_info.kmer_arg);
    }
    
    ///////////////////////////////////////////////////////////////////////////
    // Binary:
    if (args_info.binary_flag) {
        size_t n_byte = 0;
        uint64_t n_kmer = 0;
        uint64_t n_dna = 0;
        uint64_t n_seq = 0;
        size_t n_totalfilesize = 0;
        size_t subsize = ALDER_KMER_BUFSIZE;
        s = alder_kmer_binary(NULL, 0, subsize,
                              &n_kmer, &n_dna, &n_seq,
                              &n_totalfilesize,
                              &n_byte,
                              args_info.select_version_arg,
                              (int)args_info.kmer_arg,
                              args_info.disk_arg,
                              args_info.memory_arg,
                              args_info.min_table_memory_arg,
                              args_info.max_table_memory_arg,
                              (int)args_info.nsplit_arg,
                              args_info.progress_flag,
                              args_info.progress_to_stderr_flag,
                              option.infile,
                              args_info.outdir_arg,
                              args_info.outfile_arg);
    }
    
    ///////////////////////////////////////////////////////////////////////////
    // Assess:
    if (args_info.assess_flag) {
        alder_kmer_assess((int)args_info.upper_count_arg,
                          args_info.tabfile_arg,
                          option.infile,
                          (int)args_info.outfile_given,
                          args_info.outdir_arg,
                          args_info.outfile_arg);
    }
    
    ///////////////////////////////////////////////////////////////////////////
    // Inspect:
    if (args_info.inspect_flag) {
        alder_kmer_inspect(option.infile,
                           args_info.outdir_arg,
                           args_info.outfile_arg);
    }
    
    ///////////////////////////////////////////////////////////////////////////
    // Timing:
    time_t end = time(NULL);
    alder_log("END: %.*s", (int)(strlen(ctime(&end))-1), ctime(&end));
    double run_time = difftime(end, start);
    alder_log("RUN TIME: %.f (s) = %.f (m) = %.f (h)", run_time, run_time/60, run_time/3600);
    
    ///////////////////////////////////////////////////////////////////////////
    // Cleanup!
    alder_logger_finalize();
    alder_logger_error_finalize();
    if (!args_info.log_given) {
        alder_file_rm(args_info.log_arg);
    }
    my_cmdline_parser_free(&args_info);
    alder_kmer_option_free(&option);
    return s;
}
Пример #5
0
void main(int argc, char *argv[])
{
	int n=m;
	float J=Interaction;
	PlantSeeds(-6);
	float t=T;
	int beta=1.0/t;
	int s=0;
	int H=0;
	float r1,dh=0;
	int step,num,i,j;
	double po,lo,k;
	int spinarray[m][n];

	/*Initial values of the spins*/
	for (i=0;i<m;i++)
	{
		for (j=0;j<n;j++)
		{
			r1=myrand(0,1);
			if (r1<=0.5)
			{
				spinarray[i][j]=-1;
				s--;
			}
			else 
			{
				spinarray[i][j]=1;
				s++;
			}
		}
	}

	/*For the ncurses display*/
	initscr();
	int flips = 0;
        start_color();noecho();
        init_pair(1,COLOR_RED,COLOR_BLACK); // 1:up spin
        init_pair(2,COLOR_GREEN,COLOR_BLACK); // -1: down spin
        draw(spinarray,0,s,t);
        int ch;
        keypad(stdscr, TRUE); // trap arrow keys and other special keys
        nodelay(stdscr, TRUE); // non-blocking I/O
	/*For the ncurses display*/

	for (step=0;;step++)
	{
		draw(spinarray,step,s,t);
		for (num=0;num<m*n;num++)
		{
			ch=getch();
			switch(ch)
			{
				case 'Q':
				case 'q':
					endwin();
					exit(0);
					break;
				case KEY_DOWN:
					if (t>0.4) t-=0.2;
					else t/=2;
					break;
				case KEY_UP:
					if (t>0.2) t+=0.2;
					else t*=2;
					break;
				case 'w':
					t+=0.02;
					break;
				case 's':
					t-=0.02;
					break;
				case 't':
					avg=0;
					num_avg=0;
					take_avg=1;
					show_avg=0;
					break;
				case 'y':
					take_avg=0;
					show_avg=1;
					break;
				case 'j':
					J*=-1;

				defaults:
					break;
			}
			if (take_avg==1)
			{
				avg+=s;
				num_avg++;
		//		printf("%d\t%d",avg,num_avg);
			}
			beta=1.0/t;

			i=randint(0,m-1);
			j=randint(0,n-1);
		//	if (i==m-1) addstr("Gotcha\n");
			dh=2*J*spinarray[i][j]*(spinarray[next(i)][j]+spinarray[i][next(j)]+spinarray[prev(i)][j]+spinarray[i][prev(j)]);

			if (dh<=0)
			{
				spinarray[i][j]*=-1;
				s+=2*spinarray[i][j];
		//		draw(spinarray,step,s,t);
			}
			else
			{
				if (exp(-1*beta*dh)>=myrand(0,1))
				{
					spinarray[i][j]*=-1;
					s+=2*spinarray[i][j];
		//		draw(spinarray,step,s,t);
				}
			}

		}

	}
}