Remove logs

milestone_5
chortas 3 years ago
parent bfdc81ee4b
commit 8ab0002e44

@ -1,6 +1,5 @@
#include "Py_py-api.h"
#include "genlib.h"
#include "log.h"
#include "geostat.h"
#include "pressure.h"
#include "simpio.h"
@ -44,8 +43,6 @@
int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario_mod* variogram, struct statistic_mod* stat, int* cores) {
clock_t t = clock();
log_info("RESULT = in progress");
int i, varioNargs = 12, j = 0;
PyObject* listvario;
PyObject* vgr;
@ -59,7 +56,6 @@ int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario
stat->variance = (double*)malloc(stat->nblock_var * sizeof(double));
if (stat->variance == NULL) {
free(stat->mean);
log_error("RESULT = failed");
return 0;
}
@ -80,7 +76,6 @@ int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario
cores)) {
free(stat->mean);
free(stat->variance);
log_error("RESULT = failed");
return 0;
}
@ -90,7 +85,6 @@ int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario
if (variogram->var == NULL) {
free(stat->mean);
free(stat->variance);
log_error("RESULT = failed");
return 0;
}
variogram->vario = (int*)malloc(variogram->Nvario * sizeof(int));
@ -98,7 +92,6 @@ int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario
free(stat->mean);
free(stat->variance);
free(variogram->var);
log_error("RESULT = failed");
return 0;
}
variogram->alpha = (double*)malloc(variogram->Nvario * sizeof(double));
@ -107,7 +100,6 @@ int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario
free(stat->variance);
free(variogram->var);
free(variogram->vario);
log_error("RESULT = failed");
return 0;
}
variogram->scf = (double*)malloc(3 * variogram->Nvario * sizeof(double));
@ -117,7 +109,6 @@ int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario
free(variogram->var);
free(variogram->vario);
free(variogram->alpha);
log_error("RESULT = failed");
return 0;
}
variogram->ap = (double*)malloc(9 * variogram->Nvario * sizeof(double));
@ -128,13 +119,11 @@ int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario
free(variogram->vario);
free(variogram->alpha);
free(variogram->scf);
log_error("RESULT = failed");
return 0;
}
for (i = 0; i < variogram->Nvario; i++) {
vgr = PyList_GetItem(listvario, i);
if (PyTuple_Size(vgr) != 12) {
log_error("RESULT = failed");
return 0;
}
(variogram->var)[i] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++));
@ -154,6 +143,5 @@ int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario
t = clock() - t;
double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time
log_info("RESULT = success, ELAPSED = %f seconds", time_taken);
return 1;
}

@ -4,8 +4,6 @@
#include "simpio.h"
#include "toolsFFTMA.h"
#include "toolsIO.h"
#include "log.h"
#include "memory.h"
#include <Python.h>
#include <numpy/arrayobject.h>
#include <stdarg.h>
@ -20,11 +18,6 @@
/* Y is the realization with mean and variance wanted */
void Py_kgeneration(long seed, struct grid_mod grid, struct statistic_mod stat, struct vario_mod variogram, struct realization_mod* Z, struct realization_mod* Y, int n[3], int cores) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
clock_t t = clock();
int i, N;
int typelog;
@ -34,15 +27,6 @@ void Py_kgeneration(long seed, struct grid_mod grid, struct statistic_mod stat,
n[1] = 0;
n[2] = 0;
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);
}
generate(&seed, N, Z, cores);
/*FFTMA*/
@ -55,26 +39,4 @@ void Py_kgeneration(long seed, struct grid_mod grid, struct statistic_mod stat,
typelog = stat.type + 2;
nor2log(Y, typelog, Y);
}
printf("termino nor2log\n");
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);
printf("termino pykgeneration\n");
free(used_ram_t0);
free(used_ram_tf);
}

@ -1,6 +1,4 @@
#include "geostat.h"
#include "log.h"
#include "memory.h"
#include <math.h>
#include <stdarg.h>
#include <stddef.h>
@ -22,21 +20,8 @@
/*ireal: vector defining the i-part */
void build_real(int n[3], int NTOT, double* covar, double* realization, double* ireal, int cores) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
clock_t t = clock();
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);
}
/*decomposition and multiplication in the spectral domain*/
for (k = 1; k <= n[2]; k++) {
@ -54,23 +39,4 @@ void build_real(int n[3], int NTOT, double* covar, double* realization, double*
}
}
}
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);
}

