|
|
|
@ -3,8 +3,8 @@
|
|
|
|
|
#include "stdlib.h"
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
|
|
|
|
#define MAX_CHUNK_SIZE 2048*2048
|
|
|
|
|
#define N_BUFFERS 3
|
|
|
|
|
#define MAX_CHUNK_SIZE 33554432*2
|
|
|
|
|
#define N_BUFFERS 8
|
|
|
|
|
|
|
|
|
|
int min(int value1, int value2) {
|
|
|
|
|
if (value1 < value2) return value1;
|
|
|
|
@ -50,10 +50,10 @@ void buffer_flush(chunk_array_t* chunk_array, buffer_t* buffer) {
|
|
|
|
|
void buffer_update(chunk_array_t* chunk_array, buffer_t* buffer, size_t pos) {
|
|
|
|
|
buffer_flush(chunk_array, buffer);
|
|
|
|
|
|
|
|
|
|
int new_init = pos/chunk_array->chunk_size;
|
|
|
|
|
buffer->init_pos = new_init * chunk_array->chunk_size;
|
|
|
|
|
int mod = get_mod(chunk_array, buffer->init_pos);
|
|
|
|
|
if (chunk_array->mmap_array) {
|
|
|
|
|
int new_init = pos/chunk_array->chunk_size;
|
|
|
|
|
buffer->init_pos = new_init * chunk_array->chunk_size;
|
|
|
|
|
int mod = get_mod(chunk_array, buffer->init_pos);
|
|
|
|
|
memcpy(buffer->data, &chunk_array->mmap_array[buffer->init_pos], mod * sizeof(double));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -90,16 +90,6 @@ chunk_array_t* chunk_array_create(char* filename, size_t total_size) {
|
|
|
|
|
|
|
|
|
|
chunk_array->chunk_size = min(MAX_CHUNK_SIZE, total_size);
|
|
|
|
|
|
|
|
|
|
if (chunk_array->chunk_size*N_BUFFERS < total_size) {
|
|
|
|
|
|
|
|
|
|
chunk_array->mmap_array = mmap ( NULL, total_size*sizeof(double), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0 );
|
|
|
|
|
|
|
|
|
|
if (chunk_array->mmap_array == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chunk_array->buffers = malloc(sizeof(buffer_t) * N_BUFFERS);
|
|
|
|
|
|
|
|
|
|
chunk_array->buffers[0] = buffer_create(chunk_array->chunk_size);
|
|
|
|
@ -112,19 +102,28 @@ chunk_array_t* chunk_array_create(char* filename, size_t total_size) {
|
|
|
|
|
if (total_size > i*chunk_array->chunk_size) {
|
|
|
|
|
chunk_array->n_buffers++;
|
|
|
|
|
chunk_array->buffers[i] = buffer_create(chunk_array->chunk_size);
|
|
|
|
|
chunk_array->buffers[i]->init_pos = chunk_array->chunk_size;
|
|
|
|
|
chunk_array->buffers[i]->init_pos = i*chunk_array->chunk_size;
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (chunk_array->chunk_size*chunk_array->n_buffers < total_size) {
|
|
|
|
|
|
|
|
|
|
chunk_array->mmap_array = mmap ( NULL, total_size*sizeof(double), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0 );
|
|
|
|
|
|
|
|
|
|
if (chunk_array->mmap_array == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chunk_array->filename = filename;
|
|
|
|
|
chunk_array->total_size = total_size;
|
|
|
|
|
return chunk_array;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buffer_t* chunk_array_update(chunk_array_t* chunk_array, size_t pos) {
|
|
|
|
|
|
|
|
|
|
buffer_t* buffer = chunk_array->buffers[0];
|
|
|
|
|
int distance = abs(buffer->init_pos - pos);
|
|
|
|
|
|
|
|
|
|