Commit fdbfc2a9 authored by Pavel Kus's avatar Pavel Kus

autotuning state can be saved to file

parent 3aa7f40f
......@@ -159,8 +159,9 @@ module elpa_api
procedure(elpa_autotune_setup_i), deferred, public :: autotune_setup !< method to prepare the ELPA autotuning
procedure(elpa_autotune_step_i), deferred, public :: autotune_step !< method to do an autotuning step
procedure(elpa_autotune_set_best_i), deferred, public :: autotune_set_best !< method to set the best options
procedure(elpa_autotune_print_best_i), deferred, public :: autotune_print_best !< method to set the best options
procedure(elpa_autotune_print_state_i), deferred, public :: autotune_print_state !< method to set the best options
procedure(elpa_autotune_print_best_i), deferred, public :: autotune_print_best !< method to print the best options
procedure(elpa_autotune_print_state_i), deferred, public :: autotune_print_state !< method to print the state
procedure(elpa_autotune_save_state_i), deferred, public :: autotune_save_state !< method to save the state
#endif
!> \brief These method have to be public, in order to be overrideable in the extension types
......@@ -347,6 +348,23 @@ module elpa_api
class(elpa_autotune_t), intent(in), target :: tune_state
end subroutine
end interface
!> \brief abstract definition of the autotune save state method
!> Parameters
!> \details
!> \param self class(elpa_t): the ELPA object, which should be tuned
!> \param tune_state class(elpa_autotune_t): the autotuning object
!> \param file_name string, the name of the file where to save the state
!> Prints the best combination of ELPA options
abstract interface
subroutine elpa_autotune_save_state_i(self, tune_state, file_name)
import elpa_t, elpa_autotune_t
implicit none
class(elpa_t), intent(inout) :: self
class(elpa_autotune_t), intent(in), target :: tune_state
character(*), intent(in) :: file_name
end subroutine
end interface
#endif
!> \brief abstract definition of set method for integer values
......
......@@ -162,6 +162,7 @@ module elpa_impl
procedure, public :: autotune_set_best => elpa_autotune_set_best
procedure, public :: autotune_print_best => elpa_autotune_print_best
procedure, public :: autotune_print_state => elpa_autotune_print_state
procedure, public :: autotune_save_state => elpa_autotune_save_state
#endif
procedure, private :: construct_scalapack_descriptor => elpa_construct_scalapack_descriptor
end type elpa_impl_t
......@@ -1119,14 +1120,39 @@ module elpa_impl
print *, "This should not happen"
end select
!print *, "The following settings were found to be best:"
if (elpa_index_print_autotune_state_c(self%index, ts_impl%level, ts_impl%domain, ts_impl%min_loc, &
ts_impl%min_val, ts_impl%current, ts_impl%cardinality) /= 1) then
ts_impl%min_val, ts_impl%current, ts_impl%cardinality, c_null_char) /= 1) then
stop "This should not happen (in elpa_autotune_print_state())"
endif
end subroutine
!> \brief function to save the state of the autotuning
!> Parameters
!> \param self class(elpa_impl_t) the allocated ELPA object
!> \param tune_state class(elpa_autotune_t): the autotuning object
!> \param file_name string, the name of the file where to save the state
subroutine elpa_autotune_save_state(self, tune_state, file_name)
implicit none
class(elpa_impl_t), intent(inout) :: self
class(elpa_autotune_t), intent(in), target :: tune_state
type(elpa_autotune_impl_t), pointer :: ts_impl
character(*), intent(in) :: file_name
select type(tune_state)
type is (elpa_autotune_impl_t)
ts_impl => tune_state
class default
print *, "This should not happen"
end select
if (elpa_index_print_autotune_state_c(self%index, ts_impl%level, ts_impl%domain, ts_impl%min_loc, &
ts_impl%min_val, ts_impl%current, ts_impl%cardinality, file_name // c_null_char) /= 1) then
stop "This should not happen (in elpa_autotune_save_state())"
endif
end subroutine
!c> /*! \brief C interface for the implementation of the elpa_autotune_set_best method
!c> *
!c> * \param elpa_t handle: of the ELPA object which should be tuned
......
......@@ -1023,10 +1023,16 @@ int elpa_index_print_autotune_parameters(elpa_index_t index, int autotune_level,
}
int elpa_index_print_autotune_state(elpa_index_t index, int autotune_level, int autotune_domain, int min_loc,
double min_val, int current, int cardinality) {
double min_val, int current, int cardinality, char* file_name) {
char buff[100];
elpa_index_t index_best;
int min_loc_cpy = min_loc;
FILE *f;
if(file_name == "")
f = stderr;
else
f = fopen(file_name, "w");
// get index with the currently best parameters
index_best = elpa_index_instance();
......@@ -1044,35 +1050,38 @@ int elpa_index_print_autotune_state(elpa_index_t index, int autotune_level, int
}
int is_process_id_zero = elpa_index_get_int_value(index, "is_process_id_zero", NULL);
if (is_process_id_zero) {
fprintf(stderr, "\n*** AUTOTUNING STATE ***\n");
fprintf(stderr, "** This is the state of the autotuning object\n");
fprintf(stderr, "autotune level = %d\n", autotune_level);
fprintf(stderr, "autotune domain = %d\n", autotune_domain);
fprintf(stderr, "autotune cardinality = %d\n", cardinality);
fprintf(stderr, "current idx = %d\n", current);
fprintf(stderr, "best idx = %d\n", min_loc);
fprintf(stderr, "best time = %lf\n", min_val);
fprintf(f, "*** AUTOTUNING STATE ***\n");
fprintf(f, "** This is the state of the autotuning object\n");
fprintf(f, "autotune level = %d\n", autotune_level);
fprintf(f, "autotune domain = %d\n", autotune_domain);
fprintf(f, "autotune cardinality = %d\n", cardinality);
fprintf(f, "current idx = %d\n", current);
fprintf(f, "best idx = %d\n", min_loc);
fprintf(f, "best time = %lf\n", min_val);
if(min_loc_cpy > -1) {
fprintf(stderr, "** The following parameters are autotuned with so far the best values\n");
fprintf(f, "** The following parameters are autotuned with so far the best values\n");
for (int i = 0; i < nelements(int_entries); i++) {
if (is_tunable(index, i, autotune_level, autotune_domain)) {
elpa_index_print_int_parameter(index_best, buff, i);
fprintf(stderr, "%s", buff);
fprintf(f, "%s", buff);
}
}
fprintf(stderr, "** The following parameters would be autotuned on the selected autotuning level, but were overridden by the set() method\n");
fprintf(f, "** The following parameters would be autotuned on the selected autotuning level, but were overridden by the set() method\n");
for (int i = 0; i < nelements(int_entries); i++) {
if (is_tunable_but_overriden(index, i, autotune_level, autotune_domain)) {
elpa_index_print_int_parameter(index_best, buff, i);
fprintf(stderr, "%s", buff);
fprintf(f, "%s", buff);
}
}
}else{
fprintf(stderr, "** No output after first step\n");
fprintf(f, "** No output after first step\n");
}
fprintf(stderr, "*** END OF AUTOTUNING STATE ***\n");
fprintf(f, "*** END OF AUTOTUNING STATE ***\n");
}
elpa_index_free(index_best);
if(file_name != "")
fclose(f);
return 1;
}
......
......@@ -451,16 +451,17 @@ int elpa_index_print_all_parameters(elpa_index_t index);
/*
!f> interface
!f> function elpa_index_print_autotune_state_c(index, autotune_level, autotune_domain, min_loc, &
!f> min_val, current, cardinality) result(success) &
!f> min_val, current, cardinality, file_name) result(success) &
!f> bind(C, name="elpa_index_print_autotune_state")
!f> import c_int, c_ptr, c_char, c_double
!f> type(c_ptr), intent(in), value :: index
!f> integer(kind=c_int), intent(in), value :: autotune_level, autotune_domain, min_loc, current, cardinality
!f> real(kind=c_double), intent(in), value :: min_val
!f> character(kind=c_char), intent(in) :: file_name(*)
!f> integer(kind=c_int) :: success
!f> end function
!f> end interface
!f>
*/
int elpa_index_print_autotune_state(elpa_index_t index, int autotune_level, int autotune_domain, int min_loc,
double min_val, int current, int cardinality);
double min_val, int current, int cardinality, char* filename);
......@@ -230,6 +230,7 @@ program test
.true., .true., print_times=.false.)
a(:,:) = as(:,:)
call e%autotune_print_state(tune_state)
call e%autotune_save_state(tune_state, "saved_state_"//trim(iter_string)//".txt")
end do
! set and print the autotuned-settings
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment