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
MAM_BICGSTAB
Commits
d396827d
Commit
d396827d
authored
Mar 20, 2024
by
iker_martin
Browse files
Fixed minor memory errors
parent
03439e71
Changes
2
Show whitespace changes
Inline
Side-by-side
BiCGStab_Iker/BiCGStab.c
View file @
d396827d
...
...
@@ -103,6 +103,8 @@ void BiCGStab_init (Compute_data *computeData) {
#pragma omp parallel for
for
(
i
=
0
;
i
<
n_dist
;
i
++
)
computeData
->
diags
[
i
]
=
DONE
/
computeData
->
diags
[
i
];
InitDoubles
(
computeData
->
p_hat
,
n_dist
,
DZERO
,
DZERO
);
InitDoubles
(
computeData
->
q_hat
,
n_dist
,
DZERO
,
DZERO
);
#endif
CreateDoubles
(
&
computeData
->
aux
,
n
);
...
...
@@ -193,6 +195,7 @@ void BiCGStab_compute (Compute_data *computeData, user_redist_t *user_data) {
#else
computeData
->
p_hat
=
computeData
->
p
;
#endif
//dump(computeData);
#ifdef SPMV_OPTIMIZED
joinDistributeVectorSPMV
(
COLL_P2P_SPMV
,
MPI_COMM_WORLD
,
p_hat
,
vecP
,
vdimP
,
vdspP
,
vdimR
,
vdspR
,
vectDatatypeP
,
vectDatatypeR
);
...
...
@@ -335,10 +338,14 @@ void BiCGStab_free (Compute_data *computeData) {
RemoveDoubles
(
&
computeData
->
diags
);
RemoveDoubles
(
&
computeData
->
p_hat
);
RemoveDoubles
(
&
computeData
->
q_hat
);
#endif
#if DIRECT_ERROR
RemoveDoubles
(
&
computeData
->
res_err
);
RemoveDoubles
(
&
computeData
->
x_exact
);
#endif
RemoveDoubles
(
&
computeData
->
x
);
RemoveDoubles
(
&
computeData
->
b
);
RemoveInts
(
&
computeData
->
sizes
);
RemoveInts
(
&
computeData
->
dspls
);
RemoveInts
(
&
computeData
->
vlen
);
RemoveSparseMatrix
(
&
computeData
->
matL
);
}
...
...
@@ -391,6 +398,7 @@ int main (int argc, char **argv) {
/***************************************/
if
(
argc
==
4
)
{
mat_from_file
=
atoi
(
argv
[
2
]);
numTarget
=
atoi
(
argv
[
3
]);
}
else
{
mat_from_file
=
atoi
(
argv
[
2
]);
nodes
=
atoi
(
argv
[
3
]);
...
...
@@ -408,7 +416,6 @@ int main (int argc, char **argv) {
TransposeSparseMatrices
(
sym
,
0
,
&
mat
,
0
);
dim
=
mat
.
dim1
;
}
numTarget
=
atoi
(
argv
[
3
]);
// Distributing the matrix
dim
=
DistributeMatrix
(
mat
,
index
,
&
matL
,
indexL
,
vdimL
,
vdspL
,
root
,
MPI_COMM_WORLD
);
...
...
@@ -488,7 +495,6 @@ int main (int argc, char **argv) {
RemoveDoubles
(
&
sol1
);
BiCGStab_init
(
&
computeData
);
originals_set_data
(
&
computeData
,
numTarget
);
dump
(
&
computeData
);
}
...
...
@@ -540,7 +546,7 @@ void originals_set_data(Compute_data *computeData, int num_target) {
TransformHeadertoLength
(
computeData
->
matL
.
vptr
,
computeData
->
n
);
CreateInts
(
&
computeData
->
vlen
,
computeData
->
n
);
CopyInts
(
computeData
->
matL
.
vptr
,
computeData
->
vlen
,
computeData
->
n
);
CopyInts
(
computeData
->
matL
.
vptr
+
1
,
computeData
->
vlen
,
computeData
->
n
);
TransformLengthtoHeader
(
computeData
->
matL
.
vptr
,
computeData
->
n
);
MAM_Set_target_number
(
num_target
);
...
...
@@ -712,6 +718,229 @@ void dump(Compute_data *computeData) {
sleep
(
1
);
MPI_Barrier
(
computeData
->
comm
);
}
if
(
computeData
->
myId
==
0
)
printf
(
"
\n
"
);
if
(
computeData
->
myId
==
0
)
printf
(
"Vptr="
);
fflush
(
stdout
);
MPI_Barrier
(
computeData
->
comm
);
for
(
i
=
0
;
i
<
computeData
->
numP
;
i
++
)
{
if
(
computeData
->
myId
==
i
)
{
for
(
int
j
=
0
;
j
<
computeData
->
my_size
+
1
;
j
++
)
{
printf
(
"%d, "
,
computeData
->
matL
.
vptr
[
j
]);
}
}
fflush
(
stdout
);
sleep
(
1
);
MPI_Barrier
(
computeData
->
comm
);
}
if
(
computeData
->
myId
==
0
)
printf
(
"Vpos="
);
fflush
(
stdout
);
MPI_Barrier
(
computeData
->
comm
);
for
(
i
=
0
;
i
<
computeData
->
numP
;
i
++
)
{
if
(
computeData
->
myId
==
i
)
{
for
(
int
j
=
0
;
j
<
computeData
->
matL
.
vptr
[
computeData
->
my_size
];
j
++
)
{
printf
(
"%d, "
,
computeData
->
matL
.
vpos
[
j
]);
}
}
fflush
(
stdout
);
sleep
(
1
);
MPI_Barrier
(
computeData
->
comm
);
}
if
(
computeData
->
myId
==
0
)
printf
(
"Vval="
);
fflush
(
stdout
);
MPI_Barrier
(
computeData
->
comm
);
for
(
i
=
0
;
i
<
computeData
->
numP
;
i
++
)
{
if
(
computeData
->
myId
==
i
)
{
for
(
int
j
=
0
;
j
<
computeData
->
matL
.
vptr
[
computeData
->
my_size
];
j
++
)
{
printf
(
"%lf, "
,
computeData
->
matL
.
vval
[
j
]);
}
}
fflush
(
stdout
);
sleep
(
1
);
MPI_Barrier
(
computeData
->
comm
);
}
if
(
computeData
->
myId
==
0
)
printf
(
"
\n
X="
);
fflush
(
stdout
);
MPI_Barrier
(
computeData
->
comm
);
for
(
i
=
0
;
i
<
computeData
->
numP
;
i
++
)
{
if
(
computeData
->
myId
==
i
)
{
for
(
int
j
=
0
;
j
<
computeData
->
my_size
;
j
++
)
{
printf
(
"%lf, "
,
computeData
->
x
[
j
]);
}
}
fflush
(
stdout
);
sleep
(
1
);
MPI_Barrier
(
computeData
->
comm
);
}
if
(
computeData
->
myId
==
0
)
printf
(
"
\n
B="
);
fflush
(
stdout
);
MPI_Barrier
(
computeData
->
comm
);
for
(
i
=
0
;
i
<
computeData
->
numP
;
i
++
)
{
if
(
computeData
->
myId
==
i
)
{
for
(
int
j
=
0
;
j
<
computeData
->
my_size
;
j
++
)
{
printf
(
"%lf, "
,
computeData
->
b
[
j
]);
}
}
fflush
(
stdout
);
sleep
(
1
);
MPI_Barrier
(
computeData
->
comm
);
}
if
(
computeData
->
myId
==
0
)
printf
(
"
\n
r="
);
fflush
(
stdout
);
MPI_Barrier
(
computeData
->
comm
);
for
(
i
=
0
;
i
<
computeData
->
numP
;
i
++
)
{
if
(
computeData
->
myId
==
i
)
{
for
(
int
j
=
0
;
j
<
computeData
->
my_size
;
j
++
)
{
printf
(
"%lf, "
,
computeData
->
r
[
j
]);
}
}
fflush
(
stdout
);
sleep
(
1
);
MPI_Barrier
(
computeData
->
comm
);
}
if
(
computeData
->
myId
==
0
)
printf
(
"
\n
r0="
);
fflush
(
stdout
);
MPI_Barrier
(
computeData
->
comm
);
for
(
i
=
0
;
i
<
computeData
->
numP
;
i
++
)
{
if
(
computeData
->
myId
==
i
)
{
for
(
int
j
=
0
;
j
<
computeData
->
my_size
;
j
++
)
{
printf
(
"%lf, "
,
computeData
->
r0
[
j
]);
}
}
fflush
(
stdout
);
sleep
(
1
);
MPI_Barrier
(
computeData
->
comm
);
}
if
(
computeData
->
myId
==
0
)
printf
(
"
\n
p="
);
fflush
(
stdout
);
MPI_Barrier
(
computeData
->
comm
);
for
(
i
=
0
;
i
<
computeData
->
numP
;
i
++
)
{
if
(
computeData
->
myId
==
i
)
{
for
(
int
j
=
0
;
j
<
computeData
->
my_size
;
j
++
)
{
printf
(
"%lf, "
,
computeData
->
p
[
j
]);
}
}
fflush
(
stdout
);
sleep
(
1
);
MPI_Barrier
(
computeData
->
comm
);
}
if
(
computeData
->
myId
==
0
)
printf
(
"
\n
diags="
);
fflush
(
stdout
);
MPI_Barrier
(
computeData
->
comm
);
for
(
i
=
0
;
i
<
computeData
->
numP
;
i
++
)
{
if
(
computeData
->
myId
==
i
)
{
for
(
int
j
=
0
;
j
<
computeData
->
my_size
;
j
++
)
{
printf
(
"%lf, "
,
computeData
->
diags
[
j
]);
}
}
fflush
(
stdout
);
sleep
(
1
);
MPI_Barrier
(
computeData
->
comm
);
}
if
(
computeData
->
myId
==
0
)
printf
(
"
\n
p_hat="
);
fflush
(
stdout
);
MPI_Barrier
(
computeData
->
comm
);
for
(
i
=
0
;
i
<
computeData
->
numP
;
i
++
)
{
if
(
computeData
->
myId
==
i
)
{
for
(
int
j
=
0
;
j
<
computeData
->
my_size
;
j
++
)
{
printf
(
"%lf, "
,
computeData
->
p_hat
[
j
]);
}
}
fflush
(
stdout
);
sleep
(
1
);
MPI_Barrier
(
computeData
->
comm
);
}
/*
if(computeData->myId == 0) printf("\nq_hat=");
fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
for(int j=0; j<computeData->my_size; j++) {
printf("%lf, ", computeData->q_hat[j]);
}
}
fflush(stdout);
sleep(1);
MPI_Barrier(computeData->comm);
}
if(computeData->myId == 0) printf("\ns=");
fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
for(int j=0; j<computeData->my_size; j++) {
printf("%lf, ", computeData->s[j]);
}
}
fflush(stdout);
sleep(1);
MPI_Barrier(computeData->comm);
}
if(computeData->myId == 0) printf("\ny=");
fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
for(int j=0; j<computeData->my_size; j++) {
printf("%lf, ", computeData->y[j]);
}
}
fflush(stdout);
sleep(1);
MPI_Barrier(computeData->comm);
}
*/
}
/*
typedef struct {
double tol, tol0;
int iter, n;
double rho;
double *x, *b;
double *s, *q, *r, *p, *r0, *y, *p_hat, *q_hat;
double *aux;
SparseMatrix matL;
#if PRECOND
double *diags;
#endif
#if DIRECT_ERROR
double *res_err, *x_exact;
double direct_err;
#endif
double t1;
int *sizes, *dspls;
int my_size, my_dspl;
int *vlen;
int myId, numP;
MPI_Comm comm;
} Compute_data;
*/
BiCGStab_Iker/ToolsMPI.c
View file @
d396827d
...
...
@@ -180,7 +180,7 @@ int DistributeMatrix (SparseMatrix spr, int index, ptr_SparseMatrix sprL, int in
// Calculating the vectors of sizes (vdimL) and displacements (vdspl)
divL
=
(
dim
/
nProcs
);
rstL
=
(
dim
%
nProcs
);
for
(
i
=
0
;
i
<
nProcs
;
i
++
)
vdimL
[
i
]
=
divL
+
(
i
<
rstL
);
vdspL
[
0
]
=
0
;
for
(
i
=
0
;
i
<
nProcs
;
i
++
)
vdspL
[
i
+
1
]
=
vdspL
[
i
]
+
vdimL
[
i
];
vdspL
[
0
]
=
0
;
for
(
i
=
1
;
i
<
nProcs
;
i
++
)
vdspL
[
i
]
=
vdspL
[
i
-
1
]
+
vdimL
[
i
-
1
];
dimL
=
vdimL
[
myId
];
dspL
=
vdspL
[
myId
];
// Distribution of the matrix, by blocks
...
...
@@ -234,7 +234,7 @@ int ComputeMatrixSizes (int dim, int *vdimL, int *vdspL, MPI_Comm comm) {
// Calculating the vectors of sizes (vdimL) and displacements (vdspl)
divL
=
(
dim
/
nProcs
);
rstL
=
(
dim
%
nProcs
);
for
(
i
=
0
;
i
<
nProcs
;
i
++
)
vdimL
[
i
]
=
divL
+
(
i
<
rstL
);
vdspL
[
0
]
=
0
;
for
(
i
=
0
;
i
<
nProcs
;
i
++
)
vdspL
[
i
+
1
]
=
vdspL
[
i
]
+
vdimL
[
i
];
vdspL
[
0
]
=
0
;
for
(
i
=
1
;
i
<
nProcs
;
i
++
)
vdspL
[
i
]
=
vdspL
[
i
-
1
]
+
vdimL
[
i
-
1
];
return
dim
;
}
...
...
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