void process_send_ping(struct thorium_actor *self) { struct process *concrete_self; int destination; int size; int index; int buffer_size; int range; uint64_t checksum; int count; char *buffer; int i; uint64_t *bucket; concrete_self = thorium_actor_concrete_actor(self); range = concrete_self->maximum_buffer_size - concrete_self->minimum_buffer_size; buffer_size = rand() % range; buffer_size += concrete_self->minimum_buffer_size; count = buffer_size + sizeof(checksum); buffer = thorium_actor_allocate(self, count); /* * Generate content; */ for (i = 0; i < buffer_size; ++i) { buffer[i] = i % 256; } checksum = core_hash_data_uint64_t(buffer, buffer_size, SEED); bucket = (uint64_t *)(buffer + buffer_size); *bucket = checksum; size = core_vector_size(&concrete_self->actors); index = rand() % size; destination = core_vector_at_as_int(&concrete_self->actors, index); thorium_actor_send_buffer(self, destination, ACTION_PING, count, buffer); ++concrete_self->active_messages; }
void biosal_input_stream_count_reply_mock(struct thorium_actor *self, struct thorium_message *message) { struct biosal_input_stream *concrete_self; void *buffer; int count; struct core_vector mega_blocks; char *file; struct core_memory_pool *ephemeral_memory; uint64_t result; struct biosal_mega_block *block; concrete_self = (struct biosal_input_stream *)thorium_actor_concrete_actor(self); buffer = thorium_message_buffer(message); count = thorium_message_count(message); ephemeral_memory = thorium_actor_get_ephemeral_memory(self); core_vector_init(&mega_blocks, 0); core_vector_set_memory_pool(&mega_blocks, ephemeral_memory); core_vector_unpack(&mega_blocks, buffer); block = core_vector_at_last(&mega_blocks); result = biosal_mega_block_get_entries(block); #if 0 file = core_string_get(&concrete_self->file_for_parallel_counting); #endif file = concrete_self->file_name; printf("%s/%d COUNT_IN_PARALLEL result for %s is %" PRIu64 "\n", thorium_actor_script_name(self), thorium_actor_name(self), file, result); core_vector_destroy(&mega_blocks); thorium_actor_send_buffer(self, concrete_self->controller, ACTION_INPUT_COUNT_IN_PARALLEL_REPLY, count, buffer); }
void thorium_actor_send_reply_buffer(struct thorium_actor *actor, int action, int count, void *buffer) { thorium_actor_send_buffer(actor, thorium_actor_source(actor), action, count, buffer); }
void thorium_actor_send_to_self_buffer(struct thorium_actor *actor, int tag, int count, void *buffer) { thorium_actor_send_buffer(actor, thorium_actor_name(actor), tag, count, buffer); }
/* * Basically, this actor does this: * - spawn visitors * - let them visit stuff * - kill them. * - spawn walkers * - let them walk * - kill the walkers * - return OK */ void biosal_unitig_manager_receive(struct thorium_actor *self, struct thorium_message *message) { struct biosal_unitig_manager *concrete_self; int tag; void *buffer; int spawner; int expected; int script; int actor_count; int source; struct core_string file_name; char *directory; int argc; char **argv; char *path; tag = thorium_message_action(message); source = thorium_message_source(message); buffer = thorium_message_buffer(message); concrete_self = (struct biosal_unitig_manager *)thorium_actor_concrete_actor(self); if (tag == ACTION_START) { core_vector_unpack(&concrete_self->spawners, buffer); spawner = thorium_actor_get_random_spawner(self, &concrete_self->spawners); concrete_self->state = STATE_SPAWN_WRITER; thorium_actor_send_int(self, spawner, ACTION_SPAWN, SCRIPT_WRITER_PROCESS); } else if (tag == ACTION_SPAWN_REPLY && concrete_self->state == STATE_SPAWN_WRITER) { thorium_message_unpack_int(message, 0, &concrete_self->writer_process); /* * open the file now. */ argc = thorium_actor_argc(self); argv = thorium_actor_argv(self); directory = core_command_get_output_directory(argc, argv); core_string_init(&file_name, directory); core_string_append(&file_name, "/"); core_string_append(&file_name, "unitigs.fasta"); path = core_string_get(&file_name); thorium_actor_send_buffer(self, concrete_self->writer_process, ACTION_OPEN, strlen(path) + 1, path); core_string_destroy(&file_name); } else if (tag == ACTION_OPEN_REPLY && source == concrete_self->writer_process) { /* * Spawn visitors. */ concrete_self->state = STATE_VISITORS; thorium_actor_send_to_self_empty(self, ACTION_PING); } else if (tag == ACTION_PING) { spawner = thorium_actor_get_random_spawner(self, &concrete_self->spawners); thorium_actor_send_int(self, spawner, ACTION_SPAWN, SCRIPT_MANAGER); } else if (tag == ACTION_SPAWN_REPLY) { thorium_message_unpack_int(message, 0, &concrete_self->manager); script = SCRIPT_UNITIG_VISITOR; if (concrete_self->state == STATE_WALKERS) { script = SCRIPT_UNITIG_WALKER; } thorium_actor_send_int(self, concrete_self->manager, ACTION_MANAGER_SET_SCRIPT, script); } else if (tag == ACTION_ASK_TO_STOP) { thorium_actor_send_empty(self, concrete_self->writer_process, ACTION_ASK_TO_STOP); thorium_actor_send_empty(self, concrete_self->manager, ACTION_ASK_TO_STOP); thorium_actor_send_to_self_empty(self, ACTION_STOP); thorium_actor_send_reply_empty(self, ACTION_ASK_TO_STOP_REPLY); } else if (tag == ACTION_MANAGER_SET_SCRIPT_REPLY) { actor_count = UNITIG_VISITOR_COUNT_PER_WORKER; if (concrete_self->state == STATE_WALKERS) actor_count = UNITIG_WALKER_COUNT_PER_WORKER; thorium_actor_send_reply_int(self, ACTION_MANAGER_SET_ACTORS_PER_WORKER, actor_count); } else if (tag == ACTION_MANAGER_SET_ACTORS_PER_WORKER_REPLY) { thorium_actor_send_reply_vector(self, ACTION_START, &concrete_self->spawners); } else if (tag == ACTION_START_REPLY && concrete_self->state == STATE_VISITORS && core_vector_size(&concrete_self->visitors) == 0) { core_vector_unpack(&concrete_self->visitors, buffer); printf("DEBUG the system has %d visitors\n", (int)core_vector_size(&concrete_self->visitors)); thorium_actor_send_to_supervisor_empty(self, ACTION_START_REPLY); } else if (tag == ACTION_START_REPLY && concrete_self->state == STATE_WALKERS && core_vector_size(&concrete_self->walkers) == 0) { core_vector_unpack(&concrete_self->walkers, buffer); printf("DEBUG the system has %d walkers\n", (int)core_vector_size(&concrete_self->walkers)); core_timer_start(&concrete_self->timer); concrete_self->completed = 0; thorium_actor_send_range_int(self, &concrete_self->walkers, ACTION_SET_CONSUMER, concrete_self->writer_process); thorium_actor_send_range_vector(self, &concrete_self->walkers, ACTION_START, &concrete_self->graph_stores); } else if (tag == ACTION_SET_PRODUCERS) { core_vector_unpack(&concrete_self->graph_stores, buffer); core_timer_start(&concrete_self->timer); concrete_self->completed = 0; thorium_actor_send_range_vector(self, &concrete_self->visitors, ACTION_START, &concrete_self->graph_stores); } else if (tag == ACTION_START_REPLY && concrete_self->state == STATE_VISITORS) { ++concrete_self->completed; expected = core_vector_size(&concrete_self->visitors); if (concrete_self->completed % UNITIG_VISITOR_COUNT_PER_WORKER == 0 || concrete_self->completed == expected) { printf("PROGRESS unitig visitors %d/%d\n", concrete_self->completed, expected); } if (concrete_self->completed == expected) { core_timer_stop(&concrete_self->timer); core_timer_print_with_description(&concrete_self->timer, "Visit vertices for unitigs"); /* * Stop the visitor manager and all visitors too. */ thorium_actor_send_empty(self, concrete_self->manager, ACTION_ASK_TO_STOP); /* * Reset graph stores. */ thorium_actor_send_range_empty(self, &concrete_self->graph_stores, ACTION_RESET); concrete_self->completed = 0; } } else if (tag == ACTION_RESET_REPLY) { ++concrete_self->completed; expected = core_vector_size(&concrete_self->graph_stores); if (concrete_self->completed == expected) { concrete_self->completed = 0; concrete_self->state = STATE_WALKERS; /* * Go back at the beginning. */ thorium_actor_send_to_self_empty(self, ACTION_PING); } } else if (tag == ACTION_START_REPLY && concrete_self->state == STATE_WALKERS) { ++concrete_self->completed; expected = core_vector_size(&concrete_self->walkers); if (concrete_self->completed % UNITIG_WALKER_COUNT_PER_WORKER == 0 || concrete_self->completed == expected) { printf("PROGRESS unitig walkers %d/%d\n", concrete_self->completed, expected); } if (concrete_self->completed == expected) { core_timer_stop(&concrete_self->timer); core_timer_print_with_description(&concrete_self->timer, "Walk for unitigs"); thorium_actor_send_to_supervisor_empty(self, ACTION_SET_PRODUCERS_REPLY); } } }
void biosal_assembly_graph_store_yield_reply_summary(struct thorium_actor *self, struct thorium_message *message) { struct biosal_assembly_graph_store *concrete_self; int limit; int processed; int new_count; void *new_buffer; struct biosal_assembly_vertex *vertex; int coverage; int parent_count; int child_count; /*int child_count;*/ concrete_self = thorium_actor_concrete_actor(self); limit = 4321; processed = 0; /* * This loop gather canonical information only. */ while (processed < limit && core_map_iterator_has_next(&concrete_self->iterator)) { core_map_iterator_next(&concrete_self->iterator, NULL, (void **)&vertex); coverage = biosal_assembly_vertex_coverage_depth(vertex); parent_count = biosal_assembly_vertex_parent_count(vertex); child_count = biosal_assembly_vertex_child_count(vertex); /* * Don't count any real arc twice. */ /* child_count = biosal_assembly_vertex_child_count(vertex); concrete_self->arc_count += child_count; */ /* * Gather degree information too ! */ biosal_assembly_graph_summary_add(&concrete_self->graph_summary, coverage, parent_count, child_count); biosal_assembly_graph_summary_add(&concrete_self->graph_summary, coverage, child_count, parent_count); ++processed; } if (core_map_iterator_has_next(&concrete_self->iterator)) { thorium_actor_send_to_self_empty(self, ACTION_YIELD); } else { /* * Send the answer */ new_count = biosal_assembly_graph_summary_pack_size(&concrete_self->graph_summary); new_buffer = thorium_actor_allocate(self, new_count); biosal_assembly_graph_summary_pack(&concrete_self->graph_summary, new_buffer); thorium_actor_send_buffer(self, concrete_self->source_for_summary, ACTION_ASSEMBLY_GET_SUMMARY_REPLY, new_count, new_buffer); /* * Reset the iterator. */ core_map_iterator_destroy(&concrete_self->iterator); core_map_iterator_init(&concrete_self->iterator, &concrete_self->table); } }