aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f>2007-08-21 18:01:12 +0000
committerschnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f>2007-08-21 18:01:12 +0000
commit99ddac2d94b2e6dcba4fb6b53b197e9cd531126e (patch)
tree1dc4e1ce639e1d982ac3f034d125c31fe325b166
parentd69f79bf4ab1ef19da7a5351cfcd41bfffa28fd3 (diff)
Provide aliased functions which can be used to announce certain events
(key/value pairs) to Formaline. Provide a simulation ID as well as the existing build ID and run ID. A simulation ID should remain constant over restarts with the same parameter file, the run ID should change. A simulation ID thus describes a particular physics setup. git-svn-id: http://svn.cactuscode.org/arrangements/CactusUtils/Formaline/trunk@126 83718e91-0e4f-0410-abf4-91180603181f
-rw-r--r--interface.ccl39
-rw-r--r--par/announce.par2
-rw-r--r--src/announce.cc425
-rw-r--r--src/id.cc92
-rw-r--r--src/id.hh8
5 files changed, 423 insertions, 143 deletions
diff --git a/interface.ccl b/interface.ccl
index 9a447c8..fa8779b 100644
--- a/interface.ccl
+++ b/interface.ccl
@@ -29,3 +29,42 @@ FUNCTION UniqueSimulationID (CCTK_POINTER_TO_CONST IN cctkGH)
PROVIDES FUNCTION UniqueSimulationID \
WITH Formaline_UniqueSimulationID \
LANGUAGE C
+
+
+
+# Return a pointer to an unmodifiable C string
+# which contains a unique ID for this run
+CCTK_POINTER_TO_CONST \
+FUNCTION UniqueRunID (CCTK_POINTER_TO_CONST IN cctkGH)
+
+PROVIDES FUNCTION UniqueRunID \
+ WITH Formaline_UniqueRunID \
+ LANGUAGE C
+
+
+
+# Announce some information
+# Note the order (value, key);
+# this is necessary because string arguments have to be at the end
+# of the argument list.
+void \
+FUNCTION AnnounceBoolean (CCTK_POINTER_TO_CONST IN cctkGH, \
+ CCTK_INT IN value, \
+ CCTK_STRING IN key)
+void \
+FUNCTION AnnounceInt (CCTK_POINTER_TO_CONST IN cctkGH, \
+ CCTK_INT IN value, \
+ CCTK_STRING IN key)
+void \
+FUNCTION AnnounceReal (CCTK_POINTER_TO_CONST IN cctkGH, \
+ CCTK_REAL IN value, \
+ CCTK_STRING IN key)
+void \
+FUNCTION AnnounceString (CCTK_POINTER_TO_CONST IN cctkGH, \
+ CCTK_STRING IN value, \
+ CCTK_STRING IN key)
+
+PROVIDES FUNCTION AnnounceBoolean WITH Formaline_AnnounceBoolean LANGUAGE C
+PROVIDES FUNCTION AnnounceInt WITH Formaline_AnnounceInt LANGUAGE C
+PROVIDES FUNCTION AnnounceReal WITH Formaline_AnnounceReal LANGUAGE C
+PROVIDES FUNCTION AnnounceString WITH Formaline_AnnounceString LANGUAGE C
diff --git a/par/announce.par b/par/announce.par
index 3e33dc8..65a0d34 100644
--- a/par/announce.par
+++ b/par/announce.par
@@ -7,7 +7,7 @@ Cactus::cctk_show_schedule = no
Cactus::cctk_itlast = 0
-ActiveThorns = "CoordBase"
+ActiveThorns = "CoordBase InitBase"
ActiveThorns = "IOUtil"
IO::out_dir = $parfile
diff --git a/src/announce.cc b/src/announce.cc
index 472fcec..9935201 100644
--- a/src/announce.cc
+++ b/src/announce.cc
@@ -101,7 +101,7 @@ namespace Formaline
if (verbose) CCTK_INFO ("Announcing initial meta information");
if (create_id_files) {
- // Create files from the build id and job id
+ // Create files from the build, run, and simulation ids
// (This shows what jobs were run in the output directory)
{
ostringstream filenamebuf;
@@ -114,11 +114,20 @@ namespace Formaline
}
{
ostringstream filenamebuf;
- filenamebuf << out_dir << "/formaline-" << get_job_id (cctkGH);
+ filenamebuf << out_dir << "/formaline-" << get_simulation_id (cctkGH);
string const filenamestring = filenamebuf.str();
ofstream fil;
fil.open (filenamestring.c_str(), ios::trunc);
- fil << get_job_id (cctkGH) << endl;
+ fil << get_simulation_id (cctkGH) << endl;
+ fil.close ();
+ }
+ {
+ ostringstream filenamebuf;
+ filenamebuf << out_dir << "/formaline-" << get_run_id (cctkGH);
+ string const filenamestring = filenamebuf.str();
+ ofstream fil;
+ fil.open (filenamestring.c_str(), ios::trunc);
+ fil << get_run_id (cctkGH) << endl;
fil.close ();
}
}
@@ -130,18 +139,18 @@ namespace Formaline
if (announce_to_portal)
{
- stores.add_storage (new portal (get_job_id (cctkGH), storage::initial));
+ stores.add_storage (new portal (get_run_id (cctkGH), storage::initial));
}
if (send_as_rdf)
{
stores.add_storage
- (new rdf (get_job_id (cctkGH), storage::initial, cctkGH));
+ (new rdf (get_run_id (cctkGH), storage::initial, cctkGH));
}
if (store_into_file)
{
- stores.add_storage (new file (get_job_id (cctkGH), storage::initial));
+ stores.add_storage (new file (get_run_id (cctkGH), storage::initial));
}
if (stores.num_storages() == 0) return;
@@ -637,18 +646,142 @@ namespace Formaline
}
} // for all parameters
}
-
-
-
+
+
+
+#if 0
// Simulation state
-
+
{
+ // This information is wrong when recovering
stores.store ("cctk_iteration", cctk_iteration);
+ stores.store ("cctk_time", cctk_time);
}
-
+#endif
+
} // announce
-
+
+#if 0
last_update_time = get_current_time();
+#endif
+ }
+
+
+
+ class args {
+ cGH const * cctkGH;
+ multistorage & stores;
+ char const * reductions;
+
+ public:
+ args (cGH const * cctkGH_,
+ multistorage & stores_,
+ char const * reductions_);
+
+ void
+ output_variable (int varindex,
+ char const * options)
+ const;
+ };
+
+ args::args (cGH const * const cctkGH_,
+ multistorage & stores_,
+ char const * const reductions_)
+ : cctkGH (cctkGH_),
+ stores (stores_),
+ reductions (reductions_)
+ {
+ }
+
+ void
+ args::output_variable (int const varindex,
+ char const * const options)
+ const
+ {
+ 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();
+
+ 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)
+ {
+ case CCTK_VARIABLE_INT:
+ {
+ 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;
+ {
+ 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;
+ case CCTK_ARRAY:
+ case CCTK_GF:
+ // not supported yet
+ // TODO: output warning
+ break;
+ default:
+ CCTK_WARN (0, "internal error");
+ }
+ }
+
+ // C-style wrapper
+ extern "C" {
+ static
+ void
+ args_output_variable (int const varindex,
+ char const * const options,
+ void * const theargs0)
+ {
+ args * const theargs = static_cast <args *> (theargs0);
+ theargs->output_variable (varindex, options);
+ }
}
@@ -674,18 +807,18 @@ namespace Formaline
if (announce_to_portal)
{
- stores.add_storage (new portal (get_job_id (cctkGH), storage::update));
+ stores.add_storage (new portal (get_run_id (cctkGH), storage::update));
}
if (send_as_rdf)
{
stores.add_storage
- (new rdf (get_job_id (cctkGH), storage::update, cctkGH));
+ (new rdf (get_run_id (cctkGH), storage::update, cctkGH));
}
if (store_into_file)
{
- stores.add_storage (new file (get_job_id (cctkGH), storage::update));
+ stores.add_storage (new file (get_run_id (cctkGH), storage::update));
}
if (stores.num_storages() == 0) return;
@@ -718,104 +851,12 @@ namespace Formaline
// Groups and variables
-
- {
- struct args {
- cGH const * 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 * 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);
-
- 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;
- }
+ {
+ args theargs (cctkGH, stores, out_reductions);
- switch (group.grouptype)
- {
- case CCTK_SCALAR:
- switch (group.vartype)
- {
- case CCTK_VARIABLE_INT:
- {
- 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;
- {
- 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;
- case CCTK_ARRAY:
- case CCTK_GF:
- // not supported yet
- // TODO: output warning
- break;
- default:
- CCTK_WARN (0, "internal error");
- }
- }
- } theargs;
-
- theargs.cctkGH = cctkGH;
- theargs.stores = & stores;
- theargs.reductions = out_reductions;
-
int const icnt
- = CCTK_TraverseString (out_vars, theargs.output_variable, & theargs,
+ = CCTK_TraverseString (out_vars, args_output_variable, & theargs,
CCTK_GROUP_OR_VAR);
if (icnt < 0)
{
@@ -869,18 +910,18 @@ namespace Formaline
if (announce_to_portal)
{
- stores.add_storage (new portal (get_job_id (cctkGH), storage::final));
+ stores.add_storage (new portal (get_run_id (cctkGH), storage::final));
}
if (send_as_rdf)
{
stores.add_storage
- (new rdf (get_job_id (cctkGH), storage::final, cctkGH));
+ (new rdf (get_run_id (cctkGH), storage::final, cctkGH));
}
if (store_into_file)
{
- stores.add_storage (new file (get_job_id (cctkGH), storage::final));
+ stores.add_storage (new file (get_run_id (cctkGH), storage::final));
}
if (stores.num_storages() == 0) return;
@@ -1000,18 +1041,18 @@ namespace Formaline
if (announce_to_portal)
{
- stores.add_storage (new portal (get_job_id (cctkGH), storage::update));
+ stores.add_storage (new portal (get_run_id (cctkGH), storage::update));
}
if (send_as_rdf)
{
stores.add_storage
- (new rdf (get_job_id (cctkGH), storage::update, cctkGH));
+ (new rdf (get_run_id (cctkGH), storage::update, cctkGH));
}
if (store_into_file)
{
- stores.add_storage (new file (get_job_id (cctkGH), storage::update));
+ stores.add_storage (new file (get_run_id (cctkGH), storage::update));
}
if (stores.num_storages() == 0) return;
@@ -1075,18 +1116,18 @@ namespace Formaline
if (announce_to_portal)
{
- stores.add_storage (new portal (get_job_id (cctkGH), storage::update));
+ stores.add_storage (new portal (get_run_id (cctkGH), storage::update));
}
if (send_as_rdf)
{
stores.add_storage
- (new rdf (get_job_id (cctkGH), storage::update, cctkGH));
+ (new rdf (get_run_id (cctkGH), storage::update, cctkGH));
}
if (store_into_file)
{
- stores.add_storage (new file (get_job_id (cctkGH), storage::update));
+ stores.add_storage (new file (get_run_id (cctkGH), storage::update));
}
if (stores.num_storages() == 0) return;
@@ -1112,4 +1153,150 @@ namespace Formaline
+ extern "C"
+ void
+ Formaline_AnnounceBoolean (CCTK_POINTER_TO_CONST const cctkGH_,
+ CCTK_INT const value,
+ CCTK_STRING const key)
+ {
+ cGH const * const cctkGH = static_cast<cGH const *> (cctkGH_);
+ DECLARE_CCTK_PARAMETERS;
+
+ // Only store from the root processor
+ if (CCTK_MyProc (cctkGH) != 0) return;
+
+ // Announce
+ multistorage stores;
+
+ if (announce_to_portal)
+ {
+ stores.add_storage (new portal (get_run_id (cctkGH), storage::update));
+ }
+
+ if (send_as_rdf)
+ {
+ stores.add_storage
+ (new rdf (get_run_id (cctkGH), storage::update, cctkGH));
+ }
+
+ if (store_into_file)
+ {
+ stores.add_storage (new file (get_run_id (cctkGH), storage::update));
+ }
+
+ if (stores.num_storages() == 0) return;
+
+ stores.store (key, static_cast <bool> (value));
+ }
+
+ extern "C"
+ void
+ Formaline_AnnounceInt (CCTK_POINTER_TO_CONST const cctkGH_,
+ CCTK_INT const value,
+ CCTK_STRING const key)
+ {
+ cGH const * const cctkGH = static_cast<cGH const *> (cctkGH_);
+ DECLARE_CCTK_PARAMETERS;
+
+ // Only store from the root processor
+ if (CCTK_MyProc (cctkGH) != 0) return;
+
+ // Announce
+ multistorage stores;
+
+ if (announce_to_portal)
+ {
+ stores.add_storage (new portal (get_run_id (cctkGH), storage::update));
+ }
+
+ if (send_as_rdf)
+ {
+ stores.add_storage
+ (new rdf (get_run_id (cctkGH), storage::update, cctkGH));
+ }
+
+ if (store_into_file)
+ {
+ stores.add_storage (new file (get_run_id (cctkGH), storage::update));
+ }
+
+ if (stores.num_storages() == 0) return;
+
+ stores.store (key, value);
+ }
+
+ extern "C"
+ void
+ Formaline_AnnounceReal (CCTK_POINTER_TO_CONST const cctkGH_,
+ CCTK_REAL const value,
+ CCTK_STRING const key)
+ {
+ cGH const * const cctkGH = static_cast<cGH const *> (cctkGH_);
+ DECLARE_CCTK_PARAMETERS;
+
+ // Only store from the root processor
+ if (CCTK_MyProc (cctkGH) != 0) return;
+
+ // Announce
+ multistorage stores;
+
+ if (announce_to_portal)
+ {
+ stores.add_storage (new portal (get_run_id (cctkGH), storage::update));
+ }
+
+ if (send_as_rdf)
+ {
+ stores.add_storage
+ (new rdf (get_run_id (cctkGH), storage::update, cctkGH));
+ }
+
+ if (store_into_file)
+ {
+ stores.add_storage (new file (get_run_id (cctkGH), storage::update));
+ }
+
+ if (stores.num_storages() == 0) return;
+
+ stores.store (key, value);
+ }
+
+ extern "C"
+ void
+ Formaline_AnnounceString (CCTK_POINTER_TO_CONST const cctkGH_,
+ CCTK_STRING const value,
+ CCTK_STRING const key)
+ {
+ cGH const * const cctkGH = static_cast<cGH const *> (cctkGH_);
+ DECLARE_CCTK_PARAMETERS;
+
+ // Only store from the root processor
+ if (CCTK_MyProc (cctkGH) != 0) return;
+
+ // Announce
+ multistorage stores;
+
+ if (announce_to_portal)
+ {
+ stores.add_storage (new portal (get_run_id (cctkGH), storage::update));
+ }
+
+ if (send_as_rdf)
+ {
+ stores.add_storage
+ (new rdf (get_run_id (cctkGH), storage::update, cctkGH));
+ }
+
+ if (store_into_file)
+ {
+ stores.add_storage (new file (get_run_id (cctkGH), storage::update));
+ }
+
+ if (stores.num_storages() == 0) return;
+
+ stores.store (key, value);
+ }
+
+
+
} // namespace Formaline
diff --git a/src/id.cc b/src/id.cc
index 4ea6531..866b856 100644
--- a/src/id.cc
+++ b/src/id.cc
@@ -1,9 +1,12 @@
#include <cctype>
+#include <fstream>
#include <iomanip>
+#include <iostream>
#include <sstream>
#include <string>
#include "cctk.h"
+#include "cctk_Parameters.h"
#include "util_Network.h"
// IRIX wants this before <time.h>
@@ -51,17 +54,56 @@ namespace Formaline
- // Get a unique job id
+ // Get a unique simulation id
char const *
- get_job_id (cGH const * const cctkGH)
+ get_simulation_id (cGH const * const cctkGH)
{
- // Unique job ID
- static char * job_id = 0;
+ // Unique simulation ID
+ static char * simulation_id = 0;
- if (job_id != 0) return job_id;
+ if (simulation_id != 0) return simulation_id;
- ostringstream job_idbuf;
- job_idbuf << "job-";
+ string simulation_id_str;
+ struct not_good { };
+ try {
+ // Expect the simulation ID id a file in the parent directory of
+ // the output directory
+ DECLARE_CCTK_PARAMETERS;
+ string const out_dir_str = string (out_dir);
+ size_t const last_nonslash = out_dir_str.find_last_not_of ("/");
+ if (last_nonslash == string::npos) throw (not_good());
+ size_t const last_slash = out_dir_str.rfind ('/', last_nonslash);
+ size_t const len = last_slash == string::npos ? 0 : last_slash + 1;
+ string const simulation_id_filename =
+ out_dir_str.substr (0, len) + string("SIMULATION_ID");
+
+ // Open file and read content
+ ifstream simulation_id_file (simulation_id_filename.c_str());
+ if (not simulation_id_file) throw (not_good());
+ getline (simulation_id_file, simulation_id_str);
+ if (simulation_id_str.empty()) throw (not_good());
+ } catch (not_good) {
+ // Use the run ID as fallback if no simulation ID can be found
+ simulation_id_str = string (get_run_id (cctkGH));
+ }
+
+ simulation_id = strdup (simulation_id_str.c_str());
+ return simulation_id;
+ }
+
+
+
+ // Get a unique run id
+ char const *
+ get_run_id (cGH const * const cctkGH)
+ {
+ // Unique run ID
+ static char * run_id = 0;
+
+ if (run_id != 0) return run_id;
+
+ ostringstream run_idbuf;
+ run_idbuf << "run-";
char cparfilename [10000];
CCTK_ParameterFilename (sizeof cparfilename, cparfilename);
@@ -85,28 +127,28 @@ namespace Formaline
}
}
}
- job_idbuf << parfilename;
+ run_idbuf << parfilename;
- job_idbuf << "-";
+ run_idbuf << "-";
char run_host [1000];
Util_GetHostName (run_host, sizeof run_host);
- job_idbuf << run_host;
+ run_idbuf << run_host;
- job_idbuf << "-";
+ run_idbuf << "-";
#if 0
char const * const run_user = CCTK_RunUser();
#else
char const * const run_user = getenv ("USER");
#endif
- job_idbuf << run_user;
+ run_idbuf << run_user;
- job_idbuf << "-";
+ run_idbuf << "-";
time_t const tim = time (0);
struct tm * const ptm = gmtime (& tim);
- job_idbuf << setfill ('0')
+ run_idbuf << setfill ('0')
<< setw(4) << 1900 + ptm->tm_year
<< "."
<< setw(2) << ptm->tm_mon + 1
@@ -119,15 +161,15 @@ namespace Formaline
<< "."
<< setw(2) << ptm->tm_sec;
- job_idbuf << "-";
+ run_idbuf << "-";
pid_t const pid = getpid();
- job_idbuf << pid;
+ run_idbuf << pid;
- string const job_idstr = job_idbuf.str();
- job_id = strdup (job_idstr.c_str());
+ string const run_idstr = run_idbuf.str();
+ run_id = strdup (run_idstr.c_str());
- return job_id;
+ return run_id;
}
@@ -140,10 +182,17 @@ namespace Formaline
}
extern "C" CCTK_POINTER_TO_CONST
+ Formaline_UniqueRunID (CCTK_POINTER_TO_CONST const cctkGH_)
+ {
+ cGH const * const cctkGH = static_cast<cGH const *> (cctkGH_);
+ return static_cast<CCTK_POINTER_TO_CONST> (get_run_id (cctkGH));
+ }
+
+ extern "C" CCTK_POINTER_TO_CONST
Formaline_UniqueSimulationID (CCTK_POINTER_TO_CONST const cctkGH_)
{
cGH const * const cctkGH = static_cast<cGH const *> (cctkGH_);
- return static_cast<CCTK_POINTER_TO_CONST> (get_job_id (cctkGH));
+ return static_cast<CCTK_POINTER_TO_CONST> (get_simulation_id (cctkGH));
}
@@ -152,7 +201,8 @@ namespace Formaline
Formaline_PrintIDs ()
{
CCTK_VInfo (CCTK_THORNSTRING, "Build id: %s", get_build_id (0));
- CCTK_VInfo (CCTK_THORNSTRING, "Simulation id: %s", get_job_id (0));
+ CCTK_VInfo (CCTK_THORNSTRING, "Simulation id: %s", get_simulation_id (0));
+ CCTK_VInfo (CCTK_THORNSTRING, "Run id: %s", get_run_id (0));
return 0;
}
diff --git a/src/id.hh b/src/id.hh
index 08bdb03..e088802 100644
--- a/src/id.hh
+++ b/src/id.hh
@@ -10,9 +10,13 @@ namespace Formaline
char const *
get_build_id (cGH const * const cctkGH);
- // Get a unique job id
+ // Get a unique simulation id
char const *
- get_job_id (cGH const * const cctkGH);
+ get_simulation_id (cGH const * const cctkGH);
+
+ // Get a unique run id
+ char const *
+ get_run_id (cGH const * const cctkGH);
} // namespace Formaline