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.
76 lines
2.0 KiB
C
76 lines
2.0 KiB
C
#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;
|
|
int nlimit = 13;
|
|
|
|
if (N == 1) {
|
|
n = 1;
|
|
} else {
|
|
|
|
for (k = 0; k < Nvari; k++) {
|
|
temp1 = fabs(ap[9 * k + i]) * scf[3 * k] * scf[3 * k];
|
|
for (j = 1; j < 3; j++) {
|
|
temp2 = fabs(ap[9 * k + 3 * j + i]) * scf[3 * k + j] * scf[3 * k + j];
|
|
if (temp2 > temp1)
|
|
temp1 = temp2;
|
|
}
|
|
}
|
|
temp1 = sqrt(temp1);
|
|
temp1 /= (double)D;
|
|
if ((double)N / temp1 < 2.) {
|
|
n = N + (int)(2 * temp1);
|
|
} else {
|
|
n = N + (int)temp1;
|
|
}
|
|
if ((n % 2) != 0)
|
|
n = n + 1;
|
|
nmax = maxfactor(n, cores);
|
|
while (nmax > nlimit) {
|
|
n += 2;
|
|
nmax = maxfactor(n, 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;
|
|
}
|