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.
80 lines
2.3 KiB
C
80 lines
2.3 KiB
C
#include "geostat.h"
|
|
#include "file_array.h"
|
|
#include <math.h>
|
|
#include <stdarg.h>
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
#include "log.h"
|
|
#include "memory.h"
|
|
|
|
void clean_real(struct realization_mod* realin, int n[3], struct grid_mod grid, file_array_t* vectorresult, struct realization_mod* realout, int cores) {
|
|
double* used_ram_t0 = malloc(sizeof(double));
|
|
getVirtualMemUsed(used_ram_t0);
|
|
|
|
clock_t t = clock();
|
|
|
|
int i, j, k, maille0, maille1;
|
|
double NTOT;
|
|
|
|
NTOT = n[0] * n[1] * n[2];
|
|
/*is the output realization already allocated?*/
|
|
/*if not, memory allocation*/
|
|
|
|
log_info("RESULT = in progress, NTOT = %f", NTOT);
|
|
|
|
struct cpustat initial[cores];
|
|
struct cpustat final[cores];
|
|
|
|
for (int i = 0; i < cores; i++) {
|
|
get_stats(&initial[i], i - 1);
|
|
}
|
|
|
|
file_array_read(vectorresult);
|
|
|
|
if (realout->vector == NULL || realout->n != realin->n) {
|
|
realout->vector = (double*)malloc(realin->n * sizeof(double));
|
|
if (realout->vector == NULL) {
|
|
log_error("RESULT = failed - No memory available");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
realout->n = realin->n;
|
|
realout->code = 1;
|
|
for (k = 1; k <= grid.NZ; k++) {
|
|
for (j = 1; j <= grid.NY; j++) {
|
|
for (i = 1; i <= grid.NX; i++) {
|
|
maille1 = i + (j - 1 + (k - 1) * n[1]) * n[0];
|
|
maille0 = i - 1 + (j - 1 + (k - 1) * grid.NY) * grid.NX;
|
|
/* Modif du 18 juin 2003 */
|
|
/*realout->vector[maille0] = vectorresult[maille1]/(double) NTOT;*/
|
|
double valuemaille1;
|
|
file_array_get(vectorresult, maille1, &valuemaille1);
|
|
realout->vector[maille0] = valuemaille1;
|
|
}
|
|
}
|
|
}
|
|
|
|
t = clock() - t;
|
|
double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time
|
|
|
|
double* used_ram_tf = malloc(sizeof(double));
|
|
getVirtualMemUsed(used_ram_tf);
|
|
|
|
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]));
|
|
}
|
|
|
|
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);
|
|
}
|