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.
83 lines
2.8 KiB
C
83 lines
2.8 KiB
C
#include "geostat.h"
|
|
#include <math.h>
|
|
#include <stdarg.h>
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
#include "chunk_array.h"
|
|
#include "log.h"
|
|
#include "memory.h"
|
|
|
|
/* build_real */
|
|
/* build a realization in the spectral domain */
|
|
/*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 */
|
|
/*covar: vector defining the covariance in spectral domain */
|
|
/*realization: vector defining the real part */
|
|
/*ireal: vector defining the i-part */
|
|
|
|
void build_real(int n[3], int NTOT, chunk_array_t* covar, chunk_array_t* realization, chunk_array_t* ireal, int cores) {
|
|
double* used_ram_t0 = malloc(sizeof(double));
|
|
getVirtualMemUsed(used_ram_t0);
|
|
|
|
int i, j, k, maille1;
|
|
double temp;
|
|
|
|
log_info("RESULT = in progress, NTOT = %d, covar = %f, n[0] = %d, n[1] = %d, n[2] = %d", NTOT, *covar, n[0], n[1], n[2]);
|
|
|
|
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();
|
|
|
|
/*decomposition and multiplication in the spectral domain*/
|
|
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];
|
|
chunk_array_get(covar, maille1, &temp);
|
|
if (temp > 0.) {
|
|
temp = sqrt(temp) / (double)NTOT;
|
|
} else if (temp < 0.) {
|
|
temp = sqrt(-temp) / (double)NTOT;
|
|
}
|
|
double valuerealizationmaille1, valueirealmaille1;
|
|
|
|
chunk_array_get(realization, maille1, &valuerealizationmaille1);
|
|
chunk_array_get(ireal, maille1, &valueirealmaille1);
|
|
|
|
chunk_array_save(realization, maille1, temp * valuerealizationmaille1);
|
|
chunk_array_save(ireal, maille1, temp * valueirealmaille1);
|
|
}
|
|
}
|
|
}
|
|
|
|
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, realization = %f, ireal = %f, ELAPSED = %f seconds, DIF USED VIRTUAL MEM = %5.1f MB", *realization, *ireal, time_taken, *used_ram_tf - *used_ram_t0);
|
|
|
|
free(used_ram_t0);
|
|
free(used_ram_tf);
|
|
} |