You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
simulacion-permeabilidad/fftma_module/gen/lib_src/cgrid.c

77 lines
2.3 KiB
C

#include "geostat.h"
#include "log.h"
#include "memory.h"
#include <stdlib.h>
#include <time.h>
/*computes the size of the grid for FFTs*/
/*input: */
/*variogram: structure defining the variogram model*/
/*grid: structure defining the actual grid */
/*output: */
/*n: vector with the number of cells along the */
/* X, Y and Z axes for the underlying grid */
/* i = [0 1 2] */
void cgrid(struct vario_mod variogram, struct grid_mod grid, int n[3], int cores) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
clock_t t = clock();
int i, N;
double D;
log_info("RESULT = in progress");
struct cpustat initial[cores];
struct cpustat final[cores];
for (int i = 0; i < cores; i++) {
get_stats(&initial[i], i - 1);
}
if (n == NULL || n[0] == 0 || n[1] == 0 || n[2] == 0) {
for (i = 0; i < 3; i++) {
switch (i) {
case 0:
N = grid.NX;
D = grid.DX;
break;
case 1:
N = grid.NY;
D = grid.DY;
break;
case 2:
N = grid.NZ;
D = grid.DZ;
break;
}
n[i] = length(N, i, variogram.scf, variogram.ap, D, variogram.Nvario, cores);
}
} else {
if ((n[0] < grid.NX) || (n[1] < grid.NY) || (n[2] < grid.NZ)) {
log_error("RESULT = failed - Indicated dimensions are inappropriate in cgrid");
exit;
}
}
t = clock() - t;
double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time
for (int i = 0; i < cores; i++) {
get_stats(&final[i], i - 1);
}
for (int i = 0; i < cores; i++) {
log_info("CPU %d: %lf%%", i, calculate_load(&initial[i], &final[i]));
}
double* used_ram_tf = malloc(sizeof(double));
getVirtualMemUsed(used_ram_tf);
log_info("RESULT = success, n[0] = %d, n[1] = %d, n[2] = %d, ELAPSED = %f seconds, DIF USED VIRTUAL MEM = %5.1f MB", n[0], n[1], n[2], time_taken, *used_ram_tf - *used_ram_t0);
free(used_ram_t0);
free(used_ram_tf);
}