@ -1,26 +1,10 @@
#include "genlib.h"
#include "log.h"
#include "memory.h"
#include <math.h>
#include <stdio.h>
#include <time.h>
/*cardsin covariance function*/
double cardsin(double h, int cores) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
clock_t t = clock();
log_info("RESULT = in progress, h = %f", h);
struct cpustat initial[cores];
struct cpustat final[cores];
for (int i = 0; i < cores; i++) {
get_stats(&initial[i], i - 1);
}
float delta = 20.371;
double z;
@ -31,24 +15,5 @@ double cardsin(double h, int cores) {
z = 1.;
}
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, z = %f, ELAPSED = %f seconds, DIF USED VIRTUAL MEM = %5.1f MB", z, time_taken, *used_ram_tf - *used_ram_t0);
free(used_ram_t0);
free(used_ram_tf);
return z;
}

@ -1,6 +1,4 @@
#include "geostat.h"
#include "log.h"
#include "memory.h"
#include <stdlib.h>
#include <time.h>
@ -13,23 +11,9 @@
/* X, Y and Z axes for the underlying grid */
/* i = [0 1 2] */
void cgrid(struct vario_mod variogram, struct grid_mod grid, int n[3], int cores) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
clock_t t = clock();
int i, N;
double D;
log_info("RESULT = in progress");
struct cpustat initial[cores];
struct cpustat final[cores];
for (int i = 0; i < cores; i++) {
get_stats(&initial[i], i - 1);
}
if (n == NULL || n[0] == 0 || n[1] == 0 || n[2] == 0) {
for (i = 0; i < 3; i++) {
switch (i) {
@ -50,27 +34,7 @@ void cgrid(struct vario_mod variogram, struct grid_mod grid, int n[3], int cores
}
} else {
if ((n[0] < grid.NX) || (n[1] < grid.NY) || (n[2] < grid.NZ)) {
log_error("RESULT = failed - Indicated dimensions are inappropriate in cgrid");
exit;
}
}
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, n[0] = %d, n[1] = %d, n[2] = %d, ELAPSED = %f seconds, DIF USED VIRTUAL MEM = %5.1f MB", n[0], n[1], n[2], time_taken, *used_ram_tf - *used_ram_t0);
free(used_ram_t0);
free(used_ram_tf);
}

@ -1,6 +1,4 @@
#include "geostat.h"
#include "log.h"
#include "memory.h"
#include <math.h>
#include <stdarg.h>
#include <stddef.h>
@ -10,11 +8,6 @@
#include <time.h>
void clean_real(struct realization_mod* realin, int n[3], struct grid_mod grid, double* 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;
@ -22,19 +15,9 @@ void clean_real(struct realization_mod* realin, int n[3], struct grid_mod grid,
/*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);
}
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;
}
}
@ -52,23 +35,4 @@ void clean_real(struct realization_mod* realin, int n[3], struct grid_mod grid,
}
}
}
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);
}

@ -1,26 +1,10 @@
#include "genlib.h"
#include "geostat.h"
#include "log.h"
#include "memory.h"
#include <math.h>
#include <time.h>
/*selection of model covariance*/
double cov_value(struct vario_mod variogram, double di, double dj, double dk, int cores) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
clock_t t = clock();
log_info("RESULT = in progress, di = %f, dj = %f, dk = %f", di, dj, dk);
struct cpustat initial[cores];
struct cpustat final[cores];
for (int i = 0; i < cores; i++) {
get_stats(&initial[i], i - 1);
}
double hx, hy, hz, h;
double cov;
int k;
@ -64,25 +48,5 @@ double cov_value(struct vario_mod variogram, double di, double dj, double dk, in
break;
}
}
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, cov = %f, hx = %f, hy = %f, hz = %f, h = %f , ELAPSED = %f seconds, DIF USED VIRTUAL MEM = %5.1f MB", cov, hx, hy, hz, h, time_taken, *used_ram_tf - *used_ram_t0);
free(used_ram_t0);
free(used_ram_tf);
return cov;
}

@ -1,28 +1,12 @@
#include "geostat.h"
#include "log.h"
#include "memory.h"
#include <time.h>
/*builds the sampled covariance function*/
/*dimensions are even*/
void covariance(double* covar, struct vario_mod variogram, struct grid_mod mesh, int n[3], int cores) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
clock_t t = clock();
int i, j, k, maille, n2[3], symmetric;
double di, dj, dk;
log_info("RESULT = in progress");
struct cpustat initial[cores];
struct cpustat final[cores];
for (int i = 0; i < cores; i++) {
get_stats(&initial[i], i - 1);
}
for (i = 0; i < 3; i++)
n2[i] = n[i] / 2;
@ -90,23 +74,4 @@ void covariance(double* covar, struct vario_mod variogram, struct grid_mod mesh,
}
}
}
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, di = %f, dj = %f, dk = %f, ELAPSED = %f seconds, DIF USED VIRTUAL MEM = %5.1f MB", di, dj, dk, time_taken, *used_ram_tf - *used_ram_t0);
free(used_ram_t0);
free(used_ram_tf);
}

