Ejemplo n.º 1
0
void thorium_transport_destroy(struct thorium_transport *self)
{
    /*
     * Print the report if requested.
     */
    if (core_bitmap_get_bit_uint32_t(&self->flags, FLAG_PROFILE)) {
        thorium_transport_profiler_print_report(&self->transport_profiler);
    }

    thorium_transport_profiler_destroy(&self->transport_profiler);

    CORE_DEBUGGER_ASSERT(thorium_transport_get_active_request_count(self) == 0);

    if (self->transport_interface != NULL) {
        self->transport_interface->destroy(self);

        core_memory_free(self->concrete_transport, MEMORY_TRANSPORT);
        self->concrete_transport = NULL;
    }

    self->node = NULL;
    self->rank = -1;
    self->size = -1;

    core_timer_destroy(&self->timer);
}
Ejemplo n.º 2
0
void core_string_destroy(struct core_string *string)
{
    if (string->data != NULL) {
        core_memory_free(string->data, MEMORY_STRING);
        string->data = NULL;
    }
}
Ejemplo n.º 3
0
void thorium_actor_pack_proxy_message(struct thorium_actor *self, struct thorium_message *message,
                int real_source)
{
    int real_tag;
    int count;
    int new_count;
    void *buffer;
    void *new_buffer;
    int offset;
    struct core_memory_pool *ephemeral_memory;

    /*
     * pack data in this order:
     *
     * - data (count bytes)
     * - real_source
     * - real_tag
     */
    ephemeral_memory = thorium_actor_get_ephemeral_memory(self);
    real_tag = thorium_message_action(message);
    buffer = thorium_message_buffer(message);
    count = thorium_message_count(message);

#ifdef DEBUG_BINOMIAL_TREE
    printf("DEBUG_BINOMIAL_TREE pack_proxy_message count %d source %d action %x\n", count,
                    thorium_actor_name(self),
                    real_tag);
    thorium_message_print(message);

#endif

    new_count = count + sizeof(real_source) + sizeof(real_tag);

    /* use slab allocator */
    new_buffer = core_memory_pool_allocate(ephemeral_memory, new_count);

#ifdef THORIUM_ACTOR_DEBUG
    printf("DEBUG12 core_memory_pool_allocate %p (pack proxy message)\n",
                    new_buffer);
#endif

    if (count > 0)
        core_memory_copy(new_buffer, buffer, count);

    offset = count;
    core_memory_copy((char *)new_buffer + offset, &real_source, sizeof(real_source));
    offset += sizeof(real_source);
    core_memory_copy((char *)new_buffer + offset, &real_tag, sizeof(real_tag));
    offset += sizeof(real_tag);

    thorium_message_init(message, ACTION_PROXY_MESSAGE, new_count, new_buffer);
    thorium_message_set_source(message, real_source);

#if 0
    /* free the old buffer
     */
    core_memory_free(buffer);
    buffer = NULL;
#endif
}
Ejemplo n.º 4
0
void core_fasta_input_destroy(struct biosal_input_format *input)
{
    struct core_fasta_input *fasta;

    fasta = (struct core_fasta_input *)biosal_input_format_implementation(input);
    core_buffered_reader_destroy(&fasta->reader);

    if (fasta->buffer != NULL) {
        core_memory_free(fasta->buffer, MEMORY_FASTA);
        fasta->buffer = NULL;
    }

    if (fasta->next_header != NULL) {
        core_memory_free(fasta->next_header, MEMORY_FASTA);
        fasta->next_header= NULL;
    }
}
Ejemplo n.º 5
0
void core_map_destroy(struct core_map *self)
{
    core_dynamic_hash_table_destroy(&self->table);

#ifdef CORE_MAP_ALIGNMENT_ENABLED
    core_memory_free(self->key_buffer);
    self->key_buffer = NULL;
#endif
}
Ejemplo n.º 6
0
void biosal_input_stream_destroy(struct thorium_actor *actor)
{
    struct biosal_input_stream *concrete_self;

    concrete_self = (struct biosal_input_stream *)thorium_actor_concrete_actor(actor);

#if 0
    core_string_destroy(&concrete_selffile_for_parallel_counting);
#endif

    if (concrete_self->buffer_for_sequence != NULL) {
        core_memory_free(concrete_self->buffer_for_sequence, MEMORY_INPUT_STREAM);
        concrete_self->buffer_for_sequence = NULL;
        concrete_self->maximum_sequence_length = 0;
    }

    concrete_self->open = 0;

    if (concrete_self->proxy_ready) {
        biosal_input_proxy_destroy(&concrete_self->proxy);
        concrete_self->proxy_ready = 0;
    }

    if (concrete_self->file_name != NULL) {
        core_memory_free(concrete_self->file_name, MEMORY_INPUT_STREAM);
        concrete_self->file_name = NULL;
    }

    concrete_self->file_name = NULL;
    biosal_dna_codec_destroy(&concrete_self->codec);

    core_vector_destroy(&concrete_self->mega_blocks);

    concrete_self->total_entries = 0;
    concrete_self->finished_parallel_stream_count = 0;

    core_vector_destroy(&concrete_self->spawners);
    core_vector_destroy(&concrete_self->parallel_streams);
    core_vector_destroy(&concrete_self->start_offsets);
    core_vector_destroy(&concrete_self->end_offsets);
    core_vector_destroy(&concrete_self->parallel_mega_blocks);
}
Ejemplo n.º 7
0
void core_string_combine(struct core_string *string, const char *data, int operation)
{
    int old_length;
    int length;
    int new_length;
    char *new_data;

    /*
     * Nothing to do.
     */
    if (data == NULL) {
        return;
    }

    length = strlen(data);

    /* Nothing to combine
     */
    if (length == 0) {
        return;
    }

    old_length = 0;

    if (string->data != NULL) {
        old_length = strlen(string->data);
    }

    new_length = old_length + length;

    new_data = (char *)core_memory_allocate(new_length + 1, MEMORY_STRING);

    strcpy(new_data, "");

    if (operation == CORE_STRING_APPEND) {
        if (string->data != NULL) {
            strcat(new_data, string->data);
        }
        strcat(new_data, data);

    } else if (operation == CORE_STRING_PREPEND) {
        strcat(new_data, data);
        if (string->data != NULL) {
            strcat(new_data, string->data);
        }
    }

    if (string->data != NULL) {
        core_memory_free(string->data, MEMORY_STRING);
    }

    string->data = new_data;
}
Ejemplo n.º 8
0
void core_vector_sort(struct core_vector *self, core_compare_fn_t compare)
{
    void *saved_pivot_value;
    int element_size;

    element_size = core_vector_element_size(self);

    saved_pivot_value = core_memory_allocate(element_size, MEMORY_VECTOR_HELPER);

    core_vector_quicksort(self, 0, core_vector_size(self) - 1, compare, saved_pivot_value);

    core_memory_free(saved_pivot_value, MEMORY_VECTOR_HELPER);
}
Ejemplo n.º 9
0
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);
}
Ejemplo n.º 10
0
void core_fast_ring_destroy(struct core_fast_ring *self)
{
    self->number_of_cells = 0;
    self->cell_size = 0;
    self->head = 0;
    self->tail = 0;

#ifdef CORE_FAST_RING_USE_CACHE
    self->head_cache = 0;
    self->tail_cache = 0;
#endif

    core_memory_free(self->cells, MEMORY_FAST_RING);

    self->cells = NULL;
}
Ejemplo n.º 11
0
void biosal_input_controller_destroy(struct thorium_actor *actor)
{
    struct biosal_input_controller *concrete_actor;
    int i;
    char *pointer;
    struct core_map_iterator iterator;
    struct core_vector *vector;

    concrete_actor = (struct biosal_input_controller *)thorium_actor_concrete_actor(actor);

    core_timer_destroy(&concrete_actor->input_timer);
    core_timer_destroy(&concrete_actor->counting_timer);
    core_timer_destroy(&concrete_actor->distribution_timer);

    biosal_dna_codec_destroy(&concrete_actor->codec);

    for (i = 0; i < core_vector_size(&concrete_actor->files); i++) {
        pointer = *(char **)core_vector_at(&concrete_actor->files, i);
        core_memory_free(pointer, MEMORY_CONTROLLER);
    }

    core_vector_destroy(&concrete_actor->mega_block_vector);
    core_vector_destroy(&concrete_actor->counting_streams);
    core_vector_destroy(&concrete_actor->reading_streams);
    core_vector_destroy(&concrete_actor->partition_commands);
    core_vector_destroy(&concrete_actor->consumer_active_requests);
    core_vector_destroy(&concrete_actor->stream_consumers);
    core_vector_destroy(&concrete_actor->files);
    core_vector_destroy(&concrete_actor->spawners);
    core_vector_destroy(&concrete_actor->counts);
    core_vector_destroy(&concrete_actor->consumers);
    core_vector_destroy(&concrete_actor->stores_per_spawner);
    core_queue_destroy(&concrete_actor->unprepared_spawners);

    core_map_iterator_init(&iterator, &concrete_actor->mega_blocks);
    while (core_map_iterator_has_next(&iterator)) {
        core_map_iterator_next(&iterator, NULL, (void **)&vector);

        core_vector_destroy(vector);
    }
    core_map_iterator_destroy(&iterator);
    core_map_destroy(&concrete_actor->mega_blocks);
    core_map_destroy(&concrete_actor->assigned_blocks);
}
Ejemplo n.º 12
0
void thorium_worker_pool_print_load(struct thorium_worker_pool *self, int type)
{
    int count;
    int i;
    float epoch_load;
    struct thorium_worker *worker;
    float loop_load;

    uint64_t epoch_wake_up_count;
    uint64_t loop_wake_up_count;
    /*
    int scheduling_score;
    */
    int node_name;
    char *buffer;
    char *buffer_for_wake_up_events;
    char *buffer_for_future_timeline;
    int allocated;
    int offset;
    int offset_for_wake_up;
    int offset_for_future;
    int extra;
    time_t current_time;
    int elapsed;
    float selected_load;
    uint64_t selected_wake_up_count;
    float sum;
    char loop[] = "COMPUTATION";
    char epoch[] = "EPOCH";
    char *description;
    float load;

    description = NULL;

    if (type == THORIUM_WORKER_POOL_LOAD_LOOP) {
        description = loop;
    } else if (type == THORIUM_WORKER_POOL_LOAD_EPOCH) {
        description = epoch;
    } else {
        return;
    }

    current_time = time(NULL);
    elapsed = current_time - self->starting_time;

    extra = 100;

    count = thorium_worker_pool_worker_count(self);
    allocated = count * 20 + 20 + extra;

    buffer = core_memory_allocate(allocated, MEMORY_WORKER_POOL_KEY);
    buffer_for_wake_up_events = core_memory_allocate(allocated, MEMORY_WORKER_POOL_KEY);
    buffer_for_future_timeline = core_memory_allocate(allocated, MEMORY_WORKER_POOL_KEY);
    node_name = thorium_node_name(self->node);
    offset = 0;
    offset_for_wake_up = 0;
    offset_for_future = 0;
    i = 0;
    sum = 0;

    while (i < count && offset + extra < allocated) {

        worker = thorium_worker_pool_get_worker(self, i);

        epoch_load = thorium_worker_get_epoch_load(worker);
        loop_load = thorium_worker_get_loop_load(worker);
        epoch_wake_up_count = thorium_worker_get_epoch_wake_up_count(worker);
        loop_wake_up_count = thorium_worker_get_loop_wake_up_count(worker);

        selected_load = epoch_load;
        selected_wake_up_count = epoch_wake_up_count;

        if (type == THORIUM_WORKER_POOL_LOAD_EPOCH) {
            selected_load = epoch_load;
            selected_wake_up_count = epoch_wake_up_count;

        } else if (type == THORIUM_WORKER_POOL_LOAD_LOOP) {
            selected_load = loop_load;
            selected_wake_up_count = loop_wake_up_count;
        }

        /*
        offset += sprintf(buffer + offset, " [%d %d %.2f]", i,
                        scheduling_score,
                        selected_load);
                        */
        offset += sprintf(buffer + offset, " %.2f",
                        selected_load);

        offset_for_wake_up += sprintf(buffer_for_wake_up_events + offset_for_wake_up, " %" PRIu64 "",
                        selected_wake_up_count);

        offset_for_future += sprintf(buffer_for_future_timeline + offset_for_future, " %d",
                        thorium_worker_get_scheduled_actor_count(worker));

        sum += selected_load;

        ++i;
    }

    load = sum / count;

    printf("thorium_worker_pool: node/%d %s LOAD %d s %.2f/%d (%.2f)%s\n",
                    node_name,
                    description, elapsed,
                    sum, count, load, buffer);

    printf("thorium_worker_pool: node/%d %s FUTURE_TIMELINE %d s %s\n",
                    node_name,
                    description, elapsed,
                    buffer_for_future_timeline);

    printf("thorium_worker_pool: node/%d %s WAKE_UP_COUNT %d s %s\n",
                    node_name,
                    description, elapsed,
                    buffer_for_wake_up_events);

    core_memory_free(buffer, MEMORY_WORKER_POOL_KEY);
    core_memory_free(buffer_for_wake_up_events, MEMORY_WORKER_POOL_KEY);
    core_memory_free(buffer_for_future_timeline, MEMORY_WORKER_POOL_KEY);
}
Ejemplo n.º 13
0
int main(int argc, char **argv)
{
    BEGIN_TESTS();

    {
        struct core_map big_map;
        int kmer_length = 43;
        struct biosal_dna_kmer kmer;
        int count;
        int run_test;
        int coverage;
        void *key;
        int key_length;
        int *bucket;
        int i;
        struct biosal_dna_codec codec;
        struct core_memory_pool memory;

        core_memory_pool_init(&memory, 1048576, -1);
        biosal_dna_codec_init(&codec);

        run_test = 1;
        count = 100000000;

        printf("STRESS TEST\n");

        biosal_dna_kmer_init_mock(&kmer, kmer_length, &codec, &memory);
        key_length = biosal_dna_kmer_pack_size(&kmer, kmer_length, &codec);
        biosal_dna_kmer_destroy(&kmer, &memory);

        core_map_init(&big_map, key_length, sizeof(coverage));

        key = core_memory_allocate(key_length, -1);

        i = 0;
        while (i < count && run_test) {

            biosal_dna_kmer_init_random(&kmer, kmer_length, &codec, &memory);
            biosal_dna_kmer_pack_store_key(&kmer, key, kmer_length, &codec, &memory);

            bucket = core_map_add(&big_map, key);
            coverage = 99;
            (*bucket) = coverage;

            biosal_dna_kmer_destroy(&kmer, &memory);

            if (i % 100000 == 0) {
                printf("ADD %d/%d %" PRIu64 "\n", i, count,
                                core_map_size(&big_map));
            }
            i++;
        }

        core_map_destroy(&big_map);
        core_memory_free(key, -1);
        biosal_dna_codec_destroy(&codec);
        core_memory_pool_destroy(&memory);
    }

    END_TESTS();

    return 0;
}