-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutomation.c
67 lines (63 loc) · 1.89 KB
/
Automation.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include "mat.h"
int main(int argc, char const *argv[])
{
double *a, *b, *c, time_spend;
clock_t begin, end;
FILE *file = fopen("mpi_data.txt", "w");
FILE *data=fopen("data.txt","w");
fclose(data);
fclose(file);
char instruction[100];
data =fopen("data.txt","a+");
for (size_t i = 100; i < 1000; i += 100)
{
//nonoptimized
begin = clock();
a = malloc(i * i * 8);
b = malloc(i * i * 8);
a = gen_matrix(i, i);
b = gen_matrix(i, i);
c = malloc(i * i * 8);
mmult(c, a, i, i, b, i, i);
end = clock();
time_spend = ((double)(end - begin)) / CLOCKS_PER_SEC;
fprintf(data,"%6ld,%10f,", i, time_spend);
//simd
begin = clock();
a = malloc(i * i * 8);
b = malloc(i * i * 8);
a = gen_matrix(i, i);
b = gen_matrix(i, i);
c = malloc(i * i * 8);
mmult_vectorized(c, a, i, i, b, i, i);
end = clock();
time_spend = ((double)(end - begin)) / CLOCKS_PER_SEC;
fprintf(data,"%10f, ", time_spend);
//OMP
begin = clock();
a = malloc(i * i * 8);
b = malloc(i * i * 8);
a = gen_matrix(i, i);
b = gen_matrix(i, i);
c = malloc(i * i * 8);
mmult_omp(c, a, i, i, b, i, i);
end = clock();
time_spend = ((double)(end - begin)) / CLOCKS_PER_SEC;
fprintf(data,"%10f, ", time_spend);
//mpi
sprintf(instruction, "(mpiexec -f ~/hosts -n 4 ./mmult_mpi %d) > mpi_data.txt", i);
system(instruction);
file = fopen("mpi_data.txt", "r");
fscanf(file, "%lf", &time_spend);
fclose(file);
fprintf(data,"%10f\n", time_spend);
}
fclose(data);
sprintf(instruction, "gnuplot graph.gnu");
system(instruction);
}