From bed0c36525736448f66e7e6b98082ba4fd1077f3 Mon Sep 17 00:00:00 2001
From: Chen Wang <wangvsa@gmail.com>
Date: Mon, 30 Dec 2024 12:03:43 -0800
Subject: [PATCH 1/3] Remove confusing outputs

Signed-off-by: Chen Wang <wangvsa@gmail.com>
---
 src/dyad/modules/dyad.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/dyad/modules/dyad.c b/src/dyad/modules/dyad.c
index 803828b1..0b54941d 100644
--- a/src/dyad/modules/dyad.c
+++ b/src/dyad/modules/dyad.c
@@ -429,6 +429,9 @@ dyad_rc_t dyad_module_ctx_init (const opt_parse_out_t *opt, flux_t *h)
         return DYAD_RC_NOCTX;
     }
 
+    // DYAD can be configured via environment variables
+    // and users can override the settings through command
+    // line arguments.
     if (opt->prod_managed_path) {
         setenv (DYAD_PATH_PRODUCER_ENV, opt->prod_managed_path, 1);
         const mode_t m = (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH | S_ISGID);
@@ -438,20 +441,15 @@ dyad_rc_t dyad_module_ctx_init (const opt_parse_out_t *opt, flux_t *h)
 
     if (opt->dtl_mode) {
         setenv (DYAD_DTL_MODE_ENV, opt->dtl_mode, 1);
-        DYAD_LOG_STDERR ("DYAD_MOD: DTL 'mode' option set. Setting env %s=%s\n",
+        DYAD_LOG_STDERR ("DYAD_MOD: DTL mode option set. Setting env %s=%s\n",
                          DYAD_DTL_MODE_ENV,
                          opt->dtl_mode);
-    } else {
-        DYAD_LOG_STDERR ("DYAD_MOD: Did not find DTL 'mode' option. Using env %s=%s\n",
-                         DYAD_DTL_MODE_ENV,
-                         getenv (DYAD_DTL_MODE_ENV));
     }
 
     char *kvs_namespace = getenv ("DYAD_KVS_NAMESPACE");
     if (kvs_namespace != NULL) {
         DYAD_LOG_STDERR ("DYAD_MOD: DYAD_KVS_NAMESPACE is set to `%s'\n", kvs_namespace);
     } else {
-        DYAD_LOG_STDERR ("DYAD_MOD: DYAD_KVS_NAMESPACE is not set\n");
         // Required so that dyad_ctx_init can pass
         // TODO: figure out a better for this.
         setenv (DYAD_KVS_NAMESPACE_ENV, "dyad_module_dummy_env", 1);

From 90e347ca30b361e96bdc5f7c41af8becab9fdc3d Mon Sep 17 00:00:00 2001
From: Chen Wang <wangvsa@gmail.com>
Date: Mon, 30 Dec 2024 12:11:44 -0800
Subject: [PATCH 2/3] Debug information should be outputed to STDOUT

Signed-off-by: Chen Wang <wangvsa@gmail.com>
---
 src/dyad/modules/dyad.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/dyad/modules/dyad.c b/src/dyad/modules/dyad.c
index 0b54941d..4aeee532 100644
--- a/src/dyad/modules/dyad.c
+++ b/src/dyad/modules/dyad.c
@@ -411,7 +411,6 @@ int opt_parse (opt_parse_out_t *restrict opt,
     // Retrive the remaining command line argument (not options).
     // it is expected to be the producer managed directory
     while (optind < _argc) {
-        DYAD_LOG_STDERR ("DYAD_MOD: positional arguments %s\n", _argv[optind]);
         prod_managed_path = _argv[optind++];
     }
     opt->prod_managed_path = prod_managed_path;
@@ -436,19 +435,19 @@ dyad_rc_t dyad_module_ctx_init (const opt_parse_out_t *opt, flux_t *h)
         setenv (DYAD_PATH_PRODUCER_ENV, opt->prod_managed_path, 1);
         const mode_t m = (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH | S_ISGID);
         mkdir_as_needed (opt->prod_managed_path, m);
-        DYAD_LOG_STDERR ("DYAD_MOD: Loading DYAD Module with Path %s\n", opt->prod_managed_path);
+        DYAD_LOG_STDOUT ("DYAD_MOD: Loading DYAD Module with Path %s\n", opt->prod_managed_path);
     }
 
     if (opt->dtl_mode) {
         setenv (DYAD_DTL_MODE_ENV, opt->dtl_mode, 1);
-        DYAD_LOG_STDERR ("DYAD_MOD: DTL mode option set. Setting env %s=%s\n",
+        DYAD_LOG_STDOUT ("DYAD_MOD: DTL mode option set. Setting env %s=%s\n",
                          DYAD_DTL_MODE_ENV,
                          opt->dtl_mode);
     }
 
     char *kvs_namespace = getenv ("DYAD_KVS_NAMESPACE");
     if (kvs_namespace != NULL) {
-        DYAD_LOG_STDERR ("DYAD_MOD: DYAD_KVS_NAMESPACE is set to `%s'\n", kvs_namespace);
+        DYAD_LOG_STDOUT ("DYAD_MOD: DYAD_KVS_NAMESPACE is set to `%s'\n", kvs_namespace);
     } else {
         // Required so that dyad_ctx_init can pass
         // TODO: figure out a better for this.

From 2e499caac229f09c131520aca1c09f6a962f6608 Mon Sep 17 00:00:00 2001
From: Chen Wang <wangvsa@gmail.com>
Date: Mon, 30 Dec 2024 14:04:27 -0800
Subject: [PATCH 3/3] Remove unused variable

Signed-off-by: Chen Wang <wangvsa@gmail.com>
---
 src/dyad/modules/dyad.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/src/dyad/modules/dyad.c b/src/dyad/modules/dyad.c
index 4aeee532..e21c301e 100644
--- a/src/dyad/modules/dyad.c
+++ b/src/dyad/modules/dyad.c
@@ -309,7 +309,6 @@ typedef struct opt_parse_out opt_parse_out_t;
 
 int opt_parse (opt_parse_out_t *restrict opt,
                const unsigned broker_rank,
-               dyad_dtl_mode_t *restrict dtl_mode,
                int argc,
                char **restrict argv)
 {
@@ -319,7 +318,6 @@ int opt_parse (opt_parse_out_t *restrict opt,
     sprintf (log_file_name, "dyad_mod_%u.out", broker_rank);
     sprintf (err_file_name, "dyad_mod_%d.err", broker_rank);
 #endif  // DYAD_LOGGER_NO_LOG
-    *dtl_mode = DYAD_DTL_END;
 
     int rc = DYAD_RC_OK;
     char *prod_managed_path = NULL;
@@ -335,7 +333,7 @@ int opt_parse (opt_parse_out_t *restrict opt,
     // argv[0] to be the executable name, so it starts
     // checking from optind = 1.
     // since Flux module argv doesn't contain the executable
-    // name as its first argument, we need to create a dummy
+    // name in its first argument, we need to create a dummy
     // _argc and _argv here for getopt() to work properly.
     extern int optind;
     optind = 1;
@@ -343,7 +341,7 @@ int opt_parse (opt_parse_out_t *restrict opt,
     char **_argv = malloc (sizeof (char *) * _argc);
     _argv[0] = NULL;
     for (int i = 1; i < _argc; i++) {
-        // we will reuse the same same string in argv[].
+        // we will reuse the same string in argv[].
         _argv[i] = argv[i - 1];
     }
 
@@ -372,10 +370,7 @@ int opt_parse (opt_parse_out_t *restrict opt,
                 // mode as the option, then skip reinitializing
                 DYAD_LOG_STDERR ("DYAD_MOD: DTL 'mode' option -m with value `%s'\n", optarg);
                 opt->dtl_mode = optarg;
-                if (strcmp ("UCX", optarg) == 0)
-                    *dtl_mode = DYAD_DTL_UCX;
-                else if (strcmp ("FLUX_RPC", optarg) == 0)
-                    *dtl_mode = DYAD_DTL_FLUX_RPC;
+                // TODO: check if the user specified dtl_mode is valid.
                 break;
             case 'i':
 #ifndef DYAD_LOGGER_NO_LOG
@@ -404,10 +399,6 @@ int opt_parse (opt_parse_out_t *restrict opt,
     DYAD_LOG_STDERR_REDIRECT (err_file_name);
 #endif  // DYAD_LOGGER_NO_LOG
 
-    if (*dtl_mode == DYAD_DTL_END) {
-        opt->dtl_mode = NULL;
-    }
-
     // Retrive the remaining command line argument (not options).
     // it is expected to be the producer managed directory
     while (optind < _argc) {
@@ -487,7 +478,6 @@ DYAD_DLL_EXPORTED int mod_main (flux_t *h, int argc, char **argv)
     DYAD_LOGGER_INIT ();
     DYAD_LOG_STDOUT ("DYAD_MOD: Loading mod_main\n");
     dyad_mod_ctx_t *mod_ctx = NULL;
-    dyad_dtl_mode_t dtl_mode = DYAD_DTL_DEFAULT;
 
     if (!h) {
         DYAD_LOG_STDERR ("DYAD_MOD: Failed to get flux handle\n");
@@ -507,7 +497,7 @@ DYAD_DLL_EXPORTED int mod_main (flux_t *h, int argc, char **argv)
     opt_parse_out_t opt = {NULL, NULL, false, false};
     DYAD_LOG_STDOUT ("DYAD_MOD: Parsing command line options\n");
 
-    if (DYAD_IS_ERROR (opt_parse (&opt, broker_rank, &dtl_mode, argc, argv))) {
+    if (DYAD_IS_ERROR (opt_parse (&opt, broker_rank, argc, argv))) {
         DYAD_LOG_STDERR ("DYAD_MOD: Cannot parse command line arguments\n");
         goto mod_error;
     }