void biosal_input_stream_receive(struct thorium_actor *actor, struct thorium_message *message) { int tag; int source; uint64_t count; struct biosal_input_stream *concrete_self; int i; int has_sequence; int sequences; int sequence_index; int buffer_size; char *buffer; char *read_buffer; struct biosal_mega_block mega_block; char *file_name_in_buffer; if (thorium_actor_take_action(actor, message)) { return; } concrete_self = thorium_actor_concrete_actor(actor); tag = thorium_message_action(message); source = thorium_message_source(message); buffer = (char *)thorium_message_buffer(message); /* Do nothing if there is an error. * has_error returns the error to the source. */ /* if (biosal_input_stream_has_error(actor, message)) { return; } */ if (tag == ACTION_INPUT_OPEN) { #ifdef BIOSAL_INPUT_STREAM_DEBUG printf("DEBUG ACTION_INPUT_OPEN\n"); #endif if (concrete_self->open) { concrete_self->error = BIOSAL_INPUT_ERROR_ALREADY_OPEN; thorium_actor_send_reply_int(actor, ACTION_INPUT_OPEN_REPLY, concrete_self->error); thorium_actor_send_to_self_empty(actor, ACTION_ASK_TO_STOP); return; } concrete_self->open = 1; /* TODO: find out the maximum read length in some way */ concrete_self->maximum_sequence_length = BIOSAL_INPUT_MAXIMUM_SEQUENCE_LENGTH; concrete_self->buffer_for_sequence = (char *)core_memory_allocate(concrete_self->maximum_sequence_length, MEMORY_INPUT_STREAM); /*biosal_input_stream_init(actor);*/ #ifdef BIOSAL_INPUT_STREAM_DEBUG printf("DEBUG biosal_input_stream_receive open %s\n", buffer); #endif /*core_memory_copy(&concrete_self->file_index, buffer, sizeof(concrete_self->file_index));*/ file_name_in_buffer = buffer; printf("stream/%d (node/%d) opens file %s offset %" PRIu64 "\n", thorium_actor_name(actor), thorium_actor_node_name(actor), file_name_in_buffer, concrete_self->starting_offset); #ifdef DEBUG_ISSUE_594 thorium_message_print(message); printf("Buffer %s\n", buffer); #endif concrete_self->file_name = core_memory_allocate(strlen(file_name_in_buffer) + 1, MEMORY_INPUT_STREAM); strcpy(concrete_self->file_name, file_name_in_buffer); biosal_input_proxy_init(&concrete_self->proxy, concrete_self->file_name, concrete_self->starting_offset, concrete_self->ending_offset); concrete_self->proxy_ready = 1; /* Die if there is an error... */ if (biosal_input_stream_has_error(actor, message)) { #ifdef BIOSAL_INPUT_STREAM_DEBUG printf("DEBUG has error\n"); #endif thorium_actor_send_reply_int(actor, ACTION_INPUT_OPEN_REPLY, concrete_self->error); thorium_actor_send_to_self_empty(actor, ACTION_ASK_TO_STOP); return; } concrete_self->controller = source; /* no error here... */ thorium_actor_send_reply_int(actor, ACTION_INPUT_OPEN_REPLY, concrete_self->error); } else if (tag == ACTION_INPUT_COUNT) { /* count a little bit and yield the worker */ if (concrete_self->count_customer == THORIUM_ACTOR_NOBODY) { concrete_self->count_customer = source; } if (biosal_input_stream_check_open_error(actor, message)) { thorium_actor_send_reply_int64_t(actor, ACTION_INPUT_COUNT_REPLY, concrete_self->error); thorium_actor_send_to_self_empty(actor, ACTION_ASK_TO_STOP); return; } #ifdef BIOSAL_INPUT_STREAM_DEBUG printf("DEBUG ACTION_INPUT_COUNT received...\n"); #endif i = 0; /* continue counting ... */ has_sequence = 1; while (i < concrete_self->granularity && has_sequence) { has_sequence = biosal_input_proxy_get_sequence(&concrete_self->proxy, concrete_self->buffer_for_sequence); #if 0 printf("Sequence= %s\n", concrete_self->buffer_for_sequence); #endif i++; } sequences = biosal_input_proxy_size(&concrete_self->proxy); #ifdef BIOSAL_INPUT_STREAM_DEBUG printf("DEBUG ACTION_INPUT_COUNT sequences %d...\n", sequences); #endif if (!has_sequence || sequences % concrete_self->mega_block_size == 0) { biosal_mega_block_init(&mega_block, -1, concrete_self->last_offset, sequences - concrete_self->last_entries, sequences); core_vector_push_back(&concrete_self->mega_blocks, &mega_block); concrete_self->last_entries = sequences; concrete_self->last_offset = biosal_input_proxy_offset(&concrete_self->proxy); thorium_actor_send_int64_t(actor, concrete_self->controller, ACTION_INPUT_COUNT_PROGRESS, sequences); } if (has_sequence) { /*printf("DEBUG yield\n");*/ thorium_actor_send_to_self_empty(actor, ACTION_YIELD); /* notify the controller of our progress... */ } else { thorium_actor_send_to_self_empty(actor, ACTION_INPUT_COUNT_READY); } } else if (tag == ACTION_YIELD_REPLY) { if (biosal_input_stream_check_open_error(actor, message)) { /* * it is not clear that there can be an error when receiving YIELD. error = concrete_self->error; thorium_actor_send_reply_int(actor, ACTION_INPUT_COUNT_REPLY, error); thorium_actor_send_to_self(actor, ACTION_ASK_TO_STOP); */ return; } thorium_actor_send_to_self_empty(actor, ACTION_INPUT_COUNT); } else if (tag == ACTION_INPUT_COUNT_READY) { if (biosal_input_stream_check_open_error(actor, message)) { return; } count = biosal_input_proxy_size(&concrete_self->proxy); thorium_actor_send_vector(actor, concrete_self->count_customer, ACTION_INPUT_COUNT_REPLY, &concrete_self->mega_blocks); printf("input_stream/%d on node/%d counted entries in %s, %" PRIu64 "\n", thorium_actor_name(actor), thorium_actor_node_name(actor), concrete_self->file_name, count); } else if (tag == ACTION_INPUT_CLOSE) { #ifdef BIOSAL_INPUT_STREAM_DEBUG printf("DEBUG destroy proxy\n"); #endif concrete_self->error = BIOSAL_INPUT_ERROR_NO_ERROR; if (biosal_input_stream_check_open_error(actor, message)) { concrete_self->error = BIOSAL_INPUT_ERROR_FILE_NOT_OPEN; thorium_message_init(message, ACTION_INPUT_CLOSE_REPLY, sizeof(concrete_self->error), &concrete_self->error); thorium_actor_send(actor, source, message); thorium_actor_send_to_self_empty(actor, ACTION_ASK_TO_STOP); return; } thorium_message_init(message, ACTION_INPUT_CLOSE_REPLY, sizeof(concrete_self->error), &concrete_self->error); thorium_actor_send(actor, source, message); thorium_actor_send_to_self_empty(actor, ACTION_ASK_TO_STOP); #ifdef BIOSAL_INPUT_STREAM_DEBUG printf("actor %d sending ACTION_INPUT_CLOSE_REPLY to %d\n", thorium_actor_name(actor), source); #endif } else if (tag == ACTION_INPUT_GET_SEQUENCE) { if (biosal_input_stream_check_open_error(actor, message)) { /* the error management could be better. */ concrete_self->error = BIOSAL_INPUT_ERROR_FILE_NOT_OPEN; thorium_message_init(message, ACTION_INPUT_GET_SEQUENCE_REPLY, sizeof(concrete_self->error), &concrete_self->error); thorium_actor_send(actor, source, message); return; } sequence_index = biosal_input_proxy_size(&concrete_self->proxy); /* TODO it would be clearer to use a struct to pack a int and a char [] * then to use the code below. */ read_buffer = concrete_self->buffer_for_sequence + sizeof(sequence_index); has_sequence = biosal_input_proxy_get_sequence(&concrete_self->proxy, read_buffer); if (!has_sequence) { thorium_message_init(message, ACTION_INPUT_GET_SEQUENCE_END, 0, NULL); thorium_actor_send(actor, source, message); return; } buffer_size = sizeof(sequence_index) + strlen(read_buffer) + 1; core_memory_copy(concrete_self->buffer_for_sequence, &sequence_index, sizeof(sequence_index)); thorium_message_init(message, ACTION_INPUT_GET_SEQUENCE_REPLY, buffer_size, concrete_self->buffer_for_sequence); thorium_actor_send(actor, source, message); } else if (tag == ACTION_INPUT_PUSH_SEQUENCES) { biosal_input_stream_push_sequences(actor, message); } else if (tag == ACTION_ASK_TO_STOP) { thorium_actor_send_to_self_empty(actor, ACTION_STOP); thorium_actor_send_range_empty(actor, &concrete_self->parallel_streams, ACTION_ASK_TO_STOP); thorium_actor_send_reply_empty(actor, ACTION_ASK_TO_STOP_REPLY); } else if (tag == ACTION_INPUT_STREAM_RESET) { /* fail silently */ if (!concrete_self->open) { thorium_actor_send_reply_empty(actor, ACTION_INPUT_STREAM_RESET_REPLY); return; } #ifdef BIOSAL_INPUT_STREAM_DEBUG printf("DEBUG ACTION_INPUT_STREAM_RESET\n"); #endif biosal_input_proxy_destroy(&concrete_self->proxy); biosal_input_proxy_init(&concrete_self->proxy, concrete_self->file_name, concrete_self->starting_offset, concrete_self->ending_offset); thorium_actor_send_reply_empty(actor, ACTION_INPUT_STREAM_RESET_REPLY); } else if (tag == ACTION_PUSH_SEQUENCE_DATA_BLOCK_REPLY) { thorium_actor_send_to_supervisor_int(actor, ACTION_INPUT_PUSH_SEQUENCES_REPLY, source); } }
void biosal_input_stream_init(struct thorium_actor *actor) { struct biosal_input_stream *input; struct biosal_input_stream *concrete_self; input = (struct biosal_input_stream *)thorium_actor_concrete_actor(actor); concrete_self = input; concrete_self->proxy_ready = 0; concrete_self->buffer_for_sequence = NULL; concrete_self->maximum_sequence_length = 0; concrete_self->open = 0; concrete_self->error = BIOSAL_INPUT_ERROR_NO_ERROR; concrete_self->file_name = NULL; biosal_dna_codec_init(&concrete_self->codec); if (biosal_dna_codec_must_use_two_bit_encoding(&concrete_self->codec, thorium_actor_get_node_count(actor))) { biosal_dna_codec_enable_two_bit_encoding(&concrete_self->codec); } /*concrete_self->mega_block_size = 2097152*/ /* * This is the mega block size in number of sequences. */ concrete_self->mega_block_size = 2097152; concrete_self->granularity = 1024; concrete_self->last_offset = 0; concrete_self->last_entries = 0; concrete_self->starting_offset = 0; /* * Use a large ending offset. */ concrete_self->ending_offset = 0; --concrete_self->ending_offset; core_vector_init(&concrete_self->mega_blocks, sizeof(struct biosal_mega_block)); thorium_actor_add_action(actor, ACTION_INPUT_STREAM_SET_START_OFFSET, biosal_input_stream_set_start_offset); thorium_actor_add_action(actor, ACTION_INPUT_STREAM_SET_END_OFFSET, biosal_input_stream_set_end_offset); #ifdef ENABLE_PARALLEL_COUNT thorium_actor_add_action(actor, ACTION_INPUT_COUNT_IN_PARALLEL, biosal_input_stream_count_in_parallel); thorium_actor_add_action(actor, ACTION_INPUT_COUNT_REPLY, biosal_input_stream_count_reply); #else thorium_actor_add_action(actor, ACTION_INPUT_COUNT_IN_PARALLEL, biosal_input_stream_count_in_parallel_mock); thorium_actor_add_action(actor, ACTION_INPUT_COUNT_REPLY, biosal_input_stream_count_reply_mock); #endif concrete_self->count_customer = THORIUM_ACTOR_NOBODY; #if 0 core_string_init(&concrete_self->file_for_parallel_counting, NULL); #endif /* * Parallel counting. */ concrete_self->total_entries = 0; /* * Disable parallel counting. */ concrete_self->finished_parallel_stream_count = 0; core_vector_init(&concrete_self->spawners, sizeof(int)); core_vector_init(&concrete_self->parallel_streams, sizeof(int)); core_vector_init(&concrete_self->start_offsets, sizeof(uint64_t)); core_vector_init(&concrete_self->end_offsets, sizeof(uint64_t)); core_vector_init(&concrete_self->parallel_mega_blocks, sizeof(struct core_vector)); printf("%s/%d is now online on node %d\n", thorium_actor_script_name(actor), thorium_actor_name(actor), thorium_actor_node_name(actor)); }
static void source_receive(struct thorium_actor *self, struct thorium_message *message) { int action; void *buffer; int leader; int source; int count; struct source *concrete_self; int name; concrete_self = (struct source *)thorium_actor_concrete_actor(self); action = thorium_message_action(message); buffer = thorium_message_buffer(message); source = thorium_message_source(message); name = thorium_actor_name(self); count = thorium_message_count(message); if (action == ACTION_ASK_TO_STOP) { thorium_actor_log(self, "sent %d ACTION_PING messages\n", concrete_self->message_count); thorium_actor_send_to_self_empty(self, ACTION_STOP); } else if (action == ACTION_NOTIFY) { #ifdef LATENCY_PROBE_USE_MULTIPLEXER thorium_actor_send_to_self_empty(self, ACTION_ENABLE_MULTIPLEXER); #endif CORE_DEBUGGER_ASSERT(core_vector_empty(&concrete_self->targets)); core_vector_unpack(&concrete_self->targets, buffer); if (source_is_important(self)) { printf("%d (node %d worker %d) has %d targets\n", thorium_actor_name(self), thorium_actor_node_name(self), thorium_actor_worker_name(self), (int)core_vector_size(&concrete_self->targets)); } concrete_self->leader = source; source_send_ping(self); } else if (action == ACTION_PING_REPLY) { CORE_DEBUGGER_ASSERT(count == 0); ++concrete_self->message_count; CORE_DEBUGGER_ASSERT_IS_EQUAL_INT(count, 0); CORE_DEBUGGER_ASSERT_IS_NULL(buffer); if (concrete_self->message_count % PERIOD == 0 || concrete_self->event_count < 500) { if (source_is_important(self)) { printf("progress %d %d/%d\n", name, concrete_self->message_count, concrete_self->event_count); } } if (concrete_self->message_count == concrete_self->event_count) { leader = concrete_self->leader; thorium_actor_send_empty(self, leader, ACTION_NOTIFY_REPLY); if (source_is_important(self)) printf("%d (ACTION_PING sent: %d)" " sends ACTION_NOTIFY_REPLY to %d\n", thorium_actor_name(self), concrete_self->message_count, leader); } else { source_send_ping(self); } } }