@ -1,26 +1,10 @@
#include "genlib.h"
#include "log.h"
#include "memory.h"
#include <math.h>
#include <stdio.h>
#include <time.h>
/*cubic covariance function*/
double cubic(double h, int cores) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
clock_t t = clock();
log_info("RESULT = in progress, h = %f", h);
struct cpustat initial[cores];
struct cpustat final[cores];
for (int i = 0; i < cores; i++) {
get_stats(&initial[i], i - 1);
}
double z;
if (h >= 1.) {
@ -28,25 +12,6 @@ double cubic(double h, int cores) {
} else {
z = 1. - 7. * (double)(h * h) + (35. / 4.) * (double)(h * h * h) - 3.5 * (double)(h * h * h * h * h) + .75 * (double)(h * h * h * h * h * h * h);
}
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, z = %f, ELAPSED = %f seconds, DIF USED VIRTUAL MEM = %5.1f MB", z, time_taken, *used_ram_tf - *used_ram_t0);
free(used_ram_t0);
free(used_ram_tf);
return z;
}

@ -1,11 +1,8 @@
#include "genlib.h"
#include "log.h"
#include <math.h>
#include <stdio.h>
/*exponential covariance function*/
double exponential(double h) {
log_info("RESULT = in progress, h = %f", h);
return (exp(-3. * (double)h));
}

@ -1,6 +1,4 @@
#include "geostat.h"
#include "log.h"
#include "memory.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
@ -25,20 +23,6 @@
/*realout: structure defining a realization - */
void FFTMA2(struct vario_mod variogram, struct grid_mod grid, int n[3], struct realization_mod* realin, struct realization_mod* realout, int cores, long* seed) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
clock_t t = clock();
log_info("RESULT = in progress");
struct cpustat initial[cores];
struct cpustat final[cores];
for (int i = 0; i < cores; i++) {
get_stats(&initial[i], i - 1);
}
int NTOT, i, j, k, NMAX, NDIM, ntot, nmax, NXYZ, nxyz;
int solver;
double temp;
@ -99,9 +83,6 @@ void FFTMA2(struct vario_mod variogram, struct grid_mod grid, int n[3], struct r
/* build realization in spectral domain */
build_real(n, NTOT, covar, realization, ireal, cores);
double* used_ram_tf = malloc(sizeof(double));
getVirtualMemUsed(used_ram_tf);
free(covar);
/*backward fourier transform*/
@ -113,20 +94,4 @@ void FFTMA2(struct vario_mod variogram, struct grid_mod grid, int n[3], struct r
/*output realization*/
clean_real(realin, n, grid, realization, realout, cores);
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]));
}
log_info("RESULT = success, NTOT = %d, NMAX = %d, NDIM = %d, ntot = %d, nmax = %d, NXYZ = %d, nxyz = %d, ELAPSED = %f seconds, DIF USED VIRTUAL MEM = %5.1f MB", NTOT, NMAX, NDIM, ntot, nmax, NXYZ, nxyz, time_taken, *used_ram_tf - *used_ram_t0);
free(used_ram_t0);
free(used_ram_tf);
}

