#include "geostat.h" #include #include #include #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) { clock_t t = clock(); 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); } 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()); 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])); } free(total_ram); free(used_ram); free(iv); log_info("RESULT = success, ELAPSED = %f seconds", time_taken); }