summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>2006-06-29 16:25:58 +0000
committertradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>2006-06-29 16:25:58 +0000
commited3b129327948cb4f7305dfcd31e343e9b90b877 (patch)
treea5511416ac331f3772f75fbd08457519934ae70c
parentea32143ca6b9f1feb42a62275d2f2fcaffc69754 (diff)
Added new command line option '--logdir <dir>' which sets the output directory
for logfiles created by the \texttt{-r} option. If the directory doesn't exist yet, it will be created by Cactus. This applies patch http://www.cactuscode.org/old/pipermail/developers/2006-June/004901.html. git-svn-id: http://svn.cactuscode.org/flesh/trunk@4337 17b73243-c579-4c4c-a9d2-2d5706c11dac
-rw-r--r--doc/UsersGuide/RunningCactus.tex38
-rw-r--r--src/include/CommandLine.h1
-rw-r--r--src/main/CommandLine.c134
-rw-r--r--src/main/ProcessCommandLine.c112
4 files changed, 208 insertions, 77 deletions
diff --git a/doc/UsersGuide/RunningCactus.tex b/doc/UsersGuide/RunningCactus.tex
index 79121747..3403c5d0 100644
--- a/doc/UsersGuide/RunningCactus.tex
+++ b/doc/UsersGuide/RunningCactus.tex
@@ -178,7 +178,7 @@ The same script can be used to checkout additional thorns.
Another script, \texttt{MakeThornList}, can be used to produce a minimal
ThornList from a given Cactus par file. It needs a \emph{master} ThornList
-to be copied into your \texttt{~\.cactus} directory.
+to be copied into your \texttt{~\.cactus} directory.
See \url{http://www.cactuscode.org/toolkit/makeThornList/}.
@@ -330,7 +330,7 @@ There are three ways to pass options to the configuration process.
Or: list your Cactus configuration files in an environment variable
\texttt{CACTUS\_CONFIG\_FILES}:
- \texttt{gmake <\var{config name}>-config
+ \texttt{gmake <\var{config name}>-config
CACTUS\_CONFIG\_FILES=$<$\var{list of config files}$>$}
Multiple configuration files, with their file names separated by a
@@ -344,13 +344,13 @@ There are three ways to pass options to the configuration process.
\texttt{gmake <\var{config name}>-config options=<\var{filename}>}
The options file has the same format as \texttt{\$\{HOME\}/.cactus/config}.
- (Note these options are \emph{added} to those from the
+ (Note these options are \emph{added} to those from the
\texttt{\$\{HOME\}/.cactus/config} file.)
\item[4]{}
Pass the options individually on the command line,
- \texttt{gmake <\var{config name}>-config
+ \texttt{gmake <\var{config name}>-config
<\var{option name}>=<\var{chosen value}>, ...}
Not all configuration options can be set on the command line.
@@ -391,7 +391,7 @@ you are compiling for, such as \texttt{sx6-nec-superux}; the format is
\item {Compiled Thorns}
These specify the chosen set of thorns for compilation. If the thorn choice is not provided
-during configuration, a list containing all thorns in the
+during configuration, a list containing all thorns in the
\texttt{arrangements} directory
is automatically created, and the users prompted for any changes.
@@ -992,7 +992,7 @@ reconfigures an existing one overwriting any previous configuration options.\\
The configuration options are stored in a file
\texttt{configs/<\var{config}>/config-info}.
-\item [\texttt{gmake <\var{config}>-configinfo}] displays the options
+\item [\texttt{gmake <\var{config}>-configinfo}] displays the options
of the configuration (\texttt{cat configs/<\var{config}>/config-info}).
\item[\texttt{gmake <\var{config}>-cvsupdate}] updates the Flesh and this
@@ -1288,8 +1288,12 @@ Short Version & Long Version \\
\hline
-r[o|e|oe|eo] & --redirect=[o|e|oe|eo]\\
\hline
+ & --logdir=<\var{directory}> \\
+\hline
-b[no|line|full] & --buffering=[no|line|full]\\
\hline
+ -b <\var{mode}> & --buffering=<\var{mode}>\\
+\hline
-i & --ignore-next \\
\hline
& --parameter-level=<\var{level}> \\
@@ -1304,28 +1308,37 @@ Short Version & Long Version \\
\begin{Lentry}
+
\item [\texttt{-O} or \texttt{--describe-all-parameters}]
Prints a full list of all parameters from all thorns which were compiled,
along with descriptions and allowed values. This can take an optional extra
parameter \texttt{v} (i.e. \texttt{-Ov} to give verbose information about
all parameters).
+
\item [\texttt{-o<\var{param}>} or \texttt{--describe-parameter=<\var{param}>}]
Prints the description and allowed values for a given parameter --- takes one
argument.
+
\item [\texttt{-S} or \texttt{--print-schedule}]
Print only the schedule tree.
+
\item [\texttt{-T} or \texttt{--list-thorns}]
Prints a list of all the thorns which were compiled in.
+
\item [\texttt{-t<\var{arrangement or thorn}>} or \texttt{--test-thorn-compiled=<\var{arrangement or thorn>}} ]
Checks if a given thorn was compiled in --- takes one argument.
+
\item [\texttt{-h}, \texttt{-?} or \texttt{--help}]
Prints a help message.
+
\item [\texttt{-v} or \texttt{--version}]
Prints version information of the code.
+
%\item [\texttt{-x <nprocs>} or \texttt{--test-parameters <nprocs>}]
%Runs the code far enough to check the consistency of the parameters. If
%given a numeric argument it will attempt to simulate being on that number
%of processors. [To be implemented.]
+
\item [\texttt{-L<\var{level}>} or \texttt{--logging-level=<\var{level}>}]
Sets the logging level of the code. All warning messages are given a
level --- the lower the level the greater the severity. This
@@ -1333,12 +1346,14 @@ parameter \texttt{-L} controls the level of messages to be seen, with all
warnings of level $\le$ \texttt{<\var{level}>} printed to standard output. The
default is a logging level of~0, meaning that only level~0 messages
should be printed to standard output.
+
\item [\texttt{-W<\var{level}>} or \texttt{--warning-level=<\var{level}>}]
Similar to \texttt{-W}, but for standard error instead of
standard output. All warnings of level $\le$ \texttt{<\var{level}>} are
printed to standard error. The default is a warning level of~1,
meaning that level~0 and level~1 messages should be printed to
standard error.
+
\item [\texttt{-E<\var{level}>} or \texttt{--error-level=<\var{level}>}]
Similar to \texttt{-W}, but for fatal errors: Cactus treats all
warnings with level $\le$ \texttt{<\var{level}>} as fatal errors, and aborts
@@ -1350,11 +1365,16 @@ the Cactus run immediately (after printing the warning message%%%
}%%%
). The default value is zero, \ie{} only level~0 warnings
will abort the Cactus run.
+
\item [\texttt{-r[o|e|oe|eo]} or \texttt{--redirect=[o|e|oe|eo]}]
Redirects the standard output (`\texttt{o}') and/or standard error
(`\texttt{e}') of each processor to a file. By default
the standard outputs from processors other than processor 0 are discarded.
+\item [\texttt{--logdir=<\var{directory}>}]
+Sets the output directory for logfiles created by the \texttt{-r} option.
+If the directory doesn't exist yet, it will be created by Cactus.
+
\item [\texttt{-b[no|line|full]} or \texttt{--buffering=[no|line|full]}]
Set the \texttt{stdout} buffering mode. Buffered I/O is a
standard feature of C programmes. This delays writing the actual
@@ -1369,12 +1389,14 @@ the standard outputs from processors other than processor 0 are discarded.
messages, i.e.\ the \texttt{stderr} stream, is always unbuffered
(and hence usually slower than \texttt{stdout}).
-\item [\texttt{-i} or \texttt{--ignore-next}]
-Causes the next argument on the command line to be ignored.
\item [\texttt{--parameter-level=<\var{level}>}]
Sets the level of parameter checking to be used, one of \texttt{strict},
\texttt{normal} (the default), or \texttt{relaxed}.
See Section~\ref{sec:Parameter_File}.
+
+\item [\texttt{-i} or \texttt{--ignore-next}]
+Causes the next argument on the command line to be ignored.
+
\end{Lentry}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/src/include/CommandLine.h b/src/include/CommandLine.h
index 0eb4fa8c..89e89070 100644
--- a/src/include/CommandLine.h
+++ b/src/include/CommandLine.h
@@ -23,6 +23,7 @@ void CCTKi_CommandLineWarningLevel(const char *argument);
void CCTKi_CommandLineErrorLevel(const char *argument);
void CCTKi_CommandLineParameterLevel(const char *argument);
void CCTKi_CommandLineRedirect(const char *argument);
+void CCTKi_CommandLineLogDir(const char *argument);
void CCTKi_CommandLineSetBuffering(const char *argument);
void CCTKi_CommandLinePrintSchedule(void);
void CCTKi_CommandLineListThorns(void);
diff --git a/src/main/CommandLine.c b/src/main/CommandLine.c
index 84e94801..fac58368 100644
--- a/src/main/CommandLine.c
+++ b/src/main/CommandLine.c
@@ -16,10 +16,12 @@
#include "cctk_Flesh.h"
#include "cGH.h"
+#include "util_String.h"
#include "cctk_Version.h"
#include "cctk_ActiveThorns.h"
#include "cctk_CommandLine.h"
#include "cctk_Comm.h"
+#include "cctk_File.h"
#include "cctk_Misc.h"
#include "cctk_ParamCheck.h"
#include "cctk_WarnLevel.h"
@@ -46,7 +48,9 @@ static void CommandLinePrintParameter (const cParamData *properties);
/********************************************************************
********************* Local Data *****************************
********************************************************************/
-static int already_redirected_stdout = 0;
+static char* logdir = NULL;
+static int requested_stdout_redirection = 0;
+static int requested_stderr_redirection = 0;
static int paramchecking = 0;
@@ -67,9 +71,10 @@ int cctki_onlyprintschedule = 0;
* places you have to update if you add a new command-line option.
*/
#define CACTUS_COMMANDLINE_OPTIONS \
- "[-h] [-O] [-o paramname] [-L n] [-W n] [-E n] [-r[o|e|oe|eo]] " \
- "[-b [no|line|full]] " \
- "[-S] [-T] [-t name] [--parameter-level <level>] [-v] " \
+ "[-h] [-O] [-o paramname] [-L n] [-W n] [-E n] " \
+ "[-r[o|e|oe|eo]] [--logdir <dir>] " \
+ "[-b <no|line|full>] " \
+ "[-S] [-T] [-t name] [--parameter-level <level>] [-v] " \
"<parameter_file_name>"
@@ -213,13 +218,13 @@ void CCTKi_CommandLineDescribeParameter (const char *argument)
cthorn = CCTK_ImplementationThorn (thorn);
properties = CCTK_ParameterData (param, cthorn);
}
-
+
free (thorn);
free (param);
}
-
+
if(properties)
- {
+ {
if (CCTK_MyProc (NULL) == 0)
{
CommandLinePrintParameter (properties);
@@ -234,7 +239,7 @@ void CCTKi_CommandLineDescribeParameter (const char *argument)
}
retcode = 1;
}
-
+
CCTK_Exit (NULL, retcode);
}
@@ -430,7 +435,10 @@ void CCTKi_CommandLineParameterLevel (const char *argument)
@date Fri Jul 23 11:32:46 1999
@author Tom Goodale
@desc
- Redirect standard output on non-root processors into a file
+ Redirect stdout/stderr on non-root processors into a file
+
+ Redirection is defered until all command line options
+ (including a possible '-logdir <dir>') have been processed.
@enddesc
@var argument
@@ -441,26 +449,35 @@ void CCTKi_CommandLineParameterLevel (const char *argument)
@@*/
void CCTKi_CommandLineRedirect (const char *argument)
{
- int myproc;
- char fname[24];
-
-
- myproc = CCTK_MyProc (NULL);
- if (myproc)
+ if (!argument || strchr(argument,'o')) /* redirect stdout */
{
- if (!argument || strchr(argument,'o')) /* redirect stdout */
- {
- sprintf (fname, "CCTK_Proc%u.out", myproc);
- freopen (fname, "w", stdout);
- already_redirected_stdout = 1;
- }
- if (argument && strchr(argument,'e')) /* redirect stderr */
- {
- sprintf (fname, "CCTK_Proc%u.err", myproc);
- freopen (fname, "w", stderr);
- }
+ requested_stdout_redirection = 1;
+ }
+ if (argument && strchr(argument,'e')) /* redirect stderr */
+ {
+ requested_stderr_redirection = 1;
}
}
+
+
+ /*@@
+ @routine CCTKi_CommandLineLogDir
+ @date Thu 22 July 2006
+ @author Thomas Radke
+ @desc
+ Set the output directory for redirected stdout/stderr logfiles.
+ @enddesc
+
+ @var argument
+ @vdesc option argument
+ @vtype const char *
+ @vio in
+ @endvar
+@@*/
+void CCTKi_CommandLineLogDir (const char *argument)
+{
+ logdir = Util_Strdup (argument);
+}
/*@@
@routine CCTKi_CommandLineSetBuffering
@date 2006-05-27
@@ -596,8 +613,10 @@ void CCTKi_CommandLineHelp (void)
"-L, --logging-level <n> : Sets the logging level to n.\n"
"-W, --warning-level <n> : Sets the warning level to n.\n"
"-E, --error-level <n> : Sets the error level to n.\n"
- "-r, --redirect [o|e|oe|eo] : Redirects standard output and/or\n"
+ "-r, --redirect[o|e|oe|eo] : Redirects standard output and/or\n"
" standard error to files.\n"
+ " --logdir <dir> : Sets the output directory for logfiles\n"
+ " created by the '-r' option\n"
"-b, --buffering <no|line|full> : Set stdout buffering mode.\n"
"-S, --print-schedule : Print the schedule tree, then exit.\n"
"-T, --list-thorns : Lists the compiled-in thorns.\n"
@@ -663,18 +682,71 @@ void CCTKi_CommandLineUsage (void)
@@*/
void CCTKi_CommandLineFinished (void)
{
+ int myproc;
+ char *logfilename;
+
+
/* Are we in a paramcheck run ? */
if (! paramchecking)
{
cctki_paramchecking = 0;
}
- /* if no redirect was requested on the command line
- send stdout messages on non-root processors to /dev/null */
- if (! already_redirected_stdout && CCTK_MyProc (NULL) != 0)
+ /* redirect stdout/stderr on non-root processors */
+ if (logdir && !(requested_stdout_redirection || requested_stderr_redirection))
{
- freopen (NULL_DEVICE, "w", stdout);
+ CCTK_VWarn (CCTK_WARN_PICKY, __LINE__, __FILE__, "Cactus",
+ "Specifying the '-logdir' option without the '-r' option "
+ "is a no-op and will be ignored.");
+ }
+ myproc = CCTK_MyProc (NULL);
+ if (myproc)
+ {
+ /* if specified on the command line, create the output directory
+ for redirected stdout/stderr logfiles */
+ if (logdir)
+ {
+ if (requested_stdout_redirection || requested_stderr_redirection)
+ {
+ if (CCTK_CreateDirectory (0755, logdir) < 0)
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, "Cactus",
+ "Could not create output directory '%s' for "
+ "stdout/stderr logfiles ! Falling back to using the "
+ "current working directory...", logdir);
+ free (logdir);
+ logdir = Util_Strdup (".");
+ }
+ }
+ }
+ else
+ {
+ /* make cwd the default logdir */
+ logdir = Util_Strdup (".");
+ }
+
+ /* if redirection was requested on the command line
+ send stdout/stderr messages to <logdir>/CCTK_Proc<id>.{out,err}
+ otherwise redirect stdout to the NULL device */
+ logfilename = malloc (strlen (logdir) + 32);
+ if (requested_stdout_redirection)
+ {
+ sprintf (logfilename, "%s/CCTK_Proc%u.out", logdir, myproc);
+ freopen (logfilename, "w", stdout);
+ }
+ else
+ {
+ freopen (NULL_DEVICE, "w", stdout);
+ }
+
+ if (requested_stderr_redirection)
+ {
+ sprintf (logfilename, "%s/CCTK_Proc%u.err", logdir, myproc);
+ freopen (logfilename, "w", stderr);
+ }
+ free (logfilename);
}
+ free (logdir);
}
diff --git a/src/main/ProcessCommandLine.c b/src/main/ProcessCommandLine.c
index 57543700..d47ad721 100644
--- a/src/main/ProcessCommandLine.c
+++ b/src/main/ProcessCommandLine.c
@@ -110,40 +110,60 @@ int CCTKi_ProcessCommandLine(int *inargc, char ***inargv, tFleshConfig *ConfigDa
int option_index = 0;
int c;
int ignore;
+ /* constants for identifying each options by the return value
+ from getopt_long_only() */
+ enum
+ {
+ help_option = 'h',
+ describe_all_paramters_option = 'O',
+ describe_parameter_option = 'o',
+ test_parameters_option = 'x',
+ logging_level_option = 'L',
+ warning_level_option = 'W',
+ error_level_option = 'E',
+ parameter_level_option = 256, /* no short option */
+ redirect_option = 'r',
+ logdir_option = 257, /* no short option */
+ buffering_option = 'b',
+ print_schedule_option = 'S',
+ list_thorns_option = 'T',
+ test_thorns_compiled_option = 't',
+ version_option = 'v',
+ ignore_next_option = 'i'
+ };
+ /* the longopts argument passed into getopt_long_only() */
+ const struct option long_options[] =
+ {
+ {"help", no_argument, NULL, help_option},
+ {"describe-all-parameters", optional_argument, NULL, describe_all_paramters_option},
+ {"describe-parameter", required_argument, NULL, describe_parameter_option},
+ /*{"test-parameters", optional_argument, NULL, test_parameters_option},*/
+ {"logging-level", required_argument, NULL, logging_level_option},
+ {"warning-level", required_argument, NULL, warning_level_option},
+ {"error-level", required_argument, NULL, error_level_option},
+ {"parameter-level", required_argument, NULL, parameter_level_option},
+ {"redirect", optional_argument, NULL, redirect_option},
+ {"logdir", required_argument, NULL, logdir_option},
+ {"buffering", required_argument, NULL, buffering_option},
+ {"print-schedule", no_argument, NULL, print_schedule_option},
+ {"list-thorns", no_argument, NULL, list_thorns_option},
+ {"test-thorn-compiled", required_argument, NULL, test_thorns_compiled_option},
+ {"version", no_argument, NULL, version_option},
+ {"ignore-next", no_argument, NULL, ignore_next_option},
+ {0, 0, 0, 0}
+ };
+
/* Store the command line */
argc = *inargc;
-
argv = *inargv;
ignore = 0;
- /* Process the command line - needs some work !*/
-
if(argc>1)
{
while (1)
{
- struct option long_options[] =
- {
- {"help", no_argument, NULL, 'h'},
- {"describe-all-parameters", optional_argument, NULL, 'O'},
- {"describe-parameter", required_argument, NULL, 'o'},
- /*{"test-parameters", optional_argument, NULL, 'x'},*/
- {"logging-level", required_argument, NULL, 'L'},
- {"warning-level", required_argument, NULL, 'W'},
- {"error-level", required_argument, NULL, 'E'},
- {"parameter-level", required_argument, NULL, 256},
- {"redirect", optional_argument, NULL, 'r'},
- {"buffering", required_argument, NULL, 'b'},
- {"print-schedule", no_argument, NULL, 'S'},
- {"list-thorns", no_argument, NULL, 'T'},
- {"test-thorn-compiled", required_argument, NULL, 't'},
- {"version", no_argument, NULL, 'v'},
- {"ignore-next", no_argument, NULL, 'i'},
- {0, 0, 0, 0}
- };
-
c = getopt_long_only (argc, argv, "hO::o:x::L:W:E:r::b:STt:vi",
long_options, &option_index);
if (c == -1)
@@ -153,21 +173,37 @@ int CCTKi_ProcessCommandLine(int *inargc, char ***inargv, tFleshConfig *ConfigDa
{
switch (c)
{
- case 't': CCTKi_CommandLineTestThornCompiled(optarg); break;
- case 'O': CCTKi_CommandLineDescribeAllParameters(optarg); break;
- case 'o': CCTKi_CommandLineDescribeParameter(optarg); break;
- case 'x': CCTKi_CommandLineTestParameters(optarg); break;
- case 'L': CCTKi_CommandLineLoggingLevel(optarg); break;
- case 'W': CCTKi_CommandLineWarningLevel(optarg); break;
- case 'E': CCTKi_CommandLineErrorLevel(optarg); break;
- case 256: CCTKi_CommandLineParameterLevel(optarg); break;
- case 'r': CCTKi_CommandLineRedirect(optarg); break;
- case 'b': CCTKi_CommandLineSetBuffering(optarg); break;
- case 'S': CCTKi_CommandLinePrintSchedule(); break;
- case 'T': CCTKi_CommandLineListThorns(); break;
- case 'v': CCTKi_CommandLineVersion(); break;
- case 'i': ignore = 1; break;
- case 'h':
+ case describe_all_paramters_option:
+ CCTKi_CommandLineDescribeAllParameters(optarg); break;
+ case describe_parameter_option:
+ CCTKi_CommandLineDescribeParameter(optarg); break;
+ case test_parameters_option:
+ CCTKi_CommandLineTestParameters(optarg); break;
+ case logging_level_option:
+ CCTKi_CommandLineLoggingLevel(optarg); break;
+ case warning_level_option:
+ CCTKi_CommandLineWarningLevel(optarg); break;
+ case error_level_option:
+ CCTKi_CommandLineErrorLevel(optarg); break;
+ case parameter_level_option:
+ CCTKi_CommandLineParameterLevel(optarg); break;
+ case redirect_option:
+ CCTKi_CommandLineRedirect(optarg); break;
+ case logdir_option:
+ CCTKi_CommandLineLogDir(optarg); break;
+ case buffering_option:
+ CCTKi_CommandLineSetBuffering(optarg); break;
+ case print_schedule_option:
+ CCTKi_CommandLinePrintSchedule(); break;
+ case list_thorns_option:
+ CCTKi_CommandLineListThorns(); break;
+ case test_thorns_compiled_option:
+ CCTKi_CommandLineTestThornCompiled(optarg); break;
+ case version_option:
+ CCTKi_CommandLineVersion(); break;
+ case ignore_next_option:
+ ignore = 1; break;
+ case help_option:
case '?':
CCTKi_CommandLineHelp(); break;
default: