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/generate.c

68 lines
1.9 KiB
C

#include "geostat.h"
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include "log.h"
#include "memory.h"
/* GENERATION OF A GAUSSIAN WHITE NOISE VECTOR */
/*input: */
/* seed: seed */
/* n: number of components in the vector */
/*output: */
/* realization: structure defining the realization*/
void generate(long* seed, int n, struct realization_mod* realization) {
clock_t t = clock();
log_info("RESULT = in progress, n = %d", n);
struct cpustat st0_0, st0_1;
get_stats(&st0_0, -1);
int i;
long idum2 = 123456789, iy = 0;
long* iv;
int iset = 0;
iv = (long*)malloc(NTAB * sizeof(long));
/*negative seed*/
if (*seed > 0.0)
*seed = -(*seed);
/*realization definition*/
(*realization).n = n;
(*realization).code = 0;
(*realization).vector = (double*)malloc(n * sizeof(double));
if ((*realization).vector == NULL) {
log_error("RESULT = failed - No memory available in generate");
exit;
}
/*Gaussian white noise generation*/
for (i = 0; i < n; i++)
(*realization).vector[i] = gasdev(seed, &idum2, &iy, iv, &iset);
t = clock() - t;
double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time
double* total_ram = malloc(sizeof(double));
getTotalVirtualMem(total_ram);
double* used_ram = malloc(sizeof(double));
getVirtualMemUsed(used_ram);
log_info("TOTAL VIRTUAL MEM = %5.1f MB, USED VIRTUAL MEM = %5.1f MB, USED VIRTUAL MEM BY CURRENT PROCESS = %d MB",
*total_ram, *used_ram, getVirtualMemUsedByCurrentProcess());
get_stats(&st0_1, -1);
log_info("CPU: %lf%%\n", calculate_load(&st0_0, &st0_1));
free(total_ram);
free(used_ram);
free(iv);
log_info("RESULT = success, ELAPSED = %f seconds", time_taken);
}