void spate_spawn_reply(struct thorium_actor *self, struct thorium_message *message) { int new_actor; int spawner; struct spate *concrete_self; concrete_self = (struct spate *)thorium_actor_concrete_actor(self); thorium_message_unpack_int(message, 0, &new_actor); if (concrete_self->input_controller == THORIUM_ACTOR_NOBODY) { concrete_self->input_controller = new_actor; thorium_actor_add_action_with_source(self, ACTION_START_REPLY, spate_start_reply_controller, concrete_self->input_controller); thorium_actor_log(self, "spate %d spawned controller %d", thorium_actor_name(self), new_actor); spawner = thorium_actor_get_spawner(self, &concrete_self->initial_actors); thorium_actor_send_int(self, spawner, ACTION_SPAWN, SCRIPT_MANAGER); } else if (concrete_self->manager_for_sequence_stores == THORIUM_ACTOR_NOBODY) { concrete_self->manager_for_sequence_stores = new_actor; thorium_actor_add_action_with_source(self, ACTION_START_REPLY, spate_start_reply_manager, concrete_self->manager_for_sequence_stores); thorium_actor_log(self, "spate %d spawned manager %d", thorium_actor_name(self), new_actor); spawner = thorium_actor_get_spawner(self, &concrete_self->initial_actors); thorium_actor_send_int(self, spawner, ACTION_SPAWN, SCRIPT_ASSEMBLY_GRAPH_BUILDER); } else if (concrete_self->assembly_graph_builder == THORIUM_ACTOR_NOBODY) { concrete_self->assembly_graph_builder = new_actor; thorium_actor_add_action_with_source(self, ACTION_START_REPLY, spate_start_reply_builder, concrete_self->assembly_graph_builder); thorium_actor_add_action_with_source(self, ACTION_SET_PRODUCERS_REPLY, spate_set_producers_reply, concrete_self->assembly_graph_builder); thorium_actor_log(self, "spate %d spawned graph builder %d", thorium_actor_name(self), new_actor); thorium_actor_send_int(self, concrete_self->manager_for_sequence_stores, ACTION_MANAGER_SET_SCRIPT, SCRIPT_SEQUENCE_STORE); } }
void thorium_actor_send_to_supervisor_int(struct thorium_actor *actor, int tag, int value) { thorium_actor_send_int(actor, thorium_actor_supervisor(actor), tag, value); }
void spate_start(struct thorium_actor *self, struct thorium_message *message) { void *buffer; int name; struct spate *concrete_self; int spawner; char *directory_name; int already_created; int argc; char **argv; #ifdef SPATE_VERBOSE thorium_actor_send_to_self_int(self, ACTION_ENABLE_LOG_LEVEL, LOG_LEVEL_DEFAULT); #endif concrete_self = (struct spate *)thorium_actor_concrete_actor(self); buffer = thorium_message_buffer(message); name = thorium_actor_name(self); /* * The buffer contains initial actors spawned by Thorium */ core_vector_unpack(&concrete_self->initial_actors, buffer); if (!spate_must_print_help(self)) { thorium_actor_log(self, "spate/%d starts", name); } if (core_vector_index_of(&concrete_self->initial_actors, &name) == 0) { concrete_self->is_leader = 1; } /* * Abort if the actor is not the leader of the tribe. */ if (!concrete_self->is_leader) { return; } if (spate_must_print_help(self)) { spate_help(self); spate_stop(self); return; } /* * Otherwise, the coverage distribution will take care of creating * the directory. */ core_timer_start(&concrete_self->timer); /* * Verify if the directory already exists. If it does, don't * do anything as it is not a good thing to overwrite previous science * results. */ argc = thorium_actor_argc(self); argv = thorium_actor_argv(self); directory_name = biosal_command_get_output_directory(argc, argv); already_created = core_directory_verify_existence(directory_name); if (already_created) { thorium_actor_log(self, "%s/%d Error: output directory \"%s\" already exists, please delete it or use a different output directory", thorium_actor_script_name(self), thorium_actor_name(self), directory_name); spate_stop(self); return; } spawner = thorium_actor_get_spawner(self, &concrete_self->initial_actors); thorium_actor_send_int(self, spawner, ACTION_SPAWN, SCRIPT_INPUT_CONTROLLER); }
void biosal_input_stream_count_in_parallel(struct thorium_actor *self, struct thorium_message *message) { struct biosal_input_stream *concrete_self; char *file; uint64_t file_size; uint64_t start_offset; uint64_t end_offset; void *buffer; int spawner; int i; int size; uint64_t parallel_block_size; /* * The block size for deciding when to spawn new actors for * I/O. */ parallel_block_size = 536870912; /* parallel_block_size = 0; --parallel_block_size; */ /* * Approach: * * 1. Check number of bytes. * 2. Determine the number of streams. * 3. Spawn streams using a manager. * 4. Set the offsets for each stream * 5. Set ask them to count */ concrete_self = (struct biosal_input_stream *)thorium_actor_concrete_actor(self); buffer = thorium_message_buffer(message); core_vector_unpack(&concrete_self->spawners, buffer); file = concrete_self->file_name; file_size = core_file_get_size(file); printf("COUNT_IN_PARALLEL %s %" PRIu64 "\n", file, file_size); start_offset = 0; i = 0; while (start_offset < file_size) { end_offset = start_offset + parallel_block_size - 1; if (end_offset > file_size - 1 || end_offset < start_offset) { end_offset = file_size - 1; } core_vector_push_back_uint64_t(&concrete_self->start_offsets, start_offset); core_vector_push_back_uint64_t(&concrete_self->end_offsets, end_offset); printf("DEBUG PARALLEL BLOCK %s %i %" PRIu64 " %" PRIu64 "\n", file, i, start_offset, end_offset); start_offset = end_offset + 1; ++i; } size = core_vector_size(&concrete_self->start_offsets); thorium_actor_add_action(self, ACTION_SPAWN_REPLY, biosal_input_stream_spawn_reply); printf("DEBUG stream/%d spawns %d streams for counting\n", thorium_actor_name(self), size); for (i = 0; i < size; i++) { spawner = thorium_actor_get_random_spawner(self, &concrete_self->spawners); thorium_actor_send_int(self, spawner, ACTION_SPAWN, SCRIPT_INPUT_STREAM); } }
/* * 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 thorium_actor_send_reply_int(struct thorium_actor *actor, int tag, int value) { thorium_actor_send_int(actor, thorium_actor_source(actor), tag, value); }
void thorium_actor_send_to_self_int(struct thorium_actor *actor, int tag, int value) { thorium_actor_send_int(actor, thorium_actor_name(actor), tag, value); }