void thorium_cfs_scheduler_destroy(struct thorium_scheduler *self) { struct thorium_cfs_scheduler *concrete_self; concrete_self = self->concrete_self; core_red_black_tree_destroy(&concrete_self->tree); CORE_DEBUGGER_ASSERT(core_memory_pool_profile_balance_count(&concrete_self->pool) == 0); core_memory_pool_destroy(&concrete_self->pool); }
void biosal_assembly_arc_classifier_push_arc_block(struct thorium_actor *self, struct thorium_message *message) { struct biosal_assembly_arc_classifier *concrete_self; int source; struct biosal_assembly_arc_block input_block; struct biosal_assembly_arc_block *output_block; struct core_vector output_blocks; struct core_memory_pool *ephemeral_memory; int consumer_count; struct core_vector *input_arcs; struct core_vector *output_arcs; int size; int i; struct biosal_assembly_arc *arc; void *buffer; int count; struct biosal_dna_kmer *kmer; int consumer_index; int arc_count; int consumer; struct thorium_message new_message; int new_count; void *new_buffer; int *bucket; int maximum_pending_requests; int maximum_buffer_length; int reservation; count = thorium_message_count(message); buffer = thorium_message_buffer(message); if (count == 0) { printf("Error, count is 0 (classifier_push_arc_block)\n"); return; } concrete_self = (struct biosal_assembly_arc_classifier *)thorium_actor_concrete_actor(self); source = thorium_message_source(message); consumer_count = core_vector_size(&concrete_self->consumers); ephemeral_memory = thorium_actor_get_ephemeral_memory(self); CORE_DEBUGGER_LEAK_DETECTION_BEGIN(ephemeral_memory, classify_arcs); core_vector_init(&output_blocks, sizeof(struct biosal_assembly_arc_block)); core_vector_set_memory_pool(&output_blocks, ephemeral_memory); biosal_assembly_arc_block_init(&input_block, ephemeral_memory, concrete_self->kmer_length, &concrete_self->codec); #ifdef BIOSAL_ASSEMBLY_ARC_CLASSIFIER_DEBUG printf("UNPACKING\n"); #endif biosal_assembly_arc_block_unpack(&input_block, buffer, concrete_self->kmer_length, &concrete_self->codec, ephemeral_memory); #ifdef BIOSAL_ASSEMBLY_ARC_CLASSIFIER_DEBUG printf("OK\n"); #endif input_arcs = biosal_assembly_arc_block_get_arcs(&input_block); /* * Configure the ephemeral memory reservation. */ arc_count = core_vector_size(input_arcs); reservation = (arc_count / consumer_count) * 2; core_vector_resize(&output_blocks, consumer_count); CORE_DEBUGGER_ASSERT(!core_memory_pool_has_double_free(ephemeral_memory)); /* * Initialize output blocks. * There is one for each destination. */ for (i = 0; i < consumer_count; i++) { output_block = core_vector_at(&output_blocks, i); biosal_assembly_arc_block_init(output_block, ephemeral_memory, concrete_self->kmer_length, &concrete_self->codec); biosal_assembly_arc_block_reserve(output_block, reservation); } size = core_vector_size(input_arcs); /* * Classify every arc in the input block * and put them in output blocks. */ #ifdef BIOSAL_ASSEMBLY_ARC_CLASSIFIER_DEBUG printf("ClassifyArcs arc_count= %d\n", size); #endif CORE_DEBUGGER_ASSERT(!core_memory_pool_has_double_free(ephemeral_memory)); for (i = 0; i < size; i++) { arc = core_vector_at(input_arcs, i); kmer = biosal_assembly_arc_source(arc); consumer_index = biosal_dna_kmer_store_index(kmer, consumer_count, concrete_self->kmer_length, &concrete_self->codec, ephemeral_memory); output_block = core_vector_at(&output_blocks, consumer_index); /* * Make a copy of the arc and copy it. * It will be freed */ biosal_assembly_arc_block_add_arc_copy(output_block, arc, concrete_self->kmer_length, &concrete_self->codec, ephemeral_memory); } /* * Input arcs are not needed anymore. */ biosal_assembly_arc_block_destroy(&input_block, ephemeral_memory); CORE_DEBUGGER_ASSERT(!core_memory_pool_has_double_free(ephemeral_memory)); /* * Finally, send these output blocks to consumers. */ maximum_pending_requests = 0; maximum_buffer_length = 0; /* * Figure out the maximum buffer length tor * messages. */ for (i = 0; i < consumer_count; i++) { output_block = core_vector_at(&output_blocks, i); new_count = biosal_assembly_arc_block_pack_size(output_block, concrete_self->kmer_length, &concrete_self->codec); if (new_count > maximum_buffer_length) { maximum_buffer_length = new_count; } } #if 0 printf("POOL_BALANCE %d\n", core_memory_pool_profile_balance_count(ephemeral_memory)); #endif for (i = 0; i < consumer_count; i++) { output_block = core_vector_at(&output_blocks, i); output_arcs = biosal_assembly_arc_block_get_arcs(output_block); arc_count = core_vector_size(output_arcs); /* * Don't send an empty message. */ if (arc_count > 0) { /* * Allocation is not required because new_count <= maximum_buffer_length */ new_count = biosal_assembly_arc_block_pack_size(output_block, concrete_self->kmer_length, &concrete_self->codec); new_buffer = thorium_actor_allocate(self, maximum_buffer_length); CORE_DEBUGGER_ASSERT(new_count <= maximum_buffer_length); biosal_assembly_arc_block_pack(output_block, new_buffer, concrete_self->kmer_length, &concrete_self->codec); thorium_message_init(&new_message, ACTION_ASSEMBLY_PUSH_ARC_BLOCK, new_count, new_buffer); consumer = core_vector_at_as_int(&concrete_self->consumers, i); /* * Send the message. */ thorium_actor_send(self, consumer, &new_message); thorium_message_destroy(&new_message); /* update event counters for control. */ bucket = core_vector_at(&concrete_self->pending_requests, i); ++(*bucket); ++concrete_self->active_requests; if (*bucket > maximum_pending_requests) { maximum_pending_requests = *bucket; } if (*bucket > concrete_self->maximum_pending_request_count) { ++concrete_self->consumer_count_above_threshold; } } CORE_DEBUGGER_ASSERT(!core_memory_pool_has_double_free(ephemeral_memory)); #if 0 printf("i = %d\n", i); #endif /* * Destroy output block. */ biosal_assembly_arc_block_destroy(output_block, ephemeral_memory); CORE_DEBUGGER_LEAK_CHECK_DOUBLE_FREE(ephemeral_memory); CORE_DEBUGGER_ASSERT(!core_memory_pool_has_double_free(ephemeral_memory)); } core_vector_destroy(&output_blocks); CORE_DEBUGGER_ASSERT(!core_memory_pool_has_double_free(ephemeral_memory)); CORE_DEBUGGER_LEAK_CHECK_DOUBLE_FREE(ephemeral_memory); /* * Check if a response must be sent now. */ ++concrete_self->received_blocks; concrete_self->source = source; /* * Only send a direct reply if there is enough memory. * * As long as maximum_pending_requests is lower than maximum_pending_request_count, * there is still space for at least one additional request. */ if (maximum_pending_requests < concrete_self->maximum_pending_request_count && core_memory_has_enough_bytes()) { thorium_actor_send_empty(self, concrete_self->source, ACTION_ASSEMBLY_PUSH_ARC_BLOCK_REPLY); } else { concrete_self->producer_is_waiting = 1; } CORE_DEBUGGER_LEAK_DETECTION_END(ephemeral_memory, classify_arcs); }