-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestes.c
97 lines (78 loc) · 2.42 KB
/
testes.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <stdlib.h>
#include <pthread.h>
#include <stdio.h>
#include "includes/timer.h"
#include "includes/funcs.h"
#include "includes/inteseq.h"
#include "includes/inteconc_div.h"
#include "includes/inteconc.h"
#define VERS 3
#define NUM_FUNC 7
void processa_ganho(double temp[NUM_FUNC][VERS]) {
int i;
double ganho_d, ganho_p;
printf("Ganhos: (tempo sequencial) / (tempo concorrente)\n");
for (i = 0; i < NUM_FUNC; i++) {
ganho_d = temp[i][0] / temp[i][1];
ganho_p = temp[i][0] / temp[i][2];
printf("f(%c) -> Concorrente(D): [%6.4lf] Concorrente(P): [%6.4lf]\n", 97 + i, ganho_d, ganho_p);
}
}
int main(int argc, char *argv[]) {
double a, b, erro, res;
double comeco, fim, tempo;
double tempos_f[NUM_FUNC][VERS];
int i, j, nThreads;
double (*funcs[NUM_FUNC])(double) = {f_a, f_b, f_c, f_d, f_e, f_f, f_g};
if (argc < 5) {
fprintf(stderr, "Digite: %s <nº de threads> <a> <b> <erro máximo>\n", argv[0]);
exit(-1);
}
nThreads = atoi(argv[1]);
a = atof(argv[2]);
b = atof(argv[3]);
erro = atof(argv[4]);
for (i = 0; i < NUM_FUNC; i++) {
for (j = 0; j < VERS; j++) {
tempos_f[i][j] = -1;
}
}
printf("Algoritmo sequencial:\n");
for (i = 0; i < NUM_FUNC; i++) {
if((i == 1) && ((a < -1 || b > 1) || (b < -1 || a > 1)))
continue;
GET_TIME(comeco);
res = integral_seq(a, b, erro, funcs[i]);
GET_TIME(fim);
tempo = fim - comeco;
tempos_f[i][0] = tempo;
printf("f(%c) -> resultado: %15.9lf | tempo: %15.9lf\n", 97 + i, res, tempo);
}
printf("\n");
printf("Algoritmo concorrente com divisão inicial de tarefas:\n");
for (i = 0; i < NUM_FUNC; i++) {
if ((i == 1) && ((a < -1 || b > 1) || (b < -1 || a > 1)))
continue;
GET_TIME(comeco);
res = integral_conc_div(nThreads, a, b, erro, funcs[i]);
GET_TIME(fim);
tempo = fim - comeco;
tempos_f[i][1] = tempo;
printf("f(%c) -> resultado: %15.9lf | tempo: %15.9lf\n", 97 + i, res, tempo);
}
printf("\n");
printf("Algoritmo concorrente com pilha de tarefas:\n");
for (i = 0; i < NUM_FUNC; i++) {
if ((i == 1) && ((a < -1 || b > 1) || (b < -1 || a > 1)))
continue;
GET_TIME(comeco);
res = integral_conc(nThreads, a, b, erro, funcs[i]);
GET_TIME(fim);
tempo = fim - comeco;
tempos_f[i][2] = tempo;
printf("f(%c) -> resultado: %15.9lf | tempo: %15.9lf\n", 97 + i, res, tempo);
}
printf("\n");
processa_ganho(tempos_f);
return 0;
}