static void source_init(struct thorium_actor *self) { struct source *concrete_self; int argc; char **argv; concrete_self = thorium_actor_concrete_actor(self); concrete_self->message_count = 0; argc = thorium_actor_argc(self); argv = thorium_actor_argv(self); concrete_self->event_count = DEFAULT_EVENT_COUNT; if (core_command_has_argument(argc, argv, OPTION_EVENT_COUNT)) { concrete_self->event_count = core_command_get_argument_value_int(argc, argv, OPTION_EVENT_COUNT); } core_vector_init(&concrete_self->targets, sizeof(int)); core_vector_set_memory_pool(&concrete_self->targets, thorium_actor_get_persistent_memory_pool(self)); concrete_self->target = -1; }
int spate_add_file(struct thorium_actor *self) { char *file; int argc; char **argv; struct thorium_message message; struct spate *concrete_self; concrete_self = (struct spate *)thorium_actor_concrete_actor(self); argc = thorium_actor_argc(self); argv = thorium_actor_argv(self); if (concrete_self->file_index < argc) { file = argv[concrete_self->file_index]; thorium_message_init(&message, ACTION_ADD_FILE, strlen(file) + 1, file); thorium_actor_send(self, concrete_self->input_controller, &message); thorium_message_destroy(&message); ++concrete_self->file_index; return 1; } return 0; }
void process_init(struct thorium_actor *self) { struct process *concrete_self; int argc; char **argv; argc = thorium_actor_argc(self); argv = thorium_actor_argv(self); concrete_self = thorium_actor_concrete_actor(self); core_vector_init(&concrete_self->actors, sizeof(int)); thorium_actor_add_action(self, ACTION_START, process_start); thorium_actor_add_action(self, ACTION_ASK_TO_STOP, process_stop); thorium_actor_add_action(self, ACTION_PING, process_ping); thorium_actor_add_action(self, ACTION_PING_REPLY, process_ping_reply); thorium_actor_add_action(self, ACTION_NOTIFY, process_notify); concrete_self->passed = 0; concrete_self->failed = 0; concrete_self->events = 0; concrete_self->minimum_buffer_size = 16; concrete_self->maximum_buffer_size = 512*1024; if (core_command_has_argument(argc, argv, MIN_BUFFER_SIZE_OPTION)) { concrete_self->maximum_buffer_size = core_command_get_argument_value_int(argc, argv, MIN_BUFFER_SIZE_OPTION); } if (core_command_has_argument(argc, argv, MAX_BUFFER_SIZE_OPTION)) { concrete_self->maximum_buffer_size = core_command_get_argument_value_int(argc, argv, MAX_BUFFER_SIZE_OPTION); } concrete_self->event_count = 100000; if (core_command_has_argument(argc, argv, EVENT_COUNT_OPTION)) { concrete_self->event_count = core_command_get_argument_value_int(argc, argv, EVENT_COUNT_OPTION); } concrete_self->concurrent_event_count = 8; if (core_command_has_argument(argc, argv, CONCURRENT_EVENT_COUNT_OPTION)) { concrete_self->concurrent_event_count = core_command_get_argument_value_int(argc, argv, CONCURRENT_EVENT_COUNT_OPTION); } concrete_self->active_messages = 0; printf("%s/%d using %s %d %s %d %s %d %s %d\n", thorium_actor_script_name(self), thorium_actor_name(self), MIN_BUFFER_SIZE_OPTION, concrete_self->minimum_buffer_size, MAX_BUFFER_SIZE_OPTION, concrete_self->maximum_buffer_size, EVENT_COUNT_OPTION, concrete_self->event_count, CONCURRENT_EVENT_COUNT_OPTION, concrete_self->concurrent_event_count); }
void framr_process_args(actor_t *actor) { int argc; char **argv; argc = thorium_actor_argc(actor); argv = thorium_actor_argv(actor); if (core_command_has_argument(argc, argv, "-v")) { thorium_actor_send_to_self_empty(actor, ACTION_ENABLE_LOG_LEVEL); } framr_t *self = thorium_actor_concrete_actor(actor); self->kmer_length = biosal_command_get_kmer_length(argc, argv); pm("kmer length set to %d\n", self->kmer_length); }
int spate_must_print_help(struct thorium_actor *self) { int argc; char **argv; int i; argc = thorium_actor_argc(self); if (argc == 1) { return 1; } argv = thorium_actor_argv(self); for (i = 0; i < argc; i++) { if (strstr(argv[i], "-help") != NULL || strstr(argv[i], "-version") != NULL) { return 1; } } return 0; }
void reader_receive(struct thorium_actor *actor, struct thorium_message *message) { int tag; int argc; char **argv; /*int i;*/ int name; struct reader *reader1; int source; uint64_t count; void *buffer; int sequences; int script; int sequence_index; char *received_sequence; int error; reader1 = (struct reader *)thorium_actor_concrete_actor(actor); tag = thorium_message_action(message); source = thorium_message_source(message); buffer = thorium_message_buffer(message); name = thorium_actor_name(actor); if (tag == ACTION_START) { core_vector_init(&reader1->spawners, 0); core_vector_unpack(&reader1->spawners, buffer); argc = thorium_actor_argc(actor); argv = thorium_actor_argv(actor); name = thorium_actor_name(actor); reader1->last_report = 0; /* printf("actor %i received %i arguments\n", name, argc); for (i = 0; i < argc ;i++) { printf(" argument %i : %s\n", i, argv[i]); } */ if (core_vector_index_of(&reader1->spawners, &name) != 0) { thorium_message_init(message, ACTION_STOP, 0, NULL); thorium_actor_send(actor, name, message); return; } if (argc == 1) { thorium_message_init(message, ACTION_STOP, 0, NULL); thorium_actor_send(actor, name, message); return; } reader1->sequence_reader = thorium_actor_spawn(actor, SCRIPT_INPUT_STREAM); reader1->file = argv[argc - 1]; thorium_message_init(message, ACTION_INPUT_OPEN, strlen(reader1->file) + 1, reader1->file); printf("actor %i: asking actor %i to count entries in %s\n", name, reader1->sequence_reader, reader1->file); thorium_actor_send(actor, reader1->sequence_reader, message); } else if (tag == ACTION_INPUT_COUNT_PROGRESS) { sequences = *(int64_t *)buffer; if (sequences < reader1->last_report + 10000000) { return; } printf("Actor %i received a progress report from actor %i: %i\n", name, source, sequences); reader1->last_report = sequences; } else if (tag == ACTION_INPUT_OPEN_REPLY && !reader1->counted) { thorium_message_unpack_int(message, 0, &error); if (error == BIOSAL_INPUT_ERROR_NO_ERROR) { printf("Successfully opened file.\n"); thorium_actor_send_reply_empty(actor, ACTION_INPUT_COUNT); } else if (error == BIOSAL_INPUT_ERROR_FILE_NOT_FOUND) { printf("Error, file not found! \n"); thorium_actor_send_to_self_empty(actor, ACTION_STOP); } else if (error == BIOSAL_INPUT_ERROR_FORMAT_NOT_SUPPORTED) { printf("Error, format not supported! \n"); thorium_actor_send_to_self_empty(actor, ACTION_STOP); } } else if (tag == ACTION_INPUT_COUNT_REPLY) { count = *(int64_t*)thorium_message_buffer(message); printf("actor %i: file has %" PRIu64 " items\n", name, count); thorium_message_init(message, ACTION_INPUT_CLOSE, 0, NULL); thorium_actor_send(actor, source, message); reader1->counted = 1; } else if (tag == ACTION_INPUT_CLOSE_REPLY && !reader1->pulled) { /* not necessary, it is already dead. */ thorium_actor_send_reply_empty(actor, ACTION_ASK_TO_STOP); printf("actor %d received ACTION_INPUT_CLOSE_REPLY from actor %d, asking it to stop" " with ACTION_ASK_TO_STOP\n", name, source); /* thorium_message_init(message, ACTION_STOP, 0, NULL); thorium_actor_send(actor, name, message); return; */ script = SCRIPT_INPUT_STREAM; thorium_message_init(message, ACTION_SPAWN, sizeof(script), &script); thorium_actor_send(actor, name, message); } else if (tag == ACTION_INPUT_CLOSE_REPLY && reader1->pulled) { thorium_actor_send_reply_empty(actor, ACTION_ASK_TO_STOP); thorium_actor_send_to_self_empty(actor, ACTION_STOP); } else if (tag == ACTION_ASK_TO_STOP_REPLY && reader1->pulled) { /* this tag will never arrive here */ thorium_message_init(message, ACTION_STOP, 0, NULL); thorium_actor_send(actor, name, message); } else if (tag == ACTION_SPAWN_REPLY && source == name) { reader1->sequence_reader = *(int *)buffer; printf("actor %d tells actor %d to open %s to pull sequences from the file\n", name, reader1->sequence_reader, reader1->file); thorium_message_init(message, ACTION_INPUT_OPEN, strlen(reader1->file) + 1, reader1->file); thorium_actor_send(actor, reader1->sequence_reader, message); } else if (tag == ACTION_INPUT_OPEN_REPLY && reader1->counted) { thorium_message_init(message, ACTION_INPUT_GET_SEQUENCE, 0, NULL); thorium_actor_send(actor, source, message); } else if (tag == ACTION_INPUT_GET_SEQUENCE_REPLY) { sequence_index = *(int *)buffer; received_sequence = (char*)buffer + sizeof(sequence_index); /* printf("DEBUG %d %s\n", sequence_index, received_sequence); */ if (sequence_index == 123456) { printf("actor %d says that sequence %d is %s.\n", name, sequence_index, received_sequence); } else if (sequence_index % 100000 == 0) { printf("actor %d is pulling sequences from fellow local actor %d," " %d sequences pulled so far !\n", name, reader1->sequence_reader, sequence_index); } if (sequence_index < 1000000) { thorium_message_init(message, ACTION_INPUT_GET_SEQUENCE, 0, NULL); thorium_actor_send(actor, source, message); } else { thorium_message_init(message, ACTION_INPUT_CLOSE, 0, NULL); thorium_actor_send(actor, source, message); reader1->pulled = 1; } } else if (tag == ACTION_INPUT_GET_SEQUENCE_END) { printf("actor %d: reached the end...\n", name); thorium_message_init(message, ACTION_INPUT_CLOSE, 0, NULL); thorium_actor_send(actor, source, message); reader1->pulled = 1; } }
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); }
/* * 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_coverage_distribution_write_distribution(struct thorium_actor *self) { struct core_map_iterator iterator; int *coverage; uint64_t *canonical_frequency; uint64_t frequency; struct biosal_coverage_distribution *concrete_actor; struct core_vector coverage_values; struct core_vector_iterator vector_iterator; struct core_buffered_file_writer descriptor; struct core_buffered_file_writer descriptor_canonical; struct core_string file_name; struct core_string canonical_file_name; int argc; char **argv; int name; char *directory_name; name = thorium_actor_name(self); argc = thorium_actor_argc(self); argv = thorium_actor_argv(self); directory_name = biosal_command_get_output_directory(argc, argv); /* Create the directory if it does not exist */ if (!core_directory_verify_existence(directory_name)) { core_directory_create(directory_name); } core_string_init(&file_name, ""); core_string_append(&file_name, directory_name); core_string_append(&file_name, "/"); core_string_append(&file_name, BIOSAL_COVERAGE_DISTRIBUTION_DEFAULT_OUTPUT_FILE); core_string_init(&canonical_file_name, ""); core_string_append(&canonical_file_name, directory_name); core_string_append(&canonical_file_name, "/"); core_string_append(&canonical_file_name, BIOSAL_COVERAGE_DISTRIBUTION_DEFAULT_OUTPUT_FILE_CANONICAL); core_buffered_file_writer_init(&descriptor, core_string_get(&file_name)); core_buffered_file_writer_init(&descriptor_canonical, core_string_get(&canonical_file_name)); concrete_actor = (struct biosal_coverage_distribution *)thorium_actor_concrete_actor(self); core_vector_init(&coverage_values, sizeof(int)); core_map_iterator_init(&iterator, &concrete_actor->distribution); #ifdef BIOSAL_COVERAGE_DISTRIBUTION_DEBUG thorium_actor_log(self, "map size %d\n", (int)core_map_size(&concrete_actor->distribution)); #endif while (core_map_iterator_has_next(&iterator)) { core_map_iterator_next(&iterator, (void **)&coverage, (void **)&canonical_frequency); #ifdef BIOSAL_COVERAGE_DISTRIBUTION_DEBUG thorium_actor_log(self, "DEBUG COVERAGE %d FREQUENCY %" PRIu64 "\n", *coverage, *frequency); #endif core_vector_push_back(&coverage_values, coverage); } core_map_iterator_destroy(&iterator); core_vector_sort_int(&coverage_values); #ifdef BIOSAL_COVERAGE_DISTRIBUTION_DEBUG thorium_actor_log(self, "after sort "); core_vector_print_int(&coverage_values); thorium_actor_log(self, "\n"); #endif core_vector_iterator_init(&vector_iterator, &coverage_values); #if 0 core_buffered_file_writer_printf(&descriptor_canonical, "Coverage\tFrequency\n"); #endif core_buffered_file_writer_printf(&descriptor, "Coverage\tFrequency\n"); #ifdef BIOSAL_COVERAGE_DISTRIBUTION_DEBUG #endif while (core_vector_iterator_has_next(&vector_iterator)) { core_vector_iterator_next(&vector_iterator, (void **)&coverage); canonical_frequency = (uint64_t *)core_map_get(&concrete_actor->distribution, coverage); frequency = 2 * *canonical_frequency; core_buffered_file_writer_printf(&descriptor_canonical, "%d %" PRIu64 "\n", *coverage, *canonical_frequency); core_buffered_file_writer_printf(&descriptor, "%d\t%" PRIu64 "\n", *coverage, frequency); } core_vector_destroy(&coverage_values); core_vector_iterator_destroy(&vector_iterator); thorium_actor_log(self, "distribution %d wrote %s\n", name, core_string_get(&file_name)); thorium_actor_log(self, "distribution %d wrote %s\n", name, core_string_get(&canonical_file_name)); core_buffered_file_writer_destroy(&descriptor); core_buffered_file_writer_destroy(&descriptor_canonical); core_string_destroy(&file_name); core_string_destroy(&canonical_file_name); }