Commit 015362fd authored by Guillaume Sylvand's avatar Guillaume Sylvand

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
......@@ -37,6 +37,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
/*******************************************************************************
*
......@@ -235,3 +236,40 @@ int MORSE_My_Mpi_Rank(void)
return MORSE_SUCCESS;
#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);
int MORSE_Disable (MORSE_enum option);
int MORSE_Set (MORSE_enum param, int value);
int MORSE_Get (MORSE_enum param, int *value);
int MORSE_Set_update_progress_callback(void (*p)(int, int)) ;
/* Sequences */
int MORSE_Sequence_Create (MORSE_sequence_t **sequence);
......
......@@ -23,7 +23,6 @@
*
**/
#include <stdlib.h>
#include <limits.h>
#include "runtime/starpu/include/morse_starpu.h"
/*******************************************************************************
......@@ -46,28 +45,8 @@ int RUNTIME_sequence_destroy( MORSE_context_t *morse, MORSE_sequence_t *sequence
return MORSE_SUCCESS;
}
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 ;
}
}
// Defined in control/auxilliary.c
extern void (*update_progress_callback)(int, int) ;
// no progress indicator for algorithms faster than 'PROGRESS_MINIMUM_DURATION' seconds
#define PROGRESS_MINIMUM_DURATION 10
......@@ -85,16 +64,16 @@ int RUNTIME_progress( MORSE_context_t *morse)
int max = starpu_task_nsubmitted();
if (max==0)
return MORSE_SUCCESS;
// update_progress(0, max);
// update_progress_callback(0, max);
while ((tasksLeft = starpu_task_nsubmitted()) > 0) {
current = max - tasksLeft;
if (timer > PROGRESS_MINIMUM_DURATION)
update_progress(current, max);
update_progress_callback(current, max);
sleep(1);
timer++;
}
if (timer > PROGRESS_MINIMUM_DURATION)
update_progress(max, max);
update_progress_callback(max, max);
return MORSE_SUCCESS;
}
......
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