Example #1
0
void Module_DMAP::execute_generic_worker(const Options & options) {
	/* TODO: handle contamination check
	if (options.contamination_check) {
		if (options.verbose)
			DEFAULT_CHANNEL << "Reading contamination SA in file " << options.contamination_file << endl;
		clock_t start = clock();
		CR.load(options.contamination_file.c_str());
		clock_t end = clock();

		DEFAULT_CHANNEL << "Hash (contamination) loading time = ";
		print_formatted_time(DEFAULT_CHANNEL, (end - start) / (double)CLOCKS_PER_SEC);
		DEFAULT_CHANNEL << endl;
	}
	 */
	{
		DEFAULT_CHANNEL << '[' << my_rank << "] Loading hash: " << options.reference_file << '_' << (my_rank + 1) << ".eht" << endl;

		clock_t start = clock();
		stringstream filename;
		filename << options.reference_file << '_' << (my_rank + 1) << ".eht";
		H.load(filename.str().c_str());
		clock_t end = clock();

		DEFAULT_CHANNEL << '[' << my_rank << "] Hash (reference) loading time = ";
		print_formatted_time(DEFAULT_CHANNEL, (end - start) / (double)CLOCKS_PER_SEC);
		DEFAULT_CHANNEL << endl;
	}

	if (my_rank == 0) {
		if (not force_fastqformat) {
			fastqformat = Fasta::check_FASTQ_type_file(query1);
			if (fastqformat == Fasta::unknown_fastq_encoding) {
				ERROR_CHANNEL << "The program can not autodetect input format file, please use --force-illumina or --force-standard options" << endl;
				exit(4);
			}
			DEFAULT_CHANNEL << "[0] FASTQ format: " << (fastqformat == Fasta::illumina_fastq_encoding ? "ILLUMINA" : "STANDARD") << " (autodetected)" << endl;
		}
		// open file for input
		if (options.paired_ends) {
			DEFAULT_CHANNEL << '[' << my_rank << "] Opening " << query1 << " and " << query2 << " files" << endl;
			input_file1.open(query1);
			input_file2.open(query1);
		} else {
			DEFAULT_CHANNEL << '[' << my_rank << "] Opening " << query1 << " file" << endl;
			input_file1.open(query1);
		}
	} else if (my_rank == (nprocs -1)) {
		// open file for output
		DEFAULT_CHANNEL << '[' << my_rank << "] Opening output " << options.output_file << " file" << endl;
		output_samfile.open_file_mpi(options);
	} // else do nothig: generic worker

	// retrieve information for contig conversion
	{
		stringstream header_name;
		header_name << options.reference_file << "_h.dht";

		contig_conversion.link(H.globalToLocal,header_name.str());
	}

	thread_group threads;
	if (options.paired_ends) {
		// PROCESS PAIR ENDS FILES
		if (my_rank == 0)
			DEFAULT_CHANNEL << "[0] Processing files " << options.query1 << " and " << options.query2 << endl;
		for (int id=0; id < threads_number; id++)
			threads.create_thread(boost::bind(&this->generic_worker_paired_thr, this, id));
		threads.join_all();
	} else {
		// PROCESS SINGLE READ FILES
		if (my_rank == 0)
			DEFAULT_CHANNEL << "[0] Processing file " << options.query1 << endl;
		for (int id=0; id < threads_number; id++)
			threads.create_thread(boost::bind(&this->generic_worker_single_thr, this, id));
		threads.join_all();
		// Send finalization to next node
		if (my_rank != (nprocs -1)) {
			int number = 0;
			MPI::COMM_WORLD.Send(&number,1,MPI::INT,my_rank+1,COMMUNICATION_CHANNEL);
		}
	}

	DEFAULT_CHANNEL << '[' << my_rank << "] Finished!" << endl;
}
Example #2
0
void Module_DMAP::execute(const Options & options) {
	clock_t started = clock();
	processed = 0;

	initialize_parameters(options);

	my_rank = MPI::COMM_WORLD.Get_rank();
	nprocs = MPI::COMM_WORLD.Get_size();
	proc_name = new char[MPI_MAX_PROCESSOR_NAME];
	int resultlen;
	MPI::Get_processor_name(proc_name, resultlen);

	// Check for the correct number of files
	if (my_rank == 0) {
		stringstream filename_numberfile;
		filename_numberfile << options.reference_file << "_n.dht";
		ifstream nf(filename_numberfile.str().c_str());
		if (nf.fail()) {
			ERROR_CHANNEL << "File " << filename_numberfile.str() << " not found! Check the reference name!" << endl;
			exit(5);
		}
		string s;
		getline(nf,s);
		int n_files = -1;
		n_files = atoi(s.c_str());
		DEFAULT_CHANNEL << "Number of rNA files in the set: " << s << endl;
		if (n_files != nprocs) {
			ERROR_CHANNEL << "Wrong number of files: expected " << nprocs << " files but the data structure was built for " << n_files << " processes!" << endl;
			exit(5);
		} else {
			DEFAULT_CHANNEL << '[' << my_rank << "] Found " << n_files << '/' << nprocs << " files" << endl;
		}
	}

	if (my_rank == 0)
		DEFAULT_CHANNEL << '[' << my_rank << "] Reading process started on machine " << proc_name << endl;
	else if (my_rank == nprocs-1)
		DEFAULT_CHANNEL << '[' << my_rank << "] Writing process started on machine " << proc_name << endl;
	else
		DEFAULT_CHANNEL << '[' << my_rank << "] Slave process " << my_rank << "/" << (nprocs-1) << " started on machine " << proc_name << endl;

	execute_generic_worker(options);

	if (my_rank == 0)
		DEFAULT_CHANNEL << '[' << my_rank << "] Reading process waiting for finalize on " << proc_name << endl;
	else if (my_rank == nprocs-1)
		DEFAULT_CHANNEL << '[' << my_rank << "] Writing process waiting for finalize on " << proc_name << endl;
	else
		DEFAULT_CHANNEL << '[' << my_rank << "] Slave process " << my_rank << "/" << (nprocs-1) << " waiting for finalize on " << proc_name << endl;

	MPI::Finalize();

	if (my_rank == 0) {
		clock_t finished = clock();
		double dif = (finished - started) / (double)CLOCKS_PER_SEC;

		DEFAULT_CHANNEL << "Time spent: " << dif << "s (";
		print_formatted_time(DEFAULT_CHANNEL, dif);
		DEFAULT_CHANNEL << ')' << endl;
		//DEFAULT_CHANNEL << "Queries per second: " << (processed/dif)	<<endl;
	}

}
Example #3
0
int main( int argc, char* argv[] ) {
	unsigned int max_time = 0;

	int * timer_ldr = (TIMER3_BASE + LDR_OFFSET);
	int * timer_val = (TIMER3_BASE + VAL_OFFSET);
	int * timer_ctrl = (TIMER3_BASE + CRTL_OFFSET);

	unsigned int terminal_output_buffer_size = 10000;
	unsigned int terminal_input_buffer_size = 100;
	unsigned int train_controller_output_buffer_size = 1000;
	unsigned int train_controller_input_buffer_size = 100;
	unsigned char terminal_output_buffer[terminal_output_buffer_size];
	unsigned char terminal_input_buffer[terminal_input_buffer_size];
	unsigned char train_controller_output_buffer[train_controller_output_buffer_size];
	unsigned char train_controller_input_buffer[train_controller_input_buffer_size];

	// 508000 cycles per second, means a tick (100ms) has 50800 cycles
	unsigned int cycles_per_tick = 50800;
	int last_timer_value = cycles_per_tick;
	int ticks = 0;

	//  Use simple ring buffers for the output to the two UARTs
	ChannelDescription terminal_channel;
	terminal_channel.channel = COM2;
	terminal_channel.speed = 115200;
	terminal_channel.out_buffer_start = 0;
	terminal_channel.out_buffer_end = 0;
	terminal_channel.in_buffer_start = 0;
	terminal_channel.in_buffer_end = 0;
	terminal_channel.output_buffer_size = terminal_output_buffer_size;
	terminal_channel.output_buffer = terminal_output_buffer;
	terminal_channel.input_buffer_size = terminal_input_buffer_size;
	terminal_channel.input_buffer = terminal_input_buffer;

	ChannelDescription train_controller_channel;
	train_controller_channel.channel = COM1;
	train_controller_channel.speed = 2400;
	train_controller_channel.out_buffer_start = 0;
	train_controller_channel.out_buffer_end = 0;
	train_controller_channel.in_buffer_start = 0;
	train_controller_channel.in_buffer_end = 0;
	train_controller_channel.output_buffer_size = train_controller_output_buffer_size;
	train_controller_channel.output_buffer = train_controller_output_buffer;
	train_controller_channel.input_buffer_size = train_controller_input_buffer_size;
	train_controller_channel.input_buffer = train_controller_input_buffer;

	//  Disable the timer before we set the load value
	*timer_ctrl = (*timer_ctrl) ^ ENABLE_MASK;
	*timer_ldr = cycles_per_tick;
	//  Turn the timer on enabled, with clock 508khz and periodic mode
	*timer_ctrl = ENABLE_MASK | CLKSEL_MASK | MODE_MASK;

	robsetspeed( &terminal_channel);
	robsetspeed( &train_controller_channel);

	unsigned char command_buffer[200];
	unsigned int command_buffer_pos = 0;
	command_buffer[0] = 0;

	while(1){
		int * line1 = (int *)( UART1_BASE + UART_LCRH_OFFSET );
		assert((!(*line1 & FEN_MASK)),"The FIFO is enabled in main, and that is bad.\n");
		int * line2 = (int *)( UART2_BASE + UART_LCRH_OFFSET );
		assert((!(*line2 & FEN_MASK)),"The FIFO is enabled in main, and that is bad.\n");
		int observed_val = *timer_val;
		//  Output any information about errors.
		robchannelerrorcheck(&terminal_channel);
		robchannelerrorcheck(&train_controller_channel);
		//  Send some of the data in the output buffers
		robchannelsend(&terminal_channel);
		robchannelsend(&train_controller_channel);
		//  Get any data that is available
		robgetc(&terminal_channel);
		robgetc(&train_controller_channel);
		unsigned char c = robtakec(&terminal_channel);
		if(c){
			//  Store the data in our command buffer
			command_buffer[command_buffer_pos] = c;
			command_buffer[command_buffer_pos+1] = 0;
			command_buffer_pos++;
			if(c == '\r' || c == '\n'){
				if(handle_command(&terminal_channel,&train_controller_channel, command_buffer, &command_buffer_pos)){
					return 0;
				}
			}
			assert(command_buffer_pos < 190, "Command too big.");
		}

		unsigned int diff = observed_val > last_timer_value ? (cycles_per_tick - observed_val) + last_timer_value : last_timer_value - observed_val;
		if(diff > max_time)
			max_time = diff;
		if(observed_val > last_timer_value){
			ticks++;
			//  Clear the screen
			robprintf( &terminal_channel, "\x1B""[2J");
			print_formatted_time(&terminal_channel, ticks);
			print_loop_timing(&terminal_channel, observed_val, last_timer_value, cycles_per_tick, max_time);
			print_channel_info(&terminal_channel,&terminal_channel);
			print_channel_info(&terminal_channel,&train_controller_channel);
			robprintf( &terminal_channel, command_buffer);
		}
		last_timer_value = observed_val;
	}
	return 0;
}