From 7633d13cdc3b0e955ec97018b4be71628e6e034b Mon Sep 17 00:00:00 2001
From: Florent Pruvost <florent.pruvost@inria.fr>
Date: Wed, 7 Feb 2024 17:22:02 +0100
Subject: [PATCH] Add user mpi communicator feature.

---
 compute/pzgetrf.c                             |  2 +-
 control/control.c                             | 40 +++++++++++++++++--
 coreblas/compute/CMakeLists.txt               |  3 ++
 example/lapack_to_chameleon/CTestLists.cmake  | 15 +++++--
 example/lapack_to_chameleon/step6.c           | 20 +++++++++-
 example/lapack_to_chameleon/step6.h           |  8 ++--
 include/chameleon.h                           | 29 +++++++++-----
 include/chameleon/runtime.h                   |  5 ++-
 include/chameleon/runtime_struct.h            | 12 ++++++
 include/chameleon/struct.h                    | 12 ++++++
 runtime/openmp/control/runtime_descriptor.c   |  3 +-
 .../openmp/control/runtime_descriptor_ipiv.c  |  4 +-
 runtime/parsec/control/runtime_descriptor.c   |  4 +-
 .../parsec/control/runtime_descriptor_ipiv.c  |  4 +-
 runtime/quark/control/runtime_descriptor.c    |  3 +-
 .../quark/control/runtime_descriptor_ipiv.c   |  4 +-
 runtime/starpu/codelets/codelet_convert.c     |  1 +
 runtime/starpu/codelets/codelet_dlag2h.c      |  2 +
 runtime/starpu/codelets/codelet_dlag2z.c      |  1 +
 runtime/starpu/codelets/codelet_dzasum.c      |  1 +
 runtime/starpu/codelets/codelet_gemm.c        |  1 +
 runtime/starpu/codelets/codelet_gemmex.c      |  2 +
 runtime/starpu/codelets/codelet_hgemm.c       |  2 +
 .../starpu/codelets/codelet_ipiv_to_perm.c    |  1 +
 runtime/starpu/codelets/codelet_map.c         |  1 +
 runtime/starpu/codelets/codelet_zaxpy.c       |  1 +
 runtime/starpu/codelets/codelet_zbuild.c      |  1 +
 runtime/starpu/codelets/codelet_zcesca.c      |  1 +
 runtime/starpu/codelets/codelet_zgeadd.c      |  1 +
 runtime/starpu/codelets/codelet_zgelqt.c      |  1 +
 runtime/starpu/codelets/codelet_zgemm.c       |  2 +
 runtime/starpu/codelets/codelet_zgemv.c       |  1 +
 runtime/starpu/codelets/codelet_zgeqrt.c      |  1 +
 runtime/starpu/codelets/codelet_zgered.c      |  2 +
 runtime/starpu/codelets/codelet_zgerst.c      |  2 +
 runtime/starpu/codelets/codelet_zgersum.c     |  2 +-
 runtime/starpu/codelets/codelet_zgessm.c      |  1 +
 runtime/starpu/codelets/codelet_zgessq.c      |  1 +
 runtime/starpu/codelets/codelet_zgesum.c      |  1 +
 runtime/starpu/codelets/codelet_zgetrf.c      |  1 +
 .../starpu/codelets/codelet_zgetrf_blocked.c  |  3 ++
 .../starpu/codelets/codelet_zgetrf_incpiv.c   |  1 +
 .../starpu/codelets/codelet_zgetrf_nopiv.c    |  1 +
 .../codelets/codelet_zgetrf_nopiv_percol.c    |  2 +
 .../starpu/codelets/codelet_zgetrf_percol.c   |  2 +
 runtime/starpu/codelets/codelet_zgram.c       |  1 +
 runtime/starpu/codelets/codelet_zhe2ge.c      |  1 +
 runtime/starpu/codelets/codelet_zhemm.c       |  2 +
 runtime/starpu/codelets/codelet_zher2k.c      |  1 +
 runtime/starpu/codelets/codelet_zherfb.c      |  1 +
 runtime/starpu/codelets/codelet_zherk.c       |  1 +
 runtime/starpu/codelets/codelet_zlacpy.c      |  6 ++-
 runtime/starpu/codelets/codelet_zlag2c.c      |  2 +
 runtime/starpu/codelets/codelet_zlange.c      |  2 +
 runtime/starpu/codelets/codelet_zlanhe.c      |  1 +
 runtime/starpu/codelets/codelet_zlansy.c      |  1 +
 runtime/starpu/codelets/codelet_zlantr.c      |  1 +
 runtime/starpu/codelets/codelet_zlascal.c     |  1 +
 runtime/starpu/codelets/codelet_zlaset.c      |  1 +
 runtime/starpu/codelets/codelet_zlaset2.c     |  1 +
 runtime/starpu/codelets/codelet_zlaswp.c      |  2 +
 runtime/starpu/codelets/codelet_zlatro.c      |  1 +
 runtime/starpu/codelets/codelet_zlauum.c      |  1 +
 runtime/starpu/codelets/codelet_zplghe.c      |  1 +
 runtime/starpu/codelets/codelet_zplgsy.c      |  1 +
 runtime/starpu/codelets/codelet_zplrnt.c      |  1 +
 runtime/starpu/codelets/codelet_zplssq.c      |  2 +
 runtime/starpu/codelets/codelet_zpotrf.c      |  1 +
 runtime/starpu/codelets/codelet_zssssm.c      |  1 +
 runtime/starpu/codelets/codelet_zsymm.c       |  2 +
 runtime/starpu/codelets/codelet_zsyr2k.c      |  1 +
 runtime/starpu/codelets/codelet_zsyrk.c       |  1 +
 runtime/starpu/codelets/codelet_zsyssq.c      |  1 +
 .../starpu/codelets/codelet_zsytrf_nopiv.c    |  1 +
 runtime/starpu/codelets/codelet_ztplqt.c      |  1 +
 runtime/starpu/codelets/codelet_ztpmlqt.c     |  1 +
 runtime/starpu/codelets/codelet_ztpmqrt.c     |  1 +
 runtime/starpu/codelets/codelet_ztpqrt.c      |  1 +
 runtime/starpu/codelets/codelet_ztradd.c      |  1 +
 runtime/starpu/codelets/codelet_ztrasm.c      |  1 +
 runtime/starpu/codelets/codelet_ztrmm.c       |  1 +
 runtime/starpu/codelets/codelet_ztrsm.c       |  1 +
 runtime/starpu/codelets/codelet_ztrssq.c      |  1 +
 runtime/starpu/codelets/codelet_ztrtri.c      |  1 +
 .../starpu/codelets/codelet_ztsmlq_hetra1.c   |  1 +
 .../starpu/codelets/codelet_ztsmqr_hetra1.c   |  1 +
 runtime/starpu/codelets/codelet_ztstrf.c      |  1 +
 runtime/starpu/codelets/codelet_zunmlq.c      |  1 +
 runtime/starpu/codelets/codelet_zunmqr.c      |  1 +
 runtime/starpu/control/runtime_async.c        |  6 +--
 runtime/starpu/control/runtime_control.c      | 24 +++++------
 runtime/starpu/control/runtime_descriptor.c   |  8 ++--
 .../starpu/control/runtime_descriptor_ipiv.c  | 19 +++++----
 runtime/starpu/control/runtime_tags.c         |  3 +-
 runtime/starpu/include/chameleon_starpu.h.in  | 12 +++---
 95 files changed, 267 insertions(+), 68 deletions(-)

diff --git a/compute/pzgetrf.c b/compute/pzgetrf.c
index 91724fd6a..a229b7f33 100644
--- a/compute/pzgetrf.c
+++ b/compute/pzgetrf.c
@@ -398,7 +398,7 @@ void chameleon_pzgetrf( struct chameleon_pzgetrf_s *ws,
     if ( (ws->alg == ChamGetrfNoPivPerColumn) ||
          (ws->alg == ChamGetrfNoPiv ) )
     {
-        RUNTIME_ipiv_init( IPIV );
+        RUNTIME_ipiv_init( sequence, IPIV );
     }
 
     RUNTIME_options_finalize( &options, chamctxt );
diff --git a/control/control.c b/control/control.c
index 3c9ba6a92..a43f9d571 100644
--- a/control/control.c
+++ b/control/control.c
@@ -35,7 +35,8 @@
  *
  * @ingroup Control
  *
- * @brief Initialize CHAMELEON.
+ * @brief Initialize CHAMELEON with number of cpus and gpus (using
+ * MPI_COMM_WORLD).
  *
  ******************************************************************************
  *
@@ -59,7 +60,8 @@ int __chameleon_init(int cores, int gpus)
  *
  * @ingroup Control
  *
- * @brief Initialize CHAMELEON.
+ * @brief Initialize CHAMELEON with number of cpus and gpus and threads per
+ * worker (using MPI_COMM_WORLD).
  *
  ******************************************************************************
  *
@@ -78,6 +80,37 @@ int __chameleon_init(int cores, int gpus)
  *
  */
 int __chameleon_initpar(int ncpus, int ngpus, int nthreads_per_worker)
+{
+    return __chameleon_initparcomm( ncpus, ngpus, nthreads_per_worker, MPI_COMM_WORLD );
+}
+
+/**
+ *
+ * @ingroup Control
+ *
+ * @brief Initialize CHAMELEON with number of cpus and gpus and threads per
+ * worker and using a given MPI communicator.
+ *
+ ******************************************************************************
+ *
+ * @param[in] ncpus
+ *          Number of cores to use.
+ *
+ * @param[in] ngpus
+ *          Number of cuda devices to use.
+ *
+ * @param[in] nthreads_per_worker
+ *          Number of threads per worker (cpu, cuda device).
+ *
+ * @param[in] comm
+ *          The MPI communicator.
+ *
+ ******************************************************************************
+ *
+ * @retval CHAMELEON_SUCCESS successful exit
+ *
+ */
+int __chameleon_initparcomm(int ncpus, int ngpus, int nthreads_per_worker, MPI_Comm comm)
 {
     CHAM_context_t *chamctxt;
 
@@ -124,6 +157,7 @@ int __chameleon_initpar(int ncpus, int ngpus, int nthreads_per_worker)
 #endif
 
     chamctxt->ncudas = ngpus;
+    chamctxt->comm = comm;
     return RUNTIME_init( chamctxt, ncpus, ngpus, nthreads_per_worker );
 }
 
@@ -145,7 +179,7 @@ int __chameleon_finalize(void)
         chameleon_error("CHAMELEON_Finalize", "CHAMELEON not initialized");
         return CHAMELEON_ERR_NOT_INITIALIZED;
     }