@ -1,5 +1,3 @@
#include "log.h"
#include "memory.h"
#include <math.h>
#include <stdio.h>
#include <time.h>
@ -93,20 +91,6 @@
/* 10-06-2000, MLR */
void fourt(double* datar, double* datai, int nn[3], int ndim, int ifrwd, int icplx, double* workr, double* worki, int cores) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
clock_t t = clock();
log_info("RESULT = in progress");
struct cpustat initial[cores];
struct cpustat final[cores];
for (int i = 0; i < cores; i++) {
get_stats(&initial[i], i - 1);
}
int ifact[21], ntot, idim, np1, n, np2, m, ntwo, iff, idiv, iquot, irem, inon2, non2p, np0, nprev, icase, ifmin, i, j, jmax, np2hf, i2, i1max, i3, j3, i1, ifp1, ifp2, i2max, i1rng, istep, imin, imax, mmax, mmin, mstep, j1, j2max, j2, jmin, j3max, nhalf;
double theta, wstpr, wstpi, wminr, wmini, wr, wi, wtemp, thetm, wmstr, wmsti, twowr, sr, si, oldsr, oldsi, stmpr, stmpi, tempr, tempi, difi, difr, sumr, sumi, TWOPI = 6.283185307179586476925286766559;
@ -598,23 +582,5 @@ void fourt(double* datar, double* datai, int nn[3], int ndim, int ifrwd, int icp
np1 = np2;
nprev = n;
}
L920:
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, DIF USED VIRTUAL MEM = %5.1f MB", time_taken, *used_ram_tf - *used_ram_t0);
free(used_ram_t0);
free(used_ram_tf);
L920: return;
}

@ -1,50 +1,15 @@
#include "genlib.h"
#include "log.h"
#include "memory.h"
#include <math.h>
#include <stdio.h>
#include <time.h>
/*gamma covariance function*/
double gammf(double h, double alpha, int cores) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
clock_t t = clock();
log_info("RESULT = in progress, h = %f, alpha = %f", h, alpha);
struct cpustat initial[cores];
struct cpustat final[cores];
for (int i = 0; i < cores; i++) {
get_stats(&initial[i], i - 1);
}
float delta;
double z;
delta = pow(20., 1. / alpha) - 1.;
z = 1. / (double)(pow(1. + h * delta, alpha));
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_t0);
log_info("RESULT = success, delta = %f, z = %f, ELAPSED = %f seconds, DIF USED VIRTUAL MEM = %5.1f MB", delta, z, time_taken, *used_ram_tf - *used_ram_t0);
free(used_ram_t0);
free(used_ram_tf);
return z;
}

@ -1,6 +1,4 @@
#include "genlib.h"
#include "log.h"
#include "memory.h"
#include <math.h>
#include <time.h>
@ -10,20 +8,6 @@ double gasdev(long* idum, long* idum2, long* iy, long iv[NTAB], int cores) {
/*returns a normally distributed deviate with 0 mean*/
/*and unit variance, using ran2(idum) as the source */
/*of uniform deviates */
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
clock_t t = clock();
log_info("RESULT = in progress, idum = %f, idum2 = %f, iy = %f", *idum, *idum2, *iy);
struct cpustat initial[cores];
struct cpustat final[cores];
for (int i = 0; i < cores; i++) {
get_stats(&initial[i], i - 1);
}
double ran2(long* idum, long* idum2, long* iy, long iv[NTAB], int cores);
static int iset = 0;
static double gset;
@ -40,48 +24,9 @@ double gasdev(long* idum, long* idum2, long* iy, long iv[NTAB], int cores) {
gset = v1 * fac;
iset = 1;
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, gset = %f, fac = %f, v1 = %f, ELAPSED = %f seconds, DIF USED VIRTUAL MEM = %5.1f MB", gset, fac, v1, time_taken, *used_ram_tf - *used_ram_t0);
free(used_ram_t0);
free(used_ram_tf);
return (v2 * fac);
} else {
iset = 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, gset = %f, ELAPSED = %f seconds, DIF USED VIRTUAL MEM = %5.1f MB", gset, time_taken, *used_ram_tf - *used_ram_t0);
free(used_ram_t0);
free(used_ram_tf);
return gset;
}
}

