Line | |
---|
1 | //Author Antonio-Gabriel Sturzu |
---|
2 | |
---|
3 | #include<stdio.h> |
---|
4 | #include<omp.h> |
---|
5 | #define lim 100001 |
---|
6 | |
---|
7 | |
---|
8 | int main() |
---|
9 | { |
---|
10 | int m[1000][1000],n,i,j,k,chunk=1; |
---|
11 | double start,stop; |
---|
12 | FILE *f=fopen("royfloyd.in","r"); |
---|
13 | |
---|
14 | fscanf(f,"%i",&n); |
---|
15 | for(i=0;i<n;i++) |
---|
16 | for(j=0;j<n;j++) |
---|
17 | { |
---|
18 | fscanf(f,"%i",&m[i][j]); |
---|
19 | if(i!=j && m[i][j]==0) |
---|
20 | m[i][j]=lim; |
---|
21 | } |
---|
22 | fclose(f); |
---|
23 | |
---|
24 | start=omp_get_wtime(); |
---|
25 | for(k=0;k<n;k++) |
---|
26 | { |
---|
27 | #pragma omp parallel shared(m,k) private(i,j) |
---|
28 | { |
---|
29 | #pragma omp for schedule(static) |
---|
30 | for(i=0;i<n;i++) |
---|
31 | for(j=0;j<n;j++) |
---|
32 | if(m[i][k]+m[k][j]<m[i][j]) |
---|
33 | m[i][j]=m[i][k]+m[k][j]; |
---|
34 | } |
---|
35 | } |
---|
36 | stop=omp_get_wtime(); |
---|
37 | printf("Au trecut %f secunde\n",stop-start); |
---|
38 | f=fopen("royfloyd.out","w"); |
---|
39 | for(i=0;i<n;i++) |
---|
40 | { |
---|
41 | for(j=0;j<n-1;j++) |
---|
42 | { |
---|
43 | if(m[i][j]==lim) |
---|
44 | m[i][j]=0; |
---|
45 | fprintf(f,"%i ",m[i][j]); |
---|
46 | } |
---|
47 | if(m[i][n-1]==lim) |
---|
48 | m[i][n-1]=0; |
---|
49 | fprintf(f,"%i\n",m[i][n-1]); |
---|
50 | } |
---|
51 | fclose(f); |
---|
52 | return 0; |
---|
53 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.