From a410f5f253b7150830eb2aa5480d4275bbd36357 Mon Sep 17 00:00:00 2001 From: Engin Kayraklioglu Date: Mon, 24 Feb 2025 17:56:33 -0600 Subject: [PATCH 1/3] Fix a bug in the runtime when sbatch is used Signed-off-by: Engin Kayraklioglu --- .../src/launch/slurm-srun/launch-slurm-srun.c | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/runtime/src/launch/slurm-srun/launch-slurm-srun.c b/runtime/src/launch/slurm-srun/launch-slurm-srun.c index 770cf3d9b710..7e6c8694f2b4 100644 --- a/runtime/src/launch/slurm-srun/launch-slurm-srun.c +++ b/runtime/src/launch/slurm-srun/launch-slurm-srun.c @@ -360,14 +360,24 @@ static char* chpl_launch_create_command(int argc, char* argv[], // if were running a batch job if (getenv("CHPL_LAUNCHER_USE_SBATCH") != NULL || generate_sbatch_script) { - slurmFilename = (char*)chpl_mem_allocMany( - (strlen(baseSBATCHFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1), - sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); + + const int filename_size = strlen(baseSBATCHFilename) + + snprintf(NULL, 0, "%d", (int)mypid) + 1; + + if (filename_size <= 0) { + chpl_internal_error("An unexpected error occured while computing \ + sbatch filename size"); + } + + slurmFilename = (char*)chpl_mem_allocMany(filename_size, sizeof(char), + CHPL_RT_MD_FILENAME, -1, 0); + // set the sbatch filename - snprintf(slurmFilename, strlen(slurmFilename), "%s%d", baseSBATCHFilename, - (int)mypid); + const int ret = snprintf(slurmFilename, filename_size, "%s%d", + baseSBATCHFilename, (int)mypid); // open the batch file and create the header + slurmFile = fopen(slurmFilename, "w"); fprintf(slurmFile, "#!/bin/sh\n\n"); From 7404239653fc9437ba553917b19a2b87011e5872 Mon Sep 17 00:00:00 2001 From: Engin Kayraklioglu Date: Tue, 25 Feb 2025 12:36:16 -0600 Subject: [PATCH 2/3] Improve the error message for performance tests Signed-off-by: Engin Kayraklioglu --- util/test/sub_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/test/sub_test.py b/util/test/sub_test.py index 62c578ddff39..b924b67d43f5 100755 --- a/util/test/sub_test.py +++ b/util/test/sub_test.py @@ -2488,6 +2488,8 @@ def run_compileline(flag, lookingfor): # only notify for a failed execution if launching the test was successful elif (not launcher_error): sys.stdout.write('%s[Error execution failed for %s]\n'%(futuretest,test_name)) + sys.stdout.write('[Execution output was as follows:]\n') + sys.stdout.write(trim_output(output)) if exectimeout or status != 0 or exec_status != 0: break From d6a8079ff2d1b3feaf1a66767ec64ab9472ca9bb Mon Sep 17 00:00:00 2001 From: Engin Kayraklioglu Date: Tue, 25 Feb 2025 12:38:22 -0600 Subject: [PATCH 3/3] Add one more fix for message generation upon an error Signed-off-by: Engin Kayraklioglu --- runtime/src/launch/slurm-srun/launch-slurm-srun.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/runtime/src/launch/slurm-srun/launch-slurm-srun.c b/runtime/src/launch/slurm-srun/launch-slurm-srun.c index 7e6c8694f2b4..923e836605cf 100644 --- a/runtime/src/launch/slurm-srun/launch-slurm-srun.c +++ b/runtime/src/launch/slurm-srun/launch-slurm-srun.c @@ -658,10 +658,11 @@ static void chpl_launch_cleanup(void) { // remove sbatch file unless it was explicitly generated by the user if (getenv("CHPL_LAUNCHER_USE_SBATCH") != NULL && !generate_sbatch_script) { if (unlink(slurmFilename)) { - char* msg = (char*)chpl_mem_allocMany( - (strlen(slurmFilename) + strlen(strerror(errno)) + 36), - sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); - snprintf(msg, strlen(msg), "Error removing temporary file '%s': %s", + const int msg_size = strlen(slurmFilename) + + strlen(strerror(errno)) + 36; + char* msg = (char*)chpl_mem_allocMany(msg_size, sizeof(char), + CHPL_RT_MD_FILENAME, -1, 0); + snprintf(msg, msg_size, "Error removing temporary file '%s': %s", slurmFilename, strerror(errno)); chpl_warning(msg, 0, 0); chpl_mem_free(msg, 0, 0);