-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPSPtest.c
50 lines (41 loc) · 1.13 KB
/
APSPtest.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
#include <stdio.h>
#include <stdlib.h>
#include<sys/time.h>
#include "MatUtil.h"
int main(int argc, char **argv)
{
struct timeval tv1,tv2,tv3,tv4;
FILE *f = fopen("dynamic.txt", "a");
if(f == NULL)
printf("Error opening the file\n");
if(argc != 2)
{
printf("Usage: test {N}\n");
exit(-1);
}
//generate a random matrix.
size_t N = atoi(argv[1]);
int *mat = (int*)malloc(sizeof(int)*N*N);
GenMatrix(mat, N);
//compute the reference result.
int *ref = (int*)malloc(sizeof(int)*N*N);
memcpy(ref, mat, sizeof(int)*N*N);
gettimeofday(&tv1,NULL);
ST_APSP(ref, N);
gettimeofday(&tv2,NULL);
fprintf(f,"%ld,", (tv2.tv_sec -tv1.tv_sec)*1000000+tv2.tv_usec-tv1.tv_usec);
//compute your results
int *result = (int*)malloc(sizeof(int)*N*N);
memcpy(result, mat, sizeof(int)*N*N);
//replace by parallel algorithm
gettimeofday(&tv3,NULL);
parallel(result, N);
gettimeofday(&tv4,NULL);
fprintf(f,"%ld\n", (tv4.tv_sec -tv3.tv_sec)*1000000+tv4.tv_usec-tv3.tv_usec);
//compare your result with reference result
if(CmpArray(result, ref, N*N))
printf("Your result is correct.\n");
else
printf("Your result is wrong.\n");
fclose(f);
}