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

75 lines
2.0 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, int cores) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
log_info("RESULT = in progress, n = %d", n);
struct cpustat initial[cores];
struct cpustat final[cores];
for (int i = 0; i < cores; i++) {
get_stats(&initial[i], i - 1);
}
clock_t t = clock();
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);
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%%\n", i, calculate_load(&initial[i], &final[i]));
}
double* used_ram_tf = malloc(sizeof(double));
getVirtualMemUsed(used_ram_tf);
free(iv);
log_info("RESULT = success, ELAPSED = %f seconds, DIF USED VIRTUAL MEM = %5.1f MB", time_taken, *used_ram_tf - *used_ram_t0);
free(used_ram_t0);
free(used_ram_tf);
}