@ -1,10 +1,8 @@
#include "genlib.h"
#include "log.h"
#include <math.h>
#include <stdio.h>
/*gaussian covariance function*/
double gaussian(double h) {
log_info("RESULT = in progress, h = %f", h);
return (exp(-3. * (double)(h * h)));
}

@ -2,8 +2,6 @@
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include "log.h"
#include "memory.h"
/* GENERATION OF A GAUSSIAN WHITE NOISE VECTOR */
/*input: */
@ -13,20 +11,6 @@
/* 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;
@ -55,24 +39,5 @@ void generate(long* seed, int n, struct realization_mod* realization, int cores)
chunk_array_flush((*realization).vector_2);*/
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);
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);
}

@ -1,24 +1,8 @@
#include "log.h"
#include "memory.h"
#include <math.h>
#include <time.h>
/* compute the length for one dimension*/
int length(int N, int i, double* scf, double* ap, double D, int Nvari, int cores) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
clock_t t = clock();
log_info("RESULT = in progress, N = %d, i = %d, D = %f, Nvari = %d", N, i, D, Nvari);
struct cpustat initial[cores];
struct cpustat final[cores];
for (int i = 0; i < cores; i++) {
get_stats(&initial[i], i - 1);
}
int maxfactor(int n, int cores);
double temp1, temp2;
int n, j, k, nmax;
@ -52,24 +36,5 @@ int length(int N, int i, double* scf, double* ap, double D, int Nvari, int cores
}
}
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, n = %d, ELAPSED = %f seconds, DIF USED VIRTUAL MEM = %5.1f MB", n, time_taken, *used_ram_tf - *used_ram_t0);
free(used_ram_t0);
free(used_ram_tf);
return n;
}

@ -1,177 +0,0 @@
/*
* Copyright (c) 2020 rxi
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include <stdlib.h>
#include "log.h"
#include <string.h>
#define MAX_CALLBACKS 32
typedef struct {
log_LogFn fn;
void *udata;
int level;
} Callback;
static struct {
void *udata;
log_LockFn lock;
int level;
bool quiet;
Callback callbacks[MAX_CALLBACKS];
} L;
static const char *level_strings[] = {
"TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"
};
#ifdef LOG_USE_COLOR
static const char *level_colors[] = {
"\x1b[94m", "\x1b[36m", "\x1b[32m", "\x1b[33m", "\x1b[31m", "\x1b[35m"
};
#endif
static void stdout_callback(log_Event *ev) {
char buf[16];
buf[strftime(buf, sizeof(buf), "%H:%M:%S", ev->time)] = '\0';
#ifdef LOG_USE_COLOR
fprintf(
ev->udata, "%s %s%-5s\x1b[0m \x1b[0m%s:%d:\x1b[0m ",
buf, level_colors[ev->level], level_strings[ev->level],
ev->file, ev->line);
#else
fprintf(
ev->udata, "%s %-5s %s:%d: ",
buf, level_strings[ev->level], ev->file, ev->line);
#endif
vfprintf(ev->udata, ev->fmt, ev->ap);
fprintf(ev->udata, "\n");
fflush(ev->udata);
}
static void file_callback(log_Event *ev) {
char buf[64];
buf[strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ev->time)] = '\0';
fprintf(
ev->udata, "%s %-5s %s:%d: ",
buf, level_strings[ev->level], ev->file, ev->line);
vfprintf(ev->udata, ev->fmt, ev->ap);
fprintf(ev->udata, "\n");
fflush(ev->udata);
}
static void lock(void) {
if (L.lock) { L.lock(true, L.udata); }
}
static void unlock(void) {
if (L.lock) { L.lock(false, L.udata); }
}
const char* log_level_string(int level) {
return level_strings[level];
}
void log_set_lock(log_LockFn fn, void *udata) {
L.lock = fn;
L.udata = udata;
}
void log_set_level(int level) {
L.level = level;
}
void log_set_quiet(bool enable) {
L.quiet = enable;
}
int log_add_callback(log_LogFn fn, void *udata, int level) {
for (int i = 0; i < MAX_CALLBACKS; i++) {
if (!L.callbacks[i].fn) {
L.callbacks[i] = (Callback) { fn, udata, level };
return 0;
}
}
return -1;
}
int log_add_fp(FILE *fp, int level) {
return log_add_callback(file_callback, fp, level);
}
static void init_event(log_Event *ev, void *udata) {
if (!ev->time) {
time_t t = time(NULL);
ev->time = localtime(&t);
}
ev->udata = udata;
}
void log_log(int level, const char *file, int line, const char *fmt, ...) {
log_Event ev = {
.fmt = fmt,
.file = file,
.line = line,
.level = level,
};
char* env_var = getenv("ENV");
if (env_var != NULL && strcmp("false", env_var) == 0) return;
char* substr_mem = strstr(fmt, "MEM");
char* substr_cpu = strstr(fmt, "CPU");
if (env_var != NULL && strcmp("analysis", env_var) == 0 && substr_mem == NULL && substr_cpu == NULL) return;
lock();
if (!L.quiet && level >= L.level) {
init_event(&ev, stderr);
va_start(ev.ap, fmt);
stdout_callback(&ev);
va_end(ev.ap);
}
for (int i = 0; i < MAX_CALLBACKS && L.callbacks[i].fn; i++) {
Callback *cb = &L.callbacks[i];
if (level >= cb->level) {
init_event(&ev, cb->udata);
va_start(ev.ap, fmt);
cb->fn(&ev);
va_end(ev.ap);
}
}
unlock();
}

@ -1,49 +0,0 @@
/**
* Copyright (c) 2020 rxi
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MIT license. See `log.c` for details.
*/
#ifndef LOG_H
#define LOG_H
#include <stdio.h>
#include <stdarg.h>
#include <stdbool.h>
#include <time.h>
#define LOG_VERSION "0.1.0"
typedef struct {
va_list ap;
const char *fmt;
const char *file;
struct tm *time;
void *udata;
int line;
int level;
} log_Event;
typedef void (*log_LogFn)(log_Event *ev);
typedef void (*log_LockFn)(bool lock, void *udata);
enum { LOG_TRACE, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL };
#define log_trace(...) log_log(LOG_TRACE, __FILE__, __LINE__, __VA_ARGS__)
#define log_debug(...) log_log(LOG_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
#define log_info(...) log_log(LOG_INFO, __FILE__, __LINE__, __VA_ARGS__)
#define log_warn(...) log_log(LOG_WARN, __FILE__, __LINE__, __VA_ARGS__)
#define log_error(...) log_log(LOG_ERROR, __FILE__, __LINE__, __VA_ARGS__)
#define log_fatal(...) log_log(LOG_FATAL, __FILE__, __LINE__, __VA_ARGS__)
const char* log_level_string(int level);
void log_set_lock(log_LockFn fn, void *udata);
void log_set_level(int level);
void log_set_quiet(bool enable);
int log_add_callback(log_LogFn fn, void *udata, int level);
int log_add_fp(FILE *fp, int level);
void log_log(int level, const char *file, int line, const char *fmt, ...);
#endif

@ -1,23 +1,7 @@
#include "genlib.h"
#include "log.h"
#include "memory.h"
/*determines the greatest prime factor of an integer*/
int maxfactor(int n, int cores) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
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 test_fact(int* pnum, int fact, int* pmaxfac);
int lnum, fact;
int maxfac;
@ -47,24 +31,5 @@ int maxfactor(int n, int cores) {
}
}
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, maxfac = %d, ELAPSED = %f seconds, DIF USED VIRTUAL MEM = %5.1f MB", maxfac, time_taken, *used_ram_tf - *used_ram_t0);
free(used_ram_t0);
free(used_ram_tf);
return maxfac;
}

@ -1,94 +0,0 @@
#include <sys/types.h>
#include <sys/sysinfo.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/times.h>
#include <sys/vtimes.h>
#include <unistd.h>
#include "log.h"
#include "memory.h"
static unsigned long long lastTotalUser, lastTotalUserLow, lastTotalSys, lastTotalIdle;
static clock_t lastCPU, lastSysCPU, lastUserCPU;
static int numProcessors;
void getTotalVirtualMem(double* total_ram) {
const double megabyte = 1024 * 1024;
struct sysinfo si;
sysinfo(&si);
*total_ram = si.totalram / megabyte;
}
void getVirtualMemUsed(double* used_ram) {
const double megabyte = 1024 * 1024;
struct sysinfo si;
sysinfo(&si);
*used_ram = (si.totalram - si.freeram) / megabyte;
}
int parseLine(char* line) {
// This assumes that a digit will be found and the line ends in " Kb".
int i = strlen(line);
const char* p = line;
while (*p <'0' || *p > '9') p++;
line[i-3] = '\0';
i = atoi(p);
return i;
}
int getVirtualMemUsedByCurrentProcess() {
FILE* file = fopen("/proc/self/status", "r");
int result = -1;
char line[128];
while (fgets(line, 128, file) != NULL){
if (strncmp(line, "VmSize:", 7) == 0){
result = parseLine(line);
break;
}
}
fclose(file);
return result / 1024;
}
void skip_lines(FILE *fp, int numlines) {
int cnt = 0;
char ch;
while ((cnt < numlines) && ((ch = getc(fp)) != EOF)) {
if (ch == '\n') cnt++;
}
}
void get_stats(struct cpustat *st, int cpunum) {
FILE *fp = fopen("/proc/stat", "r");
int lskip = cpunum+1;
skip_lines(fp, lskip);
char cpun[255];
fscanf(fp, "%s %d %d %d %d %d %d %d", cpun, &(st->t_user), &(st->t_nice),
&(st->t_system), &(st->t_idle), &(st->t_iowait), &(st->t_irq),
&(st->t_softirq));
fclose(fp);
return;
}
double calculate_load(struct cpustat *prev, struct cpustat *cur) {
int idle_prev = (prev->t_idle) + (prev->t_iowait);
int idle_cur = (cur->t_idle) + (cur->t_iowait);
int nidle_prev = (prev->t_user) + (prev->t_nice) + (prev->t_system) + (prev->t_irq) + (prev->t_softirq);
int nidle_cur = (cur->t_user) + (cur->t_nice) + (cur->t_system) + (cur->t_irq) + (cur->t_softirq);
int total_prev = idle_prev + nidle_prev;
int total_cur = idle_cur + nidle_cur;
double totald = (double) total_cur - (double) total_prev;
double idled = (double) idle_cur - (double) idle_prev;
if (totald == 0 && idled == 0) return 0;
double cpu_perc = (1000 * (totald - idled) / totald + 1) / 10;
return cpu_perc;
}

@ -1,24 +0,0 @@
#include "sys/types.h"
#include "sys/sysinfo.h"
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
#include "sys/times.h"
#include "sys/vtimes.h"
void getTotalVirtualMem();
void getVirtualMemUsed();
int getVirtualMemUsedByCurrentProcess();
struct cpustat {
unsigned long t_user;
unsigned long t_nice;
unsigned long t_system;
unsigned long t_idle;
unsigned long t_iowait;
unsigned long t_irq;
unsigned long t_softirq;
};
void get_stats(struct cpustat *st, int cpunum);
double calculate_load(struct cpustat *prev, struct cpustat *cur);

@ -1,5 +1,4 @@
#include "geostat.h"
#include "log.h"
#include <math.h>
#include <stdlib.h>
#include <time.h>
@ -15,12 +14,6 @@
/* lognormal numbers */
void nor2log(struct realization_mod* realin, int typelog, struct realization_mod* realout) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
clock_t t = clock();
log_info("RESULT = in progress");
int i;
double coeff;
@ -69,20 +62,8 @@ void nor2log(struct realization_mod* realin, int typelog, struct realization_mod
(*realout).vector[i] = exp((*realin).vector[i] * coeff);
break;
default:
log_error("RESULT = failed - Unexpected case in nor2log");
return;
break;
}
}
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);
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);
}

