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
307a89eb
Commit
307a89eb
authored
Sep 28, 2023
by
iker_martin
Browse files
Added time recopilation to the code. Ready for executions.
parent
5ea0baf4
Changes
3
Show whitespace changes
Inline
Side-by-side
Main/ConjugateGradient.c
View file @
307a89eb
...
...
@@ -64,6 +64,7 @@ int n_check = 30;
int
dist_old
(
struct
Dist_data
*
dist_data
,
Compute_data
*
computeData
,
int
num_children
,
int
sm
,
int
ss
,
int
rm
,
int
rs
,
int
send_sync
);
void
dist_new
(
struct
Dist_data
*
dist_data
,
Compute_data
*
computeData
);
void
update_dist_data
(
struct
Dist_data
*
dist_data
);
void
print_global_results
();
//----------------------------------------------------------------------------------------------------
void
get_dist
(
int
total_r
,
int
id
,
int
numP
,
struct
Dist_data
*
dist_data
);
void
set_counts
(
int
id
,
int
numP
,
struct
Dist_data
data_dist
,
int
*
sendcounts
);
...
...
@@ -105,7 +106,6 @@ int main (int argc, char *argv[]) {
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
numP
);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
myId
);
dist_data
.
comm
=
MPI_COMM_WORLD
;
printf
(
"Nuevo set %d/%d
\n
"
,
myId
,
numP
);
int
new_group
=
init_malleability
(
myId
,
numP
,
ROOT
,
dist_data
.
comm
,
argv
[
0
],
nodelist
,
num_cpus
,
num_nodes
);
update_dist_data
(
&
dist_data
);
...
...
@@ -113,17 +113,22 @@ int main (int argc, char *argv[]) {
if
(
!
new_group
)
{
//First set of processes
init_app
(
&
computeData
,
&
dist_data
,
argv
);
dist_old
(
&
dist_data
,
&
computeData
,
num_children
,
sm
,
ss
,
rm
,
rs
,
send_sync
);
MPI_Barrier
(
MPI_COMM_WORLD
);
set_global_time
(
MPI_Wtime
());
}
else
{
dist_new
(
&
dist_data
,
&
computeData
);
}
// if(computeData.iter==0)
terminate
=
compute
(
&
computeData
,
&
dist_data
,
sm
);
if
(
myId
==
ROOT
&&
terminate
)
{
if
(
terminate
)
{
MPI_Barrier
(
dist_data
.
comm
);
if
(
dist_data
.
myId
==
ROOT
)
{
print_global_results
();
printf
(
"End(%d) --> (%d,%20.10e)
\n
"
,
computeData
.
n
,
computeData
.
iter
,
computeData
.
tol
);
}
}
// End of CG
free_malleability
();
...
...
@@ -425,7 +430,6 @@ int compute(Compute_data *computeData, struct Dist_data *dist_data, int sm) {
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
// if(computeData->iter==3) dumb(computeData,dist_data);
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)
computeData
->
tol
=
sqrt
(
computeData
->
beta
);
// tol = sqrt(beta) = norm (res)
...
...
@@ -732,6 +736,20 @@ void getIds_intercomm(struct Dist_data dist_data, int numP_other, int **idS) {
(
*
idS
)[
1
]
=
idE
;
}
void
print_global_results
()
{
size_t
i
;
double
sp_time
,
sy_time
,
asy_time
,
mall_time
,
global_time
;
retrieve_results
(
&
sp_time
,
&
sy_time
,
&
asy_time
,
&
mall_time
,
&
global_time
);
global_time
=
MPI_Wtime
()
-
global_time
;
printf
(
"T_spawn: %lf"
,
sp_time
);
printf
(
"
\n
T_SR: %lf"
,
sy_time
);
printf
(
"
\n
T_AR: %lf"
,
asy_time
);
printf
(
"
\n
T_Malleability: %lf"
,
mall_time
);
printf
(
"
\n
T_total: %lf
\n
"
,
global_time
);
}
/*
double starttime, endtime, total, res;
...
...
malleability/malleabilityManager.c
View file @
307a89eb
...
...
@@ -32,6 +32,9 @@ void* thread_async_work();
void
print_comms_state
();
void
malleability_comms_update
(
MPI_Comm
comm
);
void
comm_results
(
int
root
,
int
compute
);
//FIXME Borrar
void
def_malleability_results
(
MPI_Datatype
*
new_type
);
//FIXME BORRAR
typedef
struct
{
int
spawn_method
;
int
spawn_dist
;
...
...
@@ -40,6 +43,12 @@ typedef struct {
int
red_strategies
;
int
grp
;
double
exec_start
;
double
spawn_start
,
spawn_time
;
double
sync_time
,
sync_end
;
double
async_time
,
async_end
;
double
malleability_end
,
malleability_time
;
}
malleability_config_t
;
typedef
struct
{
//FIXME numC_spawned no se esta usando
...
...
@@ -181,7 +190,7 @@ int malleability_checkpoint() {
break
;
case
MALL_NOT_STARTED
:
// Comprobar si se tiene que realizar un redimensionado
//
mall_conf->
results->
malleability_time
[mall_conf->grp]
= MPI_Wtime();
mall_conf
->
malleability_time
=
MPI_Wtime
();
state
=
spawn_step
();
...
...
@@ -194,8 +203,7 @@ int malleability_checkpoint() {
case
MALL_SPAWN_SINGLE_PENDING
:
state
=
check_spawn_state
(
&
(
mall
->
intercomm
),
mall
->
comm
,
&
end_real_time
);
if
(
state
==
MALL_SPAWN_COMPLETED
||
state
==
MALL_SPAWN_ADAPTED
)
{
//mall_conf->results->spawn_time[mall_conf->grp] = MPI_Wtime() - mall_conf->results->spawn_start;
//mall_conf->results->spawn_real_time[mall_conf->grp] = end_real_time - mall_conf->results->spawn_start;
mall_conf
->
spawn_time
=
MPI_Wtime
()
-
mall_conf
->
spawn_start
;
malleability_checkpoint
();
}
...
...
@@ -219,12 +227,12 @@ int malleability_checkpoint() {
break
;
case
MALL_SPAWN_ADAPT_PENDING
:
//
mall_conf->
results->
spawn_start = MPI_Wtime();
mall_conf
->
spawn_start
=
MPI_Wtime
();
unset_spawn_postpone_flag
(
state
);
state
=
check_spawn_state
(
&
(
mall
->
intercomm
),
mall
->
comm
,
&
end_real_time
);
if
(
!
malleability_spawn_contains_strat
(
mall_conf
->
spawn_strategies
,
MALL_SPAWN_PTHREAD
,
NULL
))
{
//
mall_conf->
results->
spawn_time
[mall_conf->grp]
= MPI_Wtime() - mall_conf->
results->
spawn_start;
mall_conf
->
spawn_time
=
MPI_Wtime
()
-
mall_conf
->
spawn_start
;
malleability_checkpoint
();
}
break
;
...
...
@@ -235,7 +243,7 @@ int malleability_checkpoint() {
break
;
case
MALL_DIST_COMPLETED
:
//TODO No es esto muy feo?
//
mall_conf->
results->
malleability_end = MPI_Wtime();
mall_conf
->
malleability_end
=
MPI_Wtime
();
state
=
MALL_COMPLETED
;
break
;
}
...
...
@@ -508,13 +516,13 @@ void Children_init() {
recv_data
(
numP_parents
,
dist_a_data
,
MALLEABILITY_USE_ASYNCHRONOUS
);
}
//
mall_conf->
results->
async_end= MPI_Wtime(); // Obtener timestamp de cuando termina comm asincrona
mall_conf
->
async_end
=
MPI_Wtime
();
// Obtener timestamp de cuando termina comm asincrona
}
comm_data_info
(
rep_s_data
,
dist_s_data
,
MALLEABILITY_CHILDREN
,
mall
->
myId
,
root_parents
,
mall
->
intercomm
);
if
(
dist_s_data
->
entries
||
rep_s_data
->
entries
)
{
// Recibir datos sincronos
recv_data
(
numP_parents
,
dist_s_data
,
MALLEABILITY_USE_SYNCHRONOUS
);
//
mall_conf->
results->
sync_end = MPI_Wtime(); // Obtener timestamp de cuando termina comm sincrona
mall_conf
->
sync_end
=
MPI_Wtime
();
// Obtener timestamp de cuando termina comm sincrona
// TODO Crear funcion especifica y anyadir para Asinc
// TODO Tener en cuenta el tipo y qty
...
...
@@ -533,8 +541,9 @@ void Children_init() {
MPI_Bcast
(
rep_s_data
->
arrays
[
i
],
rep_s_data
->
qty
[
i
],
datatype
,
root_parents
,
mall
->
intercomm
);
}
}
//
mall_conf->
results->
malleability_end = MPI_Wtime(); // Obtener timestamp de cuando termina maleabilidad
mall_conf
->
malleability_end
=
MPI_Wtime
();
// Obtener timestamp de cuando termina maleabilidad
comm_results
(
root_parents
,
1
);
if
(
!
is_intercomm
)
{
malleability_comms_update
(
mall
->
intercomm
);
}
...
...
@@ -553,12 +562,12 @@ void Children_init() {
* Si se pide en segundo plano devuelve el estado actual.
*/
int
spawn_step
(){
//
mall_conf->
results->
spawn_start = MPI_Wtime();
mall_conf
->
spawn_start
=
MPI_Wtime
();
state
=
init_spawn
(
mall
->
name_exec
,
mall
->
num_cpus
,
mall
->
num_nodes
,
mall
->
nodelist
,
mall
->
myId
,
mall
->
numP
,
mall
->
numC
,
mall
->
root
,
mall_conf
->
spawn_dist
,
mall_conf
->
spawn_method
,
mall_conf
->
spawn_strategies
,
mall
->
thread_comm
,
&
(
mall
->
intercomm
));
if
(
!
malleability_spawn_contains_strat
(
mall_conf
->
spawn_strategies
,
MALL_SPAWN_PTHREAD
,
NULL
))
{
//
mall_conf->
results->
spawn_time
[mall_conf->grp]
= MPI_Wtime() - mall_conf->
results->
spawn_start;
mall_conf
->
spawn_time
=
MPI_Wtime
()
-
mall_conf
->
spawn_start
;
}
return
state
;
}
...
...
@@ -603,7 +612,7 @@ int start_redistribution() {
comm_data_info
(
rep_a_data
,
dist_a_data
,
MALLEABILITY_NOT_CHILDREN
,
mall
->
myId
,
mall
->
root
,
mall
->
intercomm
);
if
(
dist_a_data
->
entries
||
rep_a_data
->
entries
)
{
// Enviar datos asincronos
//FIXME No se envian los datos replicados (rep_a_data)
//
mall_conf->
results->
async_time
[mall_conf->grp]
= MPI_Wtime();
mall_conf
->
async_time
=
MPI_Wtime
();
if
(
malleability_red_contains_strat
(
mall_conf
->
red_strategies
,
MALL_RED_THREAD
,
NULL
))
{
return
thread_creation
();
}
else
{
...
...
@@ -671,7 +680,7 @@ int check_redistribution() {
}
MPI_Comm_test_inter
(
mall
->
intercomm
,
&
is_intercomm
);
//
if(!is_intercomm) mall_conf->
results->
async_end = MPI_Wtime(); // Merge method only
if
(
!
is_intercomm
)
mall_conf
->
async_end
=
MPI_Wtime
();
// Merge method only
return
end_redistribution
();
}
...
...
@@ -697,9 +706,9 @@ int end_redistribution() {
comm_data_info
(
rep_s_data
,
dist_s_data
,
MALLEABILITY_NOT_CHILDREN
,
mall
->
myId
,
mall
->
root
,
mall
->
intercomm
);
if
(
dist_s_data
->
entries
||
rep_s_data
->
entries
)
{
// Enviar datos sincronos
//
mall_conf->
results->sync_time[mall_conf->grp]
= MPI_Wtime();
mall_conf
->
sync_time
=
MPI_Wtime
();
send_data
(
mall
->
numC
,
dist_s_data
,
MALLEABILITY_USE_SYNCHRONOUS
);
//
if(!is_intercomm) mall_conf->
results->
sync_end = MPI_Wtime(); // Merge method only
if
(
!
is_intercomm
)
mall_conf
->
sync_end
=
MPI_Wtime
();
// Merge method only
// TODO Crear funcion especifica y anyadir para Asinc
// TODO Tener en cuenta el tipo
...
...
@@ -719,6 +728,9 @@ int end_redistribution() {
}
}
int
compute
=
mall_conf
->
spawn_method
==
MALL_SPAWN_MERGE
?
1
:
0
;
comm_results
(
rootBcast
,
compute
);
local_state
=
MALL_DIST_COMPLETED
;
if
(
!
is_intercomm
)
{
// Merge Spawn
if
(
mall
->
numP
<
mall
->
numC
)
{
// Expand
...
...
@@ -759,10 +771,7 @@ int shrink_redistribution() {
MPI_Comm_free
(
&
(
mall
->
intercomm
));
//mall_conf->results->spawn_time[mall_conf->grp] += MPI_Wtime() - time_extra;
if
(
malleability_spawn_contains_strat
(
mall_conf
->
spawn_strategies
,
MALL_SPAWN_PTHREAD
,
NULL
))
{
// mall_conf->results->spawn_real_time[mall_conf->grp] += MPI_Wtime() - time_extra;
}
mall_conf
->
spawn_time
+=
MPI_Wtime
()
-
time_extra
;
return
MALL_DIST_COMPLETED
;
}
else
{
return
MALL_ZOMBIE
;
...
...
@@ -855,7 +864,7 @@ int thread_check() {
return
-
2
;
}
MPI_Comm_test_inter
(
mall
->
intercomm
,
&
is_intercomm
);
//
if(!is_intercomm) mall_conf->
results->
async_end = MPI_Wtime(); // Merge method only
if
(
!
is_intercomm
)
mall_conf
->
async_end
=
MPI_Wtime
();
// Merge method only
return
end_redistribution
();
}
...
...
@@ -907,3 +916,55 @@ void malleability_comms_update(MPI_Comm comm) {
MPI_Comm_set_name
(
mall
->
comm
,
"MPI_COMM_MALL"
);
MPI_Comm_set_name
(
mall
->
user_comm
,
"MPI_COMM_MALL_USER"
);
}
void
comm_results
(
int
root
,
int
compute
)
{
MPI_Datatype
new_type
;
def_malleability_results
(
&
new_type
);
MPI_Bcast
(
mall_conf
,
1
,
new_type
,
root
,
mall
->
intercomm
);
if
(
compute
)
{
mall_conf
->
sync_time
=
mall_conf
->
sync_end
-
mall_conf
->
sync_time
;
if
(
dist_a_data
->
entries
)
mall_conf
->
async_time
=
mall_conf
->
async_end
-
mall_conf
->
async_time
;
mall_conf
->
malleability_time
=
mall_conf
->
malleability_end
-
mall_conf
->
malleability_time
;
}
MPI_Type_free
(
&
new_type
);
}
void
set_global_time
(
double
ex_start
)
{
mall_conf
->
exec_start
=
ex_start
;
}
void
retrieve_results
(
double
*
sp_time
,
double
*
sy_time
,
double
*
asy_time
,
double
*
mall_time
,
double
*
ex_start
)
{
*
sp_time
=
mall_conf
->
spawn_time
;
*
sy_time
=
mall_conf
->
sync_time
;
*
asy_time
=
mall_conf
->
async_time
;
*
mall_time
=
mall_conf
->
malleability_time
;
*
ex_start
=
mall_conf
->
exec_start
;
}
void
def_malleability_results
(
MPI_Datatype
*
new_type
)
{
int
i
,
counts
=
5
;
int
blocklengths
[
counts
];
MPI_Aint
displs
[
counts
],
dir
;
MPI_Datatype
types
[
counts
];
blocklengths
[
0
]
=
blocklengths
[
1
]
=
blocklengths
[
2
]
=
blocklengths
[
3
]
=
blocklengths
[
4
]
=
1
;
types
[
0
]
=
types
[
1
]
=
types
[
2
]
=
types
[
3
]
=
types
[
4
]
=
MPI_DOUBLE
;
// Rellenar vector displs
MPI_Get_address
(
mall_conf
,
&
dir
);
// Obtener direccion base
MPI_Get_address
(
&
(
mall_conf
->
spawn_time
),
&
displs
[
0
]);
MPI_Get_address
(
&
(
mall_conf
->
sync_time
),
&
displs
[
1
]);
MPI_Get_address
(
&
(
mall_conf
->
async_time
),
&
displs
[
2
]);
MPI_Get_address
(
&
(
mall_conf
->
malleability_time
),
&
displs
[
3
]);
MPI_Get_address
(
&
(
mall_conf
->
exec_start
),
&
displs
[
4
]);
for
(
i
=
0
;
i
<
counts
;
i
++
)
displs
[
i
]
-=
dir
;
MPI_Type_create_struct
(
counts
,
blocklengths
,
displs
,
types
,
new_type
);
MPI_Type_commit
(
new_type
);
}
malleability/malleabilityManager.h
View file @
307a89eb
...
...
@@ -22,4 +22,8 @@ void malleability_add_data(void *data, size_t total_qty, int type, int dependenc
void
malleability_modify_data
(
void
*
data
,
size_t
index
,
size_t
total_qty
,
int
type
,
int
dependency
,
int
is_replicated
,
int
is_constant
);
void
malleability_get_entries
(
size_t
*
entries
,
int
is_replicated
,
int
is_constant
);
void
malleability_get_data
(
void
**
data
,
size_t
index
,
int
is_replicated
,
int
is_constant
);
void
retrieve_results
(
double
*
sp_time
,
double
*
sy_time
,
double
*
asy_time
,
double
*
mall_time
,
double
*
ex_start
);
//FIXME BORRAR
void
set_global_time
(
double
ex_start
);
//FIXME BORRAR
#endif
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