From b877f3693acbfced1752e27345dbb30d09f5fb58 Mon Sep 17 00:00:00 2001
From: Guillaume Sylvand <guillaume.sylvand@airbus.com>
Date: Sat, 29 Oct 2016 12:34:33 +0000
Subject: [PATCH] Add new call MORSE_user_tag_size(int user_tag_width, int
 user_tag_sep)

to change the default values for tag_width(=31) and tag_sep(=24).
Today, it serves only with starPU.
---
 control/descriptor.c                        | 28 +++++++++++++++++++++
 include/morse.h.in                          |  1 +
 include/runtime.h                           |  1 +
 runtime/parsec/control/runtime_descriptor.c |  5 ++++
 runtime/quark/control/runtime_descriptor.c  |  5 ++++
 runtime/starpu/control/runtime_descriptor.c | 15 ++++++++---
 6 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/control/descriptor.c b/control/descriptor.c
index 70472522f..6f6673618 100644
--- a/control/descriptor.c
+++ b/control/descriptor.c
@@ -581,3 +581,31 @@ int MORSE_Desc_Release (MORSE_desc_t  *desc) {
 int MORSE_Desc_Getoncpu(MORSE_desc_t  *desc) {
   return RUNTIME_desc_getoncpu( desc );
 }
+
+/** ***************************************************************************
+ *
+ * @ingroup Descriptor
+ *
+ *  MORSE_user_tag_size - Set the sizes for the MPI tags
+ *  Default value: tag_width=31, tag_sep=24, meaning that the MPI tag is stored in 31 bits,
+ *  with 24 bits for the tile tag and 7 for the descriptor.
+ *  This function must be called before any descriptor creation.
+ *
+ ******************************************************************************
+ *
+ * @param[in] user_tag_width
+ *          The new value for tag_width.
+ *
+ * @param[in] user_tag_sep
+ *          The new value for tag_sep.
+ *
+ ******************************************************************************
+ *
+ * @return
+ *          \retval none
+ *
+ *****************************************************************************/
+void MORSE_user_tag_size(int user_tag_width, int user_tag_sep) {
+  RUNTIME_user_tag_size(user_tag_width, user_tag_sep);
+  return;
+}
diff --git a/include/morse.h.in b/include/morse.h.in
index f1e5d57b9..c5a0edfe2 100644
--- a/include/morse.h.in
+++ b/include/morse.h.in
@@ -96,6 +96,7 @@ int MORSE_Desc_Destroy (MORSE_desc_t **desc);
 int MORSE_Desc_Acquire (MORSE_desc_t  *desc);
 int MORSE_Desc_Release (MORSE_desc_t  *desc);
 int MORSE_Desc_Getoncpu(MORSE_desc_t  *desc);
+void MORSE_user_tag_size(int, int) ;
 
 /* Workspaces */
 int MORSE_Dealloc_Workspace (MORSE_desc_t **desc);
diff --git a/include/runtime.h b/include/runtime.h
index 6cd6c2a14..eeea0e3f4 100644
--- a/include/runtime.h
+++ b/include/runtime.h
@@ -72,6 +72,7 @@ int   RUNTIME_desc_acquire     (MORSE_desc_t*);
 /* Release the data described by the descriptor to be used by the StarPU tasks again. */
 int   RUNTIME_desc_release     (MORSE_desc_t*);
 int   RUNTIME_desc_getoncpu    (MORSE_desc_t*);
+void  RUNTIME_user_tag_size    (int, int) ;
 
 /*******************************************************************************
  * RUNTIME Options
diff --git a/runtime/parsec/control/runtime_descriptor.c b/runtime/parsec/control/runtime_descriptor.c
index 2a471292b..c9b40556e 100644
--- a/runtime/parsec/control/runtime_descriptor.c
+++ b/runtime/parsec/control/runtime_descriptor.c
@@ -11,6 +11,11 @@
 #include "runtime/parsec/include/morse_parsec.h"
 #include <dague/data.h>
 
+void RUNTIME_user_tag_size(int user_tag_width, int user_tag_sep) {
+  (void)user_tag_width;
+  (void)user_tag_sep;
+}
+
 void *RUNTIME_mat_alloc( size_t size)
 {
     return malloc(size);
diff --git a/runtime/quark/control/runtime_descriptor.c b/runtime/quark/control/runtime_descriptor.c
index c16000fd4..ca5061b62 100644
--- a/runtime/quark/control/runtime_descriptor.c
+++ b/runtime/quark/control/runtime_descriptor.c
@@ -25,6 +25,11 @@
 #include <stdlib.h>
 #include "runtime/quark/include/morse_quark.h"
 
+void RUNTIME_user_tag_size(int user_tag_width, int user_tag_sep) {
+  (void)user_tag_width;
+  (void)user_tag_sep;
+}
+
 void *RUNTIME_mat_alloc( size_t size)
 {
     return malloc(size);
diff --git a/runtime/starpu/control/runtime_descriptor.c b/runtime/starpu/control/runtime_descriptor.c
index a0a95469f..6f8a68c99 100644
--- a/runtime/starpu/control/runtime_descriptor.c
+++ b/runtime/starpu/control/runtime_descriptor.c
@@ -28,10 +28,12 @@
 
 #if defined(CHAMELEON_USE_MPI)
 
-/* Take 24 bits for the tile id, and 7 bits for descriptor id */
+/* Take 24 bits for the tile id, and 7 bits for descriptor id.
+   These values can be changed through the call MORSE_user_tag_size(int tag_width, int tag_sep) */
 #define TAG_WIDTH_MIN 20
 static int tag_width = 31;
 static int tag_sep   = 24;
+static int _tag_mpi_initialized_ = 0;
 
 #ifndef HAVE_STARPU_MPI_DATA_REGISTER
 #define starpu_mpi_data_register( handle_, tag_, owner_ )        \
@@ -49,6 +51,15 @@ static int tag_sep   = 24;
 #define FOLDED 0
 #endif
 
+void RUNTIME_user_tag_size(int user_tag_width, int user_tag_sep) {
+  if (_tag_mpi_initialized_ == 0) {
+    tag_width=user_tag_width;
+    tag_sep=user_tag_sep;
+  } else
+    morse_error("RUNTIME_user_tag_size", "must be called before creating any Morse descriptor with MORSE_Desc_create(). The tag sizes will not be modified.");
+}
+
+
 void *RUNTIME_mat_alloc( size_t size)
 {
 #if defined(CHAMELEON_SIMULATION) && !defined(STARPU_MALLOC_SIMULATION_FOLDED) && !defined(CHAMELEON_USE_MPI)
@@ -111,8 +122,6 @@ void RUNTIME_desc_create( MORSE_desc_t *desc )
      * Check that we are not going over MPI tag limitations
      */
     {
-        static int _tag_mpi_initialized_ = 0;
-
         if (!_tag_mpi_initialized_) {
             int *tag_ub = NULL;
             int ok = 0;
-- 
GitLab