Example #1
0
dataset_t* datacache_find(datacache_t*cache, uint8_t*hash)
{
    datacache_entry_t*e = dict_lookup(cache->dict, hash);
    if(e)
        return e->dataset;
    char*filename = dataset_filename(hash);
    reader_t*r = filereader_new2(filename);
    if(!r)
        return NULL;
    dataset_t*dataset = dataset_read(r);
    if(!dataset || r->error) {
        unlink(filename);
        return NULL;
    }
    return dataset;
}
Example #2
0
int main(int argv, char ** argc) {


    problem_t problem = problem_create(201, 270);

	material_t ice = {
		.alpha = 1.1965*pow(10.0, -6.0),
		.rho = 917.3,
		.L = 334000.0,
		.kappa = 2.246
	};

	material_t snow = {
		.alpha = 6.6671*pow(10.0, -7.0),
		.rho = 584,
		.L = 334000.0,
		.kappa = 0.8048
	};


	problem.borders[0].position = 0.0;
	problem.borders[1].position = 2.5;
	problem.borders[2].position = 199.5;

	problem.materials[0] = ice;
	problem.materials[1] = snow;
	problem.beta = 0.3;

	// Read and create dataset
	FILE * datafile = fopen("data.csv", "r");
	if (datafile == NULL) {
		error_warning("Could not open input file. Using fake values.");
		problem.dataset = dataset_create(4);
	} else {
		problem.dataset = dataset_read(datafile, 4);
		fclose(datafile);
	}

    problem_print_header(&problem);
    problem_iterate(&problem, (unsigned)(24*8.64*pow(10.0, 7.0))); // 24 dag
	problem_destroy(&problem);

    return EXIT_SUCCESS;
}
Example #3
0
int main(int argc, char** argv)
{
    FILE* f;
    metadata_t* meta;
    fp_context_t* context;
    struct sort_config sc;
    dataset_t* ds;
    char target[256];
    stream_t* stream;
    config_t conf;
    external_dataset_t* ext;
    int i; 

    if(argc < 2)
    {
        printf("Barf!\n");
        exit(-1);
    }
    
    if((f = fopen(argv[1], "r")) == NULL)
    {
        printf("Cannot open dataset file %s.\n", argv[1]);
        return -1;
    }
    meta = metadata_read(f);
    sc.verbose = 1;
    sc.normalize = 0;
    sc.denormalize = 0;
    sc.benchmark = 1;
    sc.find_order = ITERATIVE;
    sc.index = KEEP;
    sc.cmp = HILBERT;
    sc.print = stdout;
    context = fp_create_context(&sc, meta->dimz, meta->dimf, meta->start_order);
    ds = dataset_read(f, meta, context);
    fclose(f);
    dataset_print(ds, FALSE);
    
    strcpy(target, argv[1]);
    strcat(target, ".stream");
    printf("Number of records: %d\n", ds->n_records);
    printf("Record size: %d\n", context->record_size);

    conf.memory_size = 1000; 
    conf.block_size = 0x100;
    conf.record_size = context->record_size;
    stream = stream_create(&conf, target);
    stream_open(stream, O_CREAT | O_TRUNC | O_SYNC | O_WRONLY);
    dataset_convert(ds, stream);
    stream_close(stream);
    stream_open(stream, O_SYNC | O_RDONLY);
    ext = external_dataset_create(stream, meta, ds->n_records);

    for(i = 0; i < ds->n_records / MEMORY_RECORDS(stream); i++)
    {
        memory_read(stream, ext->mem->records, MEMORY_RECORDS(stream));
        ext->mem->n_records = MEMORY_RECORDS(stream);
        dataset_print(ext->mem, FALSE);
    }
    if(ds->n_records % MEMORY_RECORDS(stream))
    {
        memory_read(stream, ext->mem->records, ds->n_records % MEMORY_RECORDS(stream));
        ext->mem->n_records = ds->n_records % MEMORY_RECORDS(stream);
        dataset_print(ext->mem, FALSE);
    }
    printf("Stream position: %ld vs. %ld\n", stream->pos, stream_tell(stream));
    external_dataset_sort(ext);
    
    
    external_dataset_destroy(ext);
    stream_destroy(stream);
    stats_print();
    dataset_destroy(ds);
    fp_destroy_context(context);
    metadata_destroy(meta);
    return 0;
}