Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 015362fd authored by Guillaume Sylvand's avatar Guillaume Sylvand
Browse files

Add API to allow user defined progress indicator (default indicator is a percentage)

To use your own progress indicator,
- Define a function with prototype "void my_update_progress(int currentValue, int maximumValue)"
- Pass it to chameleon with "ierr=MORSE_Set_update_progress_callback(my_update_progress)"
- Activate progress indicator with MORSE_Enable(MORSE_PROGRESS)
parent 83f13018
No related branches found
No related tags found
No related merge requests found
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <limits.h>
/******************************************************************************* /*******************************************************************************
* *
...@@ -235,3 +236,40 @@ int MORSE_My_Mpi_Rank(void) ...@@ -235,3 +236,40 @@ int MORSE_My_Mpi_Rank(void)
return MORSE_SUCCESS; return MORSE_SUCCESS;
#endif #endif
} }
/*******************************************************************************
* Display a progress percentage in stderr
**/
void update_progress(int currentValue, int maximumValue) {
div_t res ;
static int progress = -1; /* varie de 0 a 100 au cours du calcul concerne */
if (maximumValue==0)
res.quot=100 ;
else {
if (currentValue<INT_MAX/100)
res=div(currentValue*100, maximumValue) ;
/* Calcule le quotient de la division */
else
res.quot=(int)( (long long) currentValue*100/maximumValue) ;
}
// Print the percentage
if (res.quot > progress)
fprintf(stderr, "%3d%%\b\b\b\b", res.quot) ;
progress=res.quot ;
if (currentValue>=maximumValue) {
progress=-1 ;
}
}
// A function to display the progress indicator.
// By default it is update_progress()
// The user can change it with MORSE_Set_update_progress_callback()
void (*update_progress_callback)(int, int) = update_progress;
int MORSE_Set_update_progress_callback(void (*p)(int, int)) {
update_progress_callback=p ;
return MORSE_SUCCESS;
}
...@@ -105,6 +105,7 @@ int MORSE_Enable (MORSE_enum option); ...@@ -105,6 +105,7 @@ int MORSE_Enable (MORSE_enum option);
int MORSE_Disable (MORSE_enum option); int MORSE_Disable (MORSE_enum option);
int MORSE_Set (MORSE_enum param, int value); int MORSE_Set (MORSE_enum param, int value);
int MORSE_Get (MORSE_enum param, int *value); int MORSE_Get (MORSE_enum param, int *value);
int MORSE_Set_update_progress_callback(void (*p)(int, int)) ;
/* Sequences */ /* Sequences */
int MORSE_Sequence_Create (MORSE_sequence_t **sequence); int MORSE_Sequence_Create (MORSE_sequence_t **sequence);
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
* *
**/ **/
#include <stdlib.h> #include <stdlib.h>
#include <limits.h>
#include "runtime/starpu/include/morse_starpu.h" #include "runtime/starpu/include/morse_starpu.h"
/******************************************************************************* /*******************************************************************************
...@@ -46,28 +45,8 @@ int RUNTIME_sequence_destroy( MORSE_context_t *morse, MORSE_sequence_t *sequence ...@@ -46,28 +45,8 @@ int RUNTIME_sequence_destroy( MORSE_context_t *morse, MORSE_sequence_t *sequence
return MORSE_SUCCESS; return MORSE_SUCCESS;
} }
void update_progress(int currentValue, int maximumValue) { // Defined in control/auxilliary.c
div_t res ; extern void (*update_progress_callback)(int, int) ;
static int progress = -1; /* varie de 0 a 100 au cours du calcul concerne */
if (maximumValue==0)
res.quot=100 ;
else {
if (currentValue<INT_MAX/100)
res=div(currentValue*100, maximumValue) ;
/* Calcule le quotient de la division */
else
res.quot=(int)( (long long) currentValue*100/maximumValue) ;
}
// Print the percentage
if (res.quot > progress)
fprintf(stderr, "%3d%%\b\b\b\b", res.quot) ;
progress=res.quot ;
if (currentValue>=maximumValue) {
progress=-1 ;
}
}
// no progress indicator for algorithms faster than 'PROGRESS_MINIMUM_DURATION' seconds // no progress indicator for algorithms faster than 'PROGRESS_MINIMUM_DURATION' seconds
#define PROGRESS_MINIMUM_DURATION 10 #define PROGRESS_MINIMUM_DURATION 10
...@@ -85,16 +64,16 @@ int RUNTIME_progress( MORSE_context_t *morse) ...@@ -85,16 +64,16 @@ int RUNTIME_progress( MORSE_context_t *morse)
int max = starpu_task_nsubmitted(); int max = starpu_task_nsubmitted();
if (max==0) if (max==0)
return MORSE_SUCCESS; return MORSE_SUCCESS;
// update_progress(0, max); // update_progress_callback(0, max);
while ((tasksLeft = starpu_task_nsubmitted()) > 0) { while ((tasksLeft = starpu_task_nsubmitted()) > 0) {
current = max - tasksLeft; current = max - tasksLeft;
if (timer > PROGRESS_MINIMUM_DURATION) if (timer > PROGRESS_MINIMUM_DURATION)
update_progress(current, max); update_progress_callback(current, max);
sleep(1); sleep(1);
timer++; timer++;
} }
if (timer > PROGRESS_MINIMUM_DURATION) if (timer > PROGRESS_MINIMUM_DURATION)
update_progress(max, max); update_progress_callback(max, max);
return MORSE_SUCCESS; return MORSE_SUCCESS;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment