diff --git a/fftma_module/gen/lib_src/Py_getvalues.c b/fftma_module/gen/lib_src/Py_getvalues.c index ad2ea6b..4f5a4ab 100644 --- a/fftma_module/gen/lib_src/Py_getvalues.c +++ b/fftma_module/gen/lib_src/Py_getvalues.c @@ -12,6 +12,7 @@ #include #include #include +#include #if PY_MAJOR_VERSION >= 3 #define PyIntObject PyLongObject @@ -42,6 +43,8 @@ #endif int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario_mod* variogram, struct statistic_mod* stat) { + clock_t t = clock(); + log_info("RESULT = in progress"); int i, varioNargs = 12, j = 0; PyObject* listvario; @@ -146,6 +149,9 @@ int Py_getvalues(PyObject* args, long* seed, struct grid_mod* grid, struct vario (variogram->ap)[i * 9 + 5] = PyFloat_AsDouble(PyTuple_GetItem(vgr, j++)); } - log_info("RESULT = success"); + 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; } diff --git a/fftma_module/gen/lib_src/Py_kgeneration.c b/fftma_module/gen/lib_src/Py_kgeneration.c index fba9662..bd8943a 100644 --- a/fftma_module/gen/lib_src/Py_kgeneration.c +++ b/fftma_module/gen/lib_src/Py_kgeneration.c @@ -12,13 +12,15 @@ #include #include #include +#include /* kgeneration */ /* Z is the GWN with 0-mean and 1-variance */ /* 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]) -{ +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]) { + clock_t t = clock(); + int i, N; int typelog; @@ -40,6 +42,9 @@ void Py_kgeneration(long seed, struct grid_mod grid, struct statistic_mod stat, typelog = stat.type + 2; nor2log(Y, typelog, Y); } + + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time - log_info("RESULT = success"); + log_info("RESULT = success, ELAPSED = %f seconds", time_taken); } diff --git a/fftma_module/gen/lib_src/build_real.c b/fftma_module/gen/lib_src/build_real.c index c2b70d2..deeb21b 100644 --- a/fftma_module/gen/lib_src/build_real.c +++ b/fftma_module/gen/lib_src/build_real.c @@ -6,6 +6,7 @@ #include #include #include +#include /* build_real */ /* build a realization in the spectral domain */ @@ -20,6 +21,8 @@ /*ireal: vector defining the i-part */ void build_real(int n[3], int NTOT, double* covar, double* realization, double* ireal) { + 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]); @@ -41,5 +44,8 @@ void build_real(int n[3], int NTOT, double* covar, double* realization, double* } } - log_info("RESULT = success, realization = %f, ireal = %f", *realization, *ireal); + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time + + log_info("RESULT = success, realization = %f, ireal = %f, ELAPSED = %f seconds", *realization, *ireal, time_taken); } diff --git a/fftma_module/gen/lib_src/cardsin.c b/fftma_module/gen/lib_src/cardsin.c index 63674fe..537bdd7 100644 --- a/fftma_module/gen/lib_src/cardsin.c +++ b/fftma_module/gen/lib_src/cardsin.c @@ -2,9 +2,12 @@ #include "log.h" #include #include +#include /*cardsin covariance function*/ double cardsin(double h) { + clock_t t = clock(); + log_info("RESULT = in progress, h = %f", h); float delta = 20.371; @@ -17,7 +20,10 @@ double cardsin(double h) { z = 1.; } - log_info("RESULT = success, z = %f", z); + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time + + log_info("RESULT = success, z = %f, ELAPSED = %f seconds", z, time_taken); return z; } diff --git a/fftma_module/gen/lib_src/cgrid.c b/fftma_module/gen/lib_src/cgrid.c index 0f2e604..a424551 100644 --- a/fftma_module/gen/lib_src/cgrid.c +++ b/fftma_module/gen/lib_src/cgrid.c @@ -1,6 +1,7 @@ #include "geostat.h" #include "log.h" #include +#include /*computes the size of the grid for FFTs*/ /*input: */ @@ -11,6 +12,8 @@ /* 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]) { + clock_t t = clock(); + int i, N; double D; @@ -41,5 +44,8 @@ void cgrid(struct vario_mod variogram, struct grid_mod grid, int n[3]) { } } - log_info("RESULT = success, n[0] = %d, n[1] = %d, n[2] = %d", n[0], n[1], n[2]); + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time + + log_info("RESULT = success, n[0] = %d, n[1] = %d, n[2] = %d, ELAPSED = %f seconds", n[0], n[1], n[2], time_taken); } diff --git a/fftma_module/gen/lib_src/clean_real.c b/fftma_module/gen/lib_src/clean_real.c index 25bd9fe..3d34a74 100644 --- a/fftma_module/gen/lib_src/clean_real.c +++ b/fftma_module/gen/lib_src/clean_real.c @@ -6,8 +6,11 @@ #include #include #include +#include void clean_real(struct realization_mod* realin, int n[3], struct grid_mod grid, double* vectorresult, struct realization_mod* realout) { + clock_t t = clock(); + int i, j, k, maille0, maille1; double NTOT; @@ -39,5 +42,8 @@ void clean_real(struct realization_mod* realin, int n[3], struct grid_mod grid, } } - log_info("RESULT = success"); + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time + + log_info("RESULT = success, ELAPSED = %f seconds", time_taken); } diff --git a/fftma_module/gen/lib_src/cov_value.c b/fftma_module/gen/lib_src/cov_value.c index f123c55..a846c7f 100644 --- a/fftma_module/gen/lib_src/cov_value.c +++ b/fftma_module/gen/lib_src/cov_value.c @@ -2,9 +2,12 @@ #include "geostat.h" #include "log.h" #include +#include /*selection of model covariance*/ double cov_value(struct vario_mod variogram, double di, double dj, double dk) { + clock_t t = clock(); + log_info("RESULT = in progress, di = %f, dj = %f, dk = %f", di, dj, dk); double hx, hy, hz, h; @@ -51,7 +54,10 @@ double cov_value(struct vario_mod variogram, double di, double dj, double dk) { } } - log_info("RESULT = success, hx = %f, hy = %f, hz = %f, h = %f, cov = %f", hx, hy, hz, h, cov); + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time + + log_info("RESULT = success, hx = %f, hy = %f, hz = %f, h = %f, cov = %f, ELAPSED = %f seconds", hx, hy, hz, h, cov, time_taken); return cov; } diff --git a/fftma_module/gen/lib_src/covariance.c b/fftma_module/gen/lib_src/covariance.c index a5c1cd4..47f56a4 100644 --- a/fftma_module/gen/lib_src/covariance.c +++ b/fftma_module/gen/lib_src/covariance.c @@ -1,9 +1,12 @@ #include "geostat.h" #include "log.h" +#include /*builds the sampled covariance function*/ /*dimensions are even*/ void covariance(double* covar, struct vario_mod variogram, struct grid_mod mesh, int n[3]) { + clock_t t = clock(); + int i, j, k, maille, n2[3], symmetric; double di, dj, dk; @@ -77,5 +80,8 @@ void covariance(double* covar, struct vario_mod variogram, struct grid_mod mesh, } } - log_info("RESULT = success, di = %f, dj = %f, dk = %f", di, dj, dk); + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time + + log_info("RESULT = success, di = %f, dj = %f, dk = %f, ELAPSED = %f seconds", di, dj, dk, time_taken); } diff --git a/fftma_module/gen/lib_src/cubic.c b/fftma_module/gen/lib_src/cubic.c index 670031d..75d2c30 100644 --- a/fftma_module/gen/lib_src/cubic.c +++ b/fftma_module/gen/lib_src/cubic.c @@ -2,9 +2,12 @@ #include "log.h" #include #include +#include /*cubic covariance function*/ double cubic(double h) { + clock_t t = clock(); + log_info("RESULT = in progress, h = %f", h); double z; @@ -15,7 +18,10 @@ double cubic(double h) { 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); } - log_info("RESULT = success, z = %f"); + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time + + log_info("RESULT = success, z = %f, ELAPSED = %f seconds", z, time_taken); return z; } diff --git a/fftma_module/gen/lib_src/fftma2.c b/fftma_module/gen/lib_src/fftma2.c index dae4d29..eb6ab48 100644 --- a/fftma_module/gen/lib_src/fftma2.c +++ b/fftma_module/gen/lib_src/fftma2.c @@ -3,6 +3,7 @@ #include #include #include +#include /*FAST FOURIER TRANSFORM MOVING AVERAGE METHOD */ /*Turns a Gaussian white noise vector into a */ @@ -23,6 +24,8 @@ /*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) { + clock_t t = clock(); + log_info("RESULT = in progress"); int NTOT, i, j, k, NMAX, NDIM, ntot, nmax, NXYZ, nxyz; @@ -97,5 +100,8 @@ void FFTMA2(struct vario_mod variogram, struct grid_mod grid, int n[3], struct r free(realization); - log_info("RESULT = success, NTOT = %d, NMAX = %d, NDIM = %d, ntot = %d, nmax = %d, NXYZ = %d, nxyz = %d", NTOT, NMAX, NDIM, ntot, nmax, NXYZ, nxyz); + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time + + log_info("RESULT = success, NTOT = %d, NMAX = %d, NDIM = %d, ntot = %d, nmax = %d, NXYZ = %d, nxyz = %d, ELAPSED = %f seconds", NTOT, NMAX, NDIM, ntot, nmax, NXYZ, nxyz, time_taken); } diff --git a/fftma_module/gen/lib_src/fourt.c b/fftma_module/gen/lib_src/fourt.c index b9360c6..33c7a6e 100644 --- a/fftma_module/gen/lib_src/fourt.c +++ b/fftma_module/gen/lib_src/fourt.c @@ -1,6 +1,7 @@ #include "log.h" #include #include +#include /*fast fourier transform */ /* THE COOLEY-TUKEY FAST FOURIER TRANSFORM */ @@ -91,6 +92,8 @@ /* 10-06-2000, MLR */ void fourt(double* datar, double* datai, int nn[3], int ndim, int ifrwd, int icplx, double* workr, double* worki) { + clock_t t = clock(); + log_info("RESULT = in progress"); 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; @@ -584,6 +587,9 @@ void fourt(double* datar, double* datai, int nn[3], int ndim, int ifrwd, int icp nprev = n; } L920: - log_info("RESULT = succes"); + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time + + log_info("RESULT = success, ELAPSED = %f", time_taken); return; } diff --git a/fftma_module/gen/lib_src/gammf.c b/fftma_module/gen/lib_src/gammf.c index cbf5842..89ebd2c 100644 --- a/fftma_module/gen/lib_src/gammf.c +++ b/fftma_module/gen/lib_src/gammf.c @@ -2,9 +2,12 @@ #include "log.h" #include #include +#include /*gamma covariance function*/ double gammf(double h, double alpha) { + clock_t t = clock(); + log_info("RESULT = in progress, h = %f, alpha = %f", h, alpha); float delta; @@ -13,6 +16,9 @@ double gammf(double h, double alpha) { delta = pow(20., 1. / alpha) - 1.; z = 1. / (double)(pow(1. + h * delta, alpha)); - log_info("RESULT = success, delta = %f, z = %f", delta, z); + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time + + log_info("RESULT = success, delta = %f, z = %f, ELAPSED = %f seconds", delta, z, time_taken); return z; } diff --git a/fftma_module/gen/lib_src/gasdev.c b/fftma_module/gen/lib_src/gasdev.c index 5f1392a..fbd2ee1 100644 --- a/fftma_module/gen/lib_src/gasdev.c +++ b/fftma_module/gen/lib_src/gasdev.c @@ -1,6 +1,7 @@ #include "genlib.h" #include "log.h" #include +#include #define NTAB 32 @@ -8,6 +9,8 @@ double gasdev(long* idum, long* idum2, long* iy, long iv[NTAB]) { /*returns a normally distributed deviate with 0 mean*/ /*and unit variance, using ran2(idum) as the source */ /*of uniform deviates */ + clock_t t = clock(); + log_info("RESULT = in progress, idum = %f, idum2 = %f, iy = %f", *idum, *idum2, *iy); double ran2(long* idum, long* idum2, long* iy, long iv[NTAB]); @@ -25,11 +28,19 @@ double gasdev(long* idum, long* idum2, long* iy, long iv[NTAB]) { fac = sqrt(-2.0 * log(rsq) / rsq); gset = v1 * fac; iset = 1; - log_info("RESULT = success, gset = %f, fac = %f, v1 = %f", gset, fac, v1); + + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time + + log_info("RESULT = success, gset = %f, fac = %f, v1 = %f, ELAPSED = %f seconds", gset, fac, v1, time_taken); return (v2 * fac); } else { iset = 0; - log_info("RESULT = success, gset = %f", gset); + + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time + + log_info("RESULT = success, gset = %f, ELAPSED = %f seconds", gset, time_taken); return gset; } } diff --git a/fftma_module/gen/lib_src/generate.c b/fftma_module/gen/lib_src/generate.c index dc4efbe..53b847e 100644 --- a/fftma_module/gen/lib_src/generate.c +++ b/fftma_module/gen/lib_src/generate.c @@ -1,6 +1,7 @@ #include "geostat.h" #include #include +#include #include "log.h" /* GENERATION OF A GAUSSIAN WHITE NOISE VECTOR */ @@ -11,6 +12,8 @@ /* realization: structure defining the realization*/ void generate(long* seed, int n, struct realization_mod* realization) { + clock_t t = clock(); + log_info("RESULT = in progress, n = %d", n); int i; @@ -37,6 +40,9 @@ void generate(long* seed, int n, struct realization_mod* realization) { for (i = 0; i < n; i++) (*realization).vector[i] = gasdev(seed, &idum2, &iy, iv, &iset); - log_info("RESULT = success"); + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time + + log_info("RESULT = success, ELAPSED = %f seconds", time_taken); free(iv); } diff --git a/fftma_module/gen/lib_src/length.c b/fftma_module/gen/lib_src/length.c index fd9e12a..91bff7f 100644 --- a/fftma_module/gen/lib_src/length.c +++ b/fftma_module/gen/lib_src/length.c @@ -1,8 +1,11 @@ #include "log.h" #include +#include /* compute the length for one dimension*/ int length(int N, int i, double* scf, double* ap, double D, int Nvari) { + clock_t t = clock(); + log_info("RESULT = in progress, N = %d, i = %d, D = %f, Nvari = %d", N, i, D, Nvari); int maxfactor(int n); @@ -38,6 +41,9 @@ int length(int N, int i, double* scf, double* ap, double D, int Nvari) { } } - log_info("RESULT = success, n = %d", n); + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time + + log_info("RESULT = success, n = %d, ELAPSED = %f seconds", n, time_taken); return n; } diff --git a/fftma_module/gen/lib_src/log.c b/fftma_module/gen/lib_src/log.c new file mode 100644 index 0000000..c6c8573 --- /dev/null +++ b/fftma_module/gen/lib_src/log.c @@ -0,0 +1,168 @@ +/* + * 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 "log.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, + }; + + 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(); +} diff --git a/fftma_module/gen/lib_src/log.h b/fftma_module/gen/lib_src/log.h new file mode 100644 index 0000000..b1fae24 --- /dev/null +++ b/fftma_module/gen/lib_src/log.h @@ -0,0 +1,49 @@ +/** + * 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 +#include +#include +#include + +#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 diff --git a/fftma_module/gen/lib_src/maxfactor.c b/fftma_module/gen/lib_src/maxfactor.c index cf6c970..a225fac 100644 --- a/fftma_module/gen/lib_src/maxfactor.c +++ b/fftma_module/gen/lib_src/maxfactor.c @@ -3,6 +3,8 @@ /*determines the greatest prime factor of an integer*/ int maxfactor(int n) { + clock_t t = clock(); + log_info("RESULT = in progress, n = %d", n); int test_fact(int* pnum, int fact, int* pmaxfac); @@ -34,6 +36,9 @@ int maxfactor(int n) { } } - log_info("RESULT = success, maxfac = %d", maxfac); + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time + + log_info("RESULT = success, maxfac = %d, ELAPSED = %f seconds", maxfac, time_taken); return maxfac; } diff --git a/fftma_module/gen/lib_src/nor2log.c b/fftma_module/gen/lib_src/nor2log.c index 085070a..78719de 100644 --- a/fftma_module/gen/lib_src/nor2log.c +++ b/fftma_module/gen/lib_src/nor2log.c @@ -2,6 +2,7 @@ #include "log.h" #include #include +#include /*TURNS NORMAL NUMBERS INTO LOGNORMAL NUMBERS */ /*input: */ @@ -14,6 +15,8 @@ /* lognormal numbers */ void nor2log(struct realization_mod* realin, int typelog, struct realization_mod* realout) { + clock_t t = clock(); + log_info("RESULT = in progress"); int i; double coeff; @@ -69,5 +72,8 @@ void nor2log(struct realization_mod* realin, int typelog, struct realization_mod } } - log_info("RESULT = success"); + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time + + log_info("RESULT = success, ELAPSED = %f seconds", time_taken); } diff --git a/fftma_module/gen/lib_src/prebuild_gwn.c b/fftma_module/gen/lib_src/prebuild_gwn.c index 2e31024..4e376f1 100644 --- a/fftma_module/gen/lib_src/prebuild_gwn.c +++ b/fftma_module/gen/lib_src/prebuild_gwn.c @@ -6,6 +6,7 @@ #include #include #include +#include /* prebuild_gwn */ /* Produce a first construction in real space of the Gaussian white noise */ @@ -21,6 +22,8 @@ /*realization: structure defining a realization*/ void prebuild_gwn(struct grid_mod grid, int n[3], struct realization_mod* realin, double* realization, int solver) { + clock_t t = clock(); + int i, j, k, maille0, maille1; int ntot; @@ -47,5 +50,9 @@ void prebuild_gwn(struct grid_mod grid, int n[3], struct realization_mod* realin } } } - log_info("RESULT = success"); + + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time + + log_info("RESULT = success, ELAPSED = %f seconds"); } diff --git a/fftma_module/gen/lib_src/ran2.c b/fftma_module/gen/lib_src/ran2.c index 5a1ba58..b54d06a 100644 --- a/fftma_module/gen/lib_src/ran2.c +++ b/fftma_module/gen/lib_src/ran2.c @@ -1,3 +1,4 @@ +#include #include "genlib.h" #include "log.h" @@ -17,6 +18,8 @@ #define RNMX (1.0 - EPS) double ran2(long* idum, long* idum2, long* iy, long iv[NTAB]) { + clock_t t = clock(); + int j; long k; double temp; @@ -53,12 +56,16 @@ double ran2(long* idum, long* idum2, long* iy, long iv[NTAB]) { iv[j] = *idum; if (*iy < 1) (*iy) += IMM1; + + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time + if ((temp = AM * (*iy)) > RNMX) { - log_info("RESULT = success"); + log_info("RESULT = success, ELAPSED = %f", time_taken); return (RNMX); } else { - log_info("RESULT = success, temp = %f, temp"); + log_info("RESULT = success, temp = %f, ELAPSED = %f seconds", temp, time_taken); return temp; } } diff --git a/fftma_module/gen/save_logs.sh b/fftma_module/gen/save_logs.sh new file mode 100755 index 0000000..5ae280b --- /dev/null +++ b/fftma_module/gen/save_logs.sh @@ -0,0 +1 @@ +python3 test.py 2>&1 | tee log.txt \ No newline at end of file