struct biosal_assembly_vertex *biosal_assembly_graph_store_find_vertex(struct thorium_actor *self, struct biosal_dna_kmer *kmer) { struct core_memory_pool *ephemeral_memory; struct biosal_assembly_graph_store *concrete_self; char *sequence; struct biosal_dna_kmer storage_kmer; char *key; struct biosal_assembly_vertex *canonical_vertex; ephemeral_memory = thorium_actor_get_ephemeral_memory(self); concrete_self = thorium_actor_concrete_actor(self); sequence = core_memory_pool_allocate(ephemeral_memory, concrete_self->kmer_length + 1); biosal_dna_kmer_get_sequence(kmer, sequence, concrete_self->kmer_length, &concrete_self->transport_codec); biosal_dna_kmer_init(&storage_kmer, sequence, &concrete_self->storage_codec, ephemeral_memory); key = core_memory_pool_allocate(ephemeral_memory, concrete_self->key_length_in_bytes); biosal_dna_kmer_pack_store_key(&storage_kmer, key, concrete_self->kmer_length, &concrete_self->storage_codec, ephemeral_memory); canonical_vertex = core_map_get(&concrete_self->table, key); #ifdef CORE_DEBUGGER_ASSERT if (canonical_vertex == NULL) { printf("not found Seq = %s name %d kmerlength %d key_length %d hash %" PRIu64 "\n", sequence, thorium_actor_name(self), concrete_self->kmer_length, concrete_self->key_length_in_bytes, biosal_dna_kmer_hash(&storage_kmer, concrete_self->kmer_length, &concrete_self->storage_codec)); } #endif CORE_DEBUGGER_ASSERT(canonical_vertex != NULL); core_memory_pool_free(ephemeral_memory, sequence); core_memory_pool_free(ephemeral_memory, key); biosal_dna_kmer_destroy(&storage_kmer, ephemeral_memory); return canonical_vertex; }
/* *This is called from within the actor running inside this worker. */ void thorium_worker_free_message(struct thorium_worker *worker, struct thorium_message *message) { int source_worker; void *buffer; buffer = thorium_message_buffer(message); source_worker = thorium_message_worker(message); if (source_worker == worker->name) { /* This is from the current worker */ core_memory_pool_free(&worker->outbound_message_memory_pool, buffer); #ifdef THORIUM_WORKER_DEBUG_INJECTION ++worker->counter_freed_outbound_buffers_from_self; #endif } else { /* This is from another fellow local worker * or from another BIOSAL node altogether. */ CORE_DEBUGGER_ASSERT(thorium_message_buffer(message) != NULL); thorium_worker_enqueue_message_for_triage(worker, message); } }
void biosal_dna_kmer_destroy(struct biosal_dna_kmer *sequence, struct core_memory_pool *memory) { if (sequence->encoded_data != NULL) { core_memory_pool_free(memory, sequence->encoded_data); sequence->encoded_data = NULL; } }
void biosal_dna_kmer_reverse_complement_self(struct biosal_dna_kmer *self, int kmer_length, struct biosal_dna_codec *codec, struct core_memory_pool *memory) { #ifdef BIOSAL_DNA_CODEC_HAS_REVERSE_COMPLEMENT_IMPLEMENTATION biosal_dna_codec_reverse_complement_in_place(codec, kmer_length, self->encoded_data); #else char *sequence; sequence = core_memory_pool_allocate(memory, kmer_length + 1); biosal_dna_kmer_get_sequence(self, sequence, kmer_length, codec); #ifdef BIOSAL_DNA_KMER_DEBUG printf("DEBUG %p before %s\n", (void *)self, sequence); #endif biosal_dna_helper_reverse_complement_in_place(sequence); #ifdef BIOSAL_DNA_KMER_DEBUG printf("DEBUG %p after %s\n", (void *)self, sequence); #endif biosal_dna_kmer_destroy(self, memory); biosal_dna_kmer_init(self, sequence, codec, memory); core_memory_pool_free(memory, sequence); sequence = NULL; #endif }
void biosal_dna_kmer_init_random(struct biosal_dna_kmer *sequence, int kmer_length, struct biosal_dna_codec *codec, struct core_memory_pool *memory) { char *dna; int i; int code; dna = (char *)core_memory_pool_allocate(memory, kmer_length + 1); for (i = 0; i < kmer_length; i++) { code = rand() % 4; if (code == 0) { dna[i] = 'A'; } else if (code == 1) { dna[i] = 'T'; } else if (code == 2) { dna[i] = 'C'; } else if (code == 3) { dna[i] = 'G'; } } dna[kmer_length] = '\0'; biosal_dna_kmer_init(sequence, dna, codec, memory); core_memory_pool_free(memory, dna); }
void core_simple_queue_free_item(struct core_simple_queue *self, struct core_simple_queue_item *item) { #ifdef USE_BLOCK_ALLOCATION item->next_ = self->garbage_; self->garbage_ = item; #else core_memory_pool_free(self->pool_, item); #endif }
void test_allocator(struct core_memory_pool *memory) { int i; int size; void *pointer; struct core_vector vector; struct core_timer timer; uint64_t elapsed; i = 1000000; size = 45; core_vector_init(&vector, sizeof(void *)); core_timer_init(&timer); core_timer_start(&timer); while (i--) { if (memory != NULL) { pointer = core_memory_pool_allocate(memory, size); } else { pointer = core_memory_allocate(size, -1); } core_vector_push_back(&vector, &pointer); } core_timer_stop(&timer); elapsed = core_timer_get_elapsed_nanoseconds(&timer); if (memory == NULL) { printf("Not using memory pool... "); } else { printf("Using memory pool... "); } printf("Elapsed : %" PRIu64 " milliseconds\n", elapsed / 1000 / 1000); size = core_vector_size(&vector); for (i = 0; i < size; ++i) { pointer = core_vector_at_as_void_pointer(&vector, i); if (memory != NULL) { core_memory_pool_free(memory, pointer); } else { core_memory_free(pointer, -1); } } core_vector_destroy(&vector); core_timer_destroy(&timer); }
void core_vector_destroy(struct core_vector *self) { if (self->data != NULL) { core_memory_pool_free(self->memory, self->data); ++self->profile_free_calls; self->data = NULL; } CORE_DEBUGGER_ASSERT(self->profile_allocate_calls == self->profile_free_calls); self->element_size = 0; self->maximum_size = 0; self->size = 0; core_vector_set_memory_pool(self, NULL); }
void biosal_dna_kmer_print(struct biosal_dna_kmer *self, int kmer_length, struct biosal_dna_codec *codec, struct core_memory_pool *memory) { char *dna_sequence; dna_sequence = core_memory_pool_allocate(memory, kmer_length + 1); biosal_dna_codec_decode(codec, kmer_length, self->encoded_data, dna_sequence); printf("KMER length: %d nucleotides, sequence: %s hash %" PRIu64 "\n", kmer_length, dna_sequence, biosal_dna_kmer_canonical_hash(self, kmer_length, codec, memory)); core_memory_pool_free(memory, dna_sequence); dna_sequence = NULL; }
void core_vector_reserve(struct core_vector *self, int64_t size) { void *new_data; int64_t old_byte_count; int64_t new_byte_count; #ifdef CORE_VECTOR_DEBUG printf("DEBUG core_vector_reserve %p %d buckets current_size %d\n", (void *)self, (int)size, (int)self->size); #endif if (size <= self->maximum_size) { return; } new_byte_count = size * self->element_size; old_byte_count = self->size * self->element_size; #ifdef CORE_VECTOR_DEBUG printf("DEBUG core_vector_reserve old_byte_count %d new_byte_count %d\n", old_byte_count, new_byte_count); #endif new_data = core_memory_pool_allocate(self->memory, new_byte_count); ++self->profile_allocate_calls; #ifdef CORE_VECTOR_DEBUG printf("DEBUG size %d old %p new %p\n", (int)self->size, (void *)self->data, (void *)new_data); #endif /* * copy old data */ if (self->size > 0) { core_memory_copy(new_data, self->data, old_byte_count); core_memory_pool_free(self->memory, self->data); ++self->profile_free_calls; self->data = NULL; } self->data = new_data; self->maximum_size = size; }
void biosal_dna_kmer_init_mock(struct biosal_dna_kmer *sequence, int kmer_length, struct biosal_dna_codec *codec, struct core_memory_pool *memory) { char *dna; int i; dna = (char *)core_memory_pool_allocate(memory, kmer_length + 1); for (i = 0; i < kmer_length; i++) { dna[i] = 'A'; } dna[kmer_length] = '\0'; biosal_dna_kmer_init(sequence, dna, codec, memory); core_memory_pool_free(memory, dna); }
void core_string_rotate_path(char *sequence, int length, int rotation, int kmer_length, struct core_memory_pool *pool) { char *buffer; /* * Impossible. */ if (length < kmer_length) { return; } /* * Simplify the rotation */ rotation %= length; buffer = core_memory_pool_allocate(pool, length); /* * Algorithm: * * 1. Copy (l - r) from old @ r to new @ 0 * 2. Copy (r - k + 1) from old @ (k - 1) to new @ (l - r) (only if (r - k + 1 > 0)) * 3. Copy (k - 1) from new @ 0 to new @ (l - k + 1) */ core_memory_copy(buffer + 0, sequence + rotation, (length - rotation)); /* * Copy the middle * */ if ((rotation - kmer_length + 1) > 0) core_memory_copy(buffer + (length - rotation), sequence + (kmer_length - 1), (rotation - kmer_length + 1)); core_memory_copy(buffer + (length - kmer_length + 1), buffer + 0, (kmer_length - 1)); /* * Copy the new sequence. */ core_memory_copy(sequence, buffer, length); core_memory_pool_free(pool, buffer); }
void thorium_actor_send_range_vector(struct thorium_actor *actor, struct core_vector *actors, int tag, struct core_vector *vector) { struct thorium_message message; int count; void *buffer; struct core_memory_pool *ephemeral_memory; ephemeral_memory = thorium_actor_get_ephemeral_memory(actor); count = core_vector_pack_size(vector); buffer = core_memory_pool_allocate(ephemeral_memory, count); core_vector_pack(vector, buffer); thorium_message_init(&message, tag, count, buffer); thorium_actor_send_range(actor, actors, &message); thorium_message_destroy(&message); core_memory_pool_free(ephemeral_memory, buffer); }
void core_simple_queue_destroy(struct core_simple_queue *self) { struct core_simple_queue_item *item; struct core_simple_queue_item *next; item = self->allocations_; while (item != NULL) { next = item->next_; core_memory_pool_free(self->pool_, item); item = next; } self->head_ = NULL; self->tail_ = NULL; self->garbage_ = NULL; self->allocations_ = NULL; self->pool_ = NULL; self->size_ = 0; self->bytes_per_unit_ = 0; }
void thorium_worker_run(struct thorium_worker *worker) { struct thorium_actor *actor; struct thorium_message other_message; #ifdef THORIUM_NODE_INJECT_CLEAN_WORKER_BUFFERS void *buffer; #endif #ifdef THORIUM_NODE_ENABLE_INSTRUMENTATION time_t current_time; int elapsed; int period; uint64_t current_nanoseconds; uint64_t elapsed_nanoseconds; #endif #ifdef THORIUM_WORKER_DEBUG int tag; int destination; struct thorium_message *message; #endif #ifdef THORIUM_WORKER_ENABLE_LOCK thorium_worker_lock(worker); #endif #ifdef THORIUM_NODE_ENABLE_INSTRUMENTATION period = THORIUM_NODE_LOAD_PERIOD; current_time = time(NULL); elapsed = current_time - worker->last_report; if (elapsed >= period) { current_nanoseconds = core_timer_get_nanoseconds(&worker->timer); #ifdef THORIUM_WORKER_DEBUG_LOAD printf("DEBUG Updating load report\n"); #endif elapsed_nanoseconds = current_nanoseconds - worker->epoch_start_in_nanoseconds; if (elapsed_nanoseconds > 0) { worker->epoch_load = (0.0 + worker->epoch_used_nanoseconds) / elapsed_nanoseconds; worker->epoch_used_nanoseconds = 0; worker->last_wake_up_count = core_thread_get_wake_up_count(&worker->thread); /* \see http://stackoverflow.com/questions/9657993/negative-zero-in-c */ if (worker->epoch_load == 0) { worker->epoch_load = 0; } worker->epoch_start_in_nanoseconds = current_nanoseconds; worker->last_report = current_time; } #ifdef THORIUM_WORKER_PRINT_SCHEDULING_QUEUE /* if (thorium_node_name(worker->node) == 0 && worker->name == 0) { */ thorium_scheduler_print(&worker->scheduler, thorium_node_name(worker->node), worker->name); /* } */ #endif if (core_bitmap_get_bit_uint32_t(&worker->flags, FLAG_DEBUG_ACTORS)) { thorium_worker_print_actors(worker, NULL); } } #endif #ifdef THORIUM_WORKER_DEBUG if (core_bitmap_get_bit_uint32_t(&worker->flags, FLAG_DEBUG)) { printf("DEBUG worker/%d thorium_worker_run\n", thorium_worker_name(worker)); } #endif /* check for messages in inbound FIFO */ if (thorium_worker_dequeue_actor(worker, &actor)) { #ifdef THORIUM_WORKER_DEBUG message = biosal_work_message(&work); tag = thorium_message_action(message); destination = thorium_message_destination(message); if (tag == ACTION_ASK_TO_STOP) { printf("DEBUG pulled ACTION_ASK_TO_STOP for %d\n", destination); } #endif /* * Update the priority of the actor * before starting the timer because this is part of the * runtime system (RTS). */ #ifdef THORIUM_UPDATE_SCHEDULING_PRIORITIES thorium_priority_assigner_update(&worker->scheduler, actor); #endif #ifdef THORIUM_NODE_ENABLE_INSTRUMENTATION core_timer_start(&worker->timer); #endif core_bitmap_set_bit_uint32_t(&worker->flags, FLAG_BUSY); /* * Dispatch message to a worker */ thorium_worker_work(worker, actor); core_bitmap_clear_bit_uint32_t(&worker->flags, FLAG_BUSY); #ifdef THORIUM_NODE_ENABLE_INSTRUMENTATION core_timer_stop(&worker->timer); elapsed_nanoseconds = core_timer_get_elapsed_nanoseconds(&worker->timer); if (elapsed_nanoseconds >= THORIUM_GRANULARITY_WARNING_THRESHOLD) { } worker->epoch_used_nanoseconds += elapsed_nanoseconds; worker->loop_used_nanoseconds += elapsed_nanoseconds; worker->scheduling_epoch_used_nanoseconds += elapsed_nanoseconds; worker->last_elapsed_nanoseconds = elapsed_nanoseconds; #endif } /* queue buffered message */ if (core_fast_queue_dequeue(&worker->outbound_message_queue_buffer, &other_message)) { if (!core_fast_ring_push_from_producer(&worker->outbound_message_queue, &other_message)) { #ifdef SHOW_FULL_RING_WARNINGS printf("thorium_worker: Warning: ring is full => outbound_message_queue\n"); #endif core_fast_queue_enqueue(&worker->outbound_message_queue_buffer, &other_message); } } #ifdef THORIUM_NODE_INJECT_CLEAN_WORKER_BUFFERS /* * Free outbound buffers, if any */ if (thorium_worker_fetch_clean_outbound_buffer(worker, &buffer)) { core_memory_pool_free(&worker->outbound_message_memory_pool, buffer); #ifdef THORIUM_WORKER_DEBUG_INJECTION ++worker->counter_freed_outbound_buffers_from_other_workers; #endif } #endif /* * Transfer messages for triage */ if (core_fast_queue_dequeue(&worker->clean_message_queue_for_triage, &other_message)) { CORE_DEBUGGER_ASSERT(thorium_message_buffer(&other_message) != NULL); thorium_worker_enqueue_message_for_triage(worker, &other_message); } #ifdef THORIUM_WORKER_ENABLE_LOCK thorium_worker_unlock(worker); #endif }
void biosal_assembly_graph_store_print(struct thorium_actor *self) { struct core_map_iterator iterator; struct biosal_dna_kmer kmer; void *key; struct biosal_assembly_vertex *value; int coverage; char *sequence; struct biosal_assembly_graph_store *concrete_self; int maximum_length; int length; struct core_memory_pool *ephemeral_memory; ephemeral_memory = thorium_actor_get_ephemeral_memory(self); concrete_self = thorium_actor_concrete_actor(self); core_map_iterator_init(&iterator, &concrete_self->table); printf("map size %d\n", (int)core_map_size(&concrete_self->table)); maximum_length = 0; while (core_map_iterator_has_next(&iterator)) { core_map_iterator_next(&iterator, (void **)&key, (void **)&value); biosal_dna_kmer_init_empty(&kmer); biosal_dna_kmer_unpack(&kmer, key, concrete_self->kmer_length, thorium_actor_get_ephemeral_memory(self), &concrete_self->storage_codec); length = biosal_dna_kmer_length(&kmer, concrete_self->kmer_length); /* printf("length %d\n", length); */ if (length > maximum_length) { maximum_length = length; } biosal_dna_kmer_destroy(&kmer, thorium_actor_get_ephemeral_memory(self)); } /* printf("MAx length %d\n", maximum_length); */ sequence = core_memory_pool_allocate(ephemeral_memory, maximum_length + 1); sequence[0] = '\0'; core_map_iterator_destroy(&iterator); core_map_iterator_init(&iterator, &concrete_self->table); while (core_map_iterator_has_next(&iterator)) { core_map_iterator_next(&iterator, (void **)&key, (void **)&value); biosal_dna_kmer_init_empty(&kmer); biosal_dna_kmer_unpack(&kmer, key, concrete_self->kmer_length, thorium_actor_get_ephemeral_memory(self), &concrete_self->storage_codec); biosal_dna_kmer_get_sequence(&kmer, sequence, concrete_self->kmer_length, &concrete_self->storage_codec); coverage = biosal_assembly_vertex_coverage_depth(value); printf("Sequence %s Coverage %d\n", sequence, coverage); biosal_dna_kmer_destroy(&kmer, thorium_actor_get_ephemeral_memory(self)); } core_map_iterator_destroy(&iterator); core_memory_pool_free(ephemeral_memory, sequence); }
void thorium_worker_destroy(struct thorium_worker *worker) { void *buffer; thorium_load_profiler_destroy(&worker->profiler); if (core_bitmap_get_bit_uint32_t(&worker->flags, FLAG_ENABLE_ACTOR_LOAD_PROFILER)) { core_buffered_file_writer_destroy(&worker->load_profile_writer); } core_map_destroy(&worker->actor_received_messages); /* thorium_worker_print_balance(worker); */ while (thorium_worker_fetch_clean_outbound_buffer(worker, &buffer)) { core_memory_pool_free(&worker->outbound_message_memory_pool, buffer); #ifdef THORIUM_WORKER_DEBUG_INJECTION ++worker->counter_freed_outbound_buffers_from_other_workers; #endif } #ifdef THORIUM_WORKER_DEBUG_INJECTION printf("AFTER COLLECTION\n"); thorium_worker_print_balance(worker); printf("THORIUM-> clean_message_queue_for_triage has %d items\n", core_fast_queue_size(&worker->clean_message_queue_for_triage)); printf("THORIUM-> clean_message_ring_for_triage has %d items\n", core_fast_ring_size_from_producer(&worker->clean_message_ring_for_triage)); printf("THORIUM-> injected_clean_outbound_buffers has %d items\n", core_fast_ring_size_from_producer(&worker->injected_clean_outbound_buffers)); #endif core_timer_destroy(&worker->timer); #ifdef THORIUM_WORKER_ENABLE_LOCK core_lock_destroy(&worker->lock); #endif core_fast_ring_destroy(&worker->actors_to_schedule); #ifdef THORIUM_NODE_INJECT_CLEAN_WORKER_BUFFERS core_fast_ring_destroy(&worker->injected_clean_outbound_buffers); core_fast_ring_destroy(&worker->clean_message_ring_for_triage); core_fast_queue_destroy(&worker->clean_message_queue_for_triage); #endif thorium_scheduler_destroy(&worker->scheduler); core_fast_ring_destroy(&worker->outbound_message_queue); core_fast_queue_destroy(&worker->outbound_message_queue_buffer); core_map_destroy(&worker->actors); core_map_iterator_destroy(&worker->actor_iterator); core_set_destroy(&worker->evicted_actors); worker->node = NULL; worker->name = -1; core_bitmap_set_bit_uint32_t(&worker->flags, FLAG_DEAD); core_memory_pool_destroy(&worker->ephemeral_memory); core_memory_pool_destroy(&worker->outbound_message_memory_pool); thorium_priority_assigner_destroy(&worker->assigner); }
void biosal_assembly_graph_store_mark_vertex_as_visited(struct thorium_actor *self, struct thorium_message *message) { struct biosal_assembly_graph_store *concrete_self; char *buffer; int source; int path_index; char *sequence; struct core_memory_pool *ephemeral_memory; struct biosal_dna_kmer kmer; struct biosal_dna_kmer storage_kmer; struct biosal_assembly_vertex *canonical_vertex; int position; void *key; int force; force = 1; position = 0; concrete_self = thorium_actor_concrete_actor(self); source = thorium_message_source(message); buffer = thorium_message_buffer(message); ephemeral_memory = thorium_actor_get_ephemeral_memory(self); /* * Get the kmer. */ biosal_dna_kmer_init_empty(&kmer); position += biosal_dna_kmer_unpack(&kmer, buffer, concrete_self->kmer_length, ephemeral_memory, &concrete_self->transport_codec); sequence = core_memory_pool_allocate(ephemeral_memory, concrete_self->kmer_length + 1); biosal_dna_kmer_get_sequence(&kmer, sequence, concrete_self->kmer_length, &concrete_self->transport_codec); biosal_dna_kmer_init(&storage_kmer, sequence, &concrete_self->storage_codec, ephemeral_memory); /* * Get store key */ key = core_memory_pool_allocate(ephemeral_memory, concrete_self->key_length_in_bytes); biosal_dna_kmer_pack_store_key(&storage_kmer, key, concrete_self->kmer_length, &concrete_self->storage_codec, ephemeral_memory); /* Get vertex. */ canonical_vertex = core_map_get(&concrete_self->table, key); biosal_dna_kmer_destroy(&kmer, ephemeral_memory); biosal_dna_kmer_destroy(&storage_kmer, ephemeral_memory); core_memory_pool_free(ephemeral_memory, key); core_memory_pool_free(ephemeral_memory, sequence); position += thorium_message_unpack_int(message, position, &path_index); /* * At this point, mark the vertex with flag BIOSAL_VERTEX_FLAG_USED * so that any other actor that attempt to grab it will have to communicate * with the actor. */ /* * This is a good idea to always update with the last one. */ if (force || !biosal_assembly_vertex_get_flag(canonical_vertex, BIOSAL_VERTEX_FLAG_USED)) { biosal_assembly_graph_store_mark_as_used(self, canonical_vertex, source, path_index); } #if 0 #endif thorium_actor_send_reply_empty(self, ACTION_MARK_VERTEX_AS_VISITED_REPLY); }
void biosal_assembly_graph_store_push_kmer_block(struct thorium_actor *self, struct thorium_message *message) { struct core_memory_pool *ephemeral_memory; struct biosal_dna_kmer_frequency_block block; struct biosal_assembly_vertex *bucket; void *packed_kmer; struct core_map_iterator iterator; struct biosal_assembly_graph_store *concrete_self; /*int tag;*/ void *key; struct core_map *kmers; struct biosal_dna_kmer kmer; void *buffer; int count; struct biosal_dna_kmer encoded_kmer; char *raw_kmer; int period; struct biosal_dna_kmer *kmer_pointer; int *frequency; ephemeral_memory = thorium_actor_get_ephemeral_memory(self); concrete_self = thorium_actor_concrete_actor(self); /*tag = thorium_message_action(message);*/ buffer = thorium_message_buffer(message); count = thorium_message_count(message); /* * Handler for PUSH_DATA */ biosal_dna_kmer_frequency_block_init(&block, concrete_self->kmer_length, ephemeral_memory, &concrete_self->transport_codec, 0); biosal_dna_kmer_frequency_block_unpack(&block, buffer, ephemeral_memory, &concrete_self->transport_codec); key = core_memory_pool_allocate(ephemeral_memory, concrete_self->key_length_in_bytes); kmers = biosal_dna_kmer_frequency_block_kmers(&block); core_map_iterator_init(&iterator, kmers); period = 2500000; raw_kmer = core_memory_pool_allocate(thorium_actor_get_ephemeral_memory(self), concrete_self->kmer_length + 1); if (!concrete_self->printed_vertex_size) { printf("DEBUG VERTEX DELIVERY %d bytes\n", count); concrete_self->printed_vertex_size = 1; } while (core_map_iterator_has_next(&iterator)) { /* * add kmers to store */ core_map_iterator_next(&iterator, (void **)&packed_kmer, (void **)&frequency); /* Store the kmer in 2 bit encoding */ biosal_dna_kmer_init_empty(&kmer); biosal_dna_kmer_unpack(&kmer, packed_kmer, concrete_self->kmer_length, ephemeral_memory, &concrete_self->transport_codec); kmer_pointer = &kmer; if (concrete_self->codec_are_different) { /* * Get a copy of the sequence */ biosal_dna_kmer_get_sequence(kmer_pointer, raw_kmer, concrete_self->kmer_length, &concrete_self->transport_codec); biosal_dna_kmer_init(&encoded_kmer, raw_kmer, &concrete_self->storage_codec, thorium_actor_get_ephemeral_memory(self)); kmer_pointer = &encoded_kmer; } biosal_dna_kmer_pack_store_key(kmer_pointer, key, concrete_self->kmer_length, &concrete_self->storage_codec, thorium_actor_get_ephemeral_memory(self)); #ifdef BIOSAL_DEBUG_ISSUE_540 if (strcmp(raw_kmer, "AGCTGGTAGTCATCACCAGACTGGAACAG") == 0 || strcmp(raw_kmer, "CGCGATCTGTTGCTGGGCCTAACGTGGTA") == 0 || strcmp(raw_kmer, "TACCACGTTAGGCCCAGCAACAGATCGCG") == 0) { printf("Examine store key for %s\n", raw_kmer); core_debugger_examine(key, concrete_self->key_length_in_bytes); } #endif bucket = core_map_get(&concrete_self->table, key); if (bucket == NULL) { /* This is the first time that this kmer is seen. */ bucket = core_map_add(&concrete_self->table, key); biosal_assembly_vertex_init(bucket); #if 0 printf("DEBUG303 ADD_KEY"); biosal_dna_kmer_print(&encoded_kmer, concrete_self->kmer_length, &concrete_self->storage_codec, ephemeral_memory); #endif } if (concrete_self->codec_are_different) { biosal_dna_kmer_destroy(&encoded_kmer, thorium_actor_get_ephemeral_memory(self)); } biosal_dna_kmer_destroy(&kmer, ephemeral_memory); biosal_assembly_vertex_increase_coverage_depth(bucket, *frequency); if (concrete_self->received >= concrete_self->last_received + period) { printf("%s/%d received %" PRIu64 " kmers so far," " store has %" PRIu64 " canonical kmers, %" PRIu64 " kmers\n", thorium_actor_script_name(self), thorium_actor_name(self), concrete_self->received, core_map_size(&concrete_self->table), 2 * core_map_size(&concrete_self->table)); concrete_self->last_received = concrete_self->received; } concrete_self->received += *frequency; } core_memory_pool_free(ephemeral_memory, key); core_memory_pool_free(ephemeral_memory, raw_kmer); core_map_iterator_destroy(&iterator); biosal_dna_kmer_frequency_block_destroy(&block, thorium_actor_get_ephemeral_memory(self)); thorium_actor_send_reply_empty(self, ACTION_PUSH_KMER_BLOCK_REPLY); }
void biosal_assembly_graph_store_push_arc_block(struct thorium_actor *self, struct thorium_message *message) { struct biosal_assembly_graph_store *concrete_self; int size; int i; void *buffer; int count; struct biosal_assembly_arc_block input_block; struct biosal_assembly_arc *arc; struct core_memory_pool *ephemeral_memory; struct core_vector *input_arcs; char *sequence; void *key; #if 0 /* * Don't do anything to rule out that this is the problem. */ thorium_actor_send_reply_empty(self, ACTION_ASSEMBLY_PUSH_ARC_BLOCK_REPLY); return; #endif concrete_self = thorium_actor_concrete_actor(self); ephemeral_memory = thorium_actor_get_ephemeral_memory(self); sequence = core_memory_pool_allocate(ephemeral_memory, concrete_self->kmer_length + 1); ++concrete_self->received_arc_block_count; count = thorium_message_count(message); buffer = thorium_message_buffer(message); biosal_assembly_arc_block_init(&input_block, ephemeral_memory, concrete_self->kmer_length, &concrete_self->transport_codec); biosal_assembly_arc_block_unpack(&input_block, buffer, concrete_self->kmer_length, &concrete_self->transport_codec, ephemeral_memory); input_arcs = biosal_assembly_arc_block_get_arcs(&input_block); size = core_vector_size(input_arcs); if (!concrete_self->printed_arc_size) { printf("DEBUG ARC DELIVERY %d bytes, %d arcs\n", count, size); concrete_self->printed_arc_size = 1; } key = core_memory_pool_allocate(ephemeral_memory, concrete_self->key_length_in_bytes); for (i = 0; i < size; i++) { arc = core_vector_at(input_arcs, i); #ifdef BIOSAL_ASSEMBLY_ADD_ARCS biosal_assembly_graph_store_add_arc(self, arc, sequence, key); #endif ++concrete_self->received_arc_count; } core_memory_pool_free(ephemeral_memory, key); biosal_assembly_arc_block_destroy(&input_block, ephemeral_memory); /* * * Add the arcs to the graph */ thorium_actor_send_reply_empty(self, ACTION_ASSEMBLY_PUSH_ARC_BLOCK_REPLY); core_memory_pool_free(ephemeral_memory, sequence); }
void biosal_assembly_graph_store_get_starting_vertex(struct thorium_actor *self, struct thorium_message *message) { struct biosal_assembly_graph_store *concrete_self; struct biosal_dna_kmer transport_kmer; struct biosal_dna_kmer storage_kmer; struct core_memory_pool *ephemeral_memory; struct thorium_message new_message; int new_count; void *new_buffer; char *sequence; void *storage_key; struct biosal_assembly_vertex *vertex; concrete_self = thorium_actor_concrete_actor(self); ephemeral_memory = thorium_actor_get_ephemeral_memory(self); while (core_map_iterator_has_next(&concrete_self->iterator)) { storage_key = NULL; vertex = NULL; core_map_iterator_next(&concrete_self->iterator, (void **)&storage_key, (void **)&vertex); /* * Skip the vertex if it does have the status * BIOSAL_VERTEX_FLAG_USED. */ if (biosal_assembly_vertex_get_flag(vertex, BIOSAL_VERTEX_FLAG_USED)) { continue; } CORE_DEBUGGER_ASSERT(storage_key != NULL); #ifdef BIOSAL_ASSEMBLY_GRAPH_STORE_DEBUG_GET_STARTING_VERTEX printf("From storage\n"); biosal_assembly_vertex_print(vertex); core_debugger_examine(storage_key, concrete_self->key_length_in_bytes); #endif biosal_dna_kmer_init_empty(&storage_kmer); biosal_dna_kmer_unpack(&storage_kmer, storage_key, concrete_self->kmer_length, ephemeral_memory, &concrete_self->storage_codec); #ifdef BIOSAL_ASSEMBLY_GRAPH_STORE_DEBUG_GET_STARTING_VERTEX printf("DEBUG starting kmer Storage kmer hash %" PRIu64 "\n", biosal_dna_kmer_hash(&storage_kmer, concrete_self->kmer_length, &concrete_self->storage_codec)); biosal_dna_kmer_print(&storage_kmer, concrete_self->kmer_length, &concrete_self->storage_codec, ephemeral_memory); #endif sequence = core_memory_pool_allocate(ephemeral_memory, concrete_self->kmer_length + 1); biosal_dna_kmer_get_sequence(&storage_kmer, sequence, concrete_self->kmer_length, &concrete_self->storage_codec); #ifdef BIOSAL_ASSEMBLY_GRAPH_STORE_DEBUG_GET_STARTING_VERTEX printf("SEQUENCE %s\n", sequence); #endif biosal_dna_kmer_init(&transport_kmer, sequence, &concrete_self->transport_codec, ephemeral_memory); new_count = biosal_dna_kmer_pack_size(&transport_kmer, concrete_self->kmer_length, &concrete_self->transport_codec); new_buffer = thorium_actor_allocate(self, new_count); biosal_dna_kmer_pack(&transport_kmer, new_buffer, concrete_self->kmer_length, &concrete_self->transport_codec); #ifdef BIOSAL_ASSEMBLY_GRAPH_STORE_DEBUG_GET_STARTING_VERTEX printf("Packed version:\n"); core_debugger_examine(new_buffer, new_count); printf("TRANSPORT Kmer new_count %d\n", new_count); biosal_dna_kmer_print(&transport_kmer, concrete_self->kmer_length, &concrete_self->transport_codec, ephemeral_memory); #endif thorium_message_init(&new_message, ACTION_ASSEMBLY_GET_STARTING_KMER_REPLY, new_count, new_buffer); thorium_actor_send_reply(self, &new_message); thorium_message_destroy(&new_message); biosal_dna_kmer_destroy(&transport_kmer, ephemeral_memory); core_memory_pool_free(ephemeral_memory, sequence); biosal_dna_kmer_destroy(&storage_kmer, ephemeral_memory); return; } /* * An empty reply means that the store has nothing more to yield. */ thorium_actor_send_reply_empty(self, ACTION_ASSEMBLY_GET_STARTING_KMER_REPLY); }