Ejemplo n.º 1
0
int bitset_resize(bitset* bset, int new_size) {

    int prev_buffer_size = calculate_buffer_size(bset->total_bits);

    int buffer_size = calculate_buffer_size(new_size);

    if(prev_buffer_size < buffer_size) {

        unsigned short int* temp = realloc(bset->bit_buffer, buffer_size); 

        if(temp == NULL) {
             return BITSET_ALLOC_ERROR;
        }

        int prev_total_buckets = (prev_buffer_size / SHORT_INT_SIZE);
        int new_buckets = (buffer_size / SHORT_INT_SIZE) - prev_total_buckets;

        memset(temp + prev_total_buckets, 0, new_buckets * SHORT_INT_SIZE);

        bset->bit_buffer = temp;
    }

    bset->total_bits = new_size;

    return BITSET_SUCCESS;
}
Ejemplo n.º 2
0
void bitset_serialize(bitset* bset, FILE* fp) {

    fwrite(&bset->total_bits, 1, sizeof(unsigned int), fp);

    int buffer_size = calculate_buffer_size(bset->total_bits);
    fwrite(bset->bit_buffer, buffer_size, 1, fp);
}
Ejemplo n.º 3
0
char *
bits_save (BITS *bits)
{
    int
        block_nbr;                      /*  Bitstring block number           */
    word
        comp_size;                      /*  Size of compressed block         */
    BITBLOCK
        *block_ptr;                     /*  Points to bitstring block        */
    byte
        *buffer = NULL,                 /*  Stream buffer                    */
        *position;                      /*  Current position in the stream   */
    long
        size;
    char
        *encoded = NULL;

    ASSERT (bits);

    size = calculate_buffer_size (bits);
    buffer = mem_alloc (size);
    if (buffer)
      {
        position = buffer;
        /*  Write bitstring header to stream                                 */
        *((int *)position) = bits-> block_count;
        position += sizeof (bits-> block_count);

        *((dbyte *)position) = bits-> free_list;
        position += sizeof (bits-> free_list);

        /*  Write bitstring blocks to stream                                 */
        for (block_nbr = 0; block_nbr < bits-> block_count; block_nbr++)
          {
            block_ptr = bits-> block [block_nbr];
            comp_size = compress_block (block_ptr-> block.data,
                                    compressed, (word)BIT_DATASIZE);

            *((dbyte *)position) = block_ptr-> right;
            position += sizeof (block_ptr-> right);

            *((int *)position) = block_ptr-> size;
            position += sizeof (block_ptr-> size);

            *((word *)position) = comp_size;
            position += sizeof (word);
            memcpy (position, compressed, comp_size);
            position += comp_size;
          }
        /* Encode binary buffer in base64                                    */
        encoded = mem_alloc ((long)((double) size * 1.5) + 2);
        if (encoded)
            encode_base64 (buffer, encoded, size);

        mem_free (buffer);
      }
    return (encoded);
}
Ejemplo n.º 4
0
/* TODO: this is very similar to snis_server's version of same function */
static int __attribute__((unused)) read_and_unpack_buffer(struct starsystem_info *ss, unsigned char *buffer, char *format, ...)
{
	va_list ap;
	struct packed_buffer pb;
	int rc, size = calculate_buffer_size(format);

	rc = snis_readsocket(ss->socket, buffer, size);
	if (rc != 0)
		return rc;
	packed_buffer_init(&pb, buffer, size);
	va_start(ap, format);
	rc = packed_buffer_extract_va(&pb, format, ap);
	va_end(ap);
	return rc;
}
Ejemplo n.º 5
0
int bitset_deserialize(bitset** bset, FILE* fp) {

    int bitset_size;
    fread(&bitset_size, 1, sizeof(unsigned int), fp);

    bitset* out;
    int creation_status = bitset_create(&out, bitset_size);
    if(creation_status != BITSET_SUCCESS) {
        return creation_status;
    } 

    int buffer_size = calculate_buffer_size(bitset_size);
    fread(out->bit_buffer, buffer_size, 1, fp);

    (*bset) = out;
    return BITSET_SUCCESS;
}
Ejemplo n.º 6
0
int bitset_create(bitset** bset, unsigned int size) {
    bitset* retval = malloc(sizeof(bitset));
    if(retval == NULL) {
        (*bset) = NULL;
        return BITSET_ALLOC_ERROR;
    }

    retval->total_bits = 0;

    int buffer_size = calculate_buffer_size(size);

    retval->bit_buffer = malloc(buffer_size);
    if(retval->bit_buffer == NULL) {
        free(retval);
        (*bset) = NULL;
        return BITSET_ALLOC_ERROR;
    }

    memset(retval->bit_buffer, 0, buffer_size);
    retval->total_bits = size;
    (*bset) = retval;
    return BITSET_SUCCESS;
}
Ejemplo n.º 7
0
int main(int argc, char** argv)
{
    struct options options;
    if (process_options(argc, argv, true, &options) != 0)
        return 0;

    if (options.rmat.a + options.rmat.b + options.rmat.c >= 1) {
        printf("Error: The sum of probabilities must equal 1\n");
        return 0;
    }
    double d = 1 - (options.rmat.a + options.rmat.b + options.rmat.c);
    xscale_node     = options.rmat.xscale_node;
    xscale_interval = options.rmat.xscale_interval;
    uint_fast32_t seed[5];
    make_mrg_seed(options.rng.userseed1, options.rng.userseed2, seed);
    mrg_state state;
    mrg_seed(&state, seed);
    //mrg_skip(&new_state, 50, 7, 0); // Do an initial skip?

    edge_t total_edges = options.rmat.edges;
    if((total_edges % options.rmat.xscale_interval) > options.rmat.xscale_node) {
        total_edges /= options.rmat.xscale_interval;
        total_edges++;
    }
    else {
        total_edges /= options.rmat.xscale_interval;
    }

    if (options.global.symmetric) {
        total_edges *= 2;
    }

    printf("Generator type: R-MAT\n");
    printf("Scale: %d (%" PRIu64 " vertices)\n", options.rmat.scale, ((uint64_t)1 << options.rmat.scale));
    printf("Edges: %" PRIet "\n", total_edges);
    printf("Probabilities: A=%4.2f, B=%4.2f, C=%4.2f, D=%4.2f\n", options.rmat.a, options.rmat.b, options.rmat.c, d);

    double start = get_time();

    // io thread
    size_t buffer_size = calculate_buffer_size(options.global.buffer_size);
    buffer_queue flushq;
    buffer_manager manager(&flushq, options.global.buffers_per_thread, buffer_size);
    io_thread_func io_func(options.global.graphname.c_str(), total_edges, &flushq, &manager, buffer_size);
    boost::thread io_thread(boost::ref(io_func));

    // worker threads
    int nthreads = options.global.nthreads;
    edge_t edges_per_thread = options.rmat.edges / nthreads;
    threadid_t* workers[nthreads];
    boost::thread* worker_threads[nthreads];
    for (int i = 0; i < nthreads; i++) {
        workers[i] = new threadid_t(i);
        thread_buffer* buffer = manager.register_thread(*workers[i]);
        // last thread gets the remainder (if any)
        edge_t start = i * edges_per_thread;
        edge_t end = (i == nthreads-1) ? (options.rmat.edges) : ((i+1) * edges_per_thread);
        worker_threads[i] = new boost::thread(generate, buffer,
                                              state, options.rmat.scale, start, end,
                                              options.rmat.a, options.rmat.b, options.rmat.c, /*d,*/
                                              options.global.symmetric);
    }

    // Wait until work completes
    for (int i = 0; i < nthreads; i++) {
        worker_threads[i]->join();
    }
    io_func.stop();
    io_thread.join();

    // cleanup
    for (int i = 0; i < nthreads; i++) {
        manager.unregister_thread(*workers[i]);
        delete worker_threads[i];
        delete workers[i];
    }

    double elapsed = get_time() - start;
    printf("Generation time: %fs\n", elapsed);

    make_ini_file(options.global.graphname.c_str(), (uint64_t)1 << options.rmat.scale, total_edges);

    return 0;
}