diff --git a/runtime/starpu/control/runtime_context.c b/runtime/starpu/control/runtime_context.c index 1d031cee31468be44a04d8e2e30e3296f60b476a..e0369dfd9ef3b3ed42508390495681e6a75d92d9 100644 --- a/runtime/starpu/control/runtime_context.c +++ b/runtime/starpu/control/runtime_context.c @@ -26,6 +26,8 @@ #include <stdlib.h> #include "runtime/starpu/include/morse_starpu.h" +int _starpu_is_initialized(void); + /******************************************************************************* * Create new context **/ @@ -34,10 +36,16 @@ void RUNTIME_context_create( MORSE_context_t *morse ) starpu_conf_t *conf; morse->scheduler = CHAMELEON_SCHED_STARPU; - morse->schedopt = (void*) malloc (sizeof(struct starpu_conf)); - conf = morse->schedopt; - starpu_conf_init( conf ); + if (! _starpu_is_initialized() ) { + morse->schedopt = (void*) malloc (sizeof(struct starpu_conf)); + conf = morse->schedopt; + + starpu_conf_init( conf ); + } + else { + morse->schedopt = NULL; + } return; } @@ -48,7 +56,10 @@ void RUNTIME_context_create( MORSE_context_t *morse ) void RUNTIME_context_destroy( MORSE_context_t *morse ) { - free(morse->schedopt); + /* StarPU was already initialized by an external library */ + if (morse->schedopt) { + free(morse->schedopt); + } return; } diff --git a/runtime/starpu/control/runtime_control.c b/runtime/starpu/control/runtime_control.c index 88968fd8442c801150a2a5844306e265020e011c..32bf13b870f7461ea424352659c458742a2d4412 100644 --- a/runtime/starpu/control/runtime_control.c +++ b/runtime/starpu/control/runtime_control.c @@ -44,6 +44,11 @@ int RUNTIME_init_scheduler( MORSE_context_t *morse, int ncpus, int ncudas, int n starpu_conf_t *conf = (starpu_conf_t*)(morse->schedopt); int hres = -1; + /* StarPU was already initialized by an external library */ + if (conf == NULL) { + return 0; + } + conf->ncpus = ncpus; conf->ncuda = ncudas; conf->nopencl = 0; @@ -124,6 +129,12 @@ int RUNTIME_init_scheduler( MORSE_context_t *morse, int ncpus, int ncudas, int n void RUNTIME_finalize_scheduler( MORSE_context_t *morse ) { (void)morse; + + /* StarPU was already initialized by an external library */ + if (morse->schedopt == NULL) { + return 0; + } + #if defined(CHAMELEON_USE_MPI) starpu_mpi_shutdown(); #endif