@ -1,12 +1,9 @@
#include "genlib.h"
#include "log.h"
#include <math.h>
#include <stdio.h>
/*nugget covariance function*/
double nugget(double h) {
log_info("RESULT = in progress, h = %f", h);
if (h == 0) {
return (1.);
} else {

@ -1,10 +1,8 @@
#include "genlib.h"
#include "log.h"
#include <math.h>
#include <stdio.h>
/*power covariance function*/
double power(double h, double alpha) {
log_info("RESULT = in progress, h = %f, alpha = %f", h, alpha);
return pow(h, alpha);
}

@ -1,6 +1,4 @@
#include "geostat.h"
#include "log.h"
#include "memory.h"
#include <math.h>
#include <stdarg.h>
#include <stddef.h>
@ -23,11 +21,6 @@
/*realization: structure defining a realization*/
void prebuild_gwn(struct grid_mod grid, int n[3], struct realization_mod* realin, double* realization, int solver, int cores, long* seed) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
clock_t t = clock();
int i, j, k, maille0, maille1;
int ntot;
@ -38,15 +31,6 @@ void prebuild_gwn(struct grid_mod grid, int n[3], struct realization_mod* realin
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];
realization[0] = 0.;
/*printf("Antes de llamar a chunkarray read\n");
@ -76,23 +60,4 @@ void prebuild_gwn(struct grid_mod grid, int n[3], struct realization_mod* realin
}
}
}
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);
}

@ -1,7 +1,5 @@
#include <time.h>
#include "genlib.h"
#include "log.h"
#include "memory.h"
#define IM1 2147483563
#define IM2 2147483399
@ -19,24 +17,10 @@
#define RNMX (1.0 - EPS)
double ran2(long* idum, long* idum2, long* iy, long iv[NTAB], int cores) {
double* used_ram_t0 = malloc(sizeof(double));
getVirtualMemUsed(used_ram_t0);
clock_t t = clock();
int j;
long k;
double temp;
log_info("RESULT = in progress, idum = %f, idum2 = %f, iy = %f", *idum, *idum2, *iy);
struct cpustat initial[cores];
struct cpustat final[cores];
for (int i = 0; i < cores; i++) {
get_stats(&initial[i], i - 1);
}
if (*idum <= 0) {
if (-(*idum) < 1)
*idum = 1;
@ -68,29 +52,10 @@ double ran2(long* idum, long* idum2, long* iy, long iv[NTAB], int cores) {
if (*iy < 1)
(*iy) += IMM1;
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);
if ((temp = AM * (*iy)) > RNMX) {
log_info("RESULT = success, RNMX = %f, ELAPSED = %f, DIF USED VIRTUAL MEM = %5.1f MB", RNMX, time_taken, *used_ram_tf - *used_ram_t0);
return (RNMX);
}
else {
log_info("RESULT = success, temp = %f, ELAPSED = %f seconds, DIF USED VIRTUAL MEM = %5.1f MB", temp, time_taken, *used_ram_tf - *used_ram_t0);
return temp;
}
free(used_ram_t0);
free(used_ram_tf);
}

@ -1,12 +1,10 @@
#include "genlib.h"
#include "log.h"
#include <math.h>
#include <stdio.h>
/*spherical covariance function*/
double spherical(double h) {
double z;
log_info("RESULT = in progress, h = %f", h);
if (h >= 1.) {
z = 0.;
@ -14,7 +12,5 @@ double spherical(double h) {
z = 1. - 1.5 * (double)h + 0.5 * (double)(h * h * h);
}
log_info("RESULT = success, z = %f", z);
return z;
}

@ -7,7 +7,6 @@
#include "toolsFFTMA.h"
#include "toolsFFTPSIM.h"
#include "toolsIO.h"
#include "lib_src/log.h"
#include "chunk_array.h"
#include <Python.h>
#include <math.h>
@ -23,7 +22,7 @@
/* Y is the realization with mean and variance wanted */
static PyObject* genFunc(PyObject* self, PyObject* args) {
log_info("RESULT = in progress");
//log_info("RESULT = in progress");
int n[3];
struct realization_mod Z, Y;
struct grid_mod grid;
@ -77,7 +76,7 @@ static PyObject* genFunc(PyObject* self, PyObject* args) {
/*chunk_array_free(Z.vector_2);
remove("realization1.txt");*/
log_info("RESULT = success");
//log_info("RESULT = success");
return out_array;
}

@ -42,8 +42,6 @@ module_FFTMA = Extension(
"./lib_src/clean_real.c",
"./lib_src/testmemory.c",
"./lib_src/genlib.c",
"./lib_src/log.c",
"./lib_src/memory.c",
"./lib_src/chunk_array.c"
],
)

Loading…
Cancel
Save