From 9d841d90fadccab439ca127714769a1d10bcacb9 Mon Sep 17 00:00:00 2001 From: R Chinmay Date: Sat, 30 Jan 2021 23:17:40 +0530 Subject: [PATCH 01/18] Reduce-FILENAME_MAX-in-runtime-directory Signed-off-by: R Chinmay --- runtime/etc/Makefile.gmp-gmp | 20 ++++++ runtime/etc/Makefile.hwloc-hwloc | 20 ++++++ runtime/etc/Makefile.jemalloc-jemalloc | 19 ++++++ runtime/etc/Makefile.unwind-libunwind | 19 ++++++ runtime/make/Makefile.runtime.gmp-gmp | 21 ++++++ runtime/make/Makefile.runtime.hwloc-hwloc | 19 ++++++ .../make/Makefile.runtime.jemalloc-jemalloc | 24 +++++++ .../make/Makefile.runtime.unwind-libunwind | 20 ++++++ .../src/launch/pbs-aprun/launch-pbs-aprun.c | 17 +++-- .../launch-pbs-gasnetrun_ibv.c | 21 +++++- .../slurm-gasnetrun_common.h | 26 ++++++-- .../src/launch/slurm-srun/launch-slurm-srun.c | 65 ++++++++++++++++--- 12 files changed, 269 insertions(+), 22 deletions(-) create mode 100644 runtime/etc/Makefile.gmp-gmp create mode 100644 runtime/etc/Makefile.hwloc-hwloc create mode 100644 runtime/etc/Makefile.jemalloc-jemalloc create mode 100644 runtime/etc/Makefile.unwind-libunwind create mode 100644 runtime/make/Makefile.runtime.gmp-gmp create mode 100644 runtime/make/Makefile.runtime.hwloc-hwloc create mode 100644 runtime/make/Makefile.runtime.jemalloc-jemalloc create mode 100644 runtime/make/Makefile.runtime.unwind-libunwind diff --git a/runtime/etc/Makefile.gmp-gmp b/runtime/etc/Makefile.gmp-gmp new file mode 100644 index 000000000000..c6285028d000 --- /dev/null +++ b/runtime/etc/Makefile.gmp-gmp @@ -0,0 +1,20 @@ +# Copyright 2020 Hewlett Packard Enterprise Development LP +# Copyright 2004-2019 Cray Inc. +# Other additional copyright holders may be indicated within. +# +# The entirety of this work is licensed under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +GEN_LFLAGS += -L$(GMP_LIB_DIR) -Wl,-rpath,$(GMP_LIB_DIR) + diff --git a/runtime/etc/Makefile.hwloc-hwloc b/runtime/etc/Makefile.hwloc-hwloc new file mode 100644 index 000000000000..30aa709a5bf6 --- /dev/null +++ b/runtime/etc/Makefile.hwloc-hwloc @@ -0,0 +1,20 @@ +# Copyright 2020 Hewlett Packard Enterprise Development LP +# Copyright 2004-2019 Cray Inc. +# Other additional copyright holders may be indicated within. +# +# The entirety of this work is licensed under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +GEN_CFLAGS += -I$(HWLOC_INCLUDE_DIR) +GEN_LFLAGS += -L$(HWLOC_LIB_DIR) -Wl,-rpath,$(HWLOC_LIB_DIR) diff --git a/runtime/etc/Makefile.jemalloc-jemalloc b/runtime/etc/Makefile.jemalloc-jemalloc new file mode 100644 index 000000000000..21b7412ec24e --- /dev/null +++ b/runtime/etc/Makefile.jemalloc-jemalloc @@ -0,0 +1,19 @@ +# Copyright 2020 Hewlett Packard Enterprise Development LP +# Copyright 2004-2019 Cray Inc. +# Other additional copyright holders may be indicated within. +# +# The entirety of this work is licensed under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +GEN_LFLAGS += -L$(JEMALLOC_LIB_DIR) -Wl,-rpath,$(JEMALLOC_LIB_DIR) diff --git a/runtime/etc/Makefile.unwind-libunwind b/runtime/etc/Makefile.unwind-libunwind new file mode 100644 index 000000000000..7e688b5eb04e --- /dev/null +++ b/runtime/etc/Makefile.unwind-libunwind @@ -0,0 +1,19 @@ +# Copyright 2020 Hewlett Packard Enterprise Development LP +# Copyright 2004-2019 Cray Inc. +# Other additional copyright holders may be indicated within. +# +# The entirety of this work is licensed under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +GEN_LFLAGS += -L$(LIBUNWIND_LIB_DIR) diff --git a/runtime/make/Makefile.runtime.gmp-gmp b/runtime/make/Makefile.runtime.gmp-gmp new file mode 100644 index 000000000000..40c920977328 --- /dev/null +++ b/runtime/make/Makefile.runtime.gmp-gmp @@ -0,0 +1,21 @@ +# Copyright 2020 Hewlett Packard Enterprise Development LP +# Copyright 2004-2019 Cray Inc. +# Other additional copyright holders may be indicated within. +# +# The entirety of this work is licensed under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +RUNTIME_DEFS += -DCHPL_HAS_GMP +RUNTIME_INCLS += -I$(GMP_INCLUDE_DIR) + diff --git a/runtime/make/Makefile.runtime.hwloc-hwloc b/runtime/make/Makefile.runtime.hwloc-hwloc new file mode 100644 index 000000000000..e5302af51a8d --- /dev/null +++ b/runtime/make/Makefile.runtime.hwloc-hwloc @@ -0,0 +1,19 @@ +# Copyright 2020 Hewlett Packard Enterprise Development LP +# Copyright 2004-2019 Cray Inc. +# Other additional copyright holders may be indicated within. +# +# The entirety of this work is licensed under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +RUNTIME_INCLS += -I$(HWLOC_INCLUDE_DIR) diff --git a/runtime/make/Makefile.runtime.jemalloc-jemalloc b/runtime/make/Makefile.runtime.jemalloc-jemalloc new file mode 100644 index 000000000000..d92d419b7937 --- /dev/null +++ b/runtime/make/Makefile.runtime.jemalloc-jemalloc @@ -0,0 +1,24 @@ +# Copyright 2020 Hewlett Packard Enterprise Development LP +# Copyright 2004-2019 Cray Inc. +# Other additional copyright holders may be indicated within. +# +# The entirety of this work is licensed under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +RUNTIME_INCLS += -I$(JEMALLOC_INCLUDE_DIR) +# Chapel third-party install of jemalloc calls the routines +# chpl_je_malloc, chpl_je_free, etc +# +# CHPL_JEMALLOC_PREFIX is set in third-party/jemalloc/Makefile.include +RUNTIME_DEFS += -DCHPL_JEMALLOC_PREFIX=$(CHPL_JEMALLOC_PREFIX) diff --git a/runtime/make/Makefile.runtime.unwind-libunwind b/runtime/make/Makefile.runtime.unwind-libunwind new file mode 100644 index 000000000000..864478be09ae --- /dev/null +++ b/runtime/make/Makefile.runtime.unwind-libunwind @@ -0,0 +1,20 @@ +# Copyright 2020 Hewlett Packard Enterprise Development LP +# Copyright 2004-2019 Cray Inc. +# Other additional copyright holders may be indicated within. +# +# The entirety of this work is licensed under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +RUNTIME_DEFS += -DCHPL_DO_UNWIND +RUNTIME_INCLS += -I$(LIBUNWIND_INCLUDE_DIR) diff --git a/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c b/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c index dc142609d317..586dfb972262 100644 --- a/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c +++ b/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c @@ -50,7 +50,7 @@ static char* walltime = NULL; static char* queue = NULL; static int generate_qsub_script = 0; -static char expectFilename[FILENAME_MAX]; +static char* expectFilename=NULL; extern int fileno(FILE *stream); @@ -243,6 +243,10 @@ static char** chpl_launch_create_argv(int argc, char* argv[], } else { mypid = 0; } + expectFilename=(char *)malloc(sizeof(char)*(strlen(baseExpectFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1)); + if(expectFilename==NULL) { + chpl_internal_error("Memory allocation using malloc failed."); + } snprintf(expectFilename, FILENAME_MAX, "%s%d", baseExpectFilename, (int)mypid); @@ -393,10 +397,15 @@ static void genQsubScript(int argc, char *argv[], int numLocales) { static void chpl_launch_cleanup(void) { if (!debug) { if (unlink(expectFilename)) { - char msg[FILENAME_MAX + 35]; - snprintf(msg, FILENAME_MAX + 35, "Error removing temporary file '%s': %s", + char* msg=(char *)malloc(sizeof(char)*(strlen(expectFilename) + strlen(strerror(errno)) + 36)); + if(msg==NULL){ + free(expectFilename); + chpl_internal_error("Memory allocation using malloc failed."); + } + snprintf(msg, FILENAME_MAX + 45, "Error removing temporary file '%s': %s", expectFilename, strerror(errno)); chpl_warning(msg, 0, 0); + free(msg); } } } @@ -416,7 +425,7 @@ int chpl_launch(int argc, char* argv[], int32_t numLocales) { argv[0]); chpl_launch_cleanup(); } - + free(expectFilename); return retcode; } diff --git a/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c b/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c index f52121d16deb..5f207718778d 100644 --- a/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c +++ b/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c @@ -38,9 +38,9 @@ #define baseExpectFilename ".chpl-expect-" #define baseSysFilename ".chpl-sys-" -char pbsFilename[FILENAME_MAX]; -char expectFilename[FILENAME_MAX]; -char sysFilename[FILENAME_MAX]; +char* pbsFilename=NULL; +char* expectFilename=NULL; +char* sysFilename=NULL; /* copies of binary to run per node */ #define procsPerNode 1 @@ -170,6 +170,18 @@ static char* chpl_launch_create_command(int argc, char* argv[], #else mypid = 0; #endif + sysFilename=(char *)malloc(size(char)*(strlen(baseSysFilename) + + snprintf(NULL, 0, "%d", (int)mypid +1))); + expectFilename=(char *)malloc(size(char)*(strlen(baseExpectFilename) + + snprintf(NULL, 0, "%d", (int)mypid +1))); + pbsFilename=(char *)malloc(size(char)*(strlen(basePBSFilename) + + snprintf(NULL, 0, "%d", (int)mypid +1))); + if(sysFilename==NULL || expectFilename==NULL || pbsFilename==NULL) { + free(sysFilename); + free(expectFilename); + free(pbsFilename); + chpl_internal_error("Memory allocation using malloc failed."); + } sprintf(sysFilename, "%s%d", baseSysFilename, (int)mypid); sprintf(expectFilename, "%s%d", baseExpectFilename, (int)mypid); sprintf(pbsFilename, "%s%d", basePBSFilename, (int)mypid); @@ -235,6 +247,9 @@ static void chpl_launch_cleanup(void) { sprintf(command, "rm %s", sysFilename); system(command); #endif + free(pbsFilename); + free(expectFilename); + free(sysFilename); } diff --git a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h index e6f4043e269a..febba925a4a0 100644 --- a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h +++ b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h @@ -49,7 +49,7 @@ static char* debug = NULL; static char* walltime = NULL; static char* partition = NULL; static char* exclude = NULL; -char slurmFilename[FILENAME_MAX]; +char* slurmFilename = NULL; /* copies of binary to run per node */ #define procsPerNode 1 @@ -178,8 +178,8 @@ static char* chpl_launch_create_command(int argc, char* argv[], int32_t numLocales) { int i; int size; - char baseCommand[2*FILENAME_MAX]; - char envProp[2*FILENAME_MAX]; + char* baseCommand = NULL; + char* envProp = NULL; char* command; FILE* slurmFile; char* projectString = getenv(launcherAccountEnvvar); @@ -233,6 +233,11 @@ static char* chpl_launch_create_command(int argc, char* argv[], } else { mypid = getpid(); } + slurmFilename=(char *)malloc(sizeof(char)*(strlen(baseSBATCHFilename) + + snprintf(NULL, 0, "%d", (int)mypid) + 1)); + if(slurmFilename==NULL) { + chpl_internal_error("Memory allocation using malloc failed."); + } sprintf(slurmFilename, "%s%d", baseSBATCHFilename, (int)mypid); if (getenv("CHPL_LAUNCHER_USE_SBATCH") != NULL) { @@ -268,7 +273,11 @@ static char* chpl_launch_create_command(int argc, char* argv[], fclose(slurmFile); chmod(slurmFilename, 0755); - + baseCommand=(char *)malloc(sizeof(char)*(strlen(slurmFilename) + 9)); + if(baseCommand==NULL){ + free(slurmFilename); + chpl_internal_error("Memory allocation using malloc failed."); + } sprintf(baseCommand, "sbatch %s\n", slurmFilename); } else { char iCom[2*FILENAME_MAX-10]; @@ -296,7 +305,11 @@ static char* chpl_launch_create_command(int argc, char* argv[], for (i=1; i size) { chpl_internal_error("buffer overflow"); } @@ -330,6 +343,7 @@ int chpl_launch(int argc, char* argv[], int32_t numLocales) { retcode = chpl_launch_using_system(chpl_launch_create_command(argc, argv, numLocales), argv[0]); chpl_launch_cleanup(); + free(slurmFilename); return retcode; } diff --git a/runtime/src/launch/slurm-srun/launch-slurm-srun.c b/runtime/src/launch/slurm-srun/launch-slurm-srun.c index f5e8930c6889..caf13e0f2f4c 100644 --- a/runtime/src/launch/slurm-srun/launch-slurm-srun.c +++ b/runtime/src/launch/slurm-srun/launch-slurm-srun.c @@ -45,7 +45,7 @@ static char* nodelist = NULL; static char* partition = NULL; static char* exclude = NULL; -char slurmFilename[FILENAME_MAX]; +char* slurmFilename = NULL; /* copies of binary to run per node */ #define procsPerNode 1 @@ -142,14 +142,13 @@ static int getCoresPerLocale(int nomultithread) { return numCores; } -#define MAX_COM_LEN (FILENAME_MAX + 128) // create the command that will actually launch the program and // create any files needed for the launch like the batch script static char* chpl_launch_create_command(int argc, char* argv[], int32_t numLocales) { int i; int size; - char baseCommand[MAX_COM_LEN]; + char* baseCommand=NULL; char* command; FILE* slurmFile; char* account = getenv("CHPL_LAUNCHER_ACCOUNT"); @@ -183,9 +182,9 @@ static char* chpl_launch_create_command(int argc, char* argv[], // because they haven't been initialized yet char* bufferStdout = getenv("CHPL_LAUNCHER_SLURM_BUFFER_STDOUT"); const char* tmpDir = getTmpDir(); - char stdoutFile [MAX_COM_LEN]; - char stdoutFileNoFmt [MAX_COM_LEN]; - char tmpStdoutFileNoFmt [MAX_COM_LEN]; + char* stdoutFile = NULL; + char* stdoutFileNoFmt = NULL; + char* tmpStdoutFileNoFmt = NULL; // command line walltime takes precedence over env var if (!walltime) { @@ -244,6 +243,11 @@ 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 *)malloc(sizeof(char)*(strlen(baseSBATCHFilename) + + snprintf(NULL, 0, "%d", (int)mypid) + 1)); + if(slurmFilename==NULL){ + chpl_internal_error("Memory allocation using malloc failed."); + } // set the sbatch filename sprintf(slurmFilename, "%s%d", baseSBATCHFilename, (int)mypid); @@ -305,14 +309,23 @@ static char* chpl_launch_create_command(int argc, char* argv[], // set the output file name to either the user specified // name or to the binaryName..out if none specified if (outputfn != NULL) { + stdoutFile=(char *)malloc(sizeof(char)*(strlen(outputfn) + 1)); sprintf(stdoutFile, "%s", outputfn); + stdoutFileNoFmt=(char *)malloc(sizeof(char)*(strlen(outputfn) + 1)); sprintf(stdoutFileNoFmt, "%s", outputfn); } else { + stdoutFile=(char *)malloc(sizeof(char)*(strlen(argv[0]) + 9)); sprintf(stdoutFile, "%s.%s.out", argv[0], "%j"); + stdoutFileNoFmt=(char *)malloc(sizeof(char *)*(strlen(argv[0]+ 20))); sprintf(stdoutFileNoFmt, "%s.%s.out", argv[0], "$SLURM_JOB_ID"); } - + if(stdoutFile==NULL || stdoutFileNoFmt==NULL){ + free(stdoutFile); + free(stdoutFileNoFmt); + free(slurmFilename); + chpl_internal_error("Memory allocation using malloc failed."); + } // We have slurm use the real output file to capture slurm errors/timeouts // We only redirect the program output to the tmp file fprintf(slurmFile, "#SBATCH --output=%s\n", stdoutFile); @@ -324,6 +337,13 @@ static char* chpl_launch_create_command(int argc, char* argv[], // If we're buffering the output, set the temp output file name. // It's always /binaryName..out. if (bufferStdout != NULL) { + tmpStdoutFileNoFmt=(char *)malloc(sizeof(char) * (strlen(tmpDir) + strlen(argv[0]) + 20)); + if(tmpStdoutFileNoFmt==NULL){ + free(stdoutFile); + free(stdoutFileNoFmt); + free(slurmFilename); + chpl_internal_error("Memory allocation using malloc failed."); + } sprintf(tmpStdoutFileNoFmt, "%s/%s.%s.out", tmpDir, argv[0], "$SLURM_JOB_ID"); } @@ -348,6 +368,9 @@ static char* chpl_launch_create_command(int argc, char* argv[], if (bufferStdout != NULL) { fprintf(slurmFile, "cat %s >> %s\n", tmpStdoutFileNoFmt, stdoutFileNoFmt); fprintf(slurmFile, "rm %s &> /dev/null\n", tmpStdoutFileNoFmt); + //tmpStdoutFileNoFmt is only allocated memory if bufferStdout!=NULL + //Hence free up inside this condition. + free(tmpStdoutFileNoFmt); } // close the batch file and change permissions @@ -360,6 +383,13 @@ static char* chpl_launch_create_command(int argc, char* argv[], // the baseCommand is what will call the batch file // that was just created + baseCommand=(char *)malloc(sizeof(char)*(strlen(slurmFilename) + 9)); + if(baseCommand==NULL){ + free(stdoutFile); + free(stdoutFileNoFmt); + free(slurmFilename); + chpl_internal_error("Memory allocation using malloc failed."); + } sprintf(baseCommand, "sbatch %s\n", slurmFilename); } // else we're running an interactive job @@ -431,7 +461,14 @@ static char* chpl_launch_create_command(int argc, char* argv[], for (i=1; i size) { chpl_internal_error("buffer overflow"); } @@ -460,7 +501,12 @@ 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[FILENAME_MAX + 128]; + char* msg=(char *)malloc(sizeof(char)*(strlen(slurmFilename) + + strlen(strerror(errno)) + 36)); + if(msg==NULL){ + free(slurmFilename); + chpl_internal_error("Memory allocation using malloc failed."); + } snprintf(msg, sizeof(msg), "Error removing temporary file '%s': %s", slurmFilename, strerror(errno)); chpl_warning(msg, 0, 0); @@ -495,6 +541,7 @@ int chpl_launch(int argc, char* argv[], int32_t numLocales) { chpl_launch_cleanup(); } + free(slurmFilename); return retcode; } From bba606e3a011b585b937ecfd3d7bee2593465e98 Mon Sep 17 00:00:00 2001 From: R Chinmay Date: Sat, 30 Jan 2021 23:38:33 +0530 Subject: [PATCH 02/18] Deleting Files added by mistake Signed-off-by: R Chinmay --- runtime/etc/Makefile.gmp-gmp | 20 ---------------- runtime/etc/Makefile.hwloc-hwloc | 20 ---------------- runtime/etc/Makefile.jemalloc-jemalloc | 19 --------------- runtime/etc/Makefile.unwind-libunwind | 19 --------------- runtime/make/Makefile.runtime.gmp-gmp | 21 ---------------- runtime/make/Makefile.runtime.hwloc-hwloc | 19 --------------- .../make/Makefile.runtime.jemalloc-jemalloc | 24 ------------------- .../make/Makefile.runtime.unwind-libunwind | 20 ---------------- 8 files changed, 162 deletions(-) delete mode 100644 runtime/etc/Makefile.gmp-gmp delete mode 100644 runtime/etc/Makefile.hwloc-hwloc delete mode 100644 runtime/etc/Makefile.jemalloc-jemalloc delete mode 100644 runtime/etc/Makefile.unwind-libunwind delete mode 100644 runtime/make/Makefile.runtime.gmp-gmp delete mode 100644 runtime/make/Makefile.runtime.hwloc-hwloc delete mode 100644 runtime/make/Makefile.runtime.jemalloc-jemalloc delete mode 100644 runtime/make/Makefile.runtime.unwind-libunwind diff --git a/runtime/etc/Makefile.gmp-gmp b/runtime/etc/Makefile.gmp-gmp deleted file mode 100644 index c6285028d000..000000000000 --- a/runtime/etc/Makefile.gmp-gmp +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2020 Hewlett Packard Enterprise Development LP -# Copyright 2004-2019 Cray Inc. -# Other additional copyright holders may be indicated within. -# -# The entirety of this work is licensed under the Apache License, -# Version 2.0 (the "License"); you may not use this file except -# in compliance with the License. -# -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -GEN_LFLAGS += -L$(GMP_LIB_DIR) -Wl,-rpath,$(GMP_LIB_DIR) - diff --git a/runtime/etc/Makefile.hwloc-hwloc b/runtime/etc/Makefile.hwloc-hwloc deleted file mode 100644 index 30aa709a5bf6..000000000000 --- a/runtime/etc/Makefile.hwloc-hwloc +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2020 Hewlett Packard Enterprise Development LP -# Copyright 2004-2019 Cray Inc. -# Other additional copyright holders may be indicated within. -# -# The entirety of this work is licensed under the Apache License, -# Version 2.0 (the "License"); you may not use this file except -# in compliance with the License. -# -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -GEN_CFLAGS += -I$(HWLOC_INCLUDE_DIR) -GEN_LFLAGS += -L$(HWLOC_LIB_DIR) -Wl,-rpath,$(HWLOC_LIB_DIR) diff --git a/runtime/etc/Makefile.jemalloc-jemalloc b/runtime/etc/Makefile.jemalloc-jemalloc deleted file mode 100644 index 21b7412ec24e..000000000000 --- a/runtime/etc/Makefile.jemalloc-jemalloc +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2020 Hewlett Packard Enterprise Development LP -# Copyright 2004-2019 Cray Inc. -# Other additional copyright holders may be indicated within. -# -# The entirety of this work is licensed under the Apache License, -# Version 2.0 (the "License"); you may not use this file except -# in compliance with the License. -# -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -GEN_LFLAGS += -L$(JEMALLOC_LIB_DIR) -Wl,-rpath,$(JEMALLOC_LIB_DIR) diff --git a/runtime/etc/Makefile.unwind-libunwind b/runtime/etc/Makefile.unwind-libunwind deleted file mode 100644 index 7e688b5eb04e..000000000000 --- a/runtime/etc/Makefile.unwind-libunwind +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2020 Hewlett Packard Enterprise Development LP -# Copyright 2004-2019 Cray Inc. -# Other additional copyright holders may be indicated within. -# -# The entirety of this work is licensed under the Apache License, -# Version 2.0 (the "License"); you may not use this file except -# in compliance with the License. -# -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -GEN_LFLAGS += -L$(LIBUNWIND_LIB_DIR) diff --git a/runtime/make/Makefile.runtime.gmp-gmp b/runtime/make/Makefile.runtime.gmp-gmp deleted file mode 100644 index 40c920977328..000000000000 --- a/runtime/make/Makefile.runtime.gmp-gmp +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2020 Hewlett Packard Enterprise Development LP -# Copyright 2004-2019 Cray Inc. -# Other additional copyright holders may be indicated within. -# -# The entirety of this work is licensed under the Apache License, -# Version 2.0 (the "License"); you may not use this file except -# in compliance with the License. -# -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -RUNTIME_DEFS += -DCHPL_HAS_GMP -RUNTIME_INCLS += -I$(GMP_INCLUDE_DIR) - diff --git a/runtime/make/Makefile.runtime.hwloc-hwloc b/runtime/make/Makefile.runtime.hwloc-hwloc deleted file mode 100644 index e5302af51a8d..000000000000 --- a/runtime/make/Makefile.runtime.hwloc-hwloc +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2020 Hewlett Packard Enterprise Development LP -# Copyright 2004-2019 Cray Inc. -# Other additional copyright holders may be indicated within. -# -# The entirety of this work is licensed under the Apache License, -# Version 2.0 (the "License"); you may not use this file except -# in compliance with the License. -# -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -RUNTIME_INCLS += -I$(HWLOC_INCLUDE_DIR) diff --git a/runtime/make/Makefile.runtime.jemalloc-jemalloc b/runtime/make/Makefile.runtime.jemalloc-jemalloc deleted file mode 100644 index d92d419b7937..000000000000 --- a/runtime/make/Makefile.runtime.jemalloc-jemalloc +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright 2020 Hewlett Packard Enterprise Development LP -# Copyright 2004-2019 Cray Inc. -# Other additional copyright holders may be indicated within. -# -# The entirety of this work is licensed under the Apache License, -# Version 2.0 (the "License"); you may not use this file except -# in compliance with the License. -# -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -RUNTIME_INCLS += -I$(JEMALLOC_INCLUDE_DIR) -# Chapel third-party install of jemalloc calls the routines -# chpl_je_malloc, chpl_je_free, etc -# -# CHPL_JEMALLOC_PREFIX is set in third-party/jemalloc/Makefile.include -RUNTIME_DEFS += -DCHPL_JEMALLOC_PREFIX=$(CHPL_JEMALLOC_PREFIX) diff --git a/runtime/make/Makefile.runtime.unwind-libunwind b/runtime/make/Makefile.runtime.unwind-libunwind deleted file mode 100644 index 864478be09ae..000000000000 --- a/runtime/make/Makefile.runtime.unwind-libunwind +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2020 Hewlett Packard Enterprise Development LP -# Copyright 2004-2019 Cray Inc. -# Other additional copyright holders may be indicated within. -# -# The entirety of this work is licensed under the Apache License, -# Version 2.0 (the "License"); you may not use this file except -# in compliance with the License. -# -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -RUNTIME_DEFS += -DCHPL_DO_UNWIND -RUNTIME_INCLS += -I$(LIBUNWIND_INCLUDE_DIR) From 2e63718d41290648167a696bf4b9221d2205271e Mon Sep 17 00:00:00 2001 From: R Chinmay Date: Thu, 4 Feb 2021 01:29:12 +0530 Subject: [PATCH 03/18] Change-to-chpl_mem_-functions Signed-off-by: R Chinmay --- .../src/launch/pbs-aprun/launch-pbs-aprun.c | 20 +++-- .../launch-pbs-gasnetrun_ibv.c | 29 ++++---- .../slurm-gasnetrun_common.h | 23 ++---- .../src/launch/slurm-srun/launch-slurm-srun.c | 74 +++++++------------ 4 files changed, 58 insertions(+), 88 deletions(-) diff --git a/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c b/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c index 586dfb972262..003ff1005d5f 100644 --- a/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c +++ b/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c @@ -243,10 +243,10 @@ static char** chpl_launch_create_argv(int argc, char* argv[], } else { mypid = 0; } - expectFilename=(char *)malloc(sizeof(char)*(strlen(baseExpectFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1)); - if(expectFilename==NULL) { - chpl_internal_error("Memory allocation using malloc failed."); - } + expectFilename=(char *)chpl_mem_allocMany((strlen(baseExpectFilename) + + snprintf(NULL, 0, "%d", (int)mypid) + + 1), + sizeof(char), CHPL_RT_MD_UNKNOWN, -1, 0); snprintf(expectFilename, FILENAME_MAX, "%s%d", baseExpectFilename, (int)mypid); @@ -397,15 +397,13 @@ static void genQsubScript(int argc, char *argv[], int numLocales) { static void chpl_launch_cleanup(void) { if (!debug) { if (unlink(expectFilename)) { - char* msg=(char *)malloc(sizeof(char)*(strlen(expectFilename) + strlen(strerror(errno)) + 36)); - if(msg==NULL){ - free(expectFilename); - chpl_internal_error("Memory allocation using malloc failed."); - } + char* msg=(char *)chpl_mem_allocMany((strlen(expectFilename) + + strlen(strerror(errno)) + 36), + sizeof(char), CHPL_RT_MD_UNKNOWN, -1, 0); snprintf(msg, FILENAME_MAX + 45, "Error removing temporary file '%s': %s", expectFilename, strerror(errno)); chpl_warning(msg, 0, 0); - free(msg); + chpl_mem_free(msg); } } } @@ -425,7 +423,7 @@ int chpl_launch(int argc, char* argv[], int32_t numLocales) { argv[0]); chpl_launch_cleanup(); } - free(expectFilename); + chpl_mem_free(expectFilename); return retcode; } diff --git a/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c b/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c index 5f207718778d..e038347098fa 100644 --- a/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c +++ b/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c @@ -170,18 +170,17 @@ static char* chpl_launch_create_command(int argc, char* argv[], #else mypid = 0; #endif - sysFilename=(char *)malloc(size(char)*(strlen(baseSysFilename) + - snprintf(NULL, 0, "%d", (int)mypid +1))); - expectFilename=(char *)malloc(size(char)*(strlen(baseExpectFilename) + - snprintf(NULL, 0, "%d", (int)mypid +1))); - pbsFilename=(char *)malloc(size(char)*(strlen(basePBSFilename) + - snprintf(NULL, 0, "%d", (int)mypid +1))); - if(sysFilename==NULL || expectFilename==NULL || pbsFilename==NULL) { - free(sysFilename); - free(expectFilename); - free(pbsFilename); - chpl_internal_error("Memory allocation using malloc failed."); - } + sysFilename=(char *)chpl_mem_allocMany((strlen(baseSysFilename) + + snprintf(NULL, 0, "%d", (int)mypid) + 1), + sizeof(char), CHPL_RT_MD_UNKNOWN, -1, 0); + expectFilename=(char *)chpl_mem_allocMany((strlen(baseExpectFilename) + + snprintf(NULL, 0, "%d", (int)mypid) + + 1), sizeof(char), + CHPL_RT_MD_UNKNOWN, -1, 0); + pbsFilename=(char *)chpl_mem_allocMany((strlen(basePBSFilename) + + snprintf(NULL, 0, "%d", (int)mypid) + + 1), sizeof(char), CHPL_RT_MD_UNKNOWN, + -1, 0); sprintf(sysFilename, "%s%d", baseSysFilename, (int)mypid); sprintf(expectFilename, "%s%d", baseExpectFilename, (int)mypid); sprintf(pbsFilename, "%s%d", basePBSFilename, (int)mypid); @@ -247,9 +246,9 @@ static void chpl_launch_cleanup(void) { sprintf(command, "rm %s", sysFilename); system(command); #endif - free(pbsFilename); - free(expectFilename); - free(sysFilename); + chpl_mem_free(pbsFilename); + chpl_mem_free(expectFilename); + chpl_mem_free(sysFilename); } diff --git a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h index febba925a4a0..3e357d962c9d 100644 --- a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h +++ b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h @@ -233,11 +233,10 @@ static char* chpl_launch_create_command(int argc, char* argv[], } else { mypid = getpid(); } - slurmFilename=(char *)malloc(sizeof(char)*(strlen(baseSBATCHFilename) + - snprintf(NULL, 0, "%d", (int)mypid) + 1)); - if(slurmFilename==NULL) { - chpl_internal_error("Memory allocation using malloc failed."); - } + slurmFilename=(char *)chpl_mem_allocMany((strlen(baseSBATCHFilename) + + snprintf(NULL, 0, "%d", (int)mypid) + + 1), sizeof(char), + CHPL_RT_MD_UNKNOWN, -1, 0); sprintf(slurmFilename, "%s%d", baseSBATCHFilename, (int)mypid); if (getenv("CHPL_LAUNCHER_USE_SBATCH") != NULL) { @@ -273,11 +272,8 @@ static char* chpl_launch_create_command(int argc, char* argv[], fclose(slurmFile); chmod(slurmFilename, 0755); - baseCommand=(char *)malloc(sizeof(char)*(strlen(slurmFilename) + 9)); - if(baseCommand==NULL){ - free(slurmFilename); - chpl_internal_error("Memory allocation using malloc failed."); - } + baseCommand=(char *)chpl_mem_allocMany((strlen(slurmFilename) + 9), + sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, 0); sprintf(baseCommand, "sbatch %s\n", slurmFilename); } else { char iCom[2*FILENAME_MAX-10]; @@ -305,11 +301,8 @@ static char* chpl_launch_create_command(int argc, char* argv[], for (i=1; i.out if none specified if (outputfn != NULL) { - stdoutFile=(char *)malloc(sizeof(char)*(strlen(outputfn) + 1)); + stdoutFile=(char *)chpl_mem_allocMany((strlen(outputfn) + 1), + sizeof(char), CHPL_RT_MD_UNKNOWN, -1, 0); sprintf(stdoutFile, "%s", outputfn); - stdoutFileNoFmt=(char *)malloc(sizeof(char)*(strlen(outputfn) + 1)); + stdoutFileNoFmt=(char *)chpl_mem_allocMany((strlen(outputfn) + 1), + sizeof(char), CHPL_RT_MD_UNKNOWN, -1, 0); sprintf(stdoutFileNoFmt, "%s", outputfn); } else { - stdoutFile=(char *)malloc(sizeof(char)*(strlen(argv[0]) + 9)); + stdoutFile=(char *)chpl_mem_allocMany((strlen(argv[0]) + 9), + sizeof(char), CHPL_RT_MD_UNKNOWN, -1, 0); sprintf(stdoutFile, "%s.%s.out", argv[0], "%j"); - stdoutFileNoFmt=(char *)malloc(sizeof(char *)*(strlen(argv[0]+ 20))); + stdoutFileNoFmt=(char *)chpl_mem_allocMany((strlen(argv[0]) + 20), + sizeof(char), CHPL_RT_MD_UNKNOWN, -1, 0); sprintf(stdoutFileNoFmt, "%s.%s.out", argv[0], "$SLURM_JOB_ID"); } - if(stdoutFile==NULL || stdoutFileNoFmt==NULL){ - free(stdoutFile); - free(stdoutFileNoFmt); - free(slurmFilename); - chpl_internal_error("Memory allocation using malloc failed."); - } // We have slurm use the real output file to capture slurm errors/timeouts // We only redirect the program output to the tmp file fprintf(slurmFile, "#SBATCH --output=%s\n", stdoutFile); @@ -337,13 +334,9 @@ static char* chpl_launch_create_command(int argc, char* argv[], // If we're buffering the output, set the temp output file name. // It's always /binaryName..out. if (bufferStdout != NULL) { - tmpStdoutFileNoFmt=(char *)malloc(sizeof(char) * (strlen(tmpDir) + strlen(argv[0]) + 20)); - if(tmpStdoutFileNoFmt==NULL){ - free(stdoutFile); - free(stdoutFileNoFmt); - free(slurmFilename); - chpl_internal_error("Memory allocation using malloc failed."); - } + tmpStdoutFileNoFmt=(char *)chpl_mem_allocMany((strlen(tmpDir) + + strlen(argv[0]) + 20), + sizeof(char), CHPL_RT_MD_UNKNOWN, -1, 0); sprintf(tmpStdoutFileNoFmt, "%s/%s.%s.out", tmpDir, argv[0], "$SLURM_JOB_ID"); } @@ -370,7 +363,7 @@ static char* chpl_launch_create_command(int argc, char* argv[], fprintf(slurmFile, "rm %s &> /dev/null\n", tmpStdoutFileNoFmt); //tmpStdoutFileNoFmt is only allocated memory if bufferStdout!=NULL //Hence free up inside this condition. - free(tmpStdoutFileNoFmt); + chpl_mem_free(tmpStdoutFileNoFmt); } // close the batch file and change permissions @@ -383,13 +376,8 @@ static char* chpl_launch_create_command(int argc, char* argv[], // the baseCommand is what will call the batch file // that was just created - baseCommand=(char *)malloc(sizeof(char)*(strlen(slurmFilename) + 9)); - if(baseCommand==NULL){ - free(stdoutFile); - free(stdoutFileNoFmt); - free(slurmFilename); - chpl_internal_error("Memory allocation using malloc failed."); - } + baseCommand=(char *)chpl_mem_allocMany((strlen(slurmFilename) + 9), + sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, 0); sprintf(baseCommand, "sbatch %s\n", slurmFilename); } // else we're running an interactive job @@ -462,13 +450,8 @@ static char* chpl_launch_create_command(int argc, char* argv[], len += sprintf(iCom+len, "%s ", argv[i]); } - baseCommand=(char *)malloc(sizeof(char)*(strlen(iCom) + 8)); - if(baseCommand==NULL){ - free(stdoutFile); - free(stdoutFileNoFmt); - free(slurmFilename); - chpl_internal_error("Memory allocation using malloc failed."); - } + baseCommand=(char *)chpl_mem_allocMany((strlen(iCom) + 8), sizeof(char), + CHPL_RT_MD_COMMAND_BUFFER, -1, 0); // launch the job using srun sprintf(baseCommand, "srun %s ", iCom); } @@ -478,9 +461,9 @@ static char* chpl_launch_create_command(int argc, char* argv[], command = chpl_mem_allocMany(size, sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, 0); sprintf(command, "%s", baseCommand); //free dynamically allocated memory - free(baseCommand); - free(stdoutFile); - free(stdoutFileNoFmt); + chpl_mem_free(baseCommand); + chpl_mem_free(stdoutFile); + chpl_mem_free(stdoutFileNoFmt); if (strlen(command)+1 > size) { chpl_internal_error("buffer overflow"); } @@ -501,12 +484,9 @@ 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 *)malloc(sizeof(char)*(strlen(slurmFilename) + - strlen(strerror(errno)) + 36)); - if(msg==NULL){ - free(slurmFilename); - chpl_internal_error("Memory allocation using malloc failed."); - } + char* msg=(char *)chpl_mem_allocMany((strlen(slurmFilename) + + strlen(strerror(errno)) + 36), + sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, 0); snprintf(msg, sizeof(msg), "Error removing temporary file '%s': %s", slurmFilename, strerror(errno)); chpl_warning(msg, 0, 0); @@ -541,7 +521,7 @@ int chpl_launch(int argc, char* argv[], int32_t numLocales) { chpl_launch_cleanup(); } - free(slurmFilename); + chpl_mem_free(slurmFilename); return retcode; } From 84b75d64e2df8329c1ed9d3f8b1d9c578b2d9970 Mon Sep 17 00:00:00 2001 From: R Chinmay Date: Thu, 4 Feb 2021 01:37:02 +0530 Subject: [PATCH 04/18] Changing free to chpl_mem_free functions Signed-off-by: R Chinmay --- .../launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h index 3e357d962c9d..3fedace00114 100644 --- a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h +++ b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h @@ -311,7 +311,7 @@ static char* chpl_launch_create_command(int argc, char* argv[], command = chpl_mem_allocMany(size, sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, 0); sprintf(command, "%s", baseCommand); - free(baseCommand); + chpl_mem_free(baseCommand); if (strlen(command)+1 > size) { chpl_internal_error("buffer overflow"); } @@ -336,7 +336,7 @@ int chpl_launch(int argc, char* argv[], int32_t numLocales) { retcode = chpl_launch_using_system(chpl_launch_create_command(argc, argv, numLocales), argv[0]); chpl_launch_cleanup(); - free(slurmFilename); + chpl_mem_free(slurmFilename); return retcode; } From 820aff0e23cc5c66a8a054915496d7b830b2c66d Mon Sep 17 00:00:00 2001 From: R Chinmay Date: Fri, 5 Feb 2021 00:05:49 +0530 Subject: [PATCH 05/18] Added CHPL_RT_MD_FILENAME enumeration Signed-off-by: R Chinmay --- runtime/include/chpl-mem-desc.h | 1 + runtime/src/launch/pbs-aprun/launch-pbs-aprun.c | 4 ++-- .../pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c | 8 ++++---- .../slurm-gasnetrun_common.h | 2 +- runtime/src/launch/slurm-srun/launch-slurm-srun.c | 14 +++++++------- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/runtime/include/chpl-mem-desc.h b/runtime/include/chpl-mem-desc.h index a275a70a3364..7154540cf42b 100644 --- a/runtime/include/chpl-mem-desc.h +++ b/runtime/include/chpl-mem-desc.h @@ -53,6 +53,7 @@ extern "C" { m(SET_WIDE_STRING, "set wide string", true ), \ m(GET_WIDE_STRING, "get wide string", true ), \ m(COMMAND_BUFFER, "command buffer", true ), \ + m(FILENAME, "filename string", true ), \ m(COMM_UTIL, "comm layer utility space", false), \ m(COMM_XMIT_RCV_BUF, "comm layer transmit/receive buffer", false), \ m(COMM_FRK_SND_INFO, "comm layer sent remote fork info", false), \ diff --git a/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c b/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c index 003ff1005d5f..7b45a159ca85 100644 --- a/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c +++ b/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c @@ -246,7 +246,7 @@ static char** chpl_launch_create_argv(int argc, char* argv[], expectFilename=(char *)chpl_mem_allocMany((strlen(baseExpectFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1), - sizeof(char), CHPL_RT_MD_UNKNOWN, -1, 0); + sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); snprintf(expectFilename, FILENAME_MAX, "%s%d", baseExpectFilename, (int)mypid); @@ -399,7 +399,7 @@ static void chpl_launch_cleanup(void) { if (unlink(expectFilename)) { char* msg=(char *)chpl_mem_allocMany((strlen(expectFilename) + strlen(strerror(errno)) + 36), - sizeof(char), CHPL_RT_MD_UNKNOWN, -1, 0); + sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); snprintf(msg, FILENAME_MAX + 45, "Error removing temporary file '%s': %s", expectFilename, strerror(errno)); chpl_warning(msg, 0, 0); diff --git a/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c b/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c index e038347098fa..6fd3ce1763bf 100644 --- a/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c +++ b/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c @@ -171,15 +171,15 @@ static char* chpl_launch_create_command(int argc, char* argv[], mypid = 0; #endif sysFilename=(char *)chpl_mem_allocMany((strlen(baseSysFilename) + - snprintf(NULL, 0, "%d", (int)mypid) + 1), - sizeof(char), CHPL_RT_MD_UNKNOWN, -1, 0); + snprintf(NULL, 0, "%d", (int)mypid) + 1), + sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); expectFilename=(char *)chpl_mem_allocMany((strlen(baseExpectFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1), sizeof(char), - CHPL_RT_MD_UNKNOWN, -1, 0); + CHPL_RT_MD_FILENAME, -1, 0); pbsFilename=(char *)chpl_mem_allocMany((strlen(basePBSFilename) + snprintf(NULL, 0, "%d", (int)mypid) + - 1), sizeof(char), CHPL_RT_MD_UNKNOWN, + 1), sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); sprintf(sysFilename, "%s%d", baseSysFilename, (int)mypid); sprintf(expectFilename, "%s%d", baseExpectFilename, (int)mypid); diff --git a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h index 3fedace00114..8aead37f682b 100644 --- a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h +++ b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h @@ -236,7 +236,7 @@ static char* chpl_launch_create_command(int argc, char* argv[], slurmFilename=(char *)chpl_mem_allocMany((strlen(baseSBATCHFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1), sizeof(char), - CHPL_RT_MD_UNKNOWN, -1, 0); + CHPL_RT_MD_FILENAME, -1, 0); sprintf(slurmFilename, "%s%d", baseSBATCHFilename, (int)mypid); if (getenv("CHPL_LAUNCHER_USE_SBATCH") != NULL) { diff --git a/runtime/src/launch/slurm-srun/launch-slurm-srun.c b/runtime/src/launch/slurm-srun/launch-slurm-srun.c index 90c2dffc3018..d32319bb7685 100644 --- a/runtime/src/launch/slurm-srun/launch-slurm-srun.c +++ b/runtime/src/launch/slurm-srun/launch-slurm-srun.c @@ -246,7 +246,7 @@ static char* chpl_launch_create_command(int argc, char* argv[], slurmFilename=(char *)chpl_mem_allocMany((strlen(baseSBATCHFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1), sizeof(char), - CHPL_RT_MD_UNKNOWN, -1, 0); + CHPL_RT_MD_FILENAME, -1, 0); // set the sbatch filename sprintf(slurmFilename, "%s%d", baseSBATCHFilename, (int)mypid); @@ -309,18 +309,18 @@ static char* chpl_launch_create_command(int argc, char* argv[], // name or to the binaryName..out if none specified if (outputfn != NULL) { stdoutFile=(char *)chpl_mem_allocMany((strlen(outputfn) + 1), - sizeof(char), CHPL_RT_MD_UNKNOWN, -1, 0); + sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); sprintf(stdoutFile, "%s", outputfn); stdoutFileNoFmt=(char *)chpl_mem_allocMany((strlen(outputfn) + 1), - sizeof(char), CHPL_RT_MD_UNKNOWN, -1, 0); + sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); sprintf(stdoutFileNoFmt, "%s", outputfn); } else { stdoutFile=(char *)chpl_mem_allocMany((strlen(argv[0]) + 9), - sizeof(char), CHPL_RT_MD_UNKNOWN, -1, 0); + sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); sprintf(stdoutFile, "%s.%s.out", argv[0], "%j"); stdoutFileNoFmt=(char *)chpl_mem_allocMany((strlen(argv[0]) + 20), - sizeof(char), CHPL_RT_MD_UNKNOWN, -1, 0); + sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); sprintf(stdoutFileNoFmt, "%s.%s.out", argv[0], "$SLURM_JOB_ID"); } // We have slurm use the real output file to capture slurm errors/timeouts @@ -336,7 +336,7 @@ static char* chpl_launch_create_command(int argc, char* argv[], if (bufferStdout != NULL) { tmpStdoutFileNoFmt=(char *)chpl_mem_allocMany((strlen(tmpDir) + strlen(argv[0]) + 20), - sizeof(char), CHPL_RT_MD_UNKNOWN, -1, 0); + sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); sprintf(tmpStdoutFileNoFmt, "%s/%s.%s.out", tmpDir, argv[0], "$SLURM_JOB_ID"); } @@ -486,7 +486,7 @@ static void chpl_launch_cleanup(void) { if (unlink(slurmFilename)) { char* msg=(char *)chpl_mem_allocMany((strlen(slurmFilename) + strlen(strerror(errno)) + 36), - sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, 0); + sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); snprintf(msg, sizeof(msg), "Error removing temporary file '%s': %s", slurmFilename, strerror(errno)); chpl_warning(msg, 0, 0); From 021170eb5426fca8a57769a4b48bbd23e5f64c9c Mon Sep 17 00:00:00 2001 From: R Chinmay Date: Fri, 12 Feb 2021 00:27:52 +0530 Subject: [PATCH 06/18] Review Changes Signed-off-by: R Chinmay --- .../src/launch/pbs-aprun/launch-pbs-aprun.c | 9 +++-- .../slurm-gasnetrun_common.h | 16 +++++--- .../src/launch/slurm-srun/launch-slurm-srun.c | 38 ++++++++++++------- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c b/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c index 7b45a159ca85..82274c83731a 100644 --- a/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c +++ b/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c @@ -397,10 +397,11 @@ static void genQsubScript(int argc, char *argv[], int numLocales) { static void chpl_launch_cleanup(void) { if (!debug) { if (unlink(expectFilename)) { - char* msg=(char *)chpl_mem_allocMany((strlen(expectFilename) + - strlen(strerror(errno)) + 36), - sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); - snprintf(msg, FILENAME_MAX + 45, "Error removing temporary file '%s': %s", + char *format="Error removing temporary file '%s': %s"; + int msgLen=strlen(format) + strlen(expectFilename) + strlen(strerror(errno) + char* msg=(char *)chpl_mem_allocMany(msgLen, sizeof(char), + CHPL_RT_MD_COMMAND_BUFFER, -1, 0); + snprintf(msg, msgLen, "Error removing temporary file '%s': %s", expectFilename, strerror(errno)); chpl_warning(msg, 0, 0); chpl_mem_free(msg); diff --git a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h index 8aead37f682b..4d2fd8a77245 100644 --- a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h +++ b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h @@ -272,9 +272,11 @@ static char* chpl_launch_create_command(int argc, char* argv[], fclose(slurmFile); chmod(slurmFilename, 0755); - baseCommand=(char *)chpl_mem_allocMany((strlen(slurmFilename) + 9), - sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, 0); - sprintf(baseCommand, "sbatch %s\n", slurmFilename); + char* format="sbatch %s\n"; + int baseCommandLen=strlen(slurmFilename) + strlen(format); + baseCommand=(char *)chpl_mem_allocMany(baseCommandLen), sizeof(char), + CHPL_RT_MD_COMMAND_BUFFER, -1, 0); + sprintf(baseCommand, format, slurmFilename); } else { char iCom[2*FILENAME_MAX-10]; int len = 0; @@ -301,9 +303,11 @@ static char* chpl_launch_create_command(int argc, char* argv[], for (i=1; i/binaryName..out. if (bufferStdout != NULL) { - tmpStdoutFileNoFmt=(char *)chpl_mem_allocMany((strlen(tmpDir) + - strlen(argv[0]) + 20), + char* format = "%s/%s.%s.out"; + char* tempArg = "$SLURM_JOB_ID"; + int tmpStdoutFileNoFmtLen = strlen(format) + strlen(tmpDir) + + strlen(argv[0]) + strlen(tempArg); + tmpStdoutFileNoFmt = (char *)chpl_mem_allocMany(tmpStdoutFileNoFmtLen, sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); - sprintf(tmpStdoutFileNoFmt, "%s/%s.%s.out", tmpDir, argv[0], "$SLURM_JOB_ID"); + sprintf(tmpStdoutFileNoFmt, format, tmpDir, argv[0], tempArg); } // add the srun command and the (possibly wrapped) binary name. @@ -376,9 +383,11 @@ static char* chpl_launch_create_command(int argc, char* argv[], // the baseCommand is what will call the batch file // that was just created - baseCommand=(char *)chpl_mem_allocMany((strlen(slurmFilename) + 9), - sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, 0); - sprintf(baseCommand, "sbatch %s\n", slurmFilename); + char* format = "sbatch %s\n"; + int baseCommandLen = strlen(slurmFilename) + strlen(format); + baseCommand=(char *)chpl_mem_allocMany(baseCommandLen, sizeof(char), + CHPL_RT_MD_COMMAND_BUFFER, -1, 0); + sprintf(baseCommand, format, slurmFilename); } // else we're running an interactive job else { @@ -449,11 +458,12 @@ static char* chpl_launch_create_command(int argc, char* argv[], for (i=1; i Date: Mon, 9 Dec 2024 11:51:58 -0800 Subject: [PATCH 07/18] Use calculated buffer sizes for snprintf calls Also includes some formatting fixes Signed-off-by: Anna Rift --- .../src/launch/pbs-aprun/launch-pbs-aprun.c | 14 ++-- .../launch-pbs-gasnetrun_ibv.c | 21 +++--- .../slurm-gasnetrun_common.h | 32 +++++----- .../src/launch/slurm-srun/launch-slurm-srun.c | 64 ++++++++++--------- 4 files changed, 68 insertions(+), 63 deletions(-) diff --git a/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c b/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c index 0708987ed616..a1b6c8353b4d 100644 --- a/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c +++ b/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c @@ -236,12 +236,12 @@ static char** chpl_launch_create_argv(int argc, char* argv[], } else { mypid = 0; } - expectFilename=(char *)chpl_mem_allocMany((strlen(baseExpectFilename) + - snprintf(NULL, 0, "%d", (int)mypid) - + 1), - sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); - snprintf(expectFilename, FILENAME_MAX, "%s%d", - baseExpectFilename, (int)mypid); + int expectFilenameLen = + (strlen(baseExpectFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1); + expectFilename = (char*)chpl_mem_allocMany(expectFilenameLen, sizeof(char), + CHPL_RT_MD_FILENAME, -1, 0); + snprintf(expectFilename, expectFilenameLen, "%s%d", baseExpectFilename, + (int)mypid); initAprunAttributes(); numCoresPerLocale = getCoresPerLocale(); @@ -392,7 +392,7 @@ static void chpl_launch_cleanup(void) { if (unlink(expectFilename)) { char *format="Error removing temporary file '%s': %s"; int msgLen=strlen(format) + strlen(expectFilename) + strlen(strerror(errno) - char* msg=(char *)chpl_mem_allocMany(msgLen, sizeof(char), + char* msg=(char *)chpl_mem_allocMany(msgLen, sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, 0); snprintf(msg, msgLen, "Error removing temporary file '%s': %s", expectFilename, strerror(errno)); diff --git a/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c b/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c index b6c057192183..80f20d0a590a 100644 --- a/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c +++ b/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c @@ -167,16 +167,17 @@ static char* chpl_launch_create_command(int argc, char* argv[], #else mypid = 0; #endif - expectFilename=(char *)chpl_mem_allocMany((strlen(baseExpectFilename) + - snprintf(NULL, 0, "%d", (int)mypid) - + 1), sizeof(char), - CHPL_RT_MD_FILENAME, -1, 0); - pbsFilename=(char *)chpl_mem_allocMany((strlen(basePBSFilename) + - snprintf(NULL, 0, "%d", (int)mypid) + - 1), sizeof(char), CHPL_RT_MD_FILENAME, - -1, 0); - snprintf(expectFilename, FILENAME_MAX, "%s%d", baseExpectFilename, (int)mypid); - snprintf(pbsFilename, FILENAME_MAX, "%s%d", basePBSFilename, (int)mypid); + int expectFilenameLen = + (strlen(baseExpectFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1); + expectFilename = (char*)chpl_mem_allocMany(expectFilenameLen, sizeof(char), + CHPL_RT_MD_FILENAME, -1, 0); + int pbsFilenameLen = + (strlen(basePBSFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1); + pbsFilename = (char*)chpl_mem_allocMany(pbsFilenameLen, sizeof(char), + CHPL_RT_MD_FILENAME, -1, 0); + snprintf(expectFilename, expectFilenameLen, "%s%d", baseExpectFilename, + (int)mypid); + snprintf(pbsFilename, pbsFilenameLen, "%s%d", basePBSFilename, (int)mypid); pbsFile = fopen(pbsFilename, "w"); fprintf(pbsFile, "#!/bin/sh\n\n"); diff --git a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h index 117779e40956..3ef53f3e2c82 100644 --- a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h +++ b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h @@ -273,11 +273,12 @@ static char* chpl_launch_create_command(int argc, char* argv[], } else { mypid = getpid(); } - slurmFilename=(char *)chpl_mem_allocMany((strlen(baseSBATCHFilename) + - snprintf(NULL, 0, "%d", (int)mypid) - + 1), sizeof(char), - CHPL_RT_MD_FILENAME, -1, 0); - snprintf(slurmFilename, FILENAME_MAX, "%s%d", baseSBATCHFilename, (int)mypid); + int slurmFilenameLen = + (strlen(baseSBATCHFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1); + slurmFilename = (char*)chpl_mem_allocMany(slurmFilenameLen, sizeof(char), + CHPL_RT_MD_FILENAME, -1, 0); + snprintf(slurmFilename, slurmFilenameLen, "%s%d", baseSBATCHFilename, + (int)mypid); if (getenv("CHPL_LAUNCHER_USE_SBATCH") != NULL) { slurmFile = fopen(slurmFilename, "w"); @@ -314,10 +315,10 @@ static char* chpl_launch_create_command(int argc, char* argv[], fclose(slurmFile); chmod(slurmFilename, 0755); char* format="sbatch %s\n"; - int baseCommandLen=strlen(slurmFilename) + strlen(format); - baseCommand=(char *)chpl_mem_allocMany(baseCommandLen), sizeof(char), - CHPL_RT_MD_COMMAND_BUFFER, -1, 0); - snprintf(baseCommand, FILENAME_MAX, format, slurmFilename); + int baseCommandLen = strlen(slurmFilename) + strlen(format); + baseCommand = (char*)chpl_mem_allocMany(baseCommandLen, sizeof(char), + CHPL_RT_MD_COMMAND_BUFFER, -1, 0); + snprintf(baseCommand, baseCommandLen, format, slurmFilename); } else { char iCom[2*FILENAME_MAX-10]; int len = 0; @@ -358,16 +359,17 @@ static char* chpl_launch_create_command(int argc, char* argv[], } char* format="salloc %s"; int baseCommandLen = strlen(format) + len; - baseCommand=(char *)chpl_mem_allocMany(baseCommandLen), sizeof(char), - CHPL_RT_MD_COMMAND_BUFFER, -1, 0); - snprintf(baseCommand, FILENAME_MAX, format, iCom); + baseCommand = (char*)chpl_mem_allocMany(baseCommandLen, sizeof(char), + CHPL_RT_MD_COMMAND_BUFFER, -1, 0); + snprintf(baseCommand, baseCommandLen, format, iCom); } size = strlen(baseCommand) + 1; - command = chpl_mem_allocMany(size, sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, 0); - - snprintf(command, FILENAME_MAX, "%s", baseCommand); + command = + chpl_mem_allocMany(size, sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, 0); + + snprintf(command, size, "%s", baseCommand); chpl_mem_free(baseCommand); if (strlen(command)+1 > size) { chpl_internal_error("buffer overflow"); diff --git a/runtime/src/launch/slurm-srun/launch-slurm-srun.c b/runtime/src/launch/slurm-srun/launch-slurm-srun.c index f717b82721ae..f8ec0efe87de 100644 --- a/runtime/src/launch/slurm-srun/launch-slurm-srun.c +++ b/runtime/src/launch/slurm-srun/launch-slurm-srun.c @@ -360,10 +360,9 @@ 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); + slurmFilename = (char*)chpl_mem_allocMany( + (strlen(baseSBATCHFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1), + sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); // set the sbatch filename snprintf(slurmFilename, sizeof(slurmFilename), "%s%d", baseSBATCHFilename, (int)mypid); @@ -435,24 +434,26 @@ static char* chpl_launch_create_command(int argc, char* argv[], // set the output file name to either the user specified // name or to the binaryName..out if none specified if (outputfn != NULL) { - stdoutFile=(char *)chpl_mem_allocMany((strlen(outputfn) + 1), - sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); - snprintf(stdoutFile, FILENAME_MAX, "%s", outputfn); - stdoutFileNoFmt=(char *)chpl_mem_allocMany((strlen(outputfn) + 1), - sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); - snprintf(stdoutFileNoFmt, FILENAME_MAX, "%s", outputfn); + int stdoutFileLen = (strlen(outputfn) + 1); + stdoutFile = (char*)chpl_mem_allocMany(stdoutFileLen, sizeof(char), + CHPL_RT_MD_FILENAME, -1, 0); + snprintf(stdoutFile, stdoutFileLen, "%s", outputfn); + stdoutFileNoFmt = (char*)chpl_mem_allocMany(stdoutFileLen, sizeof(char), + CHPL_RT_MD_FILENAME, -1, 0); + snprintf(stdoutFileNoFmt, stdoutFileLen, "%s", outputfn); } else { char* format="%s.%s.out"; - int stdoutFileLen = strlen(format) + strlen(argv[0])+ strlen("%j"); - stdoutFile=(char *)chpl_mem_allocMany(stdoutFileLen, sizeof(char), - CHPL_RT_MD_FILENAME, -1, 0); - snprintf(stdoutFile, FILENAME_MAX, format, argv[0], "%j"); + int stdoutFileLen = strlen(format) + strlen(argv[0]) + strlen("%j"); + stdoutFile = (char*)chpl_mem_allocMany(stdoutFileLen, sizeof(char), + CHPL_RT_MD_FILENAME, -1, 0); + snprintf(stdoutFile, stdoutFileLen, format, argv[0], "%j"); char* tempArg = "$SLURM_JOB_ID"; - int stdoutFileNoFmtLen = strlen(format) + strlen(argv[0]) + strlen(tempArg); - stdoutFileNoFmt=(char *)chpl_mem_allocMany(stdoutFileNoFmtLen, - sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); - snprintf(stdoutFileNoFmt, FILENAME_MAX, format, argv[0], tempArg); + int stdoutFileNoFmtLen = + strlen(format) + strlen(argv[0]) + strlen(tempArg); + stdoutFileNoFmt = (char*)chpl_mem_allocMany( + stdoutFileNoFmtLen, sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); + snprintf(stdoutFileNoFmt, stdoutFileNoFmtLen, format, argv[0], tempArg); } // We have slurm use the real output file to capture slurm errors/timeouts // We only redirect the program output to the tmp file @@ -467,11 +468,12 @@ static char* chpl_launch_create_command(int argc, char* argv[], if (bufferStdout != NULL) { char* format = "%s/%s.%s.out"; char* tempArg = "$SLURM_JOB_ID"; - int tmpStdoutFileNoFmtLen = strlen(format) + strlen(tmpDir) + - strlen(argv[0]) + strlen(tempArg); - tmpStdoutFileNoFmt = (char *)chpl_mem_allocMany(tmpStdoutFileNoFmtLen, - sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); - snprintf(tmpStdoutFileNoFmt, FILENAME_MAX, format, tmpDir, argv[0], tempArg); + int tmpStdoutFileNoFmtLen = + strlen(format) + strlen(tmpDir) + strlen(argv[0]) + strlen(tempArg); + tmpStdoutFileNoFmt = (char*)chpl_mem_allocMany( + tmpStdoutFileNoFmtLen, sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); + snprintf(tmpStdoutFileNoFmt, tmpStdoutFileNoFmtLen, format, tmpDir, + argv[0], tempArg); } // add the srun command @@ -518,12 +520,12 @@ static char* chpl_launch_create_command(int argc, char* argv[], } // the baseCommand is what will call the batch file - // that was just created + // that was just created char* format = "sbatch %s\n"; int baseCommandLen = strlen(slurmFilename) + strlen(format); - baseCommand=(char *)chpl_mem_allocMany(baseCommandLen, sizeof(char), - CHPL_RT_MD_COMMAND_BUFFER, -1, 0); - snprintf(baseCommand, FILENAME_MAX, format, slurmFilename); + baseCommand = (char*)chpl_mem_allocMany(baseCommandLen, sizeof(char), + CHPL_RT_MD_COMMAND_BUFFER, -1, 0); + snprintf(baseCommand, baseCommandLen, format, slurmFilename); } // else we're running an interactive job else { @@ -620,7 +622,7 @@ static char* chpl_launch_create_command(int argc, char* argv[], // copy baseCommand into command and return it size = strlen(baseCommand) + 1; command = chpl_mem_allocMany(size, sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, 0); - snprintf(command, FILENAME_MAX, "%s", baseCommand); + snprintf(command, size, "%s", baseCommand); //free dynamically allocated memory chpl_mem_free(baseCommand); chpl_mem_free(stdoutFile); @@ -646,9 +648,9 @@ 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); + char* msg = (char*)chpl_mem_allocMany( + (strlen(slurmFilename) + strlen(strerror(errno)) + 36), + sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); snprintf(msg, sizeof(msg), "Error removing temporary file '%s': %s", slurmFilename, strerror(errno)); chpl_warning(msg, 0, 0); From aa9398e4ad82c032b3f977f2aa50ab6a65ba209e Mon Sep 17 00:00:00 2001 From: Anna Rift Date: Mon, 9 Dec 2024 11:57:48 -0800 Subject: [PATCH 08/18] Remove commented use and extraneous free of sysFilename Signed-off-by: Anna Rift --- runtime/src/launch/aprun/launch-aprun.c | 3 --- .../src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c | 1 - 2 files changed, 4 deletions(-) diff --git a/runtime/src/launch/aprun/launch-aprun.c b/runtime/src/launch/aprun/launch-aprun.c index f6d14099409d..1c763202a3ef 100644 --- a/runtime/src/launch/aprun/launch-aprun.c +++ b/runtime/src/launch/aprun/launch-aprun.c @@ -29,9 +29,6 @@ #include "error.h" #include "aprun-utils.h" -// #define baseSysFilename ".chpl-sys-" -// char sysFilename[FILENAME_MAX]; - #define CHPL_CC_ARG "-cc" static const char *_ccArg = NULL; static const char* debug = NULL; diff --git a/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c b/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c index 80f20d0a590a..c9fc541242f6 100644 --- a/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c +++ b/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c @@ -263,7 +263,6 @@ static void chpl_launch_cleanup(void) { #endif chpl_mem_free(pbsFilename); chpl_mem_free(expectFilename); - chpl_mem_free(sysFilename); } From 717dd47af66c3ff77f5a1c8253379bc831f12105 Mon Sep 17 00:00:00 2001 From: Anna Rift Date: Mon, 9 Dec 2024 12:41:35 -0800 Subject: [PATCH 09/18] Use helper to build up command str Signed-off-by: Anna Rift --- .../slurm-gasnetrun_common.h | 94 +++++++++++-------- 1 file changed, 56 insertions(+), 38 deletions(-) diff --git a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h index 3ef53f3e2c82..df8415440eda 100644 --- a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h +++ b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h @@ -173,17 +173,46 @@ static void genNumLocalesOptions(FILE* slurmFile, sbatchVersion sbatch, } } -static int propagate_environment(char* buf, size_t size) +static void propagate_environment(char* buf, size_t size) { - int len = 0; - // Indiscriminately propagate all environment variables. // We could do this more selectively, but we would be likely // to leave out something important. char *enviro_keys = chpl_get_enviro_keys(','); - if (enviro_keys) - len += snprintf(buf, size, " -E '%s'", enviro_keys); - return len; + if (enviro_keys) appendToCmdBuf(buf, " -E '%s'", enviro_keys); +} + +// Helper for appending arguments to a variable-size command buffer. +// - Requires the buffer pointer is uninitialized on first call. +// - After exceeding an initial allocated size estimate, each call will allocate +// additional memory as needed. +static char* appendToCmdBuf(char* com, const char* format, ...) { + static const int initialSize = 2048; + static int charsWritten = 0; + + if (charsWritten == 0) { + assert(com == NULL); + com = (char*)chpl_mem_allocMany(initialSize, sizeof(char), + CHPL_RT_MD_COMMAND_BUFFER, -1, 0); + } + + va_list argsForLen, argsForPrint; + va_start(argsForLen, format); + va_copy(argsForPrint, argsForLen); + + const int addedLen = vsnprintf(NULL, 0, format, argsForLen); + va_end(argsForLen); + int newLen = charsWritten + addedLen; + + if (newLen >= initialSize) { + com = (char*)chpl_mem_realloc(com, newLen * sizeof(char), + CHPL_RT_MD_COMMAND_BUFFER, -1, 0); + } + + vsnprintf(com + charsWritten, addedLen + 1, format, argsForPrint); + va_end(argsForPrint); + + charsWritten = newLen; } static char* chpl_launch_create_command(int argc, char* argv[], @@ -302,7 +331,7 @@ static char* chpl_launch_create_command(int argc, char* argv[], CHPL_THIRD_PARTY, WRAP_TO_STR(LAUNCH_PATH), GASNETRUN_LAUNCHER, numLocales, numLocales); - propagate_environment(envProp, sizeof(envProp)); + propagate_environment(envProp); fprintf(slurmFile, "%s", envProp); fprintf(slurmFile, " %s %s", chpl_get_real_binary_wrapper(), chpl_get_real_binary_name()); @@ -320,45 +349,34 @@ static char* chpl_launch_create_command(int argc, char* argv[], CHPL_RT_MD_COMMAND_BUFFER, -1, 0); snprintf(baseCommand, baseCommandLen, format, slurmFilename); } else { - char iCom[2*FILENAME_MAX-10]; - int len = 0; + char* iCom = NULL; if (!getSlurmDebug()) { - len += snprintf(iCom+len, sizeof(iCom)-len, "--quiet "); + appendToCmdBuf(iCom, "--quiet "); } - len += snprintf(iCom+len, sizeof(iCom)-len, "-J %s ", jobName); - len += snprintf(iCom+len, sizeof(iCom)-len, "-N %d ", numNodes); - len += snprintf(iCom+len, sizeof(iCom)-len, "--ntasks=%d ", numLocales); - if (nodeAccessStr != NULL) - len += snprintf(iCom+len, sizeof(iCom)-len, "--%s ", nodeAccessStr); - if (walltime) - len += snprintf(iCom+len, sizeof(iCom)-len, "--time=%s ", walltime); - if (nodelist) - len += snprintf(iCom+len, sizeof(iCom)-len, "--nodelist=%s ", nodelist); - if(partition) - len += snprintf(iCom+len, sizeof(iCom)-len, "--partition=%s ", partition); - if(exclude) - len += snprintf(iCom+len, sizeof(iCom)-len, "--exclude=%s ", exclude); - if(gpusPerNode) - len += snprintf(iCom+len, sizeof(iCom)-len, "--gpus-per-node=%s ", gpusPerNode); - if(projectString && strlen(projectString) > 0) - len += snprintf(iCom+len, sizeof(iCom)-len, "--account=%s ", - projectString); - if (constraint) - len += snprintf(iCom+len, sizeof(iCom)-len, " -C %s", constraint); - len += snprintf(iCom+len, sizeof(iCom)-len, - " %s/%s/%s -n %d -N %d -c 0", + appendToCmdBuf(iCom, "-J %s ", jobName); + appendToCmdBuf(iCom, "-N %d ", numNodes); + appendToCmdBuf(iCom, "--ntasks=%d ", numLocales); + if (nodeAccessStr != NULL) appendToCmdBuf(iCom, "--%s ", nodeAccessStr); + if (walltime) appendToCmdBuf(iCom, "--time=%s ", walltime); + if (nodelist) appendToCmdBuf(iCom, "--nodelist=%s ", nodelist); + if (partition) appendToCmdBuf(iCom, "--partition=%s ", partition); + if (exclude) appendToCmdBuf(iCom, "--exclude=%s ", exclude); + if (gpusPerNode) appendToCmdBuf(iCom, "--gpus-per-node=%s ", gpusPerNode); + if (projectString && strlen(projectString) > 0) + appendToCmdBuf(iCom, "--account=%s ", projectString); + if (constraint) appendToCmdBuf(iCom, "-C %s", constraint); + appendToCmdBuf(iCom, " %s/%s/%s -n %d -N %d -c 0", CHPL_THIRD_PARTY, WRAP_TO_STR(LAUNCH_PATH), GASNETRUN_LAUNCHER, numLocales, numNodes); - len += propagate_environment(iCom+len, sizeof(iCom) - len); - len += snprintf(iCom+len, sizeof(iCom)-len, " %s %s", - chpl_get_real_binary_wrapper(), + propagate_environment(iCom); + appendToCmdBuf(iCom, " %s %s", chpl_get_real_binary_wrapper(), chpl_get_real_binary_name()); for (i=1; i Date: Mon, 9 Dec 2024 12:47:00 -0800 Subject: [PATCH 10/18] Reuse helper for another command str Signed-off-by: Anna Rift --- runtime/include/chpllaunch.h | 1 + runtime/src/chpl-launcher-common.c | 33 ++++++++++ .../slurm-gasnetrun_common.h | 64 +++++-------------- .../src/launch/slurm-srun/launch-slurm-srun.c | 50 +++++++-------- 4 files changed, 74 insertions(+), 74 deletions(-) diff --git a/runtime/include/chpllaunch.h b/runtime/include/chpllaunch.h index 43c1926c6b29..01b04e08926b 100644 --- a/runtime/include/chpllaunch.h +++ b/runtime/include/chpllaunch.h @@ -45,6 +45,7 @@ typedef struct { int chpl_doDryRun(void); void chpl_append_to_largv(int* largc, const char*** largv, int* largv_len, const char* arg); +char* chpl_append_to_cmd(char* cmdBuf, const char* format, ...); int chpl_run_utility1K(const char *command, char *const argv[], char *outbuf, int outbuflen); int chpl_run_cmdstr(const char *commandStr, char *outbuf, int outbuflen); diff --git a/runtime/src/chpl-launcher-common.c b/runtime/src/chpl-launcher-common.c index c5abe13877ba..2045ac922d3b 100644 --- a/runtime/src/chpl-launcher-common.c +++ b/runtime/src/chpl-launcher-common.c @@ -102,6 +102,39 @@ void chpl_append_to_largv(int* largc, const char*** largv, int* largv_len, (*largv)[(*largc)++] = (arg); } +// Helper for appending arguments to a variable-size command buffer. +// - Requires the buffer pointer is uninitialized on first call. +// - After exceeding an initial allocated size estimate, each call will allocate +// additional memory as needed. +char* chpl_append_to_cmd(char* cmdBuf, const char* format, ...) { + static const int initialSize = 2048; + static int charsWritten = 0; + + if (charsWritten == 0) { + assert(cmdBuf == NULL); + cmdBuf = (char*)chpl_mem_allocMany(initialSize, sizeof(char), + CHPL_RT_MD_COMMAND_BUFFER, -1, 0); + } + + va_list argsForLen, argsForPrint; + va_start(argsForLen, format); + va_copy(argsForPrint, argsForLen); + + const int addedLen = vsnprintf(NULL, 0, format, argsForLen); + va_end(argsForLen); + int newLen = charsWritten + addedLen; + + if (newLen >= initialSize) { + cmdBuf = (char*)chpl_mem_realloc(cmdBuf, newLen * sizeof(char), + CHPL_RT_MD_COMMAND_BUFFER, -1, 0); + } + + vsnprintf(cmdBuf + charsWritten, addedLen + 1, format, argsForPrint); + va_end(argsForPrint); + + charsWritten = newLen; +} + // // Use this function to run short utility programs that will return less // than 1024 characters of output. The program must not expect any input. diff --git a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h index df8415440eda..650864d1fcd5 100644 --- a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h +++ b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h @@ -179,41 +179,9 @@ static void propagate_environment(char* buf, size_t size) // We could do this more selectively, but we would be likely // to leave out something important. char *enviro_keys = chpl_get_enviro_keys(','); - if (enviro_keys) appendToCmdBuf(buf, " -E '%s'", enviro_keys); + if (enviro_keys) chpl_append_to_cmd(buf, " -E '%s'", enviro_keys); } -// Helper for appending arguments to a variable-size command buffer. -// - Requires the buffer pointer is uninitialized on first call. -// - After exceeding an initial allocated size estimate, each call will allocate -// additional memory as needed. -static char* appendToCmdBuf(char* com, const char* format, ...) { - static const int initialSize = 2048; - static int charsWritten = 0; - - if (charsWritten == 0) { - assert(com == NULL); - com = (char*)chpl_mem_allocMany(initialSize, sizeof(char), - CHPL_RT_MD_COMMAND_BUFFER, -1, 0); - } - - va_list argsForLen, argsForPrint; - va_start(argsForLen, format); - va_copy(argsForPrint, argsForLen); - - const int addedLen = vsnprintf(NULL, 0, format, argsForLen); - va_end(argsForLen); - int newLen = charsWritten + addedLen; - - if (newLen >= initialSize) { - com = (char*)chpl_mem_realloc(com, newLen * sizeof(char), - CHPL_RT_MD_COMMAND_BUFFER, -1, 0); - } - - vsnprintf(com + charsWritten, addedLen + 1, format, argsForPrint); - va_end(argsForPrint); - - charsWritten = newLen; -} static char* chpl_launch_create_command(int argc, char* argv[], int32_t numLocales, @@ -352,28 +320,28 @@ static char* chpl_launch_create_command(int argc, char* argv[], char* iCom = NULL; if (!getSlurmDebug()) { - appendToCmdBuf(iCom, "--quiet "); + chpl_append_to_cmd(iCom, "--quiet "); } - appendToCmdBuf(iCom, "-J %s ", jobName); - appendToCmdBuf(iCom, "-N %d ", numNodes); - appendToCmdBuf(iCom, "--ntasks=%d ", numLocales); - if (nodeAccessStr != NULL) appendToCmdBuf(iCom, "--%s ", nodeAccessStr); - if (walltime) appendToCmdBuf(iCom, "--time=%s ", walltime); - if (nodelist) appendToCmdBuf(iCom, "--nodelist=%s ", nodelist); - if (partition) appendToCmdBuf(iCom, "--partition=%s ", partition); - if (exclude) appendToCmdBuf(iCom, "--exclude=%s ", exclude); - if (gpusPerNode) appendToCmdBuf(iCom, "--gpus-per-node=%s ", gpusPerNode); + chpl_append_to_cmd(iCom, "-J %s ", jobName); + chpl_append_to_cmd(iCom, "-N %d ", numNodes); + chpl_append_to_cmd(iCom, "--ntasks=%d ", numLocales); + if (nodeAccessStr != NULL) chpl_append_to_cmd(iCom, "--%s ", nodeAccessStr); + if (walltime) chpl_append_to_cmd(iCom, "--time=%s ", walltime); + if (nodelist) chpl_append_to_cmd(iCom, "--nodelist=%s ", nodelist); + if (partition) chpl_append_to_cmd(iCom, "--partition=%s ", partition); + if (exclude) chpl_append_to_cmd(iCom, "--exclude=%s ", exclude); + if (gpusPerNode) chpl_append_to_cmd(iCom, "--gpus-per-node=%s ", gpusPerNode); if (projectString && strlen(projectString) > 0) - appendToCmdBuf(iCom, "--account=%s ", projectString); - if (constraint) appendToCmdBuf(iCom, "-C %s", constraint); - appendToCmdBuf(iCom, " %s/%s/%s -n %d -N %d -c 0", + chpl_append_to_cmd(iCom, "--account=%s ", projectString); + if (constraint) chpl_append_to_cmd(iCom, "-C %s", constraint); + chpl_append_to_cmd(iCom, " %s/%s/%s -n %d -N %d -c 0", CHPL_THIRD_PARTY, WRAP_TO_STR(LAUNCH_PATH), GASNETRUN_LAUNCHER, numLocales, numNodes); propagate_environment(iCom); - appendToCmdBuf(iCom, " %s %s", chpl_get_real_binary_wrapper(), + chpl_append_to_cmd(iCom, " %s %s", chpl_get_real_binary_wrapper(), chpl_get_real_binary_name()); for (i=1; i 1) { - len += snprintf(iCom+len, sizeof(iCom)-len, "--cpu-bind=none "); + chpl_append_to_cmd(iCom, "--cpu-bind=none "); } // request specified node access if (nodeAccessStr != NULL) - len += snprintf(iCom+len, sizeof(iCom)-len, "--%s ", nodeAccessStr); + chpl_append_to_cmd(iCom, "--%s ", nodeAccessStr); // request specified amount of memory if (memStr != NULL) - len += snprintf(iCom+len, sizeof(iCom)-len, "--mem=%s ", memStr); + chpl_append_to_cmd(iCom, "--mem=%s ", memStr); // kill the job if any program instance halts with non-zero exit status - len += snprintf(iCom+len, sizeof(iCom)-len, "--kill-on-bad-exit "); + chpl_append_to_cmd(iCom, "--kill-on-bad-exit "); // Set the walltime if it was specified if (walltime) { - len += snprintf(iCom+len, sizeof(iCom)-len, "--time=%s ",walltime); + chpl_append_to_cmd(iCom, "--time=%s ", walltime); } // Set the nodelist if it was specified if (nodelist) { - len += snprintf(iCom+len, sizeof(iCom)-len, "--nodelist=%s ", nodelist); + chpl_append_to_cmd(iCom, "--nodelist=%s ", nodelist); } // Set the partition if it was specified if (partition) { - len += snprintf(iCom+len, sizeof(iCom)-len, "--partition=%s ", - partition); + chpl_append_to_cmd(iCom, "--partition=%s ", partition); } // Set the exclude list if it was specified if (exclude) { - len += snprintf(iCom+len, sizeof(iCom)-len, "--exclude=%s ", exclude); + chpl_append_to_cmd(iCom, "--exclude=%s ", exclude); } // Set the gpus per node if it was specified if (gpusPerNode) { - len += snprintf(iCom+len, sizeof(iCom)-len, "--gpus-per-node=%s ", - gpusPerNode); + chpl_append_to_cmd(iCom, "--gpus-per-node=%s ", gpusPerNode); } // set any constraints if (constraint) { - len += snprintf(iCom+len, sizeof(iCom)-len, "--constraint=%s ", constraint); + chpl_append_to_cmd(iCom, "--constraint=%s ", constraint); } // set the account name if one was provided if (account && strlen(account) > 0) { - len += snprintf(iCom+len, sizeof(iCom)-len, "--account=%s ", account); + chpl_append_to_cmd(iCom, "--account=%s ", account); } // add the (possibly wrapped) binary name - len += snprintf(iCom+len, sizeof(iCom)-len, "%s %s", + chpl_append_to_cmd(iCom, "%s %s ", chpl_get_real_binary_wrapper(), chpl_get_real_binary_name()); // add any arguments passed to the launcher to the binary for (i=1; i Date: Mon, 9 Dec 2024 12:53:58 -0800 Subject: [PATCH 11/18] Comment helper function body Signed-off-by: Anna Rift --- runtime/src/chpl-launcher-common.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/runtime/src/chpl-launcher-common.c b/runtime/src/chpl-launcher-common.c index 2045ac922d3b..b30bedc8d90c 100644 --- a/runtime/src/chpl-launcher-common.c +++ b/runtime/src/chpl-launcher-common.c @@ -110,28 +110,31 @@ char* chpl_append_to_cmd(char* cmdBuf, const char* format, ...) { static const int initialSize = 2048; static int charsWritten = 0; + va_list argsForLen, argsForPrint; + va_start(argsForLen, format); + va_copy(argsForPrint, argsForLen); + + // Allocate buffer to initial size on first call if (charsWritten == 0) { assert(cmdBuf == NULL); cmdBuf = (char*)chpl_mem_allocMany(initialSize, sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, 0); } - va_list argsForLen, argsForPrint; - va_start(argsForLen, format); - va_copy(argsForPrint, argsForLen); - + // Determine additional characters to be written const int addedLen = vsnprintf(NULL, 0, format, argsForLen); va_end(argsForLen); int newLen = charsWritten + addedLen; + // Allocate more memory if needed if (newLen >= initialSize) { cmdBuf = (char*)chpl_mem_realloc(cmdBuf, newLen * sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, 0); } + // Write the new characters vsnprintf(cmdBuf + charsWritten, addedLen + 1, format, argsForPrint); va_end(argsForPrint); - charsWritten = newLen; } From 6f0911a5f989c646a934264b3f30f1539ace1000 Mon Sep 17 00:00:00 2001 From: Anna Rift Date: Mon, 9 Dec 2024 12:57:06 -0800 Subject: [PATCH 12/18] Put back sysFilename comment To avoid out-of-scope change Signed-off-by: Anna Rift --- runtime/src/launch/aprun/launch-aprun.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runtime/src/launch/aprun/launch-aprun.c b/runtime/src/launch/aprun/launch-aprun.c index 1c763202a3ef..f6d14099409d 100644 --- a/runtime/src/launch/aprun/launch-aprun.c +++ b/runtime/src/launch/aprun/launch-aprun.c @@ -29,6 +29,9 @@ #include "error.h" #include "aprun-utils.h" +// #define baseSysFilename ".chpl-sys-" +// char sysFilename[FILENAME_MAX]; + #define CHPL_CC_ARG "-cc" static const char *_ccArg = NULL; static const char* debug = NULL; From d9e8dbda8379f12c1a4f557a8cb3d67b3dfc61d0 Mon Sep 17 00:00:00 2001 From: Anna Rift Date: Mon, 9 Dec 2024 13:04:02 -0800 Subject: [PATCH 13/18] Format cleanups Signed-off-by: Anna Rift --- runtime/src/launch/pbs-aprun/launch-pbs-aprun.c | 13 +++++++------ .../pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c | 8 ++++---- .../slurm-gasnetrun_common/slurm-gasnetrun_common.h | 3 +-- runtime/src/launch/slurm-srun/launch-slurm-srun.c | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c b/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c index a1b6c8353b4d..2e1b6ae3ad10 100644 --- a/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c +++ b/runtime/src/launch/pbs-aprun/launch-pbs-aprun.c @@ -50,7 +50,7 @@ static char* walltime = NULL; static char* queue = NULL; static int generate_qsub_script = 0; -static char* expectFilename=NULL; +static char* expectFilename = NULL; extern int fileno(FILE *stream); @@ -237,7 +237,7 @@ static char** chpl_launch_create_argv(int argc, char* argv[], mypid = 0; } int expectFilenameLen = - (strlen(baseExpectFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1); + strlen(baseExpectFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1; expectFilename = (char*)chpl_mem_allocMany(expectFilenameLen, sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); snprintf(expectFilename, expectFilenameLen, "%s%d", baseExpectFilename, @@ -390,10 +390,11 @@ static void genQsubScript(int argc, char *argv[], int numLocales) { static void chpl_launch_cleanup(void) { if (!chpl_doDryRun() && !debug) { if (unlink(expectFilename)) { - char *format="Error removing temporary file '%s': %s"; - int msgLen=strlen(format) + strlen(expectFilename) + strlen(strerror(errno) - char* msg=(char *)chpl_mem_allocMany(msgLen, sizeof(char), - CHPL_RT_MD_COMMAND_BUFFER, -1, 0); + char* format = "Error removing temporary file '%s': %s"; + int msgLen = + strlen(format) + strlen(expectFilename) + strlen(strerror(errno)); + char* msg = (char*)chpl_mem_allocMany(msgLen, sizeof(char), + CHPL_RT_MD_COMMAND_BUFFER, -1, 0); snprintf(msg, msgLen, "Error removing temporary file '%s': %s", expectFilename, strerror(errno)); chpl_warning(msg, 0, 0); diff --git a/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c b/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c index c9fc541242f6..a05db314aec3 100644 --- a/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c +++ b/runtime/src/launch/pbs-gasnetrun_ibv/launch-pbs-gasnetrun_ibv.c @@ -41,8 +41,8 @@ static char* walltime = NULL; #define basePBSFilename ".chpl-pbs-qsub-" #define baseExpectFilename ".chpl-expect-" -char* pbsFilename=NULL; -char* expectFilename=NULL; +char* pbsFilename = NULL; +char* expectFilename = NULL; #define launcherAccountEnvvar "CHPL_LAUNCHER_ACCOUNT" @@ -168,11 +168,11 @@ static char* chpl_launch_create_command(int argc, char* argv[], mypid = 0; #endif int expectFilenameLen = - (strlen(baseExpectFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1); + strlen(baseExpectFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1; expectFilename = (char*)chpl_mem_allocMany(expectFilenameLen, sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); int pbsFilenameLen = - (strlen(basePBSFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1); + strlen(basePBSFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1; pbsFilename = (char*)chpl_mem_allocMany(pbsFilenameLen, sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); snprintf(expectFilename, expectFilenameLen, "%s%d", baseExpectFilename, diff --git a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h index 650864d1fcd5..f90cf5c14bc9 100644 --- a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h +++ b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h @@ -182,7 +182,6 @@ static void propagate_environment(char* buf, size_t size) if (enviro_keys) chpl_append_to_cmd(buf, " -E '%s'", enviro_keys); } - static char* chpl_launch_create_command(int argc, char* argv[], int32_t numLocales, int32_t numLocalesPerNode) { @@ -271,7 +270,7 @@ static char* chpl_launch_create_command(int argc, char* argv[], mypid = getpid(); } int slurmFilenameLen = - (strlen(baseSBATCHFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1); + strlen(baseSBATCHFilename) + snprintf(NULL, 0, "%d", (int)mypid) + 1; slurmFilename = (char*)chpl_mem_allocMany(slurmFilenameLen, sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); snprintf(slurmFilename, slurmFilenameLen, "%s%d", baseSBATCHFilename, diff --git a/runtime/src/launch/slurm-srun/launch-slurm-srun.c b/runtime/src/launch/slurm-srun/launch-slurm-srun.c index dd017f44331e..6e2ef3a32bae 100644 --- a/runtime/src/launch/slurm-srun/launch-slurm-srun.c +++ b/runtime/src/launch/slurm-srun/launch-slurm-srun.c @@ -434,7 +434,7 @@ static char* chpl_launch_create_command(int argc, char* argv[], // set the output file name to either the user specified // name or to the binaryName..out if none specified if (outputfn != NULL) { - int stdoutFileLen = (strlen(outputfn) + 1); + int stdoutFileLen = strlen(outputfn) + 1; stdoutFile = (char*)chpl_mem_allocMany(stdoutFileLen, sizeof(char), CHPL_RT_MD_FILENAME, -1, 0); snprintf(stdoutFile, stdoutFileLen, "%s", outputfn); @@ -506,8 +506,8 @@ static char* chpl_launch_create_command(int argc, char* argv[], if (bufferStdout != NULL) { fprintf(slurmFile, "cat %s >> %s\n", tmpStdoutFileNoFmt, stdoutFileNoFmt); fprintf(slurmFile, "rm %s &> /dev/null\n", tmpStdoutFileNoFmt); - //tmpStdoutFileNoFmt is only allocated memory if bufferStdout!=NULL - //Hence free up inside this condition. + // tmpStdoutFileNoFmt is only allocated memory if bufferStdout!=NULL + // Hence free up inside this condition. chpl_mem_free(tmpStdoutFileNoFmt); } @@ -621,7 +621,7 @@ static char* chpl_launch_create_command(int argc, char* argv[], size = strlen(baseCommand) + 1; command = chpl_mem_allocMany(size, sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, 0); snprintf(command, size, "%s", baseCommand); - //free dynamically allocated memory + // free dynamically allocated memory chpl_mem_free(baseCommand); chpl_mem_free(stdoutFile); chpl_mem_free(stdoutFileNoFmt); From 36009a47f4d7b9dc891e05e0c26d60d9d7990f23 Mon Sep 17 00:00:00 2001 From: Anna Rift Date: Mon, 9 Dec 2024 13:08:34 -0800 Subject: [PATCH 14/18] Add assert.h include Signed-off-by: Anna Rift --- runtime/src/chpl-launcher-common.c | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/src/chpl-launcher-common.c b/runtime/src/chpl-launcher-common.c index b30bedc8d90c..935d40615787 100644 --- a/runtime/src/chpl-launcher-common.c +++ b/runtime/src/chpl-launcher-common.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "chplcgfns.h" #include "chpl-comm-launch.h" #include "chpl-comm-locales.h" From f269fb2a663209d848763e11dbb6042e19748f13 Mon Sep 17 00:00:00 2001 From: Anna Rift Date: Tue, 10 Dec 2024 13:54:49 -0800 Subject: [PATCH 15/18] Remove now-unused size arg to propagate_environment Signed-off-by: Anna Rift --- .../src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h index f90cf5c14bc9..46971d1ef9ef 100644 --- a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h +++ b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h @@ -173,7 +173,7 @@ static void genNumLocalesOptions(FILE* slurmFile, sbatchVersion sbatch, } } -static void propagate_environment(char* buf, size_t size) +static void propagate_environment(char* buf) { // Indiscriminately propagate all environment variables. // We could do this more selectively, but we would be likely From e4a8ff6a49cb45d7e59931d0c1e4739b27f09bc1 Mon Sep 17 00:00:00 2001 From: Anna Rift Date: Tue, 10 Dec 2024 14:18:50 -0800 Subject: [PATCH 16/18] Apply reviewer feedback Signed-off-by: Anna Rift --- runtime/include/chpllaunch.h | 4 +- runtime/src/chpl-launcher-common.c | 25 ++++++----- .../slurm-gasnetrun_common.h | 38 +++++++++-------- .../src/launch/slurm-srun/launch-slurm-srun.c | 41 ++++++++++--------- 4 files changed, 59 insertions(+), 49 deletions(-) diff --git a/runtime/include/chpllaunch.h b/runtime/include/chpllaunch.h index 01b04e08926b..d33d68d1f3be 100644 --- a/runtime/include/chpllaunch.h +++ b/runtime/include/chpllaunch.h @@ -45,7 +45,9 @@ typedef struct { int chpl_doDryRun(void); void chpl_append_to_largv(int* largc, const char*** largv, int* largv_len, const char* arg); -char* chpl_append_to_cmd(char* cmdBuf, const char* format, ...); +void chpl_append_to_cmd(char** cmdBufPtr, int* charsWritten, + const char* format, ...) + __attribute__((format(printf, 2, 3))); int chpl_run_utility1K(const char *command, char *const argv[], char *outbuf, int outbuflen); int chpl_run_cmdstr(const char *commandStr, char *outbuf, int outbuflen); diff --git a/runtime/src/chpl-launcher-common.c b/runtime/src/chpl-launcher-common.c index 935d40615787..28d16962dd24 100644 --- a/runtime/src/chpl-launcher-common.c +++ b/runtime/src/chpl-launcher-common.c @@ -104,39 +104,42 @@ void chpl_append_to_largv(int* largc, const char*** largv, int* largv_len, } // Helper for appending arguments to a variable-size command buffer. -// - Requires the buffer pointer is uninitialized on first call. +// - Requires cmdBufPtr points to an uninitialized pointer on first call, and +// charsWritten is 0. // - After exceeding an initial allocated size estimate, each call will allocate // additional memory as needed. -char* chpl_append_to_cmd(char* cmdBuf, const char* format, ...) { +void chpl_append_to_cmd(char** cmdBufPtr, int* charsWritten, + const char* format, ...) { + // Estimate of a buffer size that probably won't require extending, to avoid + // reallocations and copying. static const int initialSize = 2048; - static int charsWritten = 0; va_list argsForLen, argsForPrint; va_start(argsForLen, format); va_copy(argsForPrint, argsForLen); // Allocate buffer to initial size on first call - if (charsWritten == 0) { - assert(cmdBuf == NULL); - cmdBuf = (char*)chpl_mem_allocMany(initialSize, sizeof(char), + if (*cmdBufPtr == NULL) { + assert(*charsWritten == 0); + *cmdBufPtr = (char*)chpl_mem_allocMany(initialSize, sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, 0); } // Determine additional characters to be written const int addedLen = vsnprintf(NULL, 0, format, argsForLen); va_end(argsForLen); - int newLen = charsWritten + addedLen; + int newLen = *charsWritten + addedLen; // Allocate more memory if needed if (newLen >= initialSize) { - cmdBuf = (char*)chpl_mem_realloc(cmdBuf, newLen * sizeof(char), - CHPL_RT_MD_COMMAND_BUFFER, -1, 0); + *cmdBufPtr = (char*)chpl_mem_realloc(*cmdBufPtr, newLen * sizeof(char), + CHPL_RT_MD_COMMAND_BUFFER, -1, 0); } // Write the new characters - vsnprintf(cmdBuf + charsWritten, addedLen + 1, format, argsForPrint); + vsnprintf(*cmdBufPtr + *charsWritten, addedLen + 1, format, argsForPrint); va_end(argsForPrint); - charsWritten = newLen; + *charsWritten = newLen; } // diff --git a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h index 46971d1ef9ef..64b6b84a9b1c 100644 --- a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h +++ b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h @@ -173,7 +173,7 @@ static void genNumLocalesOptions(FILE* slurmFile, sbatchVersion sbatch, } } -static void propagate_environment(char* buf) +static void propagate_environment(char** buf) { // Indiscriminately propagate all environment variables. // We could do this more selectively, but we would be likely @@ -317,36 +317,38 @@ static char* chpl_launch_create_command(int argc, char* argv[], snprintf(baseCommand, baseCommandLen, format, slurmFilename); } else { char* iCom = NULL; + int len = 0; if (!getSlurmDebug()) { - chpl_append_to_cmd(iCom, "--quiet "); + chpl_append_to_cmd(&iCom, &len, "--quiet "); } - chpl_append_to_cmd(iCom, "-J %s ", jobName); - chpl_append_to_cmd(iCom, "-N %d ", numNodes); - chpl_append_to_cmd(iCom, "--ntasks=%d ", numLocales); - if (nodeAccessStr != NULL) chpl_append_to_cmd(iCom, "--%s ", nodeAccessStr); - if (walltime) chpl_append_to_cmd(iCom, "--time=%s ", walltime); - if (nodelist) chpl_append_to_cmd(iCom, "--nodelist=%s ", nodelist); - if (partition) chpl_append_to_cmd(iCom, "--partition=%s ", partition); - if (exclude) chpl_append_to_cmd(iCom, "--exclude=%s ", exclude); - if (gpusPerNode) chpl_append_to_cmd(iCom, "--gpus-per-node=%s ", gpusPerNode); + chpl_append_to_cmd(&iCom, &len, "-J %s ", jobName); + chpl_append_to_cmd(&iCom, &len, "-N %d ", numNodes); + chpl_append_to_cmd(&iCom, &len, "--ntasks=%d ", numLocales); + if (nodeAccessStr != NULL) chpl_append_to_cmd(&iCom, &len, "--%s ", nodeAccessStr); + if (walltime) chpl_append_to_cmd(&iCom, &len, "--time=%s ", walltime); + if (nodelist) chpl_append_to_cmd(&iCom, &len, "--nodelist=%s ", nodelist); + if (partition) chpl_append_to_cmd(&iCom, &len, "--partition=%s ", partition); + if (exclude) chpl_append_to_cmd(&iCom, &len, "--exclude=%s ", exclude); + if (gpusPerNode) chpl_append_to_cmd(&iCom, &len, "--gpus-per-node=%s ", gpusPerNode); if (projectString && strlen(projectString) > 0) - chpl_append_to_cmd(iCom, "--account=%s ", projectString); - if (constraint) chpl_append_to_cmd(iCom, "-C %s", constraint); - chpl_append_to_cmd(iCom, " %s/%s/%s -n %d -N %d -c 0", + chpl_append_to_cmd(&iCom, &len, "--account=%s ", projectString); + if (constraint) chpl_append_to_cmd(&iCom, &len, "-C %s", constraint); + chpl_append_to_cmd(&iCom, &len, " %s/%s/%s -n %d -N %d -c 0", CHPL_THIRD_PARTY, WRAP_TO_STR(LAUNCH_PATH), GASNETRUN_LAUNCHER, numLocales, numNodes); - propagate_environment(iCom); - chpl_append_to_cmd(iCom, " %s %s", chpl_get_real_binary_wrapper(), + propagate_environment(&iCom); + chpl_append_to_cmd(&iCom, &len, " %s %s", chpl_get_real_binary_wrapper(), chpl_get_real_binary_name()); for (i=1; i 1) { - chpl_append_to_cmd(iCom, "--cpu-bind=none "); + chpl_append_to_cmd(&iCom, &len, "--cpu-bind=none "); } // request specified node access if (nodeAccessStr != NULL) - chpl_append_to_cmd(iCom, "--%s ", nodeAccessStr); + chpl_append_to_cmd(&iCom, &len, "--%s ", nodeAccessStr); // request specified amount of memory if (memStr != NULL) - chpl_append_to_cmd(iCom, "--mem=%s ", memStr); + chpl_append_to_cmd(&iCom, &len, "--mem=%s ", memStr); // kill the job if any program instance halts with non-zero exit status - chpl_append_to_cmd(iCom, "--kill-on-bad-exit "); + chpl_append_to_cmd(&iCom, &len, "--kill-on-bad-exit "); // Set the walltime if it was specified if (walltime) { - chpl_append_to_cmd(iCom, "--time=%s ", walltime); + chpl_append_to_cmd(&iCom, &len, "--time=%s ", walltime); } // Set the nodelist if it was specified if (nodelist) { - chpl_append_to_cmd(iCom, "--nodelist=%s ", nodelist); + chpl_append_to_cmd(&iCom, &len, "--nodelist=%s ", nodelist); } // Set the partition if it was specified if (partition) { - chpl_append_to_cmd(iCom, "--partition=%s ", partition); + chpl_append_to_cmd(&iCom, &len, "--partition=%s ", partition); } // Set the exclude list if it was specified if (exclude) { - chpl_append_to_cmd(iCom, "--exclude=%s ", exclude); + chpl_append_to_cmd(&iCom, &len, "--exclude=%s ", exclude); } // Set the gpus per node if it was specified if (gpusPerNode) { - chpl_append_to_cmd(iCom, "--gpus-per-node=%s ", gpusPerNode); + chpl_append_to_cmd(&iCom, &len, "--gpus-per-node=%s ", gpusPerNode); } // set any constraints if (constraint) { - chpl_append_to_cmd(iCom, "--constraint=%s ", constraint); + chpl_append_to_cmd(&iCom, &len, "--constraint=%s ", constraint); } // set the account name if one was provided if (account && strlen(account) > 0) { - chpl_append_to_cmd(iCom, "--account=%s ", account); + chpl_append_to_cmd(&iCom, &len, "--account=%s ", account); } // add the (possibly wrapped) binary name - chpl_append_to_cmd(iCom, "%s %s ", + chpl_append_to_cmd(&iCom, &len, "%s %s ", chpl_get_real_binary_wrapper(), chpl_get_real_binary_name()); // add any arguments passed to the launcher to the binary for (i=1; i Date: Mon, 16 Dec 2024 12:02:46 -0800 Subject: [PATCH 17/18] Fix __attribute__ for new formals Signed-off-by: Anna Rift --- runtime/include/chpllaunch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/include/chpllaunch.h b/runtime/include/chpllaunch.h index d33d68d1f3be..839847b35f4d 100644 --- a/runtime/include/chpllaunch.h +++ b/runtime/include/chpllaunch.h @@ -47,7 +47,7 @@ void chpl_append_to_largv(int* largc, const char*** largv, int* largv_len, const char* arg); void chpl_append_to_cmd(char** cmdBufPtr, int* charsWritten, const char* format, ...) - __attribute__((format(printf, 2, 3))); + __attribute__((format(printf, 3, 4))); int chpl_run_utility1K(const char *command, char *const argv[], char *outbuf, int outbuflen); int chpl_run_cmdstr(const char *commandStr, char *outbuf, int outbuflen); From 2ed21a363df5b9ab87e29fcab7e67d79b74c05f1 Mon Sep 17 00:00:00 2001 From: Anna Rift Date: Tue, 17 Dec 2024 09:12:36 -0800 Subject: [PATCH 18/18] Fix propagate_environment for chpl_append_to_buf changes Signed-off-by: Anna Rift --- .../slurm-gasnetrun_common.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h index 64b6b84a9b1c..f49b66636ec9 100644 --- a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h +++ b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h @@ -173,13 +173,21 @@ static void genNumLocalesOptions(FILE* slurmFile, sbatchVersion sbatch, } } -static void propagate_environment(char** buf) +// Append environment variables using chpl_append_to_cmd. +// charsWritten may be NULL, in which case it is ignored. +static void propagate_environment(char** buf, int* charsWritten) { + int ignoredCharsWritten; + if (!charsWritten) { + charsWritten = &ignoredCharsWritten; + } + // Indiscriminately propagate all environment variables. // We could do this more selectively, but we would be likely // to leave out something important. char *enviro_keys = chpl_get_enviro_keys(','); - if (enviro_keys) chpl_append_to_cmd(buf, " -E '%s'", enviro_keys); + if (enviro_keys) + chpl_append_to_cmd(buf, charsWritten, " -E '%s'", enviro_keys); } static char* chpl_launch_create_command(int argc, char* argv[], @@ -189,7 +197,6 @@ static char* chpl_launch_create_command(int argc, char* argv[], int i; int size; char* baseCommand = NULL; - char* envProp = NULL; char* command; FILE* slurmFile; char* projectString = getenv(launcherAccountEnvvar); @@ -298,8 +305,10 @@ static char* chpl_launch_create_command(int argc, char* argv[], CHPL_THIRD_PARTY, WRAP_TO_STR(LAUNCH_PATH), GASNETRUN_LAUNCHER, numLocales, numLocales); - propagate_environment(envProp); + char* envProp = NULL; + propagate_environment(&envProp, NULL); fprintf(slurmFile, "%s", envProp); + chpl_mem_free(envProp); fprintf(slurmFile, " %s %s", chpl_get_real_binary_wrapper(), chpl_get_real_binary_name()); @@ -337,7 +346,7 @@ static char* chpl_launch_create_command(int argc, char* argv[], chpl_append_to_cmd(&iCom, &len, " %s/%s/%s -n %d -N %d -c 0", CHPL_THIRD_PARTY, WRAP_TO_STR(LAUNCH_PATH), GASNETRUN_LAUNCHER, numLocales, numNodes); - propagate_environment(&iCom); + propagate_environment(&iCom, &len); chpl_append_to_cmd(&iCom, &len, " %s %s", chpl_get_real_binary_wrapper(), chpl_get_real_binary_name()); for (i=1; i