Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Iker Martín Álvarez
Malleable_CG
Commits
9100320b
Commit
9100320b
authored
Sep 20, 2023
by
iker_martin
Browse files
Bugfix in Conjugate Gradient code. One variable was not initialised correctly
parent
95f9a9a6
Changes
1
Show whitespace changes
Inline
Side-by-side
Main/ConjugateGradient.c
View file @
9100320b
...
...
@@ -72,7 +72,7 @@ void getIds_intercomm(struct Dist_data dist_data, int numP_other, int **idS);
int
main
(
int
argc
,
char
*
argv
[])
{
int
terminate
;
int
num_nodes
,
num_cpus
=
20
;
int
req
,
num_nodes
,
num_cpus
=
20
;
char
*
nodelist
=
NULL
;
Compute_data
computeData
;
...
...
@@ -89,7 +89,7 @@ int main (int argc, char *argv[]) {
num_cpus
=
num_nodes
*
num_cpus
;
}
MPI_Init
(
&
argc
,
&
argv
);
MPI_Init
_thread
(
&
argc
,
&
argv
,
MPI_THREAD_MULTIPLE
,
&
req
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
numP
);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
myId
);
...
...
@@ -109,6 +109,7 @@ int main (int argc, char *argv[]) {
dist_data
.
numP_parents
=
numP
;
terminate
=
compute
(
&
computeData
,
&
dist_data
,
argv
);
terminate
=
1
;
if
(
myId
==
ROOT
&&
terminate
)
{
printf
(
"End(%d) --> (%d,%20.10e)
\n
"
,
computeData
.
n
,
computeData
.
iter
,
computeData
.
tol
);
}
...
...
@@ -262,6 +263,10 @@ void mat_alloc(Compute_data *computeData, SparseMatrix mat, struct Dist_data dis
MPI_Scatterv
((
mat
.
vptr
)
+
1
,
computeData
->
dist_rows
,
computeData
->
displs_rows
,
MPI_INT
,
(
computeData
->
subm
.
vptr
)
+
1
,
dist_data
.
tamBl
,
MPI_INT
,
ROOT
,
MPI_COMM_WORLD
);
CreateInts
(
&
(
computeData
->
vlen
),
dist_data
.
tamBl
+
1
);
for
(
i
=
0
;
i
<
dist_data
.
tamBl
+
1
;
i
++
)
{
computeData
->
vlen
[
i
]
=
computeData
->
subm
.
vptr
[
i
];
}
TransformLengthtoHeader
(
computeData
->
subm
.
vptr
,
computeData
->
subm
.
dim1
);
// The array is converted from vlen to vptr
elems
=
computeData
->
subm
.
vptr
[
dist_data
.
tamBl
];
CreateSparseMatrixValues
(
&
(
computeData
->
subm
),
dist_data
.
tamBl
,
computeData
->
n
,
elems
,
0
);
...
...
@@ -380,18 +385,13 @@ int compute(Compute_data *computeData, struct Dist_data *dist_data, char *argv[]
double
DONE
=
1
.
0
,
DMONE
=
-
1
.
0
,
DZERO
=
0
.
0
;
int
ended_loop
=
1
;
int
cnt
=
0
,
created
;
int
cnt
=
0
;
computeData
->
maxiter
=
1000
;
MPI_Barrier
(
MPI_COMM_WORLD
);
printf
(
"PRUEBA %d
\n
"
,
computeData
->
iter
);
fflush
(
stdout
);
while
((
computeData
->
iter
<
computeData
->
maxiter
)
&&
(
computeData
->
tol
>
computeData
->
umbral
))
{
//while (computeData->tol > computeData->umbral) {
//malleability_checkpoint();
if
(
created
)
{
ended_loop
=
0
;
break
;}
// if(dist_data->myId == ROOT) printf ("(%d,%20.10e)\n", computeData->iter, computeData->tol);
...
...
@@ -401,8 +401,6 @@ int compute(Compute_data *computeData, struct Dist_data *dist_data, char *argv[]
#else
ProdSparseMatrixVector
(
computeData
->
subm
,
computeData
->
d_full
,
computeData
->
z
);
// z += A * d_full
#endif
MPI_Barrier
(
MPI_COMM_WORLD
);
printf
(
"PRUEBA 1
\n
"
);
fflush
(
stdout
);
computeData
->
rho
=
ddot
(
&
(
dist_data
->
tamBl
),
computeData
->
d
,
&
IONE
,
computeData
->
z
,
&
IONE
);
// rho = (d * z)
MPI_Allreduce
(
MPI_IN_PLACE
,
&
computeData
->
rho
,
1
,
MPI_DOUBLE
,
MPI_SUM
,
MPI_COMM_WORLD
);
// Reduce(rho, SUM)
computeData
->
rho
=
computeData
->
beta
/
computeData
->
rho
;
// rho = beta / aux
...
...
@@ -411,20 +409,15 @@ int compute(Compute_data *computeData, struct Dist_data *dist_data, char *argv[]
daxpy
(
&
(
dist_data
->
tamBl
),
&
computeData
->
rho
,
computeData
->
z
,
&
IONE
,
computeData
->
res
,
&
IONE
);
// res -= rho * z
computeData
->
alpha
=
computeData
->
beta
;
// alpha = beta
computeData
->
beta
=
ddot
(
&
(
dist_data
->
tamBl
),
computeData
->
res
,
&
IONE
,
computeData
->
res
,
&
IONE
);
// beta = res' * res
MPI_Barrier
(
MPI_COMM_WORLD
);
printf
(
"PRUEBA 2
\n
"
);
fflush
(
stdout
);
MPI_Allreduce
(
MPI_IN_PLACE
,
&
computeData
->
beta
,
1
,
MPI_DOUBLE
,
MPI_SUM
,
MPI_COMM_WORLD
);
// Reduce(beta, SUM)
computeData
->
alpha
=
computeData
->
beta
/
computeData
->
alpha
;
// alpha = beta / alpha
dscal
(
&
(
dist_data
->
tamBl
),
&
computeData
->
alpha
,
computeData
->
d
,
&
IONE
);
// d = alpha * d
daxpy
(
&
(
dist_data
->
tamBl
),
&
DONE
,
computeData
->
res
,
&
IONE
,
computeData
->
d
,
&
IONE
);
// d += res
MPI_Barrier
(
MPI_COMM_WORLD
);
printf
(
"PRUEBA 3
\n
"
);
fflush
(
stdout
);
MPI_Allgatherv
(
computeData
->
d
,
dist_data
->
tamBl
,
MPI_DOUBLE
,
computeData
->
d_full
,
computeData
->
dist_rows
,
computeData
->
displs_rows
,
MPI_DOUBLE
,
MPI_COMM_WORLD
);
// d_full = Gather(d)
computeData
->
tol
=
sqrt
(
computeData
->
beta
);
// tol = sqrt(beta) = norm (res)
computeData
->
iter
++
;
printf
(
"TEST %d
\n
"
,
computeData
->
iter
);
}
#ifdef DEBUG
if
(
dist_data
->
myId
==
ROOT
)
printf
(
"Ended loop
\n
"
);
...
...
@@ -486,11 +479,6 @@ int dist_old(struct Dist_data *dist_data, Compute_data *computeData, char *argv[
malleability_add_data
(
&
(
computeData
->
z
),
computeData
->
n
,
MAL_DOUBLE
,
0
,
1
);
malleability_add_data
(
&
(
computeData
->
d_full
),
computeData
->
n
,
MAL_DOUBLE
,
1
,
1
);
CreateInts
(
&
(
computeData
->
vlen
),
dist_data
->
tamBl
+
1
);
for
(
i
=
0
;
i
<=
dist_data
->
tamBl
;
i
++
)
{
computeData
->
vlen
[
i
]
=
computeData
->
subm
.
vptr
[
i
];
}
TransformHeadertoLength
(
computeData
->
vlen
,
computeData
->
subm
.
dim1
);
// De vptr a vlen
malleability_add_data
(
&
(
computeData
->
vlen
),
computeData
->
n
,
MAL_INT
,
1
,
1
);
//FIXME Ultimo valor puede sere asinc
malleability_add_data
(
&
(
computeData
->
subm
.
vpos
),
computeData
->
n
,
MAL_INT
,
1
,
1
);
malleability_add_data
(
&
(
computeData
->
subm
.
vval
),
computeData
->
n
,
MAL_DOUBLE
,
1
,
1
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment