remove logs and add tests
parent
bfdc81ee4b
commit
cfe4af4e15
@ -1,36 +0,0 @@
|
||||
#ifndef _CHUNKARRAY_H
|
||||
#define _CHUNKARRAY_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define MAX_CHUNK_SIZE 512
|
||||
|
||||
typedef struct chunk_array {
|
||||
size_t init_pos;
|
||||
size_t chunk_size;
|
||||
size_t total_size;
|
||||
FILE* fp;
|
||||
double* data;
|
||||
}chunk_array_t;
|
||||
|
||||
chunk_array_t* chunk_array_create(char* filename, size_t total_size, size_t chunk_size);
|
||||
|
||||
void chunk_array_read(chunk_array_t* chunk_array);
|
||||
|
||||
//void chunk_array_write(chunk_array_t* chunk_array, char* filename);
|
||||
|
||||
void chunk_array_free(chunk_array_t* chunk_array);
|
||||
|
||||
bool chunk_array_get(chunk_array_t* chunk_array, size_t pos, double *value_ptr);
|
||||
|
||||
bool chunk_array_save(chunk_array_t* chunk_array, size_t pos, double valor);
|
||||
|
||||
void chunk_array_flush(chunk_array_t* chunk_array);
|
||||
|
||||
size_t chunk_array_size(chunk_array_t* chunk_array);
|
||||
|
||||
#endif
|
@ -1,73 +0,0 @@
|
||||
#include "chunk_array.h"
|
||||
#include "stdbool.h"
|
||||
|
||||
void chunk_array_free(chunk_array_t* chunk_array) {
|
||||
fclose(chunk_array->fp);
|
||||
free(chunk_array->data);
|
||||
free(chunk_array);
|
||||
}
|
||||
|
||||
bool chunk_array_update_read(chunk_array_t* chunk_array) {
|
||||
printf("Llame a chunk array update\n");
|
||||
size_t newLen = fread(chunk_array->data, sizeof(double), chunk_array->chunk_size, chunk_array->fp);
|
||||
chunk_array->init_pos += newLen;
|
||||
}
|
||||
|
||||
bool chunk_array_get(chunk_array_t* chunk_array, size_t pos, double *valor) {
|
||||
if (pos>((chunk_array->init_pos + chunk_array->chunk_size)-1)) {
|
||||
chunk_array_update_read(chunk_array);
|
||||
}
|
||||
*valor=chunk_array->data[pos%chunk_array->chunk_size];
|
||||
return true;
|
||||
}
|
||||
|
||||
bool chunk_array_save(chunk_array_t* chunk_array, size_t pos, double valor) {
|
||||
if (pos>((chunk_array->init_pos + chunk_array->chunk_size)-1)) {
|
||||
chunk_array_flush(chunk_array);
|
||||
}
|
||||
chunk_array->data[pos%chunk_array->chunk_size]=valor;
|
||||
return true;
|
||||
}
|
||||
|
||||
chunk_array_t* chunk_array_create(char* filename, size_t total_size, size_t chunk_size) {
|
||||
chunk_array_t* chunk_array = (chunk_array_t*)malloc(sizeof(chunk_array_t));
|
||||
|
||||
chunk_array->fp = fopen(filename, "w+");
|
||||
|
||||
if (chunk_array == NULL || chunk_array->fp == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
chunk_array->data = malloc(chunk_size * sizeof(double));
|
||||
|
||||
if (chunk_size > 0 && chunk_array->data == NULL) {
|
||||
free(chunk_array);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
chunk_array->init_pos = 0;
|
||||
chunk_array->chunk_size = chunk_size;
|
||||
chunk_array->total_size = total_size;
|
||||
return chunk_array;
|
||||
}
|
||||
|
||||
void chunk_array_read(chunk_array_t* chunk_array) {
|
||||
rewind(chunk_array->fp);
|
||||
chunk_array->init_pos = 0;
|
||||
size_t newLen = fread(chunk_array->data, sizeof(double), chunk_array->chunk_size, chunk_array->fp);
|
||||
}
|
||||
|
||||
void chunk_array_write(chunk_array_t* chunk_array, char* filename) {
|
||||
chunk_array->fp = fopen(filename, "w");
|
||||
if (chunk_array->fp == NULL) {
|
||||
printf("ke");
|
||||
fclose(chunk_array->fp);
|
||||
chunk_array->fp = fopen(filename, "w");
|
||||
}
|
||||
chunk_array->init_pos = 0;
|
||||
}
|
||||
|
||||
void chunk_array_flush(chunk_array_t* chunk_array) {
|
||||
size_t newLen = fwrite(chunk_array->data, sizeof(double), chunk_array->chunk_size, chunk_array->fp);
|
||||
chunk_array->init_pos += newLen;
|
||||
}
|
@ -1,11 +1,9 @@
|
||||
#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,50 +1,16 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
double gammf(double h, double alpha) {
|
||||
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,87 +1,33 @@
|
||||
#include "genlib.h"
|
||||
#include "log.h"
|
||||
#include "memory.h"
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
|
||||
#define NTAB 32
|
||||
|
||||
double gasdev(long* idum, long* idum2, long* iy, long iv[NTAB], int cores) {
|
||||
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 */
|
||||
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);
|
||||
double ran2(long* idum, long* idum2, long* iy, long iv[NTAB]);
|
||||
static int iset = 0;
|
||||
static double gset;
|
||||
double fac, rsq, v1, v2;
|
||||
|
||||
if (iset == 0) {
|
||||
do {
|
||||
v1 = 2.0 * ran2(idum, idum2, iy, iv, cores) - 1.0;
|
||||
v2 = 2.0 * ran2(idum, idum2, iy, iv, cores) - 1.0;
|
||||
v1 = 2.0 * ran2(idum, idum2, iy, iv) - 1.0;
|
||||
v2 = 2.0 * ran2(idum, idum2, iy, iv) - 1.0;
|
||||
rsq = v1 * v1 + v2 * v2;
|
||||
} while (rsq >= 1.0 || rsq == 0.0);
|
||||
|
||||
fac = sqrt(-2.0 * log(rsq) / rsq);
|
||||
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,9 @@
|
||||
#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)));
|
||||
}
|
||||
|
@ -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,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,10 +1,9 @@
|
||||
#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,20 +1,15 @@
|
||||
#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.;
|
||||
} else {
|
||||
z = 1. - 1.5 * (double)h + 0.5 * (double)(h * h * h);
|
||||
}
|
||||
|
||||
log_info("RESULT = success, z = %f", z);
|
||||
|
||||
return z;
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,54 @@
|
||||
from FFTMA import gen
|
||||
import numpy as np
|
||||
import unittest
|
||||
import time
|
||||
|
||||
def generate(N):
|
||||
start_time = time.time()
|
||||
nx, ny, nz = N,N,N
|
||||
dx, dy, dz = 1.0, 1.0, 1.0
|
||||
seed= 1548762 #rdi(10000,99999)
|
||||
var=1
|
||||
vario=2
|
||||
alpha=1
|
||||
lcx=2
|
||||
lcy=4
|
||||
lcz=16
|
||||
ap1x=1
|
||||
ap1y=0
|
||||
ap1z=0
|
||||
ap2x=0
|
||||
ap2y=1
|
||||
ap2z=0
|
||||
|
||||
v1 = (var, vario, alpha, lcx, lcy, lcz, ap1x, ap1y, ap1z, ap2x, ap2y, ap2z)
|
||||
variograms = [v1]
|
||||
|
||||
mean=15.3245987
|
||||
variance=3.5682389
|
||||
typ=3
|
||||
|
||||
k = gen(nx, ny, nz, dx, dy, dz, seed, variograms, mean, variance, typ)
|
||||
|
||||
print(f"Generation with N = {N} time = {time.time() - start_time}s")
|
||||
return k
|
||||
|
||||
|
||||
def test(N):
|
||||
k = generate(N)
|
||||
k_correct = np.load(f"out_{N}.npy")
|
||||
comparison = k == k_correct
|
||||
return comparison.all()
|
||||
|
||||
class TestGeneration(unittest.TestCase):
|
||||
def test_8(self):
|
||||
self.assertTrue(test(8))
|
||||
|
||||
def test_16(self):
|
||||
self.assertTrue(test(16))
|
||||
|
||||
def test_32(self):
|
||||
self.assertTrue(test(32))
|
||||
|
||||
def test_64(self):
|
||||
self.assertTrue(test(64))
|
Loading…
Reference in New Issue