use fork to parallel covariance

improvement-double_with_dirty_mmap_fork
Olivia Fernandez 3 years ago
parent 42bb086634
commit 794bcf9d1c

@ -2,8 +2,11 @@
#include "stdbool.h"
#include "stdlib.h"
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#define MAX_CHUNK_SIZE 2048*2048
#define MAX_CHUNK_SIZE 268435456
int min(int value1, int value2) {
if (value1 < value2) return value1;
@ -94,12 +97,22 @@ chunk_array_t* chunk_array_create(char* filename, size_t total_size) {
return NULL;
}
chunk_array->mmap_array = mmap ( NULL, total_size*sizeof(double), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0 );
int fd = open(filename, O_RDWR | O_CREAT, 0644);
if(fd < 0){
free(chunk_array);
return NULL;
}
chunk_array->mmap_array = mmap ( NULL, total_size * sizeof(double), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
if (chunk_array->mmap_array == NULL) {
free(chunk_array);
return NULL;
}
ftruncate(fd, total_size * sizeof(double));
close(fd);
chunk_array->chunk_size = min(MAX_CHUNK_SIZE, total_size);
chunk_array->buffer1 = buffer_create(chunk_array->chunk_size);
@ -113,7 +126,6 @@ chunk_array_t* chunk_array_create(char* filename, size_t total_size) {
chunk_array->buffer2 = buffer_create(chunk_array->chunk_size);
if (chunk_array->buffer2 == NULL) {
//fclose(chunk_array->fp);
buffer_free(chunk_array->buffer1);
free(chunk_array);
return NULL;

@ -4,14 +4,14 @@
/*builds the sampled covariance function*/
/*dimensions are even*/
void covariance(chunk_array_t* covar, struct vario_mod variogram, struct grid_mod mesh, int n[3]) {
int i, j, k, maille, n2[3], symmetric;
void process(chunk_array_t* covar, struct vario_mod variogram, struct grid_mod mesh, int n[3], int n2[3], int init, int end) {
int i, j, k, maille, symmetric;
double di, dj, dk;
for (i = 0; i < 3; i++)
n2[i] = n[i] / 2;
for (i = 0; i <= n2[0]; i++) {
for (i = init; i <= end; i++) {
for (j = 0; j <= n2[1]; j++) {
for (k = 0; k <= n2[2]; k++) {
@ -84,3 +84,36 @@ void covariance(chunk_array_t* covar, struct vario_mod variogram, struct grid_mo
}
}
}
/*builds the sampled covariance function*/
/*dimensions are even*/
void covariance(chunk_array_t* covar, struct vario_mod variogram, struct grid_mod mesh, int n[3]) {
int n2[3];
int i;
for (i = 0; i < 3; i++) {
n2[i] = n[i] / 2;
}
int init, end;
// child process because return value zero
if (fork() == 0) {
printf("Covar child\n");
init = 0;
end = n2[0]/2;
process(covar, variogram, mesh, n, n2, init, end);
exit(0);
}
// parent process because return value non-zero.
else {
printf("Covar parent\n");
init = n2[0]/2 + 1;
end = n2[0];
process(covar, variogram, mesh, n, n2, init, end);
wait(NULL);
}
printf("finish covariance\n");
}

Loading…
Cancel
Save