#include "geostat.h" #include "chunk_array.h" #include #include #include #include #include #include #include #include "log.h" #include "memory.h" /* prebuild_gwn */ /* Produce a first construction in real space of the Gaussian white noise */ /* grid: structure defining the grid */ /*n: vector with the number of cells along the */ /* X, Y and Z axes for the underlying grid */ /* i = [0 1 2] */ /* --> 0 0 0 : n will be computed and */ /* updated as output */ /* --> nx ny nz: these dimensions are used */ /*realin: structure defining a realization - */ /* must be a Gaussian white noise */ /*realization: structure defining a realization*/ void prebuild_gwn(struct grid_mod grid, int n[3], struct realization_mod* realin, chunk_array_t* realization, int solver, long* seed, int cores) { double* used_ram_t0 = malloc(sizeof(double)); getVirtualMemUsed(used_ram_t0); clock_t t = clock(); int i, j, k, maille0, maille1; int ntot; long idum2 = 123456789, iy = 0; long* iv = (long*)malloc(NTAB * sizeof(long)); /*negative seed*/ if (*seed > 0.0) *seed = -(*seed); log_info("RESULT = in progress, n[0] = %d, n[1] = %d, n[2] = %d, solver = %d", n[0], n[1], n[2], solver); struct cpustat initial[cores]; struct cpustat final[cores]; for (int i = 0; i < cores; i++) { get_stats(&initial[i], i - 1); } ntot = n[0] * n[1] * n[2]; chunk_array_save(realization, 0, 0.); if (solver == 1) { for (i = 0; i < ntot; i++) { double value = gasdev(seed, &idum2, &iy, iv, cores); chunk_array_save(realization, i+1, value); } } else { for (k = 1; k <= n[2]; k++) { for (j = 1; j <= n[1]; j++) { for (i = 1; i <= n[0]; i++) { maille1 = i + (j - 1 + (k - 1) * n[1]) * n[0]; if (i <= grid.NX && j <= grid.NY && k <= grid.NZ) { double value = gasdev(seed, &idum2, &iy, iv, cores); chunk_array_save(realization, maille1, value); } else { chunk_array_save(realization, maille1, 0.); } } } } } 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, 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); }