diff options
author | schnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f> | 2005-06-05 10:21:03 +0000 |
---|---|---|
committer | schnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f> | 2005-06-05 10:21:03 +0000 |
commit | c2bbe6b25ba6d4cca2b836ee75a81a00a2bd8852 (patch) | |
tree | 26d909cee6710e853775506f65c94ac46d2f5efe | |
parent | aaa4ad68fa305c5103df0b632edec573cbfe4d4a (diff) |
Make parameters steerable.
Introduce "verbose" parameter.
Announce to the portal by default.
Introduce parameter to announce only every n seconds.
Only announce every minute by default.
When calling system(), make sure that there are no shell meta
characters.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusUtils/Formaline/trunk@37 83718e91-0e4f-0410-abf4-91180603181f
-rw-r--r-- | README | 19 | ||||
-rw-r--r-- | par/announce.par | 1 | ||||
-rw-r--r-- | param.ccl | 36 | ||||
-rw-r--r-- | src/announce.cc | 990 | ||||
-rw-r--r-- | src/portal.cc | 39 |
5 files changed, 600 insertions, 485 deletions
@@ -44,8 +44,23 @@ implement reductions implement missing data types output only if value has changed -rename "file", "storage" do something more unique - update the source tarballs not only when the thorn library changes, but also when a *.ccl or make.* file changes. do not necessarily update them all when the bindings change. + + + +RSS: add RSS feed +see http://blogs.law.harvard.edu/tech/rss for an RSS specification +a simple example is: +<rss version="2.0"> + <channel> + <title>...</title> + <link>...</link> + <description>...</description> + <item> + <title>...</title> + <description>...</description> + </item> + </channel> +</rss> diff --git a/par/announce.par b/par/announce.par index 44fd447..18c9f07 100644 --- a/par/announce.par +++ b/par/announce.par @@ -17,4 +17,3 @@ ActiveThorns = "PUGH" ActiveThorns = "Formaline" Formaline::announce_to_portal = yes -Formaline::store_into_file = yes @@ -3,24 +3,36 @@ -# Parameters for announcing meta information to the portal -# (does not work yet properly) +# Global parameters -BOOLEAN announce_to_portal "Announce meta information to the portal" +BOOLEAN verbose "Produce screen output" STEERABLE=always { } no -STRING portal_hostname "Portal host name" +REAL update_interval "Update interval for the meta information (in seconds)" STEERABLE=always +{ + 0:* :: "" +} 60.0 + + + +# Parameters for announcing meta information to the portal + +BOOLEAN announce_to_portal "Announce meta information to the portal" STEERABLE=always +{ +} yes + +STRING portal_hostname "Portal host name" STEERABLE=always { "" :: "" } "portal.cct.lsu.edu" -INT portal_port "Portal port" +INT portal_port "Portal port" STEERABLE=always { 1:65535 :: "" } 9296 -STRING portal_username "User name on the portal" +STRING portal_username "User name on the portal" STEERABLE=always { "" :: "" } "" @@ -29,11 +41,11 @@ STRING portal_username "User name on the portal" # Parameters for storing meta information in a file -BOOLEAN store_into_file "Store meta information in a file" +BOOLEAN store_into_file "Store meta information in a file" STEERABLE=always { } yes -STRING storage_filename "File name for meta information" +STRING storage_filename "File name for meta information" STEERABLE=always { "" :: "" } "formaline-jar.txt" @@ -42,11 +54,11 @@ STRING storage_filename "File name for meta information" # Parameters for storing the source tree in the executable -BOOLEAN output_source "Output a tarball with the cactus source tree" +BOOLEAN output_source "Output a tarball with the cactus source tree" STEERABLE=recover { } yes -STRING output_source_subdirectory "Subdirectory, relative to IO::out_dir, for the Cactus source tarballs" +STRING output_source_subdirectory "Subdirectory, relative to IO::out_dir, for the Cactus source tarballs" STEERABLE=recover { "" :: "" } "cactus-source" @@ -55,12 +67,12 @@ STRING output_source_subdirectory "Subdirectory, relative to IO::out_dir, for th # Parameters for outputting Cactus variables -STRING out_vars "Cactus variables that should be output" +STRING out_vars "Cactus variables that should be output" STEERABLE=always { "" :: "space separated list of groups or variables" } "" -STRING out_reductions "Reduction operators that should be applied to the output variables" +STRING out_reductions "Reduction operators that should be applied to the output variables" STEERABLE=always { "" :: "space separated list of reduction operators" } "minimum maximum norm1 norm2 norm_inf sum" diff --git a/src/announce.cc b/src/announce.cc index 9f62540..b308865 100644 --- a/src/announce.cc +++ b/src/announce.cc @@ -14,9 +14,6 @@ #include <utility> #include <vector> -#include <sys/types.h> -#include <unistd.h> - #include "cctk.h" #include "cctk_Arguments.h" #include "cctk_Parameters.h" @@ -24,6 +21,24 @@ #include "util_Network.h" #include "util_String.h" +// IRIX wants this before <time.h> +#if HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif + +#if TIME_WITH_SYS_TIME +# include <sys/time.h> +# include <time.h> +#else +# if HAVE_SYS_TIME_H +# include <sys/time.h> +# elif HAVE_TIME_H +# include <time.h> +# endif +#endif + +#include <unistd.h> + #include "http_Content.h" #include "file.hh" @@ -38,13 +53,16 @@ namespace Formaline using namespace std; - + + // Unique build ID extern "C" char const build_id[]; - - - + + // Unique job ID static char * jobid = 0; + // Time of late update + static CCTK_REAL last_update_time = 0; + // Create a unique job id @@ -94,6 +112,21 @@ namespace Formaline + // Get current time + static CCTK_REAL + get_current_time () + { +#ifdef HAVE_TIME_GETTIMEOFDAY + struct timeval tv; + gettimeofday (& tv, 0); + return tv.tv_sec + tv.tv_usec / (CCTK_REAL) 1.0e+6; +#else + return 0; +#endif + } + + + extern "C" void Formaline_AnnounceInitial (CCTK_ARGUMENTS) @@ -103,430 +136,435 @@ namespace Formaline // Only store from the root processor if (CCTK_MyProc (cctkGH) != 0) return; - - + + if (verbose) CCTK_INFO ("Announcing initial meta information"); create_jobid (cctkGH); - - - multistorage stores; - - if (announce_to_portal) + // Announce { - stores.add_storage (new portal (jobid, storage::initial)); - } + + multistorage stores; - if (store_into_file) - { - stores.add_storage (new file (jobid, storage::initial)); - } + if (announce_to_portal) + { + stores.add_storage (new portal (jobid, storage::initial)); + } - if (stores.num_storages() == 0) return; + if (store_into_file) + { + stores.add_storage (new file (jobid, storage::initial)); + } + if (stores.num_storages() == 0) return; - // Information in the Portal/Announce format - { - // Don't know what this is for - stores.store ("jobtype", "default"); - } - { - int type; - void const * const ptr - = CCTK_ParameterGet ("cctk_run_title", "Cactus", & type); - assert (type == PARAMETER_STRING); - char const * const run_title = * static_cast<char const * const *> (ptr); - stores.store ("app_title", run_title); - } - { - char run_date [1000]; - Util_CurrentDate (sizeof run_date, run_date); - char run_time [1000]; - Util_CurrentTime (sizeof run_time, run_time); - ostringstream timebuf; - timebuf << run_date << " " << run_time; - string const timestr = timebuf.str(); - stores.store ("start_time", timestr.c_str()); - } - { - // Don't know what this is for - stores.store ("project_name", ""); - } - { - stores.store ("output_files", out_dir); - } - { - char run_host [1000]; - Util_GetHostName (run_host, sizeof run_host); - stores.store ("host", run_host); - } - { - unsigned long http_port; -#ifdef __HTTP_CONTENT_H__ - if (CCTK_IsThornActive ("HTTPD")) + + // Information in the Portal/Announce format { - // Thorn is compiled in and active, ask it - http_port = HTTP_Port(); + // Don't know what this is for + stores.store ("jobtype", "default"); } - else { - // Thorn is compiled in but not active, ignore it - http_port = 0; + int type; + void const * const ptr + = CCTK_ParameterGet ("cctk_run_title", "Cactus", & type); + assert (type == PARAMETER_STRING); + char const * const run_title = * static_cast<char const * const *> (ptr); + stores.store ("app_title", run_title); + } + { + char run_date [1000]; + Util_CurrentDate (sizeof run_date, run_date); + char run_time [1000]; + Util_CurrentTime (sizeof run_time, run_time); + ostringstream timebuf; + timebuf << run_date << " " << run_time; + string const timestr = timebuf.str(); + stores.store ("start_time", timestr.c_str()); + } + { + // Don't know what this is for + stores.store ("project_name", ""); } -#else { - // Thorn is not compiled in, ignore it - http_port = 0; + stores.store ("output_files", out_dir); } + { + char run_host [1000]; + Util_GetHostName (run_host, sizeof run_host); + stores.store ("host", run_host); + } + { + unsigned long http_port; +#ifdef __HTTP_CONTENT_H__ + if (CCTK_IsThornActive ("HTTPD")) + { + // Thorn is compiled in and active, ask it + http_port = HTTP_Port(); + } + else + { + // Thorn is compiled in but not active, ignore it + http_port = 0; + } +#else + { + // Thorn is not compiled in, ignore it + http_port = 0; + } #endif - stores.store ("port", (int) http_port); - } - { - stores.store ("portal_username", portal_username); - } - { + stores.store ("port", (int) http_port); + } + { + stores.store ("portal_username", portal_username); + } + { #if 0 - char const * const run_user = CCTK_RunUser(); + char const * const run_user = CCTK_RunUser(); #else - char const * const run_user = getenv ("USER"); + char const * const run_user = getenv ("USER"); #endif - stores.store ("local_username", run_user); - } - { - char parameter_filename [10000]; - CCTK_ParameterFilename (sizeof parameter_filename, parameter_filename); - stores.store ("parameter_file", parameter_filename); - } - { - char ** argv; - int argc; - CCTK_CommandLine (& argv); - for (argc = 0; argv [argc]; ++ argc); - stores.store ("executable", argc == 0 ? "" : argv[0]); - } - { - // Don't know what this is for - stores.store ("data_directory", ""); - } - { - // Could also be "private" - stores.store ("app_visibility", "public"); - } - { - // Could apparently be none, register, update, deregister - stores.store ("notification_reports", ""); - } - { - // Could apparently be none, email, im, sms - stores.store ("notification_methods", ""); - } + stores.store ("local_username", run_user); + } + { + char parameter_filename [10000]; + CCTK_ParameterFilename (sizeof parameter_filename, parameter_filename); + stores.store ("parameter_file", parameter_filename); + } + { + char ** argv; + int argc; + CCTK_CommandLine (& argv); + for (argc = 0; argv [argc]; ++ argc); + stores.store ("executable", argc == 0 ? "" : argv[0]); + } + { + // Don't know what this is for + stores.store ("data_directory", ""); + } + { + // Could also be "private" + stores.store ("app_visibility", "public"); + } + { + // Could apparently be none, register, update, deregister + stores.store ("notification_reports", ""); + } + { + // Could apparently be none, email, im, sms + stores.store ("notification_methods", ""); + } - // Cactus + // Cactus - { - char const * const cactus_version = CCTK_FullVersion(); - stores.store ("Cactus version", cactus_version); - } + { + char const * const cactus_version = CCTK_FullVersion(); + stores.store ("Cactus version", cactus_version); + } - // Compiling + // Compiling - { - stores.store ("build id", build_id); - } + { + stores.store ("build id", build_id); + } #if 0 - { - char const * const compile_user = CCTK_CompileUser(); - stores.store ("compile user", compile_user); - } + { + char const * const compile_user = CCTK_CompileUser(); + stores.store ("compile user", compile_user); + } #endif - { - char const * const compile_date = CCTK_CompileDate(); - stores.store ("compile date", compile_date); - } + { + char const * const compile_date = CCTK_CompileDate(); + stores.store ("compile date", compile_date); + } - { - char const * const compile_time = CCTK_CompileTime(); - stores.store ("compile time", compile_time); - } + { + char const * const compile_time = CCTK_CompileTime(); + stores.store ("compile time", compile_time); + } - // Running + // Running #if 0 - { - char const * const run_user = CCTK_RunUser(); - stores.store ("run user", run_user); - } + { + char const * const run_user = CCTK_RunUser(); + stores.store ("run user", run_user); + } #else - { - char const * const run_user = getenv ("USER"); - stores.store ("run user", run_user); - } + { + char const * const run_user = getenv ("USER"); + stores.store ("run user", run_user); + } #endif - { - char run_date [1000]; - Util_CurrentDate (sizeof run_date, run_date); - stores.store ("run date", run_date); - } + { + char run_date [1000]; + Util_CurrentDate (sizeof run_date, run_date); + stores.store ("run date", run_date); + } - { - char run_time [1000]; - Util_CurrentTime (sizeof run_time, run_time); - stores.store ("run time", run_time); - } + { + char run_time [1000]; + Util_CurrentTime (sizeof run_time, run_time); + stores.store ("run time", run_time); + } - { - char run_host [1000]; - Util_GetHostName (run_host, sizeof run_host); - stores.store ("run host", run_host); - } + { + char run_host [1000]; + Util_GetHostName (run_host, sizeof run_host); + stores.store ("run host", run_host); + } - { - int type; - void const * const ptr - = CCTK_ParameterGet ("cctk_run_title", "Cactus", & type); - assert (type == PARAMETER_STRING); - char const * const run_title = * static_cast<char const * const *> (ptr); - stores.store ("run title", run_title); - } + { + int type; + void const * const ptr + = CCTK_ParameterGet ("cctk_run_title", "Cactus", & type); + assert (type == PARAMETER_STRING); + char const * const run_title = * static_cast<char const * const *> (ptr); + stores.store ("run title", run_title); + } - // Command line arguments + // Command line arguments - { - char ** argv; - int argc; - int n; - CCTK_CommandLine (& argv); - for (argc = 0; argv [argc]; ++ argc); - stores.store ("argc", argc); - for (n = 0; n < argc; ++ n) { - char buffer [1000]; - snprintf (buffer, sizeof buffer, "argv[%d]", n); - stores.store (buffer, argv[n]); + char ** argv; + int argc; + int n; + CCTK_CommandLine (& argv); + for (argc = 0; argv [argc]; ++ argc); + stores.store ("argc", argc); + for (n = 0; n < argc; ++ n) + { + char buffer [1000]; + snprintf (buffer, sizeof buffer, "argv[%d]", n); + stores.store (buffer, argv[n]); + } } - } - { - char parameter_filename [10000]; - CCTK_ParameterFilename (sizeof parameter_filename, parameter_filename); - stores.store ("parameter filename", parameter_filename); - } + { + char parameter_filename [10000]; + CCTK_ParameterFilename (sizeof parameter_filename, parameter_filename); + stores.store ("parameter filename", parameter_filename); + } - // This is superfluous, and it does not look nice + // This is superfluous, and it does not look nice #if 0 - { - char parameter_filename [10000]; - char parameter_file [1000000]; - size_t count; - FILE * file; - CCTK_ParameterFilename (sizeof parameter_filename, parameter_filename); - file = fopen (parameter_filename, "r"); - count = fread (parameter_file, 1, sizeof parameter_file - 1, file); - fclose (file); - assert (count < sizeof parameter_file - 1); - parameter_file [count] = '\0'; - stores.store ("parameter file", parameter_file); - } + { + char parameter_filename [10000]; + char parameter_file [1000000]; + size_t count; + FILE * file; + CCTK_ParameterFilename (sizeof parameter_filename, parameter_filename); + file = fopen (parameter_filename, "r"); + count = fread (parameter_file, 1, sizeof parameter_file - 1, file); + fclose (file); + assert (count < sizeof parameter_file - 1); + parameter_file [count] = '\0'; + stores.store ("parameter file", parameter_file); + } #endif - { - stores.store ("out dir", out_dir); - } + { + stores.store ("out dir", out_dir); + } - { - int nprocs; - nprocs = CCTK_nProcs (cctkGH); - stores.store ("nprocs", nprocs); - } + { + int nprocs; + nprocs = CCTK_nProcs (cctkGH); + stores.store ("nprocs", nprocs); + } - // All Cactus thorns + // All Cactus thorns - { - int const numthorns = CCTK_NumCompiledThorns (); - for (int thorn = 0; thorn < numthorns; ++ thorn) { - char const * const thornname = CCTK_CompiledThorn (thorn); + int const numthorns = CCTK_NumCompiledThorns (); + for (int thorn = 0; thorn < numthorns; ++ thorn) + { + char const * const thornname = CCTK_CompiledThorn (thorn); - ostringstream keybuf; - keybuf << "thorns/" << thornname; - string const keystr = keybuf.str(); - char const * const key = keystr.c_str(); + ostringstream keybuf; + keybuf << "thorns/" << thornname; + string const keystr = keybuf.str(); + char const * const key = keystr.c_str(); - if (CCTK_IsThornActive (thornname)) - { - stores.store (key, "active"); - } - else - { - stores.store (key, "inactive"); + if (CCTK_IsThornActive (thornname)) + { + stores.store (key, "active"); + } + else + { + stores.store (key, "inactive"); + } } } - } - // All Cactus parameters + // All Cactus parameters - { - typedef pair<string, cParamData const *> param; - - // Collect all parameters into a list - // (A list allows efficient inserting) - list<param> paramlist; - for (int first = 1; ; first = 0) { - cParamData const * parameter_data; - char * parameter_fullname; + typedef pair<string, cParamData const *> param; + + // Collect all parameters into a list + // (A list allows efficient inserting) + list<param> paramlist; + for (int first = 1; ; first = 0) + { + cParamData const * parameter_data; + char * parameter_fullname; - int const ierr - = CCTK_ParameterWalk (first, 0, - & parameter_fullname, & parameter_data); - if (ierr > 0) break; - assert (ierr >= 0); + int const ierr + = CCTK_ParameterWalk (first, 0, + & parameter_fullname, & parameter_data); + if (ierr > 0) break; + assert (ierr >= 0); - // Skip parameters that belong to inactive thorns - if (CCTK_IsThornActive (parameter_data->thorn)) - { - paramlist.push_back (param (string (parameter_fullname), - parameter_data)); - } + // Skip parameters that belong to inactive thorns + if (CCTK_IsThornActive (parameter_data->thorn)) + { + paramlist.push_back (param (string (parameter_fullname), + parameter_data)); + } - free (parameter_fullname); - } + free (parameter_fullname); + } - // Copy the list into a vector - // (A vector allows efficient sorting) - vector<param> paramvector; - paramvector.insert (paramvector.begin(), - paramlist.begin(), paramlist.end()); + // Copy the list into a vector + // (A vector allows efficient sorting) + vector<param> paramvector; + paramvector.insert (paramvector.begin(), + paramlist.begin(), paramlist.end()); - // Sort the parameters - sort (paramvector.begin(), paramvector.end()); + // Sort the parameters + sort (paramvector.begin(), paramvector.end()); - // Store the parameters - for (vector<param>::const_iterator parameter = paramvector.begin(); - parameter != paramvector.end(); - ++ parameter) - { - char const * const parameter_fullname = parameter->first.c_str(); - cParamData const * const parameter_data = parameter->second; + // Store the parameters + for (vector<param>::const_iterator parameter = paramvector.begin(); + parameter != paramvector.end(); + ++ parameter) + { + char const * const parameter_fullname = parameter->first.c_str(); + cParamData const * const parameter_data = parameter->second; - ostringstream keybuf; - keybuf << "parameters/" << parameter_fullname; - string const keystr = keybuf.str(); - char const * const key = keystr.c_str(); + ostringstream keybuf; + keybuf << "parameters/" << parameter_fullname; + string const keystr = keybuf.str(); + char const * const key = keystr.c_str(); - int type; - void const * const parameter_value - = CCTK_ParameterGet (parameter_data->name, parameter_data->thorn, - & type); - assert (parameter_value != 0); - assert (type == parameter_data->type); + int type; + void const * const parameter_value + = CCTK_ParameterGet (parameter_data->name, parameter_data->thorn, + & type); + assert (parameter_value != 0); + assert (type == parameter_data->type); - int const times_set - = CCTK_ParameterQueryTimesSet (parameter_data->name, - parameter_data->thorn); + int const times_set + = CCTK_ParameterQueryTimesSet (parameter_data->name, + parameter_data->thorn); - switch (type) - { - case PARAMETER_BOOLEAN: + switch (type) { - CCTK_INT default_value; - int const ierr - = CCTK_SetBoolean (& default_value, parameter_data->defval); - assert (! ierr); - CCTK_INT const value - = * static_cast<CCTK_INT const *> (parameter_value); - if (times_set > 0 or value != default_value) + case PARAMETER_BOOLEAN: { - stores.store (key, (bool) value); - } - } - break; - case PARAMETER_INT: - { - CCTK_INT const default_value - = strtol (parameter_data->defval, 0, 0); - CCTK_INT const value - = * static_cast<CCTK_INT const *> (parameter_value); - if (times_set > 0 or value != default_value) - { - stores.store (key, value); + CCTK_INT default_value; + int const ierr + = CCTK_SetBoolean (& default_value, parameter_data->defval); + assert (! ierr); + CCTK_INT const value + = * static_cast<CCTK_INT const *> (parameter_value); + if (times_set > 0 or value != default_value) + { + stores.store (key, (bool) value); + } } - } - break; - case PARAMETER_REAL: - { - char * const default_string = strdup (parameter_data->defval); - assert (default_string); - // Convert "d" and "D" to "e" and "E", because this is what - // strtod expects - for (char * p = default_string; * p; ++ p) + break; + case PARAMETER_INT: { - switch (* p) + CCTK_INT const default_value + = strtol (parameter_data->defval, 0, 0); + CCTK_INT const value + = * static_cast<CCTK_INT const *> (parameter_value); + if (times_set > 0 or value != default_value) { - case 'd': * p = 'e'; break; - case 'D': * p = 'E'; break; + stores.store (key, value); } } - CCTK_REAL const default_value = strtod (default_string, 0); - free (default_string); - CCTK_REAL const value - = * static_cast<CCTK_REAL const *> (parameter_value); - if (times_set > 0 or value != default_value) + break; + case PARAMETER_REAL: { - stores.store (key, value); + char * const default_string = strdup (parameter_data->defval); + assert (default_string); + // Convert "d" and "D" to "e" and "E", because this is what + // strtod expects + for (char * p = default_string; * p; ++ p) + { + switch (* p) + { + case 'd': * p = 'e'; break; + case 'D': * p = 'E'; break; + } + } + CCTK_REAL const default_value = strtod (default_string, 0); + free (default_string); + CCTK_REAL const value + = * static_cast<CCTK_REAL const *> (parameter_value); + if (times_set > 0 or value != default_value) + { + stores.store (key, value); + } } - } - break; - case PARAMETER_KEYWORD: - { - char const * const value - = * static_cast<char const * const *> (parameter_value); - if (times_set > 0 - or Util_StrCmpi (parameter_data->defval, value) != 0) + break; + case PARAMETER_KEYWORD: { - stores.store (key, value); + char const * const value + = * static_cast<char const * const *> (parameter_value); + if (times_set > 0 + or Util_StrCmpi (parameter_data->defval, value) != 0) + { + stores.store (key, value); + } } - } - break; - case PARAMETER_STRING: - { - char const * const value - = * static_cast<char const * const *> (parameter_value); - if (times_set > 0 or strcmp (parameter_data->defval, value) != 0) + break; + case PARAMETER_STRING: { - stores.store (key, value); + char const * const value + = * static_cast<char const * const *> (parameter_value); + if (times_set > 0 or strcmp (parameter_data->defval, value) != 0) + { + stores.store (key, value); + } } + break; + default: + assert (0); } - break; - default: - assert (0); - } - } // for all parameters - } + } // for all parameters + } - // Simulation state + // Simulation state - { - stores.store ("cctk_iteration", cctk_iteration); - } + { + stores.store ("cctk_iteration", cctk_iteration); + } + + } // announce + + last_update_time = get_current_time(); } @@ -541,157 +579,167 @@ namespace Formaline // Only store from the root processor if (CCTK_MyProc (cctkGH) != 0) return; - - - multistorage stores; - - if (announce_to_portal) + if (get_current_time() < last_update_time + update_interval) return; + + if (verbose) CCTK_INFO ("Announcing meta information update"); + + // Announce { - stores.add_storage (new portal (jobid, storage::update)); - } + + multistorage stores; - if (store_into_file) - { - stores.add_storage (new file (jobid, storage::update)); - } + if (announce_to_portal) + { + stores.add_storage (new portal (jobid, storage::update)); + } - if (stores.num_storages() == 0) return; + if (store_into_file) + { + stores.add_storage (new file (jobid, storage::update)); + } + if (stores.num_storages() == 0) return; - // Simulation state - { - stores.store ("cctk_iteration", cctk_iteration); - stores.store ("cctk_time", cctk_time); - } + // Simulation state + + { + stores.store ("cctk_iteration", cctk_iteration); + stores.store ("cctk_time", cctk_time); + } - // Groups and variables + // Groups and variables - { - struct args { - cGH * cctkGH; - multistorage * stores; - char const * reductions; + { + struct args { + cGH * cctkGH; + multistorage * stores; + char const * reductions; - static void - output_variable (int const varindex, - char const * const options, - void * const theargs0) - { - args * const theargs = (args *) theargs0; - cGH * const cctkGH = theargs->cctkGH; - multistorage & stores = * theargs->stores; - char const * const reductions = theargs->reductions; + static void + output_variable (int const varindex, + char const * const options, + void * const theargs0) + { + args * const theargs = (args *) theargs0; + cGH * const cctkGH = theargs->cctkGH; + multistorage & stores = * theargs->stores; + char const * const reductions = theargs->reductions; - int const groupindex = CCTK_GroupIndexFromVarI (varindex); - assert (groupindex >= 0); - cGroup group; - int const ierr = CCTK_GroupData (groupindex, & group); - assert (! ierr); + int const groupindex = CCTK_GroupIndexFromVarI (varindex); + assert (groupindex >= 0); + cGroup group; + int const ierr = CCTK_GroupData (groupindex, & group); + assert (! ierr); - ostringstream keybuf, valbuf; - char * const fullname = CCTK_FullName (varindex); - assert (fullname); - keybuf << "variables/" << fullname; - free (fullname); - string const keystr = keybuf.str(); - char const * const key = keystr.c_str(); + ostringstream keybuf, valbuf; + char * const fullname = CCTK_FullName (varindex); + assert (fullname); + keybuf << "variables/" << fullname; + free (fullname); + string const keystr = keybuf.str(); + char const * const key = keystr.c_str(); - void const * const varptr - = CCTK_VarDataPtrI (cctkGH, 0, varindex); - if (! varptr) { - // No storage -- do nothing - // TODO: output warning - return; - } + void const * const varptr + = CCTK_VarDataPtrI (cctkGH, 0, varindex); + if (! varptr) { + // No storage -- do nothing + // TODO: output warning + return; + } - switch (group.grouptype) - { - case CCTK_SCALAR: - switch (group.vartype) + switch (group.grouptype) { - case CCTK_VARIABLE_INT: + case CCTK_SCALAR: + switch (group.vartype) { - CCTK_INT const val = * (CCTK_INT const *) varptr; - stores.store (key, val); - } - break; - case CCTK_VARIABLE_REAL: - { - CCTK_REAL const val = * (CCTK_REAL const *) varptr; - stores.store (key, val); - } - break; - case CCTK_VARIABLE_COMPLEX: - { - CCTK_COMPLEX const val = * (CCTK_COMPLEX const *) varptr; + case CCTK_VARIABLE_INT: + { + CCTK_INT const val = * (CCTK_INT const *) varptr; + stores.store (key, val); + } + break; + case CCTK_VARIABLE_REAL: { - ostringstream keyrebuf; - keyrebuf << key << ".Re"; - string const keyrestr = keyrebuf.str(); - char const * const keyre = keyrestr.c_str(); - stores.store (keyre, val.Re); + CCTK_REAL const val = * (CCTK_REAL const *) varptr; + stores.store (key, val); } + break; + case CCTK_VARIABLE_COMPLEX: { - ostringstream keyimbuf; - keyimbuf << key << ".Im"; - string const keyimstr = keyimbuf.str(); - char const * const keyim = keyimstr.c_str(); - stores.store (keyim, val.Im); + CCTK_COMPLEX const val = * (CCTK_COMPLEX const *) varptr; + { + ostringstream keyrebuf; + keyrebuf << key << ".Re"; + string const keyrestr = keyrebuf.str(); + char const * const keyre = keyrestr.c_str(); + stores.store (keyre, val.Re); + } + { + ostringstream keyimbuf; + keyimbuf << key << ".Im"; + string const keyimstr = keyimbuf.str(); + char const * const keyim = keyimstr.c_str(); + stores.store (keyim, val.Im); + } } + break; + default: + ; + // not supported yet + // TODO: output warning } break; - default: - ; + case CCTK_ARRAY: + case CCTK_GF: // not supported yet // TODO: output warning + break; + default: + CCTK_WARN (0, "internal error"); } - break; - case CCTK_ARRAY: - case CCTK_GF: - // not supported yet - // TODO: output warning - break; - default: - CCTK_WARN (0, "internal error"); } - } - } theargs; + } theargs; - theargs.cctkGH = cctkGH; - theargs.stores = & stores; - theargs.reductions = out_reductions; + theargs.cctkGH = cctkGH; + theargs.stores = & stores; + theargs.reductions = out_reductions; - int const icnt - = CCTK_TraverseString (out_vars, theargs.output_variable, & theargs, - CCTK_GROUP_OR_VAR); - if (icnt < 0) - { - switch (icnt) + int const icnt + = CCTK_TraverseString (out_vars, theargs.output_variable, & theargs, + CCTK_GROUP_OR_VAR); + if (icnt < 0) { - case -1: - CCTK_WARN (0, "no callback routine was given"); - break; - case -2: - CCTK_WARN (2, "option string is not associated with a group or variable"); - break; - case -3: - CCTK_WARN (2, "unterminated option string"); - break; - case -4: - CCTK_WARN (2, "garbage found at end of option string"); - break; - case -5: - CCTK_WARN (2, "invalid token in traversed string found"); - break; - default: - CCTK_WARN (1, "error while traversing output variables"); + switch (icnt) + { + case -1: + CCTK_WARN (0, "no callback routine was given"); + break; + case -2: + CCTK_WARN (2, "option string is not associated with a group or variable"); + break; + case -3: + CCTK_WARN (2, "unterminated option string"); + break; + case -4: + CCTK_WARN (2, "garbage found at end of option string"); + break; + case -5: + CCTK_WARN (2, "invalid token in traversed string found"); + break; + default: + CCTK_WARN (1, "error while traversing output variables"); + } } } - } + + } // announce + + last_update_time = get_current_time(); + } @@ -705,30 +753,36 @@ namespace Formaline // Only store from the root processor if (CCTK_MyProc (cctkGH) != 0) return; + + if (verbose) CCTK_INFO ("Announcing final meta information"); - - - multistorage stores; - - if (announce_to_portal) + // Announce { - stores.add_storage (new portal (jobid, storage::final)); - } + + multistorage stores; - if (store_into_file) - { - stores.add_storage (new file (jobid, storage::final)); - } + if (announce_to_portal) + { + stores.add_storage (new portal (jobid, storage::final)); + } - if (stores.num_storages() == 0) return; + if (store_into_file) + { + stores.add_storage (new file (jobid, storage::final)); + } + if (stores.num_storages() == 0) return; - // Simulation state - { - stores.store ("cctk_iteration", cctk_iteration); - } + // Simulation state + + { + stores.store ("cctk_iteration", cctk_iteration); + stores.store ("cctk_time", cctk_time); + } + + } // announce } diff --git a/src/portal.cc b/src/portal.cc index 8ade326..0a86256 100644 --- a/src/portal.cc +++ b/src/portal.cc @@ -1,6 +1,7 @@ // $Header$ #include <cassert> +#include <cctype> #include <cerrno> #include <cstdio> #include <cstdlib> @@ -133,9 +134,43 @@ namespace Formaline + // Check that the file name is sane + for (char const * p = scriptfilename; * p; ++ p) + { + if (! isalnum (* p)) + { + // Allow only certain characters + switch (* p) + { + case '+': + case ',': + case '-': + case '.': + case '/': + case ':': + case '_': + case '~': + break; + default: + // We don't like this character + { + static bool did_complain = false; + if (! did_complain) + { + did_complain = true; + CCTK_WARN (1, "Strange character in file name -- not calling system()"); + return; + } + } + } + } + } + + + // Make the script executable ostringstream chmodbuf; - chmodbuf << "chmod a+x '" << scriptfilenamestr << "'" + chmodbuf << "chmod a+x " << scriptfilenamestr << " < /dev/null > /dev/null 2> /dev/null"; string const chmodstr = chmodbuf.str(); char const * const chmod = chmodstr.c_str(); @@ -155,8 +190,8 @@ namespace Formaline static bool did_complain = false; if (! did_complain) { - CCTK_WARN (1, "Failed to send data to the portal"); did_complain = true; + CCTK_WARN (1, "Failed to send data to the portal"); } } |