Enable launch-gasnetrun_ibv to pass CHPL_ environment variables

Several important environment variables, including
CHPL_RT_NUM_THREADS_PER_LOCALE, need to be passed on
to the spawned jobs. Unfortunately, with the
gasnetrun_ibv launcher using SSH (vs mpirun), these
important environment variables are not passed on.
The gasnetrun_ibv.pl script knows how to accept a -E option
which is followed by a comma-separated list of environment
variables that should be forwarded. This patch enables
the use of this -E option and generates a list of
environment variables that includes anything beginning
with CHPL_ . It does so with a hopefully more general-purpose
function, chpl_get_enviro_keys, which returns a string
containing environment variable names that should be
forwarded, separated by the passed character.

Index: runtime/include/chpllaunch.h
===================================================================
--- runtime/include/chpllaunch.h        (revision 22851)
+++ runtime/include/chpllaunch.h        (working copy)
@@ -16,6 +16,8 @@
                             const char* argv0);
  int chpl_launch_using_system(char* command, char* argv0);
  
+char* chpl_get_enviro_keys(char sep);
+
  void chpl_compute_real_binary_name(const char* argv0);
  const char* chpl_get_real_binary_name(void);
  
Index: runtime/src/main_launcher.c
===================================================================
--- runtime/src/main_launcher.c (revision 22851)
+++ runtime/src/main_launcher.c (working copy)
@@ -14,6 +14,8 @@
  #include "chpltypes.h"
  #include "error.h"
  
+// used in get_enviro_keys
+extern char** environ;
  
  // This global variable stores the arguments to main
  // that should be handled by the program.
@@ -258,7 +260,50 @@
    return system(command);
  }
  
+// This function returns a string containing a character-
+// separated list of environment variables that should be
+// forwarded.
  
+char* chpl_get_enviro_keys(char sep)
+{
+  int pass;
+  int i;
+  int j;
+  int k = 0;
+  char* ret = NULL;
+
+  for( pass = 0; pass < 2; pass++ ) {
+    k = 0;
+    for( i = 0; environ && environ[i]; i++ ) {
+      if( environ[i][0] == 'C' &&
+          environ[i][1] == 'H' &&
+          environ[i][2] == 'P' &&
+          environ[i][3] == 'L' &&
+          environ[i][4] == '_' ) {
+        // Count/store the separator
+        if( k > 0 ) {
+          if( pass == 0 ) k++;
+          else ret[k++] = sep;
+        }
+
+        for( j = 0; environ[i][j] && environ[i][j] != '='; j++ ) {
+          if( pass == 0 ) {
+            // on first pass, just count.
+            k++;
+          } else {
+            // on second pass, add to buffer.
+            ret[k++] = environ[i][j];
+          }
+        }
+      }
+    }
+    if( pass == 0 ) ret = chpl_mem_allocMany(k+1, sizeof(char),
+                                             CHPL_RT_MD_COMMAND_BUFFER, -1, 
"");
+  }
+
+  return ret;
+}
+
  int handleNonstandardArg(int* argc, char* argv[], int argNum,
                           int32_t lineno, chpl_string filename) {
    int numHandled = chpl_launch_handle_arg(*argc, argv, argNum,
Index: runtime/src/launch/gasnetrun_ibv/launch-gasnetrun_ibv.c
===================================================================
--- runtime/src/launch/gasnetrun_ibv/launch-gasnetrun_ibv.c     (revision 22851)
+++ runtime/src/launch/gasnetrun_ibv/launch-gasnetrun_ibv.c     (working copy)
@@ -14,13 +14,15 @@
  static char** chpl_launch_create_argv(const char *launch_cmd,
                                        int argc, char* argv[],
                                        int32_t numLocales) {
-  const int largc = 3;
+  const int largc = 5;
    char *largv[largc];
  
    largv[0] = (char *) launch_cmd;
    largv[1] = (char *) "-n";
    sprintf(_nlbuf, "%d", numLocales);
    largv[2] = _nlbuf;
+  largv[3] = (char*) "-E";
+  largv[4] = chpl_get_enviro_keys(',');
  
    return chpl_bundle_exec_args(argc, argv, largc, largv);
  }

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Chapel-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-developers

Reply via email to