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
1b43c2cb
Commit
1b43c2cb
authored
Oct 11, 2023
by
iker_martin
Browse files
Minor changes before executing.
parent
d5d7427a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Main/ConjugateGradient.c
View file @
1b43c2cb
...
...
@@ -10,7 +10,7 @@
#include <string.h>
#include "../malleability/malleabilityManager.h"
#include<unistd.h>
#include
<unistd.h>
//#define ONLY_SYM 0
#define ROOT 0
...
...
@@ -124,6 +124,7 @@ int main (int argc, char *argv[]) {
terminate
=
compute
(
&
computeData
,
&
dist_data
,
sm
);
if
(
terminate
)
{
update_dist_data
(
&
dist_data
);
MPI_Barrier
(
dist_data
.
comm
);
if
(
dist_data
.
myId
==
ROOT
)
{
print_global_results
();
...
...
@@ -134,6 +135,9 @@ int main (int argc, char *argv[]) {
// End of CG
free_malleability
();
free_computeData
(
&
computeData
,
1
);
if
(
sm
&&
numP
>
num_children
&&
dist_data
.
myId
==
0
)
{
MPI_Abort
(
MPI_COMM_WORLD
,
-
100
);
}
MPI_Finalize
();
}
...
...
@@ -383,12 +387,12 @@ void pre_compute(Compute_data *computeData, struct Dist_data dist_data, double *
#else
ProdSparseMatrixVector
(
computeData
->
subm
,
full_vec
,
computeData
->
z
);
// z += A * full_x
#endif
d
copy
(
&
(
dist_data
.
tamBl
),
subsol
,
&
IONE
,
computeData
->
res
,
&
IONE
);
// res = b
d
axpy
(
&
(
dist_data
.
tamBl
),
&
DMONE
,
computeData
->
z
,
&
IONE
,
computeData
->
res
,
&
IONE
);
// res -= z
//
d
copy (&(computeData.subm.dim1), computeData.res, &IONE, &(computeData.d+computeData.displs_rows[myId]), &IONE); // d_full = res
r
copy
(
&
(
dist_data
.
tamBl
),
subsol
,
&
IONE
,
computeData
->
res
,
&
IONE
);
// res = b
r
axpy
(
&
(
dist_data
.
tamBl
),
&
DMONE
,
computeData
->
z
,
&
IONE
,
computeData
->
res
,
&
IONE
);
// res -= z
//
r
copy (&(computeData.subm.dim1), computeData.res, &IONE, &(computeData.d+computeData.displs_rows[myId]), &IONE); // d_full = res
MPI_Allgatherv
(
computeData
->
res
,
dist_data
.
tamBl
,
MPI_DOUBLE
,
computeData
->
d_full
,
computeData
->
dist_rows
,
computeData
->
displs_rows
,
MPI_DOUBLE
,
MPI_COMM_WORLD
);
d
copy
(
&
(
dist_data
.
tamBl
),
&
(
computeData
->
d_full
[
dist_data
.
ini
]),
&
IONE
,
computeData
->
d
,
&
IONE
);
// d = d_full[ini] to d_full[ini+tamBl]
computeData
->
beta
=
d
dot
(
&
(
dist_data
.
tamBl
),
computeData
->
res
,
&
IONE
,
computeData
->
res
,
&
IONE
);
// beta = res' * res
r
copy
(
&
(
dist_data
.
tamBl
),
&
(
computeData
->
d_full
[
dist_data
.
ini
]),
&
IONE
,
computeData
->
d
,
&
IONE
);
// d = d_full[ini] to d_full[ini+tamBl]
computeData
->
beta
=
r
dot
(
&
(
dist_data
.
tamBl
),
computeData
->
res
,
&
IONE
,
computeData
->
res
,
&
IONE
);
// beta = res' * res
MPI_Allreduce
(
MPI_IN_PLACE
,
&
computeData
->
beta
,
1
,
MPI_DOUBLE
,
MPI_SUM
,
MPI_COMM_WORLD
);
computeData
->
tol
=
sqrt
(
computeData
->
beta
);
// tol = sqrt(beta) = norm (res)
}
...
...
@@ -408,25 +412,24 @@ int compute(Compute_data *computeData, struct Dist_data *dist_data, int sm) {
while
((
computeData
->
iter
<
computeData
->
maxiter
)
&&
(
computeData
->
tol
>
computeData
->
umbral
))
{
//TODO Hacer un estudio de los valores escalares para la iteración 501
// COMPUTATION
#ifdef ONLY_SYM
ProdSymSparseMatrixVector
(
computeData
->
subm
,
computeData
->
d_full
,
computeData
->
z
);
// z += A * d_full
#else
ProdSparseMatrixVector
(
computeData
->
subm
,
computeData
->
d_full
,
computeData
->
z
);
// z += A * d_full
#endif
computeData
->
rho
=
d
dot
(
&
(
dist_data
->
tamBl
),
computeData
->
d
,
&
IONE
,
computeData
->
z
,
&
IONE
);
// rho = (d * z)
computeData
->
rho
=
r
dot
(
&
(
dist_data
->
tamBl
),
computeData
->
d
,
&
IONE
,
computeData
->
z
,
&
IONE
);
// rho = (d * z)
MPI_Allreduce
(
MPI_IN_PLACE
,
&
computeData
->
rho
,
1
,
MPI_DOUBLE
,
MPI_SUM
,
dist_data
->
comm
);
// Reduce(rho, SUM)
computeData
->
rho
=
computeData
->
beta
/
computeData
->
rho
;
// rho = beta / aux
d
axpy
(
&
(
dist_data
->
tamBl
),
&
computeData
->
rho
,
computeData
->
d
,
&
IONE
,
computeData
->
vec
,
&
IONE
);
// x += rho * d
r
axpy
(
&
(
dist_data
->
tamBl
),
&
computeData
->
rho
,
computeData
->
d
,
&
IONE
,
computeData
->
vec
,
&
IONE
);
// x += rho * d
computeData
->
rho
=
-
computeData
->
rho
;
d
axpy
(
&
(
dist_data
->
tamBl
),
&
computeData
->
rho
,
computeData
->
z
,
&
IONE
,
computeData
->
res
,
&
IONE
);
// res -= rho * z
r
axpy
(
&
(
dist_data
->
tamBl
),
&
computeData
->
rho
,
computeData
->
z
,
&
IONE
,
computeData
->
res
,
&
IONE
);
// res -= rho * z
computeData
->
alpha
=
computeData
->
beta
;
// alpha = beta
computeData
->
beta
=
d
dot
(
&
(
dist_data
->
tamBl
),
computeData
->
res
,
&
IONE
,
computeData
->
res
,
&
IONE
);
// beta = res' * res
computeData
->
beta
=
r
dot
(
&
(
dist_data
->
tamBl
),
computeData
->
res
,
&
IONE
,
computeData
->
res
,
&
IONE
);
// beta = res' * res
MPI_Allreduce
(
MPI_IN_PLACE
,
&
computeData
->
beta
,
1
,
MPI_DOUBLE
,
MPI_SUM
,
dist_data
->
comm
);
// Reduce(beta, SUM)
computeData
->
alpha
=
computeData
->
beta
/
computeData
->
alpha
;
// alpha = beta / alpha
d
scal
(
&
(
dist_data
->
tamBl
),
&
computeData
->
alpha
,
computeData
->
d
,
&
IONE
);
// d = alpha * d
d
axpy
(
&
(
dist_data
->
tamBl
),
&
DONE
,
computeData
->
res
,
&
IONE
,
computeData
->
d
,
&
IONE
);
// d += res
r
scal
(
&
(
dist_data
->
tamBl
),
&
computeData
->
alpha
,
computeData
->
d
,
&
IONE
);
// d = alpha * d
r
axpy
(
&
(
dist_data
->
tamBl
),
&
DONE
,
computeData
->
res
,
&
IONE
,
computeData
->
d
,
&
IONE
);
// d += res
MPI_Allgatherv
(
computeData
->
d
,
dist_data
->
tamBl
,
MPI_DOUBLE
,
computeData
->
d_full
,
computeData
->
dist_rows
,
computeData
->
displs_rows
,
MPI_DOUBLE
,
dist_data
->
comm
);
// d_full = Gather(d)
...
...
@@ -668,7 +671,7 @@ void dist_new(struct Dist_data *dist_data, Compute_data *computeData) {
get_dist
(
computeData
->
n
,
dist_data
->
myId
,
dist_data
->
numP
,
dist_data
);
get_rows_dist
(
computeData
,
dist_data
->
numP
,
computeData
->
n
);
CreateDoubles
(
&
computeData
->
d
,
dist_data
->
tamBl
);
d
copy
(
&
(
dist_data
->
tamBl
),
&
(
computeData
->
d_full
[
dist_data
->
ini
]),
&
IONE
,
computeData
->
d
,
&
IONE
);
// d = d_full[ini] to d_full[ini+tamBl]
r
copy
(
&
(
dist_data
->
tamBl
),
&
(
computeData
->
d_full
[
dist_data
->
ini
]),
&
IONE
,
computeData
->
d
,
&
IONE
);
// d = d_full[ini] to d_full[ini+tamBl]
malleability_get_entries
(
&
entries
,
0
,
0
);
//Get if there is any asynch data to recover
if
(
entries
)
{
is_synch
=
0
;
entry
=
0
;
}
...
...
malleability/CommDist.c
View file @
1b43c2cb
...
...
@@ -5,7 +5,7 @@
#include "distribution_methods/block_distribution.h"
#include "CommDist.h"
void
prepare_redistribution
(
int
qty
,
int
mal_type
,
int
myId
,
int
numP
,
int
numO
,
int
is_children_group
,
int
is_intercomm
,
void
**
recv
,
struct
Counts
*
s_counts
,
struct
Counts
*
r_counts
);
void
prepare_redistribution
(
int
qty
,
int
mal_type
,
int
myId
,
int
numP
,
int
numO
,
int
is_children_group
,
int
is_intercomm
,
int
is_sync
,
void
**
recv
,
struct
Counts
*
s_counts
,
struct
Counts
*
r_counts
);
void
check_requests
(
struct
Counts
s_counts
,
struct
Counts
r_counts
,
MPI_Request
**
requests
,
size_t
*
request_qty
);
void
sync_point2point
(
void
*
send
,
void
*
recv
,
int
mal_type
,
int
is_intercomm
,
int
myId
,
struct
Counts
s_counts
,
struct
Counts
r_counts
,
MPI_Comm
comm
);
...
...
@@ -76,13 +76,13 @@ int sync_communication(void *send, void **recv, int qty, int mal_type, int depen
/* PREPARE COMMUNICATION */
MPI_Comm_test_inter
(
comm
,
&
is_intercomm
);
prepare_redistribution
(
qty
,
mal_type
,
myId
,
numP
,
numO
,
is_children_group
,
is_intercomm
,
recv
,
&
s_counts
,
&
r_counts
);
/*
prepare_redistribution
(
qty
,
mal_type
,
myId
,
numP
,
numO
,
is_children_group
,
is_intercomm
,
1
,
recv
,
&
s_counts
,
&
r_counts
);
if
(
is_intercomm
)
{
MPI_Intercomm_merge
(
comm
,
is_children_group
,
&
aux_comm
);
aux_comm_used
=
1
;
}
*/
}
else
{
aux_comm
=
comm
;
}
if
(
mal_type
==
MAL_INT
)
{
datatype
=
MPI_INT
;
}
else
if
(
mal_type
==
MAL_DOUBLE
)
{
...
...
@@ -112,11 +112,11 @@ int sync_communication(void *send, void **recv, int qty, int mal_type, int depen
/* PERFORM COMMUNICATION */
switch
(
red_method
)
{
case
MALL_RED_POINT
:
sync_point2point
(
send
,
*
recv
,
mal_type
,
is_intercomm
,
myId
,
s_counts
,
r_counts
,
comm
);
sync_point2point
(
send
,
*
recv
,
mal_type
,
is_intercomm
,
myId
,
s_counts
,
r_counts
,
aux_
comm
);
break
;
case
MALL_RED_BASELINE
:
default:
MPI_Alltoallv
(
send
,
s_counts
.
counts
,
s_counts
.
displs
,
datatype
,
*
recv
,
r_counts
.
counts
,
r_counts
.
displs
,
datatype
,
comm
);
MPI_Alltoallv
(
send
,
s_counts
.
counts
,
s_counts
.
displs
,
datatype
,
*
recv
,
r_counts
.
counts
,
r_counts
.
displs
,
datatype
,
aux_
comm
);
break
;
}
...
...
@@ -253,7 +253,7 @@ int async_communication(void *send, void **recv, int qty, int mal_type, int depe
/* PREPARE COMMUNICATION */
MPI_Comm_test_inter
(
comm
,
&
is_intercomm
);
prepare_redistribution
(
qty
,
mal_type
,
myId
,
numP
,
numO
,
is_children_group
,
is_intercomm
,
recv
,
&
s_counts
,
&
r_counts
);
prepare_redistribution
(
qty
,
mal_type
,
myId
,
numP
,
numO
,
is_children_group
,
is_intercomm
,
0
,
recv
,
&
s_counts
,
&
r_counts
);
check_requests
(
s_counts
,
r_counts
,
requests
,
request_qty
);
if
(
mal_type
==
MAL_INT
)
{
...
...
@@ -394,7 +394,7 @@ void async_point2point(void *send, void *recv, int mal_type, struct Counts s_cou
* - r_counts (OUT): Struct where is indicated how many elements receives this process from other processes in the previous group.
*
*/
void
prepare_redistribution
(
int
qty
,
int
mal_type
,
int
myId
,
int
numP
,
int
numO
,
int
is_children_group
,
int
is_intercomm
,
void
**
recv
,
struct
Counts
*
s_counts
,
struct
Counts
*
r_counts
)
{
void
prepare_redistribution
(
int
qty
,
int
mal_type
,
int
myId
,
int
numP
,
int
numO
,
int
is_children_group
,
int
is_intercomm
,
int
is_sync
,
void
**
recv
,
struct
Counts
*
s_counts
,
struct
Counts
*
r_counts
)
{
int
array_size
=
numO
;
int
offset_ids
=
0
;
size_t
datasize
;
...
...
@@ -411,8 +411,8 @@ void prepare_redistribution(int qty, int mal_type, int myId, int numP, int numO,
MPI_Abort
(
MPI_COMM_WORLD
,
-
1
);
}
if
(
is_intercomm
)
{
//
offset_ids = numP; //FIXME Modify only if active?
if
(
is_intercomm
&&
is_sync
)
{
offset_ids
=
numP
;
//FIXME Modify only if active?
}
else
{
array_size
=
numP
>
numO
?
numP
:
numO
;
}
...
...
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