4747#define CHPL_PARTITION_FLAG "--partition"
4848#define CHPL_EXCLUDE_FLAG "--exclude"
4949#define CHPL_GPUS_PER_NODE_FLAG "--gpus-per-node"
50+ #define CHPL_LAUNCHER_PASSTHROUGH_FLAG "--system-launcher-flags"
5051
5152#define CHPL_LPN_VAR "LOCALES_PER_NODE"
5253
@@ -56,6 +57,8 @@ static char* nodelist = NULL;
5657static char * partition = NULL ;
5758static char * exclude = NULL ;
5859static char * gpusPerNode = NULL ;
60+ static char * * launcherPassthroughFlags = NULL ;
61+ static int numLauncherPassthroughFlags = 0 ;
5962char * slurmFilename = NULL ;
6063
6164/* copies of binary to run per node */
@@ -70,6 +73,13 @@ typedef enum {
7073
7174static const char * nodeAccessStr = NULL ;
7275
76+ static void appendPassthroughFlag (char * * * array , int * size , const char * flag ) {
77+ * array = (char * * )chpl_mem_realloc (* array , (* size + 1 ) * sizeof (char * ),
78+ CHPL_RT_MD_COMMAND_BUFFER , -1 , 0 );
79+ (* array )[* size ] = (char * )string_copy ((char * )flag , -1 , 0 );
80+ (* size )++ ;
81+ }
82+
7383// Check what version of slurm is on the system
7484static sbatchVersion determineSlurmVersion (void ) {
7585 const int buflen = 256 ;
@@ -257,6 +267,12 @@ static char* chpl_launch_create_command(int argc, char* argv[],
257267 gpusPerNode = getenv ("CHPL_LAUNCHER_GPUS_PER_NODE" );
258268 }
259269
270+ // append any user specified passthrough flags to the list of flags to pass through
271+ char * passthroughFlagsEnv = getenv ("CHPL_LAUNCHER_PASSTHROUGH_FLAGS" );
272+ if (passthroughFlagsEnv ) {
273+ appendPassthroughFlag (& launcherPassthroughFlags , & numLauncherPassthroughFlags , passthroughFlagsEnv );
274+ }
275+
260276 // request exclusive node access by default, but allow user to override
261277 nodeAccessEnv = getenv ("CHPL_LAUNCHER_NODE_ACCESS" );
262278 if (nodeAccessEnv == NULL || strcmp (nodeAccessEnv , "exclusive" ) == 0 ) {
@@ -295,6 +311,13 @@ static char* chpl_launch_create_command(int argc, char* argv[],
295311 if (projectString && strlen (projectString ) > 0 )
296312 fprintf (slurmFile , "#SBATCH -A %s\n" , projectString );
297313
314+ // add any additional flags
315+ if (launcherPassthroughFlags != NULL ) {
316+ for (int i = 0 ; i < numLauncherPassthroughFlags ; i ++ ) {
317+ fprintf (slurmFile , "#SBATCH %s\n" , launcherPassthroughFlags [i ]);
318+ }
319+ }
320+
298321 if (outputfn != NULL )
299322 fprintf (slurmFile , "#SBATCH -o %s\n" , outputfn );
300323 else
@@ -345,6 +368,12 @@ static char* chpl_launch_create_command(int argc, char* argv[],
345368 if (projectString && strlen (projectString ) > 0 )
346369 chpl_append_to_cmd (& iCom , & len , "--account=%s " , projectString );
347370 if (constraint ) chpl_append_to_cmd (& iCom , & len , "-C %s" , constraint );
371+ // add any additional flags
372+ if (launcherPassthroughFlags != NULL ) {
373+ for (int i = 0 ; i < numLauncherPassthroughFlags ; i ++ ) {
374+ chpl_append_to_cmd (& iCom , & len , " %s" , launcherPassthroughFlags [i ]);
375+ }
376+ }
348377 chpl_append_to_cmd (& iCom , & len , " %s/%s/%s -n %d -N %d -c 0" ,
349378 CHPL_THIRD_PARTY , WRAP_TO_STR (LAUNCH_PATH ),
350379 GASNETRUN_LAUNCHER , numLocales , numNodes );
@@ -407,44 +436,53 @@ int chpl_launch_handle_arg(int argc, char* argv[], int argNum,
407436 if (!strcmp (argv [argNum ], CHPL_WALLTIME_FLAG )) {
408437 walltime = argv [argNum + 1 ];
409438 return 2 ;
410- } else if (!strncmp (argv [argNum ], CHPL_WALLTIME_FLAG "=" , strlen (CHPL_WALLTIME_FLAG ))) {
411- walltime = & (argv [argNum ][strlen (CHPL_WALLTIME_FLAG ) + 1 ]);
439+ } else if (!strncmp (argv [argNum ], CHPL_WALLTIME_FLAG "=" , strlen (CHPL_WALLTIME_FLAG "=" ))) {
440+ walltime = & (argv [argNum ][strlen (CHPL_WALLTIME_FLAG "=" ) ]);
412441 return 1 ;
413442 }
414443
415444 // handle --nodelist <nodelist> or --nodelist=<nodelist>
416445 if (!strcmp (argv [argNum ], CHPL_NODELIST_FLAG )) {
417446 nodelist = argv [argNum + 1 ];
418447 return 2 ;
419- } else if (!strncmp (argv [argNum ], CHPL_NODELIST_FLAG "=" , strlen (CHPL_NODELIST_FLAG ))) {
420- nodelist = & (argv [argNum ][strlen (CHPL_NODELIST_FLAG ) + 1 ]);
448+ } else if (!strncmp (argv [argNum ], CHPL_NODELIST_FLAG "=" , strlen (CHPL_NODELIST_FLAG "=" ))) {
449+ nodelist = & (argv [argNum ][strlen (CHPL_NODELIST_FLAG "=" ) ]);
421450 return 1 ;
422451 }
423452
424453 // handle --partition <partition> or --partition=<partition>
425454 if (!strcmp (argv [argNum ], CHPL_PARTITION_FLAG )) {
426455 partition = argv [argNum + 1 ];
427456 return 2 ;
428- } else if (!strncmp (argv [argNum ], CHPL_PARTITION_FLAG "=" , strlen (CHPL_PARTITION_FLAG ))) {
429- partition = & (argv [argNum ][strlen (CHPL_PARTITION_FLAG ) + 1 ]);
457+ } else if (!strncmp (argv [argNum ], CHPL_PARTITION_FLAG "=" , strlen (CHPL_PARTITION_FLAG "=" ))) {
458+ partition = & (argv [argNum ][strlen (CHPL_PARTITION_FLAG "=" ) ]);
430459 return 1 ;
431460 }
432461
433462 // handle --exclude <nodes> or --exclude=<nodes>
434463 if (!strcmp (argv [argNum ], CHPL_EXCLUDE_FLAG )) {
435464 exclude = argv [argNum + 1 ];
436465 return 2 ;
437- } else if (!strncmp (argv [argNum ], CHPL_EXCLUDE_FLAG "=" , strlen (CHPL_EXCLUDE_FLAG ))) {
438- exclude = & (argv [argNum ][strlen (CHPL_EXCLUDE_FLAG ) + 1 ]);
466+ } else if (!strncmp (argv [argNum ], CHPL_EXCLUDE_FLAG "=" , strlen (CHPL_EXCLUDE_FLAG "=" ))) {
467+ exclude = & (argv [argNum ][strlen (CHPL_EXCLUDE_FLAG "=" ) ]);
439468 return 1 ;
440469 }
441470
442471 // handle --gpus-per-node <gpus> or --gpus-per-node=<gpus>
443472 if (!strcmp (argv [argNum ], CHPL_GPUS_PER_NODE_FLAG )) {
444473 gpusPerNode = argv [argNum + 1 ];
445474 return 2 ;
446- } else if (!strncmp (argv [argNum ], CHPL_GPUS_PER_NODE_FLAG "=" , strlen (CHPL_GPUS_PER_NODE_FLAG ))) {
447- gpusPerNode = & (argv [argNum ][strlen (CHPL_GPUS_PER_NODE_FLAG )+ 1 ]);
475+ } else if (!strncmp (argv [argNum ], CHPL_GPUS_PER_NODE_FLAG "=" , strlen (CHPL_GPUS_PER_NODE_FLAG "=" ))) {
476+ gpusPerNode = & (argv [argNum ][strlen (CHPL_GPUS_PER_NODE_FLAG "=" )]);
477+ return 1 ;
478+ }
479+
480+ // handle --system-launcher-flags <flags> or --system-launcher-flags=<flags>
481+ if (!strcmp (argv [argNum ], CHPL_LAUNCHER_PASSTHROUGH_FLAG )) {
482+ appendPassthroughFlag (& launcherPassthroughFlags , & numLauncherPassthroughFlags , argv [argNum + 1 ]);
483+ return 2 ;
484+ } else if (!strncmp (argv [argNum ], CHPL_LAUNCHER_PASSTHROUGH_FLAG "=" , strlen (CHPL_LAUNCHER_PASSTHROUGH_FLAG "=" ))) {
485+ appendPassthroughFlag (& launcherPassthroughFlags , & numLauncherPassthroughFlags , & (argv [argNum ][strlen (CHPL_LAUNCHER_PASSTHROUGH_FLAG "=" )]));
448486 return 1 ;
449487 }
450488
@@ -486,6 +524,13 @@ const argDescTuple_t* chpl_launch_get_help(void) {
486524 { "" ,
487525 "(or use $CHPL_LAUNCHER_GPUS_PER_NODE)"
488526 },
527+ {
528+ CHPL_LAUNCHER_PASSTHROUGH_FLAG " <flags>" ,
529+ "specify additional flags to pass through to the launcher"
530+ },
531+ { "" ,
532+ "(or use $CHPL_LAUNCHER_PASSTHROUGH_FLAGS)"
533+ },
489534 { NULL , NULL },
490535 };
491536 return args ;
0 commit comments