SAMPLE * split_data(SAMPLE *sample, int numChunks, int randomize){

//	printf("Entire Dataset : \n");
//	test_print(*sample);
//	printf("---------------------------------------------------------------------\n");
//	printf("---------------------------------------------------------------------\n");

	int dataset_sz = sample->n;
	EXAMPLE *dataset = sample->examples;

	// randomize the datapoints
//	if(randomize == 1){
//		randomize_dataset(sample);
//	}

	int i;
	long chunkSz = dataset_sz / numChunks;
	SAMPLE *chunks = (SAMPLE*) malloc(sizeof(SAMPLE)*numChunks) ;

//	printf("Individual Chunks");
//	printf("---------------------------------------------------------------------\n");

	long datasetStartIdx;
	// create until the last but one chunk
	SAMPLE* c;
	for(i = 1; i <= numChunks - 1; i++){
		datasetStartIdx = (i-1)*chunkSz;
		printf("(OnlineSVM): Creating %d chunk \n",i );
		create_chunk(dataset, datasetStartIdx, &(chunks[i-1]), chunkSz);
		//chunks[i-1] = *c;

		//printf("AddAj-1 : %x\t%x\t%x\n",chunk->examples->y.relations, chunk->examples->x.mention_features, chunk->examples->h.mention_labels);

//		printf("Chunk-id - %d", i);
//		printf("---------------------------------------------------------------------\n");
//		test_print(*chunk);
//		printf("---------------------------------------------------------------------\n");
	}
	// create the last chunk
	datasetStartIdx = (numChunks-1) * chunkSz; // Calculate the startoffset using the old chunk sz
	chunkSz = dataset_sz - (numChunks-1) * chunkSz; // Calculate the chunk size of the last chunk
	create_chunk(dataset, datasetStartIdx, &(chunks[numChunks-1]), chunkSz);
	printf("(OnlineSVM): Creating %d chunk \n", numChunks);
	//chunks[numChunks-1] = *c;

	//printf("AddAj-1 : %x\t%x\t%x\n",chunk->examples->y.relations, chunk->examples->x.mention_features, chunk->examples->h.mention_labels);

//	printf("Chunk-id - %d", numChunks);
//	printf("---------------------------------------------------------------------\n");
//	test_print(*chunk);
//	printf("---------------------------------------------------------------------\n");

//	printf("DONE PRINTING .. COME HERE PRONTO\n");

	//exit(0);
	return chunks;
}
static apr_status_t serf_chunk_read_iovec(serf_bucket_t *bucket,
                                          apr_size_t requested,
                                          int vecs_size,
                                          struct iovec *vecs,
                                          int *vecs_used)
{
    chunk_context_t *ctx = bucket->data;
    apr_status_t status;

    /* Before proceeding, we need to fetch some data from the stream. */
    if (ctx->state == STATE_FETCH) {
        status = create_chunk(bucket);
        if (status) {
            return status;
        }
    }

    status = serf_bucket_read_iovec(ctx->chunk, requested, vecs_size, vecs,
                                    vecs_used);

    /* Mask EOF from aggregate bucket. */
    if (APR_STATUS_IS_EOF(status) && ctx->state == STATE_CHUNK) {
        status = ctx->last_status;
        ctx->state = STATE_FETCH;
    }

    return status;
}
static apr_status_t serf_chunk_read(serf_bucket_t *bucket,
                                    apr_size_t requested,
                                    const char **data, apr_size_t *len)
{
    chunk_context_t *ctx = bucket->data;
    apr_status_t status;

    /* Before proceeding, we need to fetch some data from the stream. */
    if (ctx->state == STATE_FETCH) {
        status = create_chunk(bucket);
        if (status) {
            return status;
        }
    }

    status = serf_bucket_read(ctx->chunk, requested, data, len);

    /* Mask EOF from aggregate bucket. */
    if (APR_STATUS_IS_EOF(status) && ctx->state == STATE_CHUNK) {
        status = ctx->last_status;
        ctx->state = STATE_FETCH;
    }

    return status;
}
Example #4
0
void ensure_chunks(
    Chunk *chunks, int *chunk_count,
    float x, float y, float z, int force)
{
    int p = chunked(x);
    int q = chunked(z);
    int count = *chunk_count;
    for (int i = 0; i < count; i++) {
        Chunk *chunk = chunks + i;
        if (chunk_distance(chunk, p, q) >= DELETE_CHUNK_RADIUS) {
            map_free(&chunk->map);
            glDeleteBuffers(1, &chunk->position_buffer);
            glDeleteBuffers(1, &chunk->normal_buffer);
            glDeleteBuffers(1, &chunk->uv_buffer);
            Chunk *other = chunks + (--count);
            memcpy(chunk, other, sizeof(Chunk));
        }
    }
    int rings = force ? 1 : CREATE_CHUNK_RADIUS;
    int generated = 0;
    for (int ring = 0; ring <= rings; ring++) {
        for (int dp = -ring; dp <= ring; dp++) {
            for (int dq = -ring; dq <= ring; dq++) {
                if (ring != MAX(ABS(dp), ABS(dq))) {
                    continue;
                }
                if (!force && generated && ring > 1) {
                    continue;
                }
                int a = p + dp;
                int b = q + dq;
                Chunk *chunk = find_chunk(chunks, count, a, b);
                if (chunk) {
                    if (chunk->dirty) {
                        gen_chunk_buffers(chunk);
                        generated++;
                    }
                }
                else {
                    if (count < MAX_CHUNKS) {
                        create_chunk(chunks + count, a, b);
                        generated++;
                        count++;
                    }
                }
            }
        }
    }
    *chunk_count = count;
}
Example #5
0
void				*malloc_reg(size_t size, t_zone *zone)
{
	t_chunk				*chunk;
	t_block				*block;

	block = available_block_in_zone(zone, size);
	if (block == NULL)
	{
		ft_printf("no_block_available\tcreating chunk...\n");
		chunk = create_chunk(zone);
		if (chunk == NULL)
			return (NULL);
		block = available_block_in_chunk(chunk, size);
	}
	return (split_block(block, size) + 1);
}
bool DerivableSoundStream::onGetData(sf::SoundStream::Chunk &data)
{
    PyGILState_STATE gstate;
    gstate = PyGILState_Ensure();

	static char method[] = "on_get_data";
    static char format[] = "O";

    PyObject* pyChunk = (PyObject*)(create_chunk());
    PyObject* r = PyObject_CallMethod(m_pyobj, method, format, pyChunk);
    data.samples = static_cast<const sf::Int16*>(terminate_chunk(pyChunk));
    data.sampleCount = PyObject_Length(pyChunk);

 	Py_DECREF(pyChunk);

	PyGILState_Release(gstate);

    return PyObject_IsTrue(r);
}
Example #7
0
File: arena.c Project: melted/arena
void *arena_alloc(ahandle a, size_t s) 
{
    void *mem;
    if(s < BLOB_MIN) {
        /* Allocate in a chunk */
        size_t step;
        step += ALIGNMENT - (step % ALIGNMENT);
        if(a->chunks == NULL || a->chunks->size < step) {
            create_chunk(a);
        }
        mem = a->chunks->current;
        a->chunks->current+=step;
        a->chunks->size-=step;
    } else {
        /* Allocate a separate blob */
        struct blob* new_blob = malloc(sizeof(struct blob)+s);
        new_blob->next = a->blobs;
        a->blobs = new_blob;
        mem = (void*)new_blob+sizeof(struct blob);
    }
    return mem;
}
Example #8
0
int main(int argc, char* argv[])
{
    if (argc != 2)
    {
        fprintf(stderr, "usage: %s [dest]\n", argv[0]);
        return 1;
    }
    
    /* create dest */
    if (mkdir(argv[1], 0777) == -1 && errno != EEXIST)
    {
        fprintf(stderr, "could not create %s\n", argv[1]);
        return 1;
    }
    
    char* tmps = rs_malloc(strlen(argv[1]) + 128);
    
    /* create dest/region */
    sprintf(tmps, "%s/region", argv[1]);
    if (mkdir(tmps, 0777) == -1 && errno != EEXIST)
    {
        fprintf(stderr, "could not create %s\n", tmps);
        rs_free(tmps);
        return 1;
    }
    
    /* iterate through all regions / chunks */
    int radius = 2;
    int i = 0;
    int rx, rz, cx, cz;
    bool success = true;
    uint8_t spawn_height = 64;
    for (rx = -radius; rx < radius; rx++)
    {
        for (rz = -radius; rz < radius; rz++)
        {
            sprintf(tmps, "%s/region/r.%i.%i.mcr", argv[1], rx, rz);
            RSRegion* region = rs_region_open(tmps, true);
            if (!region)
            {
                success = false;
                fprintf(stderr, "could not create %s\n", tmps);
                break;
            }
            
            i++;
            printf("writing region %i of %i ...\n", i, 4 * radius * radius);
            for (cx = 0; cx < 32; cx++)
            {
                for (cz = 0; cz < 32; cz++)
                {
                    RSTag* chunk = NULL;
                    if (rx == 0 && rz == 0 && cx == 0 && cz == 0)
                    {
                        chunk = create_chunk(rx * 32 + cx, rz * 32 + cz, &spawn_height);
                    } else {
                        chunk = create_chunk(rx * 32 + cx, rz * 32 + cz, NULL);
                    }
                    RSNBT* nbt = rs_nbt_new();
                    rs_nbt_set_root(nbt, chunk);
                    success = rs_nbt_write_to_region(nbt, region, cx, cz);
                    rs_nbt_free(nbt);
                    
                    if (!success)
                    {
                        fprintf(stderr, "error generating chunks\n");
                        break;
                    }
                }
                
                if (!success)
                    break;
            }
            
            rs_region_close(region);
            
            if (!success)
                break;
        }
        
        if (!success)
            break;
    }
    
    if (!success)
    {
        rs_free(tmps);
        return 1;
    }

    /* create level.dat file */
    sprintf(tmps, "%s/level.dat", argv[1]);
    RSTag* level_dat = create_level_dat(spawn_height);
    RSNBT* level_nbt = rs_nbt_new();
    rs_nbt_set_root(level_nbt, level_dat);
    success = rs_nbt_write_to_file(level_nbt, tmps);
    rs_nbt_free(level_nbt);
    
    rs_free(tmps);
    
    if (!success)
    {
        fprintf(stderr, "error writing level.dat\n");
        return 1;
    }
    
    return 0;
}
Example #9
0
File: chunk.c Project: kraused/pvo
int main( int argc, char** argv )
{
    int ni;
    long N;
    pvo_cookie_t  cookie;
    pvo_float3_t* pts;
    int*          cia;
    int*          cja;
    uint8_t*      types;
    pvo_vtu_file_t fh;
    double* U;
    float*  V;
    int*    ranks;
    double t0, t1, t2, t3;
    long i, nnodes, ncells;
    int N_u, N_v, N_r;
    double r_min, r_max, gamma;

    MPI_Init( &argc, &argv );
    pvo_init( MPI_COMM_WORLD );


    MPI_Barrier( MPI_COMM_WORLD );
    t0 = MPI_Wtime();

    // Minimal and maximal value for the radius
    r_min = parse_cmdline_double();
    r_max = parse_cmdline_double();

    gamma = parse_cmdline_double();

    // Number of grid cells for each direction
    N_u = parse_cmdline_double();
    N_v = parse_cmdline_double();
    N_r = parse_cmdline_double();

    /* The data is decomposed by slicing in the radial
       direction
     */
    decompose( &N_r, &r_min, &r_max );

    nnodes = (N_u+1)*(N_v+1)*(N_r+1);
    ncells =  N_u   * N_v   * N_r   ;

    pts   = malloc( nnodes*sizeof(pvo_float3_t) );
    cia   = malloc( (ncells+1)*sizeof(int) );
    cja   = malloc( 8*ncells*sizeof(int) );
    U     = malloc( nnodes*3*sizeof(double) );
    V     = malloc( ncells*sizeof(float) );
    types = malloc( ncells*sizeof(uint8_t) );
    ranks = malloc( ncells*sizeof(int) );

    ni = parse_cmdline_int();

    if( 0 == pvo_world_rank() )
    {
        printf( " +-----------------------------------------+\n" );
        printf( " |         PVO CHUNK VTU BENCHMARK         |\n" );
        printf( " +-----------------------------------------+\n" );
        printf( "\n");
        printf( " PVO_DEFAULT_LOW_IO_LAYER   : \"%s\"\n", str_low_io_layer[PVO_DEFAULT_LOW_IO_LAYER] );
        printf( " no of cores                : %d\n", pvo_world_size() );
        printf( " no of nodes                : %d\n", nnodes );
        printf( " no of cells                : %d\n", ncells );
        printf( " no of islands              : %d\n", ni );
    }

    create_chunk( N_u, N_v, N_r, r_min, r_max, gamma, nnodes, pts, ncells, cia, cja, types, U, V );
    for( i = 0; i < ncells; ++i )
       ranks[i] = pvo_world_rank();

    if( -1 == pvo_cookie_create( pvo_world_rank()%ni, &cookie ))
        MPI_Abort( MPI_COMM_WORLD, __LINE__ );

    if( -1 == pvo_cookie_insert_var( cookie, PVO_VAR_NODEDATA, PVO_VAR_FLOAT64, 3, "U", U ))
        MPI_Abort( MPI_COMM_WORLD, __LINE__ );

    if( -1 == pvo_cookie_insert_var( cookie, PVO_VAR_CELLDATA, PVO_VAR_FLOAT32, 1, "V", V ))
        MPI_Abort( MPI_COMM_WORLD, __LINE__ );

    if( -1 == pvo_cookie_insert_var( cookie, PVO_VAR_CELLDATA, PVO_VAR_INT32, 1, "ranks", ranks ))
        MPI_Abort( MPI_COMM_WORLD, __LINE__ );

    if( -1 == pvo_vtu_file_open( "chunk", cookie, nnodes, pts, ncells, cia, cja, types, &fh ))
        MPI_Abort( MPI_COMM_WORLD, __LINE__ );

    MPI_Barrier( MPI_COMM_WORLD );
    t1 = MPI_Wtime();

    pvo_file_write( (pvo_file_t )fh );

    MPI_Barrier( MPI_COMM_WORLD );
    t2 = MPI_Wtime();

    if( 0 == pvo_world_rank() )
        printf( " time [sec]                 : %f\n", t2-t1 );

     N = (3*4/*pts*/ + 3*8/*U*/)*nnodes + (4/*cia*/ + 8*4/*cja*/ + 1/*types*/ + 4/*V*/ + 4/*ranks*/)*ncells;
     MPI_Allreduce( MPI_IN_PLACE, &N, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
    if( 0 == pvo_world_rank() )
        printf( " bandwidth [MB/sec]         : %f\n", (1.0*N)/(1048576*(t2-t1)) );

    if( -1 == pvo_vtu_file_close( fh ))
        MPI_Abort( MPI_COMM_WORLD, __LINE__ );

    if( -1 == pvo_cookie_delete( cookie ))
        MPI_Abort( MPI_COMM_WORLD, __LINE__ );

    MPI_Barrier( MPI_COMM_WORLD );
    t3 = MPI_Wtime();

    if( 0 == pvo_world_rank() )
    {
        printf( " total execution time [sec] : %f\n", t3-t0 );
        printf( "\n" );
    }

    pvo_quit();
    return MPI_Finalize();
}
Example #10
0
void initialize_chunk(world_data* world, int x, int y) {
	int index = chunk_index(world, x, y);
	world->chunks.emplace(index, world_chunk());
	create_chunk(&world->chunks[index], x, y);
}
Example #11
0
int main(int argc, char **argv)
{
    RedMemSlotInfo mem_info;
    memslot_info_init(&mem_info, 1 /* groups */, 1 /* slots */, 1, 1, 0);
    memslot_info_add_slot(&mem_info, 0, 0, 0 /* delta */, 0 /* start */, ~0ul /* end */, 0 /* generation */);

    RedSurfaceCmd cmd;
    QXLSurfaceCmd qxl;

    RedCursorCmd red_cursor_cmd;
    QXLCursorCmd cursor_cmd;
    QXLCursor *cursor;
    QXLDataChunk *chunks[2];

    void *surface_mem;

    memset(&qxl, 0, sizeof(qxl));

    qxl.surface_id = 123;

    /* try to create a surface with no issues, should succeed */
    test("no issues");
    qxl.u.surface_create.format = SPICE_SURFACE_FMT_32_xRGB;
    qxl.u.surface_create.width = 128;
    qxl.u.surface_create.stride = 512;
    qxl.u.surface_create.height = 128;
    surface_mem = malloc(0x10000);
    qxl.u.surface_create.data = to_physical(surface_mem);
    if (red_get_surface_cmd(&mem_info, 0, &cmd, to_physical(&qxl)))
        failure();

    /* try to create a surface with a stride too small to fit
     * the entire width.
     * This can be used to cause buffer overflows so refuse it.
     */
    test("stride too small");
    qxl.u.surface_create.stride = 256;
    if (!red_get_surface_cmd(&mem_info, 0, &cmd, to_physical(&qxl)))
        failure();

    /* try to create a surface quite large.
     * The sizes (width and height) were chosen so the multiplication
     * using 32 bit values gives a very small value.
     * These kind of values should be refused as they will cause
     * overflows. Also the total memory for the card is not enough to
     * hold the surface so surely can't be accepted.
     */
    test("too big image");
    qxl.u.surface_create.stride = 0x08000004 * 4;
    qxl.u.surface_create.width = 0x08000004;
    qxl.u.surface_create.height = 0x40000020;
    if (!red_get_surface_cmd(&mem_info, 0, &cmd, to_physical(&qxl)))
        failure();

    /* test base cursor with no problems */
    test("base cursor command");
    memset(&cursor_cmd, 0, sizeof(cursor_cmd));
    cursor_cmd.type = QXL_CURSOR_SET;

    cursor = create_chunk(SPICE_OFFSETOF(QXLCursor, chunk), 128 * 128 * 4, NULL, 0xaa);
    cursor->header.unique = 1;
    cursor->header.width = 128;
    cursor->header.height = 128;
    cursor->data_size = 128 * 128 * 4;

    cursor_cmd.u.set.shape = to_physical(cursor);

    if (red_get_cursor_cmd(&mem_info, 0, &red_cursor_cmd, to_physical(&cursor_cmd)))
        failure();
    free(red_cursor_cmd.u.set.shape.data);
    free(cursor);

    /* a circular list of empty chunks should not be a problems */
    test("circular empty chunks");
    memset(&cursor_cmd, 0, sizeof(cursor_cmd));
    cursor_cmd.type = QXL_CURSOR_SET;

    cursor = create_chunk(SPICE_OFFSETOF(QXLCursor, chunk), 0, NULL, 0xaa);
    cursor->header.unique = 1;
    cursor->header.width = 128;
    cursor->header.height = 128;
    cursor->data_size = 128 * 128 * 4;

    chunks[0] = create_chunk(0, 0, &cursor->chunk, 0xaa);
    chunks[0]->next_chunk = to_physical(&cursor->chunk);

    cursor_cmd.u.set.shape = to_physical(cursor);

    memset(&red_cursor_cmd, 0xaa, sizeof(red_cursor_cmd));
    if (!red_get_cursor_cmd(&mem_info, 0, &red_cursor_cmd, to_physical(&cursor_cmd))) {
        /* function does not return errors so there should be no data */
        assert(red_cursor_cmd.type == QXL_CURSOR_SET);
        assert(red_cursor_cmd.u.set.position.x == 0);
        assert(red_cursor_cmd.u.set.position.y == 0);
        assert(red_cursor_cmd.u.set.shape.data_size == 0);
    }
    free(cursor);
    free(chunks[0]);

    /* a circular list of small chunks should not be a problems */
    test("circular small chunks");
    memset(&cursor_cmd, 0, sizeof(cursor_cmd));
    cursor_cmd.type = QXL_CURSOR_SET;

    cursor = create_chunk(SPICE_OFFSETOF(QXLCursor, chunk), 1, NULL, 0xaa);
    cursor->header.unique = 1;
    cursor->header.width = 128;
    cursor->header.height = 128;
    cursor->data_size = 128 * 128 * 4;

    chunks[0] = create_chunk(0, 1, &cursor->chunk, 0xaa);
    chunks[0]->next_chunk = to_physical(&cursor->chunk);

    cursor_cmd.u.set.shape = to_physical(cursor);

    memset(&red_cursor_cmd, 0xaa, sizeof(red_cursor_cmd));
    if (!red_get_cursor_cmd(&mem_info, 0, &red_cursor_cmd, to_physical(&cursor_cmd))) {
        /* function does not return errors so there should be no data */
        assert(red_cursor_cmd.type == QXL_CURSOR_SET);
        assert(red_cursor_cmd.u.set.position.x == 0);
        assert(red_cursor_cmd.u.set.position.y == 0);
        assert(red_cursor_cmd.u.set.shape.data_size == 0);
    }
    free(cursor);
    free(chunks[0]);

    free(mem_info.mem_slots[0]);
    free(mem_info.mem_slots);
    free(surface_mem);

    return exit_code;
}