-    RUNTIME_flush();
+    RUNTIME_flush(chamctxt);
 #  if !defined(CHAMELEON_SIMULATION)
     RUNTIME_barrier(chamctxt);
 #  endif
diff --git a/coreblas/compute/CMakeLists.txt b/coreblas/compute/CMakeLists.txt
index bec6c5aaf..d6345ffca 100644
--- a/coreblas/compute/CMakeLists.txt
+++ b/coreblas/compute/CMakeLists.txt
@@ -164,6 +164,9 @@ endif()
 target_link_libraries(coreblas PRIVATE MORSE::LAPACKE)
 target_link_libraries(coreblas PRIVATE MORSE::CBLAS)
 target_link_libraries(coreblas PUBLIC MORSE::M)
+if (CHAMELEON_USE_MPI)
+  target_link_libraries(coreblas PUBLIC MPI::MPI_C)
+endif()
 
 # export target coreblas
 install(EXPORT coreblasTargets
diff --git a/example/lapack_to_chameleon/CTestLists.cmake b/example/lapack_to_chameleon/CTestLists.cmake
index 774e12e2c..2d3e86133 100644
--- a/example/lapack_to_chameleon/CTestLists.cmake
+++ b/example/lapack_to_chameleon/CTestLists.cmake
@@ -9,10 +9,19 @@ set(TESTLIST
     step3
     step4
     step5
-    step6
-    step7
     )
 
 foreach(test ${TESTLIST})
-    add_test(example_ltm_${test} ./${prec}${test})
+    add_test(example_ltm_${test} ./${test})
 endforeach()
+
+if (CHAMELEON_USE_MPI AND MPI_C_FOUND)
+  set(MPITESTLIST
+      step6
+      step7
+      )
+  set ( MPICMD mpiexec --bind-to none -n 2 )
+  foreach(test ${MPITESTLIST})
+      add_test(example_ltm_${test} ${MPICMD} ./${test})
+  endforeach()
+endif()
diff --git a/example/lapack_to_chameleon/step6.c b/example/lapack_to_chameleon/step6.c
index fcfad2e23..479b89e9c 100644
--- a/example/lapack_to_chameleon/step6.c
+++ b/example/lapack_to_chameleon/step6.c
@@ -84,8 +84,19 @@ int main(int argc, char *argv[]) {
     NCPU = iparam[IPARAM_THRDNBR];
     NGPU = iparam[IPARAM_NCUDAS];
 
-     /* Initialize CHAMELEON with main parameters */
-    int rc = CHAMELEON_Init( NCPU, NGPU );
+    /* Example of Chameleon init with a given MPI communicator */
+#if defined(CHAMELEON_USE_MPI)
+    MPI_Init(NULL, NULL);
+    int rank;
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm comm;
+    MPI_Comm_split(MPI_COMM_WORLD, rank, rank, &comm);
+#else
+    MPI_Comm comm = 0;
+#endif
+
+    /* Initialize CHAMELEON with main parameters */
+    int rc = CHAMELEON_InitParComm( NCPU, NGPU, 1, comm );
     if (rc != CHAMELEON_SUCCESS) {
         goto finalize;
     }
@@ -235,5 +246,10 @@ finalize:
     /* Finalize CHAMELEON */
     CHAMELEON_Finalize();
 
+#if defined(CHAMELEON_USE_MPI)
+    MPI_Comm_free(&comm);
+    MPI_Finalize();
+#endif
+
     return EXIT_SUCCESS;
 }
diff --git a/example/lapack_to_chameleon/step6.h b/example/lapack_to_chameleon/step6.h
index b5876ea51..d93bfcf2c 100644
--- a/example/lapack_to_chameleon/step6.h
+++ b/example/lapack_to_chameleon/step6.h
@@ -26,15 +26,15 @@
 /* Specific includes for step 6 */
 #include <coreblas/lapacke.h>
 #include <chameleon.h>
-// #if defined(CHAMELEON_USE_MPI)
-// #include <mpi.h>
-// #endif
+#if defined(CHAMELEON_USE_MPI)
+#include <mpi.h>
+#endif
 
 /* Integer parameters for step6 */
 enum iparam_step6 {
     IPARAM_THRDNBR,        /* Number of cores                            */
     IPARAM_NCUDAS,         /* Number of cuda devices                     */
-    IPARAM_NMPI,           /* Number of cuda devices                     */
+    IPARAM_NMPI,           /* Number of MPI PROCS                        */
     IPARAM_N,              /* Number of columns of the matrix            */
     IPARAM_NB,             /* Number of columns in a tile                */
     IPARAM_IB,             /* Inner-blocking size                        */
diff --git a/include/chameleon.h b/include/chameleon.h
index 03bf38843..bb7bee008 100644
--- a/include/chameleon.h
+++ b/include/chameleon.h
@@ -103,6 +103,7 @@ int CHAMELEON_Initialized       (void);
 int CHAMELEON_My_Mpi_Rank       (void) __attribute__((deprecated));
 int __chameleon_init            (int nworkers, int ncudas);
 int __chameleon_initpar         (int nworkers, int ncudas, int nthreads_per_worker);
+int __chameleon_initparcomm     (int nworkers, int ncudas, int nthreads_per_worker, MPI_Comm comm);
 int __chameleon_finalize        (void);
 int CHAMELEON_Pause             (void);
 int CHAMELEON_Resume            (void);
@@ -223,20 +224,27 @@ void CHAMELEON_Ipiv_Print ( const CHAM_ipiv_t *ipiv );
  *
  */
 #if defined(CHAMELEON_SCHED_OPENMP)
-#define CHAMELEON_Init( _nworkers_, _ncudas_ )           \
-    __chameleon_init( (_nworkers_), (_ncudas_) );       \
-    _Pragma("omp parallel")                                    \
-    _Pragma("omp master")                                      \
+
+#define CHAMELEON_Init( _nworkers_, _ncudas_ ) \
+    __chameleon_init( (_nworkers_), (_ncudas_) ); \
+    _Pragma("omp parallel") \
+    _Pragma("omp master") \
     {
 
 #define CHAMELEON_InitPar( _nworkers_, _ncudas_, _nthreads_per_worker_ ) \
     __chameleon_initpar( (_nworkers_), (_ncudas_), (_nthreads_per_worker_) ); \
-    _Pragma("omp parallel")\
-    _Pragma("omp master")\
+    _Pragma("omp parallel") \
+    _Pragma("omp master") \
     {
 
-#define CHAMELEON_Finalize()                    \
-    }                                           \
+#define CHAMELEON_InitParComm( _nworkers_, _ncudas_, _nthreads_per_worker_, _comm_ ) \
+    __chameleon_initparcomm( (_nworkers_), (_ncudas_), (_nthreads_per_worker_), (_comm_) ); \
+    _Pragma("omp parallel") \
+    _Pragma("omp master") \
+    {
+
+#define CHAMELEON_Finalize() \
+    } \
     __chameleon_finalize();
 
 #else
@@ -245,7 +253,10 @@ void CHAMELEON_Ipiv_Print ( const CHAM_ipiv_t *ipiv );
     __chameleon_init( (_nworkers_), (_ncudas_) );
 
 #define CHAMELEON_InitPar( _nworkers_, _ncudas_, _nthreads_per_worker_ ) \
-    __chameleon_initpar( (_nworkers_), (_ncudas_), (_nthreads_per_worker_) );
+    __chameleon_initpar( (_nworkers_), (_ncudas_), (_nthreads_per_worker_), MPI_COMM_WORLD );
+
+#define CHAMELEON_InitParComm( _nworkers_, _ncudas_, _nthreads_per_worker_, _comm_ ) \
+    __chameleon_initparcomm( (_nworkers_), (_ncudas_), (_nthreads_per_worker_), (_comm_) );
 
 #define CHAMELEON_Finalize()                    \
     __chameleon_finalize();
diff --git a/include/chameleon/runtime.h b/include/chameleon/runtime.h
index 2655ef346..eb41a4350 100644
--- a/include/chameleon/runtime.h
+++ b/include/chameleon/runtime.h
@@ -480,7 +480,7 @@ RUNTIME_desc_flush( const CHAM_desc_t     *desc,
  * This function flushes all data from the distributed cache of the runtime system.
  */
 void
-RUNTIME_flush( );
+RUNTIME_flush( CHAM_context_t *chamctxt );
 
 /**
  * @brief Flush a single piece of data.
@@ -707,7 +707,8 @@ void RUNTIME_sdisplay_oneprofile (cham_tasktype_t task);
 
 void RUNTIME_ipiv_create ( CHAM_ipiv_t *ipiv );
 void RUNTIME_ipiv_destroy( CHAM_ipiv_t *ipiv );
-void RUNTIME_ipiv_init   ( CHAM_ipiv_t *ipiv );
+void RUNTIME_ipiv_init   ( const RUNTIME_sequence_t *sequence,
+                           CHAM_ipiv_t *ipiv );
 void RUNTIME_ipiv_gather ( CHAM_ipiv_t *desc, int *ipiv, int node );
 
 void *RUNTIME_ipiv_getaddr   ( const CHAM_ipiv_t *ipiv, int m );
diff --git a/include/chameleon/runtime_struct.h b/include/chameleon/runtime_struct.h
index 4d345a0fd..88ff1a61d 100644
--- a/include/chameleon/runtime_struct.h
+++ b/include/chameleon/runtime_struct.h
@@ -23,6 +23,17 @@
 #ifndef _chameleon_runtime_struct_h_
 #define _chameleon_runtime_struct_h_
 
+#if defined(CHAMELEON_USE_MPI)
+#include <mpi.h>
+#else
+#ifndef MPI_Comm
+typedef uintptr_t MPI_Comm;
+#endif
+#ifndef MPI_COMM_WORLD
+#define MPI_COMM_WORLD 0
+#endif
+#endif
+
 BEGIN_C_DECLS
 
 /**
@@ -70,6 +81,7 @@ typedef struct runtime_sequence_s {
     int                status;   /**< Return status registered by the tasks for the request     */
     RUNTIME_request_t *request;  /**< Pointer to the request that failed if any, NULL otherwise */
     void              *schedopt; /**< Specific runtime data pointer to handle the sequence      */
+    MPI_Comm           comm;     /**< MPI communicator                                         */
 } RUNTIME_sequence_t;
 
 /**
diff --git a/include/chameleon/struct.h b/include/chameleon/struct.h
index bff3788a5..6f3e47662 100644
--- a/include/chameleon/struct.h
+++ b/include/chameleon/struct.h
@@ -30,6 +30,17 @@
 #include "chameleon/constants.h"
 #include "chameleon/runtime_struct.h"
 
+#if defined(CHAMELEON_USE_MPI)
+#include <mpi.h>
+#else
+#ifndef MPI_Comm
+typedef uintptr_t MPI_Comm;
+#endif
+#ifndef MPI_COMM_WORLD
+#define MPI_COMM_WORLD 0
+#endif
+#endif
+
 BEGIN_C_DECLS
 
 #define CHAMELEON_TILE_FULLRANK (1 << 0)
@@ -191,6 +202,7 @@ typedef struct chameleon_context_s {
     int                lookahead;          // depth of the look ahead in algorithms
     void              *schedopt;           // structure for runtimes
     int                mpi_outer_init;     // MPI has been initialized outside our functions
+    MPI_Comm           comm;               // MPI communicator
 } CHAM_context_t;
 
 static inline void *
diff --git a/runtime/openmp/control/runtime_descriptor.c b/runtime/openmp/control/runtime_descriptor.c
index ecec4def2..383b35a70 100644
--- a/runtime/openmp/control/runtime_descriptor.c
+++ b/runtime/openmp/control/runtime_descriptor.c
@@ -69,8 +69,9 @@ RUNTIME_desc_flush( const CHAM_desc_t     *desc,
 
 
 void
-RUNTIME_flush( )
+RUNTIME_flush( CHAM_context_t *chamctxt )
 {
+    (void)chamctxt;
     return;
 }
 
diff --git a/runtime/openmp/control/runtime_descriptor_ipiv.c b/runtime/openmp/control/runtime_descriptor_ipiv.c
index f10c4156d..c9fe8dfd0 100644
--- a/runtime/openmp/control/runtime_descriptor_ipiv.c
+++ b/runtime/openmp/control/runtime_descriptor_ipiv.c
@@ -107,9 +107,11 @@ void RUNTIME_ipiv_reducek( const RUNTIME_option_t *options,
     (void)h;
 }
 
-void RUNTIME_ipiv_init( CHAM_ipiv_t *ipiv )
+void RUNTIME_ipiv_init( const RUNTIME_sequence_t *sequence,
+                        CHAM_ipiv_t *ipiv )
 {
     assert( 0 );
+    (void)sequence;
     (void)ipiv;
 }
 
diff --git a/runtime/parsec/control/runtime_descriptor.c b/runtime/parsec/control/runtime_descriptor.c
index 84fecb360..fc926df20 100644
--- a/runtime/parsec/control/runtime_descriptor.c
+++ b/runtime/parsec/control/runtime_descriptor.c
@@ -345,8 +345,10 @@ int RUNTIME_desc_release( const CHAM_desc_t *desc )
 /**
  *  Flush cached data
  */
-void RUNTIME_flush()
+void RUNTIME_flush( CHAM_context_t *chamctxt )
 {
+    (void)chamctxt;
+    return;
 }
 
 void RUNTIME_desc_flush( const CHAM_desc_t        *desc,
diff --git a/runtime/parsec/control/runtime_descriptor_ipiv.c b/runtime/parsec/control/runtime_descriptor_ipiv.c
index fefb42abf..b0657f5ba 100644
--- a/runtime/parsec/control/runtime_descriptor_ipiv.c
+++ b/runtime/parsec/control/runtime_descriptor_ipiv.c
@@ -107,9 +107,11 @@ void RUNTIME_ipiv_reducek( const RUNTIME_option_t *options,
     (void)h;
 }
 
-void RUNTIME_ipiv_init( CHAM_ipiv_t *ipiv )
+void RUNTIME_ipiv_init( const RUNTIME_sequence_t *sequence,
+                        CHAM_ipiv_t *ipiv )
 {
     assert( 0 );
+    (void)sequence;
     (void)ipiv;
 }
 
diff --git a/runtime/quark/control/runtime_descriptor.c b/runtime/quark/control/runtime_descriptor.c
index 1e9be06fa..740522a08 100644
--- a/runtime/quark/control/runtime_descriptor.c
+++ b/runtime/quark/control/runtime_descriptor.c
@@ -70,8 +70,9 @@ RUNTIME_desc_flush( const CHAM_desc_t     *desc,
 
 
 void
-RUNTIME_flush( )
+RUNTIME_flush( CHAM_context_t *chamctxt )
 {
+    (void)chamctxt;
     return;
 }
 
diff --git a/runtime/quark/control/runtime_descriptor_ipiv.c b/runtime/quark/control/runtime_descriptor_ipiv.c
index 88e8f886e..3053435b1 100644
--- a/runtime/quark/control/runtime_descriptor_ipiv.c
+++ b/runtime/quark/control/runtime_descriptor_ipiv.c
@@ -107,9 +107,11 @@ void RUNTIME_ipiv_reducek( const RUNTIME_option_t *options,
     (void)h;
 }
 
-void RUNTIME_ipiv_init( CHAM_ipiv_t *ipiv )
+void RUNTIME_ipiv_init( const RUNTIME_sequence_t *sequence,
+                        CHAM_ipiv_t *ipiv )
 {
     assert( 0 );
+    (void)sequence;
     (void)ipiv;
 }
 
diff --git a/runtime/starpu/codelets/codelet_convert.c b/runtime/starpu/codelets/codelet_convert.c
index 0b07c069a..101268134 100644
--- a/runtime/starpu/codelets/codelet_convert.c
+++ b/runtime/starpu/codelets/codelet_convert.c
@@ -119,6 +119,7 @@ insert_task_convert( const RUNTIME_option_t *options,
     }
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &m,                 sizeof(int),
         STARPU_VALUE,    &n,                 sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_dlag2h.c b/runtime/starpu/codelets/codelet_dlag2h.c
index b910559db..993026a3d 100644
--- a/runtime/starpu/codelets/codelet_dlag2h.c
+++ b/runtime/starpu/codelets/codelet_dlag2h.c
@@ -81,6 +81,7 @@ void INSERT_TASK_dlag2h( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &m,                 sizeof(int),
         STARPU_VALUE,    &n,                 sizeof(int),
@@ -146,6 +147,7 @@ void INSERT_TASK_hlag2d( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &m,                 sizeof(int),
         STARPU_VALUE,    &n,                 sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_dlag2z.c b/runtime/starpu/codelets/codelet_dlag2z.c
index 34e0b16c0..0edc438e4 100644
--- a/runtime/starpu/codelets/codelet_dlag2z.c
+++ b/runtime/starpu/codelets/codelet_dlag2z.c
@@ -61,6 +61,7 @@ void INSERT_TASK_dlag2z( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &uplo,              sizeof(uplo),
         STARPU_VALUE,    &m,                 sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_dzasum.c b/runtime/starpu/codelets/codelet_dzasum.c
index 1fc2cf309..859ce1d36 100644
--- a/runtime/starpu/codelets/codelet_dzasum.c
+++ b/runtime/starpu/codelets/codelet_dzasum.c
@@ -62,6 +62,7 @@ void INSERT_TASK_dzasum( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &storev,              sizeof(cham_store_t),
         STARPU_VALUE,    &uplo,                sizeof(cham_uplo_t),
diff --git a/runtime/starpu/codelets/codelet_gemm.c b/runtime/starpu/codelets/codelet_gemm.c
index 69cd67a29..bdec166e3 100644
--- a/runtime/starpu/codelets/codelet_gemm.c
+++ b/runtime/starpu/codelets/codelet_gemm.c
@@ -184,6 +184,7 @@ INSERT_TASK_gemm( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, argssize,
diff --git a/runtime/starpu/codelets/codelet_gemmex.c b/runtime/starpu/codelets/codelet_gemmex.c
index efc33dab3..75473ab54 100644
--- a/runtime/starpu/codelets/codelet_gemmex.c
+++ b/runtime/starpu/codelets/codelet_gemmex.c
@@ -179,6 +179,7 @@ void INSERT_TASK_gemmex_Astat( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_gemmex,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_gemmex_args_s),
@@ -257,6 +258,7 @@ void INSERT_TASK_gemmex( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_gemmex,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_gemmex_args_s),
diff --git a/runtime/starpu/codelets/codelet_hgemm.c b/runtime/starpu/codelets/codelet_hgemm.c
index a595bf990..7a5dc716d 100644
--- a/runtime/starpu/codelets/codelet_hgemm.c
+++ b/runtime/starpu/codelets/codelet_hgemm.c
@@ -158,6 +158,7 @@ void INSERT_TASK_hgemm_Astat( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_hgemm,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_hgemm_args_s),
@@ -229,6 +230,7 @@ void INSERT_TASK_hgemm( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_hgemm,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_hgemm_args_s),
diff --git a/runtime/starpu/codelets/codelet_ipiv_to_perm.c b/runtime/starpu/codelets/codelet_ipiv_to_perm.c
index 31183c115..f5883767f 100644
--- a/runtime/starpu/codelets/codelet_ipiv_to_perm.c
+++ b/runtime/starpu/codelets/codelet_ipiv_to_perm.c
@@ -56,6 +56,7 @@ void INSERT_TASK_ipiv_to_perm( const RUNTIME_option_t *options,
     struct starpu_codelet *codelet = &cl_ipiv_to_perm;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,             &m0,  sizeof(int),
         STARPU_VALUE,             &m,   sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_map.c b/runtime/starpu/codelets/codelet_map.c
index a55c56ef8..eadd45bfd 100644
--- a/runtime/starpu/codelets/codelet_map.c
+++ b/runtime/starpu/codelets/codelet_map.c
@@ -59,6 +59,7 @@ void INSERT_TASK_map( const RUNTIME_option_t *options,
                                       A->get_blktile( A, Am, An ) );
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &A,                      sizeof(CHAM_desc_t*),
         STARPU_VALUE,    &uplo,                   sizeof(cham_uplo_t),
diff --git a/runtime/starpu/codelets/codelet_zaxpy.c b/runtime/starpu/codelets/codelet_zaxpy.c
index be1fbbbf4..08de84a22 100644
--- a/runtime/starpu/codelets/codelet_zaxpy.c
+++ b/runtime/starpu/codelets/codelet_zaxpy.c
@@ -62,6 +62,7 @@ void INSERT_TASK_zaxpy( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+            options->sequence->comm,
             codelet,
             STARPU_VALUE,    &M,                           sizeof(int),
             STARPU_VALUE,    &alpha,                       sizeof(CHAMELEON_Complex64_t),
diff --git a/runtime/starpu/codelets/codelet_zbuild.c b/runtime/starpu/codelets/codelet_zbuild.c
index 3ce93dea0..71938c7d4 100644
--- a/runtime/starpu/codelets/codelet_zbuild.c
+++ b/runtime/starpu/codelets/codelet_zbuild.c
@@ -74,6 +74,7 @@ CODELETS_CPU(zbuild, cl_zbuild_cpu_func)
     col_min = An*A->nb ;
     col_max = An == A->nt-1 ? A->n-1 : col_min+A->nb-1 ;
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &row_min,                      sizeof(int),
         STARPU_VALUE,    &row_max,                      sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zcesca.c b/runtime/starpu/codelets/codelet_zcesca.c
index 74cb9c7c6..fb6a24b99 100644
--- a/runtime/starpu/codelets/codelet_zcesca.c
+++ b/runtime/starpu/codelets/codelet_zcesca.c
@@ -94,6 +94,7 @@ void INSERT_TASK_zcesca( const RUNTIME_option_t *options,
     }
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_CL_ARGS, clargs, sizeof(struct cl_zcesca_args_s),
         STARPU_R,        RTBLKADDR(Gi, ChamComplexDouble, Gim, Gin),
diff --git a/runtime/starpu/codelets/codelet_zgeadd.c b/runtime/starpu/codelets/codelet_zgeadd.c
index 60daa3b17..fda00982f 100644
--- a/runtime/starpu/codelets/codelet_zgeadd.c
+++ b/runtime/starpu/codelets/codelet_zgeadd.c
@@ -99,6 +99,7 @@ void INSERT_TASK_zgeadd( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &trans,              sizeof(int),
         STARPU_VALUE,    &m,                  sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zgelqt.c b/runtime/starpu/codelets/codelet_zgelqt.c
index 846482361..36b1cde93 100644
--- a/runtime/starpu/codelets/codelet_zgelqt.c
+++ b/runtime/starpu/codelets/codelet_zgelqt.c
@@ -76,6 +76,7 @@ void INSERT_TASK_zgelqt(const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &m,                 sizeof(int),
         STARPU_VALUE,    &n,                 sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zgemm.c b/runtime/starpu/codelets/codelet_zgemm.c
index 4b4762725..fe62de383 100644
--- a/runtime/starpu/codelets/codelet_zgemm.c
+++ b/runtime/starpu/codelets/codelet_zgemm.c
@@ -186,6 +186,7 @@ void INSERT_TASK_zgemm_Astat( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_zgemm,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_zgemm_args_s),
@@ -257,6 +258,7 @@ void INSERT_TASK_zgemm( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_zgemm,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_zgemm_args_s),
diff --git a/runtime/starpu/codelets/codelet_zgemv.c b/runtime/starpu/codelets/codelet_zgemv.c
index a2529d999..307c58c7d 100644
--- a/runtime/starpu/codelets/codelet_zgemv.c
+++ b/runtime/starpu/codelets/codelet_zgemv.c
@@ -104,6 +104,7 @@ void INSERT_TASK_zgemv( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &trans,             sizeof(cham_trans_t),
         STARPU_VALUE,    &m,                 sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zgeqrt.c b/runtime/starpu/codelets/codelet_zgeqrt.c
index 0ee282e4a..dea86bb8f 100644
--- a/runtime/starpu/codelets/codelet_zgeqrt.c
+++ b/runtime/starpu/codelets/codelet_zgeqrt.c
@@ -77,6 +77,7 @@ void INSERT_TASK_zgeqrt(const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &m,                 sizeof(int),
         STARPU_VALUE,    &n,                 sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zgered.c b/runtime/starpu/codelets/codelet_zgered.c
index 394ef74c2..e4cdf7840 100644
--- a/runtime/starpu/codelets/codelet_zgered.c
+++ b/runtime/starpu/codelets/codelet_zgered.c
@@ -78,6 +78,7 @@ void INSERT_TASK_zgered( const RUNTIME_option_t *options,
             starpu_cham_tile_register( &handleAout, -1, tileA, ChamComplexHalf );
 
             rt_starpu_insert_task(
+                options->sequence->comm,
                 &cl_dlag2h,
                 STARPU_VALUE,    &m,                 sizeof(int),
                 STARPU_VALUE,    &n,                 sizeof(int),
@@ -119,6 +120,7 @@ void INSERT_TASK_zgered( const RUNTIME_option_t *options,
         starpu_cham_tile_register( &handleAout, -1, tileA, ChamComplexFloat );
 
         rt_starpu_insert_task(
+            options->sequence->comm,
             &cl_zlag2c,
             STARPU_VALUE,    &m,                 sizeof(int),
             STARPU_VALUE,    &n,                 sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zgerst.c b/runtime/starpu/codelets/codelet_zgerst.c
index 68490f011..a6e5821ff 100644
--- a/runtime/starpu/codelets/codelet_zgerst.c
+++ b/runtime/starpu/codelets/codelet_zgerst.c
@@ -70,6 +70,7 @@ void INSERT_TASK_zgerst( const RUNTIME_option_t *options,
                  A->myrank, Am, An );
 #endif
         rt_starpu_insert_task(
+            options->sequence->comm,
             &cl_hlag2d,
             STARPU_VALUE,    &m,                 sizeof(int),
             STARPU_VALUE,    &n,                 sizeof(int),
@@ -92,6 +93,7 @@ void INSERT_TASK_zgerst( const RUNTIME_option_t *options,
                  A->myrank, Am, An );
 #endif
         rt_starpu_insert_task(
+            options->sequence->comm,
             &cl_clag2z,
             STARPU_VALUE,    &m,                 sizeof(int),
             STARPU_VALUE,    &n,                 sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zgersum.c b/runtime/starpu/codelets/codelet_zgersum.c
index 7c218ab00..a1053aa03 100644
--- a/runtime/starpu/codelets/codelet_zgersum.c
+++ b/runtime/starpu/codelets/codelet_zgersum.c
@@ -128,7 +128,7 @@ RUNTIME_zgersum_submit_tree( const RUNTIME_option_t *options,
                              const CHAM_desc_t *A, int Am, int An )
 {
 #if defined(HAVE_STARPU_MPI_REDUX) && defined(CHAMELEON_USE_MPI)
-    starpu_mpi_redux_data_prio_tree( MPI_COMM_WORLD,
+    starpu_mpi_redux_data_prio_tree( options->sequence->comm,
                                      RTBLKADDR(A, ChamComplexDouble, Am, An),
                                      options->priority + 1,
                                      2 /* Binary tree */ );
diff --git a/runtime/starpu/codelets/codelet_zgessm.c b/runtime/starpu/codelets/codelet_zgessm.c
index 2afae3214..f592f89dc 100644
--- a/runtime/starpu/codelets/codelet_zgessm.c
+++ b/runtime/starpu/codelets/codelet_zgessm.c
@@ -71,6 +71,7 @@ void INSERT_TASK_zgessm( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,     &m,                        sizeof(int),
         STARPU_VALUE,     &n,                        sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zgessq.c b/runtime/starpu/codelets/codelet_zgessq.c
index e7de6b666..43abb20e7 100644
--- a/runtime/starpu/codelets/codelet_zgessq.c
+++ b/runtime/starpu/codelets/codelet_zgessq.c
@@ -61,6 +61,7 @@ void INSERT_TASK_zgessq( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &storev,                     sizeof(cham_store_t),
         STARPU_VALUE,    &m,                          sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zgesum.c b/runtime/starpu/codelets/codelet_zgesum.c
index d1947b4a1..a9755cd73 100644
--- a/runtime/starpu/codelets/codelet_zgesum.c
+++ b/runtime/starpu/codelets/codelet_zgesum.c
@@ -67,6 +67,7 @@ void INSERT_TASK_zgesum( const RUNTIME_option_t *options,
     }
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_CL_ARGS, clargs, sizeof(struct cl_zgesum_args_s),
         STARPU_R,        RTBLKADDR(A, ChamComplexDouble, Am, An),
diff --git a/runtime/starpu/codelets/codelet_zgetrf.c b/runtime/starpu/codelets/codelet_zgetrf.c
index 568265ee2..5abf85cdc 100644
--- a/runtime/starpu/codelets/codelet_zgetrf.c
+++ b/runtime/starpu/codelets/codelet_zgetrf.c
@@ -71,6 +71,7 @@ void INSERT_TASK_zgetrf( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,             &m,                        sizeof(int),
         STARPU_VALUE,             &n,                        sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zgetrf_blocked.c b/runtime/starpu/codelets/codelet_zgetrf_blocked.c
index 6e4662060..71767ce14 100644
--- a/runtime/starpu/codelets/codelet_zgetrf_blocked.c
+++ b/runtime/starpu/codelets/codelet_zgetrf_blocked.c
@@ -112,6 +112,7 @@ void INSERT_TASK_zgetrf_blocked_diag( const RUNTIME_option_t *options,
     }
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,             &h,                   sizeof(int),
         STARPU_VALUE,             &m0,                  sizeof(int),
@@ -185,6 +186,7 @@ void INSERT_TASK_zgetrf_blocked_offdiag( const RUNTIME_option_t *options,
     void (*callback)(void*) = options->profiling ? cl_zgetrf_blocked_offdiag_callback : NULL;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &h,                   sizeof(int),
         STARPU_VALUE,    &m0,                  sizeof(int),
@@ -253,6 +255,7 @@ void INSERT_TASK_zgetrf_blocked_trsm( const RUNTIME_option_t *options,
     void (*callback)(void*) = options->profiling ? cl_zgetrf_blocked_trsm_callback : NULL;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &m,                   sizeof(int),
         STARPU_VALUE,    &n,                   sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zgetrf_incpiv.c b/runtime/starpu/codelets/codelet_zgetrf_incpiv.c
index 03398f644..99690a73a 100644
--- a/runtime/starpu/codelets/codelet_zgetrf_incpiv.c
+++ b/runtime/starpu/codelets/codelet_zgetrf_incpiv.c
@@ -79,6 +79,7 @@ void INSERT_TASK_zgetrf_incpiv(const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &m,                 sizeof(int),
         STARPU_VALUE,    &n,                 sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zgetrf_nopiv.c b/runtime/starpu/codelets/codelet_zgetrf_nopiv.c
index 4488882e7..44dcfcac2 100644
--- a/runtime/starpu/codelets/codelet_zgetrf_nopiv.c
+++ b/runtime/starpu/codelets/codelet_zgetrf_nopiv.c
@@ -71,6 +71,7 @@ void INSERT_TASK_zgetrf_nopiv(const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &m,                         sizeof(int),
         STARPU_VALUE,    &n,                         sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zgetrf_nopiv_percol.c b/runtime/starpu/codelets/codelet_zgetrf_nopiv_percol.c
index 554735a47..0fc72a70b 100644
--- a/runtime/starpu/codelets/codelet_zgetrf_nopiv_percol.c
+++ b/runtime/starpu/codelets/codelet_zgetrf_nopiv_percol.c
@@ -90,6 +90,7 @@ void INSERT_TASK_zgetrf_nopiv_percol_diag( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,             &m,                   sizeof(int),
         STARPU_VALUE,             &n,                   sizeof(int),
@@ -161,6 +162,7 @@ void INSERT_TASK_zgetrf_nopiv_percol_trsm( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,             &m, sizeof(int),
         STARPU_VALUE,             &n, sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zgetrf_percol.c b/runtime/starpu/codelets/codelet_zgetrf_percol.c
index 3248ee0ae..ef865a7f1 100644
--- a/runtime/starpu/codelets/codelet_zgetrf_percol.c
+++ b/runtime/starpu/codelets/codelet_zgetrf_percol.c
@@ -90,6 +90,7 @@ void INSERT_TASK_zgetrf_percol_diag( const RUNTIME_option_t *options,
     int access_ppiv = ( h == 0 )       ? STARPU_NONE : STARPU_R;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,             &h,                   sizeof(int),
         STARPU_VALUE,             &m0,                  sizeof(int),
@@ -149,6 +150,7 @@ void INSERT_TASK_zgetrf_percol_offdiag( const RUNTIME_option_t *options,
     void (*callback)(void*) = options->profiling ? cl_zgetrf_percol_offdiag_callback : NULL;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &h,                   sizeof(int),
         STARPU_VALUE,    &m0,                  sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zgram.c b/runtime/starpu/codelets/codelet_zgram.c
index 883093966..7b8067496 100644
--- a/runtime/starpu/codelets/codelet_zgram.c
+++ b/runtime/starpu/codelets/codelet_zgram.c
@@ -64,6 +64,7 @@ void INSERT_TASK_zgram( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &uplo,                      sizeof(int),
         STARPU_VALUE,    &m,                         sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zhe2ge.c b/runtime/starpu/codelets/codelet_zhe2ge.c
index 2fa77bfb0..1ad5865c7 100644
--- a/runtime/starpu/codelets/codelet_zhe2ge.c
+++ b/runtime/starpu/codelets/codelet_zhe2ge.c
@@ -61,6 +61,7 @@ void INSERT_TASK_zhe2ge( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,  &uplo,                sizeof(int),
         STARPU_VALUE,     &m,                        sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zhemm.c b/runtime/starpu/codelets/codelet_zhemm.c
index c38e52596..4f299e9f4 100644
--- a/runtime/starpu/codelets/codelet_zhemm.c
+++ b/runtime/starpu/codelets/codelet_zhemm.c
@@ -188,6 +188,7 @@ void INSERT_TASK_zhemm_Astat( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_zhemm,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_zhemm_args_s),
@@ -258,6 +259,7 @@ void INSERT_TASK_zhemm( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_zhemm,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_zhemm_args_s),
diff --git a/runtime/starpu/codelets/codelet_zher2k.c b/runtime/starpu/codelets/codelet_zher2k.c
index 223522bbb..541d1bf36 100644
--- a/runtime/starpu/codelets/codelet_zher2k.c
+++ b/runtime/starpu/codelets/codelet_zher2k.c
@@ -148,6 +148,7 @@ INSERT_TASK_zher2k( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,      &uplo,                sizeof(int),
         STARPU_VALUE,     &trans,                sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zherfb.c b/runtime/starpu/codelets/codelet_zherfb.c
index 142952968..47a1449cc 100644
--- a/runtime/starpu/codelets/codelet_zherfb.c
+++ b/runtime/starpu/codelets/codelet_zherfb.c
@@ -99,6 +99,7 @@ void INSERT_TASK_zherfb(const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &uplo,              sizeof(int),
         STARPU_VALUE,    &n,                 sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zherk.c b/runtime/starpu/codelets/codelet_zherk.c
index 6e866ae69..9a03d77af 100644
--- a/runtime/starpu/codelets/codelet_zherk.c
+++ b/runtime/starpu/codelets/codelet_zherk.c
@@ -154,6 +154,7 @@ void INSERT_TASK_zherk( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_zherk,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_zherk_args_s),
diff --git a/runtime/starpu/codelets/codelet_zlacpy.c b/runtime/starpu/codelets/codelet_zlacpy.c
index 4d4f10185..2fedd9d52 100644
--- a/runtime/starpu/codelets/codelet_zlacpy.c
+++ b/runtime/starpu/codelets/codelet_zlacpy.c
@@ -120,9 +120,9 @@ insert_task_zlacpy_on_remote_node( const RUNTIME_option_t *options,
 {
     void (*callback)(void*) = options->profiling ? cl_zlacpy_callback : NULL;
 #if defined(CHAMELEON_RUNTIME_SYNC)
-    starpu_mpi_data_cpy_priority( handleB, handleA, MPI_COMM_WORLD, 0, callback, NULL, options->priority );
+    starpu_mpi_data_cpy_priority( handleB, handleA, options->sequence->comm, 0, callback, NULL, options->priority );
 #else
-    starpu_mpi_data_cpy_priority( handleB, handleA, MPI_COMM_WORLD, 1, callback, NULL, options->priority );
+    starpu_mpi_data_cpy_priority( handleB, handleA, options->sequence->comm, 1, callback, NULL, options->priority );
 #endif
 }
 #endif
@@ -183,6 +183,7 @@ void INSERT_TASK_zlacpyx( const RUNTIME_option_t *options,
 
         /* Insert the task */
         rt_starpu_insert_task(
+            options->sequence->comm,
             &cl_zlacpyx,
             /* Task codelet arguments */
             STARPU_CL_ARGS, clargs, sizeof(struct cl_zlacpy_args_s),
@@ -258,6 +259,7 @@ void INSERT_TASK_zlacpy( const RUNTIME_option_t *options,
         callback = options->profiling ? cl_zlacpy_callback : NULL;
 
         rt_starpu_insert_task(
+            options->sequence->comm,
             &cl_zlacpy,
             /* Task codelet arguments */
             STARPU_CL_ARGS, clargs, sizeof(struct cl_zlacpy_args_s),
diff --git a/runtime/starpu/codelets/codelet_zlag2c.c b/runtime/starpu/codelets/codelet_zlag2c.c
index 961cc9c03..e0b2151f9 100644
--- a/runtime/starpu/codelets/codelet_zlag2c.c
+++ b/runtime/starpu/codelets/codelet_zlag2c.c
@@ -97,6 +97,7 @@ void INSERT_TASK_zlag2c(const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &m,                 sizeof(int),
         STARPU_VALUE,    &n,                 sizeof(int),
@@ -175,6 +176,7 @@ void INSERT_TASK_clag2z( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &m,                 sizeof(int),
         STARPU_VALUE,    &n,                 sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zlange.c b/runtime/starpu/codelets/codelet_zlange.c
index 1747215a6..3e944050b 100644
--- a/runtime/starpu/codelets/codelet_zlange.c
+++ b/runtime/starpu/codelets/codelet_zlange.c
@@ -66,6 +66,7 @@ void INSERT_TASK_zlange( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &norm,              sizeof(cham_normtype_t),
         STARPU_VALUE,    &M,                 sizeof(int),
@@ -120,6 +121,7 @@ void INSERT_TASK_zlange_max(const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_R,        RTBLKADDR(A, ChamRealDouble, Am, An),
         STARPU_RW,       RTBLKADDR(B, ChamRealDouble, Bm, Bn),
diff --git a/runtime/starpu/codelets/codelet_zlanhe.c b/runtime/starpu/codelets/codelet_zlanhe.c
index c45ecc839..6c80e0924 100644
--- a/runtime/starpu/codelets/codelet_zlanhe.c
+++ b/runtime/starpu/codelets/codelet_zlanhe.c
@@ -65,6 +65,7 @@ void INSERT_TASK_zlanhe(const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &norm,              sizeof(int),
         STARPU_VALUE,    &uplo,              sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zlansy.c b/runtime/starpu/codelets/codelet_zlansy.c
index 21b5a1140..1c88303e7 100644
--- a/runtime/starpu/codelets/codelet_zlansy.c
+++ b/runtime/starpu/codelets/codelet_zlansy.c
@@ -66,6 +66,7 @@ void INSERT_TASK_zlansy( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &norm,              sizeof(int),
         STARPU_VALUE,    &uplo,              sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zlantr.c b/runtime/starpu/codelets/codelet_zlantr.c
index e2067a02c..86a5e6ce2 100644
--- a/runtime/starpu/codelets/codelet_zlantr.c
+++ b/runtime/starpu/codelets/codelet_zlantr.c
@@ -65,6 +65,7 @@ void INSERT_TASK_zlantr( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &norm,              sizeof(int),
         STARPU_VALUE,    &uplo,              sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zlascal.c b/runtime/starpu/codelets/codelet_zlascal.c
index 1246af773..c0acf8c78 100644
--- a/runtime/starpu/codelets/codelet_zlascal.c
+++ b/runtime/starpu/codelets/codelet_zlascal.c
@@ -88,6 +88,7 @@ void INSERT_TASK_zlascal( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_zlascal,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_zlascal_args_s),
diff --git a/runtime/starpu/codelets/codelet_zlaset.c b/runtime/starpu/codelets/codelet_zlaset.c
index b78055d33..91bb2d459 100644
--- a/runtime/starpu/codelets/codelet_zlaset.c
+++ b/runtime/starpu/codelets/codelet_zlaset.c
@@ -82,6 +82,7 @@ void INSERT_TASK_zlaset( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_zlaset,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_zlaset_args_s),
diff --git a/runtime/starpu/codelets/codelet_zlaset2.c b/runtime/starpu/codelets/codelet_zlaset2.c
index 33a136f35..f7d3cc3ff 100644
--- a/runtime/starpu/codelets/codelet_zlaset2.c
+++ b/runtime/starpu/codelets/codelet_zlaset2.c
@@ -61,6 +61,7 @@ void INSERT_TASK_zlaset2(const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,  &uplo,                sizeof(int),
         STARPU_VALUE,     &M,                        sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zlaswp.c b/runtime/starpu/codelets/codelet_zlaswp.c
index 2d8fc31d4..8c7d716be 100644
--- a/runtime/starpu/codelets/codelet_zlaswp.c
+++ b/runtime/starpu/codelets/codelet_zlaswp.c
@@ -51,6 +51,7 @@ void INSERT_TASK_zlaswp_get( const RUNTIME_option_t *options,
     //void (*callback)(void*) = options->profiling ? cl_zlaswp_get_callback : NULL;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,               &m0, sizeof(int),
         STARPU_VALUE,               &k,  sizeof(int),
@@ -95,6 +96,7 @@ void INSERT_TASK_zlaswp_set( const RUNTIME_option_t *options,
     //void (*callback)(void*) = options->profiling ? cl_zlaswp_set_callback : NULL;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,             &m0, sizeof(int),
         STARPU_VALUE,             &k,  sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zlatro.c b/runtime/starpu/codelets/codelet_zlatro.c
index 42fa0637d..0e9471ec3 100644
--- a/runtime/starpu/codelets/codelet_zlatro.c
+++ b/runtime/starpu/codelets/codelet_zlatro.c
@@ -72,6 +72,7 @@ void INSERT_TASK_zlatro( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,   &uplo,    sizeof(int),
         STARPU_VALUE,   &trans,   sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zlauum.c b/runtime/starpu/codelets/codelet_zlauum.c
index bdb000e52..dbdb47e92 100644
--- a/runtime/starpu/codelets/codelet_zlauum.c
+++ b/runtime/starpu/codelets/codelet_zlauum.c
@@ -80,6 +80,7 @@ void INSERT_TASK_zlauum( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_zlauum,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_zlauum_args_s),
diff --git a/runtime/starpu/codelets/codelet_zplghe.c b/runtime/starpu/codelets/codelet_zplghe.c
index bc3052e27..3c90a52b2 100644
--- a/runtime/starpu/codelets/codelet_zplghe.c
+++ b/runtime/starpu/codelets/codelet_zplghe.c
@@ -86,6 +86,7 @@ void INSERT_TASK_zplghe( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_zplghe,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_zplghe_args_s),
diff --git a/runtime/starpu/codelets/codelet_zplgsy.c b/runtime/starpu/codelets/codelet_zplgsy.c
index fd29f8d0a..18dd13e7d 100644
--- a/runtime/starpu/codelets/codelet_zplgsy.c
+++ b/runtime/starpu/codelets/codelet_zplgsy.c
@@ -86,6 +86,7 @@ void INSERT_TASK_zplgsy( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_zplgsy,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_zplgsy_args_s),
diff --git a/runtime/starpu/codelets/codelet_zplrnt.c b/runtime/starpu/codelets/codelet_zplrnt.c
index abb1ebd39..b242aecca 100644
--- a/runtime/starpu/codelets/codelet_zplrnt.c
+++ b/runtime/starpu/codelets/codelet_zplrnt.c
@@ -85,6 +85,7 @@ void INSERT_TASK_zplrnt( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_zplrnt,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_zplrnt_args_s),
diff --git a/runtime/starpu/codelets/codelet_zplssq.c b/runtime/starpu/codelets/codelet_zplssq.c
index 6a1c7a54d..cbd42e5ce 100644
--- a/runtime/starpu/codelets/codelet_zplssq.c
+++ b/runtime/starpu/codelets/codelet_zplssq.c
@@ -65,6 +65,7 @@ void INSERT_TASK_zplssq( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &storev,            sizeof(int),
         STARPU_VALUE,    &M,                 sizeof(int),
@@ -113,6 +114,7 @@ void INSERT_TASK_zplssq2( const RUNTIME_option_t *options, int N,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &N,                 sizeof(int),
         STARPU_RW, RTBLKADDR(RESULT, ChamRealDouble, RESULTm, RESULTn),
diff --git a/runtime/starpu/codelets/codelet_zpotrf.c b/runtime/starpu/codelets/codelet_zpotrf.c
index 1195a1e93..101d1acb4 100644
--- a/runtime/starpu/codelets/codelet_zpotrf.c
+++ b/runtime/starpu/codelets/codelet_zpotrf.c
@@ -97,6 +97,7 @@ void INSERT_TASK_zpotrf( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_zpotrf,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_zpotrf_args_s),
diff --git a/runtime/starpu/codelets/codelet_zssssm.c b/runtime/starpu/codelets/codelet_zssssm.c
index f9cece0bf..9c07f1268 100644
--- a/runtime/starpu/codelets/codelet_zssssm.c
+++ b/runtime/starpu/codelets/codelet_zssssm.c
@@ -78,6 +78,7 @@ void INSERT_TASK_zssssm( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &m1,                        sizeof(int),
         STARPU_VALUE,    &n1,                        sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zsymm.c b/runtime/starpu/codelets/codelet_zsymm.c
index 6748325a6..1046cbcb3 100644
--- a/runtime/starpu/codelets/codelet_zsymm.c
+++ b/runtime/starpu/codelets/codelet_zsymm.c
@@ -189,6 +189,7 @@ void INSERT_TASK_zsymm_Astat( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_zsymm,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_zsymm_args_s),
@@ -259,6 +260,7 @@ void INSERT_TASK_zsymm( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_zsymm,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_zsymm_args_s),
diff --git a/runtime/starpu/codelets/codelet_zsyr2k.c b/runtime/starpu/codelets/codelet_zsyr2k.c
index 51f72d20e..074371252 100644
--- a/runtime/starpu/codelets/codelet_zsyr2k.c
+++ b/runtime/starpu/codelets/codelet_zsyr2k.c
@@ -147,6 +147,7 @@ void INSERT_TASK_zsyr2k(const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,      &uplo,                sizeof(int),
         STARPU_VALUE,     &trans,                sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zsyrk.c b/runtime/starpu/codelets/codelet_zsyrk.c
index 78874feba..68eb97b3c 100644
--- a/runtime/starpu/codelets/codelet_zsyrk.c
+++ b/runtime/starpu/codelets/codelet_zsyrk.c
@@ -155,6 +155,7 @@ void INSERT_TASK_zsyrk( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_zsyrk,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_zsyrk_args_s),
diff --git a/runtime/starpu/codelets/codelet_zsyssq.c b/runtime/starpu/codelets/codelet_zsyssq.c
index cf710e468..63d22d8d4 100644
--- a/runtime/starpu/codelets/codelet_zsyssq.c
+++ b/runtime/starpu/codelets/codelet_zsyssq.c
@@ -59,6 +59,7 @@ void INSERT_TASK_zsyssq( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &storev,                     sizeof(cham_store_t),
         STARPU_VALUE,    &uplo,                       sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zsytrf_nopiv.c b/runtime/starpu/codelets/codelet_zsytrf_nopiv.c
index 5882c5855..8e840bf83 100644
--- a/runtime/starpu/codelets/codelet_zsytrf_nopiv.c
+++ b/runtime/starpu/codelets/codelet_zsytrf_nopiv.c
@@ -61,6 +61,7 @@ void INSERT_TASK_zsytrf_nopiv( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &uplo,                      sizeof(int),
         STARPU_VALUE,    &n,                         sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_ztplqt.c b/runtime/starpu/codelets/codelet_ztplqt.c
index 3471d4878..e9c8f78ca 100644
--- a/runtime/starpu/codelets/codelet_ztplqt.c
+++ b/runtime/starpu/codelets/codelet_ztplqt.c
@@ -67,6 +67,7 @@ void INSERT_TASK_ztplqt( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE, &M,     sizeof(int),
         STARPU_VALUE, &N,     sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_ztpmlqt.c b/runtime/starpu/codelets/codelet_ztpmlqt.c
index fb2db26e4..57733a115 100644
--- a/runtime/starpu/codelets/codelet_ztpmlqt.c
+++ b/runtime/starpu/codelets/codelet_ztpmlqt.c
@@ -109,6 +109,7 @@ void INSERT_TASK_ztpmlqt( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE, &side,  sizeof(int),
         STARPU_VALUE, &trans, sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_ztpmqrt.c b/runtime/starpu/codelets/codelet_ztpmqrt.c
index bab1d8d0a..6930734f8 100644
--- a/runtime/starpu/codelets/codelet_ztpmqrt.c
+++ b/runtime/starpu/codelets/codelet_ztpmqrt.c
@@ -109,6 +109,7 @@ void INSERT_TASK_ztpmqrt( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE, &side,  sizeof(int),
         STARPU_VALUE, &trans, sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_ztpqrt.c b/runtime/starpu/codelets/codelet_ztpqrt.c
index 0ade7095a..c65c93bcf 100644
--- a/runtime/starpu/codelets/codelet_ztpqrt.c
+++ b/runtime/starpu/codelets/codelet_ztpqrt.c
@@ -68,6 +68,7 @@ void INSERT_TASK_ztpqrt( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE, &M,     sizeof(int),
         STARPU_VALUE, &N,     sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_ztradd.c b/runtime/starpu/codelets/codelet_ztradd.c
index 57b146d6a..788873cfd 100644
--- a/runtime/starpu/codelets/codelet_ztradd.c
+++ b/runtime/starpu/codelets/codelet_ztradd.c
@@ -95,6 +95,7 @@ void INSERT_TASK_ztradd( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_ztradd,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_ztradd_args_s),
diff --git a/runtime/starpu/codelets/codelet_ztrasm.c b/runtime/starpu/codelets/codelet_ztrasm.c
index c5412d416..271a6f679 100644
--- a/runtime/starpu/codelets/codelet_ztrasm.c
+++ b/runtime/starpu/codelets/codelet_ztrasm.c
@@ -62,6 +62,7 @@ void INSERT_TASK_ztrasm( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &storev,                    sizeof(int),
         STARPU_VALUE,    &uplo,                      sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_ztrmm.c b/runtime/starpu/codelets/codelet_ztrmm.c
index a5f2a1877..42160f4c6 100644
--- a/runtime/starpu/codelets/codelet_ztrmm.c
+++ b/runtime/starpu/codelets/codelet_ztrmm.c
@@ -145,6 +145,7 @@ void INSERT_TASK_ztrmm( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_ztrmm,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_ztrmm_args_s),
diff --git a/runtime/starpu/codelets/codelet_ztrsm.c b/runtime/starpu/codelets/codelet_ztrsm.c
index 00d38429e..6d2baba8b 100644
--- a/runtime/starpu/codelets/codelet_ztrsm.c
+++ b/runtime/starpu/codelets/codelet_ztrsm.c
@@ -149,6 +149,7 @@ void INSERT_TASK_ztrsm( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_ztrsm,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_ztrsm_args_s),
diff --git a/runtime/starpu/codelets/codelet_ztrssq.c b/runtime/starpu/codelets/codelet_ztrssq.c
index 9d8003194..a0ecb6757 100644
--- a/runtime/starpu/codelets/codelet_ztrssq.c
+++ b/runtime/starpu/codelets/codelet_ztrssq.c
@@ -61,6 +61,7 @@ void INSERT_TASK_ztrssq( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &uplo,                      sizeof(int),
         STARPU_VALUE,    &diag,                      sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_ztrtri.c b/runtime/starpu/codelets/codelet_ztrtri.c
index 4918849af..c6b191910 100644
--- a/runtime/starpu/codelets/codelet_ztrtri.c
+++ b/runtime/starpu/codelets/codelet_ztrtri.c
@@ -93,6 +93,7 @@ void INSERT_TASK_ztrtri( const RUNTIME_option_t *options,
 
     /* Insert the task */
     rt_starpu_insert_task(
+        options->sequence->comm,
         &cl_ztrtri,
         /* Task codelet arguments */
         STARPU_CL_ARGS, clargs, sizeof(struct cl_ztrtri_args_s),
diff --git a/runtime/starpu/codelets/codelet_ztsmlq_hetra1.c b/runtime/starpu/codelets/codelet_ztsmlq_hetra1.c
index 05510b059..883ffc013 100644
--- a/runtime/starpu/codelets/codelet_ztsmlq_hetra1.c
+++ b/runtime/starpu/codelets/codelet_ztsmlq_hetra1.c
@@ -86,6 +86,7 @@ void INSERT_TASK_ztsmlq_hetra1( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &side,              sizeof(int),
         STARPU_VALUE,    &trans,             sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_ztsmqr_hetra1.c b/runtime/starpu/codelets/codelet_ztsmqr_hetra1.c
index be370a887..8ee421741 100644
--- a/runtime/starpu/codelets/codelet_ztsmqr_hetra1.c
+++ b/runtime/starpu/codelets/codelet_ztsmqr_hetra1.c
@@ -86,6 +86,7 @@ void INSERT_TASK_ztsmqr_hetra1( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &side,              sizeof(int),
         STARPU_VALUE,    &trans,             sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_ztstrf.c b/runtime/starpu/codelets/codelet_ztstrf.c
index 4839c0d5a..b7c5f6895 100644
--- a/runtime/starpu/codelets/codelet_ztstrf.c
+++ b/runtime/starpu/codelets/codelet_ztstrf.c
@@ -91,6 +91,7 @@ void INSERT_TASK_ztstrf( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &m,                         sizeof(int),
         STARPU_VALUE,    &n,                         sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zunmlq.c b/runtime/starpu/codelets/codelet_zunmlq.c
index db6b3726e..bc39c8dd2 100644
--- a/runtime/starpu/codelets/codelet_zunmlq.c
+++ b/runtime/starpu/codelets/codelet_zunmlq.c
@@ -111,6 +111,7 @@ void INSERT_TASK_zunmlq( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &side,              sizeof(int),
         STARPU_VALUE,    &trans,             sizeof(int),
diff --git a/runtime/starpu/codelets/codelet_zunmqr.c b/runtime/starpu/codelets/codelet_zunmqr.c
index 657c6ca87..0b7aa9233 100644
--- a/runtime/starpu/codelets/codelet_zunmqr.c
+++ b/runtime/starpu/codelets/codelet_zunmqr.c
@@ -110,6 +110,7 @@ void INSERT_TASK_zunmqr( const RUNTIME_option_t *options,
     CHAMELEON_END_ACCESS_DECLARATION;
 
     rt_starpu_insert_task(
+        options->sequence->comm,
         codelet,
         STARPU_VALUE,    &side,              sizeof(int),
         STARPU_VALUE,    &trans,             sizeof(int),
diff --git a/runtime/starpu/control/runtime_async.c b/runtime/starpu/control/runtime_async.c
index 5e4f87e6b..2f06fb4c0 100644
--- a/runtime/starpu/control/runtime_async.c
+++ b/runtime/starpu/control/runtime_async.c
@@ -28,7 +28,7 @@ int RUNTIME_sequence_create( CHAM_context_t  *chamctxt,
                              RUNTIME_sequence_t *sequence )
 {
     (void)chamctxt;
-    (void)sequence;
+    sequence->comm = chamctxt->comm;
     return CHAMELEON_SUCCESS;
 }
 
@@ -58,10 +58,10 @@ int RUNTIME_sequence_wait( CHAM_context_t     *chamctxt,
 
 #if defined(CHAMELEON_USE_MPI)
 #  if defined(HAVE_STARPU_MPI_WAIT_FOR_ALL)
-    starpu_mpi_wait_for_all(MPI_COMM_WORLD);
+    starpu_mpi_wait_for_all(sequence->comm);
 #  else
     starpu_task_wait_for_all();
-    starpu_mpi_barrier(MPI_COMM_WORLD);
+    starpu_mpi_barrier(sequence->comm);
 #  endif
 #else
     starpu_task_wait_for_all();
diff --git a/runtime/starpu/control/runtime_control.c b/runtime/starpu/control/runtime_control.c
index 62c89a00f..07b67944f 100644
--- a/runtime/starpu/control/runtime_control.c
+++ b/runtime/starpu/control/runtime_control.c
@@ -100,7 +100,7 @@ void chameleon_starpu_parallel_worker_fini( starpu_sched_opt_t *sched_opt )
 /**
  *
  */
-static int chameleon_starpu_init( struct starpu_conf *conf )
+static int chameleon_starpu_init( MPI_Comm comm, struct starpu_conf *conf )
 {
     int hres = CHAMELEON_SUCCESS;
     int rc;
@@ -118,7 +118,7 @@ static int chameleon_starpu_init( struct starpu_conf *conf )
 #  endif
 
 #  if defined(HAVE_STARPU_MPI_INIT_CONF)
-        rc = starpu_mpi_init_conf(NULL, NULL, !flag, MPI_COMM_WORLD, conf);
+        rc = starpu_mpi_init_conf(NULL, NULL, !flag, comm, conf);
 #  else
         rc = starpu_init(conf);
         if (rc < 0) {
@@ -186,7 +186,7 @@ int RUNTIME_init( CHAM_context_t *chamctxt,
 
     if ((ncpus == -1)||(nthreads_per_worker == -1))
     {
-        hres = chameleon_starpu_init( conf );
+        hres = chameleon_starpu_init( chamctxt->comm, conf );
 
         chamctxt->nworkers = ncpus;
         chamctxt->nthreads_per_worker = nthreads_per_worker;
@@ -202,7 +202,7 @@ int RUNTIME_init( CHAM_context_t *chamctxt,
 
         conf->use_explicit_workers_bindid = 1;
 
-        hres = chameleon_starpu_init( conf );
+        hres = chameleon_starpu_init( chamctxt->comm, conf );
 
         chamctxt->nworkers = ncpus;
         chamctxt->nthreads_per_worker = nthreads_per_worker;
@@ -300,11 +300,11 @@ void RUNTIME_barrier( CHAM_context_t *chamctxt )
 
 #if defined(CHAMELEON_USE_MPI)
 #  if defined(HAVE_STARPU_MPI_WAIT_FOR_ALL)
-    starpu_mpi_wait_for_all(MPI_COMM_WORLD);
-    starpu_mpi_barrier(MPI_COMM_WORLD);
+    starpu_mpi_wait_for_all(chamctxt->comm);
+    starpu_mpi_barrier(chamctxt->comm);
 #  else
     starpu_task_wait_for_all();
-    starpu_mpi_barrier(MPI_COMM_WORLD);
+    starpu_mpi_barrier(chamctxt->comm);
 #  endif
 #else
     starpu_task_wait_for_all();
@@ -380,13 +380,12 @@ int RUNTIME_comm_rank( CHAM_context_t *chamctxt )
 
 #if defined(CHAMELEON_USE_MPI)
 #  if defined(HAVE_STARPU_MPI_COMM_RANK)
-    starpu_mpi_comm_rank( MPI_COMM_WORLD, &rank );
+    starpu_mpi_comm_rank( chamctxt->comm, &rank );
 #  else
-    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
+    MPI_Comm_rank( chamctxt->comm, &rank );
 #  endif
 #endif
 
-    (void)chamctxt;
     return rank;
 }
 
@@ -398,15 +397,14 @@ int RUNTIME_comm_size( CHAM_context_t *chamctxt )
     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( chamctxt->comm, &size );
 #  else
-    MPI_Comm_size( MPI_COMM_WORLD, &size );
+    MPI_Comm_size( chamctxt->comm, &size );
 #  endif
 #else
     size = 1;
 #endif
 
-    (void)chamctxt;
     return size;
 }
 
diff --git a/runtime/starpu/control/runtime_descriptor.c b/runtime/starpu/control/runtime_descriptor.c
index 2ed4ba05a..64ba0bb05 100644
--- a/runtime/starpu/control/runtime_descriptor.c
+++ b/runtime/starpu/control/runtime_descriptor.c
@@ -267,10 +267,10 @@ int RUNTIME_desc_release( const CHAM_desc_t *desc )
 /**
  *  Flush cached data
  */
-void RUNTIME_flush()
+void RUNTIME_flush( CHAM_context_t *chamctxt )
 {
 #if defined(CHAMELEON_USE_MPI)
-    starpu_mpi_cache_flush_all_data(MPI_COMM_WORLD);
+    starpu_mpi_cache_flush_all_data(chamctxt->comm);
 #endif
 }
 
@@ -317,7 +317,7 @@ void RUNTIME_data_flush( const RUNTIME_sequence_t *sequence,
         }
 
 #if defined(CHAMELEON_USE_MPI)
-        starpu_mpi_cache_flush( MPI_COMM_WORLD, *handlebis );
+        starpu_mpi_cache_flush( sequence->comm, *handlebis );
 #endif
 
         if ( local ) {
@@ -345,7 +345,7 @@ void RUNTIME_data_migrate( const RUNTIME_sequence_t *sequence,
     old_rank = starpu_mpi_data_get_rank( lhandle );
 
     if ( old_rank != new_rank ) {
-        starpu_mpi_data_migrate( MPI_COMM_WORLD, lhandle, new_rank );
+        starpu_mpi_data_migrate( sequence->comm, lhandle, new_rank );
     }
 
     (void)sequence;
diff --git a/runtime/starpu/control/runtime_descriptor_ipiv.c b/runtime/starpu/control/runtime_descriptor_ipiv.c
index f7a651922..088b7d44a 100644
--- a/runtime/starpu/control/runtime_descriptor_ipiv.c
+++ b/runtime/starpu/control/runtime_descriptor_ipiv.c
@@ -223,7 +223,7 @@ void RUNTIME_ipiv_flushk( const RUNTIME_sequence_t *sequence,
 
     if ( *handle != NULL ) {
 #if defined(CHAMELEON_USE_MPI)
-        starpu_mpi_cache_flush( MPI_COMM_WORLD, *handle );
+        starpu_mpi_cache_flush( sequence->comm, *handle );
         if ( starpu_mpi_data_get_rank( *handle ) == A->myrank )
 #endif
         {
@@ -236,7 +236,7 @@ void RUNTIME_ipiv_flushk( const RUNTIME_sequence_t *sequence,
 
     if ( *handle != NULL ) {
 #if defined(CHAMELEON_USE_MPI)
-        starpu_mpi_cache_flush( MPI_COMM_WORLD, *handle );
+        starpu_mpi_cache_flush( sequence->comm, *handle );
         if ( starpu_mpi_data_get_rank( *handle ) == A->myrank )
 #endif
         {
@@ -272,7 +272,7 @@ void RUNTIME_perm_flushk( const RUNTIME_sequence_t *sequence,
 
     if ( *handle != NULL ) {
 #if defined(CHAMELEON_USE_MPI)
-        starpu_mpi_cache_flush( MPI_COMM_WORLD, *handle );
+        starpu_mpi_cache_flush( sequence->comm, *handle );
         if ( starpu_mpi_data_get_rank( *handle ) == A->myrank )
 #endif
         {
@@ -285,7 +285,7 @@ void RUNTIME_perm_flushk( const RUNTIME_sequence_t *sequence,
 
     if ( *handle != NULL ) {
 #if defined(CHAMELEON_USE_MPI)
-        starpu_mpi_cache_flush( MPI_COMM_WORLD, *handle );
+        starpu_mpi_cache_flush( sequence->comm, *handle );
         if ( starpu_mpi_data_get_rank( *handle ) == A->myrank )
 #endif
         {
@@ -307,7 +307,7 @@ void RUNTIME_ipiv_reducek( const RUNTIME_option_t *options,
     if ( h < ipiv->n ) {
 #if defined(HAVE_STARPU_MPI_REDUX) && defined(CHAMELEON_USE_MPI)
 #if !defined(HAVE_STARPU_MPI_REDUX_WRAPUP)
-        starpu_mpi_redux_data_prio_tree( MPI_COMM_WORLD, nextpiv,
+        starpu_mpi_redux_data_prio_tree( options->sequence->comm, nextpiv,
                                          options->priority, 2 /* Binary tree */ );
 #endif
 #endif
@@ -343,7 +343,8 @@ struct starpu_codelet cl_ipiv_init = {
     .nbuffers  = 1,
 };
 
-void RUNTIME_ipiv_init( CHAM_ipiv_t *ipiv )
+void RUNTIME_ipiv_init( const RUNTIME_sequence_t *sequence,
+                        CHAM_ipiv_t *ipiv )
 {
     int64_t mt = ipiv->mt;
     int64_t mb = ipiv->mb;
@@ -355,6 +356,7 @@ void RUNTIME_ipiv_init( CHAM_ipiv_t *ipiv )
         int n  = (m == (mt-1)) ? ipiv->m - m0 : mb;
 
         rt_starpu_insert_task(
+            sequence->comm,
             &cl_ipiv_init,
             STARPU_VALUE, &m0, sizeof(int),
             STARPU_VALUE, &n,  sizeof(int),
@@ -368,6 +370,7 @@ void RUNTIME_ipiv_gather( CHAM_ipiv_t *desc, int *ipiv, int node )
     int64_t mt   = desc->mt;
     int64_t mb   = desc->mb;
     int64_t tag  = chameleon_starpu_tag_book( (int64_t)(desc->mt) );
+    CHAM_context_t *chamctxt = chameleon_context_self();
     int     rank = CHAMELEON_Comm_rank();
     int     owner = rank;
     int     m;
@@ -387,7 +390,7 @@ void RUNTIME_ipiv_gather( CHAM_ipiv_t *desc, int *ipiv, int node )
                 if (already_received == 0)
                 {
                     MPI_Status status;
-                    starpu_mpi_recv( ipiv_src, owner, tag, MPI_COMM_WORLD, &status );
+                    starpu_mpi_recv( ipiv_src, owner, tag, chamctxt->comm, &status );
                 }
             }
             else if ( rank == owner )
@@ -396,7 +399,7 @@ void RUNTIME_ipiv_gather( CHAM_ipiv_t *desc, int *ipiv, int node )
                 int already_sent = starpu_mpi_cached_send_set( ipiv_src, node );
                 if (already_sent == 0)
                 {
-                    starpu_mpi_send( ipiv_src, node, tag, MPI_COMM_WORLD );
+                    starpu_mpi_send( ipiv_src, node, tag, chamctxt->comm );
                 }
             }
         }
diff --git a/runtime/starpu/control/runtime_tags.c b/runtime/starpu/control/runtime_tags.c
index 31cc94090..e966c461b 100644
--- a/runtime/starpu/control/runtime_tags.c
+++ b/runtime/starpu/control/runtime_tags.c
@@ -58,7 +58,8 @@ chameleon_starpu_tag_init( void )
         int          ok       = 0;
         void        *tag_ub_p = NULL;
 
-        starpu_mpi_comm_get_attr( MPI_COMM_WORLD, STARPU_MPI_TAG_UB, &tag_ub_p, &ok );
+        CHAM_context_t *chamctxt = chameleon_context_self();
+        starpu_mpi_comm_get_attr( chamctxt->comm, STARPU_MPI_TAG_UB, &tag_ub_p, &ok );
         starpu_tag_ub = (uint64_t)((intptr_t)tag_ub_p);
 
         if ( !ok ) {
diff --git a/runtime/starpu/include/chameleon_starpu.h.in b/runtime/starpu/include/chameleon_starpu.h.in
index bd3123ab5..b5840fc1b 100644
--- a/runtime/starpu/include/chameleon_starpu.h.in
+++ b/runtime/starpu/include/chameleon_starpu.h.in
@@ -129,20 +129,20 @@ void *RUNTIME_data_getaddr_withconversion( const RUNTIME_option_t *options,
 #if defined(CHAMELEON_USE_MPI)
 
 #if defined(CHAMELEON_RUNTIME_SYNC)
-#define rt_starpu_insert_task( _codelet_, ... )                         \
-    starpu_mpi_insert_task( MPI_COMM_WORLD, (_codelet_), STARPU_TASK_SYNCHRONOUS, 1, ##__VA_ARGS__ )
+#define rt_starpu_insert_task( _comm_, _codelet_, ... )                         \
+    starpu_mpi_insert_task( (_comm_), (_codelet_), STARPU_TASK_SYNCHRONOUS, 1, ##__VA_ARGS__ )
 #else
-#define rt_starpu_insert_task( _codelet_, ... )                         \
-    starpu_mpi_insert_task( MPI_COMM_WORLD, (_codelet_), ##__VA_ARGS__ )
+#define rt_starpu_insert_task( _comm_, _codelet_, ... )                         \
+    starpu_mpi_insert_task( (_comm_), (_codelet_), ##__VA_ARGS__ )
 #endif
 
 #else
 
 #if defined(CHAMELEON_RUNTIME_SYNC)
-#define rt_starpu_insert_task( _codelet_, ... )                         \
+#define rt_starpu_insert_task( _comm_, _codelet_, ... )                         \
     starpu_insert_task( (_codelet_), STARPU_TASK_SYNCHRONOUS, 1, ##__VA_ARGS__ )
 #else
-#define rt_starpu_insert_task( _codelet_, ... )                         \
+#define rt_starpu_insert_task( _comm_, _codelet_, ... )                         \
     starpu_insert_task( (_codelet_), ##__VA_ARGS__ )
 #endif
 
-- 
GitLab