Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
icc1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cristian Weiland
icc1
Commits
b537ebf2
Commit
b537ebf2
authored
9 years ago
by
Cristian Weiland
Browse files
Options
Downloads
Patches
Plain Diff
Fix some seg faults
Signed-off-by:
Cristian
<
cw14@inf.ufpr.br
>
parent
dba6b31c
No related branches found
No related tags found
1 merge request
!1
Develop
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
header.h
+1
-1
1 addition, 1 deletion
header.h
pdeSolver.c
+23
-12
23 additions, 12 deletions
pdeSolver.c
with
24 additions
and
13 deletions
header.h
+
1
−
1
View file @
b537ebf2
...
@@ -13,7 +13,7 @@ double UDivisor;
...
@@ -13,7 +13,7 @@ double UDivisor;
double
Pipi
=
M_PI
*
M_PI
;
// Pipi = Pi * Pi
double
Pipi
=
M_PI
*
M_PI
;
// Pipi = Pi * Pi
void
print_errno
(
void
);
void
print_errno
(
void
);
void
getParams
(
int
argc
,
char
*
argv
[],
FILE
*
fp
);
void
getParams
(
int
argc
,
char
*
argv
[],
FILE
*
*
fp
);
//double f(double x, double y);
//double f(double x, double y);
//void u(int i, int j, double **u, double **f);
//void u(int i, int j, double **u, double **f);
double
residueNorm
(
double
*
r
);
double
residueNorm
(
double
*
r
);
...
...
This diff is collapsed.
Click to expand it.
pdeSolver.c
+
23
−
12
View file @
b537ebf2
...
@@ -37,7 +37,7 @@ void print_errno(void) {
...
@@ -37,7 +37,7 @@ void print_errno(void) {
printf
(
"%s"
,
strerror
(
errno
));
printf
(
"%s"
,
strerror
(
errno
));
}
}
void
getParams
(
int
argc
,
char
*
argv
[],
FILE
*
fp
)
{
void
getParams
(
int
argc
,
char
*
argv
[],
FILE
*
*
fp
)
{
if
(
argc
!=
ARGS_NUM
)
{
if
(
argc
!=
ARGS_NUM
)
{
fprintf
(
stderr
,
"Wrong number of arguments.
\n
"
);
fprintf
(
stderr
,
"Wrong number of arguments.
\n
"
);
exit
(
-
1
);
exit
(
-
1
);
...
@@ -51,7 +51,7 @@ void getParams(int argc, char* argv[], FILE *fp) {
...
@@ -51,7 +51,7 @@ void getParams(int argc, char* argv[], FILE *fp) {
}
else
if
(
strcmp
(
argv
[
i
],
"-i"
)
==
0
)
{
}
else
if
(
strcmp
(
argv
[
i
],
"-i"
)
==
0
)
{
MaxI
=
atoi
(
argv
[
i
+
1
]);
MaxI
=
atoi
(
argv
[
i
+
1
]);
}
else
if
(
strcmp
(
argv
[
i
],
"-o"
)
==
0
)
{
}
else
if
(
strcmp
(
argv
[
i
],
"-o"
)
==
0
)
{
fp
=
fopen
(
argv
[
i
+
1
],
"w"
);
*
fp
=
fopen
(
argv
[
i
+
1
],
"w"
);
}
else
{
}
else
{
fprintf
(
stderr
,
"Incorrect parameter.
\n
"
);
fprintf
(
stderr
,
"Incorrect parameter.
\n
"
);
exit
(
-
1
);
exit
(
-
1
);
...
@@ -96,13 +96,13 @@ void sor(double *b, double *x, double *r, double *timeSor, double *timeResNorm)
...
@@ -96,13 +96,13 @@ void sor(double *b, double *x, double *r, double *timeSor, double *timeResNorm)
double
sigma
,
now
,
fxy
,
res
,
maxRes
=
0
,
tRes
=
0
;
// maxRes is the biggest residue, tRes is total residue in this iteration.
double
sigma
,
now
,
fxy
,
res
,
maxRes
=
0
,
tRes
=
0
;
// maxRes is the biggest residue, tRes is total residue in this iteration.
for
(
k
=
0
;
k
<
MaxI
;
k
++
)
{
for
(
k
=
0
;
k
<
MaxI
;
k
++
)
{
now
=
timestamp
();
now
=
timestamp
();
for
(
i
=
0
;
i
<
Nx
*
Ny
;
++
i
)
{
for
(
i
=
1
+
Ny
;
i
<
Nx
*
Ny
-
Ny
-
1
;
++
i
)
{
// Start at u[1][1], which means u[Ny+1]
x
[
i
]
=
x
[
i
]
+
W
*
(
calcU
(
i
,
x
)
-
x
[
i
]);
x
[
i
]
=
x
[
i
]
+
W
*
(
calcU
(
i
,
x
)
-
x
[
i
]);
}
}
*
timeSor
+=
timestamp
()
-
now
;
*
timeSor
+=
timestamp
()
-
now
;
now
=
timestamp
();
now
=
timestamp
();
printf
(
"Res = %lf - "
,
res
);
printf
(
"Res = %lf - "
,
res
);
for
(
i
=
0
;
i
<
Nx
*
Ny
;
++
i
)
{
for
(
i
=
1
+
Ny
;
i
<
Nx
*
Ny
-
Ny
-
1
;
++
i
)
{
res
=
f
(
i
);
res
=
f
(
i
);
res
-=
subsRow
(
i
,
x
);
res
-=
subsRow
(
i
,
x
);
if
(
res
>
maxRes
)
if
(
res
>
maxRes
)
...
@@ -122,8 +122,7 @@ int main(int argc, char *argv[]) {
...
@@ -122,8 +122,7 @@ int main(int argc, char *argv[]) {
int
i
,
j
,
k
;
int
i
,
j
,
k
;
FILE
*
fpExit
;
FILE
*
fpExit
;
getParams
(
argc
,
argv
,
fpExit
);
getParams
(
argc
,
argv
,
&
fpExit
);
fpExit
=
fopen
(
"saida"
,
"w"
);
Nx
=
(
M_PI
/
Hx
);
Nx
=
(
M_PI
/
Hx
);
Ny
=
(
M_PI
/
Hy
);
Ny
=
(
M_PI
/
Hy
);
...
@@ -135,7 +134,7 @@ int main(int argc, char *argv[]) {
...
@@ -135,7 +134,7 @@ int main(int argc, char *argv[]) {
double
sigma
;
double
sigma
;
double
*
b
,
*
x
,
*
r
,
*
timeSor
,
*
timeResNorm
;
double
*
b
,
*
x
,
*
r
,
*
timeSor
,
*
timeResNorm
;
b
=
malloc
(
Nx
*
Ny
*
sizeof
(
double
));
b
=
malloc
(
(
Nx
+
2
)
*
(
Ny
+
2
)
*
sizeof
(
double
));
x
=
malloc
((
Nx
+
2
)
*
(
Ny
+
2
)
*
sizeof
(
double
));
x
=
malloc
((
Nx
+
2
)
*
(
Ny
+
2
)
*
sizeof
(
double
));
r
=
malloc
(
MaxI
*
sizeof
(
double
));
r
=
malloc
(
MaxI
*
sizeof
(
double
));
timeSor
=
calloc
(
1
,
sizeof
(
double
));
timeSor
=
calloc
(
1
,
sizeof
(
double
));
...
@@ -149,9 +148,11 @@ int main(int argc, char *argv[]) {
...
@@ -149,9 +148,11 @@ int main(int argc, char *argv[]) {
x
[
in
(
i
,
Nx
+
1
)
]
=
sin
(
2
*
M_PI
*
(
i
*
Hx
));
x
[
in
(
i
,
Nx
+
1
)
]
=
sin
(
2
*
M_PI
*
(
i
*
Hx
));
}
}
//printf("Starting sor...\n");
sor
(
b
,
x
,
r
,
timeSor
,
timeResNorm
);
sor
(
b
,
x
,
r
,
timeSor
,
timeResNorm
);
print_vector
(
x
);
//
print_vector(x);
printf
(
"TimeSor: %lf
\n
TimeResNorm: %lf
\n\n
Norma do Resíduo
\n
"
,
*
timeSor
,
*
timeResNorm
);
printf
(
"TimeSor: %lf
\n
TimeResNorm: %lf
\n\n
Norma do Resíduo
\n
"
,
*
timeSor
,
*
timeResNorm
);
for
(
i
=
0
;
i
<
MaxI
;
++
i
)
{
for
(
i
=
0
;
i
<
MaxI
;
++
i
)
{
...
@@ -164,14 +165,24 @@ int main(int argc, char *argv[]) {
...
@@ -164,14 +165,24 @@ int main(int argc, char *argv[]) {
}
}
fprintf
(
fpExit
,
"
\n
"
);
fprintf
(
fpExit
,
"
\n
"
);
FILE
*
expected
=
fopen
(
"expected.txt"
,
"w"
);
FILE
*
expected
=
fopen
(
"expected.txt"
,
"w"
);
for
(
i
=
0
;
i
<
Nx
;
i
++
)
{
for
(
i
=
0
;
i
<
Ny
;
i
++
)
{
// Print bottom border.
for
(
j
=
0
;
j
<
Ny
;
j
++
)
{
fprintf
(
fpExit
,
"%lf %lf %lf
\n
"
,
0
.
0
f
,
i
*
Hy
,
x
[
i
*
Hx
]);
//fprintf(fpExit,"%lf %lf %lf\n",i*Hx,j*Hy,x[i*Ny + j]);
fprintf
(
expected
,
"%lf %lf %lf
\n
"
,
0
.
0
f
,
i
*
Hy
,
f
[
i
*
Hx
]);
fprintf
(
fpExit
,
"%lf %lf %lf
\n
"
,
i
*
Hx
,
j
*
Hy
,
subsRow
(
i
*
Ny
+
j
,
x
));
}
for
(
i
=
1
;
i
<
Nx
;
i
++
)
{
// Since im using subsRow, I cant start at position 0.
fprintf
(
fpExit
,
"%lf %lf %lf
\n
"
,
i
*
Hx
,
0
.
0
f
,
x
[
i
*
Hx
])
// Border.
fprintf
(
expected
,
"%lf %lf %lf
\n
"
,
i
*
Hx
,
0
.
0
f
,
f
[
i
*
Hx
])
// Border.
for
(
j
=
1
;
j
<
Ny
;
j
++
)
{
fprintf
(
fpExit
,
"%lf %lf %lf
\n
"
,
i
*
Hx
,
j
*
Hy
,
subsRow
(
i
*
Ny
+
j
,
x
));
// Should we change i*Hx with j*Hy? (Columns by rows?)
fprintf
(
expected
,
"%lf %lf %lf
\n
"
,
i
*
Hx
,
j
*
Hy
,
f
(
i
*
Ny
+
j
));
fprintf
(
expected
,
"%lf %lf %lf
\n
"
,
i
*
Hx
,
j
*
Hy
,
f
(
i
*
Ny
+
j
));
}
}
}
}
for
(
i
=
0
;
i
<
Ny
;
i
++
)
{
// Print bottom border.
fprintf
(
fpExit
,
"%lf %lf %lf
\n
"
,
Nx
*
Hx
,
i
*
Hy
,
x
[
i
*
Hx
]);
fprintf
(
expected
,
"%lf %lf %lf
\n
"
,
Nx
*
Hx
,
i
*
Hy
,
f
[
i
*
Hx
]);
}
// Nx columns and Ny rows.
// Nx columns and Ny rows.
fclose
(
fpExit
);
return
0
;
return
0
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment