-
Notifications
You must be signed in to change notification settings - Fork 0
/
dados.py
187 lines (157 loc) · 8.47 KB
/
dados.py
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import csv
import subprocess
import numpy as np
def executar_benchmark(nome_benchmark, num_threads):
dicionario_comandos = {
'taskloop':'./mvt_taskloop',
'for':'./mvt_for',
'sequencial':'./mvt_sequencial',
'taskloop_simd':'./mvt_taskloop_simd',
'for_simd':'./mvt_for_simd',
'sequencial_simd':'./mvt_sequencial_simd'
}
if nome_benchmark in dicionario_comandos.keys():
if 'taskloop' == nome_benchmark:
saidas = subprocess.check_output(
[dicionario_comandos['taskloop'], str(num_threads)]).split('\n')
return float(saidas[0])
elif 'for' == nome_benchmark:
saidas = subprocess.check_output(
[dicionario_comandos['for'], str(num_threads)]).split('\n')
return float(saidas[0])
elif 'sequencial' == nome_benchmark:
saidas = subprocess.check_output([dicionario_comandos['sequencial']]).split('\n')
return float(saidas[0])
elif 'taskloop_simd' == nome_benchmark:
saidas = subprocess.check_output(
[dicionario_comandos['taskloop_simd'], str(num_threads)]).split('\n')
return float(saidas[0])
elif 'for_simd' == nome_benchmark:
saidas = subprocess.check_output(
[dicionario_comandos['for_simd'], str(num_threads)]).split('\n')
return float(saidas[0])
elif 'sequencial_simd' == nome_benchmark:
saidas = subprocess.check_output([dicionario_comandos['sequencial_simd']]).split('\n')
return float(saidas[0])
else:
print('[Erro] Opção de benchmark não encontrada, verifique seu código!')
if __name__ == "__main__":
if not os.path.exists('./graficos'):
os.makedirs('./graficos')
print('[PD360] Inicializando o código...')
benchmark_taskloop = {}
benchmark_for = {}
benchmark_sequencial = {}
benchmark_sequencial_simd = {}
benchmark_for_simd = {}
benchmark_taskloop_simd = {}
tamanho_dataset = 'LARGE_DATASET'
nome_arquivo_csv = 'resultados.csv'
print('[PD360] Compilando o código sequencial...')
comando_sequencial = 'gcc -I utilities -I linear-algebra/kernels/mvt utilities/polybench.c linear-algebra/kernels/mvt/mvt.c -DPOLYBENCH_TIME -D%s -o mvt_sequencial -O0' % (
tamanho_dataset)
print(comando_sequencial)
subprocess.call(comando_sequencial.split())
print('[PD360] Compilando o código taskloop...')
comando_taskloop = 'gcc -I utilities -I linear-algebra/kernels/mvt utilities/polybench.c -fopenmp -fdump-tree-ompexp-graph linear-algebra/kernels/mvt/mvt_taskloop.c -DPOLYBENCH_TIME -D%s -o mvt_taskloop -O0' % (
tamanho_dataset)
print(comando_taskloop)
subprocess.call(comando_taskloop.split())
print('[PD360] Compilando o código parallel for...')
comando_for = 'gcc -I utilities -I linear-algebra/kernels/mvt utilities/polybench.c -fopenmp -fdump-tree-ompexp-graph linear-algebra/kernels/mvt/mvt_for.c -DPOLYBENCH_TIME -D%s -o mvt_for -O0' % (
tamanho_dataset)
print(comando_for)
subprocess.call(comando_for.split())
print('[PD360] Compilando o código sequencial + simd...')
comando_sequencial_simd = 'gcc -I utilities -I -S linear-algebra/kernels/mvt utilities/polybench.c -fopenmp -fdump-tree-ompexp-graph linear-algebra/kernels/mvt/mvt_simd.c -DPOLYBENCH_TIME -D%s -o mvt_sequencial_simd -O0' % (
tamanho_dataset)
print(comando_sequencial_simd)
subprocess.call(comando_sequencial_simd.split())
print('[PD360] Compilando o código parallel for + simd...')
comando_for_simd = 'gcc -I utilities -I -S linear-algebra/kernels/mvt utilities/polybench.c -fopenmp -fdump-tree-ompexp-graph linear-algebra/kernels/mvt/mvt_for_simd.c -DPOLYBENCH_TIME -D%s -o mvt_for_simd -O0' % (
tamanho_dataset)
print(comando_for_simd)
subprocess.call(comando_for_simd.split())
print('[PD360] Compilando o código taskloop + simd...')
comando_taskloop_simd = 'gcc -I utilities -I linear-algebra/kernels/mvt utilities/polybench.c -fopenmp -fdump-tree-ompexp-graph linear-algebra/kernels/mvt/mvt_taskloop_simd.c -DPOLYBENCH_TIME -D%s -o mvt_taskloop_simd -O0' % (
tamanho_dataset)
print(comando_taskloop_simd)
subprocess.call(comando_taskloop_simd.split())
num_tentativas = 10
num_threads_list = [2,4,8,16]
for num_threads in num_threads_list:
print('[PD360] Executando ' + str(num_tentativas) +
' tentativas com ' + str(num_threads) + ' threads...')
benchmark_taskloop[num_threads] = []
benchmark_for[num_threads] = []
benchmark_sequencial[num_threads] = []
benchmark_sequencial_simd[num_threads] = []
benchmark_for_simd[num_threads] = []
benchmark_taskloop_simd[num_threads] = []
for repetir in range(0, num_tentativas):
# Sequencial
benchmark_sequencial[num_threads].append(
executar_benchmark('sequencial', num_threads))
# For
benchmark_for[num_threads].append(
executar_benchmark('for', num_threads))
# Taskloop
benchmark_taskloop[num_threads].append(
executar_benchmark('taskloop', num_threads))
# Sequencial + Simd
benchmark_sequencial_simd[num_threads].append(
executar_benchmark('sequencial_simd', num_threads))
# For + Simd
benchmark_for_simd[num_threads].append(
executar_benchmark('for_simd', num_threads))
# Taskloop + Simd
benchmark_taskloop_simd[num_threads].append(
executar_benchmark('taskloop_simd', num_threads))
tentativas_colunas = ['tentativa_' + str(i) for i in range (0, num_tentativas)]
fieldnames = ['num_threads', 'tipo'] + tentativas_colunas + ['media']
arquivo_csv = open(nome_arquivo_csv, 'w')
writer = csv.DictWriter(arquivo_csv, fieldnames=fieldnames)
writer.writeheader()
for num_threads in num_threads_list:
csv_sequencial = {'tipo':'sequencial', 'num_threads': num_threads}
csv_for = {'tipo':'for', 'num_threads': num_threads}
csv_taskloop = {'tipo':'taskloop', 'num_threads': num_threads}
csv_sequencial_simd = {'tipo':'sequencial_simd', 'num_threads': num_threads}
csv_for_simd = {'tipo':'for_simd', 'num_threads': num_threads}
csv_taskloop_simd = {'tipo':'taskloop_simd', 'num_threads': num_threads}
for i in range (0, num_tentativas):
csv_sequencial['tentativa_' + str(i)] = benchmark_sequencial[num_threads][i]
csv_for['tentativa_' + str(i)] = benchmark_for[num_threads][i]
csv_taskloop['tentativa_' + str(i)] = benchmark_taskloop[num_threads][i]
csv_sequencial_simd['tentativa_' + str(i)] = benchmark_sequencial_simd[num_threads][i]
csv_for_simd['tentativa_' + str(i)] = benchmark_for_simd[num_threads][i]
csv_taskloop_simd['tentativa_' + str(i)] = benchmark_taskloop_simd[num_threads][i]
print('[PD360] Calculando médias das tentativas...')
# Média Sequencial
media_sequencial = sum(benchmark_sequencial[num_threads]) / float(len(benchmark_sequencial[num_threads]))
# Média For
media_for = sum(benchmark_for[num_threads]) / float(len(benchmark_for[num_threads]))
# Média Taskloop
media_taskloop = sum(benchmark_taskloop[num_threads]) / float(len(benchmark_taskloop[num_threads]))
# Média Sequencial Simd
media_sequencial_simd = sum(benchmark_sequencial_simd[num_threads]) / float(len(benchmark_sequencial_simd[num_threads]))
# Média For Simd
media_for_simd = sum(benchmark_for_simd[num_threads]) / float(len(benchmark_for_simd[num_threads]))
# Média Taskloop Simd
media_taskloop_simd = sum(benchmark_taskloop_simd[num_threads]) / float(len(benchmark_taskloop_simd[num_threads]))
csv_sequencial['media'] = media_sequencial
csv_for['media'] = media_for
csv_taskloop['media'] = media_taskloop
csv_sequencial_simd['media'] = media_sequencial_simd
csv_for_simd['media'] = media_for_simd
csv_taskloop_simd['media'] = media_taskloop_simd
print('[PD360] Escrevendo resultados em um arquivo CSV...')
writer.writerow(csv_sequencial)
writer.writerow(csv_for)
writer.writerow(csv_taskloop)
writer.writerow(csv_sequencial_simd)
writer.writerow(csv_for_simd)
writer.writerow(csv_taskloop_simd)