Commit d45d1636 authored by Mathieu Faverge's avatar Mathieu Faverge

Apply cleanup to the starpu implementation of the API

parent 1e7da445
......@@ -107,7 +107,7 @@ void morse_fatal_error(const char *func_name, const char *msg_text)
**/
int morse_rank(MORSE_context_t *morse)
{
return RUNTIME_rank( morse );
return RUNTIME_thread_rank( morse );
}
/*******************************************************************************
......@@ -233,31 +233,36 @@ 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 */
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) ;
}
if (maximumValue == 0) {
res.quot = 100;
}
else {
if (currentValue < (INT_MAX / 100) ) {
res = div(currentValue*100, maximumValue);
}
else {
/* Calcule le quotient de la division */
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 ;
// Print the percentage
if (res.quot > progress) {
fprintf(stderr, "%3d%%\b\b\b\b", res.quot);
}
progress = res.quot;
if (currentValue>=maximumValue) {
progress=-1 ;
}
if (currentValue >= maximumValue) {
progress = -1;
}
}
// A function to display the progress indicator.
......
......@@ -111,7 +111,7 @@ int MORSE_InitPar(int ncpus, int ncudas, int nthreads_per_worker)
}
# endif
#endif
RUNTIME_init_scheduler( morse, ncpus, ncudas, nthreads_per_worker );
RUNTIME_init( morse, ncpus, ncudas, nthreads_per_worker );
return MORSE_SUCCESS;
}
......@@ -138,7 +138,7 @@ int MORSE_Finalize(void)
# if !defined(CHAMELEON_SIMULATION)
RUNTIME_barrier(morse);
# endif
RUNTIME_finalize_scheduler( morse );
RUNTIME_finalize( morse );
#if defined(CHAMELEON_USE_MPI)
if (!morse->mpi_outer_init)
......@@ -250,14 +250,19 @@ int MORSE_Distributed_stop(void)
*
******************************************************************************
*
* @return
* \retval MORSE_SUCCESS successful exit
* @retval The size of the distributed computation
* @retval -1 if context not initialized
*
*****************************************************************************/
int MORSE_Comm_size( int *size )
int MORSE_Comm_size()
{
RUNTIME_comm_size (size);
return MORSE_SUCCESS;
MORSE_context_t *morse = morse_context_self();
if (morse == NULL) {
morse_error("MORSE_Comm_size()", "MORSE not initialized");
return -1;
}
return RUNTIME_comm_size( morse );
}
/** ***************************************************************************
......@@ -268,14 +273,19 @@ int MORSE_Comm_size( int *size )
*
******************************************************************************
*
* @return
* \retval MORSE_SUCCESS successful exit
* @retval The rank of the distributed computation
* @retval -1 if context not initialized
*
*****************************************************************************/
int MORSE_Comm_rank( int *rank )
int MORSE_Comm_rank()
{
RUNTIME_comm_rank (rank);
return MORSE_SUCCESS;
MORSE_context_t *morse = morse_context_self();
if (morse == NULL) {
morse_error("MORSE_Comm_rank()", "MORSE not initialized");
return -1;
}
return RUNTIME_comm_rank( morse );
}
/** ***************************************************************************
......@@ -293,5 +303,11 @@ int MORSE_Comm_rank( int *rank )
*****************************************************************************/
int MORSE_GetThreadNbr( )
{
return RUNTIME_get_thread_nbr();
MORSE_context_t *morse = morse_context_self();
if (morse == NULL) {
morse_error("MORSE_GetThreadNbr()", "MORSE not initialized");
return -1;
}
return RUNTIME_thread_size( morse );
}
......@@ -110,7 +110,17 @@ MORSE_desc_t morse_desc_init_user(MORSE_enum dtyp, int mb, int nb, int bsiz,
int (*get_blkldd) ( const MORSE_desc_t*, int ),
int (*get_rankof) ( const MORSE_desc_t*, int, int ))
{
MORSE_context_t *morse;
MORSE_desc_t desc;
memset( &desc, 0, sizeof(MORSE_desc_t) );
morse = morse_context_self();
if (morse == NULL) {
morse_error("MORSE_Desc_Create", "MORSE not initialized");
return desc;
}
// If one of the function get_* is NULL, we switch back to the default, like in morse_desc_init()
desc.get_blkaddr = get_blkaddr ? get_blkaddr : morse_getaddr_ccrb;
desc.get_blkldd = get_blkldd ? get_blkldd : morse_getblkldd_ccrb;
......@@ -144,7 +154,7 @@ MORSE_desc_t morse_desc_init_user(MORSE_enum dtyp, int mb, int nb, int bsiz,
desc.register_mat = 1;
desc.ooc = 0;
RUNTIME_comm_rank( &(desc.myrank) );
desc.myrank = RUNTIME_comm_rank( morse );
// Grid size
desc.p = p;
......@@ -185,8 +195,6 @@ MORSE_desc_t morse_desc_init_user(MORSE_enum dtyp, int mb, int nb, int bsiz,
desc.A12 = (size_t)( desc.llm%mb)*(size_t)(desc.lln - desc.lln%nb) + desc.A21;
desc.A22 = (size_t)(desc.llm - desc.llm%mb)*(size_t)( desc.lln%nb) + desc.A12;
RUNTIME_desc_init( &desc );
return desc;
}
......@@ -241,7 +249,8 @@ MORSE_desc_t* morse_desc_submatrix(MORSE_desc_t *descA, int i, int j, int m, int
descB->mt = (m == 0) ? 0 : (descB->i+m-1)/mb - descB->i/mb + 1;
descB->nt = (n == 0) ? 0 : (descB->j+n-1)/nb - descB->j/nb + 1;
RUNTIME_desc_submatrix( descB );
// Increase the number of occurences to avoid multiple free of runtime specific data structures.
descB->occurences++;
return descB;
}
......@@ -301,7 +310,7 @@ int morse_desc_mat_alloc( MORSE_desc_t *desc )
size_t size = (size_t)(desc->llm) * (size_t)(desc->lln)
* (size_t)MORSE_Element_Size(desc->dtyp);
if ((desc->mat = RUNTIME_mat_alloc(size)) == NULL) {
if ((desc->mat = RUNTIME_malloc(size)) == NULL) {
morse_error("morse_desc_mat_alloc", "malloc() failed");
return MORSE_ERR_OUT_OF_RESOURCES;
}
......@@ -327,7 +336,7 @@ int morse_desc_mat_free( MORSE_desc_t *desc )
size_t size = (size_t)(desc->llm) * (size_t)(desc->lln)
* (size_t)MORSE_Element_Size(desc->dtyp);
RUNTIME_mat_free(desc->mat, size);
RUNTIME_free(desc->mat, size);
desc->mat = NULL;
}
return MORSE_SUCCESS;
......@@ -423,7 +432,7 @@ int MORSE_Desc_Create(MORSE_desc_t **descptr, void *mat, MORSE_enum dtyp, int mb
size_t size = (size_t)(desc->llm) * (size_t)(desc->lln)
* (size_t)MORSE_Element_Size(desc->dtyp);
if ((desc->mat = RUNTIME_mat_alloc(size)) == NULL) {
if ((desc->mat = RUNTIME_malloc(size)) == NULL) {
morse_error("MORSE_Desc_Create", "malloc() failed");
return MORSE_ERR_OUT_OF_RESOURCES;
}
......@@ -843,6 +852,6 @@ int MORSE_Desc_Getoncpu(MORSE_desc_t *desc) {
*
*****************************************************************************/
void MORSE_user_tag_size(int user_tag_width, int user_tag_sep) {
RUNTIME_user_tag_size(user_tag_width, user_tag_sep);
RUNTIME_comm_set_tag_sizes( user_tag_width, user_tag_sep );
return;
}
......@@ -155,6 +155,15 @@ RUNTIME_resume( MORSE_context_t *ctxt );
void
RUNTIME_barrier( MORSE_context_t *ctxt );
/**
* @brief Show the progress of the computations when enabled.
*
* @param[in] ctxt
* The Chameleon context for which the context needs to be printed.
*/
void
RUNTIME_progress( MORSE_context_t *ctxt );
/**
* @brief Get the rank of the current worker for the runtime.
*
......@@ -405,14 +414,21 @@ RUNTIME_desc_getoncpu( const MORSE_desc_t *desc );
* This function is a asynchronous call that submit the data movement from
* remote memory to the main memory. This call must be completed by a call to
* RUNTIME_sequence_wait() to ensure that all data have been moved.
* Users should avoid to call this function as it sequentially moves back the
* data from outside the main memory to main memory, and should prefer
* RUNTIME_desc_getoncpu_async().
*
* @param[in] desc
* The descriptor to release.
*
* @param[in] sequence
* The sequence to which submit the data movements
*
* @retval MORSE_SUCCESS on success
*/
int
RUNTIME_desc_getoncpu_async( const MORSE_desc_t *desc );
RUNTIME_desc_getoncpu_async( const MORSE_desc_t *desc,
MORSE_sequence_t *sequence );
/**
* @brief Get the pointer to the data or the runtime handler associated to the
......
......@@ -84,8 +84,8 @@ int MORSE_Pause (void);
int MORSE_Resume (void);
int MORSE_Distributed_start (void);
int MORSE_Distributed_stop (void);
int MORSE_Comm_size (int *size);
int MORSE_Comm_rank (int *rank);
int MORSE_Comm_size (void);
int MORSE_Comm_rank (void);
int MORSE_Lapack_to_Tile (void *Af77, int LDA, MORSE_desc_t *A);
int MORSE_Tile_to_Lapack (MORSE_desc_t *A, void *Af77, int LDA);
int MORSE_Distributed_start (void);
......
......@@ -56,8 +56,8 @@ int RUNTIME_desc_iscached(const MORSE_desc_t *A, int Am, int An)
#endif
#endif
void MORSE_TASK_flush_data(const MORSE_option_t *options,
const MORSE_desc_t *A, int Am, int An)
void MORSE_TASK_flush_data( const MORSE_option_t *options,
const MORSE_desc_t *A, int Am, int An )
{
(void)options;
......
......@@ -28,7 +28,8 @@
/*******************************************************************************
* Create a sequence
**/
int RUNTIME_sequence_create( MORSE_context_t *morse, MORSE_sequence_t *sequence )
int RUNTIME_sequence_create( MORSE_context_t *morse,
MORSE_sequence_t *sequence )
{
(void)morse;
(void)sequence;
......@@ -38,60 +39,27 @@ int RUNTIME_sequence_create( MORSE_context_t *morse, MORSE_sequence_t *sequence
/*******************************************************************************
* Destroy a sequence
**/
int RUNTIME_sequence_destroy( MORSE_context_t *morse, MORSE_sequence_t *sequence )
int RUNTIME_sequence_destroy( MORSE_context_t *morse,
MORSE_sequence_t *sequence )
{
(void)morse;
(void)sequence;
return MORSE_SUCCESS;
}
// 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
/*******************************************************************************
* Display a progress information when executing the tasks
**/
int RUNTIME_progress( MORSE_context_t *morse )
{
int tasksLeft, current, timer = 0;
int max;
#if defined(CHAMELEON_USE_MPI)
if ( morse->my_mpi_rank != 0 )
return MORSE_SUCCESS;
#endif
max = starpu_task_nsubmitted();
if ( max == 0 )
return MORSE_SUCCESS;
// update_progress_callback(0, max);
while ((tasksLeft = starpu_task_nsubmitted()) > 0) {
current = max - tasksLeft;
if (timer > PROGRESS_MINIMUM_DURATION)
update_progress_callback(current, max);
sleep(1);
timer++;
}
if (timer > PROGRESS_MINIMUM_DURATION)
update_progress_callback(max, max);
(void)morse;
return MORSE_SUCCESS;
}
/*******************************************************************************
* Wait for the completion of a sequence
**/
int RUNTIME_sequence_wait( MORSE_context_t *morse, MORSE_sequence_t *sequence )
int RUNTIME_sequence_wait( MORSE_context_t *morse,
MORSE_sequence_t *sequence )
{
(void)morse;
(void)sequence;
if (morse->progress_enabled)
if (morse->progress_enabled) {
RUNTIME_progress(morse);
}
starpu_task_wait_for_all();
#if defined(CHAMELEON_USE_MPI)
starpu_mpi_barrier(MPI_COMM_WORLD);
......@@ -102,9 +70,12 @@ int RUNTIME_sequence_wait( MORSE_context_t *morse, MORSE_sequence_t *sequence )
/*******************************************************************************
* Terminate a sequence
**/
void RUNTIME_sequence_flush( void *schedopt, MORSE_sequence_t *sequence, MORSE_request_t *request, int status)
void RUNTIME_sequence_flush( MORSE_context_t *morse,
MORSE_sequence_t *sequence,
MORSE_request_t *request,
int status )
{
(void)schedopt;
(void)morse;
sequence->request = request;
sequence->status = status;
request->status = status;
......
......@@ -62,7 +62,6 @@ void RUNTIME_context_create( MORSE_context_t *morse )
/*******************************************************************************
* Clean the context
**/
void RUNTIME_context_destroy( MORSE_context_t *morse )
{
/* StarPU was already initialized by an external library */
......
......@@ -27,28 +27,13 @@
#include <stdlib.h>
#include "chameleon_starpu.h"
#if defined(CHAMELEON_SIMULATION)
# ifndef STARPU_SIMGRID
# error "Starpu was not built with simgrid support (--enable-simgrid). Can not run Chameleon with simulation support."
# endif
#else
# ifdef STARPU_SIMGRID
# warning "Starpu was built with simgrid support. Better build Chameleon with simulation support (-DCHAMELEON_SIMULATION=YES)."
# endif
#endif
/*******************************************************************************
* Thread rank.
**/
int RUNTIME_rank(MORSE_context_t *morse)
{
(void)morse;
return starpu_worker_get_id();
}
/*******************************************************************************
*
**/
int RUNTIME_init_scheduler( MORSE_context_t *morse, int ncpus, int ncudas, int nthreads_per_worker)
int RUNTIME_init( MORSE_context_t *morse,
int ncpus,
int ncudas,
int nthreads_per_worker )
{
starpu_conf_t *conf = (starpu_conf_t*)(morse->schedopt);
int hres = -1;
......@@ -137,18 +122,19 @@ int RUNTIME_init_scheduler( MORSE_context_t *morse, int ncpus, int ncudas, int n
/*******************************************************************************
*
*/
void RUNTIME_finalize_scheduler( MORSE_context_t *morse )
void RUNTIME_finalize( MORSE_context_t *morse )
{
(void)morse;
/* StarPU was already initialized by an external library */
if (morse->schedopt == NULL) {
if ( morse->schedopt == NULL ) {
return;
}
#if defined(CHAMELEON_USE_MPI)
starpu_mpi_shutdown();
#endif
#if defined(CHAMELEON_USE_CUDA) && !defined(CHAMELEON_SIMULATION)
starpu_cublas_shutdown();
#endif
......@@ -157,6 +143,27 @@ void RUNTIME_finalize_scheduler( MORSE_context_t *morse )
return;
}
/*******************************************************************************
* To suspend the processing of new tasks by workers
**/
void RUNTIME_pause( MORSE_context_t *morse )
{
(void)morse;
starpu_pause();
return;
}
/*******************************************************************************
* This is the symmetrical call to RUNTIME_pause,
* used to resume the workers polling for new tasks.
**/
void RUNTIME_resume( MORSE_context_t *morse )
{
(void)morse;
starpu_resume();
return;
}
/*******************************************************************************
* Busy-waiting barrier
**/
......@@ -169,84 +176,102 @@ void RUNTIME_barrier( MORSE_context_t *morse )
#endif
}
// 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
/*******************************************************************************
* Set iteration numbers for traces
* Display a progress information when executing the tasks
**/
void RUNTIME_iteration_push( MORSE_context_t *morse, unsigned long iteration )
void RUNTIME_progress( MORSE_context_t *morse )
{
(void)morse;
#if defined(HAVE_STARPU_ITERATION_PUSH)
starpu_iteration_push(iteration);
int tasksLeft, current, timer = 0;
int max;
#if defined(CHAMELEON_USE_MPI)
if ( morse->my_mpi_rank != 0 ) {
return;
}
#endif
}
void RUNTIME_iteration_pop( MORSE_context_t *morse )
{
max = starpu_task_nsubmitted();
if ( max == 0 ) {
return;
}
// update_progress_callback(0, max);
while ((tasksLeft = starpu_task_nsubmitted()) > 0) {
current = max - tasksLeft;
if (timer > PROGRESS_MINIMUM_DURATION) {
update_progress_callback(current, max);
}
sleep(1);
timer++;
}
if (timer > PROGRESS_MINIMUM_DURATION) {
update_progress_callback(max, max);
}
(void)morse;
#if defined(HAVE_STARPU_ITERATION_PUSH)
starpu_iteration_pop();
#endif
return;
}
/*******************************************************************************
* To suspend the processing of new tasks by workers
* Thread rank.
**/
void RUNTIME_pause( MORSE_context_t *morse )
int RUNTIME_thread_rank( MORSE_context_t *morse )
{
(void)morse;
starpu_pause();
return;
return starpu_worker_get_id();
}
/*******************************************************************************
* This is the symmetrical call to RUNTIME_pause,
* used to resume the workers polling for new tasks.
* Thread rank.
**/
void RUNTIME_resume( MORSE_context_t *morse )
int RUNTIME_thread_size( MORSE_context_t *morse )
{
(void)morse;
starpu_resume();
return;
return starpu_worker_get_count_by_type( STARPU_CPU_WORKER );
}
/*******************************************************************************
* This returns the rank of this process
* The process rank
**/
void RUNTIME_comm_rank( int *rank )
int RUNTIME_comm_rank( MORSE_context_t *morse )
{
int rank;
#if defined(CHAMELEON_USE_MPI)
# if defined(HAVE_STARPU_MPI_COMM_RANK)
starpu_mpi_comm_rank(MPI_COMM_WORLD, rank);
starpu_mpi_comm_rank( MPI_COMM_WORLD, &rank );
# else
MPI_Comm_rank(MPI_COMM_WORLD, rank);
MPI_Comm_rank( MPI_COMM_WORLD, &rank );
# endif
#else
*rank = 0;
rank = 0;
#endif
return;
(void)morse;
return rank;
}
/*******************************************************************************
* This returns the size of the distributed computation
**/
void RUNTIME_comm_size( int *size )
int RUNTIME_comm_size( MORSE_context_t *morse )
{
int size;
#if defined(CHAMELEON_USE_MPI)
# if defined(HAVE_STARPU_MPI_COMM_RANK)
starpu_mpi_comm_size(MPI_COMM_WORLD, size);
starpu_mpi_comm_size( MPI_COMM_WORLD, &size );
# else
MPI_Comm_size(MPI_COMM_WORLD, size);
MPI_Comm_size( MPI_COMM_WORLD, &size );
# endif
#else
*size = 1;
size = 1;
#endif
return;
}
/*******************************************************************************
* This returns the number of workers
**/
int RUNTIME_get_thread_nbr()
{
return starpu_worker_get_count_by_type( STARPU_CPU_WORKER );
(void)morse;
return size;
}
This diff is collapsed.
......@@ -40,6 +40,25 @@ double RUNTIME_get_time(){
return starpu_timing_now()*1e-6;
}
/*******************************************************************************
* Set iteration numbers for traces
**/
void RUNTIME_iteration_push( MORSE_context_t *morse, unsigned long iteration )
{
(void)morse;
#if defined(HAVE_STARPU_ITERATION_PUSH)
starpu_iteration_push(iteration);
#endif
}
void RUNTIME_iteration_pop( MORSE_context_t *morse )
{
(void)morse;
#if defined(HAVE_STARPU_ITERATION_PUSH)
starpu_iteration_pop();
#endif
}
void RUNTIME_start_profiling(){
#if defined(HAVE_STARPU_FXT_PROFILING)
starpu_fxt_start_profiling();
......
......@@ -59,6 +59,16 @@
#endif
#endif
#if defined(CHAMELEON_SIMULATION)
# if !defined(STARPU_SIMGRID)
# error "Starpu was not built with simgrid support (--enable-simgrid). Can not run Chameleon with simulation support."
# endif
#else
# if defined(STARPU_SIMGRID)
# warning "Starpu was built with simgrid support. Better build Chameleon with simulation support (-DCHAMELEON_SIMULATION=YES)."
# endif
#endif
#include "control/common.h"
#include "runtime_codelets.h"
#include "runtime_profiling.h"
......
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