Skip to content

Commit

Permalink
Merge pull request #36 from AnzhelaSukhanova/Task01
Browse files Browse the repository at this point in the history
Task01_Sukhanova
  • Loading branch information
EgorkaKulikov authored Nov 24, 2019
2 parents 5bc13f9 + c2ea658 commit a8a9c1e
Show file tree
Hide file tree
Showing 10 changed files with 10,327 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Task01/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
all: par seq

par: par.c
g++ -openmp par.c -o par

seq: seq.c
g++ seq.c -o seq

clean:
rm -rf *.o par seq
Binary file added Task01/comparison.pdf
Binary file not shown.
Binary file added Task01/comparison.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions Task01/par.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
//#include <time.h>

int main(int argc, char *argv[]) {
//double start = clock();
int n;
scanf("%d", &n);
double a[n][n + 1], c;
int i, j, k;
for (i = 0; i < n; i++) {
for (j = 0; j < n + 1; j++)
scanf("%lf", &a[i][j]);
}
#pragma omp for shared(a) simd
for (i = 0; i < n - 1; i++) {
if (a[i][i] == 0) {
#pragma omp for shared(a) simd
for (k = i + 1; k < n; k++) {
if (a[k][i] != 0) {
#pragma omp for shared(a) simd
for (j = 0; j < n +1; j++) {
c=a[k][j];
a[k][j]=a[i][j];
a[i][j]=c;
}
}
}
}
if (a[i][i]!=0) {
#pragma omp for shared(a) simd
for (k = i + 1; k < n; k++) {
c=a[k][i];
#pragma omp for shared(a) simd
for (j = 0; j < n + 1; j++) {
a[k][j] -= a[i][j] * c / a[i][i];
}
}
}
}
#pragma omp for shared(a) simd
for (i = n - 1; i >= 0; i--) {
a[i][i]=a[i][n]/a[i][i];
#pragma omp for shared(a) simd
for(j = i - 1; j >= 0; j--) {
a[j][n] -= a[j][i] * a[i][i];
}
}
FILE * file = fopen("par_res", "a");
if (file != NULL)
{
for (i = 0; i < n; i++) {
if (a[i][i] == -0) a[i][i] = 0;
fprintf(file, "%g%s", a[i][i], " ");
}
fprintf(file, "\n");
//fprintf(file, "%f\n", (clock() - start) / CLOCKS_PER_SEC);
fclose(file);
}
return 0;
}
54 changes: 54 additions & 0 deletions Task01/seq.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <stdio.h>
#include <stdlib.h>
//#include <time.h>

int main(int argc, char *argv[]) {
//double start = clock();
int n;
scanf("%d", &n);
double a[n][n + 1], c;
int i, j, k;
for (i = 0; i < n; i++) {
for (j = 0; j < n + 1; j++)
scanf("%lf", &a[i][j]);
}
for (i = 0; i < n - 1; i++) {
if (a[i][i] == 0) {
for (k = i + 1; k < n; k++) {
if (a[k][i] != 0) {
for (j = 0; j < n + 1; j++) {
c=a[k][j];
a[k][j]=a[i][j];
a[i][j]=c;
}
}
}
}
if (a[i][i]!=0) {
for (k = i + 1; k < n; k++) {
c=a[k][i];
for (j = 0; j < n + 1; j++) {
a[k][j] -= a[i][j] * c / a[i][i];
}
}
}
}
for (i = n - 1; i >= 0; i--) {
a[i][i]=a[i][n]/a[i][i];
for(j = i - 1; j >= 0; j--) {
a[j][n] -= a[j][i] * a[i][i];
}
}
FILE * file = fopen("seq_res", "a");
if (file != NULL)
{
for (i = 0; i < n; i++) {
if (a[i][i] == -0) a[i][i] = 0;
fprintf(file, "%g%s", a[i][i], " ");
}
fprintf(file, "\n");
//fprintf(file, "%f\n", (clock() - start) / CLOCKS_PER_SEC);
fclose(file);
}
return 0;
}
22 changes: 22 additions & 0 deletions Task01/tests/test1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
4
2
5
4
1
20
1
3
2
1
11
2
10
9
7
40
3
8
9
2
37

32 changes: 32 additions & 0 deletions Task01/tests/test2
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
5
1
2
-3
4
-1
-1
2
-1
3
-4
2
8
3
1
-1
2
-1
3
4
3
4
2
2
-2
1
-1
-1
2
-3
-3

32 changes: 32 additions & 0 deletions Task01/tests/test3
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
5
1
-2
4
0
2
0
4
-11
21
-2
3
-1
-3
5
-13
-4
1
-2
0
0
0
1
0
1
0
0
0
0
1
0

14 changes: 14 additions & 0 deletions Task01/tests/test4
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
3
2
3
-1
9
1
-2
1
3
1
0
2
2

Loading

0 comments on commit a8a9c1e

Please sign